vasko ozo
/
TxRxService
20190816
main.cpp@24:fba9a58e6fbd, 2019-08-08 (annotated)
- Committer:
- VASKO
- Date:
- Thu Aug 08 17:10:26 2019 +0000
- Revision:
- 24:fba9a58e6fbd
- Parent:
- 23:39d96e160cf1
- Child:
- 25:0f1f6687333c
TxRxService ready for use.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
VASKO | 7:7aaa14391264 | 1 | #include "PrjDefs.h" |
VASKO | 0:5152e3f9df72 | 2 | |
VASKO | 0:5152e3f9df72 | 3 | DigitalOut myled(LED1); |
VASKO | 0:5152e3f9df72 | 4 | |
VASKO | 19:09c21f5f0625 | 5 | Serial dpc(USBTX,USBRX); |
VASKO | 19:09c21f5f0625 | 6 | |
VASKO | 19:09c21f5f0625 | 7 | Ticker tickTx; |
VASKO | 19:09c21f5f0625 | 8 | |
VASKO | 23:39d96e160cf1 | 9 | MsgType _msg; |
VASKO | 23:39d96e160cf1 | 10 | |
VASKO | 23:39d96e160cf1 | 11 | bool tick = 0; |
VASKO | 24:fba9a58e6fbd | 12 | bool SM = 0; |
VASKO | 23:39d96e160cf1 | 13 | uint32_t ctr = 0; // счетчик обменов |
VASKO | 23:39d96e160cf1 | 14 | uint32_t ctro = 0; |
VASKO | 23:39d96e160cf1 | 15 | uint32_t Ectr = 0; // счетчик ошибок |
VASKO | 23:39d96e160cf1 | 16 | |
VASKO | 24:fba9a58e6fbd | 17 | void dpc_func(){ (void) dpc.getc(); SM=1; } |
VASKO | 23:39d96e160cf1 | 18 | |
VASKO | 24:fba9a58e6fbd | 19 | void tickIntrFunc(void){ tick = 1; }//tickIntrFunc |
VASKO | 19:09c21f5f0625 | 20 | |
VASKO | 0:5152e3f9df72 | 21 | int main() { |
VASKO | 23:39d96e160cf1 | 22 | |
VASKO | 23:39d96e160cf1 | 23 | _msg.cmd=0x41; |
VASKO | 23:39d96e160cf1 | 24 | _msg.pars.ui32[0]=0; |
VASKO | 23:39d96e160cf1 | 25 | |
VASKO | 11:6519744c77f9 | 26 | TxRxServiceInit(); |
VASKO | 23:39d96e160cf1 | 27 | tickTx.attach(&tickIntrFunc, 1); |
VASKO | 23:39d96e160cf1 | 28 | dpc.baud(115200); |
VASKO | 23:39d96e160cf1 | 29 | dpc.attach(dpc_func); |
VASKO | 12:6f63e376c0aa | 30 | |
VASKO | 2:56a194afd255 | 31 | //Exige Monumentum |
VASKO | 9:dcddb19ad551 | 32 | //Я дебил,потому что хотел выполнить действия,которые |
VASKO | 2:56a194afd255 | 33 | //требуются постоянно,один раз и именно здесь. |
VASKO | 0:5152e3f9df72 | 34 | |
VASKO | 12:6f63e376c0aa | 35 | //Для дебилов: в mbed типы "int" и "unsigned int" имеют размер 4 байта !!! |
VASKO | 12:6f63e376c0aa | 36 | |
VASKO | 16:459ad1bd82fd | 37 | //https://os.mbed.com/forum/bugs-suggestions/topic/4264/ проблема выравнивания данных |
VASKO | 16:459ad1bd82fd | 38 | |
VASKO | 0:5152e3f9df72 | 39 | while(1) { |
VASKO | 24:fba9a58e6fbd | 40 | TxRxStates _trs = GetMsg(&_msg.cmd); |
VASKO | 24:fba9a58e6fbd | 41 | if(_trs == RxRcvd){ |
VASKO | 24:fba9a58e6fbd | 42 | myled = !myled; |
VASKO | 24:fba9a58e6fbd | 43 | ctr++; |
VASKO | 24:fba9a58e6fbd | 44 | _msg.pars.ui32[0]++; |
VASKO | 24:fba9a58e6fbd | 45 | if(tick){ |
VASKO | 24:fba9a58e6fbd | 46 | tick = 0; |
VASKO | 24:fba9a58e6fbd | 47 | dpc.printf("ctr = %d, diff = %d, Ectr = %d\n\r", ctr, ctr - ctro, Ectr); |
VASKO | 24:fba9a58e6fbd | 48 | ctro = ctr; |
VASKO | 24:fba9a58e6fbd | 49 | } |
VASKO | 24:fba9a58e6fbd | 50 | SendMsg(&_msg.cmd); |
VASKO | 24:fba9a58e6fbd | 51 | }else if(_trs == RxCS_Err) Ectr++; |
VASKO | 24:fba9a58e6fbd | 52 | if(SM) { SM = 0; SendMsg(&_msg.cmd); } |
VASKO | 8:cad966c09853 | 53 | }//while(1) |
VASKO | 9:dcddb19ad551 | 54 | }//main |
VASKO | 9:dcddb19ad551 | 55 |