first commit
This commit is contained in:
parent
748c7e0d1b
commit
54eef994cb
@ -82,10 +82,16 @@ static void on_mqtt_message_received(const std::string &topic, const std::string
|
|||||||
// 获取当前时间 yyyyMMddHHmmssSSS (UTC+8)
|
// 获取当前时间 yyyyMMddHHmmssSSS (UTC+8)
|
||||||
std::string time_str = Logger::get_current_time_utc8();
|
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;
|
nlohmann::json reply;
|
||||||
reply["time"] = time_str;
|
reply["data"] = reply_data;
|
||||||
reply["result"] = success ? 0 : 1;
|
reply["isEnc"] = 0;
|
||||||
reply["seqNo"] = seqNo;
|
reply["type"] = 0;
|
||||||
|
|
||||||
// 发送应答
|
// 发送应答
|
||||||
if (mqtt_client)
|
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)
|
else if (topic == g_app_config.mqtt.topics.reset_down)
|
||||||
{
|
{
|
||||||
// 处理 reset_down
|
auto j = nlohmann::json::parse(message);
|
||||||
LOG_INFO("[MQTT] reset_down message received (not implemented yet).");
|
|
||||||
|
// 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
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user