| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- /*
- * queue.h
- *
- * Created on: 2025年8月20日
- * Author: 龙三郎
- */
- #ifndef USER_INCLUDES_TR_QUEUE_H_
- #define USER_INCLUDES_TR_QUEUE_H_
- #include "stdbool.h"
- // 队列相关
- #define QUEUE_MAX_SIZE 4096 // 定义队列的最大容量
- #define QUEUE_NUM 4 // 队列的数量
- #define QUEUE_INDEX_USB 0 // usb用的队列索引
- #define QUEUE_INDEX_ETHERNET 1 // usb用的队列索引
- #define QUEUE_INDEX_HEAR 2 // usb用的队列索引
- #define QUEUE_INDEX_UART 3 // usb用的队列索引
- // 缓存相关
- #define BUFFER_SIZE_1K 1024
- #define BUFFER_SIZE_2K 2048
- // 模块地址
- #define DSP_ADDRESS 1 // DSP主控模块的地址为1
- #define F4_ADDRESS 2 // F4模块的地址为2
- #define GUI_ADDRESS 3 // GUI模块的地址为3
- #define UART_ADDRESS 4 // 串口模块的地址为4
- #define THIS_ADDRESS DSP_ADDRESS // 本模块为DSP主控模块
- // 数据类型
- #define TYPE_DEFAULT 0 // 自定义的
- #define TYPE_WAVEFORM 1 // 波形数据
- #define TYPE_COMMAND 2 // 指令
- // 操作
- //#define isFull(q) ((q->rear + 1) % QUEUE_MAX_SIZE == q->front)
- typedef struct {
- unsigned char items[QUEUE_MAX_SIZE]; // 存储队列元素的数组
- int front; // 队首指针
- int rear; // 队尾指针
- } Queue;
- extern Queue queueList[QUEUE_NUM];
- void initializeQueue(Queue *q); // 初始化队列
- bool isFull(Queue *q); // 判断队列是否已满
- bool isEmpty(Queue *q); // 判断队列是否为空
- int currentItems(Queue *q); // 队列现有元素个数
- int remainSpace(Queue *q); // 队列剩余空间
- bool enqueue(Queue *q, unsigned char element); // 入队列,单个元素
- bool enqueueBatch(Queue *q, unsigned char *elements, unsigned int elSize); // 批量入队列
- bool dequeue(Queue *q, unsigned char *element); // 出队列,单个元素
- bool dequeueBatch(Queue *q, unsigned short len, unsigned char *element); // 批量出队列
- // 协议解析相关
- bool getVerFromProtocol(unsigned char *p, unsigned short pl, unsigned char *ver); // 获取协议版本
- bool getDaFromProtocol(unsigned char *p, unsigned short pl, unsigned char *da); // 获取目的地址
- bool getSaFromProtocol(unsigned char *p, unsigned short pl, unsigned char *sa); // 获取来源地址
- bool getTypeFromProtocol(unsigned char *p, unsigned short pl, unsigned char *type); // 获取数据类型
- bool getPayloadFromProtocol(unsigned char *p, unsigned short pl, unsigned char *s, unsigned short *sl); // 获取源数据
- // 数据转发协议相关
- bool dequeueBatchWithProtocol(Queue *q, unsigned char *d, unsigned short *dl); // 从队列中取出一个数据包。
- // 转发业务相关
- void dataforwardInit(void); // 初始化
- void dataforwardMain(void); // 主流程
- bool enqueueFromUsb(unsigned char *s, unsigned short sl); // 将从usb发来的协议数据入队列
- bool enqueueFromEthernet(unsigned char *s, unsigned short sl); // 将从以太网发来的协议数据入队列
- bool enqueueFromUart(unsigned char c); // 将从串口发来的数据入队列,一次一字符
- bool enqueueFromUartBatch(unsigned char *s, unsigned short sl); // 将从串口发来的数据入队列,批量
- bool enqueueFromHere(unsigned char *s, unsigned short sl, unsigned char da, unsigned char type); // 从本模块发出的数据入队列,源数据。不带协议格式
- extern void dataForwardedHandle(unsigned char *s, unsigned short sl, unsigned char da); // 数据转发业务处理,需要进行转发的数据在这个里面处理
- extern void dataNotForwardedHandle(unsigned char *s, unsigned short sl, unsigned char sa, unsigned char type); // 不需要转发的数据。即其他模块发送给本模块的数据。
- #endif /* USER_INCLUDES_TR_QUEUE_H_ */
|