85 lines
2.3 KiB
C
85 lines
2.3 KiB
C
#ifndef __DX_WF_24_H__
|
||
#define __DX_WF_24_H__
|
||
|
||
#include "usart.h"
|
||
#include <stdint.h>
|
||
|
||
/* 默认超时时间(毫秒) */
|
||
#define WIFI_DEFAULT_TIMEOUT 1000
|
||
|
||
/* WiFi 接收缓冲区大小 */
|
||
#define WIFI_RX_BUF_SIZE 1024
|
||
|
||
/* WiFi 数据结构体 */
|
||
typedef struct {
|
||
uint8_t rx_buffer[WIFI_RX_BUF_SIZE]; // 接收缓冲区
|
||
uint16_t rx_len; // 本次接收长度
|
||
uint8_t rx_flag; // 接收完成标志
|
||
} WIFI_HandleTypeDef;
|
||
|
||
extern WIFI_HandleTypeDef wifi;
|
||
|
||
/* MQTT消息结构体 */
|
||
typedef struct {
|
||
char topic[128];
|
||
char payload[256];
|
||
uint16_t payload_len;
|
||
} MQTT_Message_t;
|
||
|
||
|
||
// SNTP 时间结构体
|
||
typedef struct {
|
||
uint16_t year;
|
||
uint8_t month;
|
||
uint8_t day;
|
||
uint8_t hour;
|
||
uint8_t minute;
|
||
uint8_t second;
|
||
uint8_t valid; // 1表示有效,0表示无效
|
||
} SNTP_Time_t;
|
||
|
||
extern SNTP_Time_t sntp_time;
|
||
|
||
|
||
/* 解析函数 */
|
||
uint8_t WIFI_Parse_MQTT_Message(char *input, MQTT_Message_t *msg);
|
||
|
||
|
||
/* MQTT运行状态 */
|
||
typedef enum {
|
||
MQTT_STATE_IDLE = 0,
|
||
MQTT_STATE_WIFI_CONNECTED,
|
||
MQTT_STATE_SERVER_CONNECTED,
|
||
MQTT_STATE_SUBSCRIBED
|
||
} MQTT_State_t;
|
||
|
||
/* 函数声明 */
|
||
HAL_StatusTypeDef WIFI_SEND_DMA(const char *data);
|
||
HAL_StatusTypeDef WIFI_RECV_DMA_Init(void);
|
||
void WIFI_UART_IDLE_Callback(UART_HandleTypeDef *huart);
|
||
// int WIFI_Get_Received_Data(uint8_t *buffer, uint16_t len);
|
||
|
||
/* 同步应答检测函数 */
|
||
uint8_t WIFI_CheckAck(const char *cmd, const char *expect, uint32_t timeout_ms);
|
||
|
||
/* MQTT连接函数 */
|
||
uint8_t WIFI_Connect_MQTT(const char *wifi_ssid, const char *wifi_pass,
|
||
const char *mqtt_host, uint16_t mqtt_port,
|
||
const char *client_id, const char *user,
|
||
const char *pass);
|
||
|
||
uint8_t WIFI_MQTT_Publish_RAW(const char *topic, const uint8_t *payload,
|
||
uint16_t length, uint8_t qos, uint8_t retain);
|
||
|
||
void wifi_task_mqtt(void *argument);
|
||
uint8_t WIFI_MQTT_Publish_Sensor(const char *json);
|
||
uint8_t WIFI_MQTT_Publish_Status(const char *json);
|
||
|
||
/* ================= SNTP函数声明 ================= */
|
||
uint8_t WIFI_Enable_SNTP(void);
|
||
uint8_t WIFI_Get_SNTP_Time(void);
|
||
SNTP_Time_t WIFI_Get_Current_Time(void);
|
||
uint8_t WIFI_Is_Time_Valid(void);
|
||
|
||
#endif /* __DX_WF_24_H__ */
|