fix upgrade bugs

This commit is contained in:
zhangsheng 2024-11-11 20:51:40 +08:00
parent 4ef26e7865
commit dda709aadb
9 changed files with 87 additions and 59 deletions

View File

@ -1500,7 +1500,7 @@ void IniWriteValue(const char *section, const char *key, char *val, const char *
} }
fclose(fp); fclose(fp);
if (!bFoundSection) { if (!bFoundSection) {
zlog_error(zct, "No section = %s", section); zlog_warn(zct, "No section = %s", section);
} else if (!bFoundKey) { } else if (!bFoundKey) {
zlog_error(zct, "No key = %s", key); zlog_error(zct, "No key = %s", key);
} }

View File

@ -1090,7 +1090,7 @@ int SqliteDB::InintGateway() {
jsonVal["cmdBody"] = dataBody; jsonVal["cmdBody"] = dataBody;
res = data_publish(showValue.write(jsonVal).c_str(), GlobalConfig::Topic_G.mPubConfig.c_str()); res = data_publish(showValue.write(jsonVal).c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
if(res !=0 ){ if(res !=0 ){
zlog_error(zct, "data_publish res = %d", res); zlog_warn(zct, "data_publish res = %d", res);
} }
jsBody.clear(); jsBody.clear();
jsonVal["cmd"] = "25"; jsonVal["cmd"] = "25";
@ -1105,7 +1105,7 @@ int SqliteDB::InintGateway() {
jsonVal["cmdBody"] = dataBody; jsonVal["cmdBody"] = dataBody;
res = data_publish(showValue.write(jsonVal).c_str(), GlobalConfig::Topic_G.mPubConfig.c_str()); res = data_publish(showValue.write(jsonVal).c_str(), GlobalConfig::Topic_G.mPubConfig.c_str());
if(res !=0 ){ if(res !=0 ){
zlog_error(zct, "data_publish res = %d", res); zlog_warn(zct, "data_publish res = %d", res);
} }
return res; return res;
} }

View File

@ -745,9 +745,6 @@ std::string JsonData::JsonCmd_Cgi_42(Param_42 &param) {
jsonVal["message"] = str; jsonVal["message"] = str;
} }
} else {
jsonVal["success"] = false;
jsonVal["message"] = "文件名错误!";
} }
return show_value_.write(jsonVal); return show_value_.write(jsonVal);
} }

View File

@ -620,12 +620,18 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 &param){
char cmd[64]={0}; char cmd[64]={0};
sprintf(cmd, "mv /opt/%s /opt/DataNode/",param.fileName.c_str()); sprintf(cmd, "mv /opt/%s /opt/DataNode/",param.fileName.c_str());
system(cmd); 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; FILE * pFile=NULL;
size_t thisSize = 0; size_t thisSize = 0;
char *buffer=NULL; char *buffer=NULL;
pFile = fopen (file_path,"rb"); 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 else
{ {
while (fgetc(pFile) != EOF) { while (fgetc(pFile) != EOF) {
@ -637,13 +643,28 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 &param){
fclose (pFile); fclose (pFile);
} }
printf("Read %zu bytes\n", thisSize);
fclose(pFile);
zlog_info(zct,"Read %zu bytes", thisSize);
char sensor_type[6] = {0}; char sensor_type[6] = {0};
char sf_version[10] = {0}; char sf_version[10] = {0};
memcpy(sensor_type, buffer, 5); 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}; char c[2] = {0};
c[0] = buffer[5]; c[0] = buffer[5];
uint8_t hw_ver = atoi(c); uint8_t hw_ver = atoi(c);
@ -681,6 +702,7 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 &param){
{ {
char wherecon[100] = {0}; char wherecon[100] = {0};
char insertSql[200] = {0}; char insertSql[200] = {0};
char updateSql[100] = {0};
sprintf(wherecon," dataNodeNo = '%s' ",param.dataNodeNo[i].c_str()); 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); 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())) if (hw_ver != atoi(vecResult[0].c_str()))
@ -693,7 +715,16 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 &param){
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()); 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); 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); free(buffer);
return show_value_.write(jsonVal); return show_value_.write(jsonVal);

View File

@ -47,6 +47,7 @@ void RunLED() {
} }
void HeartRep() { void HeartRep() {
int count = 0;
while (1) { while (1) {
Json::Value jsHeart; Json::Value jsHeart;
Json::FastWriter fw; Json::FastWriter fw;
@ -56,9 +57,15 @@ void HeartRep() {
std::string strJson = fw.write(jsHeart); std::string strJson = fw.write(jsHeart);
int iRet = data_publish(strJson.c_str(), GlobalConfig::Topic_G.mPubHeart.c_str()); int iRet = data_publish(strJson.c_str(), GlobalConfig::Topic_G.mPubHeart.c_str());
if (iRet != 0) { if (iRet != 0) {
zlog_error(zct, "fail to send heart mqtt msg"); zlog_warn(zct, "fail to send heart mqtt msg");
} }
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); zlog_info(zct, "heart = %s,iRet = %d", strJson.c_str(), iRet);
}
if (iRet != 0) { if (iRet != 0) {
gpio_set(GlobalConfig::GPIO_G.errorLed, 1); gpio_set(GlobalConfig::GPIO_G.errorLed, 1);
sleep(1); sleep(1);
@ -76,6 +83,7 @@ void HeartRep() {
gpio_set(GlobalConfig::GPIO_G.errorLed, 0); gpio_set(GlobalConfig::GPIO_G.errorLed, 0);
} }
sleep(30); sleep(30);
count ++;
} }
} }

View File

@ -47,7 +47,7 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
timeoutflag++; timeoutflag++;
if (timeoutflag > 100) { if (timeoutflag > 100) {
DealReviveDuration(wave_shortAddr); 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); zlog_info(zct, "0x9999 timeout %d===============Size = %d", timeoutflag, offSize);
FindRecvPackage(offSize, mUartRecvTmpBuf, head); FindRecvPackage(offSize, mUartRecvTmpBuf, head);
now_task = -1; now_task = -1;
@ -352,7 +352,17 @@ void int2bytes(int i, unsigned char *bytes, int size) {
bytes[2] = (unsigned char)((0xff0000 & i) >> 16); bytes[2] = (unsigned char)((0xff0000 & i) >> 16);
bytes[3] = (unsigned char)((0xff000000 & i) >> 24); 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){ int Uart::DealAskTask(uint16_t ushortAdd){
ModifyDistAddr(ushortAdd); ModifyDistAddr(ushortAdd);
@ -372,11 +382,17 @@ int Uart::DealAskTask(uint16_t ushortAdd){
} }
else if (taskID == kScheduleWaveForm) //2.波形 else if (taskID == kScheduleWaveForm) //2.波形
{ {
GetLocalZigbeeRSSI(ushortAdd);
now_task = WAVE_CMD; now_task = WAVE_CMD;
scheduleTask.cmd = WAVE_CMD; scheduleTask.cmd = WAVE_CMD;
scheduleTask.shortAddr = ushortAdd; scheduleTask.shortAddr = ushortAdd;
wave_shortAddr = ushortAdd; wave_shortAddr = ushortAdd;
TaskResp(scheduleTask); TaskResp(scheduleTask);
mssleep(50000);
scheduleTask.cmd = SIGNAL_STRENGTH;
scheduleTask.shortAddr = ushortAdd;
scheduleTask.duration = next_duration;
TaskResp(scheduleTask);
} }
else if (taskID == kScheduleUpgrade) //3.升级 else if (taskID == kScheduleUpgrade) //3.升级
{ {
@ -512,21 +528,20 @@ void Uart::DealRecvData(const char *pData) {
DealReviveDuration(ushortAdd); DealReviveDuration(ushortAdd);
break; break;
case UPGRADE: case UPGRADE:
if (recvcode == 0) if (recvcode == 0){
{
scheduler::instance().UpgradeResult(ushortAdd,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{ }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; break;
case CONFIG: case CONFIG:
if (recvcode == 0) if (recvcode == 0){
{
DealReviveDuration(ushortAdd); DealReviveDuration(ushortAdd);
DealConfig(ushortAdd); DealConfig(ushortAdd);
}else{ }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; break;
case WAVE_COMPRESS: case WAVE_COMPRESS:

View File

@ -172,6 +172,7 @@ public:
int DealConfig(uint16_t ushortAdd); int DealConfig(uint16_t ushortAdd);
int DealWaveCompress(const char *pData,uint16_t ushortAdd); int DealWaveCompress(const char *pData,uint16_t ushortAdd);
int DealSensorRSSI(const char *pData,uint16_t ushortAdd); int DealSensorRSSI(const char *pData,uint16_t ushortAdd);
int GetLocalZigbeeRSSI(uint16_t ushortAdd);
// feature parse // feature parse
void DealDataNodeFeature(const char* pData, int flag); void DealDataNodeFeature(const char* pData, int flag);
@ -193,7 +194,7 @@ public:
void ModifyDistAddr(uint16_t distAddr); void ModifyDistAddr(uint16_t distAddr);
void modify_Localchannel(unsigned char pad); void modify_Localchannel(unsigned char pad);
void modify_LocalPanID(unsigned short padID); 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 zigbee_reset(unsigned short pad, unsigned short type);
void WriteChanl2Zigbee(unsigned char pad); void WriteChanl2Zigbee(unsigned char pad);
void WritePanId2Zigbee(unsigned short pad); void WritePanId2Zigbee(unsigned short pad);

View File

@ -18,15 +18,15 @@ void Uart::modify_distaddr_info(unsigned short id, char *zigbee, unsigned char *
WriteToUart(command1, 6); WriteToUart(command1, 6);
} }
void Uart::getZigbeeSignal(unsigned char *distAddr) { void Uart::getZigbeeSignal(uint16_t ushortAdd) {
mssleep(10000); mssleep(10000);
char command[6] = {0x00}; char command[6] = {0x00};
command[0] = 0xDE; command[0] = 0xDE;
command[1] = 0xDF; command[1] = 0xDF;
command[2] = 0xEF; command[2] = 0xEF;
command[3] = 0xDA; command[3] = 0xDA;
command[4] = distAddr[0]; command[4] = UINT16_HIGH(ushortAdd);
command[5] = distAddr[1]; command[5] = UINT16_LOW(ushortAdd);
WriteToUart(command, 6); WriteToUart(command, 6);
} }

View File

@ -70,37 +70,13 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
std::string strLongAddr = vecResult[1]; std::string strLongAddr = vecResult[1];
std::string strMeasurementID = vecResult[2]; std::string strMeasurementID = vecResult[2];
std::string strProductNo = vecResult[3]; std::string strProductNo = vecResult[3];
if (1 == flag) {
tcflush(fd, TCIOFLUSH);
if (!bSendTimeStamp) {
bSendTimeStamp = true;
mssleep(10000);
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(whereCon, 0x00, sizeof(whereCon));
memset(updateSql, 0x00, sizeof(updateSql)); memset(updateSql, 0x00, sizeof(updateSql));
sprintf(whereCon, "zigbeeShortAddr='%s'", strShortAddr.c_str()); sprintf(whereCon, "zigbeeShortAddr='%s'", strShortAddr.c_str());
sprintf(updateSql, " StaticTime = StaticTime + 1"); sprintf(updateSql, " StaticTime = StaticTime + 1");
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon); sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
}
if (vecResult[0] == "3.0" || vecResult[0] == "4.0") { if (vecResult[0] == "3.0" || vecResult[0] == "4.0") {
return; return;