The Modified Dot Library for SX1272
This version has been restoring as initial changes.
Verify the following dependencies:
Mbed-os 5.11 libmdot 3.2.0 for Mbed OS5.11
mDotEvent.h@77:7b89990cefd9, 2020-06-21 (annotated)
- Committer:
- danistywukids
- Date:
- Sun Jun 21 04:39:08 2020 +0000
- Revision:
- 77:7b89990cefd9
- Parent:
- 70:0c5b5b02d17b
- Parent:
- 75:268c51ddfc06
Early version fast-forward merge
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 | } |
danistywukids | 75:268c51ddfc06 | 252 | |
danistywukids | 75:268c51ddfc06 | 253 | virtual void PacketRx2(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) { |
danistywukids | 75:268c51ddfc06 | 254 | logDebug("mDotEvent - PacketRx ADDR: %08x", address); |
danistywukids | 75:268c51ddfc06 | 255 | RxPort = port; |
danistywukids | 75:268c51ddfc06 | 256 | PacketReceived = true; |
danistywukids | 75:268c51ddfc06 | 257 | |
danistywukids | 75:268c51ddfc06 | 258 | memcpy(RxPayload, payload, size); |
danistywukids | 75:268c51ddfc06 | 259 | RxPayloadSize = size; |
danistywukids | 75:268c51ddfc06 | 260 | |
danistywukids | 75:268c51ddfc06 | 261 | if (ctrl.Bits.Ack) { |
danistywukids | 75:268c51ddfc06 | 262 | AckReceived = true; |
danistywukids | 75:268c51ddfc06 | 263 | } |
danistywukids | 75:268c51ddfc06 | 264 | |
danistywukids | 75:268c51ddfc06 | 265 | DuplicateRx = dupRx; |
danistywukids | 75:268c51ddfc06 | 266 | |
danistywukids | 75:268c51ddfc06 | 267 | if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) { |
danistywukids | 75:268c51ddfc06 | 268 | std::string packet = mts::Text::bin2hexString(RxPayload, size); |
danistywukids | 75:268c51ddfc06 | 269 | int number = (int)strtol(packet.c_str(), NULL, 16); |
danistywukids | 75:268c51ddfc06 | 270 | logTrace("Payload: %d", number); |
danistywukids | 75:268c51ddfc06 | 271 | } |
danistywukids | 75:268c51ddfc06 | 272 | |
danistywukids | 75:268c51ddfc06 | 273 | _flags.Bits.Tx = 0; |
danistywukids | 75:268c51ddfc06 | 274 | _flags.Bits.Rx = 1; |
danistywukids | 75:268c51ddfc06 | 275 | _flags.Bits.RxData = size > 0; |
danistywukids | 75:268c51ddfc06 | 276 | _flags.Bits.RxSlot = slot; |
danistywukids | 75:268c51ddfc06 | 277 | _info.RxBuffer = payload; |
danistywukids | 75:268c51ddfc06 | 278 | _info.RxBufferSize = size; |
danistywukids | 75:268c51ddfc06 | 279 | _info.RxPort = port; |
danistywukids | 75:268c51ddfc06 | 280 | _info.RxRssi = rssi; |
danistywukids | 75:268c51ddfc06 | 281 | _info.RxSnr = snr; |
danistywukids | 75:268c51ddfc06 | 282 | _info.TxAckReceived = AckReceived; |
danistywukids | 75:268c51ddfc06 | 283 | _info.DuplicateRx = DuplicateRx; |
danistywukids | 75:268c51ddfc06 | 284 | _info.TxNbRetries = retries; |
danistywukids | 75:268c51ddfc06 | 285 | _info.Status = LORAMAC_EVENT_INFO_STATUS_OK; |
danistywukids | 75:268c51ddfc06 | 286 | Notify(); |
danistywukids | 75:268c51ddfc06 | 287 | } |
Mike Fiore |
16:b630e18103e5 | 288 | |
Jenkins@KEILDM1.dc.multitech.prv | 70:0c5b5b02d17b | 289 | 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 | 290 | logDebug("mDotEvent - RxDone"); |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 291 | |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 292 | } |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 293 | |
Jenkins@KEILDM1.dc.multitech.prv | 70:0c5b5b02d17b | 294 | virtual void BeaconRx(const lora::BeaconData_t& beacon_data, int16_t rssi, int16_t snr) { |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 295 | logDebug("mDotEvent - BeaconRx"); |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 296 | BeaconLocked = true; |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 297 | BeaconData = beacon_data; |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 298 | } |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 299 | |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 300 | virtual void BeaconLost() { |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 301 | logDebug("mDotEvent - BeaconLost"); |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 302 | BeaconLocked = false; |
Mike Fiore |
16:b630e18103e5 | 303 | } |
Mike Fiore |
16:b630e18103e5 | 304 | |
Jenkins@KEILDM1.dc.multitech.prv | 70:0c5b5b02d17b | 305 | virtual void Pong(int16_t m_rssi, int16_t m_snr, int16_t s_rssi, int16_t s_snr) { |
Mike Fiore |
16:b630e18103e5 | 306 | logDebug("mDotEvent - Pong"); |
Mike Fiore |
16:b630e18103e5 | 307 | PongReceived = true; |
Mike Fiore |
16:b630e18103e5 | 308 | PongRssi = s_rssi; |
Mike Fiore |
16:b630e18103e5 | 309 | PongSnr = s_snr; |
Mike Fiore |
16:b630e18103e5 | 310 | } |
Mike Fiore |
16:b630e18103e5 | 311 | |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 312 | virtual void ServerTime(uint32_t seconds, uint8_t sub_seconds) { |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 313 | logDebug("mDotEvent - ServerTime"); |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 314 | ServerTimeReceived = true; |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 315 | |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 316 | uint64_t current_server_time_ms = static_cast<uint64_t>(seconds) * 1000 + |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 317 | static_cast<uint16_t>(sub_seconds) * 4 + _timeSinceTx.read_ms(); |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 318 | |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 319 | ServerTimeSeconds = static_cast<uint32_t>(current_server_time_ms / 1000); |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 320 | ServerTimeMillis = static_cast<uint16_t>(current_server_time_ms % 1000); |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 321 | } |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 322 | |
Jenkins@KEILDM1.dc.multitech.prv | 70:0c5b5b02d17b | 323 | virtual void NetworkLinkCheck(int16_t m_rssi, int16_t m_snr, int16_t s_snr, uint8_t s_gateways) { |
Mike Fiore |
16:b630e18103e5 | 324 | logDebug("mDotEvent - NetworkLinkCheck"); |
Mike Fiore |
16:b630e18103e5 | 325 | LinkCheckAnsReceived = true; |
Mike Fiore |
16:b630e18103e5 | 326 | DemodMargin = s_snr; |
Mike Fiore |
16:b630e18103e5 | 327 | NbGateways = s_gateways; |
Mike Fiore |
16:b630e18103e5 | 328 | |
Mike Fiore |
16:b630e18103e5 | 329 | _flags.Bits.Tx = 0; |
Mike Fiore |
16:b630e18103e5 | 330 | _flags.Bits.LinkCheck = 1; |
Mike Fiore |
16:b630e18103e5 | 331 | _info.RxRssi = m_rssi; |
Mike Fiore |
16:b630e18103e5 | 332 | _info.RxSnr = m_snr; |
Mike Fiore |
16:b630e18103e5 | 333 | _info.DemodMargin = s_snr; |
Mike Fiore |
16:b630e18103e5 | 334 | _info.NbGateways = s_gateways; |
Mike Fiore |
16:b630e18103e5 | 335 | _info.Status = LORAMAC_EVENT_INFO_STATUS_OK; |
Mike Fiore |
16:b630e18103e5 | 336 | Notify(); |
Mike Fiore |
16:b630e18103e5 | 337 | } |
Mike Fiore |
16:b630e18103e5 | 338 | |
Mike Fiore |
16:b630e18103e5 | 339 | virtual void RxTimeout(uint8_t slot) { |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 340 | logDebug("mDotEvent - RxTimeout on Slot %d", slot); |
Mike Fiore |
16:b630e18103e5 | 341 | |
Mike Fiore |
16:b630e18103e5 | 342 | _flags.Bits.Tx = 0; |
Mike Fiore |
16:b630e18103e5 | 343 | _flags.Bits.RxSlot = slot; |
Mike Fiore |
16:b630e18103e5 | 344 | _info.Status = LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT; |
Mike Fiore |
16:b630e18103e5 | 345 | Notify(); |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 346 | |
Mike Fiore |
16:b630e18103e5 | 347 | } |
Mike Fiore |
16:b630e18103e5 | 348 | |
Mike Fiore |
16:b630e18103e5 | 349 | virtual void RxError(uint8_t slot) { |
Mike Fiore |
16:b630e18103e5 | 350 | logDebug("mDotEvent - RxError"); |
Mike Fiore |
16:b630e18103e5 | 351 | |
Mike Fiore |
16:b630e18103e5 | 352 | memset(&_flags, 0, sizeof(LoRaMacEventFlags)); |
Mike Fiore |
16:b630e18103e5 | 353 | memset(&_info, 0, sizeof(LoRaMacEventInfo)); |
Mike Fiore |
16:b630e18103e5 | 354 | |
Mike Fiore |
16:b630e18103e5 | 355 | _flags.Bits.RxSlot = slot; |
Mike Fiore |
16:b630e18103e5 | 356 | _info.Status = LORAMAC_EVENT_INFO_STATUS_RX_ERROR; |
Mike Fiore |
16:b630e18103e5 | 357 | Notify(); |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 358 | |
Mike Fiore |
16:b630e18103e5 | 359 | } |
Mike Fiore |
16:b630e18103e5 | 360 | |
Mike Fiore |
16:b630e18103e5 | 361 | virtual uint8_t MeasureBattery(void) { |
Mike Fiore |
16:b630e18103e5 | 362 | return 255; |
Mike Fiore |
16:b630e18103e5 | 363 | } |
Mike Fiore |
16:b630e18103e5 | 364 | |
Mike Fiore |
16:b630e18103e5 | 365 | bool LinkCheckAnsReceived; |
Mike Fiore |
16:b630e18103e5 | 366 | uint8_t DemodMargin; |
Mike Fiore |
16:b630e18103e5 | 367 | uint8_t NbGateways; |
Mike Fiore |
16:b630e18103e5 | 368 | |
Mike Fiore |
16:b630e18103e5 | 369 | bool PacketReceived; |
Mike Fiore |
16:b630e18103e5 | 370 | uint8_t RxPort; |
Mike Fiore |
16:b630e18103e5 | 371 | uint8_t RxPayload[255]; |
Mike Fiore |
16:b630e18103e5 | 372 | uint8_t RxPayloadSize; |
Mike Fiore |
16:b630e18103e5 | 373 | |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 374 | bool BeaconLocked; |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 375 | lora::BeaconData_t BeaconData; |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 376 | |
Mike Fiore |
16:b630e18103e5 | 377 | bool PongReceived; |
Mike Fiore |
16:b630e18103e5 | 378 | int16_t PongRssi; |
Mike Fiore |
16:b630e18103e5 | 379 | int16_t PongSnr; |
Mike Fiore |
16:b630e18103e5 | 380 | |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 381 | bool ServerTimeReceived; |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 382 | uint32_t ServerTimeSeconds; |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 383 | uint16_t ServerTimeMillis; |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 384 | |
Mike Fiore |
16:b630e18103e5 | 385 | bool AckReceived; |
Jenkins@KEILDM1.dc.multitech.prv | 64:64982192a2af | 386 | bool DuplicateRx; |
Mike Fiore |
16:b630e18103e5 | 387 | uint8_t TxNbRetries; |
Mike Fiore |
16:b630e18103e5 | 388 | |
Mike Fiore |
16:b630e18103e5 | 389 | LoRaMacEventFlags& Flags() { |
Mike Fiore |
16:b630e18103e5 | 390 | return _flags; |
Mike Fiore |
16:b630e18103e5 | 391 | } |
Mike Fiore |
16:b630e18103e5 | 392 | LoRaMacEventInfo& Info() { |
Mike Fiore |
16:b630e18103e5 | 393 | return _info; |
Mike Fiore |
16:b630e18103e5 | 394 | } |
Mike Fiore |
16:b630e18103e5 | 395 | |
Mike Fiore |
16:b630e18103e5 | 396 | private: |
Mike Fiore |
16:b630e18103e5 | 397 | |
Mike Fiore |
16:b630e18103e5 | 398 | LoRaMacEventFlags _flags; |
Mike Fiore |
16:b630e18103e5 | 399 | LoRaMacEventInfo _info; |
Mike Fiore |
16:b630e18103e5 | 400 | |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 401 | Timer _timeSinceTx; |
Jenkins@KEILDM1.dc.multitech.prv | 65:acc0468b9aec | 402 | |
Mike Fiore |
16:b630e18103e5 | 403 | // |
Mike Fiore |
16:b630e18103e5 | 404 | // /*! |
Mike Fiore |
16:b630e18103e5 | 405 | // * MAC layer event callback prototype. |
Mike Fiore |
16:b630e18103e5 | 406 | // * |
Mike Fiore |
16:b630e18103e5 | 407 | // * \param [IN] flags Bit field indicating the MAC events occurred |
Mike Fiore |
16:b630e18103e5 | 408 | // * \param [IN] info Details about MAC events occurred |
Mike Fiore |
16:b630e18103e5 | 409 | // */ |
Mike Fiore |
16:b630e18103e5 | 410 | // virtual void MacEvent(LoRaMacEventFlags *flags, LoRaMacEventInfo *info) { |
Mike Fiore |
16:b630e18103e5 | 411 | // logDebug("mDotEvent"); |
Mike Fiore |
16:b630e18103e5 | 412 | // |
Mike Fiore |
16:b630e18103e5 | 413 | // if (flags->Bits.Rx) { |
Mike Fiore |
16:b630e18103e5 | 414 | // logDebug("Rx"); |
Mike Fiore |
16:b630e18103e5 | 415 | // |
Mike Fiore |
16:b630e18103e5 | 416 | // // Event Object must delete RxBuffer |
Mike Fiore |
16:b630e18103e5 | 417 | // delete[] info->RxBuffer; |
Mike Fiore |
16:b630e18103e5 | 418 | // } |
Mike Fiore |
16:b630e18103e5 | 419 | // } |
Mike Fiore |
16:b630e18103e5 | 420 | // |
Mike Fiore |
16:b630e18103e5 | 421 | |
Mike Fiore |
16:b630e18103e5 | 422 | }; |
Mike Fiore |
16:b630e18103e5 | 423 | |
Mike Fiore |
16:b630e18103e5 | 424 | #endif // __MDOT_EVENT_H__ |