修改多余话题消息处理

This commit is contained in:
cxh 2026-01-22 15:00:11 +08:00
parent b3ff821ef4
commit dc0fc7047a

View File

@ -244,57 +244,45 @@ static void handle_record_play_request(const nlohmann::json& req)
mqtt_client->publish(g_app_config.mqtt.topics.record_play, resp.dump(), 1);
}
static void handle_vehicle_ctrl_request(const nlohmann::json& req)
{
std::string cmd = req.value("command", "");
int value = req.value("value", 0);
// value 固定为 1不是 1 直接忽略
if (value != 1)
{
LOG_WARN("[vehicle_ctrl] ignore command=" + cmd + " value=" + std::to_string(value));
return;
}
if (cmd == "startCtrl")
{
LOG_INFO("[vehicle_ctrl] startCtrl → ENABLE live");
RTMPManager::set_live_enabled_all(true);
return;
}
if (cmd == "stopCtrl")
{
LOG_INFO("[vehicle_ctrl] stopCtrl → DISABLE live");
RTMPManager::set_live_enabled_all(false);
return;
}
LOG_WARN("[vehicle_ctrl] unknown command: " + cmd);
}
static void on_mqtt_message_received(const std::string& topic, const std::string& message)
{
try
{
auto j = nlohmann::json::parse(message);
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"))
// 必须存在 data且 data 是对象
if (!j.contains("data") || !j["data"].is_object()) return;
const auto& d = j["data"];
std::string cmd = d.value("command", "");
int value = d.value("value", 0);
// 视频程序只关心 startCtrl / stopCtrl其它不打印也不处理
if (value != 1) return;
if (cmd != "startCtrl" && cmd != "stopCtrl") return;
// 视频关心的指令才打印
LOG_INFO("[MQTT] Received message on [" + topic + "]");
LOG_INFO("[MQTT] Payload: " + j.dump(-1));
// 执行
if (cmd == "startCtrl")
{
LOG_WARN("[MQTT] vehicle_ctrl missing 'command'");
return;
LOG_INFO("[vehicle_ctrl] startCtrl → ENABLE live");
RTMPManager::set_live_enabled_all(true);
}
else // stopCtrl
{
LOG_INFO("[vehicle_ctrl] stopCtrl → DISABLE live");
RTMPManager::set_live_enabled_all(false);
}
handle_vehicle_ctrl_request(j);
return;
}
@ -307,6 +295,9 @@ static void on_mqtt_message_received(const std::string& topic, const std::string
return;
}
LOG_INFO("[MQTT] Received message on [" + topic + "]");
LOG_INFO("[MQTT] Payload: " + j.dump(-1));
// ===============================
// 3. 按 topic 分发
// ===============================