diff --git a/uart/uart.cpp b/uart/uart.cpp index fd7e68b..63abdae 100644 --- a/uart/uart.cpp +++ b/uart/uart.cpp @@ -86,6 +86,7 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) { } if (srcshow) { zlog_info(zct, "0x8888 ===str_recv===,ret = %d", ret); + printf("\ncurrent time = %s\n", GetCurrentTime().c_str()); for (int i = 0; i < ret; i++) { printf("[%02x]", buff[i] & 0xff); } @@ -118,6 +119,7 @@ Uart::Uart() : mUart(mIoSev), mStrand(mIoSev) { VecWaveDataX.reserve(1000); VecWaveDataY.reserve(1000); VecWaveDataZ.reserve(1500); + memset(send_data, 0, sizeof(send_data)); } Uart::~Uart() { @@ -227,7 +229,7 @@ int Uart::ZigbeeTest() { void Uart::WriteToUart(const char *strSend, int pLen) { if (!bUpdate) { - printf( "Write To Uart Start:\n"); + printf( "\nWrite To Uart Start: %s\n",GetCurrentTime().c_str()); for (int i = 0; i < pLen; i++) { printf("%02X ", *(strSend + i) & 0xFF); } @@ -334,7 +336,6 @@ int Uart::DealAskTask(uint16_t ushortAdd){ zlog_warn(zct, "device info not found %02x%02x ", UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd)); return 1; } - ModifyDistAddr(ushortAdd); int next_duration = 0,next_task_id = 0; int taskID; ScheduleTask scheduleTask; @@ -346,7 +347,6 @@ int Uart::DealAskTask(uint16_t ushortAdd){ scheduleTask.duration = next_duration; scheduleTask.next_taskID = next_task_id; scheduleTask.shortAddr = ushortAdd; - mssleep(50000); TaskResp(scheduleTask); mssleep(50000); UpdateConfig(ushortAdd); @@ -432,8 +432,6 @@ int Uart::DealConfig(uint16_t ushortAdd){ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){ zlog_info(zct, "DealWaveCompress "); - ModifyDistAddr(ushortAdd); - mssleep(50000); now_task = WAVE_CMD; WaveResp(ushortAdd); char buf[20] = {0x00}; @@ -563,6 +561,10 @@ void Uart::DealRecvData(const char *pData) { int taskID = 0; ScheduleTask scheduleTask; zlog_info(zct, "shortAdd = %02x%02x,command = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command); + mssleep(50000); + ModifyDistAddr(ushortAdd); + mssleep(50000); + int iRet = 0; switch (command) { case DEVICE_INF: DealDataNodeInfo(pData); @@ -577,10 +579,10 @@ void Uart::DealRecvData(const char *pData) { DealException(pData); break; case MEAS_EVAL: - DealAskTask(ushortAdd); - DealDataNodeFeature(pData, 0); - - + iRet = DealDataNodeFeature(pData, 0); + if (iRet == 0){ + DealAskTask(ushortAdd); + } break; case UPGRADE: if (recvcode == 0){ @@ -611,7 +613,6 @@ void Uart::DealRecvData(const char *pData) { DealWaveCompress(pData,ushortAdd); break; case UPGRADE_ASK: - ModifyDistAddr(ushortAdd); mssleep(50000); taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration, next_task_id); taskID = kScheduleUpgrade; @@ -1239,9 +1240,9 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { memcpy(RecvBuf, (char *)&UartRecvBuf[i], 100); DealDataNodeWave(RecvBuf, command); mPackgeIndex = (unsigned int)UartRecvBuf[i + 6]; - } else if (now_task != WAVE_CMD && (command == ASK_TASK || command == DEVICE_INF || command == MEAS_EVAL || command == CONFIG || command == UPGRADE || command == DEVICE_INF2 || command == SIGNAL_STRENGTH || command == DEVICE_EXCEPTION || command == UPGRADE_ASK)) { + } else if (now_task != WAVE_CMD && ( command == DEVICE_INF || command == MEAS_EVAL || command == CONFIG || command == UPGRADE || command == DEVICE_INF2 || command == SIGNAL_STRENGTH || command == DEVICE_EXCEPTION || command == UPGRADE_ASK)) { char RecvBuf[100] = {0x00}; - if (command == ASK_TASK || command == UPGRADE_ASK) + if (command == UPGRADE_ASK) { memcpy(RecvBuf, &UartRecvBuf[i], 8); if (!CheckCrc(RecvBuf, 7)) { diff --git a/uart/uart.hpp b/uart/uart.hpp index 1b94231..5cfd88f 100644 --- a/uart/uart.hpp +++ b/uart/uart.hpp @@ -184,7 +184,7 @@ public: void GetLocalZigbeeRSSI(uint16_t ushortAdd); // feature parse - void DealDataNodeFeature(const char* pData, int flag); + int DealDataNodeFeature(const char* pData, int flag); void RecordBattery(std::string& strLongAddr, DataRecvStatic& dataStatic, std::string& nowTimetamp); void DealDataNodeWave(const char* pData, int comand); void DealWaveThread(); @@ -262,6 +262,9 @@ private: std::vector VecWaveDataX; std::vector VecWaveDataY; std::vector VecWaveDataZ; + + uint8_t send_data[100]; + std::map> map_send_data; }; typedef boost::container::dtl::singleton_default uart_inst; diff --git a/uart/uart_feature_parse.cpp b/uart/uart_feature_parse.cpp index a1432ca..4703770 100644 --- a/uart/uart_feature_parse.cpp +++ b/uart/uart_feature_parse.cpp @@ -42,7 +42,7 @@ void Uart::DataExtract(RecvData *p, int id, unsigned int &lowbit, float &n) { n = ScaleConvert(highbit); } -void Uart::DealDataNodeFeature(const char *pData, int flag) { +int Uart::DealDataNodeFeature(const char *pData, int flag) { RecvData *pRecvData = (RecvData *)pData; char whereCon[1024] = {0}; char updateSql[1024] = {0}; @@ -66,7 +66,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { if (vecResult.size() < 1) { zlog_warn(zct, "device info not found %02x%02x ", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]); - return; + return -1; } zlog_info(zct, "--------->the remote sensor short addr:%s strLongAddr=%s,softVersion = %s", buf, vecResult[1].c_str(), vecResult[0].c_str()); @@ -82,7 +82,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { if (vecResult[0] == "3.0" || vecResult[0] == "4.0") { - return; + return -2; } long nodetimestamp = BUILD_UINT32(pRecvData->Data[29], pRecvData->Data[28], pRecvData->Data[27], pRecvData->Data[26]); @@ -153,7 +153,10 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { char logInfo[100] = {0x00}; sprintf(logInfo, "ShortAddr = %s,localtimestamp = %s,staticData = %d, data = %d", strShortAddr.c_str(), localtimestamp, count, count2); zlog_info(zct, logInfo); - return; + std::vector& data_vec = map_send_data[u_short_addr]; + const uint8_t* send_data = data_vec.data(); + WriteToUart((const char*)send_data, 100); + return -3; } memset(whereCon, 0x00, sizeof(whereCon)); sprintf(szTableNameData, "t_data_%s", strMeasurementID.c_str()); @@ -598,6 +601,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { if (flag == 1) { zlog_info(zct, "DealDataNodeFeature end %02x%02x", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]); } + return 0; } float Uart::ScaleConvert(int highbit) { return 0.0001f * pow(100.0f, highbit); } diff --git a/uart/uart_parameter_config.cpp b/uart/uart_parameter_config.cpp index 60bc4b3..aeb2d64 100644 --- a/uart/uart_parameter_config.cpp +++ b/uart/uart_parameter_config.cpp @@ -550,51 +550,57 @@ int Uart::UpdateWirelessNodeTime(unsigned char* pDestShortAddr, int modifyaddr / } int Uart::TaskResp(ScheduleTask scheduleTask){ - unsigned char UpdateData[100] = {0}; - UpdateData[0] = 0xAA; - UpdateData[1] = 0x55; - UpdateData[2] = 0xAA; - UpdateData[3] = (scheduleTask.shortAddr >> 8) & 0xFF; - UpdateData[4] = scheduleTask.shortAddr & 0xFF; - UpdateData[5] = scheduleTask.cmd & 0xFF; - UpdateData[6] = 0x00; + memset(send_data,0,sizeof(send_data)); + send_data[0] = 0xAA; + send_data[1] = 0x55; + send_data[2] = 0xAA; + send_data[3] = (scheduleTask.shortAddr >> 8) & 0xFF; + send_data[4] = scheduleTask.shortAddr & 0xFF; + send_data[5] = scheduleTask.cmd & 0xFF; + send_data[6] = 0x00; char localtimestamp[32] = {0x00}; int millisecond = 0; std::string rtcTime = GetRTC(localtimestamp, millisecond); scheduleTask.timeStamp = atoi(localtimestamp); zlog_info(zct,"next taskID = %d\n",scheduleTask.next_taskID); - UpdateData[7] = UINT16_LOW(scheduleTask.duration); - UpdateData[8] = UINT16_HIGH(scheduleTask.duration); - 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] = scheduleTask.acc_z; - UpdateData[21] = scheduleTask.next_taskID & 0xFF; - UpdateData[22] = UINT16_LOW(scheduleTask.millisecond); - UpdateData[23] = UINT16_HIGH(scheduleTask.millisecond); + send_data[7] = UINT16_LOW(scheduleTask.duration); + send_data[8] = UINT16_HIGH(scheduleTask.duration); + send_data[9] = UINT32_LOW_2(scheduleTask.timeStamp); + send_data[10] = UINT32_LOW_1(scheduleTask.timeStamp); + send_data[11] = UINT32_HIGH_2(scheduleTask.timeStamp); + send_data[12] = UINT32_HIGH_1(scheduleTask.timeStamp); + send_data[20] = scheduleTask.acc_z; + send_data[21] = scheduleTask.next_taskID & 0xFF; + send_data[22] = UINT16_LOW(scheduleTask.millisecond); + send_data[23] = UINT16_HIGH(scheduleTask.millisecond); if (scheduleTask.next_taskID == WAVE_CMD) { uint8_t x,y,z; wave_feature_set_inst::instance().GetWaveCfg(scheduleTask.shortAddr,x,y,z); zlog_info(zct,"wave x = %d,y = %d,z = %d\n",x,y,z); - UpdateData[17] = (x^1) & 0xFF; - UpdateData[18] = (y^1) & 0xFF; - UpdateData[19] = (z^1) & 0xFF; + send_data[17] = (x^1) & 0xFF; + send_data[18] = (y^1) & 0xFF; + send_data[19] = (z^1) & 0xFF; } unsigned char tmp = 0x00; for (int k = 0; k < 99; k++) { - tmp += UpdateData[k]; + tmp += send_data[k]; + } + send_data[99] = tmp; + if (scheduleTask.cmd != REVIVE_DURATION) + { + mssleep(50000); + WriteToUart((const char*)send_data, 100); + mssleep(50000); + WriteToUart((const char*)send_data, 100); + }else { + map_send_data[scheduleTask.shortAddr] = std::vector(send_data, send_data + 100); } - UpdateData[99] = tmp; - mssleep(10000); - WriteToUart((const char*)UpdateData, 100); mssleep(50000); - WriteToUart((const char*)UpdateData, 100); - mssleep(50000); - WriteToUart((const char*)UpdateData, 100); + WriteToUart((const char*)send_data, 100); + int iRet = CheckZigbeeACK(); if (iRet == 0) { zlog_info(zct, "TaskResp ACK send success,shortAddr = %02x%02x", UINT16_HIGH(scheduleTask.shortAddr),UINT16_LOW(scheduleTask.shortAddr));