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.
47 lines
1.3 KiB
47 lines
1.3 KiB
#include "tpc_0d0a.h"
|
|
#include "c_lib.h"
|
|
|
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
//L1_uart_2strbuf(&s_uart0_rec);s_uart0_rec.ok = 2
|
|
/// 接收以od oa为结束的标准的assci码的协议 类似 send xx (回车换行)测试时注意以回车换行
|
|
/// 为结束标志,也就是发送的数据后面 必须有回车换行 :0x0d 0x0a
|
|
|
|
|
|
//对于连续的多条协议,比如:abcdefg\r\n12345\r\n,如果前一条处理不及时,可能会被后一条覆盖
|
|
void L1_s2b_0d0a(Ts_uart_rev_ *p) //reentrant
|
|
{
|
|
if(p->head == 0)
|
|
{
|
|
p->head = 1;
|
|
p->num = 0;
|
|
}
|
|
|
|
if(p->num >= D_tp_handle_x_len)
|
|
{
|
|
p->num = 0;
|
|
}
|
|
p->cashe[1] = p->cashe[0];
|
|
p->cashe[0] = p->reg;//
|
|
|
|
p->buf[++p->num] = p->cashe[0];
|
|
//p->buf[++p->num] = p->cashe[0];
|
|
|
|
if ((p->num > 2) && (p->cashe[0] == 0x0a) && (p->cashe[1] == 0x0d))// 0d0a
|
|
{
|
|
if(1 != p->ok)
|
|
{
|
|
p->buf[0] = p->num - 2; //去掉0d0a
|
|
if(p->sp2 != NULL) //备份缓冲区不为null
|
|
{
|
|
//byte_copy_uc(p->buf + 1,p->__buf,p->num-2); //经过调试,此处不要调用外部函数,入栈出栈会增加出错风险
|
|
for(p->i=0;p->i<p->buf[0]+1;p->i++)
|
|
{
|
|
p->sp2[p->i] = p->buf[p->i];
|
|
}
|
|
}
|
|
p->ok = 1;//收到 命令结束,必须有个地方清0,否则无法再次接受报文
|
|
}
|
|
p->head = 0;
|
|
}
|
|
}
|
|
|
|
|