sop板
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.

174 lines
5.0 KiB

4 years ago
/*****************************************************************************
update by cc @201501101001
.
uartcom/uartlib.c:
(线),
(lcd等固屏输出的)使
void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...)
-----------------------------------------------------------------------------------------
uartcom/uartcom0
uart相关的通讯协议 com + n
uart口来对应
typedef struct _ts_lcm_pro_; ? LCM的协议------------
L3_UARTcom0_exp_protocol
-----------------------------------------------------------------------------------------
uartcom/uprotocol: uartcom + n服务的
struct _s_protocol_ ()------struct _s_protocol_
void L1_uart_2buf(struct _s_protocol_ *p)
--------------------------------------------------------------------------------------------
msp/uartx.c cpu相关
L0_UART0_Init
UART0_IRQHandler
L0_Usend_uc----------s_at0
-----------------------------------------------------------------------------------------
********************************************************************************/
#include "debug.h"
4 years ago
#include "../clib/clib.h"
//NUM: 0 1 2 3 4
// Fx R1 R2 R3 ocr
// F+从机 R1 R2 R3 校验
//相关功能移动到tpc_fx.c
/// 实践中发现 如果收到多个以0d0a结束的短协议时,如果
/// 协议之间间隔时间太短,ok处理不及时 会出现丢失协议的
/// 的情况,所以 对于短暂的多个协议 应该有一定容量的缓冲
/// 保留 ,同时 处理完协议后,应该清除接收缓冲,否则缓冲
/// 会在自身满了后自动清除
//_s_HRTU_P_rf_
/// _s_HRTU_Pfx_
/// fx 11 22 33 oc -- oc = 11+ 22+33
//buf 0 1 2 3 [4]
//fd 01 02 03 06 fd为头 010203为数据 06为数据校验和(01+02+03)
//对于连续的多条协议,如果前一条处理不及时,可能会被后一条覆盖
1 year ago
void L1_s2b_debug (Ts_uart_recv_buf *p) //reentrant
{
p->ok = 1;
return;
}
//NFC协议:60 20 00 07 10 02 04 00 99 83 33 4E 36
//起始帧:60
//设备ID:20
//数据长度:00 07
//命令:10
//数据:02 04 00 99 83 33 4E
//校验:36 从起始帧到数据字段 [60 20 00 07 10 02 04 00 99 83 33 4E] 的所有字节的依次异或值
void L1_s2b_nfc (Ts_uart_recv_buf *p) //reentrant
4 years ago
{
if (0 == p->head)
{
if (p->head_0 == (p->reg & 0xFF))
4 years ago
{
p->head = 1;
p->buf[0] = p->reg;
p->index = 0;
p->num = p->maxnum;
p->ocr = p->reg;
4 years ago
}
}
else
{
p->buf[++p->index] = p->reg;
if(p->index == 3)
{
//5个字节协议头 + 1校验 + 数据(长度由2、3字节计算)
p->num = 5 + 1 + ((p->buf[2] << 8) | (p->buf[3]));
if(p->num > p->maxnum){
//error
p->head = 0;
p->ok = 0;
return;
}
}
if(p->index < p->num - 1)
{
//计算OCR
p->ocr ^= p->reg;
}
else
4 years ago
{
if(p->ocr == p->buf[p->num-1])
4 years ago
{
if (p->ok != 1)
{
//命令结束,必须有个地方清0,否则无法再次接受报文
p->ok = 1;
}
4 years ago
}
p->head = 0;
4 years ago
}
}
}
//RFID协议:BB 02 22 00 11 D5 30 00 E2 00 10 71 00 00 52 9B 09 40 B4 02 EB 98 0C 7E
//帧头:BB
//Type:00命令帧 /01响应帧 /02通知帧
//Command: 07指令桢 /22单次读写 /27多次轮询 /28停止轮询 /0C选择 / B6设置功率
//数据长度:00 07
//数据:D5 30 00 E2 00 10 71 00 00 52 9B 09 40 B4 02 EB 98
//校验:0C 从Type到数据字段 [02 22 00 11 D5 30 00 E2 00 10 71 00 00 52 9B 09 40 B4 02 EB 98] 的所有字节的累加和
//帧尾:7E
void L1_s2b_rfid (Ts_uart_recv_buf *p) //reentrant
{
if (0 == p->head)
{
if (p->head_0 == (p->reg & 0xFF))
{
p->head = 1;
p->buf[0] = p->reg;
p->index = 0;
p->num = p->maxnum;
p->ocr = p->reg;
}
}
else
{
p->buf[++p->index] = p->reg;
if(p->index == 3)
{
//5个字节协议头 + 1校验 + 数据(长度由2、3字节计算)
p->num = 5 + 1 + ((p->buf[2] << 8) | (p->buf[3]));
if(p->num > p->maxnum){
//error
p->head = 0;
p->ok = 0;
return;
}
}
if(p->index < p->num - 1)
{
//计算OCR
p->ocr ^= p->reg;
}
else
{
if(p->ocr == p->buf[p->num-1])
{
if (p->ok != 1)
{
//命令结束,必须有个地方清0,否则无法再次接受报文
p->ok = 1;
}
}
p->head = 0;
}
}
}
4 years ago
/******************************************************************************
** End Of File
******************************************************************************/