diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index a813cfe..9f396fc 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/scheduler/schedule.cpp b/scheduler/schedule.cpp index 6d8e538..4fa9ee5 100644 --- a/scheduler/schedule.cpp +++ b/scheduler/schedule.cpp @@ -394,7 +394,7 @@ SensorScheduler::SensorScheduler() { UpdateCfg::ReadCfg(update_); } -int SensorScheduler::WaveError(int short_addr) { +int SensorScheduler::WaveError(uint16_t short_addr) { auto iter = failure_map_.find(short_addr); if (iter == failure_map_.end()) { failure_map_[short_addr] = 3; // 重试次数 @@ -427,7 +427,7 @@ bool SensorScheduler::MissedWave(uint16_t short_addr) { return false; } -void SensorScheduler::WaveSuccess(int short_addr) { +void SensorScheduler::WaveSuccess(uint16_t short_addr) { success_set_.insert(short_addr); auto iter = failure_map_.find(short_addr); if (iter != failure_map_.end()) { diff --git a/scheduler/schedule.hpp b/scheduler/schedule.hpp index 3642d40..dae6c56 100644 --- a/scheduler/schedule.hpp +++ b/scheduler/schedule.hpp @@ -41,8 +41,8 @@ public: int StartSchedule(int short_addr, int &next_duration); int GetNextDuration(int short_addr); - int WaveError(int short_addr); - void WaveSuccess(int short_addr); + int WaveError(uint16_t short_addr); + void WaveSuccess(uint16_t short_addr); long GetBaseTimestamp(int id); long CalcNextTimestamp(int id, uint16_t short_addr); diff --git a/uart/uart.cpp b/uart/uart.cpp index 0dd6146..8ad9275 100644 --- a/uart/uart.cpp +++ b/uart/uart.cpp @@ -59,13 +59,12 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) { mssleep(10000); wave_trans_ = true; memset(mUartRecvTmpBuf, 0, BUF_LENGTH); - zlog_warn(zct, "wave end"); + zlog_warn(zct, "wave end,now_task = %d", now_task); } mssleep(10000); } else if (ret > 0) { maxSize += ret; timeoutflag = 0; - m_TimeStamp = 0; memcpy(mUartRecvTmpBuf + offSize, buff, ret); offSize = offSize + ret; if (offSize > BUF_LENGTH * 15) { @@ -99,7 +98,6 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) { Uart::Uart() : mUart(mIoSev), mStrand(mIoSev) { mRdLength = 0; - m_TimeStamp = 0; mlastSize = 0; fd = 0; waittime = 0; @@ -1021,7 +1019,9 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { memset(mUartRecvTmpBuf, 0x00, sizeof(mUartRecvTmpBuf)); } memcpy(UartRecvBuf + mlastSize, mUartRecvBuf, bytesRead); - + bool wave_error_x = false; + bool wave_error_y = false; + bool wave_error_z = false; bytesRead = bytesRead + mlastSize; for (int i = 0; i < bytesRead; i++) { if (UartRecvBuf[i] == head[0]) { @@ -1035,18 +1035,33 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { char buf[8] = {0x00}; sprintf(buf, "%02d", UartRecvBuf[i + 5]); int command = atoi(buf); - //zlog_info(zct, "command = %d ShortAddr :%s", command, strShortAddr.c_str()); - if ((mPackgeIndex == -1 || (unsigned int)UartRecvBuf[i + 6] == 0) && (command == WAVE_X || command == WAVE_Y || command == WAVE_Z) ) { + if (wave_error_x && !wave_error_y && !wave_error_z && command == WAVE_X) + { + continue; + } + else if (wave_error_x && wave_error_y && !wave_error_z && command == WAVE_Y) + { + continue; + } + if ( wave_error_z && command == WAVE_Z) + { + m_waveCountX = 0; + m_waveCountY = 0; + m_waveCountZ = 0; + g_VecWaveDataX.clear(); + g_VecWaveDataY.clear(); + g_VecWaveDataZ.clear(); + break; + } + if ((mPackgeIndex == -1 || (unsigned int)UartRecvBuf[i + 6] == 0) && (command == WAVE_X || command == WAVE_Y || command == WAVE_Z) && now_task == WAVE_CMD) { mPackgeIndex = UartRecvBuf[i + 6] & 0xFF; - } else if ((unsigned int)mPackgeIndex == (unsigned int)UartRecvBuf[i + 6] && mPackgeIndex != -1 && command != 2 && (command == WAVE_X || command == WAVE_Y || command == WAVE_Z)) { + } else if ((unsigned int)mPackgeIndex == (unsigned int)UartRecvBuf[i + 6] && mPackgeIndex != -1 && command != 2 && (command == WAVE_X || command == WAVE_Y || command == WAVE_Z) && now_task == WAVE_CMD) { zlog_warn(zct, "mPackgeIndex same index1:%d,index2:%02d ShortAddr :%s ", mPackgeIndex, UartRecvBuf[i + 6] & 0xff, strShortAddr.c_str()); continue; - } else if ((unsigned int)mPackgeIndex + 1 != (unsigned int)UartRecvBuf[i + 6] && mPackgeIndex != -1 && command != 2 && (command == WAVE_X || command == WAVE_Y || command == WAVE_Z)) { - m_TimeStamp = 0; + } else if ((unsigned int)mPackgeIndex + 1 != (unsigned int)UartRecvBuf[i + 6] && mPackgeIndex != -1 && command != 2 && (command == WAVE_X || command == WAVE_Y || command == WAVE_Z) && now_task == WAVE_CMD) { - zlog_warn(zct, "mPackgeIndex error index1:%d,index2:%02d ShortAddr :%s ", mPackgeIndex, UartRecvBuf[i + 6] & 0xff, strShortAddr.c_str()); - mPackgeIndex = -1; + zlog_warn(zct, "mPackgeIndex error index1:%d,index2:%02d ShortAddr :%s ,now_task = %d", mPackgeIndex, UartRecvBuf[i + 6] & 0xff, strShortAddr.c_str(),now_task); zlog_warn(zct, "mPackgeIndex error ShortAddr :%s", strShortAddr.c_str()); char tmp[10] = {0x00}; @@ -1056,7 +1071,6 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { strcat(tmp2, tmp); } zlog_warn(zct, "error str = %s", tmp2); - char insertSql[100] = {0x00}; char whereCon[50] = {0x00}; std::string error_msg = ""; @@ -1067,26 +1081,29 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { if (command == WAVE_X){ error_msg = "Index error,wave X"; strChannelID = strMeasurementID + "-X"; + wave_error_x = true; }else if (command == WAVE_Y){ error_msg = "Index error,wave Y"; strChannelID = strMeasurementID + "-Y"; + wave_error_y = true; }else if (command == WAVE_Z){ error_msg = "Index error,wave Z"; strChannelID = strMeasurementID + "-Z"; + wave_error_z = true; } - - 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); + 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); + } + JsonData jd; jd.JsonCmd_32(strMeasurementID,1,1,strChannelID,error_msg); - - break; + continue; } if (now_task == WAVE_CMD && (command == WAVE_X || command == WAVE_Y || command == WAVE_Z)) { if (!CheckCrc(&UartRecvBuf[i], 99)) { - m_TimeStamp = 0; - mPackgeIndex = -1; zlog_warn(zct, "CheckCrc error ShortAddr :%s command = %d", strShortAddr.c_str(), command); char tmp[10] = {0x00}; char tmp2[10] = {0x00}; @@ -1095,12 +1112,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { strcat(tmp2, tmp); } zlog_error(zct, "error str = %s", tmp2); - m_waveCountX = 0; - m_waveCountY = 0; - m_waveCountZ = 0; - g_VecWaveDataX.clear(); - g_VecWaveDataY.clear(); - g_VecWaveDataZ.clear(); + char insertSql[100] = {0x00}; char whereCon[50] = {0x00}; std::string error_msg = ""; @@ -1111,19 +1123,24 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { if (command == WAVE_X){ error_msg = "Crc error,wave X"; strChannelID = strMeasurementID + "-X"; + wave_error_x = true; }else if (command == WAVE_Y){ error_msg = "Crc error,wave Y"; strChannelID = strMeasurementID + "-Y"; + wave_error_y = true; }else if (command == WAVE_Z){ error_msg = "Crc error,wave Z"; 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); } - 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); - - break; + continue; } mlastSize = 0; lastSize = bytesRead - i; diff --git a/uart/uart_feature_parse.cpp b/uart/uart_feature_parse.cpp index 2c1fd03..c15e8b0 100644 --- a/uart/uart_feature_parse.cpp +++ b/uart/uart_feature_parse.cpp @@ -11,6 +11,7 @@ #include "mqttclient/mqtt_client.h" #include "minilzo/minilzo.h" #include "jsonparse/communication_cmd.hpp" +#include "scheduler/schedule.hpp" extern zlog_category_t *zct; extern zlog_category_t *zbt; @@ -802,7 +803,7 @@ void Uart::DealWave() { 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); } std::string ran = ""; @@ -847,8 +848,6 @@ void Uart::DealWave() { g_VecWaveDataZ.clear(); VecWaveDataZ.clear(); } - - wave_trans_ = false; }