#include "SQLiteDB.h" #include #include #include #include SQLiteDB::SQLiteDB(const std::string& dbPath) { if (sqlite3_open(dbPath.c_str(), &m_db) != SQLITE_OK) { std::cerr << "Error opening database: " << sqlite3_errmsg(m_db) << std::endl; m_db = nullptr; } m_dbPath = dbPath; } template bool SQLiteDB::bindParameters(sqlite3_stmt* stmt, const T& data) { // 需要为每个具体类型特化实现 return false; } template<> bool SQLiteDB::bindParameters(sqlite3_stmt* stmt, const DriverTable& data) { int index = 1; sqlite3_bind_int(stmt, index++, data.depth1); sqlite3_bind_int(stmt, index++, data.depth2); sqlite3_bind_int(stmt, index++, data.depth3); sqlite3_bind_int(stmt, index++, data.overDeep1); sqlite3_bind_int(stmt, index++, data.overDeep2); sqlite3_bind_int(stmt, index++, data.ctd1); sqlite3_bind_int(stmt, index++, data.ctd2); sqlite3_bind_int(stmt, index++, data.soundVeloc); sqlite3_bind_int(stmt, index++, data.commMast); sqlite3_bind_int(stmt, index++, data.ins); sqlite3_bind_int(stmt, index++, data.ntp); sqlite3_bind_int(stmt, index++, data.inputWaterSensor1); sqlite3_bind_int(stmt, index++, data.inputWaterSensor2); sqlite3_bind_int(stmt, index++, data.inputWaterSensor3); sqlite3_bind_int(stmt, index++, data.singleBeamSonar1); sqlite3_bind_int(stmt, index++, data.singleBeamSonar2); sqlite3_bind_int(stmt, index++, data.singleBeamSonar3); sqlite3_bind_int(stmt, index++, data.singleBeamSonar4); sqlite3_bind_int(stmt, index++, data.singleBeamSonar5); sqlite3_bind_int(stmt, index++, data.singleBeamSonar6); sqlite3_bind_int(stmt, index++, data.singleBeamSonar7); sqlite3_bind_int(stmt, index++, data.singleBeamSonar8); sqlite3_bind_int(stmt, index++, data.forwardSonar); sqlite3_bind_int(stmt, index++, data.DVL); sqlite3_bind_int(stmt, index++, data.lowFreqSonar); sqlite3_bind_int(stmt, index++, data.USBL); sqlite3_bind_int(stmt, index++, data.bowWaterlnet1); sqlite3_bind_int(stmt, index++, data.bowWaterlnet2); sqlite3_bind_int(stmt, index++, data.bowWaterlnet3); sqlite3_bind_int(stmt, index++, data.bowWaterlnet4); sqlite3_bind_int(stmt, index++, data.bowWaterlnet5); sqlite3_bind_int(stmt, index++, data.bowWaterlnet6); sqlite3_bind_int(stmt, index++, data.bowWaterlnet7); sqlite3_bind_int(stmt, index++, data.bowWaterlnet8); sqlite3_bind_int(stmt, index++, data.bowRudderDeploy); sqlite3_bind_int(stmt, index++, data.bowRudderServo1); sqlite3_bind_int(stmt, index++, data.bowRudderServo2); sqlite3_bind_int(stmt, index++, data.bowCover1); sqlite3_bind_int(stmt, index++, data.bowCover2); sqlite3_bind_int(stmt, index++, data.bowCover3); sqlite3_bind_int(stmt, index++, data.bowCover4); sqlite3_bind_int(stmt, index++, data.bowCover5); sqlite3_bind_int(stmt, index++, data.bowCover6); sqlite3_bind_int(stmt, index++, data.waterInject); sqlite3_bind_int(stmt, index++, data.mastLiftingServo); sqlite3_bind_int(stmt, index++, data.buoyancyAdjust1); sqlite3_bind_int(stmt, index++, data.buoyancyAdjust2); sqlite3_bind_int(stmt, index++, data.buoyancyAdjust3); sqlite3_bind_int(stmt, index++, data.buoyancyAdjust4); sqlite3_bind_int(stmt, index++, data.buoyancyAdjust5); sqlite3_bind_int(stmt, index++, data.sternRudderServo1); sqlite3_bind_int(stmt, index++, data.sternRudderServo2); sqlite3_bind_int(stmt, index++, data.sternRudderServo3); sqlite3_bind_int(stmt, index++, data.sternRudderServo4); sqlite3_bind_int(stmt, index++, data.thruster); sqlite3_bind_int(stmt, index++, data.bowThrow); sqlite3_bind_int(stmt, index++, data.sternThrow); sqlite3_bind_int(stmt, index++, data.photoSensor); sqlite3_bind_int(stmt, index++, data.electSensor); sqlite3_bind_int(stmt, index++, data.launchControler); sqlite3_bind_int(stmt, index++, data.sideSonar); sqlite3_bind_int(stmt, index++, data.buoyage); return true; } // 为ccuState特化实现 template<> bool SQLiteDB::bindParameters(sqlite3_stmt* stmt, const ccuState& data) { int index = 1; sqlite3_bind_int(stmt, index++, data.currentWorkCondition); sqlite3_bind_int(stmt, index++, data.fcuState); sqlite3_bind_int(stmt, index++, data.fcuFaultLeve); sqlite3_bind_double(stmt, index++, data.powerLimit); sqlite3_bind_double(stmt, index++, data.totalPowerGeneration); sqlite3_bind_double(stmt, index++, data.ch4o); sqlite3_bind_double(stmt, index++, data.o2); sqlite3_bind_double(stmt, index++, data.fcuVoltage); sqlite3_bind_double(stmt, index++, data.fcuCurrent); sqlite3_bind_double(stmt, index++, data.o2Level); sqlite3_bind_double(stmt, index++, data.placeholder1); sqlite3_bind_double(stmt, index++, data.exchangerTemperature); sqlite3_bind_double(stmt, index++, data.fcuOutPower); sqlite3_bind_double(stmt, index++, data.fcuOutIns); sqlite3_bind_double(stmt, index++, data.fcuVoltageIns); sqlite3_bind_double(stmt, index++, data.fcuVoltagePower); sqlite3_bind_double(stmt, index++, data.fcuCurrentIns); sqlite3_bind_double(stmt, index++, data.fcuCurrentPower); sqlite3_bind_double(stmt, index++, data.h2Concentration1); sqlite3_bind_double(stmt, index++, data.h2Concentration2); sqlite3_bind_double(stmt, index++, data.o2Concentration1); sqlite3_bind_double(stmt, index++, data.o2Concentration2); sqlite3_bind_double(stmt, index++, data.ch4oConcentration1); sqlite3_bind_double(stmt, index++, data.ch4oConcentration2); sqlite3_bind_double(stmt, index++, data.backpressure1); sqlite3_bind_double(stmt, index++, data.backpressure2); sqlite3_bind_int(stmt, index++, data.flameDetection); sqlite3_bind_int(stmt, index++, data.fcuGZ_1L); sqlite3_bind_int(stmt, index++, data.fcuGZ_1H); sqlite3_bind_int(stmt, index++, data.fcuGZ_2L); sqlite3_bind_int(stmt, index++, data.fcuGZ_2H); sqlite3_bind_int(stmt, index++, data.fcuGZ_3L); sqlite3_bind_int(stmt, index++, data.fcuGZ_3H); sqlite3_bind_int(stmt, index++, data.insPosRelayState); sqlite3_bind_int(stmt, index++, data.insNegRelayState); sqlite3_bind_int(stmt, index++, data.powerPosRelayState); sqlite3_bind_int(stmt, index++, data.powerNegRelayState); sqlite3_bind_int(stmt, index++, data.insBatLimit); sqlite3_bind_int(stmt, index++, data.powerBatLimit); sqlite3_bind_int(stmt, index++, data.insBatSoc); sqlite3_bind_int(stmt, index++, data.powerBatSoc); sqlite3_bind_int(stmt, index++, data.insBatTotalElectricity); sqlite3_bind_int(stmt, index++, data.powerBatTotalElectricity); sqlite3_bind_int(stmt, index++, data.insBatCurrentElectricity); sqlite3_bind_int(stmt, index++, data.powerBatCurrentElectricity); sqlite3_bind_int(stmt, index++, data.insChargeState); sqlite3_bind_int(stmt, index++, data.powerChargeState); sqlite3_bind_int(stmt, index++, data.insLinkVoltage); sqlite3_bind_int(stmt, index++, data.insPackVoltage); sqlite3_bind_int(stmt, index++, data.insCurrent); sqlite3_bind_int(stmt, index++, data.insPosInsulationResistance); sqlite3_bind_int(stmt, index++, data.insNegInsulationResistance); sqlite3_bind_int(stmt, index++, data.powerLinkVoltage); sqlite3_bind_int(stmt, index++, data.powerPackVoltage); sqlite3_bind_int(stmt, index++, data.powerCurrent); sqlite3_bind_int(stmt, index++, data.powerPosInsulationResistance); sqlite3_bind_int(stmt, index++, data.powerNegInsulationResistance); sqlite3_bind_int(stmt, index++, data.insEmergencyStatusWord); sqlite3_bind_int(stmt, index++, data.powerEmergencyStatusWord); sqlite3_bind_int(stmt, index++, data.insAlarmIdentificationWord); sqlite3_bind_int(stmt, index++, data.powerAlarmIdentificationWord); sqlite3_bind_int(stmt, index++, data.insCurrentSocHold1); sqlite3_bind_int(stmt, index++, data.insCurrentSocHold2); sqlite3_bind_int(stmt, index++, data.insCurrentSocHold3); sqlite3_bind_int(stmt, index++, data.fcuCurrentToInsLimit1); sqlite3_bind_int(stmt, index++, data.fcuCurrentToinsLimit2); sqlite3_bind_int(stmt, index++, data.powerCurrentSocHold1); sqlite3_bind_int(stmt, index++, data.powerCurrentSocHold2); sqlite3_bind_int(stmt, index++, data.powerCurrentSocHold3); sqlite3_bind_int(stmt, index++, data.powerCurrentToInsLimit1); sqlite3_bind_int(stmt, index++, data.powerCurrentToinsLimit2); sqlite3_bind_double(stmt, index++, data.placeholder2); sqlite3_bind_double(stmt, index++, data.placeholder3); sqlite3_bind_double(stmt, index++, data.placeholder4); sqlite3_bind_double(stmt, index++, data.placeholder5); return true; } // 为disHighVolBusState特化实现 template<> bool SQLiteDB::bindParameters(sqlite3_stmt* stmt, const disHighVolBusState& data) { int index = 1; sqlite3_bind_int(stmt, index++, data.fuelCellCircuitBreaker); sqlite3_bind_int(stmt, index++, data.powerLithiumBatteryCircuitBreaker); sqlite3_bind_int(stmt, index++, data.propulsionMotorCircuitBreaker); sqlite3_bind_int(stmt, index++, data.lithiumBatteryGroupInstrumentCircuitBreaker); sqlite3_bind_int(stmt, index++, data.dcDc5ModuleCircuitBreaker); sqlite3_bind_int(stmt, index++, data.bowHighVoltageDistributionBoxCircuitBreaker); sqlite3_bind_int(stmt, index++, data.sternFTDevice45CircuitBreaker); sqlite3_bind_int(stmt, index++, data.sternRudderSwitch1CircuitBreaker); sqlite3_bind_int(stmt, index++, data.sternRudderSwitch2CircuitBreaker); sqlite3_bind_int(stmt, index++, data.fbReservedCircuitBreaker); sqlite3_bind_int(stmt, index++, data.tyzReservedCircuitBreaker); sqlite3_bind_int(stmt, index++, data.reservedCircuitBreaker); sqlite3_bind_int(stmt, index++, data.busInsulationLow); sqlite3_bind_int(stmt, index++, data.busAInsulationHigh); sqlite3_bind_int(stmt, index++, data.lostPower); sqlite3_bind_int(stmt, index++, data.lostEmerPower); sqlite3_bind_int(stmt, index++, data.powerBusVoltage); sqlite3_bind_int(stmt, index++, data.dcDc5ModuleCurrent); sqlite3_bind_int(stmt, index++, data.powerBusCurrent); sqlite3_bind_int(stmt, index++, data.busbarAVoltage); sqlite3_bind_int(stmt, index++, data.propulsionMotorControlBoxCurrent); sqlite3_bind_int(stmt, index++, data.busbarACurrent); sqlite3_bind_int(stmt, index++, data.lithiumBatteryGroupMeterCurrent); sqlite3_bind_int(stmt, index++, data.bowHighVoltageDistributionBoxCurrent); sqlite3_bind_int(stmt, index++, data.sternFTDevice45Current); sqlite3_bind_int(stmt, index++, data.tyzReservedSwitchCurrent); sqlite3_bind_int(stmt, index++, data.sternRudderSwitch1Current); sqlite3_bind_int(stmt, index++, data.reservedCurrent1); sqlite3_bind_int(stmt, index++, data.sternRudderSwitch2Current); sqlite3_bind_int(stmt, index++, data.reservedCurrent2); sqlite3_bind_int(stmt, index++, data.fbReservedSwitchCurrent); sqlite3_bind_int(stmt, index++, data.reservedCurrent3); return true; } // 为disHighAVolBusState特化实现 template<> bool SQLiteDB::bindParameters(sqlite3_stmt* stmt, const disHighAVolBusState& data) { int index = 1; sqlite3_bind_int(stmt, index++, data.bowFTDevice123CircuitBreaker); sqlite3_bind_int(stmt, index++, data.actuatorCircuitBreaker); sqlite3_bind_int(stmt, index++, data.mastSteeringGearControlBoxCircuitBreaker); sqlite3_bind_int(stmt, index++, data.xczCircuitBreaker); sqlite3_bind_int(stmt, index++, data.bowRudderControlBoxCircuitBreaker); sqlite3_bind_int(stmt, index++, data.openWaterCoverStartCylinderCircuitBreaker); sqlite3_bind_int(stmt, index++, data.instrumentPowerFailureSignal); sqlite3_bind_int(stmt, index++, data.emergencyPowerFailureSignal); sqlite3_bind_int(stmt, index++, data.waterIngressionAlarm); sqlite3_bind_int(stmt, index++, data.busbarBVoltage); sqlite3_bind_int(stmt, index++, data.busbarBCurrent); sqlite3_bind_int(stmt, index++, data.bowFTDevice123Current); sqlite3_bind_int(stmt, index++, data.actuatorCurrent); sqlite3_bind_int(stmt, index++, data.mastSteeringGearControlBoxCurrent); sqlite3_bind_int(stmt, index++, data.xczCurrent); sqlite3_bind_int(stmt, index++, data.bowRudderControlBoxCurrent); sqlite3_bind_int(stmt, index++, data.openWaterCoverStartCylinderCurrent); return true; } // 为disHighBVolBusState特化实现 template<> bool SQLiteDB::bindParameters(sqlite3_stmt* stmt, const disHighBVolBusState& data) { int index = 1; sqlite3_bind_int(stmt, index++, data.lithiumBatteryGroupInstrumentCircuitBreaker); sqlite3_bind_int(stmt, index++, data.bowLowVoltageDistributionBoxCircuitBreaker); sqlite3_bind_int(stmt, index++, data.unit4InstrumentDC48VCircuitBreaker); sqlite3_bind_int(stmt, index++, data.dcC1DCDistributionPanelCircuitBreaker); sqlite3_bind_int(stmt, index++, data.reservedCircuitBreaker1); sqlite3_bind_int(stmt, index++, data.reservedCircuitBreaker2); sqlite3_bind_int(stmt, index++, data.emergencyLithiumBatteryGroup2CircuitBreaker); sqlite3_bind_int(stmt, index++, data.instrumentPowerFailureSignal); sqlite3_bind_int(stmt, index++, data.emergencyPowerFailureSignal); sqlite3_bind_int(stmt, index++, data.instrumentBusbarInsulationLow); sqlite3_bind_int(stmt, index++, data.instrumentBusbarVoltage); sqlite3_bind_int(stmt, index++, data.bowLowVoltageDistributionBoxCurrent); sqlite3_bind_int(stmt, index++, data.dcC1InstrumentDC48VCurrent); sqlite3_bind_int(stmt, index++, data.reservedCurrent1); sqlite3_bind_int(stmt, index++, data.emergencyLithiumBatteryGroup2Current); sqlite3_bind_int(stmt, index++, data.lithiumBatteryGroupInstrumentCurrent); sqlite3_bind_int(stmt, index++, data.unit4InstrumentDC48VCurrent); sqlite3_bind_int(stmt, index++, data.reservedCurrent2); sqlite3_bind_int(stmt, index++, data.emergency2BusbarVoltage); sqlite3_bind_int(stmt, index++, data.compositeEnergyManagementSystemEmergencyDC48VCurrent); sqlite3_bind_int(stmt, index++, data.fuelCellSecuritySystemEmergencyDC48VCurrent); sqlite3_bind_int(stmt, index++, data.plcControlPowerCurrent); return true; } // 为disLowBusState特化实现 template<> bool SQLiteDB::bindParameters(sqlite3_stmt* stmt, const disLowBusState& data) { int index = 1; sqlite3_bind_int(stmt, index++, data.unit1CircuitBreaker); sqlite3_bind_int(stmt, index++, data.unit2CircuitBreaker); sqlite3_bind_int(stmt, index++, data.unit3CircuitBreaker); sqlite3_bind_int(stmt, index++, data.unit5CircuitBreaker); sqlite3_bind_int(stmt, index++, data.bowPZDeviceCircuitBreaker); sqlite3_bind_int(stmt, index++, data.reservedCircuitBreaker1); sqlite3_bind_int(stmt, index++, data.reservedCircuitBreaker2); sqlite3_bind_int(stmt, index++, data.emergencyLithiumBatteryGroup1CircuitBreaker); sqlite3_bind_int(stmt, index++, data.powerFailureSignal); sqlite3_bind_int(stmt, index++, data.waterIngressionAlarm); sqlite3_bind_int(stmt, index++, data.instrumentBusbarVoltage); sqlite3_bind_int(stmt, index++, data.instrumentBusbarCurrent); sqlite3_bind_int(stmt, index++, data.unit1Current); sqlite3_bind_int(stmt, index++, data.unit2Current); sqlite3_bind_int(stmt, index++, data.unit3Current); sqlite3_bind_int(stmt, index++, data.unit5Current); sqlite3_bind_int(stmt, index++, data.bowPZDeviceCurrent); sqlite3_bind_int(stmt, index++, data.emergencyLithiumBatteryGroup1Current); sqlite3_bind_int(stmt, index++, data.emergency1BusbarVoltage); return true; } template<> bool SQLiteDB::bindParameters(sqlite3_stmt* stmt, const ccuColCmd& data) { int index = 1; sqlite3_bind_int(stmt, index++, data.workCondition); sqlite3_bind_int(stmt, index++, data.fcuCmd); sqlite3_bind_int(stmt, index++, data.fcuPowerEfficiency); sqlite3_bind_int(stmt, index++, data.fcuInsEfficiency); sqlite3_bind_int(stmt, index++, data.insBatCmd); sqlite3_bind_int(stmt, index++, data.powerBatCmd); sqlite3_bind_int(stmt, index++, data.powerBatEfficiency); sqlite3_bind_int(stmt, index++, data.heartbeat); sqlite3_bind_int(stmt, index++, data.masterState); return true; } template<> bool SQLiteDB::bindParameters(sqlite3_stmt* stmt, const disHighVolBusCmd& data) { int index = 1; sqlite3_bind_int(stmt, index++, static_cast(data.fuelCellCircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.powerLithiumBatteryCircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.propulsionMotorCircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.lithiumBatteryGroupInstrumentCircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.dcDc5ModuleCircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.bowHighVoltageDistributionBoxCircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.sternFTDevice45CircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.sternRudderSwitch1CircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.sternRudderSwitch2CircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.fbReservedCircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.tyzReservedCircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.reservedCircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.dcdc5Module)); sqlite3_bind_int(stmt, index++, static_cast(data.inputWater)); sqlite3_bind_int(stmt, index++, static_cast(data.outputWater)); return true; } template<> bool SQLiteDB::bindParameters(sqlite3_stmt* stmt, const disHighAVolBusCmd& data) { int index = 1; sqlite3_bind_int(stmt, index++, static_cast(data.bowFTDevice123CircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.actuatorCircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.mastSteeringGearControlBoxCircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.xczCircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.bowRudderControlBoxCircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.openWaterCoverStartCylinderCircuitBreaker)); return true; } template<> bool SQLiteDB::bindParameters(sqlite3_stmt* stmt, const disHighBVolBusCmd& data) { int index = 1; sqlite3_bind_int(stmt, index++, static_cast(data.lithiumBatteryGroupInstrumentCircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.bowLowVoltageDistributionBoxCircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.unit4InstrumentDC48VCircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.dcC1DCDistributionPanelCircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.reservedCircuitBreaker1)); sqlite3_bind_int(stmt, index++, static_cast(data.reservedCircuitBreaker2)); sqlite3_bind_int(stmt, index++, static_cast(data.emergencyLithiumBatteryGroup2CircuitBreaker)); return true; } template<> bool SQLiteDB::bindParameters(sqlite3_stmt* stmt, const disLowBusCmd& data) { int index = 1; sqlite3_bind_int(stmt, index++, static_cast(data.unit1CircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.unit2CircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.unit3CircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.unit5CircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.bowPZDeviceCircuitBreaker)); sqlite3_bind_int(stmt, index++, static_cast(data.reservedCircuitBreaker1)); sqlite3_bind_int(stmt, index++, static_cast(data.reservedCircuitBreaker2)); sqlite3_bind_int(stmt, index++, static_cast(data.emergencyLithiumBatteryGroup1CircuitBreaker)); return true; } SQLiteDB::~SQLiteDB() { if (m_db) { sqlite3_close(m_db); } } bool SQLiteDB::createPowerDataTables() { if (!m_db) return false; const char* sql = "CREATE TABLE IF NOT EXISTS power_data (" "timestamp DATETIME DEFAULT (strftime('%Y-%m-%d %H:%M:%f', 'now'))," "voltage REAL NOT NULL," "current REAL NOT NULL," "power REAL NOT NULL," "temperature REAL NOT NULL," "PRIMARY KEY(timestamp, voltage, current));"; char* errMsg = nullptr; if (sqlite3_exec(m_db, sql, nullptr, nullptr, &errMsg) != SQLITE_OK) { std::cerr << "SQL error: " << errMsg << std::endl; sqlite3_free(errMsg); return false; } return true; } bool SQLiteDB::createDriversTables(string tableName) { if (!m_db) return false; string createTableSQL = "CREATE TABLE IF NOT EXISTS " + tableName + " (" "timestamp DATETIME DEFAULT (strftime('%Y-%m-%d %H:%M:%f', 'now')), " "DVL INTEGER DEFAULT 0, " "USBL INTEGER DEFAULT 0, " "bowCover1 INTEGER DEFAULT 0, " "bowCover2 INTEGER DEFAULT 0, " "bowCover3 INTEGER DEFAULT 0, " "bowCover4 INTEGER DEFAULT 0, " "bowCover5 INTEGER DEFAULT 0, " "bowCover6 INTEGER DEFAULT 0, " "bowRudderDeploy INTEGER DEFAULT 0, " "bowRudderServo1 INTEGER DEFAULT 0, " "bowRudderServo2 INTEGER DEFAULT 0, " "bowThrow INTEGER DEFAULT 0, " "bowWaterlnet1 INTEGER DEFAULT 0, " "bowWaterlnet2 INTEGER DEFAULT 0, " "bowWaterlnet3 INTEGER DEFAULT 0, " "bowWaterlnet4 INTEGER DEFAULT 0, " "bowWaterlnet5 INTEGER DEFAULT 0, " "bowWaterlnet6 INTEGER DEFAULT 0, " "bowWaterlnet7 INTEGER DEFAULT 0, " "bowWaterlnet8 INTEGER DEFAULT 0, " "buoyage INTEGER DEFAULT 0, " "buoyancyAdjust1 INTEGER DEFAULT 0, " "buoyancyAdjust2 INTEGER DEFAULT 0, " "buoyancyAdjust3 INTEGER DEFAULT 0, " "buoyancyAdjust4 INTEGER DEFAULT 0, " "buoyancyAdjust5 INTEGER DEFAULT 0, " "commMast INTEGER DEFAULT 0, " "ctd1 INTEGER DEFAULT 0, " "ctd2 INTEGER DEFAULT 0, " "depth1 INTEGER DEFAULT 0, " "depth2 INTEGER DEFAULT 0, " "depth3 INTEGER DEFAULT 0, " "electSensor INTEGER DEFAULT 0, " "forwardSonar INTEGER DEFAULT 0, " "inputWaterSensor1 INTEGER DEFAULT 0, " "inputWaterSensor2 INTEGER DEFAULT 0, " "inputWaterSensor3 INTEGER DEFAULT 0, " "ins INTEGER DEFAULT 0, " "launchControler INTEGER DEFAULT 0, " "lowFreqSonar INTEGER DEFAULT 0, " "mastLiftingServo INTEGER DEFAULT 0, " "ntp INTEGER DEFAULT 0, " "overDeep1 INTEGER DEFAULT 0, " "overDeep2 INTEGER DEFAULT 0, " "photoSensor INTEGER DEFAULT 0, " "sideSonar INTEGER DEFAULT 0, " "singleBeamSonar1 INTEGER DEFAULT 0, " "singleBeamSonar2 INTEGER DEFAULT 0, " "singleBeamSonar3 INTEGER DEFAULT 0, " "singleBeamSonar4 INTEGER DEFAULT 0, " "singleBeamSonar5 INTEGER DEFAULT 0, " "singleBeamSonar6 INTEGER DEFAULT 0, " "singleBeamSonar7 INTEGER DEFAULT 0, " "singleBeamSonar8 INTEGER DEFAULT 0, " "soundVeloc INTEGER DEFAULT 0, " "sternRudderServo1 INTEGER DEFAULT 0, " "sternRudderServo2 INTEGER DEFAULT 0, " "sternRudderServo3 INTEGER DEFAULT 0, " "sternRudderServo4 INTEGER DEFAULT 0, " "sternThrow INTEGER DEFAULT 0, " "thruster INTEGER DEFAULT 0, " "waterInject INTEGER DEFAULT 0" ");"; char* errMsg = nullptr; if (sqlite3_exec(m_db, createTableSQL.c_str(), nullptr, nullptr, &errMsg) != SQLITE_OK) { std::cerr << "SQL error: " << errMsg << std::endl; sqlite3_free(errMsg); return false; } return true; } bool SQLiteDB::createStateTables() { if (!m_db) return false; const char* sql = "CREATE TABLE IF NOT EXISTS state_data (" "id INTEGER PRIMARY KEY AUTOINCREMENT," "state_id INTEGER NOT NULL," "timestamp DATETIME DEFAULT (strftime('%Y-%m-%d %H:%M:%f', 'now'))," "state_name TEXT NOT NULL," "event TEXT NOT NULL," "event_id INTEGER NOT NULL," "fault_code INTEGER DEFAULT 0," "note TEXT NOT NULL);"; char* errMsg = nullptr; if (sqlite3_exec(m_db, sql, nullptr, nullptr, &errMsg) != SQLITE_OK) { std::cerr << "SQL error: " << errMsg << std::endl; sqlite3_free(errMsg); return false; } return true; } bool SQLiteDB::insertPowerData(const PowerData& powerData) { if (!m_db) return false; const char* sql = "INSERT INTO power_data (voltage, current, power, temperature) VALUES (?, ?, ?, ?);"; sqlite3_stmt* stmt; bool result = true; if (sqlite3_prepare_v2(m_db, sql, -1, &stmt, nullptr) == SQLITE_OK) { sqlite3_bind_double(stmt, 1, powerData.voltage); sqlite3_bind_double(stmt, 2, powerData.current); sqlite3_bind_double(stmt, 3, powerData.power); sqlite3_bind_double(stmt, 4, powerData.temperature); if (sqlite3_step(stmt) != SQLITE_DONE) { std::cerr << "Error inserting data: " << sqlite3_errmsg(m_db) << std::endl; result = false; } sqlite3_finalize(stmt); } else { std::cerr << "Error preparing statement: " << sqlite3_errmsg(m_db) << std::endl; result = false; } return result; } bool SQLiteDB::insertStateData(StateData stateData,bool filter) { if (!m_db) return false; if(filter){ StateData lastStateData; if(getStateData(lastStateData)){ if(lastStateData.state_id==stateData.state_id && lastStateData.event_id==stateData.event_id && lastStateData.fault_code==stateData.fault_code && lastStateData.note==stateData.note && lastStateData.state_name==stateData.state_name && lastStateData.event==stateData.event){ return true; } } } const char* sql = "INSERT INTO state_data (state_id, state_name, event, event_id, fault_code, note) VALUES (?, ?, ?, ?, ?, ?);"; sqlite3_stmt* stmt; if (sqlite3_prepare_v2(m_db, sql, -1, &stmt, nullptr) == SQLITE_OK) { sqlite3_bind_int(stmt, 1, stateData.state_id); sqlite3_bind_text(stmt, 2, stateData.state_name.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 3, stateData.event.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_int(stmt, 4, stateData.event_id); sqlite3_bind_int(stmt, 5, stateData.fault_code); sqlite3_bind_text(stmt, 6, stateData.note.c_str(), -1, SQLITE_TRANSIENT); if (sqlite3_step(stmt) != SQLITE_DONE) { std::cerr << "Error inserting data: " << sqlite3_errmsg(m_db) << std::endl; return false; } sqlite3_finalize(stmt); } else { std::cerr << "Error preparing statement: " << sqlite3_errmsg(m_db) << std::endl; return false; } return true; } bool SQLiteDB::getStateData(StateData &stateData) { if (!m_db) { std::cerr << "Database not initialized" << std::endl; return false; } const char* sql = "SELECT * FROM state_data ORDER BY timestamp DESC LIMIT 1;"; sqlite3_stmt* stmt = nullptr; bool result = false; try { if (sqlite3_prepare_v2(m_db, sql, -1, &stmt, nullptr) != SQLITE_OK) { throw std::runtime_error(sqlite3_errmsg(m_db)); } int stepResult = sqlite3_step(stmt); if (stepResult == SQLITE_ROW) { stateData.state_id = sqlite3_column_int(stmt, 1); const char* stateName = reinterpret_cast(sqlite3_column_text(stmt, 3)); stateData.state_name = stateName ? stateName : ""; const char* event = reinterpret_cast(sqlite3_column_text(stmt, 4)); stateData.event = event ? event : ""; stateData.event_id = sqlite3_column_int(stmt, 5); stateData.fault_code = sqlite3_column_int(stmt, 6); const char* note = reinterpret_cast(sqlite3_column_text(stmt, 7)); stateData.note = note ? note : ""; result = true; } else if (stepResult != SQLITE_DONE) { throw std::runtime_error(sqlite3_errmsg(m_db)); } } catch (const std::exception& e) { std::cerr << "Error retrieving state data: " << e.what() << std::endl; } if (stmt) { sqlite3_finalize(stmt); } return result; } bool SQLiteDB::getStateData(StateData &stateData, string &time) { if (!m_db) { std::cerr << "Database not initialized" << std::endl; return false; } const char* sql = "SELECT * FROM state_data ORDER BY timestamp DESC LIMIT 1;"; sqlite3_stmt* stmt = nullptr; bool result = false; try { if (sqlite3_prepare_v2(m_db, sql, -1, &stmt, nullptr) != SQLITE_OK) { throw std::runtime_error(sqlite3_errmsg(m_db)); } int stepResult = sqlite3_step(stmt); if (stepResult == SQLITE_ROW) { stateData.state_id = sqlite3_column_int(stmt, 1); const char* timestamp = reinterpret_cast(sqlite3_column_text(stmt, 2)); time = timestamp ? timestamp : ""; const char* stateName = reinterpret_cast(sqlite3_column_text(stmt, 3)); stateData.state_name = stateName ? stateName : ""; const char* event = reinterpret_cast(sqlite3_column_text(stmt, 4)); stateData.event = event ? event : ""; stateData.event_id = sqlite3_column_int(stmt, 5); stateData.fault_code = sqlite3_column_int(stmt, 6); const char* note = reinterpret_cast(sqlite3_column_text(stmt, 7)); stateData.note = note ? note : ""; result = true; } else if (stepResult != SQLITE_DONE) { throw std::runtime_error(sqlite3_errmsg(m_db)); } } catch (const std::exception& e) { std::cerr << "Error retrieving state data: " << e.what() << std::endl; } if (stmt) { sqlite3_finalize(stmt); } return result; } bool SQLiteDB::isDatabaseConnected(const std::string& path, const std::string& dbName) { if (!m_db) return false; // 尝试执行简单查询验证连接 const char* sql = "SELECT name FROM sqlite_master WHERE type='table';"; char* errMsg = nullptr; int rc = sqlite3_exec(m_db, sql, nullptr, nullptr, &errMsg); if (rc != SQLITE_OK) { std::cerr << "Database connection check failed: " << errMsg << std::endl; sqlite3_free(errMsg); return false; } // 检查数据库路径和名称是否匹配 std::string fullPath = path + "/" + dbName; const char* dbPath = sqlite3_db_filename(m_db, "main"); if (!dbPath || fullPath != dbPath) { std::cerr << "Database path mismatch: expected " << fullPath << ", got " << (dbPath ? dbPath : "null") << std::endl; return false; } return true; } string SQLiteDB::getDBPatch(){ return m_dbPath; } long SQLiteDB::getDatabaseSize() { if (m_dbPath.empty()) { return -1; } struct stat stat_buf; int rc = stat(m_dbPath.c_str(), &stat_buf); if (rc != 0) { return -1; } return stat_buf.st_size; } bool SQLiteDB::clearPowerData() { if (!m_db) return false; const char* sql = "DELETE FROM power_data;"; char* errMsg = nullptr; if (sqlite3_exec(m_db, sql, nullptr, nullptr, &errMsg) != SQLITE_OK) { std::cerr << "SQL error: " << errMsg << std::endl; sqlite3_free(errMsg); return false; } return true; } bool SQLiteDB::clearStateData() { if (!m_db) return false; const char* sql = "DELETE FROM state_data;"; char* errMsg = nullptr; if (sqlite3_exec(m_db, sql, nullptr, nullptr, &errMsg) != SQLITE_OK) { std::cerr << "SQL error: " << errMsg << std::endl; sqlite3_free(errMsg); return false; } return true; } bool SQLiteDB::insertDisCcuData(pmState s, bool filter) { if (!m_db) return false; // 检查是否需要过滤 if (filter) { // TODO: 实现过滤逻辑,检查是否与上一条记录相同 } // 插入ccu_state表 const char* ccuSql = "INSERT INTO ccu_state (" "currentWorkCondition, fcuState, fcuFaultLeve, powerLimit, totalPowerGeneration, " "ch4o, o2, fcuVoltage, fcuCurrent, o2Level, placeholder1, exchangerTemperature, " "fcuOutPower, fcuOutIns, fcuVoltageIns, fcuVoltagePower, fcuCurrentIns, fcuCurrentPower, " "h2Concentration1, h2Concentration2, o2Concentration1, o2Concentration2, " "ch4oConcentration1, ch4oConcentration2, backpressure1, backpressure2, flameDetection, " "fcuGZ_1L, fcuGZ_1H, fcuGZ_2L, fcuGZ_2H, fcuGZ_3L, fcuGZ_3H, insPosRelayState, " "insNegRelayState, powerPosRelayState, powerNegRelayState, insBatLimit, powerBatLimit, " "insBatSoc, powerBatSoc, insBatTotalElectricity, powerBatTotalElectricity, " "insBatCurrentElectricity, powerBatCurrentElectricity, insChargeState, powerChargeState, " "insLinkVoltage, insPackVoltage, insCurrent, insPosInsulationResistance, " "insNegInsulationResistance, powerLinkVoltage, powerPackVoltage, powerCurrent, " "powerPosInsulationResistance, powerNegInsulationResistance, insEmergencyStatusWord, " "powerEmergencyStatusWord, insAlarmIdentificationWord, powerAlarmIdentificationWord, " "insCurrentSocHold1, insCurrentSocHold2, insCurrentSocHold3, fcuCurrentToInsLimit1, " "fcuCurrentToinsLimit2, powerCurrentSocHold1, powerCurrentSocHold2, powerCurrentSocHold3, " "powerCurrentToInsLimit1, powerCurrentToinsLimit2, placeholder2, placeholder3, " "placeholder4, placeholder5) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; // 插入dis_high_vol_bus_state表 const char* bus1Sql = "INSERT INTO dis_high_vol_bus_state (" "fuelCellCircuitBreaker, powerLithiumBatteryCircuitBreaker, propulsionMotorCircuitBreaker, " "lithiumBatteryGroupInstrumentCircuitBreaker, dcDc5ModuleCircuitBreaker, " "bowHighVoltageDistributionBoxCircuitBreaker, sternFTDevice45CircuitBreaker, " "sternRudderSwitch1CircuitBreaker, sternRudderSwitch2CircuitBreaker, fbReservedCircuitBreaker, " "tyzReservedCircuitBreaker, reservedCircuitBreaker, busInsulationLow, busAInsulationHigh, " "lostPower, lostEmerPower, powerBusVoltage, dcDc5ModuleCurrent, powerBusCurrent, " "busbarAVoltage, propulsionMotorControlBoxCurrent, busbarACurrent, " "lithiumBatteryGroupMeterCurrent, bowHighVoltageDistributionBoxCurrent, " "sternFTDevice45Current, tyzReservedSwitchCurrent, sternRudderSwitch1Current, " "reservedCurrent1, sternRudderSwitch2Current, reservedCurrent2, fbReservedSwitchCurrent, " "reservedCurrent3) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " "?, ?, ?, ?, ?, ?);"; // 插入dis_high_a_vol_bus_state表 const char* bus2Sql = "INSERT INTO dis_high_a_vol_bus_state (" "bowFTDevice123CircuitBreaker, actuatorCircuitBreaker, mastSteeringGearControlBoxCircuitBreaker, " "xczCircuitBreaker, bowRudderControlBoxCircuitBreaker, openWaterCoverStartCylinderCircuitBreaker, " "instrumentPowerFailureSignal, emergencyPowerFailureSignal, waterIngressionAlarm, " "busbarBVoltage, busbarBCurrent, bowFTDevice123Current, actuatorCurrent, " "mastSteeringGearControlBoxCurrent, xczCurrent, bowRudderControlBoxCurrent, " "openWaterCoverStartCylinderCurrent) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; // 插入dis_high_b_vol_bus_state表 const char* bus3Sql = "INSERT INTO dis_high_b_vol_bus_state (" "lithiumBatteryGroupInstrumentCircuitBreaker, bowLowVoltageDistributionBoxCircuitBreaker, " "unit4InstrumentDC48VCircuitBreaker, dcC1DCDistributionPanelCircuitBreaker, " "reservedCircuitBreaker1, reservedCircuitBreaker2, emergencyLithiumBatteryGroup2CircuitBreaker, " "instrumentPowerFailureSignal, emergencyPowerFailureSignal, instrumentBusbarInsulationLow, " "instrumentBusbarVoltage, bowLowVoltageDistributionBoxCurrent, dcC1InstrumentDC48VCurrent, " "reservedCurrent1, emergencyLithiumBatteryGroup2Current, lithiumBatteryGroupInstrumentCurrent, " "unit4InstrumentDC48VCurrent, reservedCurrent2, emergency2BusbarVoltage, " "compositeEnergyManagementSystemEmergencyDC48VCurrent, fuelCellSecuritySystemEmergencyDC48VCurrent, " "plcControlPowerCurrent) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?);"; // 插入dis_low_bus_state表 const char* bus4Sql = "INSERT INTO dis_low_bus_state (" "unit1CircuitBreaker, unit2CircuitBreaker, unit3CircuitBreaker, unit5CircuitBreaker, " "bowPZDeviceCircuitBreaker, reservedCircuitBreaker1, reservedCircuitBreaker2, " "emergencyLithiumBatteryGroup1CircuitBreaker, powerFailureSignal, waterIngressionAlarm, " "instrumentBusbarVoltage, instrumentBusbarCurrent, unit1Current, unit2Current, " "unit3Current, unit5Current, bowPZDeviceCurrent, emergencyLithiumBatteryGroup1Current, " "emergency1BusbarVoltage) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; // 执行所有插入操作 bool result = true; result = result && executeInsert(ccuSql, s.ccustate); result = result && executeInsert(bus1Sql, s.bus1State); result = result && executeInsert(bus2Sql, s.bus2State); result = result && executeInsert(bus3Sql, s.bus3State); result = result && executeInsert(bus4Sql, s.bus4State); return result; } bool SQLiteDB::insertCcuSysCmd(ccuColCmd cmd) { if (!m_db) return false; // 插入ccu_sys_cmd表 const char* ccuSysCmdSql = "INSERT INTO ccu_sys_cmd (" "workCondition, fcuCmd, fcuPowerEfficiency, fcuInsEfficiency, " "insBatCmd, powerBatCmd, powerBatEfficiency, heartbeat, masterState) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);"; // 执行插入操作 bool result = executeInsert(ccuSysCmdSql, cmd); return result; } bool SQLiteDB::insertDisSysCmd(disHighVolBusCmd cmd) { if (!m_db) return false; // 插入dis_sys_cmd表,根据结构体完善SQL语句 const char* disSysCmdSql = "INSERT INTO dis_high_vol_bus_cmd (" "fuelCellCircuitBreaker, powerLithiumBatteryCircuitBreaker, propulsionMotorCircuitBreaker, " "lithiumBatteryGroupInstrumentCircuitBreaker, dcDc5ModuleCircuitBreaker, " "bowHighVoltageDistributionBoxCircuitBreaker, sternFTDevice45CircuitBreaker, " "sternRudderSwitch1CircuitBreaker, sternRudderSwitch2CircuitBreaker, " "fbReservedCircuitBreaker, tyzReservedCircuitBreaker, reservedCircuitBreaker, " "dcdc5Module, inputWater, outputWater) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; // 执行插入操作 bool result = executeInsert(disSysCmdSql, cmd); return result; } bool SQLiteDB::insertDisSysCmd(disHighAVolBusCmd cmd) { if (!m_db) return false; // 插入dis_sys_cmd表,根据结构体完善SQL语句 const char* disSysCmdSql = "INSERT INTO dis_high_a_vol_bus_cmd (" "bowFTDevice123CircuitBreaker, actuatorCircuitBreaker, mastSteeringGearControlBoxCircuitBreaker, " "xczCircuitBreaker, bowRudderControlBoxCircuitBreaker, openWaterCoverStartCylinderCircuitBreaker) " "VALUES (?, ?, ?, ?, ?, ?);"; // 执行插入操作 bool result = executeInsert(disSysCmdSql, cmd); return result; } bool SQLiteDB::insertDisSysCmd(disHighBVolBusCmd cmd) { if (!m_db) return false; // 插入dis_sys_cmd表,根据结构体完善SQL语句 const char* disSysCmdSql = "INSERT INTO dis_high_b_vol_bus_cmd (" "lithiumBatteryGroupInstrumentCircuitBreaker, " "bowLowVoltageDistributionBoxCircuitBreaker, " "unit4InstrumentDC48VCircuitBreaker, " "dcC1DCDistributionPanelCircuitBreaker, " "reservedCircuitBreaker1, " "reservedCircuitBreaker2, " "emergencyLithiumBatteryGroup2CircuitBreaker) " "VALUES (?, ?, ?, ?, ?, ?, ?);"; // 执行插入操作 bool result = executeInsert(disSysCmdSql, cmd); return result; } bool SQLiteDB::insertDisSysCmd(disLowBusCmd cmd) { if (!m_db) return false; // 插入dis_sys_cmd表,根据结构体完善SQL语句 const char* disSysCmdSql = "INSERT INTO dis_low_bus_cmd (" "unit1CircuitBreaker, unit2CircuitBreaker, unit3CircuitBreaker, unit5CircuitBreaker, " "bowPZDeviceCircuitBreaker, reservedCircuitBreaker1, reservedCircuitBreaker2, " "emergencyLithiumBatteryGroup1CircuitBreaker) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?);"; // 执行插入操作 bool result = executeInsert(disSysCmdSql, cmd); return result; } bool SQLiteDB::insertCcuData(ccuState s) { if (!m_db) return false; // 插入ccu_state表 const char* ccuSql = "INSERT INTO ccu_state (" "currentWorkCondition, fcuState, fcuFaultLeve, powerLimit, totalPowerGeneration, " "ch4o, o2, fcuVoltage, fcuCurrent, o2Level, placeholder1, exchangerTemperature, " "fcuOutPower, fcuOutIns, fcuVoltageIns, fcuVoltagePower, fcuCurrentIns, fcuCurrentPower, " "h2Concentration1, h2Concentration2, o2Concentration1, o2Concentration2, " "ch4oConcentration1, ch4oConcentration2, backpressure1, backpressure2, flameDetection, " "fcuGZ_1L, fcuGZ_1H, fcuGZ_2L, fcuGZ_2H, fcuGZ_3L, fcuGZ_3H, insPosRelayState, " "insNegRelayState, powerPosRelayState, powerNegRelayState, insBatLimit, powerBatLimit, " "insBatSoc, powerBatSoc, insBatTotalElectricity, powerBatTotalElectricity, " "insBatCurrentElectricity, powerBatCurrentElectricity, insChargeState, powerChargeState, " "insLinkVoltage, insPackVoltage, insCurrent, insPosInsulationResistance, " "insNegInsulationResistance, powerLinkVoltage, powerPackVoltage, powerCurrent, " "powerPosInsulationResistance, powerNegInsulationResistance, insEmergencyStatusWord, " "powerEmergencyStatusWord, insAlarmIdentificationWord, powerAlarmIdentificationWord, " "insCurrentSocHold1, insCurrentSocHold2, insCurrentSocHold3, fcuCurrentToInsLimit1, " "fcuCurrentToinsLimit2, powerCurrentSocHold1, powerCurrentSocHold2, powerCurrentSocHold3, " "powerCurrentToInsLimit1, powerCurrentToinsLimit2, placeholder2, placeholder3, " "placeholder4, placeholder5) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; // 执行所有插入操作 bool result = true; result = executeInsert(ccuSql, s); return result; } bool SQLiteDB::insertDisHighVolBusData(disHighVolBusState s) { if (!m_db) return false; // 插入dis_high_vol_bus_state表 const char* bus1Sql = "INSERT INTO dis_high_vol_bus_state (" "fuelCellCircuitBreaker, powerLithiumBatteryCircuitBreaker, propulsionMotorCircuitBreaker, " "lithiumBatteryGroupInstrumentCircuitBreaker, dcDc5ModuleCircuitBreaker, " "bowHighVoltageDistributionBoxCircuitBreaker, sternFTDevice45CircuitBreaker, " "sternRudderSwitch1CircuitBreaker, sternRudderSwitch2CircuitBreaker, fbReservedCircuitBreaker, " "tyzReservedCircuitBreaker, reservedCircuitBreaker, busInsulationLow, busAInsulationHigh, " "lostPower, lostEmerPower, powerBusVoltage, dcDc5ModuleCurrent, powerBusCurrent, " "busbarAVoltage, propulsionMotorControlBoxCurrent, busbarACurrent, " "lithiumBatteryGroupMeterCurrent, bowHighVoltageDistributionBoxCurrent, " "sternFTDevice45Current, tyzReservedSwitchCurrent, sternRudderSwitch1Current, " "reservedCurrent1, sternRudderSwitch2Current, reservedCurrent2, fbReservedSwitchCurrent, " "reservedCurrent3) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " "?, ?, ?, ?, ?, ?);"; // 执行所有插入操作 bool result = true; result = executeInsert(bus1Sql, s); return result; } bool SQLiteDB::insertDisHighAVolBusData(disHighAVolBusState s) { if (!m_db) return false; // 插入dis_high_a_vol_bus_state表 const char* bus2Sql = "INSERT INTO dis_high_a_vol_bus_state (" "bowFTDevice123CircuitBreaker, actuatorCircuitBreaker, mastSteeringGearControlBoxCircuitBreaker, " "xczCircuitBreaker, bowRudderControlBoxCircuitBreaker, openWaterCoverStartCylinderCircuitBreaker, " "instrumentPowerFailureSignal, emergencyPowerFailureSignal, waterIngressionAlarm, " "busbarBVoltage, busbarBCurrent, bowFTDevice123Current, actuatorCurrent, " "mastSteeringGearControlBoxCurrent, xczCurrent, bowRudderControlBoxCurrent, " "openWaterCoverStartCylinderCurrent) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; // 执行所有插入操作 bool result = true; result = executeInsert(bus2Sql, s); return result; } bool SQLiteDB::insertDisHighBVolBusData(disHighBVolBusState s) { if (!m_db) return false; const char* bus3Sql = "INSERT INTO dis_high_b_vol_bus_state (" "lithiumBatteryGroupInstrumentCircuitBreaker, bowLowVoltageDistributionBoxCircuitBreaker, " "unit4InstrumentDC48VCircuitBreaker, dcC1DCDistributionPanelCircuitBreaker, " "reservedCircuitBreaker1, reservedCircuitBreaker2, emergencyLithiumBatteryGroup2CircuitBreaker, " "instrumentPowerFailureSignal, emergencyPowerFailureSignal, instrumentBusbarInsulationLow, " "instrumentBusbarVoltage, bowLowVoltageDistributionBoxCurrent, dcC1InstrumentDC48VCurrent, " "reservedCurrent1, emergencyLithiumBatteryGroup2Current, lithiumBatteryGroupInstrumentCurrent, " "unit4InstrumentDC48VCurrent, reservedCurrent2, emergency2BusbarVoltage, " "compositeEnergyManagementSystemEmergencyDC48VCurrent, fuelCellSecuritySystemEmergencyDC48VCurrent, " "plcControlPowerCurrent) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?);"; // 执行所有插入操作 bool result = true; result = executeInsert(bus3Sql, s); return result; } bool SQLiteDB::insertDisLowBusData(disLowBusState s) { if (!m_db) return false; // 插入dis_low_bus_state表 const char* bus4Sql = "INSERT INTO dis_low_bus_state (" "unit1CircuitBreaker, unit2CircuitBreaker, unit3CircuitBreaker, unit5CircuitBreaker, " "bowPZDeviceCircuitBreaker, reservedCircuitBreaker1, reservedCircuitBreaker2, " "emergencyLithiumBatteryGroup1CircuitBreaker, powerFailureSignal, waterIngressionAlarm, " "instrumentBusbarVoltage, instrumentBusbarCurrent, unit1Current, unit2Current, " "unit3Current, unit5Current, bowPZDeviceCurrent, emergencyLithiumBatteryGroup1Current, " "emergency1BusbarVoltage) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; // 执行所有插入操作 bool result = true; result = executeInsert(bus4Sql, s); return result; } bool SQLiteDB::insertDriverTables(DriverTable driverTable,string tableName) { if (!m_db) return false; // 构建插入语句 std::string insertSql = "INSERT INTO " + tableName + " (" "depth1, depth2, depth3, overDeep1, overDeep2, ctd1, ctd2, soundVeloc, commMast, ins, ntp, " "inputWaterSensor1, inputWaterSensor2, inputWaterSensor3, " "singleBeamSonar1, singleBeamSonar2, singleBeamSonar3, singleBeamSonar4, singleBeamSonar5, " "singleBeamSonar6, singleBeamSonar7, singleBeamSonar8, forwardSonar, DVL, lowFreqSonar, USBL, " "bowWaterlnet1, bowWaterlnet2, bowWaterlnet3, bowWaterlnet4, bowWaterlnet5, bowWaterlnet6, " "bowWaterlnet7, bowWaterlnet8, bowRudderDeploy, bowRudderServo1, bowRudderServo2, " "bowCover1, bowCover2, bowCover3, bowCover4, bowCover5, bowCover6, waterInject, " "mastLiftingServo, buoyancyAdjust1, buoyancyAdjust2, buoyancyAdjust3, buoyancyAdjust4, " "buoyancyAdjust5, sternRudderServo1, sternRudderServo2, sternRudderServo3, sternRudderServo4, " "thruster, bowThrow, sternThrow, " "photoSensor, electSensor, launchControler, sideSonar, buoyage) " "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " "?, ?, ?, ?, ?, ?, ?, ?);"; // 执行插入操作 bool result = executeInsert(insertSql.c_str(), driverTable); return result; } template bool SQLiteDB::executeInsert(const char* sql, const T& data) { sqlite3_stmt* stmt; if (sqlite3_prepare_v2(m_db, sql, -1, &stmt, nullptr) != SQLITE_OK) { std::cerr << "Error preparing statement: " << sqlite3_errmsg(m_db) << std::endl; return false; } // 绑定参数 if (!bindParameters(stmt, data)) { sqlite3_finalize(stmt); return false; } if (sqlite3_step(stmt) != SQLITE_DONE) { std::cerr << "Error inserting data: " << sqlite3_errmsg(m_db) << std::endl; sqlite3_finalize(stmt); return false; } sqlite3_finalize(stmt); return true; } bool SQLiteDB::createDisCcuSysTables() { if (!m_db) return false; // 创建ccu_state表 const char* ccuStateSql = "CREATE TABLE IF NOT EXISTS ccu_state (" "timestamp DATETIME DEFAULT (strftime('%Y-%m-%d %H:%M:%f', 'now'))," "currentWorkCondition INTEGER NOT NULL," "fcuState INTEGER NOT NULL," "fcuFaultLeve INTEGER NOT NULL," "powerLimit REAL NOT NULL," "totalPowerGeneration REAL NOT NULL," "ch4o REAL NOT NULL," "o2 REAL NOT NULL," "fcuVoltage REAL NOT NULL," "fcuCurrent REAL NOT NULL," "o2Level REAL NOT NULL," "placeholder1 REAL NOT NULL," "exchangerTemperature REAL NOT NULL," "fcuOutPower REAL NOT NULL," "fcuOutIns REAL NOT NULL," "fcuVoltageIns REAL NOT NULL," "fcuVoltagePower REAL NOT NULL," "fcuCurrentIns REAL NOT NULL," "fcuCurrentPower REAL NOT NULL," "h2Concentration1 REAL NOT NULL," "h2Concentration2 REAL NOT NULL," "o2Concentration1 REAL NOT NULL," "o2Concentration2 REAL NOT NULL," "ch4oConcentration1 REAL NOT NULL," "ch4oConcentration2 REAL NOT NULL," "backpressure1 REAL NOT NULL," "backpressure2 REAL NOT NULL," "flameDetection INTEGER NOT NULL," "fcuGZ_1L INTEGER NOT NULL," "fcuGZ_1H INTEGER NOT NULL," "fcuGZ_2L INTEGER NOT NULL," "fcuGZ_2H INTEGER NOT NULL," "fcuGZ_3L INTEGER NOT NULL," "fcuGZ_3H INTEGER NOT NULL," "insPosRelayState INTEGER NOT NULL," "insNegRelayState INTEGER NOT NULL," "powerPosRelayState INTEGER NOT NULL," "powerNegRelayState INTEGER NOT NULL," "insBatLimit INTEGER NOT NULL," "powerBatLimit INTEGER NOT NULL," "insBatSoc INTEGER NOT NULL," "powerBatSoc INTEGER NOT NULL," "insBatTotalElectricity INTEGER NOT NULL," "powerBatTotalElectricity INTEGER NOT NULL," "insBatCurrentElectricity INTEGER NOT NULL," "powerBatCurrentElectricity INTEGER NOT NULL," "insChargeState INTEGER NOT NULL," "powerChargeState INTEGER NOT NULL," "insLinkVoltage INTEGER NOT NULL," "insPackVoltage INTEGER NOT NULL," "insCurrent INTEGER NOT NULL," "insPosInsulationResistance INTEGER NOT NULL," "insNegInsulationResistance INTEGER NOT NULL," "powerLinkVoltage INTEGER NOT NULL," "powerPackVoltage INTEGER NOT NULL," "powerCurrent INTEGER NOT NULL," "powerPosInsulationResistance INTEGER NOT NULL," "powerNegInsulationResistance INTEGER NOT NULL," "insEmergencyStatusWord INTEGER NOT NULL," "powerEmergencyStatusWord INTEGER NOT NULL," "insAlarmIdentificationWord INTEGER NOT NULL," "powerAlarmIdentificationWord INTEGER NOT NULL," "insCurrentSocHold1 INTEGER NOT NULL," "insCurrentSocHold2 INTEGER NOT NULL," "insCurrentSocHold3 INTEGER NOT NULL," "fcuCurrentToInsLimit1 INTEGER NOT NULL," "fcuCurrentToinsLimit2 INTEGER NOT NULL," "powerCurrentSocHold1 INTEGER NOT NULL," "powerCurrentSocHold2 INTEGER NOT NULL," "powerCurrentSocHold3 INTEGER NOT NULL," "powerCurrentToInsLimit1 INTEGER NOT NULL," "powerCurrentToinsLimit2 INTEGER NOT NULL," "placeholder2 REAL NOT NULL," "placeholder3 REAL NOT NULL," "placeholder4 REAL NOT NULL," "placeholder5 REAL NOT NULL);"; // 创建dis_high_vol_bus_state表 const char* disHighVolBusStateSql = "CREATE TABLE IF NOT EXISTS dis_high_vol_bus_state (" "timestamp DATETIME DEFAULT (strftime('%Y-%m-%d %H:%M:%f', 'now'))," "fuelCellCircuitBreaker INTEGER NOT NULL," "powerLithiumBatteryCircuitBreaker INTEGER NOT NULL," "propulsionMotorCircuitBreaker INTEGER NOT NULL," "lithiumBatteryGroupInstrumentCircuitBreaker INTEGER NOT NULL," "dcDc5ModuleCircuitBreaker INTEGER NOT NULL," "bowHighVoltageDistributionBoxCircuitBreaker INTEGER NOT NULL," "sternFTDevice45CircuitBreaker INTEGER NOT NULL," "sternRudderSwitch1CircuitBreaker INTEGER NOT NULL," "sternRudderSwitch2CircuitBreaker INTEGER NOT NULL," "fbReservedCircuitBreaker INTEGER NOT NULL," "tyzReservedCircuitBreaker INTEGER NOT NULL," "reservedCircuitBreaker INTEGER NOT NULL," "busInsulationLow INTEGER NOT NULL," "busAInsulationHigh INTEGER NOT NULL," "lostPower INTEGER NOT NULL," "lostEmerPower INTEGER NOT NULL," "powerBusVoltage INTEGER NOT NULL," "dcDc5ModuleCurrent INTEGER NOT NULL," "powerBusCurrent INTEGER NOT NULL," "busbarAVoltage INTEGER NOT NULL," "propulsionMotorControlBoxCurrent INTEGER NOT NULL," "busbarACurrent INTEGER NOT NULL," "lithiumBatteryGroupMeterCurrent INTEGER NOT NULL," "bowHighVoltageDistributionBoxCurrent INTEGER NOT NULL," "sternFTDevice45Current INTEGER NOT NULL," "tyzReservedSwitchCurrent INTEGER NOT NULL," "sternRudderSwitch1Current INTEGER NOT NULL," "reservedCurrent1 INTEGER NOT NULL," "sternRudderSwitch2Current INTEGER NOT NULL," "reservedCurrent2 INTEGER NOT NULL," "fbReservedSwitchCurrent INTEGER NOT NULL," "reservedCurrent3 INTEGER NOT NULL);"; // 创建dis_high_a_vol_bus_state表 const char* disHighAVolBusStateSql = "CREATE TABLE IF NOT EXISTS dis_high_a_vol_bus_state (" "timestamp DATETIME DEFAULT (strftime('%Y-%m-%d %H:%M:%f', 'now'))," "bowFTDevice123CircuitBreaker INTEGER NOT NULL," "actuatorCircuitBreaker INTEGER NOT NULL," "mastSteeringGearControlBoxCircuitBreaker INTEGER NOT NULL," "xczCircuitBreaker INTEGER NOT NULL," "bowRudderControlBoxCircuitBreaker INTEGER NOT NULL," "openWaterCoverStartCylinderCircuitBreaker INTEGER NOT NULL," "instrumentPowerFailureSignal INTEGER NOT NULL," "emergencyPowerFailureSignal INTEGER NOT NULL," "waterIngressionAlarm INTEGER NOT NULL," "busbarBVoltage INTEGER NOT NULL," "busbarBCurrent INTEGER NOT NULL," "bowFTDevice123Current INTEGER NOT NULL," "actuatorCurrent INTEGER NOT NULL," "mastSteeringGearControlBoxCurrent INTEGER NOT NULL," "xczCurrent INTEGER NOT NULL," "bowRudderControlBoxCurrent INTEGER NOT NULL," "openWaterCoverStartCylinderCurrent INTEGER NOT NULL);"; // 创建dis_high_b_vol_bus_state表 const char* disHighBVolBusStateSql = "CREATE TABLE IF NOT EXISTS dis_high_b_vol_bus_state (" "timestamp DATETIME DEFAULT (strftime('%Y-%m-%d %H:%M:%f', 'now'))," "lithiumBatteryGroupInstrumentCircuitBreaker INTEGER NOT NULL," "bowLowVoltageDistributionBoxCircuitBreaker INTEGER NOT NULL," "unit4InstrumentDC48VCircuitBreaker INTEGER NOT NULL," "dcC1DCDistributionPanelCircuitBreaker INTEGER NOT NULL," "reservedCircuitBreaker1 INTEGER NOT NULL," "reservedCircuitBreaker2 INTEGER NOT NULL," "emergencyLithiumBatteryGroup2CircuitBreaker INTEGER NOT NULL," "instrumentPowerFailureSignal INTEGER NOT NULL," "emergencyPowerFailureSignal INTEGER NOT NULL," "instrumentBusbarInsulationLow INTEGER NOT NULL," "instrumentBusbarVoltage INTEGER NOT NULL," "bowLowVoltageDistributionBoxCurrent INTEGER NOT NULL," "dcC1InstrumentDC48VCurrent INTEGER NOT NULL," "reservedCurrent1 INTEGER NOT NULL," "emergencyLithiumBatteryGroup2Current INTEGER NOT NULL," "lithiumBatteryGroupInstrumentCurrent INTEGER NOT NULL," "unit4InstrumentDC48VCurrent INTEGER NOT NULL," "reservedCurrent2 INTEGER NOT NULL," "emergency2BusbarVoltage INTEGER NOT NULL," "compositeEnergyManagementSystemEmergencyDC48VCurrent INTEGER NOT NULL," "fuelCellSecuritySystemEmergencyDC48VCurrent INTEGER NOT NULL," "plcControlPowerCurrent INTEGER NOT NULL);"; // 创建dis_low_bus_state表 const char* disLowBusStateSql = "CREATE TABLE IF NOT EXISTS dis_low_bus_state (" "timestamp DATETIME DEFAULT (strftime('%Y-%m-%d %H:%M:%f', 'now'))," "unit1CircuitBreaker INTEGER NOT NULL," "unit2CircuitBreaker INTEGER NOT NULL," "unit3CircuitBreaker INTEGER NOT NULL," "unit5CircuitBreaker INTEGER NOT NULL," "bowPZDeviceCircuitBreaker INTEGER NOT NULL," "reservedCircuitBreaker1 INTEGER NOT NULL," "reservedCircuitBreaker2 INTEGER NOT NULL," "emergencyLithiumBatteryGroup1CircuitBreaker INTEGER NOT NULL," "powerFailureSignal INTEGER NOT NULL," "waterIngressionAlarm INTEGER NOT NULL," "instrumentBusbarVoltage INTEGER NOT NULL," "instrumentBusbarCurrent INTEGER NOT NULL," "unit1Current INTEGER NOT NULL," "unit2Current INTEGER NOT NULL," "unit3Current INTEGER NOT NULL," "unit5Current INTEGER NOT NULL," "bowPZDeviceCurrent INTEGER NOT NULL," "emergencyLithiumBatteryGroup1Current INTEGER NOT NULL," "emergency1BusbarVoltage INTEGER NOT NULL);"; // 创建ccu命令表 const char* ccuCmdSql = "CREATE TABLE IF NOT EXISTS ccu_sys_cmd (" "timestamp DATETIME DEFAULT (strftime('%Y-%m-%d %H:%M:%f', 'now'))," "workCondition INTEGER NOT NULL," "fcuCmd INTEGER NOT NULL," "fcuPowerEfficiency INTEGER NOT NULL," "fcuInsEfficiency INTEGER NOT NULL," "insBatCmd INTEGER NOT NULL," "powerBatCmd INTEGER NOT NULL," "powerBatEfficiency INTEGER NOT NULL," "heartbeat INTEGER NOT NULL," "masterState INTEGER NOT NULL);"; // 创建dis命令表 const char* disHighVolBusCmdSql = "CREATE TABLE IF NOT EXISTS dis_high_vol_bus_cmd (" "timestamp DATETIME DEFAULT (strftime('%Y-%m-%d %H:%M:%f', 'now'))," "fuelCellCircuitBreaker INTEGER NOT NULL," "powerLithiumBatteryCircuitBreaker INTEGER NOT NULL," "propulsionMotorCircuitBreaker INTEGER NOT NULL," "lithiumBatteryGroupInstrumentCircuitBreaker INTEGER NOT NULL," "dcDc5ModuleCircuitBreaker INTEGER NOT NULL," "bowHighVoltageDistributionBoxCircuitBreaker INTEGER NOT NULL," "sternFTDevice45CircuitBreaker INTEGER NOT NULL," "sternRudderSwitch1CircuitBreaker INTEGER NOT NULL," "sternRudderSwitch2CircuitBreaker INTEGER NOT NULL," "fbReservedCircuitBreaker INTEGER NOT NULL," "tyzReservedCircuitBreaker INTEGER NOT NULL," "reservedCircuitBreaker INTEGER NOT NULL," "dcdc5Module INTEGER NOT NULL," "inputWater INTEGER NOT NULL," "outputWater INTEGER NOT NULL);"; const char* disHighAVolBusCmdSql = "CREATE TABLE IF NOT EXISTS dis_high_a_vol_bus_cmd (" "timestamp DATETIME DEFAULT (strftime('%Y-%m-%d %H:%M:%f', 'now'))," "bowFTDevice123CircuitBreaker INTEGER NOT NULL," "actuatorCircuitBreaker INTEGER NOT NULL," "mastSteeringGearControlBoxCircuitBreaker INTEGER NOT NULL," "xczCircuitBreaker INTEGER NOT NULL," "bowRudderControlBoxCircuitBreaker INTEGER NOT NULL," "openWaterCoverStartCylinderCircuitBreaker INTEGER NOT NULL);"; const char* disHighBVolBusCmdSql = "CREATE TABLE IF NOT EXISTS dis_high_b_vol_bus_cmd (" "timestamp DATETIME DEFAULT (strftime('%Y-%m-%d %H:%M:%f', 'now'))," "lithiumBatteryGroupInstrumentCircuitBreaker INTEGER NOT NULL," "bowLowVoltageDistributionBoxCircuitBreaker INTEGER NOT NULL," "unit4InstrumentDC48VCircuitBreaker INTEGER NOT NULL," "dcC1DCDistributionPanelCircuitBreaker INTEGER NOT NULL," "reservedCircuitBreaker1 INTEGER NOT NULL," "reservedCircuitBreaker2 INTEGER NOT NULL," "emergencyLithiumBatteryGroup2CircuitBreaker INTEGER NOT NULL);"; const char* disLowBusCmdSql = "CREATE TABLE IF NOT EXISTS dis_low_bus_cmd (" "timestamp DATETIME DEFAULT (strftime('%Y-%m-%d %H:%M:%f', 'now'))," "unit1CircuitBreaker INTEGER NOT NULL," "unit2CircuitBreaker INTEGER NOT NULL," "unit3CircuitBreaker INTEGER NOT NULL," "unit5CircuitBreaker INTEGER NOT NULL," "bowPZDeviceCircuitBreaker INTEGER NOT NULL," "reservedCircuitBreaker1 INTEGER NOT NULL," "reservedCircuitBreaker2 INTEGER NOT NULL," "emergencyLithiumBatteryGroup1CircuitBreaker INTEGER NOT NULL);"; char* errMsg = nullptr; bool result = true; // 执行所有表创建语句 if (sqlite3_exec(m_db, ccuStateSql, nullptr, nullptr, &errMsg) != SQLITE_OK) { std::cerr << "SQL error creating ccu_state table: " << errMsg << std::endl; sqlite3_free(errMsg); result = false; } if (sqlite3_exec(m_db, disHighVolBusStateSql, nullptr, nullptr, &errMsg) != SQLITE_OK) { std::cerr << "SQL error creating dis_high_vol_bus_state table: " << errMsg << std::endl; sqlite3_free(errMsg); result = false; } if (sqlite3_exec(m_db, disHighAVolBusStateSql, nullptr, nullptr, &errMsg) != SQLITE_OK) { std::cerr << "SQL error creating dis_high_a_vol_bus_state table: " << errMsg << std::endl; sqlite3_free(errMsg); result = false; } if (sqlite3_exec(m_db, disHighBVolBusStateSql, nullptr, nullptr, &errMsg) != SQLITE_OK) { std::cerr << "SQL error creating dis_high_b_vol_bus_state table: " << errMsg << std::endl; sqlite3_free(errMsg); result = false; } if (sqlite3_exec(m_db, disLowBusStateSql, nullptr, nullptr, &errMsg) != SQLITE_OK) { std::cerr << "SQL error creating dis_low_bus_state table: " << errMsg << std::endl; sqlite3_free(errMsg); result = false; } if (sqlite3_exec(m_db, ccuCmdSql, nullptr, nullptr, &errMsg)!= SQLITE_OK) { std::cerr << "SQL error creating ccu_cmd table: " << errMsg << std::endl; sqlite3_free(errMsg); result = false; } if (sqlite3_exec(m_db, disHighVolBusCmdSql, nullptr, nullptr, &errMsg)!= SQLITE_OK) { std::cerr << "SQL error creating dis_high_vol_bus_cmd table: " << errMsg << std::endl; sqlite3_free(errMsg); result = false; } if (sqlite3_exec(m_db, disHighAVolBusCmdSql, nullptr, nullptr, &errMsg)!= SQLITE_OK) { std::cerr << "SQL error creating dis_high_a_vol_bus_cmd table: " << errMsg << std::endl; sqlite3_free(errMsg); result = false; } if (sqlite3_exec(m_db, disHighBVolBusCmdSql, nullptr, nullptr, &errMsg)!= SQLITE_OK) { std::cerr << "SQL error creating dis_high_b_vol_bus_cmd table: " << errMsg << std::endl; sqlite3_free(errMsg); result = false; } if (sqlite3_exec(m_db, disLowBusCmdSql, nullptr, nullptr, &errMsg)!= SQLITE_OK) { std::cerr << "SQL error creating dis_low_bus_cmd table: " << errMsg << std::endl; sqlite3_free(errMsg); result = false; } return result; }