完成了基础的中文和英文字符显示
This commit is contained in:
70
README.md
70
README.md
@@ -59,76 +59,6 @@ cmake --build .
|
||||
pc_hmi # Windows / Linux 下均可
|
||||
```
|
||||
|
||||
## 运行与按键映射
|
||||
|
||||
```bash
|
||||
./pc_hmi
|
||||
```
|
||||
|
||||
在控制台中使用以下按键进行菜单操作:
|
||||
|
||||
- `W` / `w` – 上(对应嵌入式的 `CN_KEY_U`)
|
||||
- `S` / `s` – 下(`CN_KEY_D`)
|
||||
- `A` / `a` – 左(`CN_KEY_L`)
|
||||
- `D` / `d` – 右(`CN_KEY_R`)
|
||||
- `Enter` – 确认 / 进入子菜单(`CN_KEY_ENT`)
|
||||
- `Esc` – 返回上一级(`CN_KEY_ESC`)
|
||||
|
||||
界面中会用 `[*名称*]` 标出当前选中的菜单项,并在底部显示对应的提示信息。
|
||||
|
||||
> 注意:当前只是一个 **最小化演示环境**,菜单树结构与嵌入式工程中的 `g_tMenuModelTab` 不完全一致,但交互方式相仿,可作为移植和调试时的参考。
|
||||
|
||||
## TCP 通信
|
||||
|
||||
项目已集成 **跨平台 TCP 模块**(`include/tcp.h` + `src/tcp.c`),可用于与设备或上位机进行 TCP 通信。
|
||||
|
||||
- **Windows**:使用 Winsock2,已自动链接 `ws2_32`。
|
||||
- **Linux**:使用 BSD socket,无需额外库。
|
||||
|
||||
### 使用前初始化
|
||||
|
||||
程序入口已调用 `Tcp_Init()`,退出前会调用 `Tcp_Cleanup()`。若在其它线程或模块中使用 TCP,无需重复初始化。
|
||||
|
||||
### TCP 客户端示例
|
||||
|
||||
```c
|
||||
#include "../include/tcp.h"
|
||||
|
||||
/* 连接服务器 */
|
||||
int sock = TcpClient_Connect("192.168.1.100", 502);
|
||||
if (sock == TCP_INVALID_SOCKET) {
|
||||
/* 连接失败 */
|
||||
return;
|
||||
}
|
||||
|
||||
/* 发送数据 */
|
||||
const char *msg = "hello";
|
||||
int sent = TcpClient_Send(sock, msg, strlen(msg));
|
||||
|
||||
/* 接收数据 */
|
||||
char buf[256];
|
||||
int n = TcpClient_Recv(sock, buf, sizeof(buf) - 1);
|
||||
if (n > 0) {
|
||||
buf[n] = '\0';
|
||||
printf("recv: %s\n", buf);
|
||||
}
|
||||
|
||||
/* 关闭连接 */
|
||||
TcpClient_Close(sock);
|
||||
```
|
||||
|
||||
### TCP 服务端示例
|
||||
|
||||
```c
|
||||
int server = TcpServer_Listen(8080);
|
||||
if (server == TCP_INVALID_SOCKET) return;
|
||||
|
||||
int client = TcpServer_Accept(server); /* 阻塞等待客户端 */
|
||||
if (client != TCP_INVALID_SOCKET) {
|
||||
TcpClient_Send(client, "welcome", 7);
|
||||
TcpClient_Close(client);
|
||||
}
|
||||
TcpServer_Close(server);
|
||||
```
|
||||
|
||||
接口说明见 `include/tcp.h`。
|
||||
|
||||
Reference in New Issue
Block a user