![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
20190816
TxRxService.cpp@15:30e45bd5902e, 2019-08-04 (annotated)
- Committer:
- VASKO
- Date:
- Sun Aug 04 15:43:47 2019 +0000
- Revision:
- 15:30e45bd5902e
- Parent:
- 14:b113f676ef42
- Child:
- 16:459ad1bd82fd
"GetCheckSum" added. "TxBuff" and "RxBuff" now are structs instead of arrays.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
VASKO | 11:6519744c77f9 | 1 | #include "PrjDefs.h" |
VASKO | 11:6519744c77f9 | 2 | |
VASKO | 11:6519744c77f9 | 3 | Serial pc(pcTx,pcRx); |
VASKO | 11:6519744c77f9 | 4 | |
VASKO | 11:6519744c77f9 | 5 | uint8_t ArrTx[ArrTxSize] = ArrTxInitializer; |
VASKO | 11:6519744c77f9 | 6 | uint8_t ArrRx[ArrRxSize] = ArrRxInitializer; |
VASKO | 15:30e45bd5902e | 7 | //uint8_t RxBuff[ArrRxSize]; |
VASKO | 15:30e45bd5902e | 8 | MsgType RxBuff; |
VASKO | 15:30e45bd5902e | 9 | //uint8_t TxBuff[ArrTxSize]; |
VASKO | 15:30e45bd5902e | 10 | MsgType TxBuff; |
VASKO | 11:6519744c77f9 | 11 | uint8_t *pArrTx = &ArrTx[0]; |
VASKO | 11:6519744c77f9 | 12 | uint8_t *pArrRx = &ArrRx[0]; |
VASKO | 13:b9e066badefa | 13 | bool RxBuffFull = 0; |
VASKO | 11:6519744c77f9 | 14 | bool ArrTxBusy = 0; |
VASKO | 11:6519744c77f9 | 15 | bool TxBuffFull = 0; |
VASKO | 11:6519744c77f9 | 16 | |
VASKO | 15:30e45bd5902e | 17 | uint8_t GetCheckSum(uint8_t *p){ |
VASKO | 15:30e45bd5902e | 18 | uint8_t cs = 0; |
VASKO | 15:30e45bd5902e | 19 | for(int i = 0; i < (MsgCmdSize + MsgParsSize); i++){ |
VASKO | 15:30e45bd5902e | 20 | cs = cs + *(p++); |
VASKO | 15:30e45bd5902e | 21 | cs = cs + 1; |
VASKO | 15:30e45bd5902e | 22 | } |
VASKO | 15:30e45bd5902e | 23 | return cs; |
VASKO | 15:30e45bd5902e | 24 | } |
VASKO | 15:30e45bd5902e | 25 | |
VASKO | 14:b113f676ef42 | 26 | void IntrTx(); |
VASKO | 14:b113f676ef42 | 27 | |
VASKO | 14:b113f676ef42 | 28 | void CopyArr_InitTx(uint8_t *parr){ |
VASKO | 15:30e45bd5902e | 29 | memcpy(&ArrTx[HeaderLength], parr, sizeof(ArrTx)); |
VASKO | 14:b113f676ef42 | 30 | pArrTx = &ArrTx[0]; |
VASKO | 14:b113f676ef42 | 31 | pc.putc(*pArrTx); |
VASKO | 14:b113f676ef42 | 32 | if(!ArrTxBusy) { |
VASKO | 14:b113f676ef42 | 33 | ArrTxBusy = 1; |
VASKO | 14:b113f676ef42 | 34 | pc.attach(IntrTx, Serial::TxIrq); |
VASKO | 14:b113f676ef42 | 35 | } |
VASKO | 14:b113f676ef42 | 36 | TxBuffFull = 0; |
VASKO | 14:b113f676ef42 | 37 | } |
VASKO | 14:b113f676ef42 | 38 | |
VASKO | 11:6519744c77f9 | 39 | void IntrTx() { |
VASKO | 11:6519744c77f9 | 40 | if ( ++pArrTx <= &ArrTx[ArrTxSize-1] ) pc.putc(*pArrTx); |
VASKO | 11:6519744c77f9 | 41 | else { |
VASKO | 15:30e45bd5902e | 42 | if(TxBuffFull) CopyArr_InitTx(&TxBuff.cmd); |
VASKO | 14:b113f676ef42 | 43 | else { |
VASKO | 14:b113f676ef42 | 44 | pc.attach(NULL, Serial::TxIrq); |
VASKO | 14:b113f676ef42 | 45 | ArrTxBusy = 0; |
VASKO | 14:b113f676ef42 | 46 | } |
VASKO | 11:6519744c77f9 | 47 | } |
VASKO | 11:6519744c77f9 | 48 | }//IntrTx |
VASKO | 11:6519744c77f9 | 49 | |
VASKO | 14:b113f676ef42 | 50 | StartTxStates StartTx(uint8_t *parr){ |
VASKO | 14:b113f676ef42 | 51 | if(TxBuffFull){ return TxBusy; } |
VASKO | 15:30e45bd5902e | 52 | *(parr + (MsgCmdSize + MsgParsSize)) = GetCheckSum(parr); |
VASKO | 14:b113f676ef42 | 53 | if(ArrTxBusy) { |
VASKO | 15:30e45bd5902e | 54 | memcpy(&TxBuff.cmd, parr, sizeof(TxBuff)); |
VASKO | 14:b113f676ef42 | 55 | TxBuffFull=1; |
VASKO | 15:30e45bd5902e | 56 | if(!ArrTxBusy) CopyArr_InitTx(&TxBuff.cmd); |
VASKO | 14:b113f676ef42 | 57 | } else CopyArr_InitTx(parr); |
VASKO | 14:b113f676ef42 | 58 | return StartOK; |
VASKO | 11:6519744c77f9 | 59 | }//StartTx |
VASKO | 11:6519744c77f9 | 60 | |
VASKO | 11:6519744c77f9 | 61 | void IntrRx() { |
VASKO | 11:6519744c77f9 | 62 | *pArrRx = pc.getc(); |
VASKO | 11:6519744c77f9 | 63 | if ( pArrRx++ >= &ArrRx[ArrRxSize-1] ) { |
VASKO | 11:6519744c77f9 | 64 | pArrRx = &ArrRx[0]; |
VASKO | 13:b9e066badefa | 65 | RxBuffFull = 1; |
VASKO | 15:30e45bd5902e | 66 | memcpy(&RxBuff.cmd, &ArrRx[HeaderLength], sizeof(RxBuff)); |
VASKO | 11:6519744c77f9 | 67 | } |
VASKO | 11:6519744c77f9 | 68 | }//IntrRx |
VASKO | 11:6519744c77f9 | 69 | |
VASKO | 11:6519744c77f9 | 70 | void TxRxServiceInit(){ |
VASKO | 14:b113f676ef42 | 71 | pc.attach(IntrRx, Serial::RxIrq); |
VASKO | 11:6519744c77f9 | 72 | pc.attach(NULL, Serial::TxIrq);//я УПЁРТЫЙ дебил |
VASKO | 11:6519744c77f9 | 73 | } |
VASKO | 11:6519744c77f9 | 74 |