mDot project for Multitech and Explora worhshop

Dependencies:   mDot_X_NUCLEO_IKS01A1 libmDot-dev-mbed5-deprecated

Fork of mDot-IKS01A1 by Peter Ferland

Committer:
MDR
Date:
Mon Jun 26 17:22:52 2017 +0000
Revision:
12:3466445b1ac6
Parent:
0:9e88a9018fc0
Add support to connect to Explora server

Who changed what in which revision?

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