34
Dependencies: BSP libNDEF libxDot-mbed5 ST25DV
examples/inc/RadioEvent.h@0:b15aed49e54b, 2017-09-30 (annotated)
- Committer:
- umickelsen
- Date:
- Sat Sep 30 22:01:56 2017 +0000
- Revision:
- 0:b15aed49e54b
Importacion inicial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
umickelsen | 0:b15aed49e54b | 1 | #ifndef __RADIO_EVENT_H__ |
umickelsen | 0:b15aed49e54b | 2 | #define __RADIO_EVENT_H__ |
umickelsen | 0:b15aed49e54b | 3 | |
umickelsen | 0:b15aed49e54b | 4 | #include "dot_util.h" |
umickelsen | 0:b15aed49e54b | 5 | #include "mDotEvent.h" |
umickelsen | 0:b15aed49e54b | 6 | |
umickelsen | 0:b15aed49e54b | 7 | class RadioEvent : public mDotEvent |
umickelsen | 0:b15aed49e54b | 8 | { |
umickelsen | 0:b15aed49e54b | 9 | |
umickelsen | 0:b15aed49e54b | 10 | public: |
umickelsen | 0:b15aed49e54b | 11 | RadioEvent() {} |
umickelsen | 0:b15aed49e54b | 12 | |
umickelsen | 0:b15aed49e54b | 13 | virtual ~RadioEvent() {} |
umickelsen | 0:b15aed49e54b | 14 | |
umickelsen | 0:b15aed49e54b | 15 | /*! |
umickelsen | 0:b15aed49e54b | 16 | * MAC layer event callback prototype. |
umickelsen | 0:b15aed49e54b | 17 | * |
umickelsen | 0:b15aed49e54b | 18 | * \param [IN] flags Bit field indicating the MAC events occurred |
umickelsen | 0:b15aed49e54b | 19 | * \param [IN] info Details about MAC events occurred |
umickelsen | 0:b15aed49e54b | 20 | */ |
umickelsen | 0:b15aed49e54b | 21 | virtual void MacEvent(LoRaMacEventFlags* flags, LoRaMacEventInfo* info) { |
umickelsen | 0:b15aed49e54b | 22 | |
umickelsen | 0:b15aed49e54b | 23 | if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) { |
umickelsen | 0:b15aed49e54b | 24 | std::string msg = "OK"; |
umickelsen | 0:b15aed49e54b | 25 | switch (info->Status) { |
umickelsen | 0:b15aed49e54b | 26 | case LORAMAC_EVENT_INFO_STATUS_ERROR: |
umickelsen | 0:b15aed49e54b | 27 | msg = "ERROR"; |
umickelsen | 0:b15aed49e54b | 28 | break; |
umickelsen | 0:b15aed49e54b | 29 | case LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT: |
umickelsen | 0:b15aed49e54b | 30 | msg = "TX_TIMEOUT"; |
umickelsen | 0:b15aed49e54b | 31 | break; |
umickelsen | 0:b15aed49e54b | 32 | case LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT: |
umickelsen | 0:b15aed49e54b | 33 | msg = "RX_TIMEOUT"; |
umickelsen | 0:b15aed49e54b | 34 | break; |
umickelsen | 0:b15aed49e54b | 35 | case LORAMAC_EVENT_INFO_STATUS_RX_ERROR: |
umickelsen | 0:b15aed49e54b | 36 | msg = "RX_ERROR"; |
umickelsen | 0:b15aed49e54b | 37 | break; |
umickelsen | 0:b15aed49e54b | 38 | case LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL: |
umickelsen | 0:b15aed49e54b | 39 | msg = "JOIN_FAIL"; |
umickelsen | 0:b15aed49e54b | 40 | break; |
umickelsen | 0:b15aed49e54b | 41 | case LORAMAC_EVENT_INFO_STATUS_DOWNLINK_FAIL: |
umickelsen | 0:b15aed49e54b | 42 | msg = "DOWNLINK_FAIL"; |
umickelsen | 0:b15aed49e54b | 43 | break; |
umickelsen | 0:b15aed49e54b | 44 | case LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL: |
umickelsen | 0:b15aed49e54b | 45 | msg = "ADDRESS_FAIL"; |
umickelsen | 0:b15aed49e54b | 46 | break; |
umickelsen | 0:b15aed49e54b | 47 | case LORAMAC_EVENT_INFO_STATUS_MIC_FAIL: |
umickelsen | 0:b15aed49e54b | 48 | msg = "MIC_FAIL"; |
umickelsen | 0:b15aed49e54b | 49 | break; |
umickelsen | 0:b15aed49e54b | 50 | default: |
umickelsen | 0:b15aed49e54b | 51 | break; |
umickelsen | 0:b15aed49e54b | 52 | } |
umickelsen | 0:b15aed49e54b | 53 | logTrace("Event: %s", msg.c_str()); |
umickelsen | 0:b15aed49e54b | 54 | |
umickelsen | 0:b15aed49e54b | 55 | logTrace("Flags Tx: %d Rx: %d RxData: %d RxSlot: %d LinkCheck: %d JoinAccept: %d", |
umickelsen | 0:b15aed49e54b | 56 | flags->Bits.Tx, flags->Bits.Rx, flags->Bits.RxData, flags->Bits.RxSlot, flags->Bits.LinkCheck, flags->Bits.JoinAccept); |
umickelsen | 0:b15aed49e54b | 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", |
umickelsen | 0:b15aed49e54b | 58 | info->Status, info->TxAckReceived, info->TxNbRetries, info->TxDatarate, info->RxPort, info->RxBufferSize, |
umickelsen | 0:b15aed49e54b | 59 | info->RxRssi, info->RxSnr, info->Energy, info->DemodMargin, info->NbGateways); |
umickelsen | 0:b15aed49e54b | 60 | } |
umickelsen | 0:b15aed49e54b | 61 | |
umickelsen | 0:b15aed49e54b | 62 | if (flags->Bits.Rx) { |
umickelsen | 0:b15aed49e54b | 63 | |
umickelsen | 0:b15aed49e54b | 64 | logDebug("Rx %d bytes", info->RxBufferSize); |
umickelsen | 0:b15aed49e54b | 65 | if (info->RxBufferSize > 0) { |
umickelsen | 0:b15aed49e54b | 66 | // print RX data as string and hexadecimal |
umickelsen | 0:b15aed49e54b | 67 | std::string rx((const char*)info->RxBuffer, info->RxBufferSize); |
umickelsen | 0:b15aed49e54b | 68 | printf("Rx data: %s [%s]\r\n", rx.c_str(), mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str()); |
umickelsen | 0:b15aed49e54b | 69 | } |
umickelsen | 0:b15aed49e54b | 70 | } |
umickelsen | 0:b15aed49e54b | 71 | } |
umickelsen | 0:b15aed49e54b | 72 | }; |
umickelsen | 0:b15aed49e54b | 73 | |
umickelsen | 0:b15aed49e54b | 74 | #endif |
umickelsen | 0:b15aed49e54b | 75 |