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.
arq.h@0:8e06c9b8b7f6, 2021-05-25 (annotated)
- Committer:
- quagga
- Date:
- Tue May 25 17:45:26 2021 +0000
- Revision:
- 0:8e06c9b8b7f6
arq radio class; todo- crc check on message
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| quagga | 0:8e06c9b8b7f6 | 1 | #include"MicroBit.h" |
| quagga | 0:8e06c9b8b7f6 | 2 | //#define ARQ_DEBUG |
| quagga | 0:8e06c9b8b7f6 | 3 | |
| quagga | 0:8e06c9b8b7f6 | 4 | #define ARQ_ID 4000 |
| quagga | 0:8e06c9b8b7f6 | 5 | #define ARQ_MSG_RECVD_EVT 1 |
| quagga | 0:8e06c9b8b7f6 | 6 | #define ARQ_MSG_SEND_FAIL 2 |
| quagga | 0:8e06c9b8b7f6 | 7 | #define ARQ_MSG_ACK_RECVD 3 |
| quagga | 0:8e06c9b8b7f6 | 8 | #define ARQ_POW_RECVD_EVT 4 |
| quagga | 0:8e06c9b8b7f6 | 9 | #define ARQ_POW_SEND_FAIL 5 |
| quagga | 0:8e06c9b8b7f6 | 10 | #define ARQ_POW_ACK_RECVD 6 |
| quagga | 0:8e06c9b8b7f6 | 11 | |
| quagga | 0:8e06c9b8b7f6 | 12 | #ifndef ARQ_H |
| quagga | 0:8e06c9b8b7f6 | 13 | #define ARQ_H |
| quagga | 0:8e06c9b8b7f6 | 14 | |
| quagga | 0:8e06c9b8b7f6 | 15 | class Arq |
| quagga | 0:8e06c9b8b7f6 | 16 | { |
| quagga | 0:8e06c9b8b7f6 | 17 | public: |
| quagga | 0:8e06c9b8b7f6 | 18 | unsigned char power; //power of transmitter |
| quagga | 0:8e06c9b8b7f6 | 19 | unsigned char received_power; |
| quagga | 0:8e06c9b8b7f6 | 20 | unsigned int timeout; //time after send with no ACK before resend in microseconds CURRENTLY IRRELEVANT!! |
| quagga | 0:8e06c9b8b7f6 | 21 | unsigned int maxtries; //max number of attempts at sending before give up :( (default 10) |
| quagga | 0:8e06c9b8b7f6 | 22 | unsigned int mintries; //min number of attempts allowable (default 1) |
| quagga | 0:8e06c9b8b7f6 | 23 | unsigned int tries; //number of attempts at last go |
| quagga | 0:8e06c9b8b7f6 | 24 | unsigned int rssi; //rssi from last ACK received i.e. rssi reported by receiver |
| quagga | 0:8e06c9b8b7f6 | 25 | unsigned int min_rssi; //rssi below which power can be reduced (default 70) |
| quagga | 0:8e06c9b8b7f6 | 26 | |
| quagga | 0:8e06c9b8b7f6 | 27 | MicroBit *uBit; |
| quagga | 0:8e06c9b8b7f6 | 28 | PacketBuffer packet; |
| quagga | 0:8e06c9b8b7f6 | 29 | |
| quagga | 0:8e06c9b8b7f6 | 30 | Arq(MicroBit *bit); |
| quagga | 0:8e06c9b8b7f6 | 31 | ~Arq(){}; |
| quagga | 0:8e06c9b8b7f6 | 32 | |
| quagga | 0:8e06c9b8b7f6 | 33 | void off(); |
| quagga | 0:8e06c9b8b7f6 | 34 | void receive(); |
| quagga | 0:8e06c9b8b7f6 | 35 | void listen(MicroBitEvent e); |
| quagga | 0:8e06c9b8b7f6 | 36 | void send(PacketBuffer packet); |
| quagga | 0:8e06c9b8b7f6 | 37 | |
| quagga | 0:8e06c9b8b7f6 | 38 | void incPower(); |
| quagga | 0:8e06c9b8b7f6 | 39 | void decPower(); |
| quagga | 0:8e06c9b8b7f6 | 40 | }; |
| quagga | 0:8e06c9b8b7f6 | 41 | |
| quagga | 0:8e06c9b8b7f6 | 42 | #endif |
| quagga | 0:8e06c9b8b7f6 | 43 | |
| quagga | 0:8e06c9b8b7f6 | 44 | //1st byte ACK,POWER_TEST or MESSAGE if ACK, RSSI of RECEIVED MESSAGE ALSO |
| quagga | 0:8e06c9b8b7f6 | 45 | //128 64 32 16 8 4 2 1 |
| quagga | 0:8e06c9b8b7f6 | 46 | // 1 1 1 0 0 0 0 0 - ACK -98 RSSI |
| quagga | 0:8e06c9b8b7f6 | 47 | // 1 0 1 1 0 0 0 1 - ACK -49 RSSI |
| quagga | 0:8e06c9b8b7f6 | 48 | // 0 0 0 0 0 0 0 0 - POWER_TEST |
| quagga | 0:8e06c9b8b7f6 | 49 | // 0 1 1 1 1 1 1 1 - MESSAGE |
| quagga | 0:8e06c9b8b7f6 | 50 | |
| quagga | 0:8e06c9b8b7f6 | 51 | //if POWER_TEST 2nd byte is power |
| quagga | 0:8e06c9b8b7f6 | 52 | //if MESSAGE 2nd byte is start of message packet[1] |
| quagga | 0:8e06c9b8b7f6 | 53 | |
| quagga | 0:8e06c9b8b7f6 | 54 |