diff --git a/utils/TcpModule/readme.md b/utils/TcpModule/readme.md index 4e693acd..389b72da 100644 --- a/utils/TcpModule/readme.md +++ b/utils/TcpModule/readme.md @@ -9,6 +9,7 @@ * I/O多路复用 * 套接字编程 * TCP协议 +* 事件循环 # 各文件的作用 * **TcpModule.h**:定义了TCP模块的公共接口和数据结构,包括服务器和客户端参数结构体、回调函数类型等。 diff --git a/utils/TcpModule/src/ITcpClient.h b/utils/TcpModule/src/ITcpClient.h index ae4cf3ff..43573c25 100644 --- a/utils/TcpModule/src/ITcpClient.h +++ b/utils/TcpModule/src/ITcpClient.h @@ -28,10 +28,13 @@ public: virtual ssize_t Write(const void *buf, const size_t bufLenght); virtual void Closed(void); }; +/** + * @brief Verify that the header of the client object is legal. + */ typedef struct i_tcp_client_header { const char *mCheckName; -} ITcpClientHeader; +} ITcpClientHeader; typedef struct tcp_client { ITcpClientHeader mHeader; diff --git a/utils/TcpModule/src/ITcpServer.h b/utils/TcpModule/src/ITcpServer.h index 098ad0b0..23ba73f5 100644 --- a/utils/TcpModule/src/ITcpServer.h +++ b/utils/TcpModule/src/ITcpServer.h @@ -17,6 +17,9 @@ #include "StatusCode.h" #include "TcpModule.h" #include +/** + * @brief Handle data interaction and connection state changes on established TCP connections. + */ class ITcpClientAccept { public: @@ -35,6 +38,9 @@ public: virtual void Init(void); virtual void UnInit(void); }; +/** + * @brief Verify that the header of the server object is legal. + */ typedef struct i_tcp_server_header { const char *mCheckName; diff --git a/utils/TcpModule/src/TcpClientImpl.cpp b/utils/TcpModule/src/TcpClientImpl.cpp index b2f27146..0ef5d44b 100644 --- a/utils/TcpModule/src/TcpClientImpl.cpp +++ b/utils/TcpModule/src/TcpClientImpl.cpp @@ -28,7 +28,7 @@ * * @param io Socket handle * @param buf The transmitted data content - * @param len + * @param len Byte length of transmitted data */ static void on_message(hio_t *io, void *buf, int len) { @@ -61,7 +61,6 @@ TcpClientImpl::TcpClientImpl(const TcpClientParam ¶m, const void *object) : } /** * @brief Initialize TCP clients, create event loops, I/O objects, and set callback functions for connection and closure. - * */ void TcpClientImpl::Init(void) { @@ -89,7 +88,6 @@ void TcpClientImpl::Init(void) } /** * @brief De-initialize the TCP client, close the I/O object and wait for the receiving thread to end. - * */ void TcpClientImpl::UnInit(void) { diff --git a/utils/TcpModule/src/TcpClientImpl.h b/utils/TcpModule/src/TcpClientImpl.h index eefe9883..3bb3262f 100644 --- a/utils/TcpModule/src/TcpClientImpl.h +++ b/utils/TcpModule/src/TcpClientImpl.h @@ -36,7 +36,7 @@ public: private: std::mutex mMutex; ///A mutex lock used to synchronize access to shared resources. - hloop_t *mLoop; + hloop_t *mLoop; ///Event loop, listening for io objects hio_t *mIo; ///Socket handle const TcpClientParam mParam; ///Basic information of the client, including port, ip, reading and closing. std::thread mTcpClientThread; diff --git a/utils/TcpModule/src/TcpModule.cpp b/utils/TcpModule/src/TcpModule.cpp index 8cb81dc2..5ebc8a7a 100644 --- a/utils/TcpModule/src/TcpModule.cpp +++ b/utils/TcpModule/src/TcpModule.cpp @@ -25,7 +25,8 @@ * @brief Verify that object is a legitimate (existing) server. * * @param object Save the address of the character pointer variable. - * If the value of the character pointer pointed by *object is "tcp_server", return turn + * Should be substituted into the private member objectThis of the client instance. + * If the value of the character pointer pointed by *object is "tcp_server", return turn * @return true Indicates that the server exists. * @return false Indicates that the server does not exist */ @@ -45,7 +46,7 @@ static bool TcpServerObjectCheck(void *object) * @brief Verify that object is a legitimate (existing) client. * * @param object Save the address of the character pointer variable. - * The correct object is returned by the function NewTcpClient in Itcpclientlmpl.cpp file. + * * @return true Indicates that the client exists. * @return false Indicates that the client does not exist */ diff --git a/utils/TcpModule/src/TcpServerImpl.cpp b/utils/TcpModule/src/TcpServerImpl.cpp index d82bdf1e..6d646670 100644 --- a/utils/TcpModule/src/TcpServerImpl.cpp +++ b/utils/TcpModule/src/TcpServerImpl.cpp @@ -109,7 +109,7 @@ TcpServerImpl::TcpServerImpl(const TcpServerParam param) : mParam(param) void TcpServerImpl::Init(void) { constexpr int NO_FALGS = 0; - mLoop = hloop_new(NO_FALGS); + mLoop = hloop_new(NO_FALGS); ///Initialize event loop if (nullptr == mLoop) { LogError("hloop_new failed\n"); return; diff --git a/utils/UartDevice/readme.md b/utils/UartDevice/readme.md new file mode 100644 index 00000000..2480b329 --- /dev/null +++ b/utils/UartDevice/readme.md @@ -0,0 +1,16 @@ +# UartDevice模块 +该模块是UART设备接口模块,提供了UART 设备操作接口,通过uart通信操作相关的硬件设备。 + +# 涉及的知识 +* uart通信协议 +* 多线程 +* 系统调用函数的使用 +* C++类和对象 +* 函数指针 + + +# 各文件的作用 +* **UartDevice.h**:定义了一个名为uart_info的结构体存储UART设备的配置信息,定义了用于UART通信的函数接口,这些函数通常与UART硬件的底层实现相对应。 +* **UartDevice.cpp**:提供了一个跨平台的UART设备接口模块,使得上层应用可以通过统一的接口来操作不同的UART硬件设备。 +* **UartDeviceImpl.cpp**:提供了UART 设备操作接口,允许用户打开、发送和接收数据到 UART 设备,实现了 UART 设备的配置、数据发送和接收等功能。 +* **UartDeviceImpl.h**:定义了一个用于UART设备操作的类 UartDeviceImpl 和相关的结构体和函数,提供了一种通过接口和智能指针封装具体实现的方式来管理UART设备。 \ No newline at end of file