DOT_Example_16_10_2018

Dependencies:   libmDot-mbed5 ISL29011

Committer:
nguyenhoang9x5555
Date:
Tue Oct 16 08:05:27 2018 +0000
Revision:
0:6a6c127cf398
DOT_EXample_16_10_2018

Who changed what in which revision?

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