You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
4.1 KiB
131 lines
4.1 KiB
|
3 days ago
|
/******************************************************************************
|
||
|
|
|
||
|
|
版权所有 (C), 2018-2099, Radkil
|
||
|
|
|
||
|
|
******************************************************************************
|
||
|
|
文 件 名 : com.h
|
||
|
|
版 本 号 : 初稿
|
||
|
|
作 者 : Radkil
|
||
|
|
生成日期 : 2026年3月27日星期五
|
||
|
|
最近修改 :
|
||
|
|
功能描述 : com.c 的头文件
|
||
|
|
|
||
|
|
修改历史 :
|
||
|
|
1.日 期 : 2026年3月27日星期五
|
||
|
|
作 者 : Radkil
|
||
|
|
修改内容 : 创建文件
|
||
|
|
|
||
|
|
******************************************************************************/
|
||
|
|
|
||
|
|
/*----------------------------------------------*
|
||
|
|
* 外部变量说明 *
|
||
|
|
*----------------------------------------------*/
|
||
|
|
|
||
|
|
/*----------------------------------------------*
|
||
|
|
* 外部函数原型说明 *
|
||
|
|
*----------------------------------------------*/
|
||
|
|
|
||
|
|
/*----------------------------------------------*
|
||
|
|
* 内部函数原型说明 *
|
||
|
|
*----------------------------------------------*/
|
||
|
|
|
||
|
|
/*----------------------------------------------*
|
||
|
|
* 全局变量 *
|
||
|
|
*----------------------------------------------*/
|
||
|
|
|
||
|
|
/*----------------------------------------------*
|
||
|
|
* 模块级变量 *
|
||
|
|
*----------------------------------------------*/
|
||
|
|
|
||
|
|
/*----------------------------------------------*
|
||
|
|
* 常量定义 *
|
||
|
|
*----------------------------------------------*/
|
||
|
|
|
||
|
|
/*----------------------------------------------*
|
||
|
|
* 宏定义 *
|
||
|
|
*----------------------------------------------*/
|
||
|
|
|
||
|
|
#ifndef __COM_H__
|
||
|
|
#define __COM_H__
|
||
|
|
|
||
|
|
|
||
|
|
#ifdef __cplusplus
|
||
|
|
#if __cplusplus
|
||
|
|
extern "C"{
|
||
|
|
#endif
|
||
|
|
#endif /* __cplusplus */
|
||
|
|
|
||
|
|
|
||
|
|
/*==============================================*
|
||
|
|
* include header files *
|
||
|
|
*----------------------------------------------*/
|
||
|
|
#include <stdint.h>
|
||
|
|
#include "common.h"
|
||
|
|
#include "rd_thread.h"
|
||
|
|
#include "ringbuffer.h"
|
||
|
|
#include "utarray.h"
|
||
|
|
|
||
|
|
/*==============================================*
|
||
|
|
* constants or macros define *
|
||
|
|
*----------------------------------------------*/
|
||
|
|
#define RECV_TIMEOUT 100 //接收超时时间(100ms)
|
||
|
|
|
||
|
|
typedef int (*cbk_ComCheck)(char *_pBuffer, uint32_t _iSize);
|
||
|
|
// 返回值 > 0 表示校验成功且返回包的实际长度
|
||
|
|
// 返回值 = 0 表示数据不完整,需要继续等待
|
||
|
|
// 返回值 < 0 表示数据错误
|
||
|
|
typedef void (*cbk_ComDecode)(const char *_pBuffer, uint32_t _iSize);
|
||
|
|
typedef int (*cbk_ComSend)(char *_pBuffer, uint32_t _iSize);
|
||
|
|
|
||
|
|
typedef struct
|
||
|
|
{
|
||
|
|
Rd_sem_t m_sem_Send;
|
||
|
|
Rd_sem_t m_sem_Recv;
|
||
|
|
rd_ringbuf_t *m_ptSend;
|
||
|
|
rd_ringbuf_t *m_ptRecv;
|
||
|
|
} TComBuffer;
|
||
|
|
|
||
|
|
typedef struct
|
||
|
|
{
|
||
|
|
uint32_t m_uiLastRecvTime; // 超时丢弃时间
|
||
|
|
cbk_ComCheck m_pfCheck; // 协议特征检查
|
||
|
|
cbk_ComDecode m_pfDecode; // 真正的协议处理
|
||
|
|
}TMutiDev;
|
||
|
|
|
||
|
|
typedef struct
|
||
|
|
{
|
||
|
|
TComBuffer m_stComBuf;
|
||
|
|
int m_iBufferSize;
|
||
|
|
int m_iDevIndex; // 表示当前正在接收的设备索引,-1表示当前无设备在处理
|
||
|
|
UT_array *m_pMutiDevArray;
|
||
|
|
cbk_ComSend m_pfSend;
|
||
|
|
void *m_pUserData;
|
||
|
|
}TComCtrl;
|
||
|
|
|
||
|
|
/*==============================================*
|
||
|
|
* project-wide global variables *
|
||
|
|
*----------------------------------------------*/
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
/*==============================================*
|
||
|
|
* routines' or functions' implementations *
|
||
|
|
*----------------------------------------------*/
|
||
|
|
TComCtrl *rd_ComCreate(cbk_ComCheck _pfCheck, cbk_ComDecode _pfDecode, cbk_ComSend _pfSend, int _iSize, void *_pUserData);
|
||
|
|
void rd_ComAddDev(TComCtrl *_ptComCtrl, cbk_ComCheck _pfCheck, cbk_ComDecode _pfDecode);
|
||
|
|
int rd_ComDelete(TComCtrl *_ptComCtrl);
|
||
|
|
int rd_ComSend(TComCtrl *_ptComCtrl, char *_pBuffer, uint32_t _iSize);
|
||
|
|
void rd_ComSendProc(TComCtrl *_ptComCtrl);
|
||
|
|
void rd_ComRecvProc(TComCtrl *_ptComCtrl, const char *_pBuffer, uint32_t _iSize);
|
||
|
|
int rd_ComWrite(TComCtrl *_ptComCtrl, char *_pBuffer, uint32_t _iSize);
|
||
|
|
int rd_ComRead(TComCtrl *_ptComCtrl, char *_pBuffer, uint32_t _iSize);
|
||
|
|
|
||
|
|
#ifdef __cplusplus
|
||
|
|
#if __cplusplus
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
#endif /* __cplusplus */
|
||
|
|
|
||
|
|
|
||
|
|
#endif /* __COM_H__ */
|