Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
TxRxService.cpp
- Committer:
- VASKO
- Date:
- 2019-08-05
- Revision:
- 17:d180adbbd61f
- Parent:
- 16:459ad1bd82fd
- Child:
- 23:39d96e160cf1
File content as of revision 17:d180adbbd61f:
#include "PrjDefs.h"
Serial pc(WorkTx,WorkRx);
uint8_t ArrTx[ArrTxSize] = ArrTxInitializer;
uint8_t ArrRx[ArrRxSize] = ArrRxInitializer;
MsgType RxBuff;
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 < (sizeof(MsgType)-1); i++){
cs = cs + *(p++);
cs = cs + 1;
}
return cs;
}
void IntrTx();
void CopyArr_InitTx(uint8_t *parr){
memcpy(&ArrTx[HeaderLength], parr, sizeof(TxBuff));
pArrTx = &ArrTx[0];
pc.putc(*pArrTx);
if(!ArrTxBusy) {
ArrTxBusy = 1;
pc.attach(IntrTx, Serial::TxIrq);
}
TxBuffFull = 0;
}
void IntrTx() {
if ( ++pArrTx <= &ArrTx[ArrTxSize-1] ) pc.putc(*pArrTx);
else {
if(TxBuffFull) CopyArr_InitTx(&TxBuff.cmd);
else {
pc.attach(NULL, Serial::TxIrq);
ArrTxBusy = 0;
}
}
}//IntrTx
StartTxStates StartTx(uint8_t *parr){
if(TxBuffFull){ return TxBusy; }
*(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
void IntrRx() {
*pArrRx = pc.getc();
if ( pArrRx++ >= &ArrRx[ArrRxSize-1] ) {
pArrRx = &ArrRx[0];
RxBuffFull = 1;
memcpy(&RxBuff.cmd, &ArrRx[HeaderLength], sizeof(RxBuff));
}
}//IntrRx
void TxRxServiceInit(){
pc.attach(IntrRx, Serial::RxIrq);
pc.attach(NULL, Serial::TxIrq);//я УПЁРТЫЙ дебил
}