#include "tpc_0d0a.h" //#include "../bsp/bsp_a9_gprs.h" #include "../clib/clib.h" //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> //L1_uart_2strbuf(&s_uart0_rec);s_uart0_rec.ok = 2 /// 接收以od oa为结束的标准的assci码的协议 类似 send xx (回车换行)测试时注意以回车换行 /// 为结束标志,也就是发送的数据后面 必须有回车换行 :0x0d 0x0a #if 1 void L1_s2b_0d0a(struct _s_PC1_0D0A_ *p)// reentrant { if(p->head == 0) { p->head = 1; p->num = 0; } if(p->num >= D_s_SSTR_0D0A_len)//128 { p->num = 0; } p->cashe[1] = p->cashe[0]; p->cashe[0] = p->reg;// p->__buf[p->num++] = p->reg; if ((p->cashe[0] == 0x0a) && (p->cashe[1] == 0x0d))// 0d0a { if((p->num > 2) && (p->__buf[p->num-3] != ':')) //排除掉 +CIPSTATUS(a9): { if(1 != p->ok) { p->buf[0] = p->num - 2; //去掉0d0a byte_copy_uc(p->buf + 1,p->__buf,p->num-2); p->ok = 1;//收到 命令结束,必须有个地方清0,否则无法再次接受报文 } } p->head = 0; } } #else void L1_s2b_0d0a(struct _s_PC1_0D0A_ *p)// reentrant { if(p->num >= D_s_SSTR_0D0A_len)//128 { p->num = 0; p->setflag = FLAG_NONE; } p->cashe[3] = p->cashe[2]; p->cashe[2] = p->cashe[1]; p->cashe[1] = p->cashe[0]; p->cashe[0] = p->reg;// p->__buf[p->num++] = p->reg; if(!p->setflag) { if((p->cashe[0] == 'K') && (p->cashe[1] == 'O')) //Ok Flag { g_at_send_status.flag = FLAG_OK; p->setflag = FLAG_DISCARD; } else if((p->cashe[0] == 'C') && (p->cashe[1] == 'T') && (p->cashe[2] == '+')) //+TCPCLOSED Flag { g_at_send_status.connected_flag = 0; p->setflag = FLAG_DISCARD; } else if((p->cashe[0] == 'M') && (p->cashe[1] == 'C') && (p->cashe[2] == '+')) //+CME ERROR { g_at_send_status.connected_flag = 0; p->setflag = FLAG_DISCARD; } else if((p->cashe[0] == 'C') && (p->cashe[1] == 'C') && (p->cashe[2] == '+')) //+CCID: { p->setflag = FLAG_CCID; p->num = 3; p->__buf[0] = '+'; p->__buf[1] = 'C'; p->__buf[2] = 'C'; } else if((p->cashe[0] == 'P') && (p->cashe[1] == 'I') && (p->cashe[2] == 'C') && (p->cashe[3] == '+')) //+CIPRCV: { g_at_send_status.heart_recv_wait_time = 0; g_at_send_status.heart_recv_wait_time_wdt = 0; p->setflag = FLAG_CIP; p->num = 4; p->__buf[0] = '+'; p->__buf[1] = 'C'; p->__buf[2] = 'I'; p->__buf[3] = 'P'; } } if ((p->cashe[0] == 0x0a) && (p->cashe[1] == 0x0d))// 0d0a { if((p->num > 2) && (p->setflag > FLAG_DISCARD)) //p->setFlag == 2 or 3 { if(1 != p->ok) { p->buf[0] = p->num + 1; //后续数据的长度 = num(实际数据) + setflag([1]位置数据) p->buf[1] = p->setflag; byte_copy_uc(p->buf + 2,p->__buf,p->num); p->ok = 1;//收到 命令结束,必须有个地方清0,否则无法再次接受报文 } } p->num = 0; p->setflag = FLAG_NONE; } } #endif #if 0 void L1_s2b_0d0a_20190605(struct _s_PC1_0D0A_ *p)// reentrant { //p->ok = 1; #if 1 if(p->num >= D_s_SSTR_0D0A_len)//50B { p->num = 0; p->setflag = 0; } p->cashe[3] = p->cashe[2]; p->cashe[2] = p->cashe[1]; p->cashe[1] = p->cashe[0]; p->cashe[0] = p->reg;// p->buf[++p->num] = p->reg; if(!p->setflag) { if((p->cashe[0] == 'K') && (p->cashe[1] == 'O')) //Ok Flag { g_at_send_status.flag = FLAG_OK; p->setflag = FLAG_DISCARD; } else if((p->cashe[0] == 'C') && (p->cashe[1] == 'T') && (p->cashe[2] == '+')) //+TCPCLOSED Flag { g_at_send_status.connected_flag = 0; p->setflag = FLAG_DISCARD; } else if((p->cashe[0] == 'M') && (p->cashe[1] == 'C') && (p->cashe[2] == '+')) //+CME ERROR { g_at_send_status.connected_flag = 0; //yinzhimeng服务器一旦发送心跳返回错误 p->setflag = FLAG_DISCARD; } else if((p->cashe[0] == 'C') && (p->cashe[1] == 'C') && (p->cashe[2] == '+')) //+CCID: { p->setflag = FLAG_CCID; p->array[0] = FLAG_CCID; p->array[1] = '+'; p->array[2] = 'C'; p->array[3] = 'C'; p->num = 3; } else if((p->cashe[0] == 'P') && (p->cashe[1] == 'I') && (p->cashe[2] == 'C') && (p->cashe[3] == '+')) //+CIPRCV: { g_at_send_status.heart_recv_wait_time = 0; g_at_send_status.heart_recv_wait_time_wdt = 0; p->setflag = FLAG_CIP; p->array[0] = FLAG_CIP; p->array[1] = '+'; p->array[2] = 'C'; p->array[3] = 'I'; p->array[4] = 'P'; p->num = 4; } } else { if(p->setflag > FLAG_DISCARD) //+CCID or +CIPRCV { p->array[p->num] = p->reg; } } if ((p->cashe[0] == 0x0a) && (p->cashe[1] == 0x0d))// 0d0a { if((p->num > 2) && (p->setflag > FLAG_DISCARD)) //p->setFlag == 2 or 3 { if(1 != p->ok) { p->buf[0] = p->num -2; p->ok = 1;//收到 命令结束,必须有个地方清0,否则无法再次接受报文 } } p->num = 0; p->setflag = FLAG_NONE; } #endif } void L1_s2b_0d0a2(struct _s_PC1_0D0A_ *p)// reentrant { //p->ok = 1; #if 1 if(p->num >= D_s_SSTR_0D0A_len)//50B { p->num = 0; p->setflag = 0; } p->cashe[3] = p->cashe[2]; p->cashe[2] = p->cashe[1]; p->cashe[1] = p->cashe[0]; p->cashe[0] = p->reg;// p->buf[++p->num] = p->reg; if(!p->setflag) { if((p->cashe[0] == 'K') && (p->cashe[1] == 'O')) //Ok Flag { g_at_send_status.flag = FLAG_OK; p->setflag = FLAG_DISCARD; } if((p->cashe[0] == 'C') && (p->cashe[1] == 'T') && (p->cashe[2] == '+')) //+TCPCLOSED Flag { g_at_send_status.connected_flag = 0; p->setflag = FLAG_DISCARD; p->array[0] = FLAG_DISCARD; p->array[1] = '+'; p->array[2] = 'T'; p->array[3] = 'C'; p->num = 3; } else if((p->cashe[0] == 'M') && (p->cashe[1] == 'C') && (p->cashe[2] == '+')) //+CME ERROR { g_at_send_status.connected_flag = 0; //yinzhimeng服务器一旦发送心跳返回错误 p->setflag = FLAG_DISCARD; p->array[0] = FLAG_DISCARD; p->array[1] = '+'; p->array[2] = 'C'; p->array[3] = 'M'; p->num = 3; } else if((p->cashe[0] == 'C') && (p->cashe[1] == 'C') && (p->cashe[2] == '+')) //+CCID: { p->setflag = FLAG_CCID; p->array[0] = FLAG_CCID; p->array[1] = '+'; p->array[2] = 'C'; p->array[3] = 'C'; p->num = 3; } else if((p->cashe[0] == 'P') && (p->cashe[1] == 'I') && (p->cashe[2] == 'C') && (p->cashe[3] == '+')) //+CIPRCV: { g_at_send_status.heart_recv_wait_time = 0; g_at_send_status.heart_recv_wait_time_wdt = 0; p->setflag = FLAG_CIP; p->array[0] = FLAG_CIP; p->array[1] = '+'; p->array[2] = 'C'; p->array[3] = 'I'; p->array[4] = 'P'; p->num = 4; } } else { if(p->setflag >= FLAG_DISCARD) //+CCID or +CIPRCV { p->array[p->num] = p->reg; } } if ((p->cashe[0] == 0x0a) && (p->cashe[1] == 0x0d))// 0d0a { if((p->num > 2) && (p->setflag >= FLAG_DISCARD) /*1*/) //p->setFlag == 2 or 3 { if(1 != p->ok) { p->buf[0] = p->num -2; p->ok = 1;//收到 命令结束,必须有个地方清0,否则无法再次接受报文 } } p->num = 0; p->setflag = FLAG_NONE; } #endif } //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> //L1_uart_2strbuf(&s_uart0_rec);s_uart0_rec.ok = 2 /// 接收以od oa为结束的标准的assci码的协议 类似 send xx (回车换行)测试时注意以回车换行 /// 为结束标志,也就是发送的数据后面 必须有回车换行 :0x0d 0x0a void L1_s2b_0d0a1(struct _s_PC1_0D0A_ *p)// reentrant { if(p->num >= D_s_SSTR_0D0A_len)//50B { p->num = 0; } // p->cashe[2] = p->cashe[1]; p->cashe[1] = p->cashe[0]; p->cashe[0] = p->reg;// //检测\r\n if(1) { p->buf[p->num+1] = p->reg; p->num ++; } if ((p->cashe[0] == 0x0a)&&(p->cashe[1] == 0x0d))// 0d0a { // 0a 0d //p->max = p->num; if(p->num > 2) { if(1 != p->ok) { p->buf[0] = p->num -2; p->ok = 1;//收到 命令结束,必须有个地方清0,否则无法再次接受报文 } } p->num = 0; } } //L1_uart_2strbuf(&s_uart0_rec);s_uart0_rec.ok = 2 /// 接收以od oa为结束的标准的assci码的协议 类似 send xx (回车换行)测试时注意以回车换行 /// 为结束标志,也就是发送的数据后面 必须有回车换行 :0x0d 0x0a void L1_s2b_0d0a_bak_1(struct _s_PC1_0D0A_ *p)// reentrant { if(p->num >= D_s_SSTR_0D0A_len)//50B { p->num = 0; } // p->cashe[2] = p->cashe[1]; p->cashe[1] = p->cashe[0]; p->cashe[0] = p->reg;// //检测\r\n if(1) { p->buf[p->num+1] = p->reg; p->num ++; } if ((p->cashe[0] == 0x0a)&&(p->cashe[1] == 0x0d))// 0d0a { // 0a 0d //p->max = p->num; if(p->num > 2) { if(1 != p->ok) { p->buf[0] = p->num -2; p->ok = 1;//收到 命令结束,必须有个地方清0,否则无法再次接受报文 } } p->num = 0; } } void L1_s2b_0d0a_bak(struct _s_PC1_0D0A_ *p)// reentrant { int i; #if 0 //有问题,处理不及时会覆盖,重写参考tpc_uart/pc_1.c if(p->ok == 1) return; #endif #if 1 if(p->num >= D_s_SSTR_0D0A_len) p->num = 0; //p->cashe[2] = p->cashe[1]; p->cashe[1] = p->cashe[0]; p->cashe[0] = p->reg;// p->buf[p->num] = p->cashe[0]; p->num ++; #if 1 if ((p->cashe[0] == 0x0a)&&(p->cashe[1] == 0x0d))// 0d0a { // 0a 0d //p->max = p->num; if(1 != p->ok) { p->array[0] = p->num; for(i=0;inum;i++) p->array[i+1] = p->buf[i]; p->ok = 1;//收到 命令结束,必须有个地方清0,否则无法再次接受报文 } p->num = 0; } #endif #endif } #endif