20190816

Dependencies:   mbed

Revision:
23:39d96e160cf1
Parent:
17:d180adbbd61f
Child:
24:fba9a58e6fbd
--- a/TxRxService.cpp	Thu Aug 08 08:48:44 2019 +0000
+++ b/TxRxService.cpp	Thu Aug 08 13:24:28 2019 +0000
@@ -7,10 +7,13 @@
 MsgType RxBuff;
 MsgType TxBuff;
 uint8_t *pArrTx = &ArrTx[0];
-uint8_t *pArrRx = &ArrRx[0];
+uint8_t *pArrRx = &ArrRx[HeaderLength];
 bool RxBuffFull = 0;
 bool ArrTxBusy = 0;
 bool TxBuffFull = 0;
+bool HdrRcvd = 0;
+bool MsgEnabled = 0;
+uint8_t HBctr = 0;
 
 uint8_t GetCheckSum(uint8_t *p){
     uint8_t cs = 0;
@@ -57,15 +60,32 @@
     }//StartTx
 
 void IntrRx() {
-    *pArrRx = pc.getc();
-    if ( pArrRx++ >= &ArrRx[ArrRxSize-1] ) {
-        pArrRx = &ArrRx[0]; 
-        RxBuffFull = 1;
-        memcpy(&RxBuff.cmd, &ArrRx[HeaderLength], sizeof(RxBuff)); 
-        }
+    uint8_t _ch = pc.getc();
+    if(_ch == HeaderByte){ 
+        if((++HBctr) >= HeaderLength){ 
+            HdrRcvd = 1;
+            pArrRx = &ArrRx[HeaderLength];
+            MsgEnabled = 0;
+            } 
+        }else{ 
+            HBctr = 0;
+            if(HdrRcvd) { HdrRcvd = 0; MsgEnabled = 1; }
+            }
+    if(MsgEnabled){
+        *pArrRx = _ch;
+        if ( pArrRx++ >= &ArrRx[ArrRxSize-1] ){
+            pArrRx = &ArrRx[HeaderLength]; 
+            RxBuffFull = 1;
+            memcpy(&RxBuff.cmd, &ArrRx[HeaderLength], sizeof(RxBuff));
+            MsgEnabled = 0;
+            }
+        }//if(MsgEnabled)
     }//IntrRx
 
 void TxRxServiceInit(){
+#ifdef BaudRate
+    pc.baud(BaudRate);
+#endif
     pc.attach(IntrRx, Serial::RxIrq);
     pc.attach(NULL, Serial::TxIrq);//я УПЁРТЫЙ дебил
     }
\ No newline at end of file