From 87fe2ff0a507923acf3bb416737cafdfb52f0c6d Mon Sep 17 00:00:00 2001
From: zhyinch <zhyinch@gmail.com>
Date: 星期二, 13 四月 2021 14:29:54 +0800
Subject: [PATCH] V1.45 负数不输出

---
 源码/核心板/Src/application/serial_at_cmd_app.c |   35 ++++++++++++++++++++++++++---------
 1 files changed, 26 insertions(+), 9 deletions(-)

diff --git "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/serial_at_cmd_app.c" "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/serial_at_cmd_app.c"
index 3519e97..2993869 100644
--- "a/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/serial_at_cmd_app.c"
+++ "b/\346\272\220\347\240\201/\346\240\270\345\277\203\346\235\277/Src/application/serial_at_cmd_app.c"
@@ -11,7 +11,7 @@
 #define CMD_READ	1
 #define CMD_WRITE	2
 #define CMD_REPLY 3
-#define EUART_RX_BUF_SIZE 100
+#define EUART_RX_BUF_SIZE 200
 typedef enum{	UsartReceiveWaitHead0, 
 				UsartReceiveWaitHead1,
 				UsartReceiveWaitMsgType,
@@ -20,7 +20,8 @@
 				UsartReceiveWaitIndex,
 				UsartReceiveWaitDataLen,
 				UsartReceiveWaitData,
-				UsartReceiveWaitChecksum
+				UsartReceiveWaitChecksum0,
+				UsartReceiveWaitChecksum1
 }UsartRecvPackState;
 
 uint8_t mUsartReceivePack[100] = {0};
@@ -38,7 +39,7 @@
 	checksum = Checksum_u16(&send_frame[2],8);
 	memcpy(&send_frame[10],&checksum,2);
 	
-	UART_PushFrame(send_frame, 12);	
+	USART_puts(send_frame, 12);	
 }
 void SendComMap(uint8_t data_length, uint8_t index)
 {
@@ -51,7 +52,10 @@
 	send_frame[5] = index;
 	send_frame[6] = data_length;
 	memcpy(&send_frame[7], &g_com_map[index>>1], data_length);
-
+	for(int i = 0; i<(data_length+5); i++)
+	{
+		checksum += send_frame[2+i];
+	}
 	checksum = Checksum_u16(&send_frame[2],5+data_length);
 	memcpy(&send_frame[7+data_length],&checksum,2);
 	
@@ -59,6 +63,7 @@
 }
 u8 remotetag_para[30];
 u8 remotesend_state=0;
+u16 rec_checksum;
 void UsartParseDataHandler(uint8_t data)
 {
 	static UsartRecvPackState usart_receive_state = UsartReceiveWaitHead0;
@@ -68,7 +73,7 @@
 
 
 	
-	if(usart_receive_state == UsartReceiveWaitChecksum) {			//若收到校验和包
+	if(usart_receive_state == UsartReceiveWaitChecksum1) {			//若收到校验和包.
 		checksum = 0;
 		for(int i = 0; i<pack_length-5; i++) { 
 			checksum += mUsartReceivePack[i];
@@ -78,7 +83,9 @@
 		checksum += pack_index;
 		checksum += pack_datalen;
 		checksum += pack_msgtype;
-		if(((data + checksum)&0xff) == 0xFF)				//校验通过
+		checksum = ~checksum;
+		rec_checksum = rec_checksum|(data<<8);
+		if(rec_checksum == checksum)				//校验通过
 		{
 			switch(pack_msgtype)
 			{
@@ -92,7 +99,8 @@
 							//SendComMap(pack_datalen,pack_index);
 							save_com_map_to_flash();
 							SendConfigConfirm(pack_msgtype,pack_length);
-							Program_Init();
+							delay_ms(500);
+							SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
 							break;
 						case CMD_READ:
 							//read包中data字节,即mUsartReceivePack[0]表示数据长度;
@@ -103,6 +111,12 @@
 							break;
 					}
 					break;
+					case MSG_WTAG:
+					remotesend_state++;
+					if(remotesend_state>14)
+						remotesend_state=1;
+					memcpy(remotetag_para,mUsartReceivePack,REMOTEPARA_LEN);
+					break;
 
 		}
 		}
@@ -110,11 +124,14 @@
 		pack_index = 0;
 		pack_length = 0;
 		index=0;
-	} else if((usart_receive_state == UsartReceiveWaitData) ) {	//若果收到的是正常通讯包
+	} else if((usart_receive_state == UsartReceiveWaitChecksum0) ) {	
+			rec_checksum = data;
+		usart_receive_state = UsartReceiveWaitChecksum1;
+	}else if((usart_receive_state == UsartReceiveWaitData) ) {	//若果收到的是正常通讯包
 		mUsartReceivePack[index] = data;
 		index++;
 		if(index == pack_length-5) {		//如果收到的index与长度相等
-			usart_receive_state = UsartReceiveWaitChecksum;
+			usart_receive_state = UsartReceiveWaitChecksum0;
 		}
 	} else if(usart_receive_state == UsartReceiveWaitDataLen) {						//收到指令类型字节
 		pack_datalen = data;

--
Gitblit v1.9.3