![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Fork to see if I can get working
Dependencies: BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated
Fork of xDotBridge_update_test20180823 by
examples/inc/RadioEvent.h@14:19fae4509473, 2016-10-11 (annotated)
- Committer:
- Mike Fiore
- Date:
- Tue Oct 11 13:53:32 2016 -0500
- Revision:
- 14:19fae4509473
use custom event handler in all examples so RX data is displayed when received
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 |
14:19fae4509473 | 66 | // print RX data as hexadecimal |
Mike Fiore |
14:19fae4509473 | 67 | //printf("Rx data: %s\r\n", mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str()); |
Mike Fiore |
14:19fae4509473 | 68 | |
Mike Fiore |
14:19fae4509473 | 69 | // print RX data as string |
Mike Fiore |
14:19fae4509473 | 70 | std::string rx((const char*)info->RxBuffer, info->RxBufferSize); |
Mike Fiore |
14:19fae4509473 | 71 | printf("Rx data: %s\r\n", rx.c_str()); |
Mike Fiore |
14:19fae4509473 | 72 | } |
Mike Fiore |
14:19fae4509473 | 73 | } |
Mike Fiore |
14:19fae4509473 | 74 | } |
Mike Fiore |
14:19fae4509473 | 75 | }; |
Mike Fiore |
14:19fae4509473 | 76 | |
Mike Fiore |
14:19fae4509473 | 77 | #endif |
Mike Fiore |
14:19fae4509473 | 78 |