1
This commit is contained in:
parent
d1de25f32c
commit
97e9efb262
@ -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;
|
||||
}
|
||||
|
||||
LOG_INFO("[MQTT] Received request on [" + topic + "]");
|
||||
LOG_INFO("[MQTT] Payload: " + j.dump(-1));
|
||||
handle_vehicle_ctrl_request(j);
|
||||
return;
|
||||
}
|
||||
|
||||
// 根据 topic 分发
|
||||
// ==========================================
|
||||
// 2. 其他 topic:必须是 type=request
|
||||
// ==========================================
|
||||
if (!j.contains("type") || j["type"] != "request")
|
||||
{
|
||||
// 非 request 的消息直接忽略
|
||||
return;
|
||||
}
|
||||
|
||||
// ===============================
|
||||
// 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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user