vasko ozo
/
TxRxService
20190816
Diff: TxRxService.cpp
- Revision:
- 15:30e45bd5902e
- Parent:
- 14:b113f676ef42
- Child:
- 16:459ad1bd82fd
--- a/TxRxService.cpp Sun Aug 04 14:09:35 2019 +0000 +++ b/TxRxService.cpp Sun Aug 04 15:43:47 2019 +0000 @@ -4,18 +4,29 @@ uint8_t ArrTx[ArrTxSize] = ArrTxInitializer; uint8_t ArrRx[ArrRxSize] = ArrRxInitializer; -uint8_t RxBuff[ArrRxSize]; -uint8_t TxBuff[ArrTxSize]; +//uint8_t RxBuff[ArrRxSize]; +MsgType RxBuff; +//uint8_t TxBuff[ArrTxSize]; +MsgType TxBuff; uint8_t *pArrTx = &ArrTx[0]; uint8_t *pArrRx = &ArrRx[0]; bool RxBuffFull = 0; bool ArrTxBusy = 0; bool TxBuffFull = 0; +uint8_t GetCheckSum(uint8_t *p){ + uint8_t cs = 0; + for(int i = 0; i < (MsgCmdSize + MsgParsSize); i++){ + cs = cs + *(p++); + cs = cs + 1; + } + return cs; + } + void IntrTx(); void CopyArr_InitTx(uint8_t *parr){ - memcpy(ArrTx, parr, ArrTxSize); + memcpy(&ArrTx[HeaderLength], parr, sizeof(ArrTx)); pArrTx = &ArrTx[0]; pc.putc(*pArrTx); if(!ArrTxBusy) { @@ -28,7 +39,7 @@ void IntrTx() { if ( ++pArrTx <= &ArrTx[ArrTxSize-1] ) pc.putc(*pArrTx); else { - if(TxBuffFull) CopyArr_InitTx(TxBuff); + if(TxBuffFull) CopyArr_InitTx(&TxBuff.cmd); else { pc.attach(NULL, Serial::TxIrq); ArrTxBusy = 0; @@ -38,10 +49,11 @@ StartTxStates StartTx(uint8_t *parr){ if(TxBuffFull){ return TxBusy; } + *(parr + (MsgCmdSize + MsgParsSize)) = GetCheckSum(parr); if(ArrTxBusy) { - memcpy(TxBuff, parr, ArrTxSize); + memcpy(&TxBuff.cmd, parr, sizeof(TxBuff)); TxBuffFull=1; - if(!ArrTxBusy) CopyArr_InitTx(TxBuff); + if(!ArrTxBusy) CopyArr_InitTx(&TxBuff.cmd); } else CopyArr_InitTx(parr); return StartOK; }//StartTx @@ -51,7 +63,7 @@ if ( pArrRx++ >= &ArrRx[ArrRxSize-1] ) { pArrRx = &ArrRx[0]; RxBuffFull = 1; - memcpy(RxBuff, ArrRx, ArrTxSize); + memcpy(&RxBuff.cmd, &ArrRx[HeaderLength], sizeof(RxBuff)); } }//IntrRx