fix cloudtopic msg proc
This commit is contained in:
@@ -2071,11 +2071,37 @@ bool parseJsonMessageCLOUD(const std::string &body,
|
||||
std::string &devid,
|
||||
std::string &guid,
|
||||
nlohmann::json &detailObj, // 这里返回整个 Detail
|
||||
std::string &front_ip, // 新增:返回 FrontIP
|
||||
std::string &front_id, // 新增:返回 FrontId
|
||||
int &node) // 新增:返回 Node
|
||||
{
|
||||
try {
|
||||
auto j = nlohmann::json::parse(body);
|
||||
// ====== 先解析外层 JSON ======
|
||||
auto outer = nlohmann::json::parse(body);
|
||||
|
||||
// ====== 提取 messageBody 字符串 ======
|
||||
if (!outer.contains("messageBody") || !outer["messageBody"].is_string()) {
|
||||
std::cerr << "[parseJsonMessageCLOUD] 'messageBody' is missing or is not a string\n";
|
||||
guid.clear();
|
||||
devid.clear();
|
||||
front_ip.clear();
|
||||
node = 0;
|
||||
detailObj = nlohmann::json::object();
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string messageBodyStr = outer["messageBody"].get<std::string>();
|
||||
if (messageBodyStr.empty()) {
|
||||
std::cerr << "[parseJsonMessageCLOUD] 'messageBody' is empty\n";
|
||||
guid.clear();
|
||||
devid.clear();
|
||||
front_ip.clear();
|
||||
node = 0;
|
||||
detailObj = nlohmann::json::object();
|
||||
return false;
|
||||
}
|
||||
|
||||
// ====== 再解析 messageBody 内层 JSON ======
|
||||
auto j = nlohmann::json::parse(messageBodyStr);
|
||||
|
||||
// guid
|
||||
if (j.contains("guid") && j["guid"].is_string()) {
|
||||
@@ -2084,9 +2110,9 @@ bool parseJsonMessageCLOUD(const std::string &body,
|
||||
guid.clear();
|
||||
}
|
||||
|
||||
// FrontIP
|
||||
if (j.contains("FrontIP") && j["FrontIP"].is_string()) {
|
||||
front_ip = j["FrontIP"].get<std::string>();
|
||||
// FrontId
|
||||
if (j.contains("FrontId") && j["FrontId"].is_string()) {
|
||||
front_ip = j["FrontId"].get<std::string>();
|
||||
} else {
|
||||
front_ip.clear();
|
||||
}
|
||||
@@ -2171,7 +2197,7 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
if (detailObj.contains("Type")) {
|
||||
if (detailObj["Type"].is_string()) {
|
||||
try {
|
||||
parsed.type = std::stoi(detailObj["Type"].get<std::string>(), nullptr, 0); // 支持 "0x2106" 格式
|
||||
parsed.type = std::stoi(detailObj["Type"].get<std::string>(), nullptr, 0); // 支持 "1103" 格式
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
@@ -2195,7 +2221,7 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
|
||||
try {
|
||||
switch (parsed.type) {
|
||||
case 0x2131: { // 读取目录
|
||||
case 1101: { // 读取目录
|
||||
|
||||
if(!recordguid(devid,guid,static_cast<int>(DeviceState::READING_FILEMENU),1)){
|
||||
return true;
|
||||
@@ -2212,7 +2238,7 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
return true;
|
||||
}
|
||||
|
||||
case 0x2132: { // 下载文件
|
||||
case 1102: { // 下载文件
|
||||
|
||||
if(!recordguid(devid,guid,static_cast<int>(DeviceState::READING_FILEDATA),1)){
|
||||
return true;
|
||||
@@ -2229,7 +2255,7 @@ bool parsemsg(const std::string& devid, const std::string& guid, const nlohmann:
|
||||
return true;
|
||||
}
|
||||
|
||||
case 0x2106: { // 定值/内部定值
|
||||
case 1103: { // 定值/内部定值
|
||||
if (!msgObj.contains("Cldid") || !msgObj["Cldid"].is_number_integer()) return false;
|
||||
if (!msgObj.contains("DataType") || !msgObj["DataType"].is_number_integer()) return false;
|
||||
if (!msgObj.contains("Operate") || !msgObj["Operate"].is_number_integer()) return false;
|
||||
@@ -2403,11 +2429,25 @@ 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), 2)) {//分两步,一步校验一步重启
|
||||
if (!recordguid(devid, guid, static_cast<int>(DeviceState::SET_CTRL), 1)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ClientManager::instance().set_ctrl_action_to_device(devid,0x01,0x00);//尝试装置重启指令!第一步校验
|
||||
ClientManager::instance().set_ctrl_action_to_device(devid,0x01,0x00);//尝试装置重启指令!
|
||||
return true;
|
||||
}
|
||||
|
||||
case 1115: { // 升级
|
||||
parsed.ok = true;
|
||||
|
||||
std::cout << "[parsemsg] upgrade device, devid=" << devid
|
||||
<< ", guid=" << guid << std::endl;
|
||||
|
||||
if (!recordguid(devid, guid, static_cast<int>(DeviceState::SET_PREUPGRADE), 2)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ClientManager::instance().set_preupgrade_action_to_device(devid, "");//尝试装置升级指令!第一步校验
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2461,10 +2501,10 @@ void send_reply_to_cloud(int reply_code, const std::string& dev_id, int type, co
|
||||
|
||||
// ---- 入队发送 ----
|
||||
queue_data_t connect_info;
|
||||
connect_info.strTopic = Topic_Reply_Topic;
|
||||
connect_info.strTopic = Cloud_Reply_Topic;
|
||||
connect_info.strText = obj.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);
|
||||
|
||||
Reference in New Issue
Block a user