可以接受来自服务器的消息,但是还需要AT指令集。

master
18650180552 2020-02-03 01:51:05 +08:00
parent a2bd3be251
commit 485f9f88df
1 changed files with 24 additions and 18 deletions

View File

@ -40,6 +40,7 @@ char index_tmp = 0;
void SendData(BYTE dat); void SendData(BYTE dat);
void SendString(char *s); void SendString(char *s);
void SendWifi(char *dat); void SendWifi(char *dat);
void SendBuffer(char *s,char len);
code char AT_SetUp[30] = "ATE0\r\n"; code char AT_SetUp[30] = "ATE0\r\n";
code char AT_Connect[] = "AT+CIPSTART=\"TCP\",\"192.168.2.108\",8080\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(){ void callbackUart(){
if (recv_flag_global == 1 || overflow_flag == 1){ if (recv_flag_global == 1 || overflow_flag == 1){
P3_Uart(); P3_Uart();
SendString(recv_buf); if(overflow_flag == 1)
recv_buf[29] = 0x49;
SendBuffer(recv_buf,30);
memset(recv_buf,0,30); memset(recv_buf,0,30);
recv_flag_global = 0; recv_flag_global = 0;
overflow_flag = 0; overflow_flag = 0;
@ -182,6 +185,7 @@ void Uart_Isr() interrupt 4
static bit flag_recv = 0; static bit flag_recv = 0;
static bit flag_need_read = 0; static bit flag_need_read = 0;
static char recv_cnt = 0; static char recv_cnt = 0;
if (RI) if (RI)
{ {
RI = 0; //Clear receive interrupt flag RI = 0; //Clear receive interrupt flag
@ -192,23 +196,20 @@ void Uart_Isr() interrupt 4
recv_buf[index + 1] = '\0'; recv_buf[index + 1] = '\0';
recv_flag_global = 1; recv_flag_global = 1;
index = 0; index = 0;
sec_last_byte = 0;
last_byte = 0; last_byte = 0;
trd_last_byte = 0;
four_last_byte = 0;
//todo //todo
} }
if( if(
(last_byte == ':') (recv_buf[index - 1] == ':')
&&(sec_last_byte == '5' ) &&(recv_buf[index - 2] == '5' )
&&(trd_last_byte == ',' ) &&(recv_buf[index - 3] == ',' )
&&(four_last_byte == 'D')) &&(recv_buf[index - 4] == 'D')
&&index > 4)
{ {
flag_need_read = 1; flag_need_read = 1;
recv_cnt = 5; recv_cnt = 4;
} }
if(flag_need_read == 1){ if(flag_need_read == 1){
if(recv_cnt > 0){ if(recv_cnt > 0){
recv_cnt --; recv_cnt --;
@ -216,14 +217,10 @@ void Uart_Isr() interrupt 4
recv_buf[index + 1] = "\0"; recv_buf[index + 1] = "\0";
recv_flag_global = 1; recv_flag_global = 1;
index = 0; index = 0;
sec_last_byte = 0; recv_cnt = 0;
last_byte = 0; flag_need_read = 0;
trd_last_byte = 0;
four_last_byte = 0;
} }
} }
RI = 0;
recv_buf[index] = SBUF; recv_buf[index] = SBUF;
last_byte = SBUF; last_byte = SBUF;
index ++; index ++;
@ -272,3 +269,12 @@ void SendWifi(char *dat){
Delay3020ms(); Delay3020ms();
SendString(dat); 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 --;
}
}