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