Programa WARIIOT AIDI421 clase C.

Dependencies:   libxDot-mbed5

Fork of mDot_claseC by Damez

Committer:
gabrielap
Date:
Wed Jun 03 15:25:22 2020 +0000
Revision:
0:293d4729cd57
Programa base para proyecto con mDot en clase C.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gabrielap 0:293d4729cd57 1 #ifndef __RADIO_EVENT_H__
gabrielap 0:293d4729cd57 2 #define __RADIO_EVENT_H__
gabrielap 0:293d4729cd57 3
gabrielap 0:293d4729cd57 4 #include "dot_util.h"
gabrielap 0:293d4729cd57 5 #include "mDotEvent.h"
gabrielap 0:293d4729cd57 6 #include "Fota.h"
gabrielap 0:293d4729cd57 7
gabrielap 0:293d4729cd57 8 class RadioEvent : public mDotEvent
gabrielap 0:293d4729cd57 9 {
gabrielap 0:293d4729cd57 10
gabrielap 0:293d4729cd57 11 public:
gabrielap 0:293d4729cd57 12 RadioEvent() {}
gabrielap 0:293d4729cd57 13
gabrielap 0:293d4729cd57 14 virtual ~RadioEvent() {}
gabrielap 0:293d4729cd57 15
gabrielap 0:293d4729cd57 16 virtual void PacketRx(uint8_t port, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, lora::DownlinkControl ctrl, uint8_t slot, uint8_t retries, uint32_t address, bool dupRx) {
gabrielap 0:293d4729cd57 17 mDotEvent::PacketRx(port, payload, size, rssi, snr, ctrl, slot, retries, address, dupRx);
gabrielap 0:293d4729cd57 18
gabrielap 0:293d4729cd57 19 #if ACTIVE_EXAMPLE == FOTA_EXAMPLE
gabrielap 0:293d4729cd57 20 if(port == 200 || port == 201 || port == 202) {
gabrielap 0:293d4729cd57 21 Fota::getInstance()->processCmd(payload, port, size);
gabrielap 0:293d4729cd57 22 }
gabrielap 0:293d4729cd57 23 #endif
gabrielap 0:293d4729cd57 24 }
gabrielap 0:293d4729cd57 25
gabrielap 0:293d4729cd57 26 /*!
gabrielap 0:293d4729cd57 27 * MAC layer event callback prototype.
gabrielap 0:293d4729cd57 28 *
gabrielap 0:293d4729cd57 29 * \param [IN] flags Bit field indicating the MAC events occurred
gabrielap 0:293d4729cd57 30 * \param [IN] info Details about MAC events occurred
gabrielap 0:293d4729cd57 31 */
gabrielap 0:293d4729cd57 32 virtual void MacEvent(LoRaMacEventFlags* flags, LoRaMacEventInfo* info) {
gabrielap 0:293d4729cd57 33
gabrielap 0:293d4729cd57 34 if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) {
gabrielap 0:293d4729cd57 35 std::string msg = "OK";
gabrielap 0:293d4729cd57 36 switch (info->Status) {
gabrielap 0:293d4729cd57 37 case LORAMAC_EVENT_INFO_STATUS_ERROR:
gabrielap 0:293d4729cd57 38 msg = "ERROR";
gabrielap 0:293d4729cd57 39 break;
gabrielap 0:293d4729cd57 40 case LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT:
gabrielap 0:293d4729cd57 41 msg = "TX_TIMEOUT";
gabrielap 0:293d4729cd57 42 break;
gabrielap 0:293d4729cd57 43 case LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT:
gabrielap 0:293d4729cd57 44 msg = "RX_TIMEOUT";
gabrielap 0:293d4729cd57 45 break;
gabrielap 0:293d4729cd57 46 case LORAMAC_EVENT_INFO_STATUS_RX_ERROR:
gabrielap 0:293d4729cd57 47 msg = "RX_ERROR";
gabrielap 0:293d4729cd57 48 break;
gabrielap 0:293d4729cd57 49 case LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL:
gabrielap 0:293d4729cd57 50 msg = "JOIN_FAIL";
gabrielap 0:293d4729cd57 51 break;
gabrielap 0:293d4729cd57 52 case LORAMAC_EVENT_INFO_STATUS_DOWNLINK_FAIL:
gabrielap 0:293d4729cd57 53 msg = "DOWNLINK_FAIL";
gabrielap 0:293d4729cd57 54 break;
gabrielap 0:293d4729cd57 55 case LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL:
gabrielap 0:293d4729cd57 56 msg = "ADDRESS_FAIL";
gabrielap 0:293d4729cd57 57 break;
gabrielap 0:293d4729cd57 58 case LORAMAC_EVENT_INFO_STATUS_MIC_FAIL:
gabrielap 0:293d4729cd57 59 msg = "MIC_FAIL";
gabrielap 0:293d4729cd57 60 break;
gabrielap 0:293d4729cd57 61 default:
gabrielap 0:293d4729cd57 62 break;
gabrielap 0:293d4729cd57 63 }
gabrielap 0:293d4729cd57 64 logTrace("Event: %s", msg.c_str());
gabrielap 0:293d4729cd57 65
gabrielap 0:293d4729cd57 66 logTrace("Flags Tx: %d Rx: %d RxData: %d RxSlot: %d LinkCheck: %d JoinAccept: %d",
gabrielap 0:293d4729cd57 67 flags->Bits.Tx, flags->Bits.Rx, flags->Bits.RxData, flags->Bits.RxSlot, flags->Bits.LinkCheck, flags->Bits.JoinAccept);
gabrielap 0:293d4729cd57 68 logTrace("Info: Status: %d ACK: %d Retries: %d TxDR: %d RxPort: %d RxSize: %d RSSI: %d SNR: %d Energy: %d Margin: %d Gateways: %d",
gabrielap 0:293d4729cd57 69 info->Status, info->TxAckReceived, info->TxNbRetries, info->TxDatarate, info->RxPort, info->RxBufferSize,
gabrielap 0:293d4729cd57 70 info->RxRssi, info->RxSnr, info->Energy, info->DemodMargin, info->NbGateways);
gabrielap 0:293d4729cd57 71 }
gabrielap 0:293d4729cd57 72
gabrielap 0:293d4729cd57 73 if (flags->Bits.Rx) {
gabrielap 0:293d4729cd57 74
gabrielap 0:293d4729cd57 75 logDebug("Rx %d bytes", info->RxBufferSize);
gabrielap 0:293d4729cd57 76 logInfo("Rx %d bytes", info->RxBufferSize);
gabrielap 0:293d4729cd57 77 if (info->RxBufferSize > 0) {
gabrielap 0:293d4729cd57 78 //logInfo("Rx data: %S\r\n", mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str());
gabrielap 0:293d4729cd57 79 //#if ACTIVE_EXAMPLE != FOTA_EXAMPLE
gabrielap 0:293d4729cd57 80 // print RX data as string and hexadecimal
gabrielap 0:293d4729cd57 81 std::string rx((const char*)info->RxBuffer, info->RxBufferSize);
gabrielap 0:293d4729cd57 82 //printf("Rx data: %s [%s]\r\n", rx.c_str(), mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str());
gabrielap 0:293d4729cd57 83 logInfo("Rx data: %s [%s]\r\n", rx.c_str(), mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str());
gabrielap 0:293d4729cd57 84 //#endif
gabrielap 0:293d4729cd57 85 }
gabrielap 0:293d4729cd57 86 }
gabrielap 0:293d4729cd57 87 }
gabrielap 0:293d4729cd57 88 };
gabrielap 0:293d4729cd57 89
gabrielap 0:293d4729cd57 90 #endif
gabrielap 0:293d4729cd57 91
gabrielap 0:293d4729cd57 92