add interface
This commit is contained in:
@@ -81,6 +81,16 @@ std::map<std::pair<std::string,std::string>, std::string> g_recall_file_index;
|
||||
std::mutex g_last_ts_mtx;
|
||||
std::unordered_map<std::string, time_t> g_last_ts_by_devid;
|
||||
|
||||
//文件下载缓存
|
||||
struct FileDownloadReplyInfo
|
||||
{
|
||||
std::string local_name; // 本地名,对应 JSON 的 Name
|
||||
std::string remote_name; // 远端名,对应 JSON 的 RemoteName
|
||||
};
|
||||
|
||||
static std::mutex g_filedownload_cache_mtx;
|
||||
static std::map<std::string, FileDownloadReplyInfo> g_filedownload_cache;
|
||||
|
||||
//目录信息缓存
|
||||
static std::mutex g_filemenu_cache_mtx;
|
||||
std::map<std::string, std::vector<tag_dir_info>> g_filemenu_cache;
|
||||
@@ -3568,7 +3578,7 @@ void check_device_busy_timeout()
|
||||
}
|
||||
|
||||
//发送超时响应
|
||||
//send_reply_to_cloud(static_cast<int>(ResponseCode::TIMEOUT),dev.terminal_id,get_type_by_state(dev.busytype),dev.guid,dev.mac);
|
||||
send_reply_to_cloud(static_cast<int>(ResponseCode::TIMEOUT),dev.terminal_id,dev.busytype,dev.guid,dev.mac);
|
||||
send_reply_to_queue(dev.guid, static_cast<int>(ResponseCode::TIMEOUT),
|
||||
"终端 id: " + dev.terminal_id + "进行业务:" + get_type_by_state(dev.busytype) +"超时600秒,停止该业务处理");
|
||||
|
||||
@@ -3616,7 +3626,7 @@ void check_device_busy_timeout()
|
||||
}
|
||||
|
||||
//发送超时响应
|
||||
//send_reply_to_cloud(static_cast<int>(ResponseCode::TIMEOUT),dev.terminal_id,get_type_by_state(dev.busytype),dev.guid,dev.mac);
|
||||
send_reply_to_cloud(static_cast<int>(ResponseCode::TIMEOUT),dev.terminal_id,dev.busytype,dev.guid,dev.mac);
|
||||
send_reply_to_queue(dev.guid, static_cast<int>(ResponseCode::TIMEOUT),
|
||||
"终端 id: " + dev.terminal_id + "进行业务:" + get_type_by_state(dev.busytype) +"超时30秒,停止该业务处理");
|
||||
|
||||
@@ -3937,7 +3947,7 @@ bool send_set_value_reply(const std::string &dev_id, unsigned char mp_index, con
|
||||
// Msg
|
||||
nlohmann::json msg;
|
||||
msg["Cldid"] = mp_index; //测点序号
|
||||
msg["DataType"] = 0x0C; //定值
|
||||
msg["DataType"] = 1; //定值
|
||||
|
||||
// DataArray(对象数组):逐个填充,DZ_Value 严格按 set_values 顺序
|
||||
nlohmann::json dataArray = nlohmann::json::array();
|
||||
@@ -3975,10 +3985,10 @@ bool send_set_value_reply(const std::string &dev_id, unsigned char mp_index, con
|
||||
|
||||
// 6) 入队发送
|
||||
queue_data_t connect_info;
|
||||
connect_info.strTopic = Topic_Reply_Topic;
|
||||
connect_info.strTopic = Cloud_Reply_Topic;
|
||||
connect_info.strText = j.dump(); // 序列化为字符串
|
||||
connect_info.tag = Topic_Reply_Tag;
|
||||
connect_info.key = Topic_Reply_Key;
|
||||
connect_info.tag = Cloud_Reply_Tag;
|
||||
connect_info.key = Cloud_Reply_Key;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(queue_data_list_mutex);
|
||||
@@ -4058,7 +4068,7 @@ bool send_internal_value_reply(const std::string &dev_id, const std::vector<DZ_k
|
||||
nlohmann::json detail;
|
||||
detail["Type"] = 1103; // 设备数据
|
||||
nlohmann::json msg;
|
||||
msg["DataType"] = 0x0D; // 内部定值
|
||||
msg["DataType"] = 2; // 内部定值
|
||||
|
||||
// 4) === 将 C# 的拼接逻辑移植为 DataArray ===
|
||||
// C# 变量对应关系:
|
||||
@@ -4173,10 +4183,10 @@ bool send_internal_value_reply(const std::string &dev_id, const std::vector<DZ_k
|
||||
|
||||
// 5) 入队发送(保持你的队列逻辑)
|
||||
queue_data_t connect_info;
|
||||
connect_info.strTopic = Topic_Reply_Topic;
|
||||
connect_info.strTopic = Cloud_Reply_Topic;
|
||||
connect_info.strText = j.dump(); // 序列化为字符串
|
||||
connect_info.tag = Topic_Reply_Tag;
|
||||
connect_info.key = Topic_Reply_Key;
|
||||
connect_info.tag = Cloud_Reply_Tag;
|
||||
connect_info.key = Cloud_Reply_Key;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(queue_data_list_mutex);
|
||||
@@ -5653,6 +5663,75 @@ bool enqueue_direct_download(const std::string& dev_id,
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////文件下载响应处理
|
||||
void filedownload_cache_put(const std::string& dev_id,
|
||||
const std::string& local_name,
|
||||
const std::string& remote_name)
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(g_filedownload_cache_mtx);
|
||||
g_filedownload_cache[dev_id] = FileDownloadReplyInfo{ local_name, remote_name };
|
||||
}
|
||||
|
||||
bool filedownload_cache_take(const std::string& dev_id, FileDownloadReplyInfo& out)
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(g_filedownload_cache_mtx);
|
||||
auto it = g_filedownload_cache.find(dev_id);
|
||||
if (it == g_filedownload_cache.end()) return false;
|
||||
|
||||
out = std::move(it->second);
|
||||
g_filedownload_cache.erase(it);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool send_file_download_reply(terminal_dev* dev,
|
||||
const std::string& local_name,
|
||||
const std::string& remote_name)
|
||||
{
|
||||
if (!dev) {
|
||||
std::cerr << "[send_file_download_reply] dev=nullptr\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// 判断 isbusy==1 且 busytype==READING_FILEDATA
|
||||
if (dev->isbusy != 1 || dev->busytype != static_cast<int>(DeviceState::READING_FILEDATA)) {
|
||||
std::cerr << "[send_file_download_reply] device not in READING_FILEDATA state." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// 构造 JSON 报文
|
||||
nlohmann::json j;
|
||||
j["guid"] = dev->guid;
|
||||
j["FrontId"] = FRONT_INST;
|
||||
j["Node"] = g_front_seg_index;
|
||||
j["Dev_mac"] = normalize_mac(dev->addr_str);
|
||||
|
||||
nlohmann::json detail;
|
||||
detail["Type"] = 1102;
|
||||
detail["Msg"] = {
|
||||
{"Name", local_name},
|
||||
{"RemoteName", remote_name}
|
||||
};
|
||||
detail["Code"] = 200;
|
||||
|
||||
j["Detail"] = detail;
|
||||
|
||||
std::cout << j.dump(4) << std::endl;
|
||||
|
||||
// ---- 入队发送 ----
|
||||
queue_data_t connect_info;
|
||||
connect_info.strTopic = Cloud_Reply_Topic;
|
||||
connect_info.strText = j.dump();
|
||||
connect_info.tag = Cloud_Reply_Tag;
|
||||
connect_info.key = Cloud_Reply_Key;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(queue_data_list_mutex);
|
||||
queue_data_list.push_back(std::move(connect_info));
|
||||
}
|
||||
|
||||
std::cout << "[send_file_download_reply] queued: " << j.dump() << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////目录响应处理
|
||||
|
||||
void filemenu_cache_put(const std::string& dev_id,
|
||||
@@ -5719,10 +5798,10 @@ bool send_file_list(terminal_dev* dev, const std::vector<tag_dir_info>& FileList
|
||||
|
||||
// ---- 入队发送 ----
|
||||
queue_data_t connect_info;
|
||||
connect_info.strTopic = Topic_Reply_Topic;
|
||||
connect_info.strTopic = Cloud_Reply_Topic;
|
||||
connect_info.strText = j.dump(); // 序列化为字符串
|
||||
connect_info.tag = Topic_Reply_Tag;
|
||||
connect_info.key = Topic_Reply_Key;
|
||||
connect_info.tag = Cloud_Reply_Tag;
|
||||
connect_info.key = Cloud_Reply_Key;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(queue_data_list_mutex);
|
||||
queue_data_list.push_back(std::move(connect_info));
|
||||
@@ -5811,10 +5890,10 @@ bool send_running_info(terminal_dev* dev, const RunningInformation& info) {
|
||||
|
||||
// ---- 入队发送 ----
|
||||
queue_data_t connect_info;
|
||||
connect_info.strTopic = Topic_Reply_Topic;
|
||||
connect_info.strTopic = Cloud_Reply_Topic;
|
||||
connect_info.strText = j.dump();
|
||||
connect_info.tag = Topic_Reply_Tag;
|
||||
connect_info.key = Topic_Reply_Key;
|
||||
connect_info.tag = Cloud_Reply_Tag;
|
||||
connect_info.key = Cloud_Reply_Key;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(queue_data_list_mutex);
|
||||
queue_data_list.push_back(std::move(connect_info));
|
||||
@@ -5919,10 +5998,10 @@ bool send_version_info(terminal_dev* dev, const DeviceVersionInfo& info) {
|
||||
|
||||
// ---- 入队发送 ----
|
||||
queue_data_t connect_info;
|
||||
connect_info.strTopic = Topic_Reply_Topic;
|
||||
connect_info.strTopic = Cloud_Reply_Topic;
|
||||
connect_info.strText = j.dump();
|
||||
connect_info.tag = Topic_Reply_Tag;
|
||||
connect_info.key = Topic_Reply_Key;
|
||||
connect_info.tag = Cloud_Reply_Tag;
|
||||
connect_info.key = Cloud_Reply_Key;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(queue_data_list_mutex);
|
||||
queue_data_list.push_back(std::move(connect_info));
|
||||
@@ -6079,12 +6158,12 @@ void on_device_response_minimal(int response_code,
|
||||
|
||||
//发送目录
|
||||
send_file_list(dev,names);
|
||||
|
||||
std::cout << "[RESP][FILEMENU->FILEMENU][OK] dev=" << id << std::endl;
|
||||
} else {
|
||||
// 失败:响应web并复位为空闲
|
||||
//send_reply_to_cloud(static_cast<int>(ResponseCode::BAD_REQUEST), id, static_cast<int>(DeviceState::READING_FILEMENU),dev->guid,dev->mac);
|
||||
send_reply_to_queue(dev->guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
"终端 id: " + dev->terminal_id + "进行业务:" + get_type_by_state(dev->busytype) +"失败,停止该业务处理");
|
||||
send_reply_to_cloud(static_cast<int>(ResponseCode::BAD_REQUEST), id, device_state_int,dev->guid,dev->mac);
|
||||
//send_reply_to_queue(dev->guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
// "终端 id: " + dev->terminal_id + "进行业务:" + get_type_by_state(dev->busytype) +"失败,停止该业务处理");
|
||||
std::cout << "[RESP][FILEMENU->FILEMENU][WARN] dev=" << id
|
||||
<< " names missing in cache" << std::endl;
|
||||
}
|
||||
@@ -6094,12 +6173,12 @@ void on_device_response_minimal(int response_code,
|
||||
dev->isbusy = 0;
|
||||
dev->busytype = 0;
|
||||
dev->busytimecount = 0;
|
||||
std::cout << "[RESP][FILEMENU->FILEMENU][OK] dev=" << id << std::endl;
|
||||
|
||||
} else {
|
||||
// 失败:响应web并复位为空闲
|
||||
//send_reply_to_cloud(response_code, id, static_cast<int>(DeviceState::READING_FILEMENU),dev->guid,dev->mac);
|
||||
send_reply_to_queue(dev->guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
"终端 id: " + dev->terminal_id + "进行业务:" + get_type_by_state(dev->busytype) +"失败,停止该业务处理");
|
||||
send_reply_to_cloud(response_code, id, device_state_int,dev->guid,dev->mac);
|
||||
//send_reply_to_queue(dev->guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
// "终端 id: " + dev->terminal_id + "进行业务:" + get_type_by_state(dev->busytype) +"失败,停止该业务处理");
|
||||
|
||||
dev->guid.clear();
|
||||
dev->isbusy = 0;
|
||||
@@ -6218,20 +6297,33 @@ void on_device_response_minimal(int response_code,
|
||||
// ====== 分支 A:当前业务就是“读取文件数据” ======
|
||||
if (ok) {
|
||||
// 成功:复位
|
||||
//send_reply_to_cloud(static_cast<int>(ResponseCode::OK), id, static_cast<int>(DeviceState::READING_FILEDATA),dev->guid,dev->mac);
|
||||
send_reply_to_queue(dev->guid, static_cast<int>(ResponseCode::OK),
|
||||
"终端 id: " + dev->terminal_id + "进行业务:" + get_type_by_state(dev->busytype) +"成功,停止该业务处理");
|
||||
FileDownloadReplyInfo file_info;
|
||||
if (filedownload_cache_take(id, file_info)) {
|
||||
send_file_download_reply(dev, file_info.local_name, file_info.remote_name);
|
||||
std::cout << "[RESP][FILEDATA->FILEDATA][OK][CACHE] dev=" << id
|
||||
<< " local_name=" << file_info.local_name
|
||||
<< " remote_name=" << file_info.remote_name
|
||||
<< std::endl;
|
||||
|
||||
} else {//取不到结果,即使上传了文件也当做失败处理
|
||||
send_reply_to_cloud(static_cast<int>(ResponseCode::BAD_REQUEST), id, device_state_int, dev->guid, dev->mac);
|
||||
//send_reply_to_queue(dev->guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
// "终端 id: " + dev->terminal_id + "进行业务:" +
|
||||
// get_type_by_state(dev->busytype) + "失败,停止该业务处理");
|
||||
|
||||
std::cout << "[RESP][FILEDATA->FILEDATA][FAIL][NO_CACHE] dev=" << id << std::endl;
|
||||
}
|
||||
|
||||
dev->guid.clear();
|
||||
dev->isbusy = 0;
|
||||
dev->busytype = 0;
|
||||
dev->busytimecount = 0;
|
||||
std::cout << "[RESP][FILEDATA->FILEDATA][OK] dev=" << id << std::endl;
|
||||
|
||||
} else {
|
||||
// 失败:响应web并复位
|
||||
//send_reply_to_cloud(response_code, id, static_cast<int>(DeviceState::READING_FILEDATA),dev->guid,dev->mac);
|
||||
send_reply_to_queue(dev->guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
"终端 id: " + dev->terminal_id + "进行业务:" + get_type_by_state(dev->busytype) +"失败,停止该业务处理");
|
||||
send_reply_to_cloud(response_code, id, device_state_int,dev->guid,dev->mac);
|
||||
//send_reply_to_queue(dev->guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
// "终端 id: " + dev->terminal_id + "进行业务:" + get_type_by_state(dev->busytype) +"失败,停止该业务处理");
|
||||
|
||||
dev->guid.clear();
|
||||
dev->isbusy = 0;
|
||||
@@ -6365,10 +6457,13 @@ void on_device_response_minimal(int response_code,
|
||||
// 发送运行信息
|
||||
send_running_info(dev, info);
|
||||
|
||||
std::cout << "[RESP][RUNNINGINFO][OK] dev=" << id << std::endl;
|
||||
|
||||
} else {
|
||||
send_reply_to_queue(dev->guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
"终端 id: " + dev->terminal_id + "进行业务:" +
|
||||
get_type_by_state(dev->busytype) + "失败,运行状态缓存不存在");
|
||||
send_reply_to_cloud(static_cast<int>(ResponseCode::BAD_REQUEST), id, device_state_int, dev->guid, dev->mac);
|
||||
//send_reply_to_queue(dev->guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
// "终端 id: " + dev->terminal_id + "进行业务:" +
|
||||
// get_type_by_state(dev->busytype) + "失败,运行状态缓存不存在");
|
||||
|
||||
std::cout << "[RESP][RUNNINGINFO][WARN] dev=" << id
|
||||
<< " running info missing in cache" << std::endl;
|
||||
@@ -6379,11 +6474,12 @@ void on_device_response_minimal(int response_code,
|
||||
dev->busytype = 0;
|
||||
dev->busytimecount = 0;
|
||||
|
||||
std::cout << "[RESP][RUNNINGINFO][OK] dev=" << id << std::endl;
|
||||
|
||||
} else {
|
||||
send_reply_to_queue(dev->guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
"终端 id: " + dev->terminal_id + "进行业务:" +
|
||||
get_type_by_state(dev->busytype) + "失败,停止该业务处理");
|
||||
send_reply_to_cloud(response_code, id, device_state_int,dev->guid,dev->mac);
|
||||
//send_reply_to_queue(dev->guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
// "终端 id: " + dev->terminal_id + "进行业务:" +
|
||||
// get_type_by_state(dev->busytype) + "失败,停止该业务处理");
|
||||
|
||||
dev->guid.clear();
|
||||
dev->isbusy = 0;
|
||||
@@ -6426,10 +6522,13 @@ void on_device_response_minimal(int response_code,
|
||||
// 发送版本信息
|
||||
send_version_info(dev, info);
|
||||
|
||||
std::cout << "[RESP][VERSIONINFO][OK] dev=" << id << std::endl;
|
||||
|
||||
} else {
|
||||
send_reply_to_queue(dev->guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
"终端 id: " + dev->terminal_id + "进行业务:" +
|
||||
get_type_by_state(dev->busytype) + "失败,版本信息缓存不存在");
|
||||
send_reply_to_cloud(static_cast<int>(ResponseCode::BAD_REQUEST), id, device_state_int, dev->guid, dev->mac);
|
||||
//send_reply_to_queue(dev->guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
// "终端 id: " + dev->terminal_id + "进行业务:" +
|
||||
// get_type_by_state(dev->busytype) + "失败,版本信息缓存不存在");
|
||||
|
||||
std::cout << "[RESP][VERSIONINFO][WARN] dev=" << id
|
||||
<< " version info missing in cache" << std::endl;
|
||||
@@ -6440,11 +6539,12 @@ void on_device_response_minimal(int response_code,
|
||||
dev->busytype = 0;
|
||||
dev->busytimecount = 0;
|
||||
|
||||
std::cout << "[RESP][VERSIONINFO][OK] dev=" << id << std::endl;
|
||||
|
||||
} else {
|
||||
send_reply_to_queue(dev->guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
"终端 id: " + dev->terminal_id + "进行业务:" +
|
||||
get_type_by_state(dev->busytype) + "失败,停止该业务处理");
|
||||
send_reply_to_cloud(response_code, id, device_state_int,dev->guid,dev->mac);
|
||||
//send_reply_to_queue(dev->guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
// "终端 id: " + dev->terminal_id + "进行业务:" +
|
||||
// get_type_by_state(dev->busytype) + "失败,停止该业务处理");
|
||||
|
||||
dev->guid.clear();
|
||||
dev->isbusy = 0;
|
||||
@@ -6500,30 +6600,36 @@ void on_device_response_minimal(int response_code,
|
||||
// 下发升级指令
|
||||
ClientManager::instance().send_upgrade_action_to_device(id, file_data, 10240);
|
||||
|
||||
//正在处理
|
||||
send_reply_to_cloud(static_cast<int>(ResponseCode::PROCESSING), id, device_state_int, dev->guid, dev->mac);
|
||||
|
||||
dev->isbusy = 1; // 完成了预校验但是仍处于忙碌,因为还要升级
|
||||
}else if(dev->isbusy == 1){
|
||||
std::cout << "[SET_PREUPGRADE] already upgrade OK, terminal_id="
|
||||
|
||||
std::cout << "[SET_PREUPGRADE] already upgrade prepare finish, terminal_id="
|
||||
<< id << std::endl;
|
||||
send_reply_to_cloud(response_code, id, device_state_int, dev->guid, dev->mac);
|
||||
send_reply_to_queue(dev->guid, response_code,
|
||||
"终端 id: " + dev->terminal_id + "进行业务:" + get_type_by_state(dev->busytype) + "," + ResponseCodeToString(response_code) + "停止该业务处理");
|
||||
}else if(dev->isbusy == 1){
|
||||
|
||||
//升级成功
|
||||
send_reply_to_cloud(static_cast<int>(ResponseCode::OK), id, device_state_int, dev->guid, dev->mac);
|
||||
//send_reply_to_queue(dev->guid, response_code,
|
||||
// "终端 id: " + dev->terminal_id + "进行业务:" + get_type_by_state(dev->busytype) + "," + ResponseCodeToString(response_code) + "停止该业务处理");
|
||||
//成功结束业务
|
||||
dev->guid.clear(); // 清空 guid
|
||||
dev->busytype = 0; // 业务类型归零
|
||||
dev->isbusy = 0; // 清空业务标志
|
||||
dev->busytimecount = 0; // 计时归零
|
||||
std::cout << "[clear_terminal_runtime_state] Cleared runtime state for terminal_id="
|
||||
<< id << std::endl;
|
||||
|
||||
|
||||
std::cout << "[SET_PREUPGRADE] already upgrade OK, terminal_id="
|
||||
<< id << std::endl;
|
||||
}
|
||||
else {
|
||||
std::cout << "[SET_PREUPGRADE] status error" <<std::endl;
|
||||
// 失败 → 直接结束业务
|
||||
send_reply_to_cloud(response_code, id, device_state_int, dev->guid, dev->mac);
|
||||
send_reply_to_queue(dev->guid, response_code,
|
||||
"终端 id: " + dev->terminal_id +
|
||||
"进行业务:" + get_type_by_state(dev->busytype) +
|
||||
",处理逻辑错误,停止该业务处理");
|
||||
send_reply_to_cloud(static_cast<int>(ResponseCode::BAD_REQUEST), id, device_state_int, dev->guid, dev->mac);
|
||||
//send_reply_to_queue(dev->guid, response_code,
|
||||
// "终端 id: " + dev->terminal_id +
|
||||
// "进行业务:" + get_type_by_state(dev->busytype) +
|
||||
// ",处理逻辑错误,停止该业务处理");
|
||||
dev->guid.clear();
|
||||
dev->busytype = 0;
|
||||
dev->isbusy = 0;
|
||||
@@ -6535,11 +6641,12 @@ void on_device_response_minimal(int response_code,
|
||||
std::cout << "[SET_PREUPGRADE] read/send failed: "
|
||||
<< e.what() << std::endl;
|
||||
|
||||
send_reply_to_cloud(response_code, id, device_state_int, dev->guid, dev->mac);
|
||||
send_reply_to_queue(dev->guid, response_code,
|
||||
"终端 id: " + dev->terminal_id +
|
||||
"进行业务:" + get_type_by_state(dev->busytype) +
|
||||
"," + ResponseCodeToString(response_code) + "停止该业务处理");
|
||||
//未知原因失败,直接结束业务
|
||||
send_reply_to_cloud(static_cast<int>(ResponseCode::FORBIDDEN), id, device_state_int, dev->guid, dev->mac);
|
||||
//send_reply_to_queue(dev->guid, response_code,
|
||||
// "终端 id: " + dev->terminal_id +
|
||||
// "进行业务:" + get_type_by_state(dev->busytype) +
|
||||
// "," + ResponseCodeToString(response_code) + "停止该业务处理");
|
||||
|
||||
// 失败也要清状态
|
||||
dev->guid.clear();
|
||||
@@ -6554,10 +6661,10 @@ void on_device_response_minimal(int response_code,
|
||||
<< id << std::endl;
|
||||
|
||||
send_reply_to_cloud(response_code, id, device_state_int, dev->guid, dev->mac);
|
||||
send_reply_to_queue(dev->guid, response_code,
|
||||
"终端 id: " + dev->terminal_id +
|
||||
"进行业务:" + get_type_by_state(dev->busytype) +
|
||||
"," + ResponseCodeToString(response_code) + "停止该业务处理");
|
||||
//send_reply_to_queue(dev->guid, response_code,
|
||||
// "终端 id: " + dev->terminal_id +
|
||||
// "进行业务:" + get_type_by_state(dev->busytype) +
|
||||
// "," + ResponseCodeToString(response_code) + "停止该业务处理");
|
||||
|
||||
dev->guid.clear();
|
||||
dev->busytype = 0;
|
||||
@@ -7276,39 +7383,40 @@ bool SendFileWebAuto(const std::string& id,
|
||||
if (dev_ptr) {
|
||||
const int bt = dev_ptr->busytype;
|
||||
|
||||
// 若处于“事件文件/统计文件”补招阶段,则使用补招专用上传目录:comtrade/wave/...
|
||||
// 若处于补招阶段,不在这边上传
|
||||
if (bt == static_cast<int>(DeviceState::READING_EVENTFILE) ||
|
||||
bt == static_cast<int>(DeviceState::READING_STATSFILE)) {
|
||||
|
||||
std::string rel = dirname_with_slash(local_path); // 例如:download/00:B7:.../
|
||||
// 将 download/ 前缀替换为 wave/
|
||||
if (!replace_prefix(rel, "download/", "wave/")) {
|
||||
// 若不是以 download/ 开头,兜底拼 wave/ + 原目录
|
||||
rel = "wave/" + rel;
|
||||
}
|
||||
|
||||
file_cloudpath = "comtrade/" + rel; // 目标:comtrade/wave/00:B7:.../
|
||||
|
||||
std::cout << "[SendFileWebAuto] dev=" << id
|
||||
<< " busytype=" << bt
|
||||
<< " -> use recall upload URL (cloud path=" << file_cloudpath << ")\n";
|
||||
} else {
|
||||
<< " -> skip upload (recall file)\n";
|
||||
return true; // 认为成功,外层业务继续处理(但不上传)
|
||||
} else if(bt == static_cast<int>(DeviceState::READING_FILEDATA)) {
|
||||
// 非补招场景沿用原来的 download 目录
|
||||
file_cloudpath = dirname_with_slash(local_path); // 保持原逻辑
|
||||
file_cloudpath = dirname_with_slash(local_path);
|
||||
std::cout << "[SendFileWebAuto] dev=" << id
|
||||
<< " busytype=" << bt
|
||||
<< " -> use default upload URL (cloud path=" << file_cloudpath << ")\n";
|
||||
|
||||
// 实际上传调用
|
||||
SendFileWeb(WEB_FILEUPLOAD, local_path, file_cloudpath, out_filename,2);
|
||||
|
||||
std::cout << "[SendFileWebAuto] File upload complete: " << out_filename << std::endl;
|
||||
|
||||
//记录下载的文件名到列表中,后续发送响应
|
||||
filedownload_cache_put(id,
|
||||
sanitize(local_path),
|
||||
sanitize(out_filename));
|
||||
}
|
||||
else {
|
||||
std::cout << "[SendFileWebAuto][WARN] dev=" << id
|
||||
<< " busytype=" << bt
|
||||
<< " -> no upload (unsupported state)\n";
|
||||
}
|
||||
} else {
|
||||
std::cout << "[SendFileWebAuto][WARN] device not found for id=" << id
|
||||
<< ", fallback to default URL\n";
|
||||
file_cloudpath = dirname_with_slash(local_path);
|
||||
}
|
||||
|
||||
// 实际上传调用
|
||||
SendFileWeb(WEB_FILEUPLOAD, local_path, file_cloudpath, out_filename);
|
||||
|
||||
std::cout << "[SendFileWebAuto] File upload complete: " << out_filename << std::endl;
|
||||
return true;
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
|
||||
@@ -136,7 +136,7 @@ void SendJsonAPI_web(const std::string& strUrl, //接口路径
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////上传文件接口
|
||||
|
||||
//处理文件上传响应
|
||||
void handleUploadResponse(const std::string& response, std::string& wavepath) {
|
||||
void handleUploadResponse(const std::string& response, std::string& wavepath, int type) {
|
||||
|
||||
using nlohmann::json; //把 nlohmann::json 这个名字带到当前作用域
|
||||
|
||||
@@ -183,13 +183,22 @@ void handleUploadResponse(const std::string& response, std::string& wavepath) {
|
||||
// 找到最后一个 '.'
|
||||
size_t pos = name.find_last_of('.');
|
||||
std::string nameWithoutExt;
|
||||
if (pos != std::string::npos) {
|
||||
// 截取去掉后缀的部分
|
||||
nameWithoutExt = name.substr(0, pos);
|
||||
} else {
|
||||
// 如果没有后缀,直接使用原文件名
|
||||
nameWithoutExt = name;
|
||||
if(1 == type) {
|
||||
if (pos != std::string::npos) {
|
||||
// 截取去掉后缀的部分
|
||||
nameWithoutExt = name.substr(0, pos); //去掉路径后缀的名
|
||||
} else {
|
||||
// 如果没有后缀,直接使用原文件名
|
||||
nameWithoutExt = name;
|
||||
}
|
||||
}
|
||||
else if(2 == type) {
|
||||
nameWithoutExt = name;//带路径全名
|
||||
}
|
||||
else{
|
||||
nameWithoutExt = fileName;//没有路径的全名
|
||||
}
|
||||
|
||||
|
||||
// 拷贝到 wavepath
|
||||
wavepath = nameWithoutExt;
|
||||
@@ -199,7 +208,7 @@ void handleUploadResponse(const std::string& response, std::string& wavepath) {
|
||||
}
|
||||
|
||||
//上传文件
|
||||
void SendFileWeb(const std::string& strUrl, const std::string& localpath, const std::string& cloudpath, std::string& wavepath) {
|
||||
void SendFileWeb(const std::string& strUrl, const std::string& localpath, const std::string& cloudpath, std::string& wavepath, int type) {
|
||||
|
||||
// 基本存在性检查
|
||||
if (access(localpath.c_str(), F_OK) != 0) {
|
||||
@@ -274,7 +283,7 @@ void SendFileWeb(const std::string& strUrl, const std::string& localpath, const
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_CONFIG, "通过文件接口上传文件 %s 失败",localpath.c_str());
|
||||
} else {
|
||||
std::cout << "http web success, response: " << resPost0 << std::endl;
|
||||
handleUploadResponse(resPost0, wavepath); // 处理响应
|
||||
handleUploadResponse(resPost0, wavepath, type); // 处理响应
|
||||
}
|
||||
|
||||
// 清理
|
||||
@@ -289,7 +298,7 @@ void SendFileWeb(const std::string& strUrl, const std::string& localpath, const
|
||||
//上传暂态文件
|
||||
void SOEFileWeb(std::string& localpath,std::string& cloudpath, std::string& wavepath)
|
||||
{
|
||||
SendFileWeb(WEB_FILEUPLOAD,localpath,cloudpath,wavepath);
|
||||
SendFileWeb(WEB_FILEUPLOAD,localpath,cloudpath,wavepath,1);
|
||||
}
|
||||
|
||||
//上传文件测试函数
|
||||
|
||||
@@ -718,7 +718,7 @@ bool save_internal_value(const std::string &dev_id, const std::vector<ushort> &f
|
||||
bool save_set_value(const std::string &dev_id, unsigned char mp_index, const std::vector<float> &fabsf);
|
||||
|
||||
//发送文件
|
||||
void SendFileWeb(const std::string& strUrl, const std::string& localpath, const std::string& cloudpath, std::string& wavepath);
|
||||
void SendFileWeb(const std::string& strUrl, const std::string& localpath, const std::string& cloudpath, std::string& wavepath,int Type);
|
||||
|
||||
//状态翻转
|
||||
void connect_status_update(const std::string& id, int status);
|
||||
|
||||
@@ -2083,7 +2083,7 @@ bool parseJsonMessageCLOUD(const std::string &body,
|
||||
std::cerr << "[parseJsonMessageCLOUD] 'messageBody' is missing or is not a string\n";
|
||||
guid.clear();
|
||||
devid.clear();
|
||||
front_ip.clear();
|
||||
front_id.clear();
|
||||
node = 0;
|
||||
detailObj = nlohmann::json::object();
|
||||
return false;
|
||||
@@ -2094,7 +2094,7 @@ bool parseJsonMessageCLOUD(const std::string &body,
|
||||
std::cerr << "[parseJsonMessageCLOUD] 'messageBody' is empty\n";
|
||||
guid.clear();
|
||||
devid.clear();
|
||||
front_ip.clear();
|
||||
front_id.clear();
|
||||
node = 0;
|
||||
detailObj = nlohmann::json::object();
|
||||
return false;
|
||||
@@ -2112,9 +2112,9 @@ bool parseJsonMessageCLOUD(const std::string &body,
|
||||
|
||||
// FrontId
|
||||
if (j.contains("FrontId") && j["FrontId"].is_string()) {
|
||||
front_ip = j["FrontId"].get<std::string>();
|
||||
front_id = j["FrontId"].get<std::string>();
|
||||
} else {
|
||||
front_ip.clear();
|
||||
front_id.clear();
|
||||
}
|
||||
|
||||
// Node
|
||||
@@ -2154,7 +2154,7 @@ bool parseJsonMessageCLOUD(const std::string &body,
|
||||
std::cerr << "[parseJsonMessageCLOUD] JSON parse error: " << e.what() << "\n";
|
||||
guid.clear();
|
||||
devid.clear();
|
||||
front_ip.clear();
|
||||
front_id.clear();
|
||||
node = 0;
|
||||
detailObj = nlohmann::json::object();
|
||||
return false;
|
||||
@@ -2222,10 +2222,23 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
try {
|
||||
switch (parsed.type) {
|
||||
case 1101: { // 读取目录
|
||||
|
||||
if(!recordguid(devid,guid,static_cast<int>(DeviceState::READING_FILEMENU),1)){
|
||||
int ret = recordguid(devid,guid,static_cast<int>(DeviceState::READING_FILEMENU),1);
|
||||
if(-1 == ret){ //0记录成功往下执行,1装置正忙,-1未找到装置
|
||||
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, "记录装置状态成功,准备读取目录");
|
||||
}
|
||||
|
||||
if (!msgObj.contains("Name") || !msgObj["Name"].is_string()) return false;
|
||||
parsed.name = msgObj["Name"].get<std::string>();
|
||||
@@ -2240,8 +2253,24 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
|
||||
case 1102: { // 下载文件
|
||||
|
||||
if(!recordguid(devid,guid,static_cast<int>(DeviceState::READING_FILEDATA),1)){
|
||||
return true;
|
||||
{
|
||||
int ret = recordguid(devid, guid, static_cast<int>(DeviceState::READING_FILEDATA), 1);
|
||||
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, "记录装置状态成功,准备下载文件");
|
||||
}
|
||||
}
|
||||
|
||||
if (!msgObj.contains("Name") || !msgObj["Name"].is_string()) return false;
|
||||
@@ -2276,7 +2305,7 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
parsed.dataArray_us.clear();
|
||||
|
||||
switch (parsed.datatype) {
|
||||
case 0x0C: { // 定值(float 阵列)
|
||||
case 1: { // 定值(float 阵列)
|
||||
|
||||
for (const auto& v : msgObj["DataArray"]) {
|
||||
if (!v.is_number()) return false;
|
||||
@@ -2285,7 +2314,7 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
}
|
||||
|
||||
// 打印 DataArray
|
||||
std::cout << "[0x0C] DataArray=[";
|
||||
std::cout << "[1] DataArray=[";
|
||||
for (size_t i = 0; i < parsed.dataArray_f.size(); ++i) {
|
||||
std::cout << parsed.dataArray_f[i] << (i + 1 < parsed.dataArray_f.size() ? ", " : "");
|
||||
}
|
||||
@@ -2297,8 +2326,24 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
switch (parsed.operate) {
|
||||
case 1: { // 读
|
||||
|
||||
if(!recordguid(devid,guid,static_cast<int>(DeviceState::READING_FIXEDVALUE),2)){
|
||||
return true;
|
||||
{
|
||||
int ret = recordguid(devid, guid, static_cast<int>(DeviceState::READING_FIXEDVALUE), 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, "记录装置状态成功,准备读取定值");
|
||||
}
|
||||
}
|
||||
|
||||
ClientManager::instance().get_fixedvalue_action_to_device(
|
||||
@@ -2308,8 +2353,24 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
}
|
||||
case 2: { // 写
|
||||
|
||||
if(!recordguid(devid,guid,static_cast<int>(DeviceState::SET_FIXEDVALUE),1)){
|
||||
return true;
|
||||
{
|
||||
int ret = recordguid(devid, guid, static_cast<int>(DeviceState::SET_FIXEDVALUE), 1);
|
||||
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, "记录装置状态成功,准备写定值");
|
||||
}
|
||||
}
|
||||
|
||||
ClientManager::instance().set_fixedvalue_action_to_device(
|
||||
@@ -2322,7 +2383,7 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
break;
|
||||
}
|
||||
|
||||
case 0x0D: { // 内部定值(uint16_t 阵列)
|
||||
case 2: { // 内部定值(uint16_t 阵列)
|
||||
for (const auto& v : msgObj["DataArray"]) {
|
||||
if (!v.is_number_integer() && !v.is_number_unsigned()) return false;
|
||||
// 范围校验 [0, 65535]
|
||||
@@ -2332,7 +2393,7 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
}
|
||||
|
||||
// 打印 DataArray
|
||||
std::cout << "[0x0D] DataArray=[";
|
||||
std::cout << "[2] DataArray=[";
|
||||
for (size_t i = 0; i < parsed.dataArray_us.size(); ++i) {
|
||||
std::cout << parsed.dataArray_us[i] << (i + 1 < parsed.dataArray_us.size() ? ", " : "");
|
||||
}
|
||||
@@ -2344,8 +2405,24 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
switch (parsed.operate) {
|
||||
case 1: { // 读
|
||||
|
||||
if(!recordguid(devid,guid,static_cast<int>(DeviceState::READING_INTERFIXEDVALUE),3)){
|
||||
return true;
|
||||
{
|
||||
int ret = recordguid(devid, guid, static_cast<int>(DeviceState::READING_INTERFIXEDVALUE), 3);
|
||||
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, "记录装置状态成功,准备读取内部定值");
|
||||
}
|
||||
}
|
||||
|
||||
ClientManager::instance().get_interfixedvalue_action_to_device(devid); // 获取内部定值
|
||||
@@ -2355,8 +2432,24 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
}
|
||||
case 2: { // 写
|
||||
|
||||
if(!recordguid(devid,guid,static_cast<int>(DeviceState::SET_INTERFIXEDVALUE),1)){
|
||||
return true;
|
||||
{
|
||||
int ret = recordguid(devid, guid, static_cast<int>(DeviceState::SET_INTERFIXEDVALUE), 1);
|
||||
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, "记录装置状态成功,准备写内部定值");
|
||||
}
|
||||
}
|
||||
|
||||
ClientManager::instance().set_interfixedvalue_action_to_device(devid, parsed.dataArray_us);
|
||||
@@ -2384,8 +2477,24 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
<< ", guid=" << guid << std::endl;
|
||||
|
||||
//
|
||||
if (!recordguid(devid, guid, static_cast<int>(DeviceState::READING_RUNNINGINFORMATION_1), 1)) {
|
||||
return true;
|
||||
{
|
||||
int ret = recordguid(devid, guid, static_cast<int>(DeviceState::READING_RUNNINGINFORMATION_1), 1);
|
||||
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, "记录装置状态成功,准备读取运行状态");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -2399,8 +2508,24 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
std::cout << "[parsemsg] read version info, devid=" << devid
|
||||
<< ", guid=" << guid << std::endl;
|
||||
|
||||
if (!recordguid(devid, guid, static_cast<int>(DeviceState::READING_DEVVERSION), 1)) {
|
||||
return true;
|
||||
{
|
||||
int ret = recordguid(devid, guid, static_cast<int>(DeviceState::READING_DEVVERSION), 1);
|
||||
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, "记录装置状态成功,准备读取版本信息");
|
||||
}
|
||||
}
|
||||
|
||||
ClientManager::instance().read_devversion_action_to_device(devid);
|
||||
@@ -2413,11 +2538,27 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
std::cout << "[parsemsg] time sync, devid=" << devid
|
||||
<< ", guid=" << guid << std::endl;
|
||||
|
||||
if (!recordguid(devid, guid, static_cast<int>(DeviceState::SET_RIGHTTIME_2), 1)) {
|
||||
return true;
|
||||
{
|
||||
int ret = recordguid(devid, guid, static_cast<int>(DeviceState::SET_RIGHTTIME_2), 1);
|
||||
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, "记录装置状态成功,准备对时");
|
||||
}
|
||||
}
|
||||
|
||||
// 方案A:Msg 为空,直接使用当前系统时间下发
|
||||
//
|
||||
ClientManager::instance().set_righttime_action_to_device(devid);
|
||||
|
||||
return true;
|
||||
@@ -2429,8 +2570,24 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
std::cout << "[parsemsg] reboot device, devid=" << devid
|
||||
<< ", guid=" << guid << std::endl;
|
||||
|
||||
if (!recordguid(devid, guid, static_cast<int>(DeviceState::SET_CTRL), 1)) {
|
||||
return true;
|
||||
{
|
||||
int ret = recordguid(devid, guid, static_cast<int>(DeviceState::SET_CTRL), 1);
|
||||
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, "记录装置状态成功,准备重启装置");
|
||||
}
|
||||
}
|
||||
|
||||
ClientManager::instance().set_ctrl_action_to_device(devid,0x01,0x00);//尝试装置重启指令!
|
||||
@@ -2443,8 +2600,24 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
std::cout << "[parsemsg] upgrade device, devid=" << devid
|
||||
<< ", guid=" << guid << std::endl;
|
||||
|
||||
if (!recordguid(devid, guid, static_cast<int>(DeviceState::SET_PREUPGRADE), 2)) {
|
||||
return true;
|
||||
{
|
||||
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, "记录装置状态成功,准备执行升级预校验");
|
||||
}
|
||||
}
|
||||
|
||||
ClientManager::instance().set_preupgrade_action_to_device(devid, "");//尝试装置升级指令!第一步校验
|
||||
@@ -2465,7 +2638,29 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
}
|
||||
}
|
||||
|
||||
//心跳和其他响应
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////云响应
|
||||
static int get_cloud_type_by_state(int type)
|
||||
{
|
||||
switch (static_cast<DeviceState>(type)) {
|
||||
case DeviceState::READING_FILEMENU: return 1101; // 读取文件目录
|
||||
case DeviceState::READING_FILEDATA: return 1102; // 下载文件数据
|
||||
|
||||
case DeviceState::READING_FIXEDVALUE: return 1103; // 读取测点定值
|
||||
case DeviceState::SET_FIXEDVALUE: return 1103; // 设置测点定值
|
||||
case DeviceState::READING_INTERFIXEDVALUE: return 1103; // 读取内部定值
|
||||
case DeviceState::SET_INTERFIXEDVALUE: return 1103; // 设置内部定值
|
||||
|
||||
case DeviceState::READING_RUNNINGINFORMATION_1: return 1111; // 主动读取运行状态
|
||||
case DeviceState::READING_DEVVERSION: return 1112; // 读取版本信息
|
||||
case DeviceState::SET_RIGHTTIME_2: return 1113; // 主动对时
|
||||
case DeviceState::SET_CTRL: return 1114; // 控制/重启
|
||||
case DeviceState::SET_PREUPGRADE: return 1115; // 升级预校验
|
||||
|
||||
default:
|
||||
return type; // 其他未映射的,保持原值,避免影响现有逻辑
|
||||
}
|
||||
}
|
||||
|
||||
void send_reply_to_cloud(int reply_code, const std::string& dev_id, int type, const std::string& guid, const std::string& mac) {
|
||||
try {
|
||||
/*std::string guid = find_guid_index_from_dev_id(dev_id);*/
|
||||
@@ -2487,7 +2682,7 @@ void send_reply_to_cloud(int reply_code, const std::string& dev_id, int type, co
|
||||
|
||||
// ---- 构造 Detail ----
|
||||
nlohmann::json detail;
|
||||
detail["Type"] = type;
|
||||
detail["Type"] = get_cloud_type_by_state(type);
|
||||
|
||||
// Msg
|
||||
nlohmann::json msg;
|
||||
|
||||
Reference in New Issue
Block a user