fix: 出厂默认 topic 使用真实设备序列号 + PRINT 修正

- cfig_flash.c: factory_dev_info() 用 gMacAddr 生成真实主题 dld960/{SN}/srv + dld960/{SN}/dev
- net_srv.h: TOPIC_DEFAULT 加注释标明为格式模板
- net_srv.c: 修复上次提交的 PRINT 宏转义异常
This commit is contained in:
wangfq
2026-07-07 10:57:20 +08:00
parent b707241429
commit ab3a4cea0a
3 changed files with 18 additions and 11 deletions
@@ -4,7 +4,7 @@
* @author wfq * @author wfq
* @version V1.0 * @version V1.0
* @date 2025-02-07 * @date 2025-02-07
* @brief ??????????¡ã?¡À??????????????? * @brief ??????????????????????????
* @attention * @attention
****************************************************************************** ******************************************************************************
*/ */
@@ -89,11 +89,23 @@ void factory_dev_info(void)
"password", "password",
0 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 = { IOT_Topic _topic = {
0, 0,
TOPIC_DEFAULT_PUBLISH, {0},
TOPIC_DEFAULT_SUBSCRIBE {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); write_net_config(&lcfg, &ccfg, &icfg, &_topic);
} }
@@ -32,6 +32,8 @@
#define COM_LSSC_UDP_PORT 5500 #define COM_LSSC_UDP_PORT 5500
#define COM_DEV_MESSAGE_PORT 4900 //udp dev local message port #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_SUBSCRIBE "dld960/{sn}/srv"
#define TOPIC_DEFAULT_PUBLISH "dld960/{sn}/dev" #define TOPIC_DEFAULT_PUBLISH "dld960/{sn}/dev"
@@ -141,9 +141,7 @@ void dg_subscribe_display_topic(void)
strcpy(mBuff, (char *)g_iot_topic.topic_sub); strcpy(mBuff, (char *)g_iot_topic.topic_sub);
{ {
PRINT(" PRINT("\nWill subscribe display_topic:\n%s\n", mBuff);
\nWill subscribe display_topic:\n%s
\n", mBuff);
} }
MQTT_Subscribe(mBuff, 1); MQTT_Subscribe(mBuff, 1);
@@ -219,11 +217,6 @@ void dev_response_heartbeat(char *dat)
void mqtt_deserialize_publish(char* topic, char* msg, int length) 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 匹配,而非硬编码默认值 // V1.01: 使用配置的 topic_sub 匹配,而非硬编码默认值
if(strstr(topic, (char *)g_iot_topic.topic_sub) != NULL) if(strstr(topic, (char *)g_iot_topic.topic_sub) != NULL)
{ {