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

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

@@ -1310,12 +1310,14 @@ bool ClientManager::set_cloud_status(const std::string& identifier, int status)
connect_status_update(identifier, status);
std::cout << "[Device " << identifier
<< "] ****Cloud status: " << ctx->cloudstatus << " updated to: " << status << std::endl;
DIY_INFOLOG_CODE(identifier,1,LOG_CODE_COMM,"设备登录状态更新为在线");
}
else if (ctx->cloudstatus == 1 && status == 0) {
//设备从在线转换至离线,通知前台状态发生翻转
connect_status_update(identifier, status);
std::cout << "[Device " << identifier
<< "] ****Cloud status: " << ctx->cloudstatus << " updated to: " << status << std::endl;
DIY_INFOLOG_CODE(identifier,1,LOG_CODE_COMM,"设备登录状态更新为离线");
}
// 修改云前置登录状态

View File

@@ -10,6 +10,7 @@
#include <queue>
#include "dealMsg.h"
#include "PQSMsg.h"
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>
struct PointInfo {
std::string point_id; // <20><><EFBFBD><EFBFBD>ID

View File

@@ -103,6 +103,10 @@ static std::map<std::string, RunningInformation> g_runninginfo_cache;
static std::mutex g_versioninfo_cache_mtx;
static std::map<std::string, DeviceVersionInfo> g_versioninfo_cache;
//装置升级
std::map<std::string, std::string> g_upgrade_file_map;
std::mutex g_upgrade_file_mutex;
//补招
std::list<JournalRecall> g_StatisticLackList; //日志补招结构类链表
std::mutex g_StatisticLackList_list_mutex; //补招队列数据锁
@@ -1641,12 +1645,12 @@ void parse_terminal_from_data(trigger_update_xml_t& trigger_update_xml,
//work_terminal.dev_key = get_value("devKey");
//work_terminal.dev_series = get_value("series");
work_terminal.processNo = get_value("processNo");
//work_terminal.addr_str = get_value("ip");
work_terminal.addr_str = get_value("ip");
//work_terminal.port = get_value("port");
//work_terminal.timestamp = get_value("updateTime");
work_terminal.Righttime = get_value("Righttime");
work_terminal.mac = get_value("mac");
work_terminal.mac = get_value("ip");
for (tinyxml2::XMLElement* monitor = root->FirstChildElement("monitorData");
monitor;
@@ -6594,8 +6598,43 @@ void on_device_response_minimal(int response_code,
try {
if(dev->isbusy == 2){
//获取升级文件
std::string file_path;
{
std::lock_guard<std::mutex> lk(g_upgrade_file_mutex);
auto it = g_upgrade_file_map.find(dev->terminal_id);
if (it != g_upgrade_file_map.end()) {
file_path = it->second;
}
}
if (file_path.empty()) {
std::cerr << "upgrade file not found for devid=" << dev->terminal_id << std::endl;
send_reply_to_cloud(static_cast<int>(ResponseCode::NOT_FOUND), id, device_state_int, dev->guid, dev->mac);
dev->guid.clear();
dev->busytype = 0;
dev->isbusy = 0;
dev->busytimecount = 0;
return;
}
std::cout << "upgrade file path=" << file_path << std::endl;
// 读取升级文件
std::vector<unsigned char> file_data = read_file_as_bytes("pqs_arm2.bin");
std::vector<unsigned char> file_data = read_file_as_bytes(file_path);
if (file_data.empty()) {
std::cerr << "read file failed: " << file_path << std::endl;
send_reply_to_cloud(static_cast<int>(ResponseCode::NOT_FOUND), id, device_state_int, dev->guid, dev->mac);
dev->guid.clear();
dev->busytype = 0;
dev->isbusy = 0;
dev->busytimecount = 0;
return;
}
std::cout << "file size=" << file_data.size() << std::endl;
// 下发升级指令
ClientManager::instance().send_upgrade_action_to_device(id, file_data, 10240);

View File

@@ -390,7 +390,7 @@ void Fileupload_test()
// 下载文件:从远端路径下载到本地,并返回本地文件路径
// 入参dev设备、remote_path远端完整路径
// 返回:本地保存路径(失败返回空字符串)
std::string getfilefromweb(const std::string& devid, const std::string& remote_path)
std::string getfilefromweb(const std::string& devid, const std::string& remote_path,int type)
{
try {
terminal_dev* dev = nullptr;
@@ -428,7 +428,17 @@ std::string getfilefromweb(const std::string& devid, const std::string& remote_p
//【3】构造本地保存路径
std::string mac = sanitize(normalize_mac(dev->addr_str));
std::string save_dir = std::string(FRONT_PATH) + "/bin/upload/" + mac + "/";
std::string save_dir;
if(type == 1) {
// 升级文件放在专门的upgrade目录下
save_dir = std::string(FRONT_PATH) + "/bin/upgrade/" + mac + "/";
}
else {
// 普通文件放在upload目录下
save_dir = std::string(FRONT_PATH) + "/bin/upload/" + mac + "/";
}
if (!create_directory_recursive(save_dir)) {
std::cerr << "[getfile][ERROR] create dir failed: " << save_dir << std::endl;
@@ -824,7 +834,7 @@ int terminal_ledger_web(std::map<std::string, terminal_dev>& terminal_dev_map,
dev.processNo = safe_str(item, "node");
dev.maxProcessNum = safe_str(item, "maxProcessNum");
//dev.mac = safe_str(item, "mac");//添加mac
dev.mac = safe_str(item, "ip");//添加mac
if (item.contains("monitorData") && item["monitorData"].is_array()) {
for (auto& mon : item["monitorData"]) {

View File

@@ -687,7 +687,7 @@ bool update_qvvr_file_download(const std::string& filename_with_mac, const std::
//上送文件列表接口
bool send_file_list(terminal_dev* dev, const std::vector<tag_dir_info> &FileList);
std::string getfilefromweb(const std::string& devid, const std::string& remote_path);
std::string getfilefromweb(const std::string& devid, const std::string& remote_path,int type);
//提取mac
std::string normalize_mac(const std::string& mac);

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),

View File

@@ -15,7 +15,6 @@
#include "cloudfront/code/rocketmq.h" //lnk20250708
#include "cloudfront/code/log4.h" //lnk20250924
#include "client2.h"
#include "cloudfront/code/log4.h"
using namespace std;