3.2.5 beta 5 优化日志存储,数据统计,传感器发射功率开关,离线数据最多存储5天,传感器特征值最多存储5天

This commit is contained in:
zhangsheng 2024-09-29 19:57:44 +08:00
parent 4d3ffb4b99
commit bfdb4cdbf7
10 changed files with 88 additions and 48 deletions

View File

@ -2036,7 +2036,7 @@ int writeIntValue(const char* section, char* key, int val, const char* file)
{
char strValue[STRVALUE_MAX_LEN];
memset(strValue, '\0', STRVALUE_MAX_LEN);
sprintf(strValue, "%-4d", val);
sprintf(strValue, "%d", val);
writeStringVlaue(section, key, strValue, file);
}

View File

@ -610,7 +610,11 @@ struct Param_56 {
int EndFrequency;
Param_56():mMode(0),mChannelId(""),mDataNodeNo(""),mPackageFlag(0),StartFrequency(0),EndFrequency(0){};
};
struct Param_57 {
int mMode;
int mZigbeePowerEnable;
Param_57():mZigbeePowerEnable(0){};
};
typedef struct DataNodeUpdate{
std::string strUpdataFileName;
std::string strSoftVersion;

View File

@ -24,8 +24,8 @@ enum enumZigBeeTransmitStatus {
//#define Q4G_MODULE
//#define WIFI_MODULE
//#define NR5G_MEIGE
#define G2UL_GATEWAY
//#define IMX6UL_GATEWAY
//#define G2UL_GATEWAY
#define IMX6UL_GATEWAY
class GlobalConfig
{
@ -78,7 +78,7 @@ public :
#define WHITE "\033[1;37m"
#ifdef IMX6UL_GATEWAY
#define SAVE_COUNT 2592
#define SAVE_COUNT 4320
#define OneWeek 259359
#endif
#ifdef G2UL_GATEWAY

View File

@ -1335,7 +1335,7 @@ int SqliteDB::QueryofflineData()
memcpy(updateSql, "sendMsg='1'",sizeof(updateSql));
sql_ctl->UpdateTableData(StaticTableName, updateSql, whereCon);
sql_ctl->UpdateTableData(dataTableName, updateSql, whereCon);
LOG_INFO("resend success dataNodeNo = %s,TimeStamp = '%s'\n",arrRetData[j][0].c_str(),arrRetData[j][8].c_str());
//LOG_INFO("resend success dataNodeNo = %s,TimeStamp = '%s'\n",arrRetData[j][0].c_str(),arrRetData[j][8].c_str());
}
}
}
@ -1392,7 +1392,7 @@ int SqliteDB::QueryofflineData()
//DeleteTableData("t_data_waveSend", whereCon);
std::string strCmd = "rm " + arrRetData[i][1];
system(strCmd.c_str());
LOG_INFO("resend success waveName = %s\n",arrRetData[i][1].c_str());
//LOG_INFO("resend success waveName = %s\n",arrRetData[i][1].c_str());
}
}
@ -1416,13 +1416,13 @@ int SqliteDB::CalculateData()
sprintf(tableName,"t_dataStatic_%s",vecRet[i][0].c_str());
const char *sql =
" timestamp >= strftime('%s', 'now', '-1 day', 'start of day','utc') "
"AND timestamp < strftime('%s', 'now', 'start of day','utc','+24 hours') ";
"AND timestamp < strftime('%s', 'now', '-1 day','start of day','utc','+24 hours') ";
int StatisticCount = GetTableRows(tableName,sql);
sql = "timeStamp >= strftime('%s', 'now', '-1 day', 'start of day','utc') AND timeStamp < strftime('%s', 'now', 'start of day','utc','+24 hours') and statisticType = '1' ";
sql = "timeStamp >= strftime('%s', 'now', '-1 day', 'start of day','utc') AND timeStamp < strftime('%s', 'now', '-1 day','start of day','utc','+24 hours') and statisticType = '1' ";
int SixCount = GetTableRows(tableName,sql);
sql = "timeStamp >= strftime('%s', 'now', '-1 day', 'start of day','utc') AND timeStamp < strftime('%s', 'now', 'start of day','utc','+24 hours') and statisticType = '1' and timing = '0'";
sql = "timeStamp >= strftime('%s', 'now', '-1 day', 'start of day','utc') AND timeStamp < strftime('%s', 'now', '-1 day','start of day','utc','+24 hours') and statisticType = '1' and timing = '0'";
int TimingCount = GetTableRows(tableName,sql);
print_info("nodeWaveSend = %s,waveInterVal = %s\n",vecRet[i][2].c_str(),vecRet[i][4].c_str());
if(vecRet[i][2] == "")
@ -1517,24 +1517,27 @@ int SqliteDB::CalculateData()
LOG_INFO("dataNodeNo = %s , Statistic Count = %d , 06 Count = %d , Timing Count = %d , CountWaveX = %d , CountWaveY = %d , CountWaveZ = %d , featureInterVal = %s , waveInterVal = %s , NodeWaveSend = %s\n"\
,vecRet[i][0].c_str(),StatisticCount,SixCount,TimingCount,CountWaveX,CountWaveY,CountWaveZ,vecRet[i][3].c_str(),vecRet[i][4].c_str(),vecRet[i][2].c_str());
if (rateX == 1 && rateY == 1 && rateZ == 1 && vecRet[i][5] == "3")
{
char updateSql[50] = {0x00};
sprintf(updateSql,"ZigbeePower = '2',UpdateFlag = 0 ");
memset(whereCon,0x00,sizeof(whereCon));
sprintf(whereCon," dataNodeNo = '%s'",vecRet[i][0].c_str());
UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
LOG_INFO("update ZigbeePower 2");
}
int zigbeepowerEnable = readIntValue( "config", "zigbeepowerEnable",(char*)GlobalConfig::Config_G.c_str());
if(zigbeepowerEnable){
if (rateX != -1 && rateY != -1 && rateZ != -1 && vecRet[i][5] == "3")
{
char updateSql[50] = {0x00};
sprintf(updateSql,"ZigbeePower = '2',UpdateFlag = 0 ");
memset(whereCon,0x00,sizeof(whereCon));
sprintf(whereCon," dataNodeNo = '%s'",vecRet[i][0].c_str());
UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
LOG_INFO("update ZigbeePower 2");
}
if ((rateX == -1 || rateY == -1 || rateZ == -1 )&& vecRet[i][5] == "2")
{
char updateSql[50] = {0x00};
sprintf(updateSql,"ZigbeePower = '3',UpdateFlag = 0 ");
memset(whereCon,0x00,sizeof(whereCon));
sprintf(whereCon," dataNodeNo = '%s'",vecRet[i][0].c_str());
UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
LOG_INFO("update ZigbeePower 3");
if ((rateX == -1 || rateY == -1 || rateZ == -1 ) && vecRet[i][5] == "2")
{
char updateSql[50] = {0x00};
sprintf(updateSql,"ZigbeePower = '3',UpdateFlag = 0 ");
memset(whereCon,0x00,sizeof(whereCon));
sprintf(whereCon," dataNodeNo = '%s'",vecRet[i][0].c_str());
UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
LOG_INFO("update ZigbeePower 3");
}
}
featureInterVal = atoi(vecRet[i][3].c_str());
waveInterVal = atoi(vecRet[i][4].c_str());

View File

@ -2789,3 +2789,23 @@ std::string JsonData::JsonCmd_Cgi_56(Param_56 &param)
return showValue.write(jsonVal);
}
std::string JsonData::JsonCmd_Cgi_57(Param_57 &param)
{
Json::Value jsonVal;
jsonVal.clear();
Json::Value jsBody;
jsonVal[JSON_FIELD_CMD] = "57";
jsonVal["success"] = true;
jsonVal["message"] = "";
int zigbeepowerEnable = -1;
if(param.mMode == 1){
zigbeepowerEnable = writeIntValue( "config", "zigbeepowerEnable",param.mZigbeePowerEnable,(char*)GlobalConfig::Config_G.c_str());
}else if (param.mMode == 0)
{
zigbeepowerEnable = readIntValue( "config", "zigbeepowerEnable",(char*)GlobalConfig::Config_G.c_str());
}
jsBody["zigbeepowerEnable"] = zigbeepowerEnable;
jsonVal["content"] = jsBody;
return showValue.write(jsonVal);
}

View File

@ -73,6 +73,7 @@ public :
std::string JsonCmd_Cgi_55(Param_55 &param);
std::string JsonCmd_Cgi_56(Param_56 &param);
std::string JsonCmd_Cgi_57(Param_57 &param);
std::string JsonCmd_Cgi_default();
private :

View File

@ -636,6 +636,20 @@ try{
param.mDataNodeNo = recvBody["dataNodeNo"].asString();
std::string data = jd.JsonCmd_Cgi_56(param);
return data;
}
case 57:{
JsonData jd;
Param_57 param;
param.mZigbeePowerEnable = recvBody["ZigbeePowerEnable"].asInt();
std::string type = recvBody["type"].asString();
if (0 == type.compare("SET")) {
param.mMode = 1;
}
if (0 == type.compare("GET")) {
param.mMode = 0;
}
std::string data = jd.JsonCmd_Cgi_57(param);
return data;
}
break;
default:

View File

@ -29,7 +29,7 @@ int main(int argc, char *argv[])
{
printf(" Firmware compile time:%s %s,version %s\n", __DATE__, __TIME__,GlobalConfig::Version.c_str());
// 初始化日志记录,日志缓存区,记录数,未使用,后期,命令启动
log_init(SOFTWARE_RUN_LOG, 1380, 200 * 1024 * 2);
log_init(SOFTWARE_RUN_LOG, 1380, 160 * 1024 * 2);
LOG_INFO("####CIDNSOFT start####\n");
// 查看版本信息

View File

@ -273,7 +273,7 @@ void CheckThread()
}
}
}
if(1500 == Battery){
if(7200 == Battery){
Battery = 0;
LOG_INFO("Battery\n");
sql_ctl->CalculateBattery();

View File

@ -635,7 +635,7 @@ int Uart::FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head)
}
break;
}else if(command == 35){
LOG_INFO("command = %d ShortAddr :%s,Timetamp=%s\n",command,strShortAddr.c_str(),strTimetamp.c_str());
//LOG_INFO("command = %d ShortAddr :%s,Timetamp=%s\n",command,strShortAddr.c_str(),strTimetamp.c_str());
// for(int j = i; j < i+100;j++){
// printf("%02X ",UartRecvBuf[j]&0xFF);
// }
@ -661,7 +661,7 @@ int Uart::FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head)
boost::split( vParamRSSI, vecDataNodeNo[1], boost::is_any_of( "," ), boost::token_compress_on );
if(vParamRSSI.size() > 0){
sprintf(updateSql, "RSSI = '%s,%02d' ",vParamRSSI[0].c_str(),UartRecvBuf[i+14]&0xFF);
LOG_INFO(updateSql);
//LOG_INFO(updateSql);
sprintf(whereCon, "dataNodeNo='%s'", (char*)vecDataNodeNo[0].c_str());
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
}
@ -718,7 +718,7 @@ int Uart::FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head)
//pTestRecv(command);
}else if(command == 218){//DA
LOG_INFO("command = %d,zigbeeShortAddr = %s , signal = %02d,strTimetamp = %s\n",command,m_strDestShortAddr.c_str(),UartRecvBuf[i+6]&0xFF,strTimetamp.c_str());
//LOG_INFO("command = %d,zigbeeShortAddr = %s , signal = %02d,strTimetamp = %s\n",command,m_strDestShortAddr.c_str(),UartRecvBuf[i+6]&0xFF,strTimetamp.c_str());
char whereCon[1024] = {0};
char updateSql[1024] = { 0 };
char tableName[100]={0x00};
@ -743,11 +743,11 @@ int Uart::FindRecvPackage(int bytesRead, char* mUartRecvBuf,char* head)
boost::split( vParamRSSI, vecDataNodeNo[2], boost::is_any_of( "," ), boost::token_compress_on );
if(vParamRSSI.size() == 1){
sprintf(updateSql, "RSSI = '%02d,%s' ",UartRecvBuf[i+6]&0xFF,vParamRSSI[0].c_str());
LOG_INFO(updateSql);
//LOG_INFO(updateSql);
}else if(vParamRSSI.size() == 2){
sprintf(updateSql, "RSSI = '%02d,%s' ",UartRecvBuf[i+6]&0xFF,vParamRSSI[1].c_str());
LOG_INFO(updateSql);
//LOG_INFO(updateSql);
}
sprintf(whereCon, "dataNodeNo='%s'", (char*)vecDataNodeNo[0].c_str());
sql_ctl->UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
@ -2246,8 +2246,6 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
RecordBattery(strLongAddr,dataStatic,nowTimetamp);
char szTableName[50]={0x00},szTableNameStatic[50]={0x00},szTableNameData[50]={0x00};
sprintf(szTableName,"t_dataStatic_%s",strLongAddr.c_str());
memcpy(szTableNameStatic,szTableName,sizeof(szTableNameStatic));
@ -2324,9 +2322,9 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
print_info("nowTimetamp = %s",nowTimetamp.c_str());
// save dataStatic of 7 days
char selectCon[128] = { 0 };
sprintf(selectCon, "channelID='%s' and sendMsg = '1' ORDER BY timeStamp ASC LIMIT 0,1",(strMeasurementID + "-S").c_str());
sprintf(selectCon, "channelID='%s' ORDER BY timeStamp ASC LIMIT 0,1",(strMeasurementID + "-S").c_str());
std::string strTime = sql_ctl->GetData(szTableName, "timeStamp", selectCon);
sprintf(whereCon,"channelID='%s' and sendMsg = '1'",(strMeasurementID + "-S").c_str());
sprintf(whereCon,"channelID='%s' ",(strMeasurementID + "-S").c_str());
int Count = sql_ctl->GetTableRows(szTableName, whereCon);
if(Count == -1){
sql_ctl->CreatedataStatictable(szTableName);
@ -2340,7 +2338,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
sprintf(updateSql, "temTop='%f',temBot='%f',dip='%d',voltage='%d',timeStamp='%s',StaticIndex = %d, nodeResend = %d,zigbeeSignal = '',zigbeeSignalNode = '',statisticType = '',timing = '' ",\
dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, nowTimetamp.c_str(),staticIndex,nodeResend);
sprintf(whereCon, "channelID='%s' and sendMsg = '1'", (strMeasurementID + "-S").c_str());
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-S").c_str());
if ( /*0 == sql_ctl->GetTableRows(T_DATASTATIC_INFO(TNAME), whereCon)*/ (Count * 3 < SAVE_COUNT && lTime < OneWeek ) || strTime.size() == 0 ) {
print_info("insert static data to sql\n");
char insertSql[1024] = { 0 };
@ -2363,7 +2361,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
}
} else {
memset(whereCon,0x00,sizeof(whereCon));
sprintf(whereCon, "channelID='%s' and sendMsg = '1' and timeStamp = '%s'", (strMeasurementID + "-S").c_str(),strTime.c_str());
sprintf(whereCon, "channelID='%s' and timeStamp = '%s'", (strMeasurementID + "-S").c_str(),strTime.c_str());
print_info("update static data to sql\n");
sql_ctl->UpdateTableData(szTableName, updateSql, whereCon);
memset(whereCon,0x00,sizeof(whereCon));
@ -2695,7 +2693,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
dataDymX.Phase4 = 0;
memset(whereCon, 0, 1024);
sprintf(whereCon, "channelID='%s' and sendMsg = '1'", (strMeasurementID + "-X").c_str());
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-X").c_str());
memset(updateSql, 0, 1024);
sprintf(updateSql, "diagnosisPk='%f',integratPk='%f',integratRMS='%f',rmsValues='%f',envelopEnergy='%f',\
Amp1='%f',Amp2='%f',Amp3='%f',Amp4='%f',Amp5='%f',Phase1='%f',Phase2='%f',Phase3='%f',Phase4='%f',timeStamp='%s',StaticIndex = %d,nodeResend = %d ",\
@ -2715,7 +2713,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
sql_ctl->UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
} else {
memset(whereCon,0x00,sizeof(whereCon));
sprintf(whereCon, "channelID='%s' and sendMsg = '1' and timeStamp = '%s'", (strMeasurementID + "-X").c_str(),strTime.c_str());
sprintf(whereCon, "channelID='%s' and timeStamp = '%s'", (strMeasurementID + "-X").c_str(),strTime.c_str());
// sprintf(whereCon, "channelID='%s' and sendMsg = '1' ", (strLongAddr + "-X").c_str());
sql_ctl->UpdateTableData(szTableName, updateSql, whereCon);
memset(whereCon,0x00,sizeof(whereCon));
@ -3058,7 +3056,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
dataDymY.Phase4 = 0;
memset(whereCon, 0, 1024);
sprintf(whereCon, "channelID='%s' and sendMsg = '1'", (strMeasurementID + "-Y").c_str());
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-Y").c_str());
memset(updateSql, 0, 1024);
sprintf(updateSql, "diagnosisPk='%f',integratPk='%f',integratRMS='%f',rmsValues='%f',envelopEnergy='%f',\
Amp1='%f',Amp2='%f',Amp3='%f',Amp4='%f',Amp5='%f',Phase1='%f',Phase2='%f',Phase3='%f',Phase4='%f',timeStamp='%s',StaticIndex = %d,nodeResend = %d ",\
@ -3079,7 +3077,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
} else {
memset(whereCon,0x00,sizeof(whereCon));
sprintf(whereCon, "channelID='%s' and sendMsg = '1' and timeStamp = '%s'", (strMeasurementID + "-Y").c_str(),strTime.c_str());
sprintf(whereCon, "channelID='%s' and timeStamp = '%s'", (strMeasurementID + "-Y").c_str(),strTime.c_str());
// sprintf(whereCon, "channelID='%s' and sendMsg = '1' ", (strLongAddr + "-Y").c_str());
sql_ctl->UpdateTableData(szTableName, updateSql, whereCon);
memset(whereCon,0x00,sizeof(whereCon));
@ -3420,7 +3418,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
dataDymZ.Phase4 = lowbit * n;
memset(whereCon, 0, 1024);
sprintf(whereCon, "channelID='%s' and sendMsg = '1'", (strMeasurementID + "-Z").c_str());
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-Z").c_str());
memset(updateSql, 0, 1024);
sprintf(updateSql, "diagnosisPk='%f',integratPk='%f',integratRMS='%f',rmsValues='%f',envelopEnergy='%f',\
@ -3442,7 +3440,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag)
} else {
memset(whereCon,0x00,sizeof(whereCon));
sprintf(whereCon, "channelID='%s' and sendMsg = '1' and timeStamp = '%s'", (strMeasurementID + "-Z").c_str(),strTime.c_str());
sprintf(whereCon, "channelID='%s' and timeStamp = '%s'", (strMeasurementID + "-Z").c_str(),strTime.c_str());
// sprintf(whereCon, "channelID='%s' and sendMsg = '1'", (strLongAddr + "-Z").c_str());
sql_ctl->UpdateTableData(szTableName, updateSql, whereCon);
memset(whereCon,0x00,sizeof(whereCon));
@ -3966,7 +3964,7 @@ void Uart::WriteDatFile(int sampleRate,string& strMeasurementID,int iChannel,std
std::string WaveData = WaveValue.write(valWaveData);
char selectCon[128] = { 0 };
sprintf(selectCon, "channelID='%s' and sendMsg = '1' ORDER BY timeStamp ASC LIMIT 0,1",strChannelID.c_str());
sprintf(selectCon, "channelID='%s' ORDER BY timeStamp ASC LIMIT 0,1",strChannelID.c_str());
std::string strTime = sql_ctl->GetData("t_data_waveSend", "timeStamp", selectCon);
long lTime = atol(nowTimetamp.c_str())-atol(strTime.c_str());
int Count = sql_ctl->GetTableRows("t_data_waveSend", NULL);
@ -3979,7 +3977,7 @@ void Uart::WriteDatFile(int sampleRate,string& strMeasurementID,int iChannel,std
char updateSql[128] = { 0 },whereCon[128] = {0};
sprintf(updateSql, "waveName='%s',timeStamp='%s'",strFileName_Record.c_str(),nowTimetamp.c_str());
memset(whereCon,0x00,sizeof(whereCon));
sprintf(whereCon, "channelID='%s' and sendMsg = '1' and timeStamp = '%s'", strChannelID.c_str(),strTime.c_str());
sprintf(whereCon, "channelID='%s' and timeStamp = '%s'", strChannelID.c_str(),strTime.c_str());
print_info("update static data to sql\n");
sql_ctl->UpdateTableData("t_data_waveSend", updateSql, whereCon);
}