add stop upgrade sensor code
This commit is contained in:
parent
c911b726e7
commit
b88551f4d2
@ -1722,3 +1722,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;
|
||||||
|
}
|
||||||
@ -414,5 +414,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_
|
||||||
|
|||||||
@ -331,6 +331,14 @@ 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))
|
||||||
|
{
|
||||||
|
zlog_error(zct, "file md5 error = %s",file_path);
|
||||||
|
upload_condfig_res.code = 1;
|
||||||
|
sprintf(upload_condfig_res.message ,"%s","");
|
||||||
|
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()) {
|
||||||
@ -369,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 ;
|
||||||
}
|
}
|
||||||
@ -401,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);
|
||||||
@ -412,7 +427,8 @@ void JsonData::CmtCmd_85(char* filename,char* file_md5,char* send_data,int& sen
|
|||||||
|
|
||||||
void JsonData::CmtCmd_86(char* recv_body,int& count,char* filename,char* file_md5,char* send_data,int& send_length)
|
void JsonData::CmtCmd_86(char* recv_body,int& count,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);
|
||||||
|
|
||||||
UpgradeSensorRes upgrade_sensor_res;
|
UpgradeSensorRes upgrade_sensor_res;
|
||||||
upgrade_sensor_res.code = 0;
|
upgrade_sensor_res.code = 0;
|
||||||
sprintf(upgrade_sensor_res.message ,"%s","");
|
sprintf(upgrade_sensor_res.message ,"%s","");
|
||||||
@ -422,6 +438,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;
|
||||||
@ -468,7 +491,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;
|
||||||
@ -487,7 +510,7 @@ void JsonData::CmtCmd_86(char* recv_body,int& count,char* filename,char* file_m
|
|||||||
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())){
|
||||||
zlog_error(zct,"hardVersion error,filename = %s",file_path);
|
zlog_error(zct,"hardVersion error,filename = %s",file_path);
|
||||||
upgrade_sensor_res.code = 2;
|
upgrade_sensor_res.code = 3;
|
||||||
sprintf(upgrade_sensor_res.message ,"%s","hardVersion error");
|
sprintf(upgrade_sensor_res.message ,"%s","hardVersion error");
|
||||||
memcpy(send_data,(char*)&upgrade_sensor_res,sizeof(DownloadConfigRes));
|
memcpy(send_data,(char*)&upgrade_sensor_res,sizeof(DownloadConfigRes));
|
||||||
return;
|
return;
|
||||||
@ -507,33 +530,79 @@ void JsonData::CmtCmd_86(char* recv_body,int& count,char* filename,char* file_m
|
|||||||
}
|
}
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
void JsonData::CmtCmd_87(char* MeasurementID,char* send_data,int& send_length)
|
||||||
void JsonData::CmtCmd_88(char* recv_body,int& count)
|
|
||||||
{
|
{
|
||||||
|
array_t arrRes;
|
||||||
|
char whereCon[128] = {};
|
||||||
|
sprintf(whereCon, "channelID like '%%%s%%' ORDER BY timeStamp DESC LIMIT 0,3", MeasurementID);
|
||||||
|
arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(T_DATA_INFO(TNAME), "*", whereCon);
|
||||||
|
int iResult = arrRes.size();
|
||||||
|
if (iResult > 0) {
|
||||||
|
int j = 0;
|
||||||
|
GetEigenvalueRes get_eigenvalue_res[iResult];
|
||||||
|
for (; j < iResult; j++) {
|
||||||
|
get_eigenvalue_res[j].version = 1;
|
||||||
|
if(arrRes[j][1] == (std::string(MeasurementID) +"-X")){
|
||||||
|
get_eigenvalue_res[j].channel = 1;
|
||||||
|
}else if (arrRes[j][1] == (std::string(MeasurementID) +"-Y")){
|
||||||
|
get_eigenvalue_res[j].channel = 2;
|
||||||
|
}else if (arrRes[j][1] == (std::string(MeasurementID) +"-Z")){
|
||||||
|
get_eigenvalue_res[j].channel = 3;
|
||||||
|
}
|
||||||
|
printf("channle = %d\n",get_eigenvalue_res[j].channel);
|
||||||
|
get_eigenvalue_res[j].DiagnosisPk = atof(arrRes[j][2].c_str());
|
||||||
|
get_eigenvalue_res[j].IntegratPk = atof(arrRes[j][3].c_str());
|
||||||
|
get_eigenvalue_res[j].IntegratRMS = atof(arrRes[j][4].c_str());
|
||||||
|
get_eigenvalue_res[j].RmsValues = atof(arrRes[j][5].c_str());
|
||||||
|
get_eigenvalue_res[j].EnvelopEnergy = atof(arrRes[j][6].c_str());
|
||||||
|
get_eigenvalue_res[j].Amp1 = atof(arrRes[j][7].c_str());
|
||||||
|
get_eigenvalue_res[j].Amp2 = atof(arrRes[j][8].c_str());
|
||||||
|
get_eigenvalue_res[j].Amp3 = atof(arrRes[j][9].c_str());
|
||||||
|
get_eigenvalue_res[j].Amp4 = atof(arrRes[j][10].c_str());
|
||||||
|
get_eigenvalue_res[j].Amp5 = atof(arrRes[j][11].c_str());
|
||||||
|
get_eigenvalue_res[j].Phase1 = atof(arrRes[j][12].c_str());
|
||||||
|
get_eigenvalue_res[j].Phase2 = atof(arrRes[j][13].c_str());
|
||||||
|
get_eigenvalue_res[j].Phase3 = atof(arrRes[j][14].c_str());
|
||||||
|
get_eigenvalue_res[j].Phase4 = atof(arrRes[j][15].c_str());
|
||||||
|
get_eigenvalue_res[j].Time = atoi(arrRes[j][17].c_str());
|
||||||
|
}
|
||||||
|
memcpy(send_data,(char*)&get_eigenvalue_res,sizeof(GetEigenvalueRes) * j);
|
||||||
|
send_length = sizeof(GetEigenvalueRes) * j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 (int 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_ ,",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sprintf(updateSql, " upgradeStatus = %d ", 4);
|
||||||
|
sprintf(wherecon,"short_addr IN (%s)",short_addr_);
|
||||||
|
sqlite_db_ctrl::instance().UpdateTableData(" firmware_upgrade ", updateSql,wherecon);
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|||||||
@ -83,7 +83,8 @@ public:
|
|||||||
void CmtCmd_84(char* filename,char* file_md5,char* send_data,int& send_length);
|
void CmtCmd_84(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_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_88(char* recv_body,int& count);
|
void CmtCmd_87(char* MeasurementID,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_;
|
||||||
|
|||||||
@ -87,20 +87,23 @@ void LocalServer::HandleTcp_cmd(const char* recv_data,char* send_data,uint8_t& r
|
|||||||
jd.CmtCmd_86(recv_body,count,upgrade_sensor.filename,upgrade_sensor.md5,send_data,send_length);
|
jd.CmtCmd_86(recv_body,count,upgrade_sensor.filename,upgrade_sensor.md5,send_data,send_length);
|
||||||
}break;
|
}break;
|
||||||
case KEigenvalue:{
|
case KEigenvalue:{
|
||||||
|
GetEigenvalueReq get_eigenvalue;
|
||||||
|
memcpy(&get_eigenvalue,recv_data + sizeof(PackageHead),sizeof(GetEigenvalueReq));
|
||||||
|
jd.CmtCmd_87(get_eigenvalue.measurement_id,send_data,send_length);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case KUpgradeSensorStop:{
|
case KUpgradeSensorStop:{
|
||||||
char *recv_body = NULL;
|
char *recv_body = NULL;
|
||||||
int count = 0;
|
|
||||||
if (recvbody_length > 0){
|
if (recvbody_length > 0){
|
||||||
recv_body = (char*)malloc(recvbody_length - 4);
|
recv_body = (char*)malloc(recvbody_length - 4);
|
||||||
memcpy((char*)&count,(char*)recv_data + sizeof(PackageHead) ,4);
|
|
||||||
memcpy(recv_body,recv_data + sizeof(PackageHead) + 4,recvbody_length - 4);
|
memcpy(recv_body,recv_data + sizeof(PackageHead) + 4,recvbody_length - 4);
|
||||||
}
|
}
|
||||||
UpgradeSensorReq upgrade_sensor;
|
int count = 0;
|
||||||
memcpy(&upgrade_sensor,recv_data + sizeof(PackageHead),sizeof(UpgradeSensorReq));
|
memcpy((char*)&count,recv_data + sizeof(PackageHead),4);
|
||||||
jd.CmtCmd_88(recv_body,count);
|
jd.CmtCmd_88(recv_body,count,send_data,send_length);
|
||||||
|
if (recv_body){
|
||||||
|
free(recv_body);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -171,13 +171,38 @@ struct UpgradeSensorRes{
|
|||||||
char message[64];
|
char message[64];
|
||||||
};
|
};
|
||||||
//获取特征值 cmd 87
|
//获取特征值 cmd 87
|
||||||
|
struct GetEigenvalueReq{
|
||||||
|
char measurement_id[20];
|
||||||
|
};
|
||||||
|
struct GetEigenvalueRes{
|
||||||
|
int version;
|
||||||
|
int channel;//参考 ChannelType
|
||||||
|
float DiagnosisPk;
|
||||||
|
float IntegratPk;
|
||||||
|
float IntegratRMS;
|
||||||
|
float RmsValues;
|
||||||
|
float EnvelopEnergy;
|
||||||
|
float Amp1;
|
||||||
|
float Amp2;
|
||||||
|
float Amp3;
|
||||||
|
float Amp4;
|
||||||
|
float Amp5;
|
||||||
|
float Phase1;
|
||||||
|
float Phase2;
|
||||||
|
float Phase3;
|
||||||
|
float Phase4;
|
||||||
|
int Time;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
//停止更新传感器 cmd 88
|
//停止更新传感器 cmd 88
|
||||||
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