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,82 @@
|
||||
#ifndef LWIP_MODULE_H
|
||||
#define LWIP_MODULE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "main.h"
|
||||
#include <stdint.h>
|
||||
#include <stddef.h> /* size_t */
|
||||
#include "lwip/sockets.h" /* LwIP socket API 和结构体定义 */
|
||||
#include "lwip/inet.h" /* LwIP inet_addr 和 INADDR_NONE 等宏 */
|
||||
|
||||
/* LwIP socket 相关宏定义(部分环境在 lwip/sockets.h 中未定义时在此兜底) */
|
||||
#ifndef F_GETFL
|
||||
#define F_GETFL 3 /* fcntl 获取文件描述符标志 */
|
||||
#endif
|
||||
#ifndef F_SETFL
|
||||
#define F_SETFL 4 /* fcntl 设置文件描述符标志 */
|
||||
#endif
|
||||
#ifndef O_NONBLOCK
|
||||
#define O_NONBLOCK 0x0004 /* 非阻塞模式,recv 无数据时立即返回不阻塞任务 */
|
||||
#endif
|
||||
#ifndef EWOULDBLOCK
|
||||
#define EWOULDBLOCK 11 /* 非阻塞 recv 无数据时的 errno */
|
||||
#endif
|
||||
#ifndef EAGAIN
|
||||
#define EAGAIN 11 /* 同上,与 EWOULDBLOCK 等价 */
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief 将主机名或 IP 字符串解析为 in_addr
|
||||
* @param[in] host 服务器地址,可为 "192.168.1.1" 或 "www.xxx.com"
|
||||
* @param[out] out_addr 解析得到的 IPv4 地址
|
||||
* @return 0 成功,-1 失败(非 IP 且 DNS 解析失败)
|
||||
*/
|
||||
int lwip_resolve_host(const char *host, struct in_addr *out_addr);
|
||||
|
||||
/**
|
||||
* @brief 创建 TCP socket 并连接到指定地址
|
||||
* @param[in] host 服务器地址(IP 或域名)
|
||||
* @param[in] port 服务器端口
|
||||
* @return >=0 socket 描述符,<0 失败
|
||||
*/
|
||||
int lwip_tcp_connect(const char *host, uint16_t port);
|
||||
|
||||
/**
|
||||
* @brief 关闭 socket
|
||||
* @param[in] sock socket 描述符
|
||||
*/
|
||||
void lwip_tcp_close(int sock);
|
||||
|
||||
/**
|
||||
* @brief 发送数据
|
||||
* @param[in] sock socket 描述符
|
||||
* @param[in] buf 发送缓冲区
|
||||
* @param[in] len 发送长度
|
||||
* @return >0 实际发送字节数,<=0 失败或对端关闭
|
||||
*/
|
||||
int lwip_tcp_send(int sock, const void *buf, size_t len);
|
||||
|
||||
/**
|
||||
* @brief 接收数据(非阻塞)
|
||||
* @param[in] sock socket 描述符
|
||||
* @param[out] buf 接收缓冲区
|
||||
* @param[in] len 缓冲区长度
|
||||
* @return >0 实际接收字节数,0 对端关闭,<0 错误(errno 需检查)
|
||||
*/
|
||||
int lwip_tcp_recv(int sock, void *buf, size_t len);
|
||||
|
||||
/**
|
||||
* @brief 设置 socket 为非阻塞模式
|
||||
* @param[in] sock socket 描述符
|
||||
* @return 0 成功,-1 失败
|
||||
*/
|
||||
int lwip_set_nonblock(int sock);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LWIP_MODULE_H */
|
||||
Reference in New Issue
Block a user