From 485f9f88dfc22b143ccfd6624575e99c23fcd52c Mon Sep 17 00:00:00 2001 From: 18650180552 Date: Mon, 3 Feb 2020 01:51:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E6=8E=A5=E5=8F=97=E6=9D=A5?= =?UTF-8?q?=E8=87=AA=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=9A=84=E6=B6=88=E6=81=AF?= =?UTF-8?q?=EF=BC=8C=E4=BD=86=E6=98=AF=E8=BF=98=E9=9C=80=E8=A6=81AT?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E9=9B=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- c51/relay_controller/main.c | 42 +++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/c51/relay_controller/main.c b/c51/relay_controller/main.c index 1df332f..0b59203 100644 --- a/c51/relay_controller/main.c +++ b/c51/relay_controller/main.c @@ -40,6 +40,7 @@ char index_tmp = 0; void SendData(BYTE dat); void SendString(char *s); void SendWifi(char *dat); +void SendBuffer(char *s,char len); code char AT_SetUp[30] = "ATE0\r\n"; code char AT_Connect[] = "AT+CIPSTART=\"TCP\",\"192.168.2.108\",8080\r\n"; @@ -115,7 +116,9 @@ void Uart_Init(){ void callbackUart(){ if (recv_flag_global == 1 || overflow_flag == 1){ P3_Uart(); - SendString(recv_buf); + if(overflow_flag == 1) + recv_buf[29] = 0x49; + SendBuffer(recv_buf,30); memset(recv_buf,0,30); recv_flag_global = 0; overflow_flag = 0; @@ -182,6 +185,7 @@ void Uart_Isr() interrupt 4 static bit flag_recv = 0; static bit flag_need_read = 0; static char recv_cnt = 0; + if (RI) { RI = 0; //Clear receive interrupt flag @@ -192,23 +196,20 @@ void Uart_Isr() interrupt 4 recv_buf[index + 1] = '\0'; recv_flag_global = 1; index = 0; - sec_last_byte = 0; last_byte = 0; - trd_last_byte = 0; - four_last_byte = 0; + //todo } if( - (last_byte == ':') - &&(sec_last_byte == '5' ) - &&(trd_last_byte == ',' ) - &&(four_last_byte == 'D')) + (recv_buf[index - 1] == ':') + &&(recv_buf[index - 2] == '5' ) + &&(recv_buf[index - 3] == ',' ) + &&(recv_buf[index - 4] == 'D') + &&index > 4) { flag_need_read = 1; - recv_cnt = 5; + recv_cnt = 4; } - - if(flag_need_read == 1){ if(recv_cnt > 0){ recv_cnt --; @@ -216,14 +217,10 @@ void Uart_Isr() interrupt 4 recv_buf[index + 1] = "\0"; recv_flag_global = 1; index = 0; - sec_last_byte = 0; - last_byte = 0; - trd_last_byte = 0; - four_last_byte = 0; + recv_cnt = 0; + flag_need_read = 0; } - } - - RI = 0; + } recv_buf[index] = SBUF; last_byte = SBUF; index ++; @@ -271,4 +268,13 @@ void SendWifi(char *dat){ SendString(AT_SendData); Delay3020ms(); SendString(dat); +} +void SendBuffer(char *s,char len){ + + while (len > 0) //Check the end of the string + { + Delay1020us(); + SendData(*s++); //Send current char and increment string ptr + len --; + } } \ No newline at end of file