feat: V1.03 initialize 上线消息 — 固件+工具同步

vd960DBN:
- dev_initialize_pub() 改为 V1.03 格式 (msg_id/cmd/ts/data/extra_info)
- iot_mqtt_srv: 订阅改双主题 dld960/{sn}/srv, 响应 topic 改 dev
- SUBACK 后自动发 initialize 告知服务器上线
- net_srv.h: 加 dev_initialize_pub 声明

DBNMQTTool:
- protocol.py: 加 CMD_INITIALIZE
- device_manager: DeviceInfo 加 extra_info, 加 mark_online()
- main.py: 接收 initialize 消息, 自动标记设备上线
- docs: 协议 V1.03 + devlog V3.1
This commit is contained in:
wangfq
2026-07-09 21:32:39 +08:00
parent 1ff731c309
commit 652fc5f938
7 changed files with 56 additions and 26 deletions
@@ -110,23 +110,17 @@ static int iot_mqtt_send_connect(void) {
return iot_mqtt_send(buf, (uint16_t)len);
}
/* 发送 MQTT SUBSCRIBE */
/* 发送 MQTT SUBSCRIBE — V1.01 双主题协议 */
static int iot_mqtt_send_subscribe(void) {
static uint8_t buf[256]; // static: 避免栈溢出
int len;
char topic[IOT_MQTT_TOPIC_MAX_LEN];
MQTTString topics[3];
int qos[3] = {1, 1, 1};
MQTTString topics[1];
int qos[1] = {1};
int count = 0;
// 订阅服务器下发消息
iot_make_topic(topic, sizeof(topic), "srv", "config", "set");
topics[count].cstring = topic; topics[count].lenstring.len = 0; count++;
iot_make_topic(topic, sizeof(topic), "srv", "config", "query");
topics[count].cstring = topic; topics[count].lenstring.len = 0; count++;
iot_make_topic(topic, sizeof(topic), "srv", "ctrl", NULL);
// V1.01: 仅订阅 dld960/{sn}/srv 双主题
snprintf(topic, sizeof(topic), "dld960/%s/srv", g_iot_dev_serial);
topics[count].cstring = topic; topics[count].lenstring.len = 0; count++;
len = MQTTSerialize_subscribe(buf, sizeof(buf), 0,
@@ -192,9 +186,9 @@ static void iot_handle_publish(const char *topic, uint8_t *payload, int payload_
return;
}
/* 构建响应 topic */
/* 构建响应 topic — V1.01 双主题 */
char resp_topic[IOT_MQTT_TOPIC_MAX_LEN];
iot_make_topic(resp_topic, sizeof(resp_topic), "dev", "config", "resp");
snprintf(resp_topic, sizeof(resp_topic), "dld960/%s/dev", g_iot_dev_serial);
/* 处理命令 — 复用 TCP JSON 的命令逻辑 */
/* 目前仅实现基本响应框架, 后续逐步对接 Loop MCU 命令 */
@@ -268,6 +262,9 @@ static void iot_handle_suback(void) {
PRINT("IOT: ← SUBACK, topics subscribed\n");
g_iot_state = IOT_STATE_READY;
_iot_reconnect_backoff = 0; // 连接成功, 重置退避
// V1.03: 订阅成功后发布 initialize 告知服务器上线
dev_initialize_pub();
}
/* 处理收到的 MQTT 数据 */
@@ -386,10 +383,9 @@ void iot_mqtt_publish_sensor(void) {
return;
}
/* 全通道一次性上报,字段按 DLD960_TCP_JSON协议.md §5.1:
ch, freq_level, has_car, loop_ok, freq_current, freq_diff,
sensitivity, condition, misc.type, misc.value
注意: mqttBuf 需 ≥ 1024 才能容纳 4 通道全字段封包 (~846 字节) */
/* 全通道一次性上报,字段按 DLD960_IoT_MQTT协议.md §5.2 V1.02:
ch, level, iscar, loop_ok, freq, diff, sens, cndtn, misc.{type,value}
注意: mqttBuf 需 ≥ 1024 才能容纳 4 通道全字段封包 (~800 字节) */
static char data_json[1024];
static char payload[1400];
char *p = data_json;