modify log info.
This commit is contained in:
parent
98f07e1def
commit
60b52a5810
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ debug/*
|
||||
.cproject
|
||||
.vscode/
|
||||
Cidn-SH
|
||||
/Release/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -408,8 +408,6 @@ int getDiskInfo(char* diskTotal, char* diskFree);
|
||||
|
||||
unsigned short cal_chksum(unsigned short* addr, int len);
|
||||
|
||||
int socketHeart(const char* pSendData);
|
||||
|
||||
int Ping(const char* ips, int timeout);
|
||||
int get_netlink_status(const char* if_name);
|
||||
int compareVersions(const std::string& version1, const std::string& version2);
|
||||
|
||||
@ -35,7 +35,8 @@ SqliteDB::~SqliteDB() {}
|
||||
void SqliteDB::SqliteInit(const char *pDbName) {
|
||||
char sql_exec[2048];
|
||||
|
||||
//创建传感器信息存储表
|
||||
// 创建传感器信息存储表
|
||||
// clang-format off
|
||||
memset(sql_exec, 0, 2048);
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);",
|
||||
T_SENSOR_INFO(TNAME),
|
||||
@ -83,6 +84,7 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
||||
"UpdateFlag",
|
||||
"LooseValue",
|
||||
"batteryPower");
|
||||
// clang-format on
|
||||
CreateTable(sql_exec);
|
||||
|
||||
int iRet = GetTableRows(" sqlite_master "," name = 't_sensor_info' and sql LIKE '%LooseValue%' ");
|
||||
@ -125,8 +127,9 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
||||
sprintf(sql_exec,"update t_sensor_info set upgradeStatus = '0' where upgradeStatus = '' ;");
|
||||
UpdateTableData(sql_exec);
|
||||
|
||||
//创建传感器数据存储表
|
||||
// 创建传感器数据存储表
|
||||
memset(sql_exec, 0, 2048);
|
||||
// clang-format off
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s integer,%s,%s,%s);",
|
||||
T_DATA_INFO(TNAME),
|
||||
T_DATA_INFO(DATANODENO),
|
||||
@ -149,6 +152,7 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
||||
T_DATA_INFO(TIMESTAMP),
|
||||
T_DATA_INFO(SENDMSG),
|
||||
T_DATA_INFO(NODERESEND));
|
||||
// clang-format on
|
||||
CreateTable(sql_exec);
|
||||
|
||||
iRet = GetTableRows(" sqlite_master "," name = 't_data_info' and sql LIKE '%nodeResend%' ");
|
||||
@ -156,7 +160,7 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
||||
CreateTable("ALTER TABLE t_data_info ADD COLUMN 'nodeResend'");
|
||||
}
|
||||
|
||||
//创建传感器静态数据存储表
|
||||
// 创建传感器静态数据存储表
|
||||
memset(sql_exec, 0, 2048);
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s integer,%s,%s,%s);",
|
||||
T_DATASTATIC_INFO(TNAME),
|
||||
@ -178,6 +182,7 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
||||
}
|
||||
|
||||
memset(sql_exec, 0, 2048);
|
||||
// clang-format off
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);",
|
||||
T_GATEWAY_INFO(TNAME),
|
||||
T_GATEWAY_INFO(GATEWAYMAC),
|
||||
@ -196,6 +201,7 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
||||
T_GATEWAY_INFO(STATUS),
|
||||
T_GATEWAY_INFO(GATEWAYUPDATE),
|
||||
T_GATEWAY_INFO(MAC2));
|
||||
// clang-format on
|
||||
CreateTable(sql_exec);
|
||||
|
||||
memset(sql_exec, 0, 2048);
|
||||
@ -217,6 +223,7 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
||||
}
|
||||
|
||||
memset(sql_exec, 0, 2048);
|
||||
// clang-format off
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s,%s);",
|
||||
T_BATTERY_INFO(TNAME),
|
||||
T_BATTERY_INFO(DATANODENO),
|
||||
@ -228,9 +235,11 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
||||
T_BATTERY_INFO(BATTERYUSAGE),
|
||||
T_BATTERY_INFO(BATTERYREMAIN),
|
||||
T_BATTERY_INFO(TIMESTAMP));
|
||||
// clang-format on
|
||||
CreateTable(sql_exec);
|
||||
|
||||
memset(sql_exec, 0, 2048);
|
||||
// clang-format off
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s,%s);",
|
||||
"t_battery_history",
|
||||
T_BATTERY_INFO(DATANODENO),
|
||||
@ -242,6 +251,7 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
||||
T_BATTERY_INFO(BATTERYUSAGE),
|
||||
T_BATTERY_INFO(BATTERYREMAIN),
|
||||
T_BATTERY_INFO(TIMESTAMP));
|
||||
// clang-format on
|
||||
CreateTable(sql_exec);
|
||||
|
||||
execute_sql_file("/opt/configenv/firmware_upgrade.sql");
|
||||
@ -251,7 +261,7 @@ void SqliteDB::SqliteInit(const char *pDbName) {
|
||||
|
||||
void SqliteDB::Createtable(const char *ptableName) {
|
||||
char sql_exec[2048];
|
||||
//创建传感器数据存储表
|
||||
// 创建传感器数据存储表
|
||||
memset(sql_exec, 0, 2048);
|
||||
sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s integer,%s,%s,%s);", ptableName, T_DATA_INFO(DATANODENO), T_DATA_INFO(CHANNELID), T_DATA_INFO(DIAGNOSISEAK), T_DATA_INFO(INTEGRATPK), T_DATA_INFO(INTEGRATRMS),
|
||||
T_DATA_INFO(RMSVALUES), T_DATA_INFO(ENVELOPNERGY), T_DATA_INFO(AMP1), T_DATA_INFO(AMP2), T_DATA_INFO(AMP3), T_DATA_INFO(AMP4), T_DATA_INFO(AMP5), T_DATA_INFO(PHASE1), T_DATA_INFO(PHASE2), T_DATA_INFO(PHASE3), T_DATA_INFO(PHASE4), "StaticIndex", T_DATA_INFO(TIMESTAMP),
|
||||
@ -446,6 +456,7 @@ std::string SqliteDB::GetData(const char *tablename, const char *column, const c
|
||||
mtx_.unlock();
|
||||
return strRes;
|
||||
}
|
||||
|
||||
array_t SqliteDB::GetDataMultiLine(const char *sql){
|
||||
array_t arrResult;
|
||||
zlog_info(zct, "[GetDataMultiLine] sql:%s", sql);
|
||||
@ -473,6 +484,7 @@ array_t SqliteDB::GetDataMultiLine(const char *sql){
|
||||
mtx_.unlock();
|
||||
return arrResult;
|
||||
}
|
||||
|
||||
array_t SqliteDB::GetDataMultiLine(const char *tablename, const char *column, const char *whereCon) {
|
||||
array_t arrResult;
|
||||
std::string strSql = "select ";
|
||||
@ -705,6 +717,7 @@ int SqliteDB::UpdateTableDataOneColumn(const char *tablename, const char *column
|
||||
}
|
||||
return iRet;
|
||||
}
|
||||
|
||||
int callback(void *data, int argc, char **argv, char **azColName) {
|
||||
// 如果需要处理查询结果,可以在此回调函数中进行操作
|
||||
for (int i = 0; i < argc; i++) {
|
||||
@ -716,7 +729,7 @@ int callback(void *data, int argc, char **argv, char **azColName) {
|
||||
int SqliteDB::execute_sql_file(const char *filename) {
|
||||
FILE *file = fopen(filename, "r");
|
||||
if (file == NULL) {
|
||||
zlog_error(zct,"无法打开 SQL 文件");
|
||||
zlog_error(zct, "can not open sql file:%s", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -728,7 +741,7 @@ int SqliteDB::execute_sql_file(const char *filename) {
|
||||
// 为文件内容分配内存
|
||||
char *sql = (char *)malloc(file_size + 1);
|
||||
if (sql == NULL) {
|
||||
zlog_error(zct,"内存分配失败");
|
||||
zlog_error(zct, "fail to malloc size:%ld", file_size + 1);
|
||||
fclose(file);
|
||||
return 2;
|
||||
}
|
||||
@ -742,7 +755,7 @@ int SqliteDB::execute_sql_file(const char *filename) {
|
||||
// 执行 SQL 文件中的语句
|
||||
char *err_msg = NULL;
|
||||
if (sqlite3_exec(GetDbHandle(), sql, callback, 0, &err_msg) != SQLITE_OK) {
|
||||
zlog_error(zct, "执行 SQL 错误: %s", err_msg);
|
||||
zlog_error(zct, "fail to exec:%s, error msg: %s", sql, err_msg);
|
||||
sqlite3_free(err_msg);
|
||||
free(sql);
|
||||
return 3;
|
||||
@ -750,6 +763,7 @@ int SqliteDB::execute_sql_file(const char *filename) {
|
||||
free(sql);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SqliteDB::InsertData(const char *tablename, const char *insertValues, int replace, bool expandable) {
|
||||
char *msg;
|
||||
int iRet = 0;
|
||||
@ -821,14 +835,14 @@ int SqliteDB::CalculateBattery() {
|
||||
vec_t vecResSig = sqlite_db_ctrl::instance().GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
||||
std::vector<std::string> vParam;
|
||||
boost::split(vParam, vecRes[i][6], boost::is_any_of(","), boost::token_compress_on);
|
||||
if (vParam.size() <= 0 || vecResSig.size() <= 0) { //第一次计算
|
||||
if (vParam.size() <= 0 || vecResSig.size() <= 0) { // 第一次计算
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, "dataNodeNo = '%s' ", vecRes[i][0].c_str());
|
||||
std::string Dip = sqlite_db_ctrl::instance().GetData(T_DATASTATIC_INFO(TNAME), " dip ", whereCon);
|
||||
if (Dip == "") {
|
||||
continue;
|
||||
}
|
||||
capacity = (0.9 + 0.1 * (90 - atoi(Dip.c_str())) / 90) * 19000; // mAh //电池总量
|
||||
capacity = (0.9 + 0.1 * (90 - atoi(Dip.c_str())) / 90) * 19000; // mAh 电池总量
|
||||
startCapacity = capacity;
|
||||
|
||||
sprintf(updateSql, "batteryPower = '%f,%f' ", startCapacity, startCapacity);
|
||||
@ -841,7 +855,7 @@ int SqliteDB::CalculateBattery() {
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
sprintf(whereCon, " dataNodeNo = '%s' order by timeStamp asc limit 0,1 ", vecRes[i][0].c_str());
|
||||
vecResSig = sqlite_db_ctrl::instance().GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
||||
if (vecResSig.size() <= 0) { //一条数据都没有
|
||||
if (vecResSig.size() <= 0) { // 一条数据都没有
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
@ -872,15 +886,15 @@ int SqliteDB::CalculateBattery() {
|
||||
|
||||
for (size_t j = 0; j < vecResbattery.size(); j++) {
|
||||
float b = 2 - 25 * k;
|
||||
float dpm = k * atoi(vecResbattery[j][2].c_str()) + b; //温度
|
||||
float cost_e = dpm * atoi(vecRes[i][3].c_str()); //特征值时间间隔
|
||||
float dpm = k * atoi(vecResbattery[j][2].c_str()) + b; // 温度
|
||||
float cost_e = dpm * atoi(vecRes[i][3].c_str()); // 特征值时间间隔
|
||||
float cost_h = cost_e / 60;
|
||||
vecworkTime.push_back(atol(vecResbattery[j][3].c_str()));
|
||||
vecsendTime.push_back(atol(vecResbattery[j][4].c_str()));
|
||||
to_math += cost_h;
|
||||
}
|
||||
|
||||
zlog_info(zct, "自放电 = %f", to_math);
|
||||
zlog_info(zct, "self discharge = %f", to_math);
|
||||
long sumworkTime = 0.0, sumsendTime = 0.0;
|
||||
for (size_t j = 0; j < vecworkTime.size(); j++) {
|
||||
sumworkTime += vecworkTime[j];
|
||||
@ -896,7 +910,7 @@ int SqliteDB::CalculateBattery() {
|
||||
|
||||
if (to_math < 0) to_math = 0;
|
||||
float usageBattery = usageworkTime + usagesendTime + to_math;
|
||||
zlog_info(zct, "已经使用 = %f", atof(vecResSig[6].c_str()));
|
||||
zlog_info(zct, "have used = %f", atof(vecResSig[6].c_str()));
|
||||
|
||||
float remainBattery = capacity - usageBattery * 0.2;
|
||||
if (remainBattery < 10) {
|
||||
@ -985,9 +999,9 @@ int SqliteDB::CalculateDip() {
|
||||
memset(whereCon, 0x00, sizeof(whereCon));
|
||||
if (vParam[1] == "2") { //人工干预
|
||||
sprintf(whereCon, " timeStamp > '%ld' ", atol(vParam[2].c_str()));
|
||||
} else if (vParam[1] == "0") { //正常状态
|
||||
sprintf(whereCon, " timeStamp > '%ld' ", atol(localtimestamp) - 86400); //一天数据
|
||||
} else if (vParam[1] == "1") { //松动状态
|
||||
} else if (vParam[1] == "0") { // 正常状态
|
||||
sprintf(whereCon, " timeStamp > '%ld' ", atol(localtimestamp) - 86400); // 一天数据
|
||||
} else if (vParam[1] == "1") { // 松动状态
|
||||
continue;
|
||||
}
|
||||
zlog_info(zct, "vParam[0]=%s,vParam[1]=%s", vParam[0].c_str(), vParam[1].c_str());
|
||||
@ -1033,7 +1047,7 @@ int SqliteDB::CalculateDip() {
|
||||
}
|
||||
|
||||
int SqliteDB::InintGateway() {
|
||||
//更新网关配置表
|
||||
// 更新网关配置表
|
||||
std::string strIP = GetGwIp_("eth0");
|
||||
std::string strServerIP = ReadStrByOpt(SERVERCONFIG, "Server", "localServerIpAddress");
|
||||
std::string strServerPort = ReadStrByOpt(SERVERCONFIG, "Server", "localServerPort");
|
||||
@ -1069,7 +1083,7 @@ int SqliteDB::InintGateway() {
|
||||
}
|
||||
}
|
||||
|
||||
//上传网关配置到MQTT
|
||||
// 上传网关配置到MQTT
|
||||
Json::Value jsSystemSetting;
|
||||
Json::Value jsBody;
|
||||
Json::FastWriter showValue;
|
||||
@ -1175,7 +1189,7 @@ std::string SqliteDB::GetNodeConfigureInfor(const char *whereCon) {
|
||||
} else {
|
||||
jsArray.resize(0);
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "查询失败";
|
||||
jsonVal["message"] = "fail to query";
|
||||
}
|
||||
|
||||
Json::Value jsBody;
|
||||
@ -1226,7 +1240,7 @@ int SqliteDB::QueryofflineData() {
|
||||
valNodeData.append(valNodeFeature);
|
||||
}
|
||||
}
|
||||
//无线传感器信息
|
||||
// 无线传感器信息
|
||||
Json::Value root;
|
||||
Json::Value valdatastatic;
|
||||
Json::Value valNodeData;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user