shuichan_old/V1.2/STM32F103_App1/HardWare/NETWORK/network.h

42 lines
1.7 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef NETWORK_H
#define NETWORK_H
#include "main.h"
#include <stdint.h>
/*===== 网络后端(通道)=====*/
/* 4G 与 WiFi 互斥运行:任一时刻只有一个后端激活,
* 两者共享 Rx_Buf/U2_CopyBuff见 stm32f1xx_it.c 的 IDLE 守卫) */
typedef enum {
NET_BACKEND_4G = 0, /* Air780E, USART3, 模组内置MQTT(AT+MPUB) */
NET_BACKEND_WIFI /* ESP-01S, UART4, TCP透传+软件MQTT */
} net_backend_t;
/*===== 网络状态 =====*/
extern volatile uint8_t g_net_mqtt_ready;
extern volatile uint8_t g_net_first_publish_ok;
extern volatile uint8_t g_no_sim_detected;
extern volatile uint8_t g_no_signal_detected; /* 4G 无信号标志air780e.c 在 AT+CSQ 检测失败时设置 */
/* 网络发送互斥:置位期间 NET_publish_* 直接丢弃OTA 下载等 AT 交互期间使用,
* 防止业务发布与进行中的 AT 指令在 USART3 上交织导致应答误判) */
extern volatile uint8_t g_net_tx_busy;
/*===== API =====*/
void NET_init(void);
void NET_process(void);
net_backend_t NET_GetActiveBackend(void);
void NET_publish_status(int sw1, int feeding, int sw2, int sw3, int sw4,
float weight_kg, float once_wt_kg, float zero_kg);
void NET_publish_response(const char *cmd_id, int ok, const char *msg);
void NET_publish_power(int on);
void NET_mqtt_report(const char *header, const char *ota_id, int val);
void NET_ota_confirm(void);
/* 下行消息统一分发与模组无关id去重 → iot.prop.set继电器控制 → iot.ota升级。
* 4G 后端切出 +MSUB 片段后调用WiFi 后端解出 MQTT PUBLISH payload 后调用。
* msg 可以是整条 +MSUB URC 或纯 JSON内部按子串匹配。 */
void net_dispatch_message(const char *msg);
#endif /* NETWORK_H */