This commit is contained in:
cxh 2025-12-30 09:29:11 +08:00
parent d1de25f32c
commit 97e9efb262

View File

@ -284,16 +284,37 @@ static void on_mqtt_message_received(const std::string& topic, const std::string
{ {
auto j = nlohmann::json::parse(message); auto j = nlohmann::json::parse(message);
// 必须是 request LOG_INFO("[MQTT] Received message on [" + topic + "]");
if (!j.contains("type") || j["type"] != "request") 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; 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) if (topic == g_app_config.mqtt.topics.video_down)
{ {
handle_video_down_request(j); 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); handle_record_play_request(j);
} }
else if (topic == g_app_config.mqtt.topics.vehicle_ctrl)
{
handle_vehicle_ctrl_request(j);
}
else else
{ {
LOG_WARN("[MQTT] Unknown topic: " + topic); LOG_WARN("[MQTT] Unknown topic: " + topic);