Stable version of the mDot library for mbed 5. This version of the library is suitable for deployment scenarios. See lastest commit message for version of mbed-os library that has been tested against.

Dependents:   mdot_two_way unh-hackathon-example unh-hackathon-example-raw TelitSensorToCloud ... more

Fork of libmDot-dev-mbed5-deprecated by MultiTech

The Dot library provides a LoRaWan certified stack for LoRa communication using MultiTech mDot and xDot devices. The stack is compatible with mbed 5.

The name of the repository can be used to determine which device the stack was compiled for and if it's a development or production-ready build:

A changelog for the Dot library can be found here.

The Dot library version and the version of mbed-os it was compiled against can both be found in the commit message for that revision of the Dot library. Building your application with the same version of mbed-os as what was used to build the Dot library is highly recommended!

The Dot-Examples repository demonstrates how to use the Dot library in a custom application.

The mDot and xDot platform pages have lots of platform specific information and document potential issues, gotchas, etc, and provide instructions for getting started with development. Please take a look at the platform page before starting development as they should answer many questions you will have.

FOTA

Full FOTA support is only available with mDot, xDot does not have the required external flash. xDot can use the FOTA example to dynamically join a multicast session only. After joining the multicast session the received Fragmentation packets could be handed to a host MCU for processing and at completion the firmware can be loaded into the xDot using the bootloader and y-modem. See xDot Developer Guide.

  • Add the following code to allow Fota to use the Dot instance

main.cpp

    // Initialize FOTA singleton
    Fota::getInstance(dot);
  • Add fragmentation handling the the PacketRx event

RadioEvent.h

    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) {
        mDotEvent::PacketRx(port, payload, size, rssi, snr, ctrl, slot, retries, address, dupRx);

#if ACTIVE_EXAMPLE == FOTA_EXAMPLE
        if(port == 200 || port == 201 || port == 202) {
            Fota::getInstance()->processCmd(payload, port, size);
        }
#endif
    }

A definition is needed to enable Fragmentation support on mDot and save fragments to flash. This should not be defined for xDot and will result in a compiler error.

mbed_app.json

{
    "macros": [
        "FOTA=1"
    ]
}

The FOTA implementation has a few differences from the LoRaWAN Protocol

  • Fragmentation Indexing starts at 0
  • McKEKey is 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
  • Start Time is a count-down in seconds to start of session
Committer:
Jenkins@KEILDM1.dc.multitech.prv
Date:
Thu Aug 23 14:18:55 2018 -0500
Revision:
64:64982192a2af
Parent:
26:17479e0039f6
Child:
65:acc0468b9aec
mdot-library revision 3.1.0 and mbed-os revision mbed-os-5.7.7

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Mike Fiore 16:b630e18103e5 1 #ifndef MDOT_EVENT_H
Mike Fiore 16:b630e18103e5 2 #define MDOT_EVENT_H
Mike Fiore 16:b630e18103e5 3
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 4 #include "mbed.h"
Mike Fiore 16:b630e18103e5 5 #include "mDot.h"
Mike Fiore 16:b630e18103e5 6 #include "MacEvents.h"
Mike Fiore 16:b630e18103e5 7 #include "MTSLog.h"
Mike Fiore 16:b630e18103e5 8 #include "MTSText.h"
Mike Fiore 16:b630e18103e5 9
Mike Fiore 16:b630e18103e5 10 typedef union {
Mike Fiore 16:b630e18103e5 11 uint8_t Value;
Mike Fiore 16:b630e18103e5 12 struct {
Mike Fiore 16:b630e18103e5 13 uint8_t :1;
Mike Fiore 16:b630e18103e5 14 uint8_t Tx :1;
Mike Fiore 16:b630e18103e5 15 uint8_t Rx :1;
Mike Fiore 16:b630e18103e5 16 uint8_t RxData :1;
Mike Fiore 16:b630e18103e5 17 uint8_t RxSlot :2;
Mike Fiore 16:b630e18103e5 18 uint8_t LinkCheck :1;
Mike Fiore 16:b630e18103e5 19 uint8_t JoinAccept :1;
Mike Fiore 16:b630e18103e5 20 } Bits;
Mike Fiore 16:b630e18103e5 21 } LoRaMacEventFlags;
Mike Fiore 16:b630e18103e5 22
Mike Fiore 16:b630e18103e5 23 typedef enum {
Mike Fiore 16:b630e18103e5 24 LORAMAC_EVENT_INFO_STATUS_OK = 0,
Mike Fiore 16:b630e18103e5 25 LORAMAC_EVENT_INFO_STATUS_ERROR,
Mike Fiore 16:b630e18103e5 26 LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT,
Mike Fiore 16:b630e18103e5 27 LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT,
Mike Fiore 16:b630e18103e5 28 LORAMAC_EVENT_INFO_STATUS_RX_ERROR,
Mike Fiore 16:b630e18103e5 29 LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL,
Mike Fiore 16:b630e18103e5 30 LORAMAC_EVENT_INFO_STATUS_DOWNLINK_FAIL,
Mike Fiore 16:b630e18103e5 31 LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL,
Mike Fiore 16:b630e18103e5 32 LORAMAC_EVENT_INFO_STATUS_MIC_FAIL,
Mike Fiore 16:b630e18103e5 33 } LoRaMacEventInfoStatus;
Mike Fiore 16:b630e18103e5 34
Mike Fiore 16:b630e18103e5 35 /*!
Mike Fiore 16:b630e18103e5 36 * LoRaMAC event information
Mike Fiore 16:b630e18103e5 37 */
Mike Fiore 16:b630e18103e5 38 typedef struct {
Mike Fiore 16:b630e18103e5 39 LoRaMacEventInfoStatus Status;
Mike Fiore 16:b630e18103e5 40 lora::DownlinkControl Ctrl;
Mike Fiore 16:b630e18103e5 41 bool TxAckReceived;
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 42 bool DuplicateRx;
Mike Fiore 16:b630e18103e5 43 uint8_t TxNbRetries;
Mike Fiore 16:b630e18103e5 44 uint8_t TxDatarate;
Mike Fiore 16:b630e18103e5 45 uint8_t RxPort;
Mike Fiore 16:b630e18103e5 46 uint8_t *RxBuffer;
Mike Fiore 16:b630e18103e5 47 uint8_t RxBufferSize;
Mike Fiore 16:b630e18103e5 48 int16_t RxRssi;
Mike Fiore 16:b630e18103e5 49 uint8_t RxSnr;
Mike Fiore 16:b630e18103e5 50 uint16_t Energy;
Mike Fiore 16:b630e18103e5 51 uint8_t DemodMargin;
Mike Fiore 16:b630e18103e5 52 uint8_t NbGateways;
Mike Fiore 16:b630e18103e5 53 } LoRaMacEventInfo;
Mike Fiore 16:b630e18103e5 54
Mike Fiore 16:b630e18103e5 55 class mDotEvent: public lora::MacEvents {
Mike Fiore 16:b630e18103e5 56 public:
Mike Fiore 16:b630e18103e5 57
Mike Fiore 16:b630e18103e5 58 mDotEvent()
Mike Fiore 16:b630e18103e5 59 :
Mike Fiore 16:b630e18103e5 60 LinkCheckAnsReceived(false),
Mike Fiore 16:b630e18103e5 61 DemodMargin(0),
Mike Fiore 16:b630e18103e5 62 NbGateways(0),
Mike Fiore 16:b630e18103e5 63 PacketReceived(false),
Mike Fiore 16:b630e18103e5 64 RxPort(0),
Mike Fiore 16:b630e18103e5 65 RxPayloadSize(0),
Mike Fiore 16:b630e18103e5 66 PongReceived(false),
Mike Fiore 16:b630e18103e5 67 PongRssi(0),
Mike Fiore 16:b630e18103e5 68 PongSnr(0),
Mike Fiore 16:b630e18103e5 69 AckReceived(false),
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 70 DuplicateRx(false),
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 71 TxNbRetries(0),
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 72 _sleep_cb(NULL)
Mike Fiore 16:b630e18103e5 73 {
Mike Fiore 16:b630e18103e5 74 memset(&_flags, 0, sizeof(LoRaMacEventFlags));
Mike Fiore 16:b630e18103e5 75 memset(&_info, 0, sizeof(LoRaMacEventInfo));
Mike Fiore 16:b630e18103e5 76 }
Mike Fiore 16:b630e18103e5 77
Mike Fiore 16:b630e18103e5 78 virtual ~mDotEvent() {
Mike Fiore 16:b630e18103e5 79 }
Mike Fiore 16:b630e18103e5 80
Mike Fiore 16:b630e18103e5 81 virtual void MacEvent(LoRaMacEventFlags *flags, LoRaMacEventInfo *info) {
Mike Fiore 16:b630e18103e5 82 if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) {
Mike Fiore 16:b630e18103e5 83 std::string msg = "OK";
Mike Fiore 16:b630e18103e5 84 switch (info->Status) {
Mike Fiore 16:b630e18103e5 85 case LORAMAC_EVENT_INFO_STATUS_ERROR:
Mike Fiore 16:b630e18103e5 86 msg = "ERROR";
Mike Fiore 16:b630e18103e5 87 break;
Mike Fiore 16:b630e18103e5 88 case LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT:
Mike Fiore 16:b630e18103e5 89 msg = "TX_TIMEOUT";
Mike Fiore 16:b630e18103e5 90 break;
Mike Fiore 16:b630e18103e5 91 case LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT:
Mike Fiore 16:b630e18103e5 92 msg = "RX_TIMEOUT";
Mike Fiore 16:b630e18103e5 93 break;
Mike Fiore 16:b630e18103e5 94 case LORAMAC_EVENT_INFO_STATUS_RX_ERROR:
Mike Fiore 16:b630e18103e5 95 msg = "RX_ERROR";
Mike Fiore 16:b630e18103e5 96 break;
Mike Fiore 16:b630e18103e5 97 case LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL:
Mike Fiore 16:b630e18103e5 98 msg = "JOIN_FAIL";
Mike Fiore 16:b630e18103e5 99 break;
Mike Fiore 16:b630e18103e5 100 case LORAMAC_EVENT_INFO_STATUS_DOWNLINK_FAIL:
Mike Fiore 16:b630e18103e5 101 msg = "DOWNLINK_FAIL";
Mike Fiore 16:b630e18103e5 102 break;
Mike Fiore 16:b630e18103e5 103 case LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL:
Mike Fiore 16:b630e18103e5 104 msg = "ADDRESS_FAIL";
Mike Fiore 16:b630e18103e5 105 break;
Mike Fiore 16:b630e18103e5 106 case LORAMAC_EVENT_INFO_STATUS_MIC_FAIL:
Mike Fiore 16:b630e18103e5 107 msg = "MIC_FAIL";
Mike Fiore 16:b630e18103e5 108 break;
Mike Fiore 16:b630e18103e5 109 default:
Mike Fiore 16:b630e18103e5 110 break;
Mike Fiore 16:b630e18103e5 111 }
Mike Fiore 16:b630e18103e5 112 logTrace("Event: %s", msg.c_str());
Mike Fiore 16:b630e18103e5 113
Mike Fiore 16:b630e18103e5 114 logTrace("Flags Tx: %d Rx: %d RxData: %d RxSlot: %d LinkCheck: %d JoinAccept: %d",
Mike Fiore 16:b630e18103e5 115 flags->Bits.Tx, flags->Bits.Rx, flags->Bits.RxData, flags->Bits.RxSlot, flags->Bits.LinkCheck, flags->Bits.JoinAccept);
Mike Fiore 16:b630e18103e5 116 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 16:b630e18103e5 117 info->Status, info->TxAckReceived, info->TxNbRetries, info->TxDatarate, info->RxPort, info->RxBufferSize,
Mike Fiore 16:b630e18103e5 118 info->RxRssi, info->RxSnr, info->Energy, info->DemodMargin, info->NbGateways);
Mike Fiore 16:b630e18103e5 119 }
Mike Fiore 16:b630e18103e5 120 }
Mike Fiore 16:b630e18103e5 121
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 122 virtual void TxStart() {
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 123 logDebug("mDotEvent - TxStart");
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 124
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 125 // Fire auto sleep cfg event if enabled
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 126 if (_sleep_cb)
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 127 _sleep_cb(mDot::AUTO_SLEEP_EVT_CFG);
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 128 }
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 129
Mike Fiore 16:b630e18103e5 130 virtual void TxDone(uint8_t dr) {
Mike Fiore 16:b630e18103e5 131 RxPayloadSize = 0;
Mike Fiore 16:b630e18103e5 132 LinkCheckAnsReceived = false;
Mike Fiore 16:b630e18103e5 133 PacketReceived = false;
Mike Fiore 16:b630e18103e5 134 AckReceived = false;
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 135 DuplicateRx = false;
Mike Fiore 16:b630e18103e5 136 PongReceived = false;
Jenkins@KEILDM1.dc.multitech.prv 26:17479e0039f6 137 TxNbRetries = 0;
Mike Fiore 16:b630e18103e5 138
Mike Fiore 16:b630e18103e5 139 logDebug("mDotEvent - TxDone");
Mike Fiore 16:b630e18103e5 140 memset(&_flags, 0, sizeof(LoRaMacEventFlags));
Mike Fiore 16:b630e18103e5 141 memset(&_info, 0, sizeof(LoRaMacEventInfo));
Mike Fiore 16:b630e18103e5 142
Mike Fiore 16:b630e18103e5 143 _flags.Bits.Tx = 1;
Mike Fiore 16:b630e18103e5 144 _info.TxDatarate = dr;
Mike Fiore 16:b630e18103e5 145 _info.Status = LORAMAC_EVENT_INFO_STATUS_OK;
Mike Fiore 16:b630e18103e5 146 Notify();
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 147
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 148 // If configured, we can sleep until the rx window opens
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 149 if (_sleep_cb)
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 150 _sleep_cb(mDot::AUTO_SLEEP_EVT_TXDONE);
Mike Fiore 16:b630e18103e5 151 }
Mike Fiore 16:b630e18103e5 152
Mike Fiore 16:b630e18103e5 153 void Notify() {
Mike Fiore 16:b630e18103e5 154 MacEvent(&_flags, &_info);
Mike Fiore 16:b630e18103e5 155 }
Mike Fiore 16:b630e18103e5 156
Mike Fiore 16:b630e18103e5 157 virtual void TxTimeout(void) {
Mike Fiore 16:b630e18103e5 158 logDebug("mDotEvent - TxTimeout");
Mike Fiore 16:b630e18103e5 159
Mike Fiore 16:b630e18103e5 160 _flags.Bits.Tx = 1;
Mike Fiore 16:b630e18103e5 161 _info.Status = LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT;
Mike Fiore 16:b630e18103e5 162 Notify();
Mike Fiore 16:b630e18103e5 163 }
Mike Fiore 16:b630e18103e5 164
Mike Fiore 16:b630e18103e5 165 virtual void JoinAccept(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) {
Mike Fiore 16:b630e18103e5 166 logDebug("mDotEvent - JoinAccept");
Mike Fiore 16:b630e18103e5 167
Mike Fiore 16:b630e18103e5 168 _flags.Bits.Tx = 0;
Mike Fiore 16:b630e18103e5 169 _flags.Bits.JoinAccept = 1;
Mike Fiore 16:b630e18103e5 170 _info.Status = LORAMAC_EVENT_INFO_STATUS_OK;
Mike Fiore 16:b630e18103e5 171 Notify();
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 172
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 173 if (_sleep_cb)
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 174 _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP);
Mike Fiore 16:b630e18103e5 175 }
Mike Fiore 16:b630e18103e5 176
Mike Fiore 16:b630e18103e5 177 virtual void JoinFailed(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) {
Mike Fiore 16:b630e18103e5 178 logDebug("mDotEvent - JoinFailed");
Mike Fiore 16:b630e18103e5 179
Mike Fiore 16:b630e18103e5 180 _flags.Bits.Tx = 0;
Mike Fiore 16:b630e18103e5 181 _flags.Bits.JoinAccept = 1;
Mike Fiore 16:b630e18103e5 182 _info.Status = LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL;
Mike Fiore 16:b630e18103e5 183 Notify();
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 184
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 185 if (_sleep_cb)
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 186 _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP);
Mike Fiore 16:b630e18103e5 187 }
Mike Fiore 16:b630e18103e5 188
Jenkins@KEILDM1.dc.multitech.prv 26:17479e0039f6 189 virtual void MissedAck(uint8_t retries) {
Jenkins@KEILDM1.dc.multitech.prv 26:17479e0039f6 190 logDebug("mDotEvent - MissedAck : retries %u", retries);
Jenkins@KEILDM1.dc.multitech.prv 26:17479e0039f6 191 TxNbRetries = retries;
Jenkins@KEILDM1.dc.multitech.prv 26:17479e0039f6 192 _info.TxNbRetries = retries;
Jenkins@KEILDM1.dc.multitech.prv 26:17479e0039f6 193 }
Jenkins@KEILDM1.dc.multitech.prv 26:17479e0039f6 194
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 195 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) {
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 196 logDebug("mDotEvent - PacketRx ADDR: %08x", address);
Mike Fiore 16:b630e18103e5 197 RxPort = port;
Mike Fiore 16:b630e18103e5 198 PacketReceived = true;
Mike Fiore 16:b630e18103e5 199
Mike Fiore 16:b630e18103e5 200 memcpy(RxPayload, payload, size);
Mike Fiore 16:b630e18103e5 201 RxPayloadSize = size;
Mike Fiore 16:b630e18103e5 202
Mike Fiore 16:b630e18103e5 203 if (ctrl.Bits.Ack) {
Mike Fiore 16:b630e18103e5 204 AckReceived = true;
Mike Fiore 16:b630e18103e5 205 }
Mike Fiore 16:b630e18103e5 206
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 207 DuplicateRx = dupRx;
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 208
Mike Fiore 16:b630e18103e5 209 if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) {
Mike Fiore 16:b630e18103e5 210 std::string packet = mts::Text::bin2hexString(RxPayload, size);
Mike Fiore 16:b630e18103e5 211 logTrace("Payload: %s", packet.c_str());
Mike Fiore 16:b630e18103e5 212 }
Mike Fiore 16:b630e18103e5 213
Mike Fiore 16:b630e18103e5 214 _flags.Bits.Tx = 0;
Mike Fiore 16:b630e18103e5 215 _flags.Bits.Rx = 1;
Mike Fiore 16:b630e18103e5 216 _flags.Bits.RxData = size > 0;
Mike Fiore 16:b630e18103e5 217 _flags.Bits.RxSlot = slot;
Mike Fiore 16:b630e18103e5 218 _info.RxBuffer = payload;
Mike Fiore 16:b630e18103e5 219 _info.RxBufferSize = size;
Mike Fiore 16:b630e18103e5 220 _info.RxPort = port;
Mike Fiore 16:b630e18103e5 221 _info.RxRssi = rssi;
Mike Fiore 16:b630e18103e5 222 _info.RxSnr = snr;
Mike Fiore 16:b630e18103e5 223 _info.TxAckReceived = AckReceived;
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 224 _info.DuplicateRx = DuplicateRx;
Jenkins@KEILDM1.dc.multitech.prv 26:17479e0039f6 225 _info.TxNbRetries = retries;
Mike Fiore 16:b630e18103e5 226 _info.Status = LORAMAC_EVENT_INFO_STATUS_OK;
Mike Fiore 16:b630e18103e5 227 Notify();
Mike Fiore 16:b630e18103e5 228 }
Mike Fiore 16:b630e18103e5 229
Mike Fiore 16:b630e18103e5 230 virtual void RxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, lora::DownlinkControl ctrl, uint8_t slot) {
Mike Fiore 16:b630e18103e5 231 logDebug("mDotEvent - RxDone");
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 232
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 233 if (_sleep_cb)
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 234 _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP);
Mike Fiore 16:b630e18103e5 235 }
Mike Fiore 16:b630e18103e5 236
Mike Fiore 16:b630e18103e5 237 virtual void Pong(int16_t m_rssi, int8_t m_snr, int16_t s_rssi, int8_t s_snr) {
Mike Fiore 16:b630e18103e5 238 logDebug("mDotEvent - Pong");
Mike Fiore 16:b630e18103e5 239 PongReceived = true;
Mike Fiore 16:b630e18103e5 240 PongRssi = s_rssi;
Mike Fiore 16:b630e18103e5 241 PongSnr = s_snr;
Mike Fiore 16:b630e18103e5 242 }
Mike Fiore 16:b630e18103e5 243
Mike Fiore 16:b630e18103e5 244 virtual void NetworkLinkCheck(int16_t m_rssi, int8_t m_snr, int8_t s_snr, uint8_t s_gateways) {
Mike Fiore 16:b630e18103e5 245 logDebug("mDotEvent - NetworkLinkCheck");
Mike Fiore 16:b630e18103e5 246 LinkCheckAnsReceived = true;
Mike Fiore 16:b630e18103e5 247 DemodMargin = s_snr;
Mike Fiore 16:b630e18103e5 248 NbGateways = s_gateways;
Mike Fiore 16:b630e18103e5 249
Mike Fiore 16:b630e18103e5 250 _flags.Bits.Tx = 0;
Mike Fiore 16:b630e18103e5 251 _flags.Bits.LinkCheck = 1;
Mike Fiore 16:b630e18103e5 252 _info.RxRssi = m_rssi;
Mike Fiore 16:b630e18103e5 253 _info.RxSnr = m_snr;
Mike Fiore 16:b630e18103e5 254 _info.DemodMargin = s_snr;
Mike Fiore 16:b630e18103e5 255 _info.NbGateways = s_gateways;
Mike Fiore 16:b630e18103e5 256 _info.Status = LORAMAC_EVENT_INFO_STATUS_OK;
Mike Fiore 16:b630e18103e5 257 Notify();
Mike Fiore 16:b630e18103e5 258 }
Mike Fiore 16:b630e18103e5 259
Mike Fiore 16:b630e18103e5 260 virtual void RxTimeout(uint8_t slot) {
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 261 logDebug("mDotEvent - RxTimeout on Slot %d", slot);
Mike Fiore 16:b630e18103e5 262
Mike Fiore 16:b630e18103e5 263 _flags.Bits.Tx = 0;
Mike Fiore 16:b630e18103e5 264 _flags.Bits.RxSlot = slot;
Mike Fiore 16:b630e18103e5 265 _info.Status = LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT;
Mike Fiore 16:b630e18103e5 266 Notify();
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 267
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 268 if (_sleep_cb) {
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 269 // If this is the first rx window we can sleep until the next one
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 270 if (slot == 1)
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 271 _sleep_cb(mDot::AUTO_SLEEP_EVT_RX1_TIMEOUT);
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 272 else
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 273 _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP);
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 274 }
Mike Fiore 16:b630e18103e5 275 }
Mike Fiore 16:b630e18103e5 276
Mike Fiore 16:b630e18103e5 277 virtual void RxError(uint8_t slot) {
Mike Fiore 16:b630e18103e5 278 logDebug("mDotEvent - RxError");
Mike Fiore 16:b630e18103e5 279
Mike Fiore 16:b630e18103e5 280 memset(&_flags, 0, sizeof(LoRaMacEventFlags));
Mike Fiore 16:b630e18103e5 281 memset(&_info, 0, sizeof(LoRaMacEventInfo));
Mike Fiore 16:b630e18103e5 282
Mike Fiore 16:b630e18103e5 283 _flags.Bits.RxSlot = slot;
Mike Fiore 16:b630e18103e5 284 _info.Status = LORAMAC_EVENT_INFO_STATUS_RX_ERROR;
Mike Fiore 16:b630e18103e5 285 Notify();
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 286
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 287 if (_sleep_cb)
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 288 _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP);
Mike Fiore 16:b630e18103e5 289 }
Mike Fiore 16:b630e18103e5 290
Mike Fiore 16:b630e18103e5 291 virtual uint8_t MeasureBattery(void) {
Mike Fiore 16:b630e18103e5 292 return 255;
Mike Fiore 16:b630e18103e5 293 }
Mike Fiore 16:b630e18103e5 294
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 295 void AttachSleepCallback(Callback<void(mDot::AutoSleepEvent_t)> cb) {
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 296 _sleep_cb = cb;
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 297 }
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 298
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 299 void DetachSleepCallback() {
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 300 _sleep_cb = NULL;
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 301 }
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 302
Mike Fiore 16:b630e18103e5 303 bool LinkCheckAnsReceived;
Mike Fiore 16:b630e18103e5 304 uint8_t DemodMargin;
Mike Fiore 16:b630e18103e5 305 uint8_t NbGateways;
Mike Fiore 16:b630e18103e5 306
Mike Fiore 16:b630e18103e5 307 bool PacketReceived;
Mike Fiore 16:b630e18103e5 308 uint8_t RxPort;
Mike Fiore 16:b630e18103e5 309 uint8_t RxPayload[255];
Mike Fiore 16:b630e18103e5 310 uint8_t RxPayloadSize;
Mike Fiore 16:b630e18103e5 311
Mike Fiore 16:b630e18103e5 312 bool PongReceived;
Mike Fiore 16:b630e18103e5 313 int16_t PongRssi;
Mike Fiore 16:b630e18103e5 314 int16_t PongSnr;
Mike Fiore 16:b630e18103e5 315
Mike Fiore 16:b630e18103e5 316 bool AckReceived;
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 317 bool DuplicateRx;
Mike Fiore 16:b630e18103e5 318 uint8_t TxNbRetries;
Mike Fiore 16:b630e18103e5 319
Mike Fiore 16:b630e18103e5 320 LoRaMacEventFlags& Flags() {
Mike Fiore 16:b630e18103e5 321 return _flags;
Mike Fiore 16:b630e18103e5 322 }
Mike Fiore 16:b630e18103e5 323 LoRaMacEventInfo& Info() {
Mike Fiore 16:b630e18103e5 324 return _info;
Mike Fiore 16:b630e18103e5 325 }
Mike Fiore 16:b630e18103e5 326
Mike Fiore 16:b630e18103e5 327 private:
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 328 /* Hook to inject a sleep method in between receive windows */
Jenkins@KEILDM1.dc.multitech.prv 64:64982192a2af 329 Callback<void(mDot::AutoSleepEvent_t)> _sleep_cb;
Mike Fiore 16:b630e18103e5 330
Mike Fiore 16:b630e18103e5 331 LoRaMacEventFlags _flags;
Mike Fiore 16:b630e18103e5 332 LoRaMacEventInfo _info;
Mike Fiore 16:b630e18103e5 333
Mike Fiore 16:b630e18103e5 334 //
Mike Fiore 16:b630e18103e5 335 // /*!
Mike Fiore 16:b630e18103e5 336 // * MAC layer event callback prototype.
Mike Fiore 16:b630e18103e5 337 // *
Mike Fiore 16:b630e18103e5 338 // * \param [IN] flags Bit field indicating the MAC events occurred
Mike Fiore 16:b630e18103e5 339 // * \param [IN] info Details about MAC events occurred
Mike Fiore 16:b630e18103e5 340 // */
Mike Fiore 16:b630e18103e5 341 // virtual void MacEvent(LoRaMacEventFlags *flags, LoRaMacEventInfo *info) {
Mike Fiore 16:b630e18103e5 342 // logDebug("mDotEvent");
Mike Fiore 16:b630e18103e5 343 //
Mike Fiore 16:b630e18103e5 344 // if (flags->Bits.Rx) {
Mike Fiore 16:b630e18103e5 345 // logDebug("Rx");
Mike Fiore 16:b630e18103e5 346 //
Mike Fiore 16:b630e18103e5 347 // // Event Object must delete RxBuffer
Mike Fiore 16:b630e18103e5 348 // delete[] info->RxBuffer;
Mike Fiore 16:b630e18103e5 349 // }
Mike Fiore 16:b630e18103e5 350 // }
Mike Fiore 16:b630e18103e5 351 //
Mike Fiore 16:b630e18103e5 352
Mike Fiore 16:b630e18103e5 353 };
Mike Fiore 16:b630e18103e5 354
Mike Fiore 16:b630e18103e5 355 #endif // __MDOT_EVENT_H__