修改台账更新和添加升级接口

This commit is contained in:
lnk
2026-05-08 09:55:34 +08:00
parent 10a24450c7
commit f879978e62
7 changed files with 128 additions and 16 deletions

View File

@@ -77,6 +77,9 @@ extern std::atomic<int> INITFLAG;
//测试用的终端数组
extern std::vector<std::string> TESTARRAY;
extern std::map<std::string, std::string> g_upgrade_file_map;
extern std::mutex g_upgrade_file_mutex;
////////////////////////////////////////////////////////////////////////////////////////////////////////外部文件函数声明
extern void execute_bash(std::string fun,int process_num,std::string type);
@@ -767,9 +770,10 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
}
json_data.processNo = std::to_string(procNo);
//int procNum = item.value("maxProcessNum", -1);
//json_data.maxProcessNum = std::to_string(procNum);
int procNum = item.value("maxProcessNum", -1);
json_data.maxProcessNum = std::to_string(procNum);
json_data.addr_str = item.value("ip", "");
json_data.mac = item.value("ip", "");
//json_data.port = item.value("port", "");
//json_data.timestamp = item.value("updateTime", "");
@@ -2595,7 +2599,7 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
return true;
}
case 1115: { // 升级
case 1120: { // 辅助升级
parsed.ok = true;
std::cout << "[parsemsg] upgrade device, devid=" << devid
@@ -2605,14 +2609,14 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
int ret = recordguid(devid, guid, static_cast<int>(DeviceState::SET_PREUPGRADE), 2);
if (-1 == ret) {
send_reply_to_queue(guid, static_cast<int>(ResponseCode::NOT_FOUND),
"未找到该装置,升级指令执行失败");
DIY_ERRORLOG_CODE(devid, 1, LOG_CODE_CLOUD, "未找到该装置,升级指令执行失败");
"未找到该装置,辅助升级指令执行失败");
DIY_ERRORLOG_CODE(devid, 1, LOG_CODE_CLOUD, "未找到该装置,辅助升级指令执行失败");
return true;
}
else if (ret > 0) {
send_reply_to_queue(guid, static_cast<int>(ResponseCode::BUSY),
"该装置正忙,升级指令执行失败");
DIY_WARNLOG_CODE(devid, 1, LOG_CODE_CLOUD, "该装置正忙,升级指令执行失败");
"该装置正忙,辅助升级指令执行失败");
DIY_WARNLOG_CODE(devid, 1, LOG_CODE_CLOUD, "该装置正忙,辅助升级指令执行失败");
return true;
}
else {
@@ -2621,6 +2625,63 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
}
}
//辅助升级就是文件替换
//ClientManager::instance().set_preupgrade_action_to_device(devid, "");//尝试装置升级指令!第一步校验
return true;
}
case 1115: {
if (!msgObj.contains("Name") || !msgObj["Name"].is_string()) return false;
parsed.ok = true;
std::cout << "[parsemsg] update, devid=" << devid
<< ", guid=" << guid << std::endl;
//【1】recordguid
{
int ret = recordguid(devid, guid, static_cast<int>(DeviceState::SET_PREUPGRADE), 2);
if (-1 == ret) {
send_reply_to_queue(guid, static_cast<int>(ResponseCode::NOT_FOUND),
"未找到该装置,装置升级指令执行失败");
DIY_ERRORLOG_CODE(devid, 1, LOG_CODE_CLOUD, "未找到该装置,装置升级指令执行失败");
return true;
}
else if (ret > 0) {
send_reply_to_queue(guid, static_cast<int>(ResponseCode::BUSY),
"该装置正忙,装置升级指令执行失败");
DIY_WARNLOG_CODE(devid, 1, LOG_CODE_CLOUD, "该装置正忙,装置升级指令执行失败");
return true;
}
else {
std::cout << "记录装置状态成功,准备执行装置升级" << std::endl;
DIY_INFOLOG_CODE(devid, 1, LOG_CODE_CLOUD, "记录装置状态成功,准备执行装置升级");
}
}
//【2】取参数加 sanitize
std::string remote_path = sanitize(msgObj["Name"].get<std::string>()); // 云端路径
std::cout << "[parsemsg][1115] remote=" << remote_path
<< std::endl;
//【3】先下载到本地
std::string local_path = getfilefromweb(devid, remote_path,1);//升级文件下载到本地的路径和普通文件不一样放在专门的upgrade目录下
if (local_path.empty()) {
send_reply_to_queue(guid, static_cast<int>(ResponseCode::BAD_REQUEST),
"文件上送失败,下载源文件失败: " + remote_path);
DIY_ERRORLOG_CODE(devid, 1, LOG_CODE_CLOUD, "装置升级失败,下载源文件失败");
return true;
}
{
std::lock_guard<std::mutex> lk(g_upgrade_file_mutex);
g_upgrade_file_map[devid] = local_path;
}
DIY_INFOLOG_CODE(devid, 1, LOG_CODE_CLOUD, "升级文件下载成功,准备执行装置升级");
ClientManager::instance().set_preupgrade_action_to_device(devid, "");//尝试装置升级指令!第一步校验
return true;
}
@@ -2665,7 +2726,7 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
<< ", dest=" << dest_file_path << std::endl;
//【3】先下载到本地
std::string local_path = getfilefromweb(devid, remote_path);
std::string local_path = getfilefromweb(devid, remote_path,0);//普通文件下载到本地的路径
if (local_path.empty()) {
send_reply_to_queue(guid, static_cast<int>(ResponseCode::BAD_REQUEST),