| | |
| | | UsartReceiveWaitIndex, |
| | | UsartReceiveWaitDataLen, |
| | | UsartReceiveWaitData, |
| | | UsartReceiveWaitChecksum, |
| | | UsartReceiveWaitChecksum0, |
| | | UsartReceiveWaitChecksum1 |
| | | |
| | | }UsartRecvPackState; |
| | | |
| | |
| | | } |
| | | u8 remotetag_para[30],remotetag_paralen,userdata_len,userdata[50]; |
| | | u8 remotesend_state=0; |
| | | u16 rec_checksum; |
| | | u16 rec_checksum,userdata_targetid; |
| | | uint16_t configremotetagID; |
| | | u32 getuserdata_tick; |
| | | void UsartParseDataHandler(uint8_t data) |
| | |
| | | uint8_t i; |
| | | |
| | | |
| | | if(usart_receive_state == UsartReceiveWaitChecksum) { //è¥æ¶å°æ ¡éªåå
|
| | | if(usart_receive_state == UsartReceiveWaitChecksum1) { //è¥æ¶å°æ ¡éªåå
|
| | | checksum = 0; |
| | | for(int i = 0; i<pack_length-2; i++) { |
| | | checksum += mUsartReceivePack[i]; |
| | | } |
| | | checksum += pack_msgtype; |
| | | checksum += pack_length; |
| | | |
| | | if(((data + checksum)&0xff) == 0xFF) //æ ¡éªéè¿ |
| | | checksum = ~checksum; |
| | | rec_checksum = rec_checksum|(data<<8); |
| | | if(rec_checksum == checksum) //æ ¡éªéè¿ |
| | | { |
| | | switch(pack_msgtype) |
| | | { |
| | |
| | | memcpy(&remotetag_para[1],&mUsartReceivePack[3],remotetag_paralen); |
| | | break; |
| | | case MSG_USERDATA: |
| | | userdata_len = mUsartReceivePack[0]; |
| | | userdata_len = mUsartReceivePack[2]; |
| | | memcpy(&userdata_targetid,mUsartReceivePack,2); |
| | | if(userdata_len==USERDATA_LEN) |
| | | { |
| | | memcpy(userdata,&mUsartReceivePack[0],USERDATA_LEN+1); |
| | | memcpy(userdata,&mUsartReceivePack[0],USERDATA_LEN+3); |
| | | getuserdata_tick = time32_incr; |
| | | SendConfigConfirm(pack_msgtype,pack_length); |
| | | } |
| | |
| | | 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-2) { //妿æ¶å°çindexä¸é¿åº¦ç¸ç |
| | | usart_receive_state = UsartReceiveWaitChecksum; |
| | | usart_receive_state = UsartReceiveWaitChecksum0; |
| | | } |
| | | } else if(usart_receive_state == UsartReceiveWaitLength) { //æ¶å°é¿åº¦åè |
| | | |