From 06b9fe215e6659889ff204196ac1f866b45bac09 Mon Sep 17 00:00:00 2001 From: zhangsheng Date: Mon, 28 Apr 2025 15:42:53 +0800 Subject: [PATCH] add code --- scheduler/schedule.cpp | 2 +- scheduler/schedule.hpp | 2 +- uart/uart.cpp | 65 ++++++++++++++++++++++++++-------- uart/uart.hpp | 6 ++++ uart/uart_feature_parse.cpp | 4 ++- uart/uart_parameter_config.cpp | 7 ++-- 6 files changed, 67 insertions(+), 19 deletions(-) diff --git a/scheduler/schedule.cpp b/scheduler/schedule.cpp index ac302b3..a534cff 100644 --- a/scheduler/schedule.cpp +++ b/scheduler/schedule.cpp @@ -284,7 +284,7 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) { return available_ts; } -int SensorScheduler::GetNextDuration(int short_addr) { +int SensorScheduler::GetNextDuration(int short_addr,int next_taskID) { int id = 0; auto iter = short_addr_map_.find(short_addr); if (iter == short_addr_map_.end()) { diff --git a/scheduler/schedule.hpp b/scheduler/schedule.hpp index baff1e6..d5289c7 100644 --- a/scheduler/schedule.hpp +++ b/scheduler/schedule.hpp @@ -39,7 +39,7 @@ public: // 上面4个结束,调GetNextDuration()获取休眠时间 // 如果是kScheduleWrongTime, 此函数next_duration表明休眠时间 int StartSchedule(int short_addr, int &next_duration); - int GetNextDuration(int short_addr); + int GetNextDuration(int short_addr,int next_taskID = 3); int WaveError(uint16_t short_addr); void WaveSuccess(uint16_t short_addr); diff --git a/uart/uart.cpp b/uart/uart.cpp index f9b57c7..a3fa925 100644 --- a/uart/uart.cpp +++ b/uart/uart.cpp @@ -339,12 +339,6 @@ int Uart::DealAskTask(uint16_t ushortAdd){ zlog_info(zct, "taskID = %d ", taskID); if (taskID == kScheduleEigenValue) //1.特征值 { - char localtimestamp[32] = {0x00}; - int millisecond = 0; - std::string rtcTime = GetRTC(localtimestamp, millisecond); - scheduleTask.cmd = MEAS_EVAL; - scheduleTask.shortAddr = ushortAdd; - scheduleTask.timeStamp = atoi(localtimestamp); TaskResp(scheduleTask); } else if (taskID == kScheduleWaveForm) //2.波形 @@ -392,13 +386,19 @@ int Uart::DealException(const char* pData){ int Uart::DealReviveDuration(uint16_t ushortAdd){ + char localtimestamp[32] = {0x00}; ScheduleTask scheduleTask; - uint16_t next_duration = scheduler::instance().GetNextDuration(ushortAdd); + int next_taskID = 0; + uint16_t next_duration = scheduler::instance().GetNextDuration(ushortAdd,next_taskID); zlog_info(zct, "next_duration = %d ", next_duration); scheduleTask.cmd = REVIVE_DURATION; scheduleTask.shortAddr = ushortAdd; scheduleTask.duration = next_duration; - + scheduleTask.next_taskID = next_taskID & 0xFF; + int millisecond = 0; + std::string rtcTime = GetRTC(localtimestamp, millisecond); + scheduleTask.timeStamp = atoi(localtimestamp); + scheduleTask.millisecond = millisecond; TaskResp(scheduleTask); return 0; } @@ -416,6 +416,7 @@ int Uart::DealConfig(uint16_t ushortAdd){ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){ zlog_info(zct, "DealWaveCompress "); + now_task = WAVE_CMD; char buf[20] = {0x00}; sprintf(buf, "%02x%02x", (ushortAdd >> 8) & 0xFF, ushortAdd & 0xFF); std::string strShortAddr = std::string(buf); @@ -430,6 +431,37 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){ g_mapCompress[strShortAddr] = tempchannel; + char sensor_rssi[10] = {0x00}; + sprintf(sensor_rssi, "%02d", pData[22] & 0xFF); + if (!strcmp(sensor_rssi, "00") || !strcmp(sensor_rssi, "0")) { + char errorInfo[100] = {0x00}; + sprintf(errorInfo, "No RSSI %s", sensor_rssi); + zlog_error(zct, errorInfo); + } else { + char tableName[100] = {0x00}; + char whereCon[100] = {0}; + char updateSql[100] = {0}; + sprintf(whereCon, "zigbeeShortAddr='%02x%02x'", UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd)); + vec_t vecDataNodeNo = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " MeasurementID,RSSI ", whereCon); + sprintf(tableName, "t_dataStatic_%s", (char *)vecDataNodeNo[0].c_str()); + memset(whereCon,0,sizeof(whereCon)); + sprintf(whereCon, "dataNodeNo='%s' order by timeStamp desc limit 1", vecDataNodeNo[0].c_str()); + std::string timestamp_last = sqlite_db_ctrl::instance().GetData(tableName, " timeStamp ", whereCon); + sprintf(updateSql, "zigbeeSignalNode = '%02d' ",atoi(sensor_rssi)); + memset(whereCon,0,sizeof(whereCon)); + sprintf(whereCon, "dataNodeNo='%s' and timeStamp = '%s'", (char*)vecDataNodeNo[0].c_str(),timestamp_last.c_str()); + sqlite_db_ctrl::instance().UpdateTableData(tableName, updateSql, whereCon); + + std::vector vParamRSSI; + boost::split(vParamRSSI, vecDataNodeNo[1], boost::is_any_of(","), boost::token_compress_on); + memset(updateSql,0,sizeof(updateSql)); + memset(whereCon,0,sizeof(whereCon)); + if (vParamRSSI.size() > 0) { + sprintf(updateSql, "RSSI = '%s,%02d' ", vParamRSSI[0].c_str(), pData[7] & 0xFF); + sprintf(whereCon, "dataNodeNo='%s'", (char *)vecDataNodeNo[0].c_str()); + sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon); + } + } zlog_info(zct, "count X = %d,Y = %d,Z = %d ", tempchannel.CountX, tempchannel.CountY, tempchannel.CountZ); zlog_info(zct, "compress X = %d,Y = %d,Z = %d ", tempchannel.compressChannelX, tempchannel.compressChannelY, tempchannel.compressChannelZ); return 0; @@ -529,19 +561,17 @@ void Uart::DealRecvData(const char *pData) { break; case UPGRADE: if (recvcode == 0){ - DealUpgrade(ushortAdd,2); - scheduler::instance().UpgradeResult(ushortAdd,0); - zlog_info(zbt, "[UPGRADE SUCCESS] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode); + zlog_info(zbt, "[UPLOAD SUCCESS] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode); }else if (recvcode == 5) { DealUpgrade(ushortAdd,2); scheduler::instance().UpgradeResult(ushortAdd,0); - zlog_warn(zbt, "[UPGRADE ALREADY] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode); + zlog_warn(zbt, "[UPLOAD ALREADY] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode); }else { DealUpgrade(ushortAdd,3); scheduler::instance().UpgradeResult(ushortAdd,recvcode); - zlog_warn(zbt, "[UPGRADE FAILED] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode); + zlog_warn(zbt, "[UPLOAD FAILED] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode); } break; case CONFIG: @@ -581,7 +611,14 @@ void Uart::DealDataNodeName(const char *pData) { } char MeasurementID[100] = {0x00}; sprintf(MeasurementID, "%02x%02x%02x%02x%02x%02x%02x%02x", pData[71], pData[72], pData[73], pData[74], pData[75], pData[76], pData[77], pData[78]); - sprintf(nodeWaveSend, "%d,%d,%d", GET_BIT(pData[79], 0), GET_BIT(pData[79], 1), GET_BIT(pData[79], 2)); + uint8_t upgrade = pData[79] & 0xFF; + if (upgrade == 1) + { + uint16_t ushortAdd = BUILD_UINT16(pData[3] & 0xFF, pData[4] & 0xFF); + DealUpgrade(ushortAdd,2); + scheduler::instance().UpgradeResult(ushortAdd,0); + } + char gbkNodeName[128] = {0x00}; sprintf(whereCon, "zigbeeShortAddr='%s'", szShortAdd); zlog_info(zct, "whereCon = %s", whereCon); diff --git a/uart/uart.hpp b/uart/uart.hpp index 25ca150..f492b66 100644 --- a/uart/uart.hpp +++ b/uart/uart.hpp @@ -118,11 +118,17 @@ typedef struct ScheduleTask_{ uint16_t shortAddr; uint16_t duration; uint32_t timeStamp; + uint16_t millisecond; + uint8_t next_taskID; + uint8_t acc_z; ScheduleTask_(){ cmd = 0; shortAddr = 0; duration = 0; timeStamp = 0; + millisecond = 0; + next_taskID = 0; + acc_z = 0; } } ScheduleTask; diff --git a/uart/uart_feature_parse.cpp b/uart/uart_feature_parse.cpp index c29f592..02f6c37 100644 --- a/uart/uart_feature_parse.cpp +++ b/uart/uart_feature_parse.cpp @@ -1040,7 +1040,9 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan } //传感器发来的数据包中的表示设备信息的数据转化为json格式后,通过调用data_publish将数据传给mqttclient : Topic:wireless/cmd/60294D203717 - int iRet = data_publish(WaveData.c_str(), GlobalConfig::Topic_G.mPubWaveData.c_str()); + int iRet = data_publish(WaveData.c_str( + + ), GlobalConfig::Topic_G.mPubWaveData.c_str()); if (iRet != 0) { char whereCon[1024] = {0x00}; char updateSql[1024] = {0x00}; diff --git a/uart/uart_parameter_config.cpp b/uart/uart_parameter_config.cpp index 9ea0ec4..19113b5 100644 --- a/uart/uart_parameter_config.cpp +++ b/uart/uart_parameter_config.cpp @@ -562,12 +562,15 @@ int Uart::TaskResp(ScheduleTask scheduleTask){ { UpdateData[7] = UINT16_LOW(scheduleTask.duration); UpdateData[8] = UINT16_HIGH(scheduleTask.duration); - }else if (scheduleTask.cmd == MEAS_EVAL) - { UpdateData[9] = UINT32_LOW_2(scheduleTask.timeStamp); UpdateData[10] = UINT32_LOW_1(scheduleTask.timeStamp); UpdateData[11] = UINT32_HIGH_2(scheduleTask.timeStamp); UpdateData[12] = UINT32_HIGH_1(scheduleTask.timeStamp); + UpdateData[20] = UINT16_HIGH(scheduleTask.acc_z); + UpdateData[21] = UINT16_HIGH(scheduleTask.next_taskID); + UpdateData[22] = UINT32_LOW_2(scheduleTask.millisecond); + UpdateData[23] = UINT32_LOW_1(scheduleTask.millisecond); + }else if (scheduleTask.cmd == WAVE_CMD) { uint8_t x,y,z;