mirror of
https://gitee.com/jiuyilian/embedded-framework.git
synced 2025-01-06 10:16:51 -05:00
Merge branch 'master' of https://gitee.com/chenhaijian1107/embedded-framework
This commit is contained in:
commit
94af1eaaea
|
@ -9,6 +9,7 @@
|
|||
* I/O多路复用
|
||||
* 套接字编程
|
||||
* TCP协议
|
||||
* 事件循环
|
||||
|
||||
# 各文件的作用
|
||||
* **TcpModule.h**:定义了TCP模块的公共接口和数据结构,包括服务器和客户端参数结构体、回调函数类型等。
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
#include "StatusCode.h"
|
||||
#include "TcpModule.h"
|
||||
#include <memory>
|
||||
/**
|
||||
* @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;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
|
16
utils/UartDevice/readme.md
Normal file
16
utils/UartDevice/readme.md
Normal file
|
@ -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设备。
|
Loading…
Reference in New Issue
Block a user