92 lines
2.2 KiB
C++
92 lines
2.2 KiB
C++
#ifndef SQLITEDB_H
|
|
#define SQLITEDB_H
|
|
|
|
#include <sqlite3.h>
|
|
#include <string>
|
|
#include <vector>
|
|
#include "json/json.h"
|
|
#include "ccuUdpMsg.h"
|
|
#include "pmSysvariable.h"
|
|
#include "driver.h"
|
|
|
|
|
|
using namespace std;
|
|
struct PowerData {
|
|
double voltage;
|
|
double current;
|
|
double power;
|
|
double temperature;
|
|
};
|
|
|
|
struct StateData {
|
|
int state_id;
|
|
std::string state_name;
|
|
std::string event;
|
|
int event_id;
|
|
int fault_code;
|
|
std::string note;
|
|
};
|
|
|
|
class SQLiteDB {
|
|
public:
|
|
SQLiteDB(const std::string& dbPath);
|
|
~SQLiteDB();
|
|
|
|
// 模板函数声明
|
|
template<typename T>
|
|
bool executeInsert(const char* sql, const T& data);
|
|
|
|
template<typename T>
|
|
bool bindParameters(sqlite3_stmt* stmt, const T& data);
|
|
// 数据库操作函数
|
|
bool createPowerDataTables();
|
|
bool createStateTables();
|
|
bool createDisCcuSysTables();
|
|
bool createDriversTables(string tableName);
|
|
|
|
bool clearPowerData();
|
|
bool clearStateData();
|
|
|
|
// 插入数据函数
|
|
bool insertPowerData(const PowerData& powerData);
|
|
bool insertStateData(StateData stateData,bool filter=true);
|
|
|
|
|
|
bool insertCcuData(ccuState s);
|
|
bool insertDisHighVolBusData(disHighVolBusState s);
|
|
bool insertDisHighAVolBusData(disHighAVolBusState s);
|
|
bool insertDisHighBVolBusData(disHighBVolBusState s);
|
|
bool insertDisLowBusData(disLowBusState s);
|
|
|
|
bool insertCcuSysCmd(ccuColCmd cmd);
|
|
bool insertDisSysCmd(disHighVolBusCmd cmd);
|
|
bool insertDisSysCmd(disHighAVolBusCmd cmd);
|
|
bool insertDisSysCmd(disHighBVolBusCmd cmd);
|
|
bool insertDisSysCmd(disLowBusCmd cmd);
|
|
|
|
bool insertDriverTables(DriverTable driverTable,string tableName);
|
|
|
|
bool insertDisCcuData(pmState s,bool filter=true);//由于信息同步原因,暂时不使用该函数
|
|
|
|
// 获取最新的状态数据
|
|
bool getStateData(StateData &stateData);
|
|
bool getStateData(StateData &stateData,string &time);
|
|
|
|
// 使用函数
|
|
bool isDatabaseConnected(const std::string& path, const std::string& dbName);
|
|
std::vector<PowerData> getPowerData(int limit = 100);
|
|
|
|
// 获取数据库状态函数
|
|
string getDBPatch();
|
|
|
|
// 获取数据库大小
|
|
long getDatabaseSize();
|
|
|
|
private:
|
|
sqlite3* m_db;
|
|
string m_dbPath;
|
|
|
|
};
|
|
|
|
#endif // SQLITEDB_H
|