Initial commit: CCU621_M firmware project with BLE debug link support.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file tcp_server.h
|
||||
* @brief TCP调试服务器头文件
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __TCP_SERVER_H
|
||||
#define __TCP_SERVER_H
|
||||
|
||||
#include "debug_link.h"
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/tcp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* 消息类型枚举 */
|
||||
typedef enum {
|
||||
TCP_MSG_HEARTBEAT = 1, /* 心跳消息 */
|
||||
TCP_MSG_SYSTEM_INFO = 2, /* 系统信息 */
|
||||
TCP_MSG_GUN_DATA = 3, /* 充电枪数据 */
|
||||
/* 可以在此添加其他消息类型 */
|
||||
} tcp_msg_type_t;
|
||||
|
||||
/* 命令类型枚举(用于接收解析) */
|
||||
typedef enum {
|
||||
TCP_CMD_HEARTBEAT = 1, /* 心跳 */
|
||||
TCP_CMD_SYSTEM_INFO = 2, /* 系统信息 */
|
||||
TCP_CMD_GUN_DATA = 3, /* 充电枪数据(服务器发送) */
|
||||
TCP_CMD_CHARGE_CONTROL = 4, /* 充电启停控制(客户端发送) */
|
||||
} tcp_cmd_type_t;
|
||||
|
||||
/* 服务器状态结构体 */
|
||||
typedef struct {
|
||||
struct tcp_pcb *server_pcb; /* 服务器PCB */
|
||||
struct tcp_pcb *client_pcb; /* 客户端PCB(仅支持一个) */
|
||||
uint8_t is_client_connected; /* 客户端连接状态 */
|
||||
|
||||
/* 协议相关状态 */
|
||||
uint32_t heartbeat_sequence; /* 心跳序列号 */
|
||||
uint8_t system_info_sent; /* 系统信息是否已发送 */
|
||||
|
||||
/* 定时计数变量 */
|
||||
uint32_t tick_counter; /* 全局tick计数器,每秒递增 */
|
||||
|
||||
/* 消息发送间隔(秒) */
|
||||
uint32_t heartbeat_last_tick; /* 上次心跳发送时的tick */
|
||||
uint32_t system_info_last_tick; /* 上次系统信息发送时的tick */
|
||||
uint32_t gun_data_last_tick; /* 上次充电枪数据发送时的tick */
|
||||
uint32_t last_heartbeat_received_tick; /* 上次收到心跳时的tick */
|
||||
} tcp_server_state_t;
|
||||
|
||||
/* 函数声明 */
|
||||
err_t tcp_server_start(void);
|
||||
void tcp_server_process(void);
|
||||
void tcp_server_stop(void);
|
||||
void tcp_server_task(void *arg);
|
||||
|
||||
/* 协议相关函数 */
|
||||
void tcp_server_send_message(tcp_msg_type_t msg_type);
|
||||
void tcp_server_process_received_data(const char *data, uint16_t len);
|
||||
|
||||
/* 通用发送函数 */
|
||||
err_t tcp_server_send_json(const char *json_data, uint16_t len);
|
||||
|
||||
int tcp_server_rx_upgrade_begin(void);
|
||||
int tcp_server_rx_upgrade_end(void);
|
||||
void tcp_server_rx_clear_pending(void);
|
||||
void tcp_server_link_rx_drain(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __TCP_SERVER_H */
|
||||
Reference in New Issue
Block a user