Using the mDot to receive data.
Dependencies: libmDot-dev-mbed5-deprecated ISL29011
Fork of mdot-examples by
examples/inc/RadioEvent.h@4:ee3739e513a9, 2018-04-14 (annotated)
- Committer:
- SDesign2018
- Date:
- Sat Apr 14 17:47:26 2018 +0000
- Revision:
- 4:ee3739e513a9
- Parent:
- 0:f3d9c16b08d7
Parsing data packet is working fine, need to add the rest of the GPS location and dates.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Maciej Pijanowski |
0:f3d9c16b08d7 | 1 | #ifndef __RADIO_EVENT_H__ |
Maciej Pijanowski |
0:f3d9c16b08d7 | 2 | #define __RADIO_EVENT_H__ |
Maciej Pijanowski |
0:f3d9c16b08d7 | 3 | |
Maciej Pijanowski |
0:f3d9c16b08d7 | 4 | #include "dot_util.h" |
Maciej Pijanowski |
0:f3d9c16b08d7 | 5 | #include "mDotEvent.h" |
Maciej Pijanowski |
0:f3d9c16b08d7 | 6 | |
Maciej Pijanowski |
0:f3d9c16b08d7 | 7 | class RadioEvent : public mDotEvent |
Maciej Pijanowski |
0:f3d9c16b08d7 | 8 | { |
Maciej Pijanowski |
0:f3d9c16b08d7 | 9 | |
Maciej Pijanowski |
0:f3d9c16b08d7 | 10 | public: |
Maciej Pijanowski |
0:f3d9c16b08d7 | 11 | RadioEvent() {} |
Maciej Pijanowski |
0:f3d9c16b08d7 | 12 | |
Maciej Pijanowski |
0:f3d9c16b08d7 | 13 | virtual ~RadioEvent() {} |
Maciej Pijanowski |
0:f3d9c16b08d7 | 14 | |
Maciej Pijanowski |
0:f3d9c16b08d7 | 15 | /*! |
Maciej Pijanowski |
0:f3d9c16b08d7 | 16 | * MAC layer event callback prototype. |
Maciej Pijanowski |
0:f3d9c16b08d7 | 17 | * |
Maciej Pijanowski |
0:f3d9c16b08d7 | 18 | * \param [IN] flags Bit field indicating the MAC events occurred |
Maciej Pijanowski |
0:f3d9c16b08d7 | 19 | * \param [IN] info Details about MAC events occurred |
Maciej Pijanowski |
0:f3d9c16b08d7 | 20 | */ |
Maciej Pijanowski |
0:f3d9c16b08d7 | 21 | virtual void MacEvent(LoRaMacEventFlags* flags, LoRaMacEventInfo* info) { |
Maciej Pijanowski |
0:f3d9c16b08d7 | 22 | |
Maciej Pijanowski |
0:f3d9c16b08d7 | 23 | if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) { |
Maciej Pijanowski |
0:f3d9c16b08d7 | 24 | std::string msg = "OK"; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 25 | switch (info->Status) { |
Maciej Pijanowski |
0:f3d9c16b08d7 | 26 | case LORAMAC_EVENT_INFO_STATUS_ERROR: |
Maciej Pijanowski |
0:f3d9c16b08d7 | 27 | msg = "ERROR"; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 28 | break; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 29 | case LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT: |
Maciej Pijanowski |
0:f3d9c16b08d7 | 30 | msg = "TX_TIMEOUT"; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 31 | break; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 32 | case LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT: |
Maciej Pijanowski |
0:f3d9c16b08d7 | 33 | msg = "RX_TIMEOUT"; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 34 | break; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 35 | case LORAMAC_EVENT_INFO_STATUS_RX_ERROR: |
Maciej Pijanowski |
0:f3d9c16b08d7 | 36 | msg = "RX_ERROR"; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 37 | break; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 38 | case LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL: |
Maciej Pijanowski |
0:f3d9c16b08d7 | 39 | msg = "JOIN_FAIL"; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 40 | break; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 41 | case LORAMAC_EVENT_INFO_STATUS_DOWNLINK_FAIL: |
Maciej Pijanowski |
0:f3d9c16b08d7 | 42 | msg = "DOWNLINK_FAIL"; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 43 | break; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 44 | case LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL: |
Maciej Pijanowski |
0:f3d9c16b08d7 | 45 | msg = "ADDRESS_FAIL"; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 46 | break; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 47 | case LORAMAC_EVENT_INFO_STATUS_MIC_FAIL: |
Maciej Pijanowski |
0:f3d9c16b08d7 | 48 | msg = "MIC_FAIL"; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 49 | break; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 50 | default: |
Maciej Pijanowski |
0:f3d9c16b08d7 | 51 | break; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 52 | } |
Maciej Pijanowski |
0:f3d9c16b08d7 | 53 | logTrace("Event: %s", msg.c_str()); |
Maciej Pijanowski |
0:f3d9c16b08d7 | 54 | |
Maciej Pijanowski |
0:f3d9c16b08d7 | 55 | logTrace("Flags Tx: %d Rx: %d RxData: %d RxSlot: %d LinkCheck: %d JoinAccept: %d", |
Maciej Pijanowski |
0:f3d9c16b08d7 | 56 | flags->Bits.Tx, flags->Bits.Rx, flags->Bits.RxData, flags->Bits.RxSlot, flags->Bits.LinkCheck, flags->Bits.JoinAccept); |
Maciej Pijanowski |
0:f3d9c16b08d7 | 57 | logTrace("Info: Status: %d ACK: %d Retries: %d TxDR: %d RxPort: %d RxSize: %d RSSI: %d SNR: %d Energy: %d Margin: %d Gateways: %d", |
Maciej Pijanowski |
0:f3d9c16b08d7 | 58 | info->Status, info->TxAckReceived, info->TxNbRetries, info->TxDatarate, info->RxPort, info->RxBufferSize, |
Maciej Pijanowski |
0:f3d9c16b08d7 | 59 | info->RxRssi, info->RxSnr, info->Energy, info->DemodMargin, info->NbGateways); |
Maciej Pijanowski |
0:f3d9c16b08d7 | 60 | } |
Maciej Pijanowski |
0:f3d9c16b08d7 | 61 | |
Maciej Pijanowski |
0:f3d9c16b08d7 | 62 | if (flags->Bits.Rx) { |
Maciej Pijanowski |
0:f3d9c16b08d7 | 63 | |
Maciej Pijanowski |
0:f3d9c16b08d7 | 64 | logDebug("Rx %d bytes", info->RxBufferSize); |
Maciej Pijanowski |
0:f3d9c16b08d7 | 65 | if (info->RxBufferSize > 0) { |
Maciej Pijanowski |
0:f3d9c16b08d7 | 66 | // print RX data as string and hexadecimal |
Maciej Pijanowski |
0:f3d9c16b08d7 | 67 | std::string rx((const char*)info->RxBuffer, info->RxBufferSize); |
Maciej Pijanowski |
0:f3d9c16b08d7 | 68 | printf("Rx data: %s [%s]\r\n", rx.c_str(), mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str()); |
Maciej Pijanowski |
0:f3d9c16b08d7 | 69 | } |
Maciej Pijanowski |
0:f3d9c16b08d7 | 70 | } |
Maciej Pijanowski |
0:f3d9c16b08d7 | 71 | } |
Maciej Pijanowski |
0:f3d9c16b08d7 | 72 | }; |
Maciej Pijanowski |
0:f3d9c16b08d7 | 73 | |
Maciej Pijanowski |
0:f3d9c16b08d7 | 74 | #endif |
Maciej Pijanowski |
0:f3d9c16b08d7 | 75 |