Bleeding edge development version of the mDot library for mbed 5. This version of the library is not guaranteed to be stable or well tested and should not be used in production or deployment scenarios.
Dependents: mDot-IKS01A1 mDot-IKS01A1 mDot-Examples mDot-IKS01A1-Explora ... more
Fork of libmDot-dev-mbed2-deprecated by
The Dot library provides a LoRaWan certified stack for LoRa communication using MultiTech mDot and xDot devices. The stack is compatible with mbed 5.
Dot Library Version 3 Updates
Dot Library versions 3.x.x require a channel plan to be injected into the stack. Channel plans are included with the 3.x.x Dot Library releases. The following code snippet demonstrates how to create a channel plan and inject it into the stack.
#include "mDot.h" #include "channel_plans.h" int main() { ChannelPlan* plan = new lora::ChannelPlan_US915(); assert(plan); mDot* dot = mDot::getInstance(plan); assert(dot); // ... }
Dot devices must not be deployed with software using a different channel plan than the Dot's default plan! This functionality is for development and testing only!
Multicast Sessions
Multicast sessions and packet rx events in library. When in Class C mode Multicast downlinks can be received. Recieved packets should be filtered on address, counter value will be maintained in the session or can be set explicitly depending on Application support to share Multicast Address, Keys and Counters.
mDot.h
/** * Add a multicast session address and keys * Downlink counter is set to 0 * Up to 3 MULTICAST_SESSIONS can be set */ int32_t setMulticastSession(uint8_t index, uint32_t addr, const uint8_t* nsk, const uint8_t* dsk); /** * Set a multicast session counter * Up to 3 MULTICAST_SESSIONS can be set */ int32_t setMulticastDownlinkCounter(uint8_t index, uint32_t count);
mDotEvent.h
The address field was added to PacketRx event.
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);
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:
- libmDot-mbed5 -> production-ready build for mDot
- libmDot-dev-mbed5 -> development build for mDot
- libxDot-mbed5 -> production-ready build for xDot
- libxDot-dev-mbed5 -> development build for xDot
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.
mDotEvent.h@136:d7d7093d4754, 2018-02-16 (annotated)
- Committer:
- Jenkins@KEILDM1.dc.multitech.prv
- Date:
- Fri Feb 16 16:00:18 2018 -0600
- Revision:
- 136:d7d7093d4754
- Parent:
- 114:8462870088eb
- Child:
- 137:893a90334924
mdot-library revision 3.0.2-51-g6ba87fb and mbed-os revision mbed-os-5.5.7
Who changed what in which revision?
User | Revision | Line number | New 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 | 90:79a8c8660a4e | 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; |
Mike Fiore |
16:b630e18103e5 | 42 | uint8_t TxNbRetries; |
Mike Fiore |
16:b630e18103e5 | 43 | uint8_t TxDatarate; |
Mike Fiore |
16:b630e18103e5 | 44 | uint8_t RxPort; |
Mike Fiore |
16:b630e18103e5 | 45 | uint8_t *RxBuffer; |
Mike Fiore |
16:b630e18103e5 | 46 | uint8_t RxBufferSize; |
Mike Fiore |
16:b630e18103e5 | 47 | int16_t RxRssi; |
Mike Fiore |
16:b630e18103e5 | 48 | uint8_t RxSnr; |
Mike Fiore |
16:b630e18103e5 | 49 | uint16_t Energy; |
Mike Fiore |
16:b630e18103e5 | 50 | uint8_t DemodMargin; |
Mike Fiore |
16:b630e18103e5 | 51 | uint8_t NbGateways; |
Mike Fiore |
16:b630e18103e5 | 52 | } LoRaMacEventInfo; |
Mike Fiore |
16:b630e18103e5 | 53 | |
Mike Fiore |
16:b630e18103e5 | 54 | class mDotEvent: public lora::MacEvents { |
Mike Fiore |
16:b630e18103e5 | 55 | public: |
Mike Fiore |
16:b630e18103e5 | 56 | |
Mike Fiore |
16:b630e18103e5 | 57 | mDotEvent() |
Mike Fiore |
16:b630e18103e5 | 58 | : |
Mike Fiore |
16:b630e18103e5 | 59 | LinkCheckAnsReceived(false), |
Mike Fiore |
16:b630e18103e5 | 60 | DemodMargin(0), |
Mike Fiore |
16:b630e18103e5 | 61 | NbGateways(0), |
Mike Fiore |
16:b630e18103e5 | 62 | PacketReceived(false), |
Mike Fiore |
16:b630e18103e5 | 63 | RxPort(0), |
Mike Fiore |
16:b630e18103e5 | 64 | RxPayloadSize(0), |
Mike Fiore |
16:b630e18103e5 | 65 | PongReceived(false), |
Mike Fiore |
16:b630e18103e5 | 66 | PongRssi(0), |
Mike Fiore |
16:b630e18103e5 | 67 | PongSnr(0), |
Mike Fiore |
16:b630e18103e5 | 68 | AckReceived(false), |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 69 | TxNbRetries(0), |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 70 | _sleep_cb(NULL) |
Mike Fiore |
16:b630e18103e5 | 71 | { |
Mike Fiore |
16:b630e18103e5 | 72 | memset(&_flags, 0, sizeof(LoRaMacEventFlags)); |
Mike Fiore |
16:b630e18103e5 | 73 | memset(&_info, 0, sizeof(LoRaMacEventInfo)); |
Mike Fiore |
16:b630e18103e5 | 74 | } |
Mike Fiore |
16:b630e18103e5 | 75 | |
Mike Fiore |
16:b630e18103e5 | 76 | virtual ~mDotEvent() { |
Mike Fiore |
16:b630e18103e5 | 77 | } |
Mike Fiore |
16:b630e18103e5 | 78 | |
Mike Fiore |
16:b630e18103e5 | 79 | virtual void MacEvent(LoRaMacEventFlags *flags, LoRaMacEventInfo *info) { |
Mike Fiore |
16:b630e18103e5 | 80 | if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) { |
Mike Fiore |
16:b630e18103e5 | 81 | std::string msg = "OK"; |
Mike Fiore |
16:b630e18103e5 | 82 | switch (info->Status) { |
Mike Fiore |
16:b630e18103e5 | 83 | case LORAMAC_EVENT_INFO_STATUS_ERROR: |
Mike Fiore |
16:b630e18103e5 | 84 | msg = "ERROR"; |
Mike Fiore |
16:b630e18103e5 | 85 | break; |
Mike Fiore |
16:b630e18103e5 | 86 | case LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT: |
Mike Fiore |
16:b630e18103e5 | 87 | msg = "TX_TIMEOUT"; |
Mike Fiore |
16:b630e18103e5 | 88 | break; |
Mike Fiore |
16:b630e18103e5 | 89 | case LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT: |
Mike Fiore |
16:b630e18103e5 | 90 | msg = "RX_TIMEOUT"; |
Mike Fiore |
16:b630e18103e5 | 91 | break; |
Mike Fiore |
16:b630e18103e5 | 92 | case LORAMAC_EVENT_INFO_STATUS_RX_ERROR: |
Mike Fiore |
16:b630e18103e5 | 93 | msg = "RX_ERROR"; |
Mike Fiore |
16:b630e18103e5 | 94 | break; |
Mike Fiore |
16:b630e18103e5 | 95 | case LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL: |
Mike Fiore |
16:b630e18103e5 | 96 | msg = "JOIN_FAIL"; |
Mike Fiore |
16:b630e18103e5 | 97 | break; |
Mike Fiore |
16:b630e18103e5 | 98 | case LORAMAC_EVENT_INFO_STATUS_DOWNLINK_FAIL: |
Mike Fiore |
16:b630e18103e5 | 99 | msg = "DOWNLINK_FAIL"; |
Mike Fiore |
16:b630e18103e5 | 100 | break; |
Mike Fiore |
16:b630e18103e5 | 101 | case LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL: |
Mike Fiore |
16:b630e18103e5 | 102 | msg = "ADDRESS_FAIL"; |
Mike Fiore |
16:b630e18103e5 | 103 | break; |
Mike Fiore |
16:b630e18103e5 | 104 | case LORAMAC_EVENT_INFO_STATUS_MIC_FAIL: |
Mike Fiore |
16:b630e18103e5 | 105 | msg = "MIC_FAIL"; |
Mike Fiore |
16:b630e18103e5 | 106 | break; |
Mike Fiore |
16:b630e18103e5 | 107 | default: |
Mike Fiore |
16:b630e18103e5 | 108 | break; |
Mike Fiore |
16:b630e18103e5 | 109 | } |
Mike Fiore |
16:b630e18103e5 | 110 | logTrace("Event: %s", msg.c_str()); |
Mike Fiore |
16:b630e18103e5 | 111 | |
Mike Fiore |
16:b630e18103e5 | 112 | logTrace("Flags Tx: %d Rx: %d RxData: %d RxSlot: %d LinkCheck: %d JoinAccept: %d", |
Mike Fiore |
16:b630e18103e5 | 113 | flags->Bits.Tx, flags->Bits.Rx, flags->Bits.RxData, flags->Bits.RxSlot, flags->Bits.LinkCheck, flags->Bits.JoinAccept); |
Mike Fiore |
16:b630e18103e5 | 114 | 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 | 115 | info->Status, info->TxAckReceived, info->TxNbRetries, info->TxDatarate, info->RxPort, info->RxBufferSize, |
Mike Fiore |
16:b630e18103e5 | 116 | info->RxRssi, info->RxSnr, info->Energy, info->DemodMargin, info->NbGateways); |
Mike Fiore |
16:b630e18103e5 | 117 | } |
Mike Fiore |
16:b630e18103e5 | 118 | } |
Mike Fiore |
16:b630e18103e5 | 119 | |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 120 | virtual void TxStart() { |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 121 | logDebug("mDotEvent - TxStart"); |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 122 | |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 123 | // Fire auto sleep cfg event if enabled |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 124 | if (_sleep_cb) |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 125 | _sleep_cb(mDot::AUTO_SLEEP_EVT_CFG); |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 126 | } |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 127 | |
Mike Fiore |
16:b630e18103e5 | 128 | virtual void TxDone(uint8_t dr) { |
Mike Fiore |
16:b630e18103e5 | 129 | RxPayloadSize = 0; |
Mike Fiore |
16:b630e18103e5 | 130 | LinkCheckAnsReceived = false; |
Mike Fiore |
16:b630e18103e5 | 131 | PacketReceived = false; |
Mike Fiore |
16:b630e18103e5 | 132 | AckReceived = false; |
Mike Fiore |
16:b630e18103e5 | 133 | PongReceived = false; |
Jenkins@KEILDM1.dc.multitech.prv | 26:17479e0039f6 | 134 | TxNbRetries = 0; |
Mike Fiore |
16:b630e18103e5 | 135 | |
Mike Fiore |
16:b630e18103e5 | 136 | logDebug("mDotEvent - TxDone"); |
Mike Fiore |
16:b630e18103e5 | 137 | memset(&_flags, 0, sizeof(LoRaMacEventFlags)); |
Mike Fiore |
16:b630e18103e5 | 138 | memset(&_info, 0, sizeof(LoRaMacEventInfo)); |
Mike Fiore |
16:b630e18103e5 | 139 | |
Mike Fiore |
16:b630e18103e5 | 140 | _flags.Bits.Tx = 1; |
Mike Fiore |
16:b630e18103e5 | 141 | _info.TxDatarate = dr; |
Mike Fiore |
16:b630e18103e5 | 142 | _info.Status = LORAMAC_EVENT_INFO_STATUS_OK; |
Mike Fiore |
16:b630e18103e5 | 143 | Notify(); |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 144 | |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 145 | // If configured, we can sleep until the rx window opens |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 146 | if (_sleep_cb) |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 147 | _sleep_cb(mDot::AUTO_SLEEP_EVT_TXDONE); |
Mike Fiore |
16:b630e18103e5 | 148 | } |
Mike Fiore |
16:b630e18103e5 | 149 | |
Mike Fiore |
16:b630e18103e5 | 150 | void Notify() { |
Mike Fiore |
16:b630e18103e5 | 151 | MacEvent(&_flags, &_info); |
Mike Fiore |
16:b630e18103e5 | 152 | } |
Mike Fiore |
16:b630e18103e5 | 153 | |
Mike Fiore |
16:b630e18103e5 | 154 | virtual void TxTimeout(void) { |
Mike Fiore |
16:b630e18103e5 | 155 | logDebug("mDotEvent - TxTimeout"); |
Mike Fiore |
16:b630e18103e5 | 156 | |
Mike Fiore |
16:b630e18103e5 | 157 | _flags.Bits.Tx = 1; |
Mike Fiore |
16:b630e18103e5 | 158 | _info.Status = LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT; |
Mike Fiore |
16:b630e18103e5 | 159 | Notify(); |
Mike Fiore |
16:b630e18103e5 | 160 | } |
Mike Fiore |
16:b630e18103e5 | 161 | |
Mike Fiore |
16:b630e18103e5 | 162 | virtual void JoinAccept(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) { |
Mike Fiore |
16:b630e18103e5 | 163 | logDebug("mDotEvent - JoinAccept"); |
Mike Fiore |
16:b630e18103e5 | 164 | |
Mike Fiore |
16:b630e18103e5 | 165 | _flags.Bits.Tx = 0; |
Mike Fiore |
16:b630e18103e5 | 166 | _flags.Bits.JoinAccept = 1; |
Mike Fiore |
16:b630e18103e5 | 167 | _info.Status = LORAMAC_EVENT_INFO_STATUS_OK; |
Mike Fiore |
16:b630e18103e5 | 168 | Notify(); |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 169 | |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 170 | if (_sleep_cb) |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 171 | _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP); |
Mike Fiore |
16:b630e18103e5 | 172 | } |
Mike Fiore |
16:b630e18103e5 | 173 | |
Mike Fiore |
16:b630e18103e5 | 174 | virtual void JoinFailed(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) { |
Mike Fiore |
16:b630e18103e5 | 175 | logDebug("mDotEvent - JoinFailed"); |
Mike Fiore |
16:b630e18103e5 | 176 | |
Mike Fiore |
16:b630e18103e5 | 177 | _flags.Bits.Tx = 0; |
Mike Fiore |
16:b630e18103e5 | 178 | _flags.Bits.JoinAccept = 1; |
Mike Fiore |
16:b630e18103e5 | 179 | _info.Status = LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL; |
Mike Fiore |
16:b630e18103e5 | 180 | Notify(); |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 181 | |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 182 | if (_sleep_cb) |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 183 | _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP); |
Mike Fiore |
16:b630e18103e5 | 184 | } |
Mike Fiore |
16:b630e18103e5 | 185 | |
Jenkins@KEILDM1.dc.multitech.prv | 26:17479e0039f6 | 186 | virtual void MissedAck(uint8_t retries) { |
Jenkins@KEILDM1.dc.multitech.prv | 26:17479e0039f6 | 187 | logDebug("mDotEvent - MissedAck : retries %u", retries); |
Jenkins@KEILDM1.dc.multitech.prv | 26:17479e0039f6 | 188 | TxNbRetries = retries; |
Jenkins@KEILDM1.dc.multitech.prv | 26:17479e0039f6 | 189 | _info.TxNbRetries = retries; |
Jenkins@KEILDM1.dc.multitech.prv | 26:17479e0039f6 | 190 | } |
Jenkins@KEILDM1.dc.multitech.prv | 26:17479e0039f6 | 191 | |
Jenkins@KEILDM1.dc.multitech.prv | 90:79a8c8660a4e | 192 | 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) { |
Jenkins@KEILDM1.dc.multitech.prv | 90:79a8c8660a4e | 193 | logDebug("mDotEvent - PacketRx ADDR: %08x", address); |
Mike Fiore |
16:b630e18103e5 | 194 | RxPort = port; |
Mike Fiore |
16:b630e18103e5 | 195 | PacketReceived = true; |
Mike Fiore |
16:b630e18103e5 | 196 | |
Mike Fiore |
16:b630e18103e5 | 197 | memcpy(RxPayload, payload, size); |
Mike Fiore |
16:b630e18103e5 | 198 | RxPayloadSize = size; |
Mike Fiore |
16:b630e18103e5 | 199 | |
Mike Fiore |
16:b630e18103e5 | 200 | if (ctrl.Bits.Ack) { |
Mike Fiore |
16:b630e18103e5 | 201 | AckReceived = true; |
Mike Fiore |
16:b630e18103e5 | 202 | } |
Mike Fiore |
16:b630e18103e5 | 203 | |
Mike Fiore |
16:b630e18103e5 | 204 | if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) { |
Mike Fiore |
16:b630e18103e5 | 205 | std::string packet = mts::Text::bin2hexString(RxPayload, size); |
Mike Fiore |
16:b630e18103e5 | 206 | logTrace("Payload: %s", packet.c_str()); |
Mike Fiore |
16:b630e18103e5 | 207 | } |
Mike Fiore |
16:b630e18103e5 | 208 | |
Mike Fiore |
16:b630e18103e5 | 209 | _flags.Bits.Tx = 0; |
Mike Fiore |
16:b630e18103e5 | 210 | _flags.Bits.Rx = 1; |
Mike Fiore |
16:b630e18103e5 | 211 | _flags.Bits.RxData = size > 0; |
Mike Fiore |
16:b630e18103e5 | 212 | _flags.Bits.RxSlot = slot; |
Mike Fiore |
16:b630e18103e5 | 213 | _info.RxBuffer = payload; |
Mike Fiore |
16:b630e18103e5 | 214 | _info.RxBufferSize = size; |
Mike Fiore |
16:b630e18103e5 | 215 | _info.RxPort = port; |
Mike Fiore |
16:b630e18103e5 | 216 | _info.RxRssi = rssi; |
Mike Fiore |
16:b630e18103e5 | 217 | _info.RxSnr = snr; |
Mike Fiore |
16:b630e18103e5 | 218 | _info.TxAckReceived = AckReceived; |
Jenkins@KEILDM1.dc.multitech.prv | 26:17479e0039f6 | 219 | _info.TxNbRetries = retries; |
Mike Fiore |
16:b630e18103e5 | 220 | _info.Status = LORAMAC_EVENT_INFO_STATUS_OK; |
Mike Fiore |
16:b630e18103e5 | 221 | Notify(); |
Mike Fiore |
16:b630e18103e5 | 222 | } |
Mike Fiore |
16:b630e18103e5 | 223 | |
Mike Fiore |
16:b630e18103e5 | 224 | 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 | 225 | logDebug("mDotEvent - RxDone"); |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 226 | |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 227 | if (_sleep_cb) |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 228 | _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP); |
Mike Fiore |
16:b630e18103e5 | 229 | } |
Mike Fiore |
16:b630e18103e5 | 230 | |
Mike Fiore |
16:b630e18103e5 | 231 | virtual void Pong(int16_t m_rssi, int8_t m_snr, int16_t s_rssi, int8_t s_snr) { |
Mike Fiore |
16:b630e18103e5 | 232 | logDebug("mDotEvent - Pong"); |
Mike Fiore |
16:b630e18103e5 | 233 | PongReceived = true; |
Mike Fiore |
16:b630e18103e5 | 234 | PongRssi = s_rssi; |
Mike Fiore |
16:b630e18103e5 | 235 | PongSnr = s_snr; |
Mike Fiore |
16:b630e18103e5 | 236 | } |
Mike Fiore |
16:b630e18103e5 | 237 | |
Mike Fiore |
16:b630e18103e5 | 238 | virtual void NetworkLinkCheck(int16_t m_rssi, int8_t m_snr, int8_t s_snr, uint8_t s_gateways) { |
Mike Fiore |
16:b630e18103e5 | 239 | logDebug("mDotEvent - NetworkLinkCheck"); |
Mike Fiore |
16:b630e18103e5 | 240 | LinkCheckAnsReceived = true; |
Mike Fiore |
16:b630e18103e5 | 241 | DemodMargin = s_snr; |
Mike Fiore |
16:b630e18103e5 | 242 | NbGateways = s_gateways; |
Mike Fiore |
16:b630e18103e5 | 243 | |
Mike Fiore |
16:b630e18103e5 | 244 | _flags.Bits.Tx = 0; |
Mike Fiore |
16:b630e18103e5 | 245 | _flags.Bits.LinkCheck = 1; |
Mike Fiore |
16:b630e18103e5 | 246 | _info.RxRssi = m_rssi; |
Mike Fiore |
16:b630e18103e5 | 247 | _info.RxSnr = m_snr; |
Mike Fiore |
16:b630e18103e5 | 248 | _info.DemodMargin = s_snr; |
Mike Fiore |
16:b630e18103e5 | 249 | _info.NbGateways = s_gateways; |
Mike Fiore |
16:b630e18103e5 | 250 | _info.Status = LORAMAC_EVENT_INFO_STATUS_OK; |
Mike Fiore |
16:b630e18103e5 | 251 | Notify(); |
Mike Fiore |
16:b630e18103e5 | 252 | } |
Mike Fiore |
16:b630e18103e5 | 253 | |
Mike Fiore |
16:b630e18103e5 | 254 | virtual void RxTimeout(uint8_t slot) { |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 255 | logDebug("mDotEvent - RxTimeout on Slot %d", slot); |
Mike Fiore |
16:b630e18103e5 | 256 | |
Mike Fiore |
16:b630e18103e5 | 257 | _flags.Bits.Tx = 0; |
Mike Fiore |
16:b630e18103e5 | 258 | _flags.Bits.RxSlot = slot; |
Mike Fiore |
16:b630e18103e5 | 259 | _info.Status = LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT; |
Mike Fiore |
16:b630e18103e5 | 260 | Notify(); |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 261 | |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 262 | if (_sleep_cb) { |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 263 | // If this is the first rx window we can sleep until the next one |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 264 | if (slot == 1) |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 265 | _sleep_cb(mDot::AUTO_SLEEP_EVT_RX1_TIMEOUT); |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 266 | else |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 267 | _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP); |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 268 | } |
Mike Fiore |
16:b630e18103e5 | 269 | } |
Mike Fiore |
16:b630e18103e5 | 270 | |
Mike Fiore |
16:b630e18103e5 | 271 | virtual void RxError(uint8_t slot) { |
Mike Fiore |
16:b630e18103e5 | 272 | logDebug("mDotEvent - RxError"); |
Mike Fiore |
16:b630e18103e5 | 273 | |
Mike Fiore |
16:b630e18103e5 | 274 | memset(&_flags, 0, sizeof(LoRaMacEventFlags)); |
Mike Fiore |
16:b630e18103e5 | 275 | memset(&_info, 0, sizeof(LoRaMacEventInfo)); |
Mike Fiore |
16:b630e18103e5 | 276 | |
Mike Fiore |
16:b630e18103e5 | 277 | _flags.Bits.RxSlot = slot; |
Mike Fiore |
16:b630e18103e5 | 278 | _info.Status = LORAMAC_EVENT_INFO_STATUS_RX_ERROR; |
Mike Fiore |
16:b630e18103e5 | 279 | Notify(); |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 280 | |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 281 | if (_sleep_cb) |
Jenkins@KEILDM1.dc.multitech.prv | 136:d7d7093d4754 | 282 | _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP); |
Mike Fiore |
16:b630e18103e5 | 283 | } |
Mike Fiore |
16:b630e18103e5 | 284 | |
Mike Fiore |
16:b630e18103e5 | 285 | virtual uint8_t MeasureBattery(void) { |
Mike Fiore |
16:b630e18103e5 | 286 | return 255; |
Mike Fiore |
16:b630e18103e5 | 287 | } |
Mike Fiore |
16:b630e18103e5 | 288 | |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 289 | void AttachSleepCallback(Callback<void(mDot::AutoSleepEvent_t)> cb) { |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 290 | _sleep_cb = cb; |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 291 | } |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 292 | |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 293 | void DetachSleepCallback() { |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 294 | _sleep_cb = NULL; |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 295 | } |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 296 | |
Mike Fiore |
16:b630e18103e5 | 297 | bool LinkCheckAnsReceived; |
Mike Fiore |
16:b630e18103e5 | 298 | uint8_t DemodMargin; |
Mike Fiore |
16:b630e18103e5 | 299 | uint8_t NbGateways; |
Mike Fiore |
16:b630e18103e5 | 300 | |
Mike Fiore |
16:b630e18103e5 | 301 | bool PacketReceived; |
Mike Fiore |
16:b630e18103e5 | 302 | uint8_t RxPort; |
Mike Fiore |
16:b630e18103e5 | 303 | uint8_t RxPayload[255]; |
Mike Fiore |
16:b630e18103e5 | 304 | uint8_t RxPayloadSize; |
Mike Fiore |
16:b630e18103e5 | 305 | |
Mike Fiore |
16:b630e18103e5 | 306 | bool PongReceived; |
Mike Fiore |
16:b630e18103e5 | 307 | int16_t PongRssi; |
Mike Fiore |
16:b630e18103e5 | 308 | int16_t PongSnr; |
Mike Fiore |
16:b630e18103e5 | 309 | |
Mike Fiore |
16:b630e18103e5 | 310 | bool AckReceived; |
Mike Fiore |
16:b630e18103e5 | 311 | uint8_t TxNbRetries; |
Mike Fiore |
16:b630e18103e5 | 312 | |
Mike Fiore |
16:b630e18103e5 | 313 | LoRaMacEventFlags& Flags() { |
Mike Fiore |
16:b630e18103e5 | 314 | return _flags; |
Mike Fiore |
16:b630e18103e5 | 315 | } |
Mike Fiore |
16:b630e18103e5 | 316 | LoRaMacEventInfo& Info() { |
Mike Fiore |
16:b630e18103e5 | 317 | return _info; |
Mike Fiore |
16:b630e18103e5 | 318 | } |
Mike Fiore |
16:b630e18103e5 | 319 | |
Mike Fiore |
16:b630e18103e5 | 320 | private: |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 321 | /* Hook to inject a sleep method in between receive windows */ |
Jenkins@KEILDM1.dc.multitech.prv | 114:8462870088eb | 322 | Callback<void(mDot::AutoSleepEvent_t)> _sleep_cb; |
Mike Fiore |
16:b630e18103e5 | 323 | |
Mike Fiore |
16:b630e18103e5 | 324 | LoRaMacEventFlags _flags; |
Mike Fiore |
16:b630e18103e5 | 325 | LoRaMacEventInfo _info; |
Mike Fiore |
16:b630e18103e5 | 326 | |
Mike Fiore |
16:b630e18103e5 | 327 | // |
Mike Fiore |
16:b630e18103e5 | 328 | // /*! |
Mike Fiore |
16:b630e18103e5 | 329 | // * MAC layer event callback prototype. |
Mike Fiore |
16:b630e18103e5 | 330 | // * |
Mike Fiore |
16:b630e18103e5 | 331 | // * \param [IN] flags Bit field indicating the MAC events occurred |
Mike Fiore |
16:b630e18103e5 | 332 | // * \param [IN] info Details about MAC events occurred |
Mike Fiore |
16:b630e18103e5 | 333 | // */ |
Mike Fiore |
16:b630e18103e5 | 334 | // virtual void MacEvent(LoRaMacEventFlags *flags, LoRaMacEventInfo *info) { |
Mike Fiore |
16:b630e18103e5 | 335 | // logDebug("mDotEvent"); |
Mike Fiore |
16:b630e18103e5 | 336 | // |
Mike Fiore |
16:b630e18103e5 | 337 | // if (flags->Bits.Rx) { |
Mike Fiore |
16:b630e18103e5 | 338 | // logDebug("Rx"); |
Mike Fiore |
16:b630e18103e5 | 339 | // |
Mike Fiore |
16:b630e18103e5 | 340 | // // Event Object must delete RxBuffer |
Mike Fiore |
16:b630e18103e5 | 341 | // delete[] info->RxBuffer; |
Mike Fiore |
16:b630e18103e5 | 342 | // } |
Mike Fiore |
16:b630e18103e5 | 343 | // } |
Mike Fiore |
16:b630e18103e5 | 344 | // |
Mike Fiore |
16:b630e18103e5 | 345 | |
Mike Fiore |
16:b630e18103e5 | 346 | }; |
Mike Fiore |
16:b630e18103e5 | 347 | |
Mike Fiore |
16:b630e18103e5 | 348 | #endif // __MDOT_EVENT_H__ |