diff --git a/common/common_func.cpp b/common/common_func.cpp index 92c2754..18ab671 100644 --- a/common/common_func.cpp +++ b/common/common_func.cpp @@ -1500,7 +1500,7 @@ void IniWriteValue(const char *section, const char *key, char *val, const char * } fclose(fp); if (!bFoundSection) { - zlog_error(zct, "No section = %s", section); + zlog_warn(zct, "No section = %s", section); } else if (!bFoundKey) { zlog_error(zct, "No key = %s", key); } diff --git a/dbaccess/sql_db.cpp b/dbaccess/sql_db.cpp index ffe637d..3929d64 100644 --- a/dbaccess/sql_db.cpp +++ b/dbaccess/sql_db.cpp @@ -1090,7 +1090,7 @@ int SqliteDB::InintGateway() { jsonVal["cmdBody"] = dataBody; res = data_publish(showValue.write(jsonVal).c_str(), GlobalConfig::Topic_G.mPubConfig.c_str()); if(res !=0 ){ - zlog_error(zct, "data_publish res = %d", res); + zlog_warn(zct, "data_publish res = %d", res); } jsBody.clear(); jsonVal["cmd"] = "25"; @@ -1105,7 +1105,7 @@ int SqliteDB::InintGateway() { jsonVal["cmdBody"] = dataBody; res = data_publish(showValue.write(jsonVal).c_str(), GlobalConfig::Topic_G.mPubConfig.c_str()); if(res !=0 ){ - zlog_error(zct, "data_publish res = %d", res); + zlog_warn(zct, "data_publish res = %d", res); } return res; } diff --git a/jsonparse/web_cmd_parse2.cpp b/jsonparse/web_cmd_parse2.cpp index 3298016..488eef6 100644 --- a/jsonparse/web_cmd_parse2.cpp +++ b/jsonparse/web_cmd_parse2.cpp @@ -745,9 +745,6 @@ std::string JsonData::JsonCmd_Cgi_42(Param_42 ¶m) { jsonVal["message"] = str; } - } else { - jsonVal["success"] = false; - jsonVal["message"] = "文件名错误!"; } return show_value_.write(jsonVal); } diff --git a/jsonparse/web_cmd_parse3.cpp b/jsonparse/web_cmd_parse3.cpp index 5385a71..5acdbd6 100644 --- a/jsonparse/web_cmd_parse3.cpp +++ b/jsonparse/web_cmd_parse3.cpp @@ -620,12 +620,18 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 ¶m){ char cmd[64]={0}; sprintf(cmd, "mv /opt/%s /opt/DataNode/",param.fileName.c_str()); system(cmd); - sprintf(file_path, "/opt/DataNodeNo/%s",param.fileName.c_str()); + sprintf(file_path, "/opt/DataNode/%s",param.fileName.c_str()); + zlog_info(zct,"file_path = %s",file_path); FILE * pFile=NULL; size_t thisSize = 0; char *buffer=NULL; pFile = fopen (file_path,"rb"); - if (pFile==NULL) zlog_error(zct,"Error opening file"); + if (pFile==NULL) { + zlog_error(zct,"Error opening file"); + jsonVal["success"] = false; + jsonVal["message"] = "Error opening file"; + return show_value_.write(jsonVal); + } else { while (fgetc(pFile) != EOF) { @@ -636,14 +642,29 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 ¶m){ fread (buffer, sizeof (char), thisSize, pFile); fclose (pFile); } - - printf("Read %zu bytes\n", thisSize); - fclose(pFile); - + + + zlog_info(zct,"Read %zu bytes", thisSize); char sensor_type[6] = {0}; char sf_version[10] = {0}; memcpy(sensor_type, buffer, 5); - printf("model:%s\n", sensor_type); + zlog_info(zct,"model:%s", sensor_type); + if (param.product == 1 ){ + if (strcmp(sensor_type,"DN101") != 0){ + jsonVal["success"] = false; + jsonVal["message"] = "product error"; + free(buffer); + return show_value_.write(jsonVal); + } + }else if(param.product == 2){ + if (strcmp(sensor_type,"DN102") != 0){ + jsonVal["success"] = false; + jsonVal["message"] = "product error"; + free(buffer); + return show_value_.write(jsonVal); + } + } + char c[2] = {0}; c[0] = buffer[5]; uint8_t hw_ver = atoi(c); @@ -681,6 +702,7 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 ¶m){ { char wherecon[100] = {0}; char insertSql[200] = {0}; + char updateSql[100] = {0}; sprintf(wherecon," dataNodeNo = '%s' ",param.dataNodeNo[i].c_str()); vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " hardVersion,softVersion,ProductNo,zigbeeShortAddr ", wherecon); if (hw_ver != atoi(vecResult[0].c_str())) @@ -693,7 +715,16 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 ¶m){ sprintf(insertSql, " '%s','%s','','','','','%d.%d','%s',1,'%s'",vecResult[3].c_str(),localtimestamp,sf_ver_m,sf_ver_s,vecResult[1].c_str(),param.fileName.c_str()); sqlite_db_ctrl::instance().InsertData(" firmware_upgrade ", insertSql); - scheduler::instance().UpgradeSensor(atoi(vecResult[3].c_str()),std::string(sensor_type),atoi(vecResult[0].c_str()),vecResult[1],std::string(sf_version)); + //0 默认状态,1 升级中,2 升级成功,3 升级失败 + memset(wherecon,0,sizeof(wherecon)); + memset(updateSql,0,sizeof(updateSql)); + sprintf(wherecon," zigbeeShortAddr = '%s'",vecResult[3].c_str()); + sprintf(updateSql, " upgradeStatus = %d ", 1); + sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql,wherecon); + uint16_t short_addr; + char *end_ptr = NULL; + short_addr = strtol(vecResult[3].c_str(), &end_ptr, 16); + scheduler::instance().UpgradeSensor(short_addr,std::string(sensor_type),atoi(vecResult[0].c_str()),vecResult[1],std::string(sf_version)); } free(buffer); return show_value_.write(jsonVal); diff --git a/threadfunc/thread_func.cpp b/threadfunc/thread_func.cpp index 5d21211..e7eb96b 100644 --- a/threadfunc/thread_func.cpp +++ b/threadfunc/thread_func.cpp @@ -47,6 +47,7 @@ void RunLED() { } void HeartRep() { + int count = 0; while (1) { Json::Value jsHeart; Json::FastWriter fw; @@ -56,9 +57,15 @@ void HeartRep() { std::string strJson = fw.write(jsHeart); int iRet = data_publish(strJson.c_str(), GlobalConfig::Topic_G.mPubHeart.c_str()); if (iRet != 0) { - zlog_error(zct, "fail to send heart mqtt msg"); + zlog_warn(zct, "fail to send heart mqtt msg"); } - zlog_info(zct, "heart = %s,iRet = %d", strJson.c_str(), iRet); + if (count == 10){ + zlog_warn(zct, "heart = %s,iRet = %d", strJson.c_str(), iRet); + count = 0; + }else{ + zlog_info(zct, "heart = %s,iRet = %d", strJson.c_str(), iRet); + } + if (iRet != 0) { gpio_set(GlobalConfig::GPIO_G.errorLed, 1); sleep(1); @@ -76,6 +83,7 @@ void HeartRep() { gpio_set(GlobalConfig::GPIO_G.errorLed, 0); } sleep(30); + count ++; } } diff --git a/uart/uart.cpp b/uart/uart.cpp index c2cb9aa..7f4aeb8 100644 --- a/uart/uart.cpp +++ b/uart/uart.cpp @@ -47,7 +47,7 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) { timeoutflag++; if (timeoutflag > 100) { DealReviveDuration(wave_shortAddr); - zlog_info(zct, "===============0x9999 timeout= %d offSize = %d===============", timeoutflag, offSize); + zlog_info(zct, "===============0x9999 timeout= %d offSize = %d===============shortAddr = %02x%02x", timeoutflag, offSize,UINT16_HIGH(wave_shortAddr),UINT16_LOW(wave_shortAddr)); zlog_info(zct, "0x9999 timeout %d===============Size = %d", timeoutflag, offSize); FindRecvPackage(offSize, mUartRecvTmpBuf, head); now_task = -1; @@ -352,7 +352,17 @@ void int2bytes(int i, unsigned char *bytes, int size) { bytes[2] = (unsigned char)((0xff0000 & i) >> 16); bytes[3] = (unsigned char)((0xff000000 & i) >> 24); } - +int Uart::GetLocalZigbeeRSSI(uint16_t ushortAdd){ + zlog_info(zct, "Local Zigbee Signal !\n"); + int Times = 0; + mssleep(20000); + while (Times < 3) { + getZigbeeSignal(ushortAdd); + Times++; + mssleep(20000); + } + mssleep(10000); +} int Uart::DealAskTask(uint16_t ushortAdd){ ModifyDistAddr(ushortAdd); @@ -372,11 +382,17 @@ int Uart::DealAskTask(uint16_t ushortAdd){ } else if (taskID == kScheduleWaveForm) //2.波形 { + GetLocalZigbeeRSSI(ushortAdd); now_task = WAVE_CMD; scheduleTask.cmd = WAVE_CMD; scheduleTask.shortAddr = ushortAdd; wave_shortAddr = ushortAdd; TaskResp(scheduleTask); + mssleep(50000); + scheduleTask.cmd = SIGNAL_STRENGTH; + scheduleTask.shortAddr = ushortAdd; + scheduleTask.duration = next_duration; + TaskResp(scheduleTask); } else if (taskID == kScheduleUpgrade) //3.升级 { @@ -512,21 +528,20 @@ void Uart::DealRecvData(const char *pData) { DealReviveDuration(ushortAdd); break; case UPGRADE: - if (recvcode == 0) - { + if (recvcode == 0){ 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); }else{ - zlog_error(zct, "shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode); + scheduler::instance().UpgradeResult(ushortAdd,recvcode); + zlog_error(zbt, "[UPGRADE FAILED] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode); } break; case CONFIG: - if (recvcode == 0) - { + if (recvcode == 0){ DealReviveDuration(ushortAdd); - DealConfig(ushortAdd); - + DealConfig(ushortAdd); }else{ - zlog_error(zct, "shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode); + zlog_error(zbt, "[CONFIG] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode); } break; case WAVE_COMPRESS: diff --git a/uart/uart.hpp b/uart/uart.hpp index 97851e6..8028c58 100644 --- a/uart/uart.hpp +++ b/uart/uart.hpp @@ -172,6 +172,7 @@ public: int DealConfig(uint16_t ushortAdd); int DealWaveCompress(const char *pData,uint16_t ushortAdd); int DealSensorRSSI(const char *pData,uint16_t ushortAdd); + int GetLocalZigbeeRSSI(uint16_t ushortAdd); // feature parse void DealDataNodeFeature(const char* pData, int flag); @@ -193,7 +194,7 @@ public: void ModifyDistAddr(uint16_t distAddr); void modify_Localchannel(unsigned char pad); void modify_LocalPanID(unsigned short padID); - void getZigbeeSignal(unsigned char* distAddr); + void getZigbeeSignal(uint16_t ushortAdd); void zigbee_reset(unsigned short pad, unsigned short type); void WriteChanl2Zigbee(unsigned char pad); void WritePanId2Zigbee(unsigned short pad); diff --git a/uart/uart_cmd.cpp b/uart/uart_cmd.cpp index a1aec5f..dcc5fe7 100644 --- a/uart/uart_cmd.cpp +++ b/uart/uart_cmd.cpp @@ -18,15 +18,15 @@ void Uart::modify_distaddr_info(unsigned short id, char *zigbee, unsigned char * WriteToUart(command1, 6); } -void Uart::getZigbeeSignal(unsigned char *distAddr) { +void Uart::getZigbeeSignal(uint16_t ushortAdd) { mssleep(10000); char command[6] = {0x00}; command[0] = 0xDE; command[1] = 0xDF; command[2] = 0xEF; command[3] = 0xDA; - command[4] = distAddr[0]; - command[5] = distAddr[1]; + command[4] = UINT16_HIGH(ushortAdd); + command[5] = UINT16_LOW(ushortAdd); WriteToUart(command, 6); } diff --git a/uart/uart_feature_parse.cpp b/uart/uart_feature_parse.cpp index 670b1ff..a4546de 100644 --- a/uart/uart_feature_parse.cpp +++ b/uart/uart_feature_parse.cpp @@ -70,37 +70,13 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { std::string strLongAddr = vecResult[1]; std::string strMeasurementID = vecResult[2]; std::string strProductNo = vecResult[3]; - if (1 == flag) { - tcflush(fd, TCIOFLUSH); - if (!bSendTimeStamp) { - bSendTimeStamp = true; - mssleep(10000); + memset(whereCon, 0x00, sizeof(whereCon)); + memset(updateSql, 0x00, sizeof(updateSql)); + sprintf(whereCon, "zigbeeShortAddr='%s'", strShortAddr.c_str()); + sprintf(updateSql, " StaticTime = StaticTime + 1"); + sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon); - zlog_info(zct, "Zigbee Signal !\n"); - int Times = 0; - mssleep(20000); - while (Times < 3) { - getZigbeeSignal(pRecvData->ShortAddr); - Times++; - mssleep(20000); - } - mssleep(10000); - } else { - return; - } - - m_strDestShortAddr = std::string(buf); - - - - } else { - memset(whereCon, 0x00, sizeof(whereCon)); - memset(updateSql, 0x00, sizeof(updateSql)); - sprintf(whereCon, "zigbeeShortAddr='%s'", strShortAddr.c_str()); - sprintf(updateSql, " StaticTime = StaticTime + 1"); - sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon); - } if (vecResult[0] == "3.0" || vecResult[0] == "4.0") { return;