
FF1705 support added
Dependencies: libxDot-dev-mbed5-deprecated ISL29011
Fork of Dot-Examples by
Dot-Examples rev. 31:7ec180e84cb6 have been tested with xdot-library 3.0.0-19-gb6c0ba2 and mbed-os-5.6.2
Revision 14:19fae4509473, committed 2016-10-11
- Comitter:
- Mike Fiore
- Date:
- Tue Oct 11 13:53:32 2016 -0500
- Parent:
- 13:f1d1ef71b3c4
- Child:
- 15:364df461110f
- Commit message:
- use custom event handler in all examples so RX data is displayed when received
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/inc/RadioEvent.h Tue Oct 11 13:53:32 2016 -0500 @@ -0,0 +1,78 @@ +#ifndef __RADIO_EVENT_H__ +#define __RADIO_EVENT_H__ + +#include "dot_util.h" +#include "mDotEvent.h" + +class RadioEvent : public mDotEvent +{ + +public: + RadioEvent() {} + + virtual ~RadioEvent() {} + + /*! + * MAC layer event callback prototype. + * + * \param [IN] flags Bit field indicating the MAC events occurred + * \param [IN] info Details about MAC events occurred + */ + virtual void MacEvent(LoRaMacEventFlags* flags, LoRaMacEventInfo* info) { + + if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) { + std::string msg = "OK"; + switch (info->Status) { + case LORAMAC_EVENT_INFO_STATUS_ERROR: + msg = "ERROR"; + break; + case LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT: + msg = "TX_TIMEOUT"; + break; + case LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT: + msg = "RX_TIMEOUT"; + break; + case LORAMAC_EVENT_INFO_STATUS_RX_ERROR: + msg = "RX_ERROR"; + break; + case LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL: + msg = "JOIN_FAIL"; + break; + case LORAMAC_EVENT_INFO_STATUS_DOWNLINK_FAIL: + msg = "DOWNLINK_FAIL"; + break; + case LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL: + msg = "ADDRESS_FAIL"; + break; + case LORAMAC_EVENT_INFO_STATUS_MIC_FAIL: + msg = "MIC_FAIL"; + break; + default: + break; + } + logTrace("Event: %s", msg.c_str()); + + logTrace("Flags Tx: %d Rx: %d RxData: %d RxSlot: %d LinkCheck: %d JoinAccept: %d", + flags->Bits.Tx, flags->Bits.Rx, flags->Bits.RxData, flags->Bits.RxSlot, flags->Bits.LinkCheck, flags->Bits.JoinAccept); + logTrace("Info: Status: %d ACK: %d Retries: %d TxDR: %d RxPort: %d RxSize: %d RSSI: %d SNR: %d Energy: %d Margin: %d Gateways: %d", + info->Status, info->TxAckReceived, info->TxNbRetries, info->TxDatarate, info->RxPort, info->RxBufferSize, + info->RxRssi, info->RxSnr, info->Energy, info->DemodMargin, info->NbGateways); + } + + if (flags->Bits.Rx) { + + logDebug("Rx %d bytes", info->RxBufferSize); + if (info->RxBufferSize > 0) { + // print RX data as hexadecimal + //printf("Rx data: %s\r\n", mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str()); + + // print RX data as string + std::string rx((const char*)info->RxBuffer, info->RxBufferSize); + printf("Rx data: %s\r\n", rx.c_str()); + } + } + } +}; + +#endif +
--- a/examples/src/auto_ota_example.cpp Tue Oct 11 13:29:32 2016 -0500 +++ b/examples/src/auto_ota_example.cpp Tue Oct 11 13:53:32 2016 -0500 @@ -1,4 +1,5 @@ #include "dot_util.h" +#include "RadioEvent.h" #if ACTIVE_EXAMPLE == AUTO_OTA_EXAMPLE @@ -35,12 +36,18 @@ #endif int main() { + // Custom event handler for automatically displaying RX data + RadioEvent events; + pc.baud(115200); mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); dot = mDot::getInstance(); + // attach the custom events handler + dot->setEvents(&events); + if (!dot->getStandbyFlag()) { // start from a well-known state logInfo("defaulting Dot configuration");
--- a/examples/src/class_c_example.cpp Tue Oct 11 13:29:32 2016 -0500 +++ b/examples/src/class_c_example.cpp Tue Oct 11 13:53:32 2016 -0500 @@ -1,5 +1,5 @@ #include "dot_util.h" -#include "mDotEvent.h" +#include "RadioEvent.h" #if ACTIVE_EXAMPLE == CLASS_C_EXAMPLE @@ -29,81 +29,8 @@ AnalogIn lux(XBEE_AD0); #endif -// Custom event handler for receiving Class C packets -class RadioEvent : public mDotEvent -{ - -public: - RadioEvent() {} - - virtual ~RadioEvent() {} - - /*! - * MAC layer event callback prototype. - * - * \param [IN] flags Bit field indicating the MAC events occurred - * \param [IN] info Details about MAC events occurred - */ - virtual void MacEvent(LoRaMacEventFlags* flags, LoRaMacEventInfo* info) { - - if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) { - std::string msg = "OK"; - switch (info->Status) { - case LORAMAC_EVENT_INFO_STATUS_ERROR: - msg = "ERROR"; - break; - case LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT: - msg = "TX_TIMEOUT"; - break; - case LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT: - msg = "RX_TIMEOUT"; - break; - case LORAMAC_EVENT_INFO_STATUS_RX_ERROR: - msg = "RX_ERROR"; - break; - case LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL: - msg = "JOIN_FAIL"; - break; - case LORAMAC_EVENT_INFO_STATUS_DOWNLINK_FAIL: - msg = "DOWNLINK_FAIL"; - break; - case LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL: - msg = "ADDRESS_FAIL"; - break; - case LORAMAC_EVENT_INFO_STATUS_MIC_FAIL: - msg = "MIC_FAIL"; - break; - default: - break; - } - logTrace("Event: %s", msg.c_str()); - - logTrace("Flags Tx: %d Rx: %d RxData: %d RxSlot: %d LinkCheck: %d JoinAccept: %d", - flags->Bits.Tx, flags->Bits.Rx, flags->Bits.RxData, flags->Bits.RxSlot, flags->Bits.LinkCheck, flags->Bits.JoinAccept); - logTrace("Info: Status: %d ACK: %d Retries: %d TxDR: %d RxPort: %d RxSize: %d RSSI: %d SNR: %d Energy: %d Margin: %d Gateways: %d", - info->Status, info->TxAckReceived, info->TxNbRetries, info->TxDatarate, info->RxPort, info->RxBufferSize, - info->RxRssi, info->RxSnr, info->Energy, info->DemodMargin, info->NbGateways); - } - - if (flags->Bits.Rx) { - - logDebug("Rx %d bytes", info->RxBufferSize); - if (info->RxBufferSize > 0) { - // print RX data as hexadecimal - //printf("Rx data: %s\r\n", mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str()); - - // print RX data as string - pc.printf("Rx data: "); - for (int i = 0; i < info->RxBufferSize; i++) { - pc.putc(info->RxBuffer[i]); - } - pc.printf("\r\n"); - } - } - } -}; - int main() { + // Custom event handler for automatically displaying RX data RadioEvent events; pc.baud(115200);
--- a/examples/src/manual_example.cpp Tue Oct 11 13:29:32 2016 -0500 +++ b/examples/src/manual_example.cpp Tue Oct 11 13:53:32 2016 -0500 @@ -1,4 +1,5 @@ #include "dot_util.h" +#include "RadioEvent.h" #if ACTIVE_EXAMPLE == MANUAL_EXAMPLE @@ -32,12 +33,18 @@ #endif int main() { + // Custom event handler for automatically displaying RX data + RadioEvent events; + pc.baud(115200); mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); dot = mDot::getInstance(); + // attach the custom events handler + dot->setEvents(&events); + if (!dot->getStandbyFlag()) { // start from a well-known state logInfo("defaulting Dot configuration");
--- a/examples/src/ota_example.cpp Tue Oct 11 13:29:32 2016 -0500 +++ b/examples/src/ota_example.cpp Tue Oct 11 13:53:32 2016 -0500 @@ -1,4 +1,5 @@ #include "dot_util.h" +#include "RadioEvent.h" #if ACTIVE_EXAMPLE == OTA_EXAMPLE @@ -35,12 +36,18 @@ #endif int main() { + // Custom event handler for automatically displaying RX data + RadioEvent events; + pc.baud(115200); mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); dot = mDot::getInstance(); + // attach the custom events handler + dot->setEvents(&events); + if (!dot->getStandbyFlag()) { // start from a well-known state logInfo("defaulting Dot configuration");
--- a/examples/src/peer_to_peer_example.cpp Tue Oct 11 13:29:32 2016 -0500 +++ b/examples/src/peer_to_peer_example.cpp Tue Oct 11 13:53:32 2016 -0500 @@ -1,5 +1,5 @@ #include "dot_util.h" -#include "mDotEvent.h" +#include "RadioEvent.h" #if ACTIVE_EXAMPLE == PEER_TO_PEER_EXAMPLE @@ -22,83 +22,8 @@ AnalogIn lux(XBEE_AD0); #endif -// Custom event handler for receiving Class C packets -class RadioEvent : public mDotEvent -{ - -public: - RadioEvent() {} - - virtual ~RadioEvent() {} - - /*! - * MAC layer event callback prototype. - * - * \param [IN] flags Bit field indicating the MAC events occurred - * \param [IN] info Details about MAC events occurred - */ - virtual void MacEvent(LoRaMacEventFlags* flags, LoRaMacEventInfo* info) { - - if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) { - std::string msg = "OK"; - switch (info->Status) { - case LORAMAC_EVENT_INFO_STATUS_ERROR: - msg = "ERROR"; - break; - case LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT: - msg = "TX_TIMEOUT"; - break; - case LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT: - msg = "RX_TIMEOUT"; - break; - case LORAMAC_EVENT_INFO_STATUS_RX_ERROR: - msg = "RX_ERROR"; - break; - case LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL: - msg = "JOIN_FAIL"; - break; - case LORAMAC_EVENT_INFO_STATUS_DOWNLINK_FAIL: - msg = "DOWNLINK_FAIL"; - break; - case LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL: - msg = "ADDRESS_FAIL"; - break; - case LORAMAC_EVENT_INFO_STATUS_MIC_FAIL: - msg = "MIC_FAIL"; - break; - default: - break; - } - logTrace("Event: %s", msg.c_str()); - - logTrace("Flags Tx: %d Rx: %d RxData: %d RxSlot: %d LinkCheck: %d JoinAccept: %d", - flags->Bits.Tx, flags->Bits.Rx, flags->Bits.RxData, flags->Bits.RxSlot, flags->Bits.LinkCheck, flags->Bits.JoinAccept); - logTrace("Info: Status: %d ACK: %d Retries: %d TxDR: %d RxPort: %d RxSize: %d RSSI: %d SNR: %d Energy: %d Margin: %d Gateways: %d", - info->Status, info->TxAckReceived, info->TxNbRetries, info->TxDatarate, info->RxPort, info->RxBufferSize, - info->RxRssi, info->RxSnr, info->Energy, info->DemodMargin, info->NbGateways); - } - - if (flags->Bits.Rx) { - - logDebug("Rx %d bytes", info->RxBufferSize); - if (info->RxBufferSize > 0) { - // print RX data as hexadecimal - printf("Rx data: %s\r\n", mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str()); - - // print RX data as string - /* - pc.printf("Rx data: "); - for (int i = 0; i < info->RxBufferSize; i++) { - pc.putc(info->RxBuffer[i]); - } - pc.printf("\r\n"); - */ - } - } - } -}; - int main() { + // Custom event handler for automatically displaying RX data RadioEvent events; uint32_t tx_frequency; uint8_t tx_datarate;