diff --git a/src/mqtt_client_wrapper.cpp b/src/mqtt_client_wrapper.cpp index 117d2be..8adc0b0 100644 --- a/src/mqtt_client_wrapper.cpp +++ b/src/mqtt_client_wrapper.cpp @@ -40,6 +40,8 @@ static void on_mqtt_message_received(const std::string &topic, const std::string } int status = j["data"]["status"].get(); + std::string seqNo = j["seqNo"].get(); + bool success = true; // 标记是否操作成功 if (status == 0) { @@ -74,7 +76,25 @@ static void on_mqtt_message_received(const std::string &topic, const std::string else { LOG_WARN("[MQTT] video_down: unknown status value " + std::to_string(status)); + success = false; } + + // 获取当前时间 yyyyMMddHHmmssSSS + auto now = std::chrono::system_clock::now(); + auto millis = std::chrono::duration_cast(now.time_since_epoch()) % 1000; + std::time_t t = std::chrono::system_clock::to_time_t(now); + std::tm tm_now = *std::localtime(&t); + std::ostringstream time_ss; + time_ss << std::put_time(&tm_now, "%Y%m%d%H%M%S") << std::setw(3) << std::setfill('0') << millis.count(); + + nlohmann::json reply; + reply["time"] = time_ss.str(); + reply["result"] = success ? 0 : 1; + reply["seqNo"] = seqNo; + + // 发送应答 + MQTTClientWrapper::publish(g_app_config.mqtt.topics.substream_down_ack, reply.dump()); + LOG_INFO("[MQTT] Replied to video_down: " + reply.dump()); } else if (topic == g_app_config.mqtt.topics.substream_down) {