From 54eef994cbe79ec3d66dc0df7751cfc43c735234 Mon Sep 17 00:00:00 2001 From: cxh Date: Tue, 9 Sep 2025 15:07:51 +0800 Subject: [PATCH] first commit --- src/mqtt_client_wrapper.cpp | 52 +++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/src/mqtt_client_wrapper.cpp b/src/mqtt_client_wrapper.cpp index 062fd58..2bd21a9 100644 --- a/src/mqtt_client_wrapper.cpp +++ b/src/mqtt_client_wrapper.cpp @@ -82,10 +82,16 @@ static void on_mqtt_message_received(const std::string &topic, const std::string // 获取当前时间 yyyyMMddHHmmssSSS (UTC+8) std::string time_str = Logger::get_current_time_utc8(); + nlohmann::json reply_data; + reply_data["time"] = time_str; + reply_data["result"] = success ? 0 : 1; + reply_data["seqNo"] = seqNo; + + // 封装外层 nlohmann::json reply; - reply["time"] = time_str; - reply["result"] = success ? 0 : 1; - reply["seqNo"] = seqNo; + reply["data"] = reply_data; + reply["isEnc"] = 0; + reply["type"] = 0; // 发送应答 if (mqtt_client) @@ -101,8 +107,44 @@ static void on_mqtt_message_received(const std::string &topic, const std::string } else if (topic == g_app_config.mqtt.topics.reset_down) { - // 处理 reset_down - LOG_INFO("[MQTT] reset_down message received (not implemented yet)."); + auto j = nlohmann::json::parse(message); + + // reset/down 的 payload 在 data 里 + auto data = j.contains("data") ? j["data"] : nlohmann::json::object(); + + std::string seqNo = data.value("seqNo", ""); + std::string errCode = data.value("errorCode", ""); + std::string des = data.value("des", ""); + + LOG_WARN("[MQTT] Reset command received, errorCode=" + errCode + ", des=" + des); + + // 停止所有流,相当于复位 + for (const auto &cam : g_app_config.cameras) + { + if (RTSPManager::is_streaming(cam.name)) + { + RTSPManager::unmount_camera(cam); + LOG_INFO("[RTSP] Camera " + cam.name + " reset/unmounted"); + } + } + + // 组装应答 data + nlohmann::json reply_data; + reply_data["time"] = Logger::get_current_time_utc8(); + reply_data["result"] = 0; // 0=成功 + reply_data["seqNo"] = seqNo; + + // 外层封装 + nlohmann::json reply; + reply["data"] = reply_data; + reply["isEnc"] = 0; + reply["type"] = 0; + + if (mqtt_client) + { + mqtt_client->publish(g_app_config.mqtt.topics.reset_down_ack, reply.dump()); + LOG_INFO("[MQTT] Replied to reset_down: " + reply.dump()); + } } else {