From 47707a47582fac55bb380d5c90643c7f10391bb7 Mon Sep 17 00:00:00 2001 From: zhangsheng Date: Thu, 10 Apr 2025 15:50:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3bug,=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=B3=A2=E5=BD=A2=E6=8E=A5=E6=94=B6=E9=9C=80=E8=A6=81=E8=A1=A5?= =?UTF-8?q?=E5=8F=91=E7=9A=84=E9=80=BB=E8=BE=91=EF=BC=8Cversion=205.6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jsonparse/web_cmd_parse3.cpp | 13 ++++--- platform/platform_init.cpp | 2 +- scheduler/schedule.cpp | 58 ++++++++++++++++------------ scheduler/schedule.hpp | 3 +- uart/uart.cpp | 20 +++++----- uart/uart_feature_parse.cpp | 73 ++++++++++++++++++++++-------------- 6 files changed, 98 insertions(+), 71 deletions(-) diff --git a/jsonparse/web_cmd_parse3.cpp b/jsonparse/web_cmd_parse3.cpp index 2b6306d..ec9ac55 100644 --- a/jsonparse/web_cmd_parse3.cpp +++ b/jsonparse/web_cmd_parse3.cpp @@ -577,6 +577,7 @@ std::string JsonData::JsonCmd_Cgi_59(Param_59 ¶m) { " LAG(timestamp) OVER (ORDER BY timestamp) AS prev_timestamp " " FROM %s" ") " + "SELECT timestamp, " " prev_timestamp, " " timestamp - prev_timestamp AS interval_seconds " @@ -894,7 +895,7 @@ std::string JsonData::JsonCmd_Cgi_62(Param_62 ¶m){ if (nSize > 0) { char szTableName[100] = {0x00}, whereCon[256] = {0x00},selectCon[100] = {0x00}; if (param.mMode == 1){ - sprintf(selectCon," dataNodeNo,channelID,timeStamp,sendMsg,nodeResend "); + sprintf(selectCon," dataNodeNo,channelID,timeStamp,sendMsg,sendMsg,nodeResend "); sprintf(szTableName,"t_data_%s",param.MeasurementID.c_str()); }else{ sprintf(selectCon," * "); @@ -903,14 +904,14 @@ std::string JsonData::JsonCmd_Cgi_62(Param_62 ¶m){ if(param.straxis == ""){ if (param.mMode == 1){ - sprintf(whereCon, " channelID like '%%%s%%' and timeStamp < '%s' and timeStamp > '%s' ", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str()); + sprintf(whereCon, " channelID like '%s-X' and timeStamp < '%s' and timeStamp > '%s' ", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str()); }else{ sprintf(whereCon, " data_nodeno like '%%%s%%' and timeStamp < '%s' and timeStamp > '%s' ", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str()); } } else{ if (param.mMode == 1){ - sprintf(whereCon, " channelID = '%s-%s' and timeStamp < '%s' and timeStamp > '%s' ", param.MeasurementID.c_str(),param.straxis.c_str(), param.timeEnd.c_str(), param.timeStart.c_str()); + sprintf(whereCon, " channelID = '%s-X' and timeStamp < '%s' and timeStamp > '%s' ", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str()); }else{ sprintf(whereCon, " data_nodeno = '%s-%s' and timeStamp < '%s' and timeStamp > '%s' ", param.MeasurementID.c_str(),param.straxis.c_str(), param.timeEnd.c_str(), param.timeStart.c_str()); } @@ -946,15 +947,15 @@ std::string JsonData::JsonCmd_Cgi_62(Param_62 ¶m){ if(param.straxis == "") { if (param.mMode == 1){ - sprintf(whereCon, " channelID like '%%%s%%' and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum); + sprintf(whereCon, " channelID like '%s-X' and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum); }else{ sprintf(whereCon, " data_nodeno like '%%%s%%' and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum); } }else{ if (param.mMode == 1){ - sprintf(whereCon, " channelID = '%s-%s' and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.MeasurementID.c_str(),param.straxis.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum); + sprintf(whereCon, " channelID = '%s-X' and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum); }else{ - sprintf(whereCon, "data_nodeno = %s-%s' and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.MeasurementID.c_str(),param.straxis.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum); + sprintf(whereCon, "data_nodeno = '%s-%s' and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.MeasurementID.c_str(),param.straxis.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum); } } array_t vecRes; diff --git a/platform/platform_init.cpp b/platform/platform_init.cpp index e591ef0..b5a8993 100644 --- a/platform/platform_init.cpp +++ b/platform/platform_init.cpp @@ -14,7 +14,7 @@ int GlobalConfig::LinkStatus_G = 0; int GlobalConfig::LinkCount = 0; int GlobalConfig::net0Status = 1; -std::string GlobalConfig::Version = "5.5"; +std::string GlobalConfig::Version = "5.6"; std::string GlobalConfig::MacAddr_G = ""; std::string GlobalConfig::MacAddr_G2 = ""; std::string GlobalConfig::IpAddr_G = ""; diff --git a/scheduler/schedule.cpp b/scheduler/schedule.cpp index 1ca5717..178e0d2 100644 --- a/scheduler/schedule.cpp +++ b/scheduler/schedule.cpp @@ -210,7 +210,7 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) { if (wave_slice_iter != sensor_id_nth_slice_.end()) { if (nth_wave_slice > wave_slice_iter->second) { if (success_set_.count(short_addr) == 0 && !RetransferWave(short_addr)) { - zlog_warn(zct, "[Nxt] [%d] add it to patch set", short_addr); + zlog_warn(zct, "[Nxt] [%d:%x] add it to patch set", id, short_addr); patch_set_.insert(short_addr); } } @@ -250,7 +250,7 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) { } } } - } else if (MissedWave(short_addr)) { + } else if (!MissedWave(short_addr)) { for (int i = 0; i < wave_slice_num_per_eigen_interval_; ++i) { if (slice_sensor_id_[i+forward_wave_slice_num] == 0) { // 判断此空闲位置是否被占用 @@ -307,6 +307,7 @@ int SensorScheduler::GetNextDuration(int short_addr) { SensorScheduler::SensorScheduler() { support_modification_ = true; std::ifstream schedule_file(SCHEDULE_CONFIG); + bool configed = false; if (schedule_file.good()) { zlog_info(zbt, "exist configuration file"); Json::Reader reader; @@ -314,13 +315,14 @@ SensorScheduler::SensorScheduler() { if (!reader.parse(schedule_file, root, false)) { zlog_error(zbt, "invalid format, fail to parse %s", SCHEDULE_CONFIG); schedule_file.close(); - return; + goto init_config; } schedule_file.close(); if (!root.isObject()) { zlog_error(zbt, "invalid format, not an object: %s", SCHEDULE_CONFIG); - return; + goto init_config; } + configed = true; start_timestamp_ = std::stol(root["schedule_start_timestamp"].asString()); start_ts_str_ = root["schedule_start_time"].asString(); long current_ts = GetLocalTs(); @@ -362,28 +364,12 @@ SensorScheduler::SensorScheduler() { int rest_duration = eigen_value_send_interval_ - eigen_value_slice_total_seconds_; wave_slice_num_per_eigen_interval_ = rest_duration / wave_form_send_duration_; seconds_per_wave_slice_ = rest_duration / wave_slice_num_per_eigen_interval_; - } else { - zlog_info(zbt, "use default configuration"); - int eigen_value_send_interval = 300; - int wave_form_send_interval = 7200; - int eigen_value_send_duration = 6; - int wave_form_send_duration = 50; - int max_sensor_num = 32; + } - // int eigen_value_send_interval = 120; - // int wave_form_send_interval = 240; - // int eigen_value_send_duration = 6; - // int wave_form_send_duration = 40; - // int max_sensor_num = 4; - std::string error_msg; - Config(eigen_value_send_interval, - wave_form_send_interval, - eigen_value_send_duration, - wave_form_send_duration, - max_sensor_num, - error_msg); +init_config: + if (!configed) { + UseDefaultConfig(); } - short_addr_map_.clear(); ShortAddrCfg::ReadCfg(short_addr_map_); @@ -810,4 +796,26 @@ void SensorScheduler::CleanIdleOccupiedSet(long ts) { } else ++it; } } -} \ No newline at end of file +} + +void SensorScheduler::UseDefaultConfig() { + zlog_info(zbt, "use default configuration"); + int eigen_value_send_interval = 300; + int wave_form_send_interval = 7200; + int eigen_value_send_duration = 6; + int wave_form_send_duration = 50; + int max_sensor_num = 32; + + // int eigen_value_send_interval = 120; + // int wave_form_send_interval = 240; + // int eigen_value_send_duration = 6; + // int wave_form_send_duration = 40; + // int max_sensor_num = 4; + std::string error_msg; + Config(eigen_value_send_interval, + wave_form_send_interval, + eigen_value_send_duration, + wave_form_send_duration, + max_sensor_num, + error_msg); +} diff --git a/scheduler/schedule.hpp b/scheduler/schedule.hpp index dae6c56..baff1e6 100644 --- a/scheduler/schedule.hpp +++ b/scheduler/schedule.hpp @@ -104,6 +104,7 @@ public: private: void UpdateUpgradeInfo(int id); void CleanIdleOccupiedSet(long ts); + void UseDefaultConfig(); // user config int eigen_value_send_interval_; @@ -132,7 +133,7 @@ private: std::unordered_set patch_set_; // 漏传的补传 void ClearFailureSuccessMap(); bool RetransferWave(uint16_t short_addr); - bool MissedWave(uint16_t short_addr); + bool MissedWave(uint16_t short_addr); // 空闲时间戳被占用 std::unordered_set free_slice_ocuppied_; diff --git a/uart/uart.cpp b/uart/uart.cpp index 9685222..e688bc9 100644 --- a/uart/uart.cpp +++ b/uart/uart.cpp @@ -1115,11 +1115,11 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { strChannelID = strMeasurementID + "-Z"; wave_error_z = true; } - if(scheduler::instance().WaveError(wave_shortAddr) < 0){ - zlog_error(zct, "WaveError error ShortAddr :%s", strShortAddr.c_str()); - sprintf(insertSql, "'%s','%s','%s',%d,'%d','%s' ", strChannelID.c_str(),strShortAddr.c_str(),localtimestamp,bytesRead,0,error_msg.c_str()); - sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql); - } + + zlog_error(zct, "WaveError error ShortAddr :%s", strShortAddr.c_str()); + sprintf(insertSql, "'%s','%s','%s',%d,'%d','%s' ", strChannelID.c_str(),strShortAddr.c_str(),localtimestamp,bytesRead,0,error_msg.c_str()); + sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql); + JsonData jd; jd.JsonCmd_32(strMeasurementID,1,1,strChannelID,error_msg); @@ -1157,11 +1157,11 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { strChannelID = strMeasurementID + "-Z"; wave_error_z = true; } - if(scheduler::instance().WaveError(wave_shortAddr) < 0){ - zlog_error(zct, "WaveError error ShortAddr :%s", strShortAddr.c_str()); - sprintf(insertSql, "'%s','%s','%s',%d,'%d','%s' ", strChannelID.c_str(),strShortAddr.c_str(),localtimestamp,bytesRead,0,error_msg.c_str()); - sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql); - } + + zlog_error(zct, "WaveError error ShortAddr :%s", strShortAddr.c_str()); + sprintf(insertSql, "'%s','%s','%s',%d,'%d','%s' ", strChannelID.c_str(),strShortAddr.c_str(),localtimestamp,bytesRead,0,error_msg.c_str()); + sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql); + JsonData jd; jd.JsonCmd_32(strMeasurementID,1,1,strChannelID,error_msg); continue; diff --git a/uart/uart_feature_parse.cpp b/uart/uart_feature_parse.cpp index db7ee36..6887d2b 100644 --- a/uart/uart_feature_parse.cpp +++ b/uart/uart_feature_parse.cpp @@ -776,6 +776,7 @@ void Uart::DealWave() { wave_trans_ = false; return; } + strShortAddr = res[30]; strLongAddr = res[0]; strMeasurementID = res[44]; if (0 == strLongAddr.length()) { @@ -783,34 +784,7 @@ void Uart::DealWave() { wave_trans_ = false; return; } - if (m_waveCountX > 0 || m_waveCountY > 0 || m_waveCountZ > 0){ - char localtimestamp[32] = {0}; - GetTimeNet(localtimestamp, 1); - char insertSql[100] = {0x00}; - char whereCon[50] = {0x00}; - sprintf(whereCon, "MeasurementID='%s'",strMeasurementID.c_str()); - memset(whereCon, 0x00, sizeof(whereCon)); - if (m_waveCountX > 0) - { - sprintf(insertSql, "'%s-X','%02x%02x','%s',0,'1','%s' ", strMeasurementID.c_str(),(wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,localtimestamp,""); - sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql); - } - if (m_waveCountY > 0) - { - sprintf(insertSql, "'%s-Y','%02x%02x','%s',0,'1','%s' ", strMeasurementID.c_str(),(wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,localtimestamp,""); - sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql); - } - if (m_waveCountZ > 0) - { - sprintf(insertSql, "'%s-Z','%02x%02x','%s',0,'1','%s' ", strMeasurementID.c_str(),(wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,localtimestamp,""); - sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql); - } - scheduler::instance().WaveSuccess(wave_shortAddr); - }else{ - if(scheduler::instance().WaveError(wave_shortAddr) < 0){ - zlog_error(zct, "wave size is 0,shortAddr %02x%02x", (wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF); - } - } + std::string ran = ""; int n = 0; @@ -854,7 +828,50 @@ void Uart::DealWave() { g_VecWaveDataZ.clear(); VecWaveDataZ.clear(); } + char localtimestamp[32] = {0}; + GetTimeNet(localtimestamp, 1); + char insertSql[100] = {0x00}; + char whereCon[50] = {0x00}; + sprintf(whereCon, "MeasurementID='%s'",strMeasurementID.c_str()); + memset(whereCon, 0x00, sizeof(whereCon)); + if (vecDataX.size() > 0) + { + sprintf(insertSql, "'%s-X','%02x%02x','%s',0,'1','%s' ", strMeasurementID.c_str(),(wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,localtimestamp,""); + sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql); + } + if (vecDataY.size() > 0) + { + sprintf(insertSql, "'%s-Y','%02x%02x','%s',0,'1','%s' ", strMeasurementID.c_str(),(wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,localtimestamp,""); + sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql); + } + if (vecDataZ.size() > 0) + { + sprintf(insertSql, "'%s-Z','%02x%02x','%s',0,'1','%s' ", strMeasurementID.c_str(),(wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,localtimestamp,""); + sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql); + } + zlog_warn(zct,"waveCountX = %d, waveCountY = %d, waveCountZ = %d", vecDataX.size() , vecDataY.size(), vecDataZ.size()); + zlog_warn(zct,"CountX = %d, CountY = %d, CountZ = %d", g_mapCompress[strShortAddr].CountX , g_mapCompress[strShortAddr].CountY, g_mapCompress[strShortAddr].CountZ); + if ((vecDataX.size() <= 0 && g_mapCompress[strShortAddr].CountX > 0) || + (vecDataY.size() <= 0 && g_mapCompress[strShortAddr].CountY > 0) || + (vecDataZ.size() <= 0 && g_mapCompress[strShortAddr].CountZ > 0)) + { + scheduler::instance().WaveError(wave_shortAddr); + }else if ((vecDataX.size() > 0 && g_mapCompress[strShortAddr].CountX > 0) || + (vecDataY.size() > 0 && g_mapCompress[strShortAddr].CountY > 0) || + (vecDataZ.size() > 0 && g_mapCompress[strShortAddr].CountZ > 0)) + { + scheduler::instance().WaveSuccess(wave_shortAddr); + } + g_mapCompress[strShortAddr].CountX = 0; + g_mapCompress[strShortAddr].CountY = 0; + g_mapCompress[strShortAddr].CountZ = 0; + g_mapCompress[strShortAddr].compressChannelX = 0; + g_mapCompress[strShortAddr].compressChannelY = 0; + g_mapCompress[strShortAddr].compressChannelZ = 0; + std::vector().swap(vecDataX); + std::vector().swap(vecDataY); + std::vector().swap(vecDataZ); wave_trans_ = false; } }