From ab3a4cea0abb06e65dd2bec1e9e525dc0685f013 Mon Sep 17 00:00:00 2001 From: wangfq Date: Tue, 7 Jul 2026 10:57:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=87=BA=E5=8E=82=E9=BB=98=E8=AE=A4=20t?= =?UTF-8?q?opic=20=E4=BD=BF=E7=94=A8=E7=9C=9F=E5=AE=9E=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8F=B7=20+=20PRINT=20=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - cfig_flash.c: factory_dev_info() 用 gMacAddr 生成真实主题 dld960/{SN}/srv + dld960/{SN}/dev - net_srv.h: TOPIC_DEFAULT 加注释标明为格式模板 - net_srv.c: 修复上次提交的 PRINT 宏转义异常 --- .../OnlyUpdateApp_Peripheral/APP/cfig_flash.c | 18 +++++++++++++++--- .../APP/include/net_srv.h | 2 ++ .../BLE/OnlyUpdateApp_Peripheral/APP/net_srv.c | 9 +-------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/cfig_flash.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/cfig_flash.c index 71433b4..b51e291 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/cfig_flash.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/cfig_flash.c @@ -4,7 +4,7 @@ * @author wfq * @version V1.0 * @date 2025-02-07 -* @brief ?????????????????????????? +* @brief ??????????��?��??????????????? * @attention ****************************************************************************** */ @@ -89,11 +89,23 @@ void factory_dev_info(void) "password", 0 }; + + // 使用实际设备序列号生成默认 topic(V1.01 双主题协议) + char sn_str[13]; + sprintf(sn_str, "%02X%02X%02X%02X%02X%02X", + gMacAddr[0], gMacAddr[1], gMacAddr[2], + gMacAddr[3], gMacAddr[4], gMacAddr[5]); + char default_pub[64], default_sub[64]; + sprintf(default_pub, "dld960/%s/dev", sn_str); + sprintf(default_sub, "dld960/%s/srv", sn_str); + IOT_Topic _topic = { 0, - TOPIC_DEFAULT_PUBLISH, - TOPIC_DEFAULT_SUBSCRIBE + {0}, + {0} }; + strncpy((char *)_topic.topic_pub, default_pub, MAX_TOPIC_LENGTH - 1); + strncpy((char *)_topic.topic_sub, default_sub, MAX_TOPIC_LENGTH - 1); write_net_config(&lcfg, &ccfg, &icfg, &_topic); } diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/include/net_srv.h b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/include/net_srv.h index 2f038f3..d4e8f9c 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/include/net_srv.h +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/include/net_srv.h @@ -32,6 +32,8 @@ #define COM_LSSC_UDP_PORT 5500 #define COM_DEV_MESSAGE_PORT 4900 //udp dev local message port +// 默认 Topic 格式模板(V1.01 双主题) +// 实际出厂值时 factory_dev_info() 会用真实序列号替换 {sn} #define TOPIC_DEFAULT_SUBSCRIBE "dld960/{sn}/srv" #define TOPIC_DEFAULT_PUBLISH "dld960/{sn}/dev" diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/net_srv.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/net_srv.c index b5da4ad..8b5e9ee 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/net_srv.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/net_srv.c @@ -141,9 +141,7 @@ void dg_subscribe_display_topic(void) strcpy(mBuff, (char *)g_iot_topic.topic_sub); { - PRINT(" -\nWill subscribe display_topic:\n%s -\n", mBuff); + PRINT("\nWill subscribe display_topic:\n%s\n", mBuff); } MQTT_Subscribe(mBuff, 1); @@ -219,11 +217,6 @@ void dev_response_heartbeat(char *dat) void mqtt_deserialize_publish(char* topic, char* msg, int length) { -// if(g_flag_debug) -// { -// printf("display_mqtt_callback rev topic: %s\n msg:%s, len:%d -\n", topic, msg, length); -// } // V1.01: 使用配置的 topic_sub 匹配,而非硬编码默认值 if(strstr(topic, (char *)g_iot_topic.topic_sub) != NULL) {