完善了数据库功能,将udp单独编译为一个静态库

This commit is contained in:
zjk
2025-02-13 22:00:15 +08:00
parent 25b4e0d688
commit 6d00ecfbf2
11 changed files with 265 additions and 172 deletions
+17 -11
View File
@@ -5,11 +5,9 @@
#include <string>
#include <vector>
#include "json/json.h"
// #include <nlohmann/json.hpp>
using namespace std;
struct PowerData {
std::string timestamp;
double voltage;
double current;
double power;
@@ -17,12 +15,12 @@ struct PowerData {
};
struct StateData {
std::string timestamp;
int state_id;
std::string state_name;
std::string event;
int event_id;
int fault_code;
std::string note;
};
class SQLiteDB {
@@ -30,21 +28,29 @@ public:
SQLiteDB(const std::string& dbPath);
~SQLiteDB();
void createPowerDataTables();
void insertPowerData(float voltage, float current, float power, float temperature);
void createStateTables();
void insertStateData(StateData stateData);
bool createPowerDataTables();
bool createStateTables();
bool clearPowerData();
bool clearStateData();
bool insertPowerData(const PowerData& powerData);
bool insertStateData(StateData stateData,bool filter=true);
// 获取最新的状态数据
bool getStateData(StateData &stateData);
// 使用函数
bool isDatabaseConnected(const std::string& path, const std::string& dbName);
std::vector<PowerData> getPowerData(int limit = 100);
//使用函数
bool isDatabaseConnected(const std::string& path, const std::string& dbName);
//获取数据库状态函数
// 获取数据库状态函数
string getDBPatch();
private:
sqlite3* m_db;
string m_dbPath;
};
#endif // SQLITEDB_H