diff --git a/src/mqtt_client_wrapper.cpp b/src/mqtt_client_wrapper.cpp index f659018..7792c86 100644 --- a/src/mqtt_client_wrapper.cpp +++ b/src/mqtt_client_wrapper.cpp @@ -284,16 +284,37 @@ static void on_mqtt_message_received(const std::string& topic, const std::string { auto j = nlohmann::json::parse(message); - // 必须是 request - if (!j.contains("type") || j["type"] != "request") + LOG_INFO("[MQTT] Received message on [" + topic + "]"); + LOG_INFO("[MQTT] Payload: " + j.dump(-1)); + + // =============================== + // 1. vehicle_ctrl:放宽协议限制 + // =============================== + if (topic == g_app_config.mqtt.topics.vehicle_ctrl) { + // vehicle_ctrl 只要求有 command + if (!j.contains("command")) + { + LOG_WARN("[MQTT] vehicle_ctrl missing 'command'"); + return; + } + + handle_vehicle_ctrl_request(j); return; } - LOG_INFO("[MQTT] Received request on [" + topic + "]"); - LOG_INFO("[MQTT] Payload: " + j.dump(-1)); + // ========================================== + // 2. 其他 topic:必须是 type=request + // ========================================== + if (!j.contains("type") || j["type"] != "request") + { + // 非 request 的消息直接忽略 + return; + } - // 根据 topic 分发 + // =============================== + // 3. 按 topic 分发 + // =============================== if (topic == g_app_config.mqtt.topics.video_down) { handle_video_down_request(j); @@ -306,10 +327,6 @@ static void on_mqtt_message_received(const std::string& topic, const std::string { handle_record_play_request(j); } - else if (topic == g_app_config.mqtt.topics.vehicle_ctrl) - { - handle_vehicle_ctrl_request(j); - } else { LOG_WARN("[MQTT] Unknown topic: " + topic);