refactor(vd960DBN): replace compile-time NET_SSC/NET_JSON/NET_IOT macros with runtime g_sub_code_enable.iot_enable
- Remove NET_SSC_ENABLE, NET_JSON_ENABLE, NET_IOT_ENABLE from net_config.h - Socket config always allocates max: 1 UDP + 2 TCP + 1 TCP_LISTEN - All #if guards in net_srv.c/h and peripheral_main.c replaced with runtime g_sub_code_enable.iot_enable checks - iot_enable=0 -> SSC mode (UDP + TCP client + JSON server) - iot_enable=1 -> IoT MQTT mode (MQTT client via iot_mqtt_srv)
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* @version V1.0
|
||||
* @date 2026-07-03
|
||||
* @brief IoT MQTT 客户端 — DLD960 IoT 协议 (MQTT + JSON)
|
||||
* 当 NET_SSC_ENABLE=0 时启用, 替代 SSC 模式
|
||||
* 当 g_sub_code_enable.iot_enable=1 时启用, 替代 SSC 模式
|
||||
* 协议参考: docs/DLD960_IoT_MQTT协议.md
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
@@ -18,39 +18,19 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* Feature toggles (0 = disabled, 1 = enabled)
|
||||
* Feature toggles
|
||||
*
|
||||
* 模式互斥:
|
||||
* NET_SSC_ENABLE=1 → SSC 模式 (UDP+TCP client) + TCP JSON server
|
||||
* NET_SSC_ENABLE=0 → IoT MQTT 模式 (MQTT client)
|
||||
*/
|
||||
#define NET_SSC_ENABLE 0 /* SSC (UDP + TCP client) protocol support */
|
||||
#define NET_JSON_ENABLE 1 /* TCP JSON protocol server (port 5960) */
|
||||
#define NET_IOT_ENABLE (!NET_SSC_ENABLE) /* IoT MQTT client (auto-derived) */
|
||||
|
||||
/*********************************************************************
|
||||
* socket configuration, IPRAW + UDP + TCP + TCP_LISTEN = number of sockets
|
||||
* 模式不再通过编译宏选择, 改为运行时 g_sub_code_enable.iot_enable:
|
||||
* iot_enable=0 → SSC 模式 (UDP+TCP client + TCP JSON server)
|
||||
* iot_enable=1 → IoT MQTT 模式 (MQTT client)
|
||||
*
|
||||
* Socket 数量按最坏情况 (SSC 模式) 静态分配:
|
||||
* 1 UDP + 2 TCP + 1 TCP_LISTEN = 4
|
||||
*/
|
||||
#define WCHNET_NUM_UDP 1 /* SSC 模式需要 UDP */
|
||||
#define WCHNET_NUM_TCP 2 /* JSON(1) + SSC client(1) max */
|
||||
#define WCHNET_NUM_IPRAW 0 /* Number of IPRAW connections */
|
||||
|
||||
#if NET_SSC_ENABLE
|
||||
#define WCHNET_NUM_UDP 1 /* SSC mode: 1 UDP */
|
||||
#else
|
||||
#define WCHNET_NUM_UDP 0 /* IoT mode: 0 UDP */
|
||||
#endif
|
||||
|
||||
#if NET_JSON_ENABLE && NET_SSC_ENABLE
|
||||
#define WCHNET_NUM_TCP 2 /* SSC+JSON: JSON(1) + SSC client(1) */
|
||||
#elif NET_JSON_ENABLE
|
||||
#define WCHNET_NUM_TCP 1 /* JSON only: listen+data(1) */
|
||||
#elif NET_SSC_ENABLE
|
||||
#define WCHNET_NUM_TCP 1 /* SSC only: TCP client(1) */
|
||||
#elif NET_IOT_ENABLE
|
||||
#define WCHNET_NUM_TCP 1 /* IoT MQTT client(1) */
|
||||
#else
|
||||
#define WCHNET_NUM_TCP 0
|
||||
#endif
|
||||
|
||||
#define WCHNET_NUM_TCP_LISTEN 1 /* Number of TCP listening (required internally) */
|
||||
|
||||
/* The number of sockets, the maximum is 31 */
|
||||
|
||||
@@ -249,10 +249,8 @@ void write_net_config(Local_Net_Cfg *local, NET_CENTER_INFO *center, IOT_NET_INF
|
||||
extern uint8_t g_flag_timestamp;
|
||||
extern uint8_t RemoteIP[4];
|
||||
|
||||
#if NET_SSC_ENABLE
|
||||
extern uint8_t SocketId_TCP;
|
||||
extern uint8_t SocketId_UDP;
|
||||
#endif
|
||||
|
||||
|
||||
void manage_udp_message(uint8_t socket, uint8_t *ip, uint16_t port, uint8_t *buf, uint32_t len);
|
||||
@@ -283,10 +281,8 @@ void GetMacAddr(unsigned char *pMAC);
|
||||
void mStopIfError(u8 iError);
|
||||
|
||||
void net_srv_init(void);
|
||||
#if NET_SSC_ENABLE
|
||||
void WCHNET_CreateTcpMqttSocket(void);
|
||||
void WCHNET_CreateTcpSocket(void);
|
||||
#endif
|
||||
void WCHNET_HandleSockInt(uint8_t socketid, uint8_t intstat);
|
||||
int get_ipstr_to_array(char *src, uint8_t *dst);
|
||||
void WCHNET_HandleGlobalInt(void);
|
||||
|
||||
Reference in New Issue
Block a user