增加协议 发送队列 50ms发送数据

“
”
This commit is contained in:
Hjh
2025-01-15 16:02:53 +08:00
commit e48aa3d84b
271 changed files with 93708 additions and 0 deletions

96
queue/user_queue.c Normal file
View File

@@ -0,0 +1,96 @@
#include "user_queue.h"
#include<string.h>
Queue queue;
DATA_LOAD_T data_load;
//初始化队列
void InitQueue(pQueue queue)
{
queue->qFront = 0;
queue->qRear = 0;
}
//队列是否为空
bool IsEmptyQueue(pQueue queue)
{
if (queue->qFront == queue->qRear)//队首等于队尾
return true;
else
return false;
}
//队列是否为满
bool IsFullQueue(pQueue queue)
{
//队尾下个数据为队首
if (((queue->qRear + 1) % QUEUE_ZISE) == queue->qFront)
return true;
else
return false;
}
//入队
uint8_t EnterQueue(pQueue queue, uint8_t *value,uint16_t len)
{
if (IsFullQueue(queue))
{
return 0;
}
//从队尾入队
memcpy(&queue->BasicArr[queue->qRear],value,len);
queue->qRear = (queue->qRear + len) % QUEUE_ZISE;//队尾移向下个位置
return 1;
}
//出队
uint8_t OutQueue(pQueue queue,uint8_t *out,uint16_t len)
{
if (IsEmptyQueue(queue))
{
return 0;
}
memcpy(out,&queue->BasicArr[queue->qFront],len);//出队值
queue->qFront = (queue->qFront + len) % QUEUE_ZISE;//指向下一个出队值
return 1;
}
uint8_t Analysis_Queue_data(pQueue queue)
{
uint8_t bcc=0,i,bcc1=0;
if (IsEmptyQueue(queue))//判断队列是否有数据
{
return 0;
}
while(queue->BasicArr[queue->qFront] != 0xAA)//找帧头
{
queue->qFront++;
if(IsEmptyQueue(queue)==true)
return 0;
}
bcc = queue->BasicArr[queue->BasicArr[++queue->qFront]+2] ;//校验位 此时队首到了帧长的位置
for(i=2;i<queue->BasicArr[queue->qFront]+2;i++)
{
bcc1+=queue->BasicArr[i] ;
}
if(bcc != bcc1)//判断校验
{
return 0;
}
if(queue->BasicArr[queue->BasicArr[queue->qFront]+3]!=0x55)//判断帧尾
{
return 0;
}
queue->qFront--;//回到队首
return 1;
}

50
queue/user_queue.h Normal file
View File

@@ -0,0 +1,50 @@
#ifndef _USER_QUEUE_H
#define _USER_QUEUE_H
#include "Include.h"
#include "stdbool.h"
#define QUEUE_ZISE 5000//队列长度
typedef struct Queue
{
int qFront;//队首
int qRear;//队尾
uint8_t BasicArr[QUEUE_ZISE];//队列数据
}Queue, * pQueue;
//Queue 等效于 struct Queue
//pQueue 等效于 struct Queue *
typedef struct data_load
{
uint8_t sendbuf[10];//数据下发
uint8_t recvbuf[100];//数据接收缓冲区
uint16_t rxlen;//上传数据长度
}DATA_LOAD_T;
extern Queue queue;
extern DATA_LOAD_T data_load;
void InitQueue(pQueue queue);
uint8_t EnterQueue(pQueue queue, uint8_t *value,uint16_t len);
uint8_t OutQueue(pQueue queue,uint8_t *out,uint16_t len);
uint8_t Analysis_Queue_data(pQueue queue);
bool IsEmptyQueue(pQueue queue);
#endif