修改台账更新和添加升级接口
This commit is contained in:
@@ -1310,12 +1310,14 @@ bool ClientManager::set_cloud_status(const std::string& identifier, int status)
|
|||||||
connect_status_update(identifier, status);
|
connect_status_update(identifier, status);
|
||||||
std::cout << "[Device " << identifier
|
std::cout << "[Device " << identifier
|
||||||
<< "] ****Cloud status: " << ctx->cloudstatus << " updated to: " << status << std::endl;
|
<< "] ****Cloud status: " << ctx->cloudstatus << " updated to: " << status << std::endl;
|
||||||
|
DIY_INFOLOG_CODE(identifier,1,LOG_CODE_COMM,"设备登录状态更新为在线");
|
||||||
}
|
}
|
||||||
else if (ctx->cloudstatus == 1 && status == 0) {
|
else if (ctx->cloudstatus == 1 && status == 0) {
|
||||||
//设备从在线转换至离线,通知前台状态发生翻转
|
//设备从在线转换至离线,通知前台状态发生翻转
|
||||||
connect_status_update(identifier, status);
|
connect_status_update(identifier, status);
|
||||||
std::cout << "[Device " << identifier
|
std::cout << "[Device " << identifier
|
||||||
<< "] ****Cloud status: " << ctx->cloudstatus << " updated to: " << status << std::endl;
|
<< "] ****Cloud status: " << ctx->cloudstatus << " updated to: " << status << std::endl;
|
||||||
|
DIY_INFOLOG_CODE(identifier,1,LOG_CODE_COMM,"设备登录状态更新为离线");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改云前置登录状态
|
// 修改云前置登录状态
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
#include "dealMsg.h"
|
#include "dealMsg.h"
|
||||||
#include "PQSMsg.h"
|
#include "PQSMsg.h"
|
||||||
|
|
||||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>ṹ
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>ṹ
|
||||||
struct PointInfo {
|
struct PointInfo {
|
||||||
std::string point_id; // <20><><EFBFBD><EFBFBD>ID
|
std::string point_id; // <20><><EFBFBD><EFBFBD>ID
|
||||||
|
|||||||
@@ -103,6 +103,10 @@ static std::map<std::string, RunningInformation> g_runninginfo_cache;
|
|||||||
static std::mutex g_versioninfo_cache_mtx;
|
static std::mutex g_versioninfo_cache_mtx;
|
||||||
static std::map<std::string, DeviceVersionInfo> g_versioninfo_cache;
|
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::list<JournalRecall> g_StatisticLackList; //日志补招结构类链表
|
||||||
std::mutex g_StatisticLackList_list_mutex; //补招队列数据锁
|
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_key = get_value("devKey");
|
||||||
//work_terminal.dev_series = get_value("series");
|
//work_terminal.dev_series = get_value("series");
|
||||||
work_terminal.processNo = get_value("processNo");
|
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.port = get_value("port");
|
||||||
//work_terminal.timestamp = get_value("updateTime");
|
//work_terminal.timestamp = get_value("updateTime");
|
||||||
work_terminal.Righttime = get_value("Righttime");
|
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");
|
for (tinyxml2::XMLElement* monitor = root->FirstChildElement("monitorData");
|
||||||
monitor;
|
monitor;
|
||||||
@@ -6594,8 +6598,43 @@ void on_device_response_minimal(int response_code,
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if(dev->isbusy == 2){
|
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);
|
ClientManager::instance().send_upgrade_action_to_device(id, file_data, 10240);
|
||||||
|
|||||||
@@ -390,7 +390,7 @@ void Fileupload_test()
|
|||||||
// 下载文件:从远端路径下载到本地,并返回本地文件路径
|
// 下载文件:从远端路径下载到本地,并返回本地文件路径
|
||||||
// 入参:dev(设备)、remote_path(远端完整路径)
|
// 入参: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 {
|
try {
|
||||||
terminal_dev* dev = nullptr;
|
terminal_dev* dev = nullptr;
|
||||||
@@ -428,7 +428,17 @@ std::string getfilefromweb(const std::string& devid, const std::string& remote_p
|
|||||||
|
|
||||||
//【3】构造本地保存路径
|
//【3】构造本地保存路径
|
||||||
std::string mac = sanitize(normalize_mac(dev->addr_str));
|
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)) {
|
if (!create_directory_recursive(save_dir)) {
|
||||||
std::cerr << "[getfile][ERROR] create dir failed: " << save_dir << std::endl;
|
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.processNo = safe_str(item, "node");
|
||||||
dev.maxProcessNum = safe_str(item, "maxProcessNum");
|
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()) {
|
if (item.contains("monitorData") && item["monitorData"].is_array()) {
|
||||||
for (auto& mon : item["monitorData"]) {
|
for (auto& mon : item["monitorData"]) {
|
||||||
|
|||||||
@@ -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);
|
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
|
//提取mac
|
||||||
std::string normalize_mac(const std::string& mac);
|
std::string normalize_mac(const std::string& mac);
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,9 @@ extern std::atomic<int> INITFLAG;
|
|||||||
//测试用的终端数组
|
//测试用的终端数组
|
||||||
extern std::vector<std::string> TESTARRAY;
|
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);
|
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);
|
json_data.processNo = std::to_string(procNo);
|
||||||
|
|
||||||
//int procNum = item.value("maxProcessNum", -1);
|
int procNum = item.value("maxProcessNum", -1);
|
||||||
//json_data.maxProcessNum = std::to_string(procNum);
|
json_data.maxProcessNum = std::to_string(procNum);
|
||||||
|
|
||||||
|
json_data.addr_str = item.value("ip", "");
|
||||||
json_data.mac = item.value("ip", "");
|
json_data.mac = item.value("ip", "");
|
||||||
//json_data.port = item.value("port", "");
|
//json_data.port = item.value("port", "");
|
||||||
//json_data.timestamp = item.value("updateTime", "");
|
//json_data.timestamp = item.value("updateTime", "");
|
||||||
@@ -2595,7 +2599,7 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 1115: { // 升级
|
case 1120: { // 辅助升级
|
||||||
parsed.ok = true;
|
parsed.ok = true;
|
||||||
|
|
||||||
std::cout << "[parsemsg] upgrade device, devid=" << devid
|
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);
|
int ret = recordguid(devid, guid, static_cast<int>(DeviceState::SET_PREUPGRADE), 2);
|
||||||
if (-1 == ret) {
|
if (-1 == ret) {
|
||||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::NOT_FOUND),
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
else if (ret > 0) {
|
else if (ret > 0) {
|
||||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::BUSY),
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
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, "");//尝试装置升级指令!第一步校验
|
ClientManager::instance().set_preupgrade_action_to_device(devid, "");//尝试装置升级指令!第一步校验
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -2665,7 +2726,7 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
|||||||
<< ", dest=" << dest_file_path << std::endl;
|
<< ", dest=" << dest_file_path << std::endl;
|
||||||
|
|
||||||
//【3】先下载到本地
|
//【3】先下载到本地
|
||||||
std::string local_path = getfilefromweb(devid, remote_path);
|
std::string local_path = getfilefromweb(devid, remote_path,0);//普通文件下载到本地的路径
|
||||||
|
|
||||||
if (local_path.empty()) {
|
if (local_path.empty()) {
|
||||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
send_reply_to_queue(guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
#include "cloudfront/code/rocketmq.h" //lnk20250708
|
#include "cloudfront/code/rocketmq.h" //lnk20250708
|
||||||
#include "cloudfront/code/log4.h" //lnk20250924
|
#include "cloudfront/code/log4.h" //lnk20250924
|
||||||
#include "client2.h"
|
#include "client2.h"
|
||||||
#include "cloudfront/code/log4.h"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user