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