20190816

Dependencies:   mbed

Revision:
16:459ad1bd82fd
Parent:
15:30e45bd5902e
Child:
17:d180adbbd61f
--- a/TxRxService.cpp	Sun Aug 04 15:43:47 2019 +0000
+++ b/TxRxService.cpp	Sun Aug 04 18:01:47 2019 +0000
@@ -4,9 +4,7 @@
 
 uint8_t ArrTx[ArrTxSize] = ArrTxInitializer;
 uint8_t ArrRx[ArrRxSize] = ArrRxInitializer;
-//uint8_t RxBuff[ArrRxSize];
 MsgType RxBuff;
-//uint8_t TxBuff[ArrTxSize];
 MsgType TxBuff;
 uint8_t *pArrTx = &ArrTx[0];
 uint8_t *pArrRx = &ArrRx[0];
@@ -16,7 +14,7 @@
 
 uint8_t GetCheckSum(uint8_t *p){
     uint8_t cs = 0;
-    for(int i = 0; i < (MsgCmdSize + MsgParsSize); i++){
+    for(int i = 0; i < (sizeof(MsgType)-1); i++){
         cs = cs + *(p++);
         cs = cs + 1;
         }
@@ -26,7 +24,7 @@
 void IntrTx(); 
 
 void CopyArr_InitTx(uint8_t *parr){
-    memcpy(&ArrTx[HeaderLength], parr, sizeof(ArrTx));
+    memcpy(&ArrTx[HeaderLength], parr, sizeof(TxBuff));
     pArrTx = &ArrTx[0];
     pc.putc(*pArrTx);
     if(!ArrTxBusy) {
@@ -49,11 +47,11 @@
 
 StartTxStates StartTx(uint8_t *parr){
         if(TxBuffFull){ return TxBusy; }
-        *(parr + (MsgCmdSize + MsgParsSize)) = GetCheckSum(parr);
-        if(ArrTxBusy) {
-            memcpy(&TxBuff.cmd, parr, sizeof(TxBuff));
-            TxBuffFull=1;
-            if(!ArrTxBusy) CopyArr_InitTx(&TxBuff.cmd);
+        *(parr + (sizeof(MsgType)-1)) = GetCheckSum(parr);
+        if(ArrTxBusy) {                                //ВНИМАНИЕ!!! IntrTx последнего байта пакета!!! НЕАТОМАРНЫЙ КУСОК КОДА!!!
+            memcpy(&TxBuff.cmd, parr, sizeof(TxBuff)); //ВНИМАНИЕ!!! IntrTx последнего байта пакета!!! НЕАТОМАРНЫЙ КУСОК КОДА!!!
+            TxBuffFull=1;                              //ВНИМАНИЕ!!! IntrTx последнего байта пакета!!! НЕАТОМАРНЫЙ КУСОК КОДА!!!
+            if(!ArrTxBusy) CopyArr_InitTx(&TxBuff.cmd);//ВНИМАНИЕ!!! IntrTx последнего байта пакета!!! НЕАТОМАРНЫЙ КУСОК КОДА!!!
             } else CopyArr_InitTx(parr);
         return StartOK;
     }//StartTx
@@ -70,5 +68,4 @@
 void TxRxServiceInit(){
     pc.attach(IntrRx, Serial::RxIrq);
     pc.attach(NULL, Serial::TxIrq);//я УПЁРТЫЙ дебил
-    }
-
+    }
\ No newline at end of file