增加了数据库功能,采用直接编译源码的方式,不使用动态库链接
This commit is contained in:
@@ -0,0 +1,818 @@
|
||||
#include "SQLite.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "../loguru.hpp"
|
||||
|
||||
SQLite::SQLite(const std::string& dbPath)
|
||||
{
|
||||
if (sqlite3_open(dbPath.c_str(), &m_db) != SQLITE_OK) {
|
||||
LOG_F(WARNING, "Can't open database: %s", sqlite3_errmsg(m_db));
|
||||
m_db = nullptr;
|
||||
}
|
||||
m_dbPath = dbPath;
|
||||
}
|
||||
|
||||
SQLite::~SQLite()
|
||||
{
|
||||
if (m_db) sqlite3_close(m_db);
|
||||
}
|
||||
|
||||
bool SQLite::createTable(const std::string& tableName, const std::string& columns) {
|
||||
if (!m_db) {
|
||||
std::cerr << "数据库未打开,无法创建表: " << tableName << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string sql = "CREATE TABLE IF NOT EXISTS " + tableName + " (" + columns + ");";
|
||||
|
||||
char* errMsg = nullptr;
|
||||
int rc = sqlite3_exec(m_db, sql.c_str(), nullptr, nullptr, &errMsg);
|
||||
if (rc != SQLITE_OK) {
|
||||
std::cerr << "创建表失败: " << tableName << "\n错误信息: " << errMsg << std::endl;
|
||||
sqlite3_free(errMsg);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SQLite::createTable()
|
||||
{
|
||||
// 1. 创建ccuState表
|
||||
std::string ccuStateColumns = R"(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
timestamp DATETIME DEFAULT (datetime('now', 'localtime')),
|
||||
fc_mode INTEGER,
|
||||
fc_status INTEGER,
|
||||
fc_fault_level INTEGER,
|
||||
output_power_limit INTEGER,
|
||||
total_generation_time INTEGER,
|
||||
total_generation_power INTEGER,
|
||||
fault_level_1 INTEGER,
|
||||
fault_level_2 INTEGER,
|
||||
fault_level_3 INTEGER,
|
||||
fault_level_4 INTEGER,
|
||||
hydrogen_capacity INTEGER,
|
||||
liquid_oxygen_capacity INTEGER,
|
||||
palladium_temp INTEGER,
|
||||
main_pipe_pressure INTEGER,
|
||||
aux_pipe_pressure INTEGER,
|
||||
cabin_pressure1 INTEGER,
|
||||
cabin_pressure2 INTEGER,
|
||||
cabin_temp1 INTEGER,
|
||||
cabin_temp2 INTEGER,
|
||||
cabin_humidity1 INTEGER,
|
||||
cabin_humidity2 INTEGER,
|
||||
flame_detector1 INTEGER,
|
||||
flame_detector2 INTEGER,
|
||||
h2_concentration1 INTEGER,
|
||||
h2_concentration2 INTEGER,
|
||||
h2_concentration3 INTEGER,
|
||||
o2_concentration1 INTEGER,
|
||||
o2_concentration2 INTEGER,
|
||||
ch3oh_concentration1 INTEGER,
|
||||
ch3oh_concentration2 INTEGER,
|
||||
reserved1_1 INTEGER, reserved1_2 INTEGER, reserved1_3 INTEGER, reserved1_4 INTEGER,
|
||||
reserved1_5 INTEGER, reserved1_6 INTEGER, reserved1_7 INTEGER, reserved1_8 INTEGER,
|
||||
reserved1_9 INTEGER, reserved1_10 INTEGER,
|
||||
cabin_ox_concentration INTEGER,
|
||||
cabin_temperature INTEGER,
|
||||
cabin_humidity INTEGER,
|
||||
cabin_pressure INTEGER,
|
||||
power_cabin_ox_concentration INTEGER,
|
||||
power_cabin_temperature INTEGER,
|
||||
power_cabin_humidity INTEGER,
|
||||
power_cabin_pressure INTEGER,
|
||||
reserved2 INTEGER,
|
||||
dyn_alarm_flag1 INTEGER, dyn_alarm_flag2 INTEGER, dyn_alarm_flag3 INTEGER,
|
||||
dyn_alarm_flag4 INTEGER, dyn_alarm_flag5 INTEGER, dyn_alarm_flag6 INTEGER,
|
||||
ins_alarm_flag1 INTEGER, ins_alarm_flag2 INTEGER, ins_alarm_flag3 INTEGER,
|
||||
ins_alarm_flag4 INTEGER, ins_alarm_flag5 INTEGER, ins_alarm_flag6 INTEGER,
|
||||
ins_relay_status1 INTEGER,
|
||||
ins_relay_status2 INTEGER,
|
||||
dyn_relay_status1 INTEGER,
|
||||
dyn_relay_status2 INTEGER,
|
||||
ins_max_discharge_power INTEGER,
|
||||
dyn_max_discharge_power INTEGER,
|
||||
ins_soc INTEGER,
|
||||
dyn_soc INTEGER,
|
||||
ins_total_energy INTEGER,
|
||||
dyn_total_energy INTEGER,
|
||||
ins_power_input INTEGER,
|
||||
dyn_power_input INTEGER,
|
||||
ins_charge_status INTEGER,
|
||||
dyn_charge_status INTEGER,
|
||||
ins_voltage_link INTEGER,
|
||||
ins_voltage_pack INTEGER,
|
||||
ins_current INTEGER,
|
||||
ins_resistance_pos INTEGER,
|
||||
ins_resistance_neg INTEGER,
|
||||
dyn_voltage_link INTEGER,
|
||||
dyn_voltage_pack INTEGER,
|
||||
dyn_current INTEGER,
|
||||
dyn_resistance_pos INTEGER,
|
||||
dyn_resistance_neg INTEGER,
|
||||
ins_emergency_status INTEGER,
|
||||
dyn_emergency_status INTEGER,
|
||||
reserved3_1 INTEGER, reserved3_2 INTEGER,
|
||||
ins_soc_threshold1 INTEGER,
|
||||
ins_soc_threshold2 INTEGER,
|
||||
ins_soc_threshold3 INTEGER,
|
||||
dyn_soc_threshold1 INTEGER,
|
||||
dyn_soc_threshold2 INTEGER,
|
||||
dyn_soc_threshold3 INTEGER,
|
||||
ins_power_limit1 INTEGER,
|
||||
ins_power_limit2 INTEGER,
|
||||
dyn_power_limit1 INTEGER,
|
||||
dyn_power_limit2 INTEGER,
|
||||
device_online_flag1 INTEGER,
|
||||
device_online_flag2 INTEGER,
|
||||
reserved4 INTEGER,
|
||||
heartbeat INTEGER
|
||||
)";
|
||||
if (!createTable("ccuState", ccuStateColumns)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. 创建disHighVolBusState表
|
||||
std::string disHighVolBusColumns = R"(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
timestamp DATETIME DEFAULT (datetime('now', 'localtime')),
|
||||
fuelCellCircuitBreaker INTEGER,
|
||||
powerLithiumBatteryCircuitBreaker INTEGER,
|
||||
propulsionMotorCircuitBreaker INTEGER,
|
||||
lithiumBatteryGroupInstrumentCircuitBreaker INTEGER,
|
||||
dcDc5ModuleCircuitBreaker INTEGER,
|
||||
bowHighVoltageDistributionBoxCircuitBreaker INTEGER,
|
||||
sternFTDevice45CircuitBreaker INTEGER,
|
||||
sternRudderSwitch1CircuitBreaker INTEGER,
|
||||
sternRudderSwitch2CircuitBreaker INTEGER,
|
||||
fbReservedCircuitBreaker INTEGER,
|
||||
tyzReservedCircuitBreaker INTEGER,
|
||||
reservedCircuitBreaker INTEGER,
|
||||
dcDcFaultWord1 INTEGER,
|
||||
dcDcFaultWord2 INTEGER,
|
||||
powerBusInsulationStatus INTEGER,
|
||||
aBusInsulationStatus INTEGER,
|
||||
meterPowerLossSignal INTEGER,
|
||||
emergencyPowerLossSignal INTEGER,
|
||||
powerBusVoltage INTEGER,
|
||||
dcDc5ModuleCurrent INTEGER,
|
||||
powerBusCurrent INTEGER,
|
||||
busbarAVoltage INTEGER,
|
||||
propulsionMotorControlBoxCurrent INTEGER,
|
||||
busbarACurrent INTEGER,
|
||||
lithiumBatteryGroupMeterCurrent INTEGER,
|
||||
bowHighVoltageDistributionBoxCurrent INTEGER,
|
||||
sternFTDevice45Current INTEGER,
|
||||
tyzReservedSwitchCurrent INTEGER,
|
||||
sternRudderSwitch1Current INTEGER,
|
||||
reservedCurrent1 INTEGER,
|
||||
sternRudderSwitch2Current INTEGER,
|
||||
reservedCurrent2 INTEGER,
|
||||
fbReservedSwitchCurrent INTEGER,
|
||||
reservedCurrent3 INTEGER,
|
||||
coolWaterPressure INTEGER
|
||||
)";
|
||||
if (!createTable("disHighVolBusState", disHighVolBusColumns)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3. 创建disHighAVolBusState表
|
||||
std::string disHighAVolBusColumns = R"(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
timestamp DATETIME DEFAULT (datetime('now', 'localtime')),
|
||||
bowFTDevice123CircuitBreaker INTEGER,
|
||||
actuatorCircuitBreaker INTEGER,
|
||||
mastSteeringGearControlBoxCircuitBreaker INTEGER,
|
||||
xczCircuitBreaker INTEGER,
|
||||
bowRudderControlBoxCircuitBreaker INTEGER,
|
||||
openWaterCoverStartCylinderCircuitBreaker INTEGER,
|
||||
instrumentPowerFailureSignal INTEGER,
|
||||
emergencyPowerFailureSignal INTEGER,
|
||||
waterIngressionAlarm INTEGER,
|
||||
busbarBVoltage INTEGER,
|
||||
busbarBCurrent INTEGER,
|
||||
bowFTDevice123Current INTEGER,
|
||||
actuatorCurrent INTEGER,
|
||||
mastSteeringGearControlBoxCurrent INTEGER,
|
||||
xczCurrent INTEGER,
|
||||
bowRudderControlBoxCurrent INTEGER,
|
||||
openWaterCoverStartCylinderCurrent INTEGER
|
||||
)";
|
||||
if (!createTable("disHighAVolBusState", disHighAVolBusColumns)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 4. 创建disLowMainBusState表
|
||||
std::string disLowMainBusColumns = R"(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
timestamp DATETIME DEFAULT (datetime('now', 'localtime')),
|
||||
lithiumBatteryGroupInstrumentCircuitBreaker INTEGER,
|
||||
bowLowVoltageDistributionBoxCircuitBreaker INTEGER,
|
||||
unit4InstrumentDC48VCircuitBreaker INTEGER,
|
||||
dcC1DCDistributionPanelCircuitBreaker INTEGER,
|
||||
reservedCircuitBreaker1 INTEGER,
|
||||
reservedCircuitBreaker2 INTEGER,
|
||||
emergencyLithiumBatteryGroup2CircuitBreaker INTEGER,
|
||||
instrumentPowerFailureSignal INTEGER,
|
||||
emergencyPowerFailureSignal INTEGER,
|
||||
instrumentBusbarInsulationLow INTEGER,
|
||||
instrumentBusbarVoltage INTEGER,
|
||||
bowLowVoltageDistributionBoxCurrent INTEGER,
|
||||
dcC1InstrumentDC48VCurrent INTEGER,
|
||||
reservedCurrent1 INTEGER,
|
||||
emergencyLithiumBatteryGroup2Current INTEGER,
|
||||
lithiumBatteryGroupInstrumentCurrent INTEGER,
|
||||
unit4InstrumentDC48VCurrent INTEGER,
|
||||
reservedCurrent2 INTEGER,
|
||||
emergency2BusbarVoltage INTEGER,
|
||||
compositeEnergyManagementSystemEmergencyDC48VCurrent INTEGER,
|
||||
fuelCellSecuritySystemEmergencyDC48VCurrent INTEGER,
|
||||
plcControlPowerCurrent INTEGER
|
||||
)";
|
||||
if (!createTable("disLowMainBusState", disLowMainBusColumns)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 5. 创建disLowBusState表
|
||||
std::string disLowBusColumns = R"(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
timestamp DATETIME DEFAULT (datetime('now', 'localtime')),
|
||||
unit1CircuitBreaker INTEGER,
|
||||
unit2CircuitBreaker INTEGER,
|
||||
unit3CircuitBreaker INTEGER,
|
||||
unit5CircuitBreaker INTEGER,
|
||||
bowPZDeviceCircuitBreaker INTEGER,
|
||||
reservedCircuitBreaker1 INTEGER,
|
||||
reservedCircuitBreaker2 INTEGER,
|
||||
emergencyLithiumBatteryGroup1CircuitBreaker INTEGER,
|
||||
powerFailureSignal INTEGER,
|
||||
emergencyPowerFailureSignal INTEGER,
|
||||
waterIngressionAlarm INTEGER,
|
||||
instrumentBusbarVoltage INTEGER,
|
||||
instrumentBusbarCurrent INTEGER,
|
||||
unit1Current INTEGER,
|
||||
unit2Current INTEGER,
|
||||
unit3Current INTEGER,
|
||||
unit5Current INTEGER,
|
||||
bowPZDeviceCurrent INTEGER,
|
||||
emergencyLithiumBatteryGroup1Current INTEGER,
|
||||
emergency1BusbarVoltage INTEGER
|
||||
)";
|
||||
if (!createTable("disLowBusState", disLowBusColumns)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SQLite::insertData(const ccuState data) {
|
||||
if (!m_db) {
|
||||
std::cerr << "数据库未打开,无法插入数据。" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* sql = R"(
|
||||
INSERT INTO CcuState (
|
||||
fc_mode, fc_status, fc_fault_level,
|
||||
output_power_limit, total_generation_time, total_generation_power,
|
||||
fault_level_1, fault_level_2, fault_level_3, fault_level_4,
|
||||
hydrogen_capacity, liquid_oxygen_capacity,
|
||||
palladium_temp, main_pipe_pressure, aux_pipe_pressure,
|
||||
cabin_pressure1, cabin_pressure2, cabin_temp1, cabin_temp2,
|
||||
cabin_humidity1, cabin_humidity2,
|
||||
flame_detector1, flame_detector2,
|
||||
h2_concentration1, h2_concentration2, h2_concentration3,
|
||||
o2_concentration1, o2_concentration2,
|
||||
ch3oh_concentration1, ch3oh_concentration2,
|
||||
reserved1_1, reserved1_2, reserved1_3, reserved1_4, reserved1_5,
|
||||
reserved1_6, reserved1_7, reserved1_8, reserved1_9, reserved1_10,
|
||||
cabin_ox_concentration, cabin_temperature, cabin_humidity, cabin_pressure,
|
||||
power_cabin_ox_concentration, power_cabin_temperature,
|
||||
power_cabin_humidity, power_cabin_pressure,
|
||||
reserved2,
|
||||
dyn_alarm_flag1, dyn_alarm_flag2, dyn_alarm_flag3,
|
||||
dyn_alarm_flag4, dyn_alarm_flag5, dyn_alarm_flag6,
|
||||
ins_alarm_flag1, ins_alarm_flag2, ins_alarm_flag3,
|
||||
ins_alarm_flag4, ins_alarm_flag5, ins_alarm_flag6,
|
||||
ins_relay_status1, ins_relay_status2,
|
||||
dyn_relay_status1, dyn_relay_status2,
|
||||
ins_max_discharge_power, dyn_max_discharge_power,
|
||||
ins_soc, dyn_soc,
|
||||
ins_total_energy, dyn_total_energy,
|
||||
ins_power_input, dyn_power_input,
|
||||
ins_charge_status, dyn_charge_status,
|
||||
ins_voltage_link, ins_voltage_pack, ins_current,
|
||||
ins_resistance_pos, ins_resistance_neg,
|
||||
dyn_voltage_link, dyn_voltage_pack, dyn_current,
|
||||
dyn_resistance_pos, dyn_resistance_neg,
|
||||
ins_emergency_status, dyn_emergency_status,
|
||||
reserved3_1, reserved3_2,
|
||||
ins_soc_threshold1, ins_soc_threshold2, ins_soc_threshold3,
|
||||
dyn_soc_threshold1, dyn_soc_threshold2, dyn_soc_threshold3,
|
||||
ins_power_limit1, ins_power_limit2,
|
||||
dyn_power_limit1, dyn_power_limit2,
|
||||
device_online_flag1, device_online_flag2,
|
||||
reserved4, heartbeat
|
||||
) VALUES (
|
||||
?, ?, ?,
|
||||
?, ?, ?,
|
||||
?, ?, ?, ?,
|
||||
?, ?,
|
||||
?, ?, ?,
|
||||
?, ?, ?, ?,
|
||||
?, ?,
|
||||
?, ?,
|
||||
?, ?, ?,
|
||||
?, ?,
|
||||
?, ?,
|
||||
?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?,
|
||||
?, ?, ?, ?,
|
||||
?,
|
||||
?, ?, ?,
|
||||
?, ?, ?,
|
||||
?, ?, ?,
|
||||
?, ?, ?,
|
||||
?, ?,
|
||||
?, ?,
|
||||
?, ?,
|
||||
?, ?,
|
||||
?, ?,
|
||||
?, ?,
|
||||
?, ?,
|
||||
?, ?, ?,
|
||||
?, ?,
|
||||
?, ?, ?,
|
||||
?, ?,
|
||||
?, ?,
|
||||
?, ?,
|
||||
?, ?,
|
||||
?, ?, ?,
|
||||
?, ?, ?,
|
||||
?, ?,
|
||||
?, ?,
|
||||
?, ?
|
||||
);
|
||||
)";
|
||||
|
||||
sqlite3_stmt* stmt = nullptr;
|
||||
if (sqlite3_prepare_v2(m_db, sql, -1, &stmt, nullptr) != SQLITE_OK) {
|
||||
std::cerr << "准备插入语句失败: " << sqlite3_errmsg(m_db) << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
int idx = 1;
|
||||
|
||||
// 辅助宏简化绑定
|
||||
#define BIND_INT(value) sqlite3_bind_int(stmt, idx++, value)
|
||||
#define BIND_16(value) sqlite3_bind_int(stmt, idx++, static_cast<int>(value))
|
||||
#define BIND_32(value) sqlite3_bind_int64(stmt, idx++, static_cast<sqlite3_int64>(value))
|
||||
|
||||
BIND_INT(data.fc_mode);
|
||||
BIND_INT(data.fc_status);
|
||||
BIND_INT(data.fc_fault_level);
|
||||
|
||||
BIND_16(data.output_power_limit);
|
||||
BIND_16(data.total_generation_time);
|
||||
BIND_16(data.total_generation_power);
|
||||
BIND_16(data.fault_level_1);
|
||||
BIND_16(data.fault_level_2);
|
||||
BIND_16(data.fault_level_3);
|
||||
BIND_16(data.fault_level_4);
|
||||
|
||||
BIND_INT(data.hydrogen_capacity);
|
||||
BIND_INT(data.liquid_oxygen_capacity);
|
||||
|
||||
BIND_16(data.palladium_temp);
|
||||
BIND_16(data.main_pipe_pressure);
|
||||
BIND_16(data.aux_pipe_pressure);
|
||||
|
||||
BIND_16(data.cabin_pressure1);
|
||||
BIND_16(data.cabin_pressure2);
|
||||
BIND_16(data.cabin_temp1);
|
||||
BIND_16(data.cabin_temp2);
|
||||
BIND_16(data.cabin_humidity1);
|
||||
BIND_16(data.cabin_humidity2);
|
||||
|
||||
BIND_INT(data.flame_detector1);
|
||||
BIND_INT(data.flame_detector2);
|
||||
|
||||
BIND_16(data.h2_concentration1);
|
||||
BIND_16(data.h2_concentration2);
|
||||
BIND_16(data.h2_concentration3);
|
||||
BIND_16(data.o2_concentration1);
|
||||
BIND_16(data.o2_concentration2);
|
||||
BIND_16(data.ch3oh_concentration1);
|
||||
BIND_16(data.ch3oh_concentration2);
|
||||
|
||||
for (int i = 0; i < 10; ++i) BIND_16(data.reserved1[i]);
|
||||
|
||||
BIND_16(data.cabin_ox_concentration);
|
||||
BIND_16(data.cabin_temperature);
|
||||
BIND_16(data.cabin_humidity);
|
||||
BIND_16(data.cabin_pressure);
|
||||
|
||||
BIND_16(data.power_cabin_ox_concentration);
|
||||
BIND_16(data.power_cabin_temperature);
|
||||
BIND_16(data.power_cabin_humidity);
|
||||
BIND_16(data.power_cabin_pressure);
|
||||
|
||||
BIND_INT(data.reserved2[0]);
|
||||
|
||||
for (int i = 0; i < 6; ++i) BIND_INT(data.dyn_alarm_flag[i]);
|
||||
for (int i = 0; i < 6; ++i) BIND_INT(data.ins_alarm_flag[i]);
|
||||
|
||||
BIND_INT(data.ins_relay_status1);
|
||||
BIND_INT(data.ins_relay_status2);
|
||||
BIND_INT(data.dyn_relay_status1);
|
||||
BIND_INT(data.dyn_relay_status2);
|
||||
|
||||
BIND_16(data.ins_max_discharge_power);
|
||||
BIND_16(data.dyn_max_discharge_power);
|
||||
|
||||
BIND_INT(data.ins_soc);
|
||||
BIND_INT(data.dyn_soc);
|
||||
|
||||
BIND_16(data.ins_total_energy);
|
||||
BIND_16(data.dyn_total_energy);
|
||||
|
||||
BIND_16(data.ins_power_input);
|
||||
BIND_16(data.dyn_power_input);
|
||||
|
||||
BIND_INT(data.ins_charge_status);
|
||||
BIND_INT(data.dyn_charge_status);
|
||||
|
||||
BIND_16(data.ins_voltage_link);
|
||||
BIND_16(data.ins_voltage_pack);
|
||||
BIND_16(data.ins_current);
|
||||
BIND_16(data.ins_resistance_pos);
|
||||
BIND_16(data.ins_resistance_neg);
|
||||
|
||||
BIND_16(data.dyn_voltage_link);
|
||||
BIND_16(data.dyn_voltage_pack);
|
||||
BIND_16(data.dyn_current);
|
||||
BIND_16(data.dyn_resistance_pos);
|
||||
BIND_16(data.dyn_resistance_neg);
|
||||
|
||||
BIND_INT(data.ins_emergency_status);
|
||||
BIND_INT(data.dyn_emergency_status);
|
||||
|
||||
BIND_INT(data.reserved3[0]);
|
||||
BIND_INT(data.reserved3[1]);
|
||||
|
||||
BIND_INT(data.ins_soc_threshold1);
|
||||
BIND_INT(data.ins_soc_threshold2);
|
||||
BIND_INT(data.ins_soc_threshold3);
|
||||
BIND_INT(data.dyn_soc_threshold1);
|
||||
BIND_INT(data.dyn_soc_threshold2);
|
||||
BIND_INT(data.dyn_soc_threshold3);
|
||||
|
||||
BIND_INT(data.ins_power_limit1);
|
||||
BIND_INT(data.ins_power_limit2);
|
||||
BIND_INT(data.dyn_power_limit1);
|
||||
BIND_INT(data.dyn_power_limit2);
|
||||
|
||||
BIND_32(data.device_online_flag1);
|
||||
BIND_32(data.device_online_flag2);
|
||||
BIND_32(data.reserved4);
|
||||
BIND_32(data.heartbeat);
|
||||
|
||||
#undef BIND_INT
|
||||
#undef BIND_16
|
||||
#undef BIND_32
|
||||
|
||||
bool success = (sqlite3_step(stmt) == SQLITE_DONE);
|
||||
if (!success) {
|
||||
std::cerr << "执行插入失败: " << sqlite3_errmsg(m_db) << std::endl;
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
return success;
|
||||
}
|
||||
|
||||
bool SQLite::insertData(const disHighVolBusState data) {
|
||||
if (!m_db) {
|
||||
std::cerr << "数据库未打开,无法插入数据。" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* sql = R"(
|
||||
INSERT INTO disHighVolBusState (
|
||||
fuelCellCircuitBreaker,
|
||||
powerLithiumBatteryCircuitBreaker,
|
||||
propulsionMotorCircuitBreaker,
|
||||
lithiumBatteryGroupInstrumentCircuitBreaker,
|
||||
dcDc5ModuleCircuitBreaker,
|
||||
bowHighVoltageDistributionBoxCircuitBreaker,
|
||||
sternFTDevice45CircuitBreaker,
|
||||
sternRudderSwitch1CircuitBreaker,
|
||||
sternRudderSwitch2CircuitBreaker,
|
||||
fbReservedCircuitBreaker,
|
||||
tyzReservedCircuitBreaker,
|
||||
reservedCircuitBreaker,
|
||||
dcDcFaultWord1,
|
||||
dcDcFaultWord2,
|
||||
powerBusInsulationStatus,
|
||||
aBusInsulationStatus,
|
||||
meterPowerLossSignal,
|
||||
emergencyPowerLossSignal,
|
||||
powerBusVoltage,
|
||||
dcDc5ModuleCurrent,
|
||||
powerBusCurrent,
|
||||
busbarAVoltage,
|
||||
propulsionMotorControlBoxCurrent,
|
||||
busbarACurrent,
|
||||
lithiumBatteryGroupMeterCurrent,
|
||||
bowHighVoltageDistributionBoxCurrent,
|
||||
sternFTDevice45Current,
|
||||
tyzReservedSwitchCurrent,
|
||||
sternRudderSwitch1Current,
|
||||
reservedCurrent1,
|
||||
sternRudderSwitch2Current,
|
||||
reservedCurrent2,
|
||||
fbReservedSwitchCurrent,
|
||||
reservedCurrent3,
|
||||
coolWaterPressure
|
||||
) VALUES (
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
);
|
||||
)";
|
||||
|
||||
sqlite3_stmt* stmt = nullptr;
|
||||
if (sqlite3_prepare_v2(m_db, sql, -1, &stmt, nullptr) != SQLITE_OK) {
|
||||
std::cerr << "准备插入语句失败: " << sqlite3_errmsg(m_db) << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
int idx = 1;
|
||||
|
||||
#define BIND_INT(x) sqlite3_bind_int(stmt, idx++, static_cast<int>(x))
|
||||
|
||||
BIND_INT(data.fuelCellCircuitBreaker);
|
||||
BIND_INT(data.powerLithiumBatteryCircuitBreaker);
|
||||
BIND_INT(data.propulsionMotorCircuitBreaker);
|
||||
BIND_INT(data.lithiumBatteryGroupInstrumentCircuitBreaker);
|
||||
BIND_INT(data.dcDc5ModuleCircuitBreaker);
|
||||
BIND_INT(data.bowHighVoltageDistributionBoxCircuitBreaker);
|
||||
BIND_INT(data.sternFTDevice45CircuitBreaker);
|
||||
BIND_INT(data.sternRudderSwitch1CircuitBreaker);
|
||||
BIND_INT(data.sternRudderSwitch2CircuitBreaker);
|
||||
BIND_INT(data.fbReservedCircuitBreaker);
|
||||
BIND_INT(data.tyzReservedCircuitBreaker);
|
||||
BIND_INT(data.reservedCircuitBreaker);
|
||||
BIND_INT(data.dcDcFaultWord1);
|
||||
BIND_INT(data.dcDcFaultWord2);
|
||||
BIND_INT(data.powerBusInsulationStatus);
|
||||
BIND_INT(data.aBusInsulationStatus);
|
||||
BIND_INT(data.meterPowerLossSignal);
|
||||
BIND_INT(data.emergencyPowerLossSignal);
|
||||
BIND_INT(data.powerBusVoltage);
|
||||
BIND_INT(data.dcDc5ModuleCurrent);
|
||||
BIND_INT(data.powerBusCurrent);
|
||||
BIND_INT(data.busbarAVoltage);
|
||||
BIND_INT(data.propulsionMotorControlBoxCurrent);
|
||||
BIND_INT(data.busbarACurrent);
|
||||
BIND_INT(data.lithiumBatteryGroupMeterCurrent);
|
||||
BIND_INT(data.bowHighVoltageDistributionBoxCurrent);
|
||||
BIND_INT(data.sternFTDevice45Current);
|
||||
BIND_INT(data.tyzReservedSwitchCurrent);
|
||||
BIND_INT(data.sternRudderSwitch1Current);
|
||||
BIND_INT(data.reservedCurrent1);
|
||||
BIND_INT(data.sternRudderSwitch2Current);
|
||||
BIND_INT(data.reservedCurrent2);
|
||||
BIND_INT(data.fbReservedSwitchCurrent);
|
||||
BIND_INT(data.reservedCurrent3);
|
||||
BIND_INT(data.coolWaterPressure);
|
||||
|
||||
#undef BIND_INT
|
||||
|
||||
bool success = (sqlite3_step(stmt) == SQLITE_DONE);
|
||||
if (!success) {
|
||||
std::cerr << "执行插入失败: " << sqlite3_errmsg(m_db) << std::endl;
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
return success;
|
||||
}
|
||||
|
||||
bool SQLite::insertData(const disHighAVolBusState data) {
|
||||
if (!m_db) {
|
||||
std::cerr << "数据库未打开,无法插入数据。" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* sql = R"(
|
||||
INSERT INTO disHighAVolBusState (
|
||||
bowFTDevice123CircuitBreaker,
|
||||
actuatorCircuitBreaker,
|
||||
mastSteeringGearControlBoxCircuitBreaker,
|
||||
xczCircuitBreaker,
|
||||
bowRudderControlBoxCircuitBreaker,
|
||||
openWaterCoverStartCylinderCircuitBreaker,
|
||||
instrumentPowerFailureSignal,
|
||||
emergencyPowerFailureSignal,
|
||||
waterIngressionAlarm,
|
||||
busbarBVoltage,
|
||||
busbarBCurrent,
|
||||
bowFTDevice123Current,
|
||||
actuatorCurrent,
|
||||
mastSteeringGearControlBoxCurrent,
|
||||
xczCurrent,
|
||||
bowRudderControlBoxCurrent,
|
||||
openWaterCoverStartCylinderCurrent
|
||||
) VALUES (
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
);
|
||||
)";
|
||||
|
||||
sqlite3_stmt* stmt = nullptr;
|
||||
if (sqlite3_prepare_v2(m_db, sql, -1, &stmt, nullptr) != SQLITE_OK) {
|
||||
std::cerr << "准备插入语句失败: " << sqlite3_errmsg(m_db) << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
int idx = 1;
|
||||
#define BIND_INT(x) sqlite3_bind_int(stmt, idx++, static_cast<int>(x))
|
||||
|
||||
BIND_INT(data.bowFTDevice123CircuitBreaker);
|
||||
BIND_INT(data.actuatorCircuitBreaker);
|
||||
BIND_INT(data.mastSteeringGearControlBoxCircuitBreaker);
|
||||
BIND_INT(data.xczCircuitBreaker);
|
||||
BIND_INT(data.bowRudderControlBoxCircuitBreaker);
|
||||
BIND_INT(data.openWaterCoverStartCylinderCircuitBreaker);
|
||||
BIND_INT(data.instrumentPowerFailureSignal);
|
||||
BIND_INT(data.emergencyPowerFailureSignal);
|
||||
BIND_INT(data.waterIngressionAlarm);
|
||||
BIND_INT(data.busbarBVoltage);
|
||||
BIND_INT(data.busbarBCurrent);
|
||||
BIND_INT(data.bowFTDevice123Current);
|
||||
BIND_INT(data.actuatorCurrent);
|
||||
BIND_INT(data.mastSteeringGearControlBoxCurrent);
|
||||
BIND_INT(data.xczCurrent);
|
||||
BIND_INT(data.bowRudderControlBoxCurrent);
|
||||
BIND_INT(data.openWaterCoverStartCylinderCurrent);
|
||||
|
||||
#undef BIND_INT
|
||||
|
||||
bool success = (sqlite3_step(stmt) == SQLITE_DONE);
|
||||
if (!success) {
|
||||
std::cerr << "执行插入失败: " << sqlite3_errmsg(m_db) << std::endl;
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
return success;
|
||||
}
|
||||
|
||||
bool SQLite::insertData(const disLowMainBusState data) {
|
||||
if (!m_db) {
|
||||
std::cerr << "数据库未打开,无法插入数据。" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* sql = R"(
|
||||
INSERT INTO disLowMainBusState (
|
||||
lithiumBatteryGroupInstrumentCircuitBreaker,
|
||||
bowLowVoltageDistributionBoxCircuitBreaker,
|
||||
unit4InstrumentDC48VCircuitBreaker,
|
||||
dcC1DCDistributionPanelCircuitBreaker,
|
||||
reservedCircuitBreaker1,
|
||||
reservedCircuitBreaker2,
|
||||
emergencyLithiumBatteryGroup2CircuitBreaker,
|
||||
instrumentPowerFailureSignal,
|
||||
emergencyPowerFailureSignal,
|
||||
instrumentBusbarInsulationLow,
|
||||
instrumentBusbarVoltage,
|
||||
bowLowVoltageDistributionBoxCurrent,
|
||||
dcC1InstrumentDC48VCurrent,
|
||||
reservedCurrent1,
|
||||
emergencyLithiumBatteryGroup2Current,
|
||||
lithiumBatteryGroupInstrumentCurrent,
|
||||
unit4InstrumentDC48VCurrent,
|
||||
reservedCurrent2,
|
||||
emergency2BusbarVoltage,
|
||||
compositeEnergyManagementSystemEmergencyDC48VCurrent,
|
||||
fuelCellSecuritySystemEmergencyDC48VCurrent,
|
||||
plcControlPowerCurrent
|
||||
) VALUES (
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
);
|
||||
)";
|
||||
|
||||
sqlite3_stmt* stmt = nullptr;
|
||||
if (sqlite3_prepare_v2(m_db, sql, -1, &stmt, nullptr) != SQLITE_OK) {
|
||||
std::cerr << "准备插入语句失败: " << sqlite3_errmsg(m_db) << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
int idx = 1;
|
||||
#define BIND_INT(x) sqlite3_bind_int(stmt, idx++, static_cast<int>(x))
|
||||
|
||||
BIND_INT(data.lithiumBatteryGroupInstrumentCircuitBreaker);
|
||||
BIND_INT(data.bowLowVoltageDistributionBoxCircuitBreaker);
|
||||
BIND_INT(data.unit4InstrumentDC48VCircuitBreaker);
|
||||
BIND_INT(data.dcC1DCDistributionPanelCircuitBreaker);
|
||||
BIND_INT(data.reservedCircuitBreaker1);
|
||||
BIND_INT(data.reservedCircuitBreaker2);
|
||||
BIND_INT(data.emergencyLithiumBatteryGroup2CircuitBreaker);
|
||||
BIND_INT(data.instrumentPowerFailureSignal);
|
||||
BIND_INT(data.emergencyPowerFailureSignal);
|
||||
BIND_INT(data.instrumentBusbarInsulationLow);
|
||||
BIND_INT(data.instrumentBusbarVoltage);
|
||||
BIND_INT(data.bowLowVoltageDistributionBoxCurrent);
|
||||
BIND_INT(data.dcC1InstrumentDC48VCurrent);
|
||||
BIND_INT(data.reservedCurrent1);
|
||||
BIND_INT(data.emergencyLithiumBatteryGroup2Current);
|
||||
BIND_INT(data.lithiumBatteryGroupInstrumentCurrent);
|
||||
BIND_INT(data.unit4InstrumentDC48VCurrent);
|
||||
BIND_INT(data.reservedCurrent2);
|
||||
BIND_INT(data.emergency2BusbarVoltage);
|
||||
BIND_INT(data.compositeEnergyManagementSystemEmergencyDC48VCurrent);
|
||||
BIND_INT(data.fuelCellSecuritySystemEmergencyDC48VCurrent);
|
||||
BIND_INT(data.plcControlPowerCurrent);
|
||||
|
||||
#undef BIND_INT
|
||||
|
||||
bool success = (sqlite3_step(stmt) == SQLITE_DONE);
|
||||
if (!success) {
|
||||
std::cerr << "执行插入失败: " << sqlite3_errmsg(m_db) << std::endl;
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
return success;
|
||||
}
|
||||
|
||||
bool SQLite::insertData(const disLowBusState data) {
|
||||
if (!m_db) {
|
||||
std::cerr << "数据库未打开,无法插入数据。" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* sql = R"(
|
||||
INSERT INTO disLowBusState (
|
||||
unit1CircuitBreaker,
|
||||
unit2CircuitBreaker,
|
||||
unit3CircuitBreaker,
|
||||
unit5CircuitBreaker,
|
||||
bowPZDeviceCircuitBreaker,
|
||||
reservedCircuitBreaker1,
|
||||
reservedCircuitBreaker2,
|
||||
emergencyLithiumBatteryGroup1CircuitBreaker,
|
||||
powerFailureSignal,
|
||||
emergencyPowerFailureSignal,
|
||||
waterIngressionAlarm,
|
||||
instrumentBusbarVoltage,
|
||||
instrumentBusbarCurrent,
|
||||
unit1Current,
|
||||
unit2Current,
|
||||
unit3Current,
|
||||
unit5Current,
|
||||
bowPZDeviceCurrent,
|
||||
emergencyLithiumBatteryGroup1Current,
|
||||
emergency1BusbarVoltage
|
||||
) VALUES (
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
);
|
||||
)";
|
||||
|
||||
sqlite3_stmt* stmt = nullptr;
|
||||
if (sqlite3_prepare_v2(m_db, sql, -1, &stmt, nullptr) != SQLITE_OK) {
|
||||
std::cerr << "准备插入语句失败: " << sqlite3_errmsg(m_db) << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
int idx = 1;
|
||||
#define BIND_INT(x) sqlite3_bind_int(stmt, idx++, static_cast<int>(x))
|
||||
|
||||
BIND_INT(data.unit1CircuitBreaker);
|
||||
BIND_INT(data.unit2CircuitBreaker);
|
||||
BIND_INT(data.unit3CircuitBreaker);
|
||||
BIND_INT(data.unit5CircuitBreaker);
|
||||
BIND_INT(data.bowPZDeviceCircuitBreaker);
|
||||
BIND_INT(data.reservedCircuitBreaker1);
|
||||
BIND_INT(data.reservedCircuitBreaker2);
|
||||
BIND_INT(data.emergencyLithiumBatteryGroup1CircuitBreaker);
|
||||
BIND_INT(data.powerFailureSignal);
|
||||
BIND_INT(data.emergencyPowerFailureSignal);
|
||||
BIND_INT(data.waterIngressionAlarm);
|
||||
BIND_INT(data.instrumentBusbarVoltage);
|
||||
BIND_INT(data.instrumentBusbarCurrent);
|
||||
BIND_INT(data.unit1Current);
|
||||
BIND_INT(data.unit2Current);
|
||||
BIND_INT(data.unit3Current);
|
||||
BIND_INT(data.unit5Current);
|
||||
BIND_INT(data.bowPZDeviceCurrent);
|
||||
BIND_INT(data.emergencyLithiumBatteryGroup1Current);
|
||||
BIND_INT(data.emergency1BusbarVoltage);
|
||||
|
||||
#undef BIND_INT
|
||||
|
||||
bool success = (sqlite3_step(stmt) == SQLITE_DONE);
|
||||
if (!success) {
|
||||
std::cerr << "执行插入失败: " << sqlite3_errmsg(m_db) << std::endl;
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
return success;
|
||||
}
|
||||
Reference in New Issue
Block a user