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
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:
- 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.
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
mDotEvent.h@74:8b02b1a9a1b6, 2020-03-25 (annotated)
- Committer:
- jreiss
- Date:
- Wed Mar 25 17:06:41 2020 +0000
- Revision:
- 74:8b02b1a9a1b6
- Parent:
- 70:0c5b5b02d17b
Remove old ARMCC archive, only ARMC6 is available.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 1 | /********************************************************************** |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 2 | * COPYRIGHT 2015 MULTI-TECH SYSTEMS, INC. |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 3 | * |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 4 | * Redistribution and use in source and binary forms, with or without modification, |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 5 | * are permitted provided that the following conditions are met: |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 6 | * 1. Redistributions of source code must retain the above copyright notice, |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 7 | * this list of conditions and the following disclaimer. |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 8 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 9 | * this list of conditions and the following disclaimer in the documentation |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 10 | * and/or other materials provided with the distribution. |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 11 | * 3. Neither the name of MULTI-TECH SYSTEMS, INC. nor the names of its contributors |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 12 | * may be used to endorse or promote products derived from this software |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 13 | * without specific prior written permission. |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 14 | * |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 18 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 23 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 25 | * |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 26 | ****************************************************************************** |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 27 | */ |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 28 | |
Mike Fiore |
16:b630e18103e5 | 29 | #ifndef MDOT_EVENT_H |
Mike Fiore |
16:b630e18103e5 | 30 | #define MDOT_EVENT_H |
Mike Fiore |
16:b630e18103e5 | 31 | |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 32 | #include "mbed.h" |
Mike Fiore |
16:b630e18103e5 | 33 | #include "mDot.h" |
Mike Fiore |
16:b630e18103e5 | 34 | #include "MacEvents.h" |
Mike Fiore |
16:b630e18103e5 | 35 | #include "MTSLog.h" |
Mike Fiore |
16:b630e18103e5 | 36 | #include "MTSText.h" |
Mike Fiore |
16:b630e18103e5 | 37 | |
Mike Fiore |
16:b630e18103e5 | 38 | typedef union { |
Mike Fiore |
16:b630e18103e5 | 39 | uint8_t Value; |
Mike Fiore |
16:b630e18103e5 | 40 | struct { |
Mike Fiore |
16:b630e18103e5 | 41 | uint8_t :1; |
Mike Fiore |
16:b630e18103e5 | 42 | uint8_t Tx :1; |
Mike Fiore |
16:b630e18103e5 | 43 | uint8_t Rx :1; |
Mike Fiore |
16:b630e18103e5 | 44 | uint8_t RxData :1; |
Mike Fiore |
16:b630e18103e5 | 45 | uint8_t RxSlot :2; |
Mike Fiore |
16:b630e18103e5 | 46 | uint8_t LinkCheck :1; |
Mike Fiore |
16:b630e18103e5 | 47 | uint8_t JoinAccept :1; |
Mike Fiore |
16:b630e18103e5 | 48 | } Bits; |
Mike Fiore |
16:b630e18103e5 | 49 | } LoRaMacEventFlags; |
Mike Fiore |
16:b630e18103e5 | 50 | |
Mike Fiore |
16:b630e18103e5 | 51 | typedef enum { |
Mike Fiore |
16:b630e18103e5 | 52 | LORAMAC_EVENT_INFO_STATUS_OK = 0, |
Mike Fiore |
16:b630e18103e5 | 53 | LORAMAC_EVENT_INFO_STATUS_ERROR, |
Mike Fiore |
16:b630e18103e5 | 54 | LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT, |
Mike Fiore |
16:b630e18103e5 | 55 | LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT, |
Mike Fiore |
16:b630e18103e5 | 56 | LORAMAC_EVENT_INFO_STATUS_RX_ERROR, |
Mike Fiore |
16:b630e18103e5 | 57 | LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL, |
Mike Fiore |
16:b630e18103e5 | 58 | LORAMAC_EVENT_INFO_STATUS_DOWNLINK_FAIL, |
Mike Fiore |
16:b630e18103e5 | 59 | LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL, |
Mike Fiore |
16:b630e18103e5 | 60 | LORAMAC_EVENT_INFO_STATUS_MIC_FAIL, |
Mike Fiore |
16:b630e18103e5 | 61 | } LoRaMacEventInfoStatus; |
Mike Fiore |
16:b630e18103e5 | 62 | |
Mike Fiore |
16:b630e18103e5 | 63 | /*! |
Mike Fiore |
16:b630e18103e5 | 64 | * LoRaMAC event information |
Mike Fiore |
16:b630e18103e5 | 65 | */ |
Mike Fiore |
16:b630e18103e5 | 66 | typedef struct { |
Mike Fiore |
16:b630e18103e5 | 67 | LoRaMacEventInfoStatus Status; |
Mike Fiore |
16:b630e18103e5 | 68 | lora::DownlinkControl Ctrl; |
Mike Fiore |
16:b630e18103e5 | 69 | bool TxAckReceived; |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 70 | bool DuplicateRx; |
Mike Fiore |
16:b630e18103e5 | 71 | uint8_t TxNbRetries; |
Mike Fiore |
16:b630e18103e5 | 72 | uint8_t TxDatarate; |
Mike Fiore |
16:b630e18103e5 | 73 | uint8_t RxPort; |
Mike Fiore |
16:b630e18103e5 | 74 | uint8_t *RxBuffer; |
Mike Fiore |
16:b630e18103e5 | 75 | uint8_t RxBufferSize; |
Mike Fiore |
16:b630e18103e5 | 76 | int16_t RxRssi; |
Mike Fiore |
16:b630e18103e5 | 77 | uint8_t RxSnr; |
Mike Fiore |
16:b630e18103e5 | 78 | uint16_t Energy; |
Mike Fiore |
16:b630e18103e5 | 79 | uint8_t DemodMargin; |
Mike Fiore |
16:b630e18103e5 | 80 | uint8_t NbGateways; |
Mike Fiore |
16:b630e18103e5 | 81 | } LoRaMacEventInfo; |
Mike Fiore |
16:b630e18103e5 | 82 | |
Mike Fiore |
16:b630e18103e5 | 83 | class mDotEvent: public lora::MacEvents { |
Mike Fiore |
16:b630e18103e5 | 84 | public: |
Mike Fiore |
16:b630e18103e5 | 85 | |
Mike Fiore |
16:b630e18103e5 | 86 | mDotEvent() |
Mike Fiore |
16:b630e18103e5 | 87 | : |
Mike Fiore |
16:b630e18103e5 | 88 | LinkCheckAnsReceived(false), |
Mike Fiore |
16:b630e18103e5 | 89 | DemodMargin(0), |
Mike Fiore |
16:b630e18103e5 | 90 | NbGateways(0), |
Mike Fiore |
16:b630e18103e5 | 91 | PacketReceived(false), |
Mike Fiore |
16:b630e18103e5 | 92 | RxPort(0), |
Mike Fiore |
16:b630e18103e5 | 93 | RxPayloadSize(0), |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 94 | BeaconLocked(false), |
Mike Fiore |
16:b630e18103e5 | 95 | PongReceived(false), |
Mike Fiore |
16:b630e18103e5 | 96 | PongRssi(0), |
Mike Fiore |
16:b630e18103e5 | 97 | PongSnr(0), |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 98 | ServerTimeReceived(false), |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 99 | ServerTimeSeconds(0U), |
Mike Fiore |
16:b630e18103e5 | 100 | AckReceived(false), |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 101 | DuplicateRx(false), |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 102 | TxNbRetries(0) |
Mike Fiore |
16:b630e18103e5 | 103 | { |
Mike Fiore |
16:b630e18103e5 | 104 | memset(&_flags, 0, sizeof(LoRaMacEventFlags)); |
Mike Fiore |
16:b630e18103e5 | 105 | memset(&_info, 0, sizeof(LoRaMacEventInfo)); |
Mike Fiore |
16:b630e18103e5 | 106 | } |
Mike Fiore |
16:b630e18103e5 | 107 | |
Mike Fiore |
16:b630e18103e5 | 108 | virtual ~mDotEvent() { |
Mike Fiore |
16:b630e18103e5 | 109 | } |
Mike Fiore |
16:b630e18103e5 | 110 | |
Mike Fiore |
16:b630e18103e5 | 111 | virtual void MacEvent(LoRaMacEventFlags *flags, LoRaMacEventInfo *info) { |
Mike Fiore |
16:b630e18103e5 | 112 | if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) { |
Mike Fiore |
16:b630e18103e5 | 113 | std::string msg = "OK"; |
Mike Fiore |
16:b630e18103e5 | 114 | switch (info->Status) { |
Mike Fiore |
16:b630e18103e5 | 115 | case LORAMAC_EVENT_INFO_STATUS_ERROR: |
Mike Fiore |
16:b630e18103e5 | 116 | msg = "ERROR"; |
Mike Fiore |
16:b630e18103e5 | 117 | break; |
Mike Fiore |
16:b630e18103e5 | 118 | case LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT: |
Mike Fiore |
16:b630e18103e5 | 119 | msg = "TX_TIMEOUT"; |
Mike Fiore |
16:b630e18103e5 | 120 | break; |
Mike Fiore |
16:b630e18103e5 | 121 | case LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT: |
Mike Fiore |
16:b630e18103e5 | 122 | msg = "RX_TIMEOUT"; |
Mike Fiore |
16:b630e18103e5 | 123 | break; |
Mike Fiore |
16:b630e18103e5 | 124 | case LORAMAC_EVENT_INFO_STATUS_RX_ERROR: |
Mike Fiore |
16:b630e18103e5 | 125 | msg = "RX_ERROR"; |
Mike Fiore |
16:b630e18103e5 | 126 | break; |
Mike Fiore |
16:b630e18103e5 | 127 | case LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL: |
Mike Fiore |
16:b630e18103e5 | 128 | msg = "JOIN_FAIL"; |
Mike Fiore |
16:b630e18103e5 | 129 | break; |
Mike Fiore |
16:b630e18103e5 | 130 | case LORAMAC_EVENT_INFO_STATUS_DOWNLINK_FAIL: |
Mike Fiore |
16:b630e18103e5 | 131 | msg = "DOWNLINK_FAIL"; |
Mike Fiore |
16:b630e18103e5 | 132 | break; |
Mike Fiore |
16:b630e18103e5 | 133 | case LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL: |
Mike Fiore |
16:b630e18103e5 | 134 | msg = "ADDRESS_FAIL"; |
Mike Fiore |
16:b630e18103e5 | 135 | break; |
Mike Fiore |
16:b630e18103e5 | 136 | case LORAMAC_EVENT_INFO_STATUS_MIC_FAIL: |
Mike Fiore |
16:b630e18103e5 | 137 | msg = "MIC_FAIL"; |
Mike Fiore |
16:b630e18103e5 | 138 | break; |
Mike Fiore |
16:b630e18103e5 | 139 | default: |
Mike Fiore |
16:b630e18103e5 | 140 | break; |
Mike Fiore |
16:b630e18103e5 | 141 | } |
Mike Fiore |
16:b630e18103e5 | 142 | logTrace("Event: %s", msg.c_str()); |
Mike Fiore |
16:b630e18103e5 | 143 | |
Mike Fiore |
16:b630e18103e5 | 144 | logTrace("Flags Tx: %d Rx: %d RxData: %d RxSlot: %d LinkCheck: %d JoinAccept: %d", |
Mike Fiore |
16:b630e18103e5 | 145 | flags->Bits.Tx, flags->Bits.Rx, flags->Bits.RxData, flags->Bits.RxSlot, flags->Bits.LinkCheck, flags->Bits.JoinAccept); |
Mike Fiore |
16:b630e18103e5 | 146 | 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 | 147 | info->Status, info->TxAckReceived, info->TxNbRetries, info->TxDatarate, info->RxPort, info->RxBufferSize, |
Mike Fiore |
16:b630e18103e5 | 148 | info->RxRssi, info->RxSnr, info->Energy, info->DemodMargin, info->NbGateways); |
Mike Fiore |
16:b630e18103e5 | 149 | } |
Mike Fiore |
16:b630e18103e5 | 150 | } |
Mike Fiore |
16:b630e18103e5 | 151 | |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 152 | virtual void TxStart() { |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 153 | logDebug("mDotEvent - TxStart"); |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 154 | |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 155 | } |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 156 | |
Mike Fiore |
16:b630e18103e5 | 157 | virtual void TxDone(uint8_t dr) { |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 158 | _timeSinceTx.reset(); |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 159 | _timeSinceTx.start(); |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 160 | |
Mike Fiore |
16:b630e18103e5 | 161 | RxPayloadSize = 0; |
Mike Fiore |
16:b630e18103e5 | 162 | LinkCheckAnsReceived = false; |
Mike Fiore |
16:b630e18103e5 | 163 | PacketReceived = false; |
Mike Fiore |
16:b630e18103e5 | 164 | AckReceived = false; |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 165 | DuplicateRx = false; |
Mike Fiore |
16:b630e18103e5 | 166 | PongReceived = false; |
Jenkins@KEILDM1.dc.multitech.prv | 26:17479e0039f6 | 167 | TxNbRetries = 0; |
Mike Fiore |
16:b630e18103e5 | 168 | |
Mike Fiore |
16:b630e18103e5 | 169 | logDebug("mDotEvent - TxDone"); |
Mike Fiore |
16:b630e18103e5 | 170 | memset(&_flags, 0, sizeof(LoRaMacEventFlags)); |
Mike Fiore |
16:b630e18103e5 | 171 | memset(&_info, 0, sizeof(LoRaMacEventInfo)); |
Mike Fiore |
16:b630e18103e5 | 172 | |
Mike Fiore |
16:b630e18103e5 | 173 | _flags.Bits.Tx = 1; |
Mike Fiore |
16:b630e18103e5 | 174 | _info.TxDatarate = dr; |
Mike Fiore |
16:b630e18103e5 | 175 | _info.Status = LORAMAC_EVENT_INFO_STATUS_OK; |
Mike Fiore |
16:b630e18103e5 | 176 | Notify(); |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 177 | |
Mike Fiore |
16:b630e18103e5 | 178 | } |
Mike Fiore |
16:b630e18103e5 | 179 | |
Mike Fiore |
16:b630e18103e5 | 180 | void Notify() { |
Mike Fiore |
16:b630e18103e5 | 181 | MacEvent(&_flags, &_info); |
Mike Fiore |
16:b630e18103e5 | 182 | } |
Mike Fiore |
16:b630e18103e5 | 183 | |
Mike Fiore |
16:b630e18103e5 | 184 | virtual void TxTimeout(void) { |
Mike Fiore |
16:b630e18103e5 | 185 | logDebug("mDotEvent - TxTimeout"); |
Mike Fiore |
16:b630e18103e5 | 186 | |
Mike Fiore |
16:b630e18103e5 | 187 | _flags.Bits.Tx = 1; |
Mike Fiore |
16:b630e18103e5 | 188 | _info.Status = LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT; |
Mike Fiore |
16:b630e18103e5 | 189 | Notify(); |
Mike Fiore |
16:b630e18103e5 | 190 | } |
Mike Fiore |
16:b630e18103e5 | 191 | |
Jenkins@KEILDM1.dc.multitech.prv | 70:0c5b5b02d17b | 192 | virtual void JoinAccept(uint8_t *payload, uint16_t size, int16_t rssi, int16_t snr) { |
Mike Fiore |
16:b630e18103e5 | 193 | logDebug("mDotEvent - JoinAccept"); |
Mike Fiore |
16:b630e18103e5 | 194 | |
Mike Fiore |
16:b630e18103e5 | 195 | _flags.Bits.Tx = 0; |
Mike Fiore |
16:b630e18103e5 | 196 | _flags.Bits.JoinAccept = 1; |
Mike Fiore |
16:b630e18103e5 | 197 | _info.Status = LORAMAC_EVENT_INFO_STATUS_OK; |
Mike Fiore |
16:b630e18103e5 | 198 | Notify(); |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 199 | |
Mike Fiore |
16:b630e18103e5 | 200 | } |
Mike Fiore |
16:b630e18103e5 | 201 | |
Jenkins@KEILDM1.dc.multitech.prv | 70:0c5b5b02d17b | 202 | virtual void JoinFailed(uint8_t *payload, uint16_t size, int16_t rssi, int16_t snr) { |
Mike Fiore |
16:b630e18103e5 | 203 | logDebug("mDotEvent - JoinFailed"); |
Mike Fiore |
16:b630e18103e5 | 204 | |
Mike Fiore |
16:b630e18103e5 | 205 | _flags.Bits.Tx = 0; |
Mike Fiore |
16:b630e18103e5 | 206 | _flags.Bits.JoinAccept = 1; |
Mike Fiore |
16:b630e18103e5 | 207 | _info.Status = LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL; |
Mike Fiore |
16:b630e18103e5 | 208 | Notify(); |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 209 | |
Mike Fiore |
16:b630e18103e5 | 210 | } |
Mike Fiore |
16:b630e18103e5 | 211 | |
Jenkins@KEILDM1.dc.multitech.prv | 26:17479e0039f6 | 212 | virtual void MissedAck(uint8_t retries) { |
Jenkins@KEILDM1.dc.multitech.prv | 26:17479e0039f6 | 213 | logDebug("mDotEvent - MissedAck : retries %u", retries); |
Jenkins@KEILDM1.dc.multitech.prv | 26:17479e0039f6 | 214 | TxNbRetries = retries; |
Jenkins@KEILDM1.dc.multitech.prv | 26:17479e0039f6 | 215 | _info.TxNbRetries = retries; |
Jenkins@KEILDM1.dc.multitech.prv | 26:17479e0039f6 | 216 | } |
Jenkins@KEILDM1.dc.multitech.prv | 26:17479e0039f6 | 217 | |
Jenkins@KEILDM1.dc.multitech.prv | 70:0c5b5b02d17b | 218 | virtual void PacketRx(uint8_t port, uint8_t *payload, uint16_t size, int16_t rssi, int16_t snr, lora::DownlinkControl ctrl, uint8_t slot, uint8_t retries, uint32_t address, bool dupRx) { |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 219 | logDebug("mDotEvent - PacketRx ADDR: %08x", address); |
Mike Fiore |
16:b630e18103e5 | 220 | RxPort = port; |
Mike Fiore |
16:b630e18103e5 | 221 | PacketReceived = true; |
Mike Fiore |
16:b630e18103e5 | 222 | |
Mike Fiore |
16:b630e18103e5 | 223 | memcpy(RxPayload, payload, size); |
Mike Fiore |
16:b630e18103e5 | 224 | RxPayloadSize = size; |
Mike Fiore |
16:b630e18103e5 | 225 | |
Mike Fiore |
16:b630e18103e5 | 226 | if (ctrl.Bits.Ack) { |
Mike Fiore |
16:b630e18103e5 | 227 | AckReceived = true; |
Mike Fiore |
16:b630e18103e5 | 228 | } |
Mike Fiore |
16:b630e18103e5 | 229 | |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 230 | DuplicateRx = dupRx; |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 231 | |
Mike Fiore |
16:b630e18103e5 | 232 | if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) { |
Mike Fiore |
16:b630e18103e5 | 233 | std::string packet = mts::Text::bin2hexString(RxPayload, size); |
Mike Fiore |
16:b630e18103e5 | 234 | logTrace("Payload: %s", packet.c_str()); |
Mike Fiore |
16:b630e18103e5 | 235 | } |
Mike Fiore |
16:b630e18103e5 | 236 | |
Mike Fiore |
16:b630e18103e5 | 237 | _flags.Bits.Tx = 0; |
Mike Fiore |
16:b630e18103e5 | 238 | _flags.Bits.Rx = 1; |
Mike Fiore |
16:b630e18103e5 | 239 | _flags.Bits.RxData = size > 0; |
Mike Fiore |
16:b630e18103e5 | 240 | _flags.Bits.RxSlot = slot; |
Mike Fiore |
16:b630e18103e5 | 241 | _info.RxBuffer = payload; |
Mike Fiore |
16:b630e18103e5 | 242 | _info.RxBufferSize = size; |
Mike Fiore |
16:b630e18103e5 | 243 | _info.RxPort = port; |
Mike Fiore |
16:b630e18103e5 | 244 | _info.RxRssi = rssi; |
Mike Fiore |
16:b630e18103e5 | 245 | _info.RxSnr = snr; |
Mike Fiore |
16:b630e18103e5 | 246 | _info.TxAckReceived = AckReceived; |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 247 | _info.DuplicateRx = DuplicateRx; |
Jenkins@KEILDM1.dc.multitech.prv | 26:17479e0039f6 | 248 | _info.TxNbRetries = retries; |
Mike Fiore |
16:b630e18103e5 | 249 | _info.Status = LORAMAC_EVENT_INFO_STATUS_OK; |
Mike Fiore |
16:b630e18103e5 | 250 | Notify(); |
Mike Fiore |
16:b630e18103e5 | 251 | } |
Mike Fiore |
16:b630e18103e5 | 252 | |
Jenkins@KEILDM1.dc.multitech.prv | 70:0c5b5b02d17b | 253 | virtual void RxDone(uint8_t *payload, uint16_t size, int16_t rssi, int16_t snr, lora::DownlinkControl ctrl, uint8_t slot) { |
Mike Fiore |
16:b630e18103e5 | 254 | logDebug("mDotEvent - RxDone"); |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 255 | |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 256 | } |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 257 | |
Jenkins@KEILDM1.dc.multitech.prv | 70:0c5b5b02d17b | 258 | virtual void BeaconRx(const lora::BeaconData_t& beacon_data, int16_t rssi, int16_t snr) { |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 259 | logDebug("mDotEvent - BeaconRx"); |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 260 | BeaconLocked = true; |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 261 | BeaconData = beacon_data; |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 262 | } |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 263 | |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 264 | virtual void BeaconLost() { |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 265 | logDebug("mDotEvent - BeaconLost"); |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 266 | BeaconLocked = false; |
Mike Fiore |
16:b630e18103e5 | 267 | } |
Mike Fiore |
16:b630e18103e5 | 268 | |
Jenkins@KEILDM1.dc.multitech.prv | 70:0c5b5b02d17b | 269 | virtual void Pong(int16_t m_rssi, int16_t m_snr, int16_t s_rssi, int16_t s_snr) { |
Mike Fiore |
16:b630e18103e5 | 270 | logDebug("mDotEvent - Pong"); |
Mike Fiore |
16:b630e18103e5 | 271 | PongReceived = true; |
Mike Fiore |
16:b630e18103e5 | 272 | PongRssi = s_rssi; |
Mike Fiore |
16:b630e18103e5 | 273 | PongSnr = s_snr; |
Mike Fiore |
16:b630e18103e5 | 274 | } |
Mike Fiore |
16:b630e18103e5 | 275 | |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 276 | virtual void ServerTime(uint32_t seconds, uint8_t sub_seconds) { |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 277 | logDebug("mDotEvent - ServerTime"); |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 278 | ServerTimeReceived = true; |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 279 | |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 280 | uint64_t current_server_time_ms = static_cast<uint64_t>(seconds) * 1000 + |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 281 | static_cast<uint16_t>(sub_seconds) * 4 + _timeSinceTx.read_ms(); |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 282 | |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 283 | ServerTimeSeconds = static_cast<uint32_t>(current_server_time_ms / 1000); |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 284 | ServerTimeMillis = static_cast<uint16_t>(current_server_time_ms % 1000); |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 285 | } |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 286 | |
Jenkins@KEILDM1.dc.multitech.prv | 70:0c5b5b02d17b | 287 | virtual void NetworkLinkCheck(int16_t m_rssi, int16_t m_snr, int16_t s_snr, uint8_t s_gateways) { |
Mike Fiore |
16:b630e18103e5 | 288 | logDebug("mDotEvent - NetworkLinkCheck"); |
Mike Fiore |
16:b630e18103e5 | 289 | LinkCheckAnsReceived = true; |
Mike Fiore |
16:b630e18103e5 | 290 | DemodMargin = s_snr; |
Mike Fiore |
16:b630e18103e5 | 291 | NbGateways = s_gateways; |
Mike Fiore |
16:b630e18103e5 | 292 | |
Mike Fiore |
16:b630e18103e5 | 293 | _flags.Bits.Tx = 0; |
Mike Fiore |
16:b630e18103e5 | 294 | _flags.Bits.LinkCheck = 1; |
Mike Fiore |
16:b630e18103e5 | 295 | _info.RxRssi = m_rssi; |
Mike Fiore |
16:b630e18103e5 | 296 | _info.RxSnr = m_snr; |
Mike Fiore |
16:b630e18103e5 | 297 | _info.DemodMargin = s_snr; |
Mike Fiore |
16:b630e18103e5 | 298 | _info.NbGateways = s_gateways; |
Mike Fiore |
16:b630e18103e5 | 299 | _info.Status = LORAMAC_EVENT_INFO_STATUS_OK; |
Mike Fiore |
16:b630e18103e5 | 300 | Notify(); |
Mike Fiore |
16:b630e18103e5 | 301 | } |
Mike Fiore |
16:b630e18103e5 | 302 | |
Mike Fiore |
16:b630e18103e5 | 303 | virtual void RxTimeout(uint8_t slot) { |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 304 | logDebug("mDotEvent - RxTimeout on Slot %d", slot); |
Mike Fiore |
16:b630e18103e5 | 305 | |
Mike Fiore |
16:b630e18103e5 | 306 | _flags.Bits.Tx = 0; |
Mike Fiore |
16:b630e18103e5 | 307 | _flags.Bits.RxSlot = slot; |
Mike Fiore |
16:b630e18103e5 | 308 | _info.Status = LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT; |
Mike Fiore |
16:b630e18103e5 | 309 | Notify(); |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 310 | |
Mike Fiore |
16:b630e18103e5 | 311 | } |
Mike Fiore |
16:b630e18103e5 | 312 | |
Mike Fiore |
16:b630e18103e5 | 313 | virtual void RxError(uint8_t slot) { |
Mike Fiore |
16:b630e18103e5 | 314 | logDebug("mDotEvent - RxError"); |
Mike Fiore |
16:b630e18103e5 | 315 | |
Mike Fiore |
16:b630e18103e5 | 316 | memset(&_flags, 0, sizeof(LoRaMacEventFlags)); |
Mike Fiore |
16:b630e18103e5 | 317 | memset(&_info, 0, sizeof(LoRaMacEventInfo)); |
Mike Fiore |
16:b630e18103e5 | 318 | |
Mike Fiore |
16:b630e18103e5 | 319 | _flags.Bits.RxSlot = slot; |
Mike Fiore |
16:b630e18103e5 | 320 | _info.Status = LORAMAC_EVENT_INFO_STATUS_RX_ERROR; |
Mike Fiore |
16:b630e18103e5 | 321 | Notify(); |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 322 | |
Mike Fiore |
16:b630e18103e5 | 323 | } |
Mike Fiore |
16:b630e18103e5 | 324 | |
Mike Fiore |
16:b630e18103e5 | 325 | virtual uint8_t MeasureBattery(void) { |
Mike Fiore |
16:b630e18103e5 | 326 | return 255; |
Mike Fiore |
16:b630e18103e5 | 327 | } |
Mike Fiore |
16:b630e18103e5 | 328 | |
Mike Fiore |
16:b630e18103e5 | 329 | bool LinkCheckAnsReceived; |
Mike Fiore |
16:b630e18103e5 | 330 | uint8_t DemodMargin; |
Mike Fiore |
16:b630e18103e5 | 331 | uint8_t NbGateways; |
Mike Fiore |
16:b630e18103e5 | 332 | |
Mike Fiore |
16:b630e18103e5 | 333 | bool PacketReceived; |
Mike Fiore |
16:b630e18103e5 | 334 | uint8_t RxPort; |
Mike Fiore |
16:b630e18103e5 | 335 | uint8_t RxPayload[255]; |
Mike Fiore |
16:b630e18103e5 | 336 | uint8_t RxPayloadSize; |
Mike Fiore |
16:b630e18103e5 | 337 | |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 338 | bool BeaconLocked; |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 339 | lora::BeaconData_t BeaconData; |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 340 | |
Mike Fiore |
16:b630e18103e5 | 341 | bool PongReceived; |
Mike Fiore |
16:b630e18103e5 | 342 | int16_t PongRssi; |
Mike Fiore |
16:b630e18103e5 | 343 | int16_t PongSnr; |
Mike Fiore |
16:b630e18103e5 | 344 | |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 345 | bool ServerTimeReceived; |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 346 | uint32_t ServerTimeSeconds; |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 347 | uint16_t ServerTimeMillis; |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 348 | |
Mike Fiore |
16:b630e18103e5 | 349 | bool AckReceived; |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 350 | bool DuplicateRx; |
Mike Fiore |
16:b630e18103e5 | 351 | uint8_t TxNbRetries; |
Mike Fiore |
16:b630e18103e5 | 352 | |
Mike Fiore |
16:b630e18103e5 | 353 | LoRaMacEventFlags& Flags() { |
Mike Fiore |
16:b630e18103e5 | 354 | return _flags; |
Mike Fiore |
16:b630e18103e5 | 355 | } |
Mike Fiore |
16:b630e18103e5 | 356 | LoRaMacEventInfo& Info() { |
Mike Fiore |
16:b630e18103e5 | 357 | return _info; |
Mike Fiore |
16:b630e18103e5 | 358 | } |
Mike Fiore |
16:b630e18103e5 | 359 | |
Mike Fiore |
16:b630e18103e5 | 360 | private: |
Mike Fiore |
16:b630e18103e5 | 361 | |
Mike Fiore |
16:b630e18103e5 | 362 | LoRaMacEventFlags _flags; |
Mike Fiore |
16:b630e18103e5 | 363 | LoRaMacEventInfo _info; |
Mike Fiore |
16:b630e18103e5 | 364 | |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 365 | Timer _timeSinceTx; |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 366 | |
Mike Fiore |
16:b630e18103e5 | 367 | // |
Mike Fiore |
16:b630e18103e5 | 368 | // /*! |
Mike Fiore |
16:b630e18103e5 | 369 | // * MAC layer event callback prototype. |
Mike Fiore |
16:b630e18103e5 | 370 | // * |
Mike Fiore |
16:b630e18103e5 | 371 | // * \param [IN] flags Bit field indicating the MAC events occurred |
Mike Fiore |
16:b630e18103e5 | 372 | // * \param [IN] info Details about MAC events occurred |
Mike Fiore |
16:b630e18103e5 | 373 | // */ |
Mike Fiore |
16:b630e18103e5 | 374 | // virtual void MacEvent(LoRaMacEventFlags *flags, LoRaMacEventInfo *info) { |
Mike Fiore |
16:b630e18103e5 | 375 | // logDebug("mDotEvent"); |
Mike Fiore |
16:b630e18103e5 | 376 | // |
Mike Fiore |
16:b630e18103e5 | 377 | // if (flags->Bits.Rx) { |
Mike Fiore |
16:b630e18103e5 | 378 | // logDebug("Rx"); |
Mike Fiore |
16:b630e18103e5 | 379 | // |
Mike Fiore |
16:b630e18103e5 | 380 | // // Event Object must delete RxBuffer |
Mike Fiore |
16:b630e18103e5 | 381 | // delete[] info->RxBuffer; |
Mike Fiore |
16:b630e18103e5 | 382 | // } |
Mike Fiore |
16:b630e18103e5 | 383 | // } |
Mike Fiore |
16:b630e18103e5 | 384 | // |
Mike Fiore |
16:b630e18103e5 | 385 | |
Mike Fiore |
16:b630e18103e5 | 386 | }; |
Mike Fiore |
16:b630e18103e5 | 387 | |
Mike Fiore |
16:b630e18103e5 | 388 | #endif // __MDOT_EVENT_H__ |