添加停止更新传感器
This commit is contained in:
parent
faa1938e82
commit
13d79e15f0
@ -1762,3 +1762,27 @@ void Binary_Bit(unsigned char *p_data, unsigned char position, int flag) {
|
|||||||
*p_data &= ~(0x01 << (position));
|
*p_data &= ~(0x01 << (position));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::string get_file_md5(const std::string& file_path) {
|
||||||
|
// 使用 md5sum 命令计算文件的 MD5 值
|
||||||
|
std::string command = "md5sum " + file_path + " | awk '{ print $1 }'";
|
||||||
|
|
||||||
|
// 使用 popen 执行命令并获取输出
|
||||||
|
std::array<char, 128> buffer;
|
||||||
|
std::string result;
|
||||||
|
std::shared_ptr<FILE> pipe(popen(command.c_str(), "r"), pclose);
|
||||||
|
|
||||||
|
if (!pipe) {
|
||||||
|
std::cerr << "Error: Unable to run md5sum command" << std::endl;
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从命令的输出流中读取数据
|
||||||
|
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
|
||||||
|
result += buffer.data();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 去除末尾的换行符
|
||||||
|
result.erase(result.find_last_not_of("\n") + 1);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@ -412,5 +412,5 @@ int Ping(const char* ips, int timeout);
|
|||||||
int get_netlink_status(const char* if_name);
|
int get_netlink_status(const char* if_name);
|
||||||
int compareVersions(const std::string& version1, const std::string& version2);
|
int compareVersions(const std::string& version1, const std::string& version2);
|
||||||
void Binary_Bit(unsigned char* p_data, unsigned char position, int flag);
|
void Binary_Bit(unsigned char* p_data, unsigned char position, int flag);
|
||||||
|
std::string get_file_md5(const std::string& file_path);
|
||||||
#endif // COMMON_FUNC_HPP_
|
#endif // COMMON_FUNC_HPP_
|
||||||
|
|||||||
@ -332,6 +332,13 @@ void JsonData::CmtCmd_84(char* filename,char* file_md5,char* send_data,int& sen
|
|||||||
sprintf(cmd, "mv /opt/%s /opt/DataNode/",filename);
|
sprintf(cmd, "mv /opt/%s /opt/DataNode/",filename);
|
||||||
system(cmd);
|
system(cmd);
|
||||||
sprintf(file_path, "/opt/DataNode/%s",filename);
|
sprintf(file_path, "/opt/DataNode/%s",filename);
|
||||||
|
if(get_file_md5(file_path) != std::string(file_md5))
|
||||||
|
{
|
||||||
|
upload_condfig_res.code = 1;
|
||||||
|
sprintf(upload_condfig_res.message ,"%s","file md5 error");
|
||||||
|
memcpy(send_data,(char*)&upload_condfig_res,sizeof(UploadConfigRes));
|
||||||
|
return ;
|
||||||
|
}
|
||||||
std::ifstream csv_data(file_path, std::ios::in);
|
std::ifstream csv_data(file_path, std::ios::in);
|
||||||
int iRet = 0;
|
int iRet = 0;
|
||||||
if (!csv_data.is_open()) {
|
if (!csv_data.is_open()) {
|
||||||
@ -370,8 +377,8 @@ void JsonData::CmtCmd_84(char* filename,char* file_md5,char* send_data,int& sen
|
|||||||
csv_data.close();
|
csv_data.close();
|
||||||
if (vecDataNode.size() == 0) {
|
if (vecDataNode.size() == 0) {
|
||||||
zlog_error(zct, "UpdataDataNodeConfig vecDataNode is 0");
|
zlog_error(zct, "UpdataDataNodeConfig vecDataNode is 0");
|
||||||
upload_condfig_res.code = 0;
|
upload_condfig_res.code = 2;
|
||||||
sprintf(upload_condfig_res.message ,"%s","");
|
sprintf(upload_condfig_res.message ,"%s","upgrade sensor is 0");
|
||||||
memcpy(send_data,(char*)&upload_condfig_res,sizeof(UploadConfigRes));
|
memcpy(send_data,(char*)&upload_condfig_res,sizeof(UploadConfigRes));
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
@ -402,7 +409,14 @@ void JsonData::CmtCmd_84(char* filename,char* file_md5,char* send_data,int& sen
|
|||||||
|
|
||||||
void JsonData::CmtCmd_85(char* filename,char* file_md5,char* send_data,int& send_length)
|
void JsonData::CmtCmd_85(char* filename,char* file_md5,char* send_data,int& send_length)
|
||||||
{
|
{
|
||||||
zlog_info(zct,"file_path = %s,file_md5 = %s",filename,file_md5);
|
zlog_info(zct,"filename = %s,file_md5 = %s",filename,file_md5);
|
||||||
|
char file_path[64]={0};
|
||||||
|
sprintf(file_path, "/opt/%s",filename);
|
||||||
|
if(get_file_md5(file_path) != std::string(file_md5))
|
||||||
|
{
|
||||||
|
zlog_error(zct, "file md5 error = %s",file_path);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
sleep(3);
|
sleep(3);
|
||||||
int iRet = system("/opt/opt.sh");
|
int iRet = system("/opt/opt.sh");
|
||||||
zlog_info(zct, "iRet = %d", iRet);
|
zlog_info(zct, "iRet = %d", iRet);
|
||||||
@ -423,6 +437,13 @@ void JsonData::CmtCmd_86(char* recv_body,int& count,char* filename,char* file_m
|
|||||||
sprintf(cmd, "mv /opt/%s /opt/DataNode/",filename);
|
sprintf(cmd, "mv /opt/%s /opt/DataNode/",filename);
|
||||||
system(cmd);
|
system(cmd);
|
||||||
sprintf(file_path, "/opt/DataNode/%s",filename);
|
sprintf(file_path, "/opt/DataNode/%s",filename);
|
||||||
|
if(get_file_md5(file_path) != std::string(file_md5))
|
||||||
|
{
|
||||||
|
upgrade_sensor_res.code = 1;
|
||||||
|
sprintf(upgrade_sensor_res.message ,"%s","file md5 error");
|
||||||
|
memcpy(send_data,(char*)&upgrade_sensor_res,sizeof(DownloadConfigRes));
|
||||||
|
return ;
|
||||||
|
}
|
||||||
FILE * pFile=NULL;
|
FILE * pFile=NULL;
|
||||||
size_t thisSize = 0;
|
size_t thisSize = 0;
|
||||||
char *buffer=NULL;
|
char *buffer=NULL;
|
||||||
@ -469,7 +490,7 @@ void JsonData::CmtCmd_86(char* recv_body,int& count,char* filename,char* file_m
|
|||||||
}
|
}
|
||||||
if (sum % 256 != ch_crc){
|
if (sum % 256 != ch_crc){
|
||||||
zlog_error(zct,"package CRC error,filename = %s",file_path);
|
zlog_error(zct,"package CRC error,filename = %s",file_path);
|
||||||
upgrade_sensor_res.code = 1;
|
upgrade_sensor_res.code = 2;
|
||||||
sprintf(upgrade_sensor_res.message ,"%s","package CRC error");
|
sprintf(upgrade_sensor_res.message ,"%s","package CRC error");
|
||||||
memcpy(send_data,(char*)&upgrade_sensor_res,sizeof(DownloadConfigRes));
|
memcpy(send_data,(char*)&upgrade_sensor_res,sizeof(DownloadConfigRes));
|
||||||
return;
|
return;
|
||||||
@ -495,7 +516,7 @@ void JsonData::CmtCmd_86(char* recv_body,int& count,char* filename,char* file_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(),filename);
|
sprintf(insertSql, " '%s','%s','','','','','%d.%d','%s',1,'%s'",vecResult[3].c_str(),localtimestamp,sf_ver_m,sf_ver_s,vecResult[1].c_str(),filename);
|
||||||
sqlite_db_ctrl::instance().InsertData(" firmware_upgrade ", insertSql);
|
sqlite_db_ctrl::instance().InsertData(" firmware_upgrade ", insertSql);
|
||||||
//0 默认状态,1 升级中,2 升级成功,3 升级失败
|
//0 默认状态,1 升级中,2 升级成功,3 升级失败,4 停止升级
|
||||||
memset(wherecon,0,sizeof(wherecon));
|
memset(wherecon,0,sizeof(wherecon));
|
||||||
memset(updateSql,0,sizeof(updateSql));
|
memset(updateSql,0,sizeof(updateSql));
|
||||||
sprintf(wherecon," zigbeeShortAddr = '%s'",vecResult[3].c_str());
|
sprintf(wherecon," zigbeeShortAddr = '%s'",vecResult[3].c_str());
|
||||||
@ -550,32 +571,37 @@ void JsonData::CmtCmd_87(char* MeasurementID,char* send_data,int& send_length)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonData::CmtCmd_88(int& short_addr,char* send_data,int& send_length)
|
void JsonData::CmtCmd_88(char* recv_body,int& count,char* send_data,int& send_length)
|
||||||
{
|
{
|
||||||
|
if (recv_body != NULL)
|
||||||
|
{
|
||||||
|
char wherecon[100] = {0};
|
||||||
|
char updateSql[100] = {0};
|
||||||
|
printf("count = %d\n",count);
|
||||||
|
char short_addr_[256]={0};
|
||||||
|
for (size_t i = 0; i < count; i++){
|
||||||
|
char temp[5]={0};
|
||||||
|
memcpy(temp,recv_body + i * 4,4);
|
||||||
|
uint16_t short_addr;
|
||||||
|
char *end_ptr = NULL;
|
||||||
|
short_addr = strtol(temp, &end_ptr, 16);
|
||||||
|
scheduler::instance().UpgradeResult(short_addr,kUpgradeSuccess);
|
||||||
|
|
||||||
|
printf("short_addr = %s\n",temp);
|
||||||
|
strcat(short_addr_,"'");
|
||||||
|
strcat(short_addr_,temp);
|
||||||
|
strcat(short_addr_,"'");
|
||||||
|
if (i + 1 != count){
|
||||||
|
strcat(short_addr_ ,",");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_file_md5(const std::string& file_path) {
|
|
||||||
// 使用 md5sum 命令计算文件的 MD5 值
|
|
||||||
std::string command = "md5sum " + file_path + " | awk '{ print $1 }'";
|
|
||||||
|
|
||||||
// 使用 popen 执行命令并获取输出
|
|
||||||
std::array<char, 128> buffer;
|
|
||||||
std::string result;
|
|
||||||
std::shared_ptr<FILE> pipe(popen(command.c_str(), "r"), pclose);
|
|
||||||
|
|
||||||
if (!pipe) {
|
|
||||||
std::cerr << "Error: Unable to run md5sum command" << std::endl;
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
sprintf(updateSql, " upgradeStatus = %d ", 4);
|
||||||
// 从命令的输出流中读取数据
|
sprintf(whereCon,"short_addr IN (%s)",short_addr_);
|
||||||
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
|
sqlite_db_ctrl::instance().UpdateTableData(" firmware_upgrade ", updateSql,wherecon);
|
||||||
result += buffer.data();
|
UpgradeStopRes upgrade_stop_res;
|
||||||
|
upgrade_stop_res.code = 0;
|
||||||
|
sprintf(upgrade_stop_res.message ,"%s","");
|
||||||
|
memcpy(send_data,(char*)&upgrade_stop_res,sizeof(UpgradeStopRes));
|
||||||
|
send_length = sizeof(UpgradeStopRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 去除末尾的换行符
|
|
||||||
result.erase(result.find_last_not_of("\n") + 1);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -84,7 +84,7 @@ public:
|
|||||||
void CmtCmd_85(char* filename,char* file_md5,char* send_data,int& send_length);
|
void CmtCmd_85(char* filename,char* file_md5,char* send_data,int& send_length);
|
||||||
void CmtCmd_86(char* recv_body,int& count,char* filename,char* file_md5,char* send_data,int& send_length);
|
void CmtCmd_86(char* recv_body,int& count,char* filename,char* file_md5,char* send_data,int& send_length);
|
||||||
void CmtCmd_87(char* MeasurementID,char* send_data,int& send_length);
|
void CmtCmd_87(char* MeasurementID,char* send_data,int& send_length);
|
||||||
void CmtCmd_88(int& short_addr,char* send_data,int& send_length);
|
void CmtCmd_88(char* recv_body,int& count,char* send_data,int& send_length);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Json::FastWriter show_value_;
|
Json::FastWriter show_value_;
|
||||||
|
|||||||
@ -93,6 +93,17 @@ void LocalServer::HandleTcp_cmd(const char* recv_data,char* send_data,uint8_t& r
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case KUpgradeSensorStop:{
|
case KUpgradeSensorStop:{
|
||||||
|
char *recv_body = NULL;
|
||||||
|
if (recvbody_length > 0){
|
||||||
|
recv_body = (char*)malloc(recvbody_length - 4);
|
||||||
|
memcpy(recv_body,recv_data + sizeof(PackageHead) + 4,recvbody_length - 4);
|
||||||
|
}
|
||||||
|
int count = 0;
|
||||||
|
memcpy((char*)&count,recv_data + sizeof(PackageHead),4);
|
||||||
|
jd.CmtCmd_88(recv_body,count,send_data,send_length);
|
||||||
|
if (recv_body){
|
||||||
|
free(recv_body);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -198,7 +198,10 @@ struct GetEigenvalueRes{
|
|||||||
struct UpgradeStopReq{
|
struct UpgradeStopReq{
|
||||||
int short_addr;
|
int short_addr;
|
||||||
};
|
};
|
||||||
|
struct UpgradeStopRes{
|
||||||
|
int code;
|
||||||
|
char message[64];
|
||||||
|
};
|
||||||
// 搜索应答 cmd 1
|
// 搜索应答 cmd 1
|
||||||
struct Search {
|
struct Search {
|
||||||
int version;
|
int version;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user