fix debug mode , mqtt resend

This commit is contained in:
zhangsheng 2026-04-02 10:51:02 +08:00
parent bc8c843865
commit e45b8db8bd
7 changed files with 46 additions and 22 deletions

View File

@ -1380,7 +1380,7 @@ int SqliteDB::QueryofflineData() {
}
}
float frTemp = 0.0f;
/*float frTemp = 0.0f;
std::string sample;
char whereCon[1024] = {0x00};
char buf[30]={0};
@ -1448,7 +1448,7 @@ int SqliteDB::QueryofflineData() {
zlog_error(zct, "data_publish res = %d", res);
}
}
}
}*/
return res;
}
int SqliteDB::ClearExpireData(){

View File

@ -301,7 +301,7 @@ std::string JsonData::JsonCmd_Cgi_10(Param_10 &param) {
sprintf(whereCon, "channelID like '%%%s%%' and %s <> ''", param.MeasurementID.c_str(), param.strStatic.c_str());
} else {
sprintf(whereCon, " channelID like '%%%s%%' and %s <> '' and timeStamp < '%s' and timeStamp > '%s' and nodeResend = 0", param.MeasurementID.c_str(), param.strStatic.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
sprintf(whereCon, " channelID like '%%%s%%' and %s <> '' and timeStamp < '%s' and timeStamp > '%s' and nodeResend IN (0, 1, 2)", param.MeasurementID.c_str(), param.strStatic.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
}
int rows = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon);
@ -333,9 +333,9 @@ std::string JsonData::JsonCmd_Cgi_10(Param_10 &param) {
memset(whereCon, 0x00, sizeof(whereCon));
if (param.timeEnd == "") {
sprintf(whereCon, "channelID like '%%%s%%' and %s <> '' and nodeResend = 0 order by timeStamp asc LIMIT %d OFFSET %d", param.MeasurementID.c_str(), param.strStatic.c_str(), 550, packgeNum);
sprintf(whereCon, "channelID like '%%%s%%' and %s <> '' and nodeResend IN (0, 1, 2) order by timeStamp asc LIMIT %d OFFSET %d", param.MeasurementID.c_str(), param.strStatic.c_str(), 550, packgeNum);
} else {
sprintf(whereCon, "channelID like '%%%s%%' and %s <> '' and nodeResend = 0 and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.MeasurementID.c_str(), param.strStatic.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum);
sprintf(whereCon, "channelID like '%%%s%%' and %s <> '' and nodeResend IN (0, 1, 2) and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.MeasurementID.c_str(), param.strStatic.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum);
}
array_t vecRes;

View File

@ -672,7 +672,7 @@ std::string JsonData::JsonCmd_Cgi_30(Param_30 &param) {
resolution = 1 / 3.2;
}
zlog_info(zct, "the sample rate is %d,the resolution %f,fftWave %d", SampleRate, resolution,fftWave.size());
zlog_info(zct, "the sample rate is %d,the resolution %f,fftWave %zu", SampleRate, resolution,fftWave.size());
char buf[32];
memset(buf, 0, 32);
sprintf(buf, "%f", resolution);

View File

@ -1416,9 +1416,10 @@ std::string JsonData::JsonCmd_Cgi_67(Param_67 &param){
char selectCon[128] = {0};
char column[128] = {0};
char tablename[256] = {0};
std::string batteryPower = "";
if(param.mMode == 0){
sprintf(selectCon, " t_sensor_info.MeasurementID = t_debug_info.MeasurementID ");
sprintf(column, " t_debug_info.*,t_sensor_info.status,t_sensor_info.dataNodeName ");
sprintf(column, " t_debug_info.*,t_sensor_info.status,t_sensor_info.dataNodeName,t_sensor_info.batteryPower ");
sprintf(tablename, " t_debug_info LEFT JOIN t_sensor_info ");
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(tablename, column, selectCon);
int nSize = arrRes.size();
@ -1458,7 +1459,16 @@ std::string JsonData::JsonCmd_Cgi_67(Param_67 &param){
jsChannelData["dataNodeRssi"] = atoi(arrRes[j][3].c_str());
jsChannelData["comprehensiveRssi"] = atof(arrRes[j][4].c_str());
jsChannelData["minimumVoltage"] = atof(arrRes[j][5].c_str());
jsChannelData["currentBatteryLevel"] = atof(arrRes[j][6].c_str());
batteryPower = arrRes[j][11];
std::vector<std::string> vParamBatteryPower;
float fBatteryPower = 100.0;
if(batteryPower != ""){
boost::split(vParamBatteryPower, batteryPower, boost::is_any_of(","), boost::token_compress_on);
if (vParamBatteryPower.size() > 0) {
fBatteryPower = atof(vParamBatteryPower[1].c_str())/atof(vParamBatteryPower[0].c_str());
}
}
jsChannelData["currentBatteryLevel"] = fBatteryPower * 100;
jsChannelData["debugStatus"] = atoi(arrRes[j][7].c_str());
jsChannelData["TimeStamp"] = arrRes[j][8];
jsSensor.append(jsChannelData);

View File

@ -488,7 +488,7 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr, bool &z, in
}
// 如果是在当前波形时间窗中,不管是空闲时间窗,还是发送波形的时间窗,下一个时间窗是特征值
int eigen_send_ts = (id - 1) * 4;
int eigen_send_ts = (id - 1) * 6;
if (eigen_send_ts > 57) {
eigen_send_ts = eigen_send_ts % 57;
}

View File

@ -647,7 +647,7 @@ int Uart::DealFeatureValue(const char *pData,uint16_t ushortAdd){
long now_time = atol(nowTimetamp.c_str());
if(ushortAdd == last_short_addr && (now_time - last_time) < 5){
zlog_warn(zct, "DealFeatureValue short_addr_last = %02x%02x,timestamp_last = %ld,nowTime = %ld",UINT16_HIGH(ushortAdd), UINT16_LOW(ushortAdd),last_time,now_time);
int iRet = DealDataNodeFeature(pData, 0);
int iRet = DealDataNodeFeature(pData, 1);
if (iRet != 0)
{
return -1;

View File

@ -97,6 +97,22 @@ void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, s
sprintf(tableName, "t_debug_info");
sprintf(updateSql, " comprehensiveRSSI = '%f',minnumVoltage = '%d',status = '2',timeStamp = '%s' ", comprehensiveRSSI,dataStatic.instantaneousBatteryVoltage,localtimestamp);
sqlite_db_ctrl::instance().UpdateTableData(tableName, updateSql, whereCon);
memset(whereCon,0x00,sizeof(whereCon));
sprintf(whereCon,"status = '1'");
uint16_t short_addr;
char *end_ptr = NULL;
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " zigbeeShortAddr ", whereCon);
if (vecResult.size() > 0)
{
std::vector<uint16_t> short_addr_list;
for (size_t i = 0; i < vecResult.size(); i++)
{
short_addr = strtol(vecResult[0].c_str(), &end_ptr, 16);
short_addr_list.push_back(short_addr);
}
scheduler::instance().OpenDebugMode(short_addr_list);
}
memset(whereCon,0x00,sizeof(whereCon));
sprintf(whereCon,"status = '1'");
int count = sqlite_db_ctrl::instance().GetTableRows(tableName, whereCon);
@ -214,9 +230,7 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
uint8_t nodeResend = pData[6] & 0xFF;
zlog_info(zct, "nodeResend = %d", nodeResend);
sprintf(buf, "%02x%02x", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]);
if (flag == 1) {
zlog_info(zct, "DealDataNodeFeature %02x%02x, %d", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1], flag);
}
uint8_t Feature_x,Feature_y,Feature_z;
char *end_ptr;
uint16_t u_short_addr = strtol(buf, &end_ptr, 16);
@ -424,8 +438,8 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
zlog_info(zct, "dataStatic.TemTop : %f dataStatic.TemBot : %f dataStatic.Dip :%d dataStatic.Voltage : %d", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage);
sprintf(updateSql, "temTop='%f',temBot='%f',dip='%d',voltage='%d',timeStamp='%s',StaticIndex = %ld, nodeResend = %d,zigbeeSignal = '',zigbeeSignalNode = '',statisticType = '%d',timing = '%d',nodeTimestamp = '%s',minmumBatteryVoltageType = '%d',instantaneousBatteryVoltage = '%d' ", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage,
nowTimetamp.c_str(), staticIndex, nodeResend, flag, timing, nodetimestamp, dataStatic.minmumBatteryVoltageType, dataStatic.instantaneousBatteryVoltage);
sprintf(updateSql, "temTop='%f',temBot='%f',dip='%d',voltage='%d',timeStamp='%s',StaticIndex = %ld, nodeResend = %d,zigbeeSignal = '',zigbeeSignalNode = '',statisticType = '0',timing = '%d',nodeTimestamp = '%s',minmumBatteryVoltageType = '%d',instantaneousBatteryVoltage = '%d' ", dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage,
nowTimetamp.c_str(), staticIndex, nodeResend, timing, nodetimestamp, dataStatic.minmumBatteryVoltageType, dataStatic.instantaneousBatteryVoltage);
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-S").c_str());
if (/*0 == sqlite_db_ctrl::instance().GetTableRows(T_DATASTATIC_INFO(TNAME), whereCon)*/ (Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0) {
zlog_info(zct, "insert static data to sql");
@ -524,7 +538,7 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
sqlite_db_ctrl::instance().UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
} else {
memset(whereCon, 0x00, sizeof(whereCon));
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' and nodeResend = 0 and nodeTimestamp = '%s'", (strMeasurementID + "-X").c_str(), strTime.c_str(),nodetimestamp);
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' and nodeResend = 0 ", (strMeasurementID + "-X").c_str(), strTime.c_str());
sqlite_db_ctrl::instance().UpdateTableData(szTableName, updateSql, whereCon);
memset(whereCon, 0x00, sizeof(whereCon));
@ -621,7 +635,7 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
sqlite_db_ctrl::instance().UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
} else {
memset(whereCon, 0x00, sizeof(whereCon));
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' and nodeResend = 0 and nodeTimestamp = '%s'", (strMeasurementID + "-Y").c_str(), strTime.c_str(),nodetimestamp);
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' and nodeResend = 0 ", (strMeasurementID + "-Y").c_str(), strTime.c_str());
sqlite_db_ctrl::instance().UpdateTableData(szTableName, updateSql, whereCon);
memset(whereCon, 0x00, sizeof(whereCon));
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-Y").c_str());
@ -724,7 +738,7 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
sqlite_db_ctrl::instance().UpdateTableData(T_DATA_INFO(TNAME), updateSql, whereCon);
} else {
memset(whereCon, 0x00, sizeof(whereCon));
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' and nodeResend = 0 and nodeTimestamp = '%s'", (strMeasurementID + "-Z").c_str(), strTime.c_str(),nodetimestamp);
sprintf(whereCon, "channelID='%s' and timeStamp = '%s' and nodeResend = 0 ", (strMeasurementID + "-Z").c_str(), strTime.c_str());
sqlite_db_ctrl::instance().UpdateTableData(szTableName, updateSql, whereCon);
memset(whereCon, 0x00, sizeof(whereCon));
sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-Z").c_str());
@ -800,6 +814,10 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
Json::FastWriter featureValue;
std::string strstatisticData = featureValue.write(root);
if(flag == 1){
zlog_info(zct, "resend data,dont send to mqtt");
return;
}
int iRet = data_publish(strstatisticData.c_str(), GlobalConfig::Topic_G.mPubData.c_str());
zlog_info(zct, "dataNodeNo = '%s' and TimeStamp = '%s',MQTT ret = %d", strMeasurementID.c_str(), nowTimetamp.c_str(), iRet);
if (iRet != 0) {
@ -817,10 +835,6 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) {
memset(selectCon, 0x00, sizeof(selectCon));
sprintf(selectCon, "zigbeeSignal <> '' ORDER BY timeStamp desc LIMIT 0,1");
strTime = sqlite_db_ctrl::instance().GetData(szTableNameStatic, "timeStamp", selectCon);
if (flag == 1) {
zlog_info(zct, "DealDataNodeFeature end %02x%02x", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]);
}
JsonData jd;
jd.JsonCmd_32(strMeasurementID,0,0,strMeasurementID,"");
DealTriger(u_short_addr,strMeasurementID);