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.
plans/ChannelPlan_AS923.cpp@172:7ec44396a51b, 2018-08-30 (annotated)
- Committer:
- Jenkins@KEILDM1.dc.multitech.prv
- Date:
- Thu Aug 30 09:05:16 2018 -0500
- Revision:
- 172:7ec44396a51b
- Parent:
- 167:09fd17fee0f5
- Child:
- 178:8f7d93f3bbb5
mdot-library revision 3.1.0-class-b-alpha-1-15-g0c33f0a and mbed-os revision mbed-os-5.7.7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1 | /********************************************************************** |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 2 | * COPYRIGHT 2016 MULTI-TECH SYSTEMS, INC. |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 3 | * |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 4 | * ALL RIGHTS RESERVED BY AND FOR THE EXCLUSIVE BENEFIT OF |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 5 | * MULTI-TECH SYSTEMS, INC. |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 6 | * |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 7 | * MULTI-TECH SYSTEMS, INC. - CONFIDENTIAL AND PROPRIETARY |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 8 | * INFORMATION AND/OR TRADE SECRET. |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 9 | * |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 10 | * NOTICE: ALL CODE, PROGRAM, INFORMATION, SCRIPT, INSTRUCTION, |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 11 | * DATA, AND COMMENT HEREIN IS AND SHALL REMAIN THE CONFIDENTIAL |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 12 | * INFORMATION AND PROPERTY OF MULTI-TECH SYSTEMS, INC. |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 13 | * USE AND DISCLOSURE THEREOF, EXCEPT AS STRICTLY AUTHORIZED IN A |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 14 | * WRITTEN AGREEMENT SIGNED BY MULTI-TECH SYSTEMS, INC. IS PROHIBITED. |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 15 | * |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 16 | ***********************************************************************/ |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 17 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 18 | #include "ChannelPlan_AS923.h" |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 19 | #include "limits.h" |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 20 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 21 | using namespace lora; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 22 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 23 | const uint8_t ChannelPlan_AS923::AS923_RADIO_POWERS[] = { 3, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 18, 19, 20 }; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 24 | const uint8_t ChannelPlan_AS923::AS923_MAX_PAYLOAD_SIZE[] = { 51, 51, 51, 115, 242, 242, 242, 242, 0, 0, 0, 0, 0, 0, 0, 0 }; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 25 | const uint8_t ChannelPlan_AS923::AS923_MAX_PAYLOAD_SIZE_REPEATER[] = { 51, 51, 51, 115, 222, 222, 222, 222, 0, 0, 0, 0, 0, 0, 0, 0 }; |
Jenkins@KEILDM1.dc.multitech.prv | 152:34599f2c02c7 | 26 | const uint8_t ChannelPlan_AS923::AS923_MAX_PAYLOAD_SIZE_400[] = { 0, 0, 11, 53, 125, 242, 242, 242, 0, 0, 0, 0, 0, 0, 0, 0 }; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 27 | const uint8_t ChannelPlan_AS923::AS923_MAX_PAYLOAD_SIZE_REPEATER_400[] = { 0, 0, 11, 53, 125, 222, 222, 222, 0, 0, 0, 0, 0, 0, 0, 0 }; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 28 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 29 | const uint8_t MAX_ERP_VALUES[] = { 8, 10, 12, 13, 14, 16, 18, 20, 21, 24, 26, 27, 29, 30, 33, 36 }; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 30 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 31 | ChannelPlan_AS923::ChannelPlan_AS923() |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 32 | : |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 33 | ChannelPlan(NULL, NULL) |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 34 | { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 35 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 36 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 37 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 38 | ChannelPlan_AS923::ChannelPlan_AS923(Settings* settings) |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 39 | : |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 40 | ChannelPlan(NULL, settings) |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 41 | { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 42 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 43 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 44 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 45 | ChannelPlan_AS923::ChannelPlan_AS923(SxRadio* radio, Settings* settings) |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 46 | : |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 47 | ChannelPlan(radio, settings) |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 48 | { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 49 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 50 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 51 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 52 | ChannelPlan_AS923::~ChannelPlan_AS923() { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 53 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 54 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 55 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 56 | void ChannelPlan_AS923::Init() { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 57 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 58 | _datarates.clear(); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 59 | _channels.clear(); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 60 | _dutyBands.clear(); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 61 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 62 | DutyBand band; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 63 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 64 | band.Index = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 65 | band.DutyCycle = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 66 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 67 | Datarate dr; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 68 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 69 | _plan = AS923; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 70 | _planName = "AS923"; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 71 | _maxTxPower = 36; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 72 | _minTxPower = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 73 | |
Jenkins@KEILDM1.dc.multitech.prv | 160:cabd3925fe66 | 74 | _minFrequency = 915000000; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 75 | _maxFrequency = 928000000; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 76 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 77 | RADIO_POWERS = AS923_RADIO_POWERS; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 78 | MAX_PAYLOAD_SIZE = AS923_MAX_PAYLOAD_SIZE; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 79 | MAX_PAYLOAD_SIZE_REPEATER = AS923_MAX_PAYLOAD_SIZE_REPEATER; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 80 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 81 | _minDatarate = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 82 | _maxDatarate = 7; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 83 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 84 | _minRx2Datarate = DR_0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 85 | _maxRx2Datarate = DR_7; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 86 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 87 | _minDatarateOffset = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 88 | _maxDatarateOffset = 7; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 89 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 90 | _numChans125k = 16; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 91 | _numChans500k = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 92 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 93 | GetSettings()->Session.Rx2Frequency = 923200000; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 94 | GetSettings()->Session.Rx2DatarateIndex = DR_2; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 95 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 96 | GetSettings()->Session.BeaconFrequency = AS923_BEACON_FREQ; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 97 | GetSettings()->Session.BeaconDatarateIndex = AS923_BEACON_DR; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 98 | GetSettings()->Session.PingSlotFrequency = AS923_BEACON_FREQ; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 99 | GetSettings()->Session.PingSlotDatarateIndex = AS923_BEACON_DR; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 100 | |
Jenkins@KEILDM1.dc.multitech.prv | 125:e2a22b15adaa | 101 | GetSettings()->Session.Max_EIRP = 16; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 102 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 103 | logInfo("Initialize datarates..."); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 104 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 105 | dr.SpreadingFactor = SF_12; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 106 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 107 | // Add DR0-5 |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 108 | while (dr.SpreadingFactor >= SF_7) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 109 | AddDatarate(-1, dr); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 110 | dr.SpreadingFactor--; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 111 | dr.Index++; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 112 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 113 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 114 | // Add DR6 |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 115 | dr.SpreadingFactor = SF_7; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 116 | dr.Bandwidth = BW_250; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 117 | AddDatarate(-1, dr); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 118 | dr.Index++; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 119 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 120 | // Add DR7 |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 121 | dr.SpreadingFactor = SF_FSK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 122 | dr.Bandwidth = BW_FSK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 123 | dr.PreambleLength = 10; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 124 | dr.Coderate = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 125 | AddDatarate(-1, dr); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 126 | dr.Index++; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 127 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 128 | _maxDatarate = DR_7; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 129 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 130 | // Skip DR8-15 RFU |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 131 | dr.SpreadingFactor = SF_INVALID; |
Jenkins@KEILDM1.dc.multitech.prv | 118:64f20bc150dd | 132 | while (dr.Index++ <= DR_15) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 133 | AddDatarate(-1, dr); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 134 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 135 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 136 | GetSettings()->Session.TxDatarate = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 137 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 138 | logInfo("Initialize channels..."); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 139 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 140 | Channel chan; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 141 | chan.DrRange.Fields.Min = DR_0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 142 | chan.DrRange.Fields.Max = DR_5; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 143 | chan.Index = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 144 | chan.Frequency = 923200000; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 145 | SetNumberOfChannels(16); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 146 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 147 | for (uint8_t i = 0; i < 2; i++) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 148 | AddChannel(i, chan); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 149 | chan.Index++; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 150 | chan.Frequency += 200000; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 151 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 152 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 153 | chan.DrRange.Value = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 154 | chan.Frequency = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 155 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 156 | for (uint8_t i = 2; i < 16; i++) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 157 | AddChannel(i, chan); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 158 | chan.Index++; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 159 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 160 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 161 | SetChannelMask(0, 0x03); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 162 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 163 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 164 | // Add downlink channel defaults |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 165 | chan.Index = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 166 | _dlChannels.resize(16); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 167 | for (uint8_t i = 0; i < 16; i++) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 168 | AddDownlinkChannel(i, chan); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 169 | chan.Index++; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 170 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 171 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 172 | band.Index = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 173 | band.FrequencyMin = _minFrequency; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 174 | band.FrequencyMax = _maxFrequency; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 175 | band.PowerMax = 14; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 176 | band.TimeOffEnd = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 177 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 178 | // Disable duty-cycle limits |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 179 | band.DutyCycle = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 180 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 181 | AddDutyBand(-1, band); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 182 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 183 | GetSettings()->Session.TxPower = GetSettings()->Network.TxPower; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 184 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 185 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 186 | uint8_t ChannelPlan_AS923::AddChannel(int8_t index, Channel channel) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 187 | logTrace("Add Channel %d : %lu : %02x %d", index, channel.Frequency, channel.DrRange.Value, _channels.size()); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 188 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 189 | assert(index < (int) _channels.size()); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 190 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 191 | if (index >= 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 192 | _channels[index] = channel; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 193 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 194 | _channels.push_back(channel); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 195 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 196 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 197 | return LORA_OK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 198 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 199 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 200 | uint8_t ChannelPlan_AS923::HandleJoinAccept(const uint8_t* buffer, uint8_t size) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 201 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 202 | if (size == 33) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 203 | Channel ch; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 204 | int index = 2; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 205 | for (int i = 13; i < size - 5; i += 3) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 206 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 207 | ch.Frequency = ((buffer[i]) | (buffer[i + 1] << 8) | (buffer[i + 2] << 16)) * 100u; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 208 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 209 | if (ch.Frequency > 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 210 | ch.Index = index; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 211 | ch.DrRange.Fields.Min = static_cast<int8_t>(DR_0); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 212 | ch.DrRange.Fields.Max = static_cast<int8_t>(DR_5); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 213 | AddChannel(index, ch); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 214 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 215 | if (GetDutyBand(ch.Frequency) > -1) |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 216 | _channelMask[0] |= (1 << index); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 217 | else |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 218 | _channelMask[0] |= ~(1 << index); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 219 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 220 | index += 1; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 221 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 222 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 223 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 224 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 225 | return LORA_OK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 226 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 227 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 228 | uint8_t ChannelPlan_AS923::SetTxConfig() { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 229 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 230 | logInfo("Configure radio for TX"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 231 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 232 | Datarate txDr = GetDatarate(GetSettings()->Session.TxDatarate); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 233 | int8_t max_pwr = GetSettings()->Session.Max_EIRP; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 234 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 235 | int8_t pwr = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 236 | |
Jenkins@KEILDM1.dc.multitech.prv | 167:09fd17fee0f5 | 237 | pwr = std::min < int8_t > (GetSettings()->Session.TxPower, max_pwr); |
Jenkins@KEILDM1.dc.multitech.prv | 167:09fd17fee0f5 | 238 | pwr -= GetSettings()->Network.AntennaGain; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 239 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 240 | for (int i = 20; i >= 0; i--) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 241 | if (RADIO_POWERS[i] <= pwr) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 242 | pwr = i; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 243 | break; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 244 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 245 | if (i == 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 246 | pwr = i; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 247 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 248 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 249 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 250 | logDebug("Session pwr: %d ant: %d max: %d", GetSettings()->Session.TxPower, GetSettings()->Network.AntennaGain, max_pwr); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 251 | logDebug("Radio Power index: %d output: %d total: %d", pwr, RADIO_POWERS[pwr], RADIO_POWERS[pwr] + GetSettings()->Network.AntennaGain); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 252 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 253 | uint32_t bw = txDr.Bandwidth; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 254 | uint32_t sf = txDr.SpreadingFactor; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 255 | uint8_t cr = txDr.Coderate; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 256 | uint8_t pl = txDr.PreambleLength; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 257 | uint16_t fdev = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 258 | bool crc = txDr.Crc; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 259 | bool iq = txDr.TxIQ; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 260 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 261 | if (GetSettings()->Network.DisableCRC == true) |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 262 | crc = false; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 263 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 264 | SxRadio::RadioModems_t modem = SxRadio::MODEM_LORA; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 265 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 266 | if (sf == SF_FSK) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 267 | modem = SxRadio::MODEM_FSK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 268 | sf = 50e3; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 269 | fdev = 25e3; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 270 | bw = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 271 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 272 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 273 | GetRadio()->SetTxConfig(modem, pwr, fdev, bw, sf, cr, pl, false, crc, false, 0, iq, 3e3); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 274 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 275 | logDebug("TX PWR: %u DR: %u SF: %u BW: %u CR: %u PL: %u CRC: %d IQ: %d", pwr, txDr.Index, sf, bw, cr, pl, crc, iq); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 276 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 277 | return LORA_OK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 278 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 279 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 280 | uint8_t ChannelPlan_AS923::SetRxConfig(uint8_t window, bool continuous, uint16_t wnd_growth) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 281 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 282 | RxWindow rxw = GetRxWindow(window); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 283 | |
Jenkins@KEILDM1.dc.multitech.prv | 157:8e9b1e84ffac | 284 | if (_dlChannels[_txChannel].Frequency != 0 && window == 1) |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 285 | GetRadio()->SetChannel(_dlChannels[_txChannel].Frequency); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 286 | else |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 287 | GetRadio()->SetChannel(rxw.Frequency); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 288 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 289 | Datarate rxDr = GetDatarate(rxw.DatarateIndex); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 290 | uint32_t bw = rxDr.Bandwidth; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 291 | uint32_t sf = rxDr.SpreadingFactor; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 292 | uint8_t cr = rxDr.Coderate; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 293 | uint8_t pl = rxDr.PreambleLength; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 294 | uint16_t sto = rxDr.SymbolTimeout() * wnd_growth; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 295 | uint32_t afc = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 296 | bool fixLen = false; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 297 | uint8_t payloadLen = 0U; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 298 | bool crc = false; // downlink does not use CRC according to LORAWAN |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 299 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 300 | if (GetSettings()->Network.DisableCRC == true) |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 301 | crc = false; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 302 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 303 | Datarate txDr = GetDatarate(GetSettings()->Session.TxDatarate); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 304 | bool iq = txDr.RxIQ; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 305 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 306 | if (P2PEnabled()) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 307 | iq = txDr.TxIQ; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 308 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 309 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 310 | // Beacon modifications - no I/Q inversion, fixed length rx, preamble |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 311 | if (window == RX_BEACON) { |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 312 | iq = txDr.TxIQ; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 313 | fixLen = true; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 314 | payloadLen = sizeof(BCNPayload); |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 315 | pl = BEACON_PREAMBLE_LENGTH; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 316 | } |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 317 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 318 | SxRadio::RadioModems_t modem = SxRadio::MODEM_LORA; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 319 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 320 | if (sf == SF_FSK) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 321 | modem = SxRadio::MODEM_FSK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 322 | sf = 50e3; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 323 | cr = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 324 | bw = 50e3; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 325 | afc = 83333; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 326 | iq = false; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 327 | crc = true; // FSK must use CRC |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 328 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 329 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 330 | // Disable printf's to actually receive packets, printing to debug may mess up the timing |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 331 | // logTrace("Configure radio for RX%d on freq: %lu", window, rxw.Frequency); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 332 | // logTrace("RX SF: %u BW: %u CR: %u PL: %u STO: %u CRC: %d IQ: %d", sf, bw, cr, pl, sto, crc, iq); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 333 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 334 | GetRadio()->SetRxConfig(modem, bw, sf, cr, afc, pl, sto, fixLen, payloadLen, crc, false, 0, iq, continuous); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 335 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 336 | return LORA_OK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 337 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 338 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 339 | Channel ChannelPlan_AS923::GetChannel(int8_t index) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 340 | Channel chan; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 341 | memset(&chan, 0, sizeof(Channel)); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 342 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 343 | chan = _channels[index]; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 344 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 345 | return chan; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 346 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 347 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 348 | uint8_t ChannelPlan_AS923::SetFrequencySubBand(uint8_t sub_band) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 349 | return LORA_OK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 350 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 351 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 352 | void ChannelPlan_AS923::LogRxWindow(uint8_t wnd) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 353 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 354 | RxWindow rxw = GetRxWindow(wnd); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 355 | Datarate rxDr = GetDatarate(rxw.DatarateIndex); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 356 | uint8_t bw = rxDr.Bandwidth; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 357 | uint8_t sf = rxDr.SpreadingFactor; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 358 | uint8_t cr = rxDr.Coderate; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 359 | uint8_t pl = rxDr.PreambleLength; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 360 | uint16_t sto = rxDr.SymbolTimeout(); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 361 | bool crc = false; // downlink does not use CRC according to LORAWAN |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 362 | bool iq = GetTxDatarate().RxIQ; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 363 | uint32_t freq = rxw.Frequency; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 364 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 365 | if (_dlChannels[_txChannel].Frequency != 0) |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 366 | freq = _dlChannels[_txChannel].Frequency; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 367 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 368 | logTrace("RX%d on freq: %lu", wnd, freq); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 369 | logTrace("RX DR: %u SF: %u BW: %u CR: %u PL: %u STO: %u CRC: %d IQ: %d", rxDr.Index, sf, bw, cr, pl, sto, crc, iq); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 370 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 371 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 372 | uint8_t ChannelPlan_AS923::GetMaxPayloadSize() { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 373 | if (GetSettings()->Session.UplinkDwelltime == 1) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 374 | if (GetSettings()->Network.RepeaterMode) |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 375 | return AS923_MAX_PAYLOAD_SIZE_REPEATER_400[GetSettings()->Session.TxDatarate]; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 376 | else |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 377 | return AS923_MAX_PAYLOAD_SIZE_400[GetSettings()->Session.TxDatarate]; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 378 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 379 | if (GetSettings()->Network.RepeaterMode) |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 380 | return MAX_PAYLOAD_SIZE_REPEATER[GetSettings()->Session.TxDatarate]; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 381 | else |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 382 | return MAX_PAYLOAD_SIZE[GetSettings()->Session.TxDatarate]; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 383 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 384 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 385 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 386 | RxWindow ChannelPlan_AS923::GetRxWindow(uint8_t window) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 387 | RxWindow rxw; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 388 | int index = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 389 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 390 | if (P2PEnabled()) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 391 | rxw.Frequency = GetSettings()->Network.TxFrequency; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 392 | index = GetSettings()->Session.TxDatarate; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 393 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 394 | switch (window) { |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 395 | case RX_1: |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 396 | { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 397 | // Use same frequency as TX |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 398 | rxw.Frequency = _channels[_txChannel].Frequency; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 399 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 400 | if (GetSettings()->Session.Rx1DatarateOffset >= 6) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 401 | index = GetSettings()->Session.TxDatarate + (GetSettings()->Session.Rx1DatarateOffset == 6 ? 1 : 2); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 402 | index = std::min<int>(index, _maxDatarate); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 403 | } else if (GetSettings()->Session.TxDatarate > GetSettings()->Session.Rx1DatarateOffset) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 404 | index = GetSettings()->Session.TxDatarate - GetSettings()->Session.Rx1DatarateOffset; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 405 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 406 | index = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 407 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 408 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 409 | // LoRaWAN 1.0.2 Sec 2.7.7 |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 410 | uint8_t minDr = GetSettings()->Session.DownlinkDwelltime == 1 ? 2 : 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 411 | index = std::min<uint8_t>(5, std::max<uint8_t>(minDr, index)); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 412 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 413 | break; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 414 | } |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 415 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 416 | case RX_BEACON: |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 417 | rxw.Frequency = GetSettings()->Session.BeaconFrequency; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 418 | index = GetSettings()->Session.BeaconDatarateIndex; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 419 | break; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 420 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 421 | case RX_SLOT: |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 422 | rxw.Frequency = GetSettings()->Session.PingSlotFrequency; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 423 | index = GetSettings()->Session.PingSlotDatarateIndex; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 424 | break; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 425 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 426 | // RX2, RXC, RX_TEST, etc.. |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 427 | default: |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 428 | rxw.Frequency = GetSettings()->Session.Rx2Frequency; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 429 | index = GetSettings()->Session.Rx2DatarateIndex; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 430 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 431 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 432 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 433 | rxw.DatarateIndex = index; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 434 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 435 | return rxw; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 436 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 437 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 438 | uint8_t ChannelPlan_AS923::HandleRxParamSetup(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 439 | status = 0x07; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 440 | int8_t datarate = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 441 | int8_t drOffset = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 442 | uint32_t freq = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 443 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 444 | drOffset = payload[index++]; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 445 | datarate = drOffset & 0x0F; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 446 | drOffset = (drOffset >> 4) & 0x07; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 447 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 448 | freq = payload[index++]; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 449 | freq |= payload[index++] << 8; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 450 | freq |= payload[index++] << 16; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 451 | freq *= 100; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 452 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 453 | if (!CheckRfFrequency(freq)) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 454 | logInfo("Freq KO"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 455 | status &= 0xFE; // Channel frequency KO |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 456 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 457 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 458 | if (datarate < _minRx2Datarate || datarate > _maxRx2Datarate) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 459 | logInfo("DR KO"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 460 | status &= 0xFD; // Datarate KO |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 461 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 462 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 463 | if (drOffset < 0 || drOffset > _maxDatarateOffset) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 464 | logInfo("DR Offset KO"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 465 | status &= 0xFB; // Rx1DrOffset range KO |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 466 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 467 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 468 | if ((status & 0x07) == 0x07) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 469 | logInfo("RxParamSetup accepted Rx2DR: %d Rx2Freq: %d Rx1Offset: %d", datarate, freq, drOffset); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 470 | SetRx2DatarateIndex(datarate); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 471 | SetRx2Frequency(freq); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 472 | SetRx1Offset(drOffset); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 473 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 474 | logInfo("RxParamSetup rejected Rx2DR: %d Rx2Freq: %d Rx1Offset: %d", datarate, freq, drOffset); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 475 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 476 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 477 | return LORA_OK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 478 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 479 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 480 | uint8_t ChannelPlan_AS923::HandleNewChannel(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 481 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 482 | status = 0x03; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 483 | uint8_t channelIndex = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 484 | Channel chParam; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 485 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 486 | channelIndex = payload[index++]; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 487 | lora::CopyFreqtoInt(payload + index, chParam.Frequency); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 488 | index += 3; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 489 | chParam.DrRange.Value = payload[index++]; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 490 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 491 | if (channelIndex < 2 || channelIndex > _channels.size() - 1) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 492 | logError("New Channel index KO"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 493 | status &= 0xFE; // Channel index KO |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 494 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 495 | |
Jenkins@KEILDM1.dc.multitech.prv | 151:2242ecfd733a | 496 | if (chParam.Frequency == 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 151:2242ecfd733a | 497 | chParam.DrRange.Value = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 151:2242ecfd733a | 498 | } else if (chParam.Frequency < _minFrequency || chParam.Frequency > _maxFrequency) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 499 | logError("New Channel frequency KO"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 500 | status &= 0xFE; // Channel frequency KO |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 501 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 502 | |
Jenkins@KEILDM1.dc.multitech.prv | 151:2242ecfd733a | 503 | if (chParam.DrRange.Fields.Min > chParam.DrRange.Fields.Max && chParam.Frequency != 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 504 | logError("New Channel datarate min/max KO"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 505 | status &= 0xFD; // Datarate range KO |
Jenkins@KEILDM1.dc.multitech.prv | 151:2242ecfd733a | 506 | } else if ((chParam.DrRange.Fields.Min < _minDatarate || chParam.DrRange.Fields.Min > _maxDatarate) && |
Jenkins@KEILDM1.dc.multitech.prv | 151:2242ecfd733a | 507 | chParam.Frequency != 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 508 | logError("New Channel datarate min KO"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 509 | status &= 0xFD; // Datarate range KO |
Jenkins@KEILDM1.dc.multitech.prv | 151:2242ecfd733a | 510 | } else if ((chParam.DrRange.Fields.Max < _minDatarate || chParam.DrRange.Fields.Max > _maxDatarate) && |
Jenkins@KEILDM1.dc.multitech.prv | 151:2242ecfd733a | 511 | chParam.Frequency != 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 512 | logError("New Channel datarate max KO"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 513 | status &= 0xFD; // Datarate range KO |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 514 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 515 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 516 | if ((status & 0x03) == 0x03) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 517 | logInfo("New Channel accepted index: %d freq: %lu drRange: %02x", channelIndex, chParam.Frequency, chParam.DrRange.Value); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 518 | AddChannel(channelIndex, chParam); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 519 | SetChannelMask(0, _channelMask[0] | 1 << (channelIndex)); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 520 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 521 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 522 | return LORA_OK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 523 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 524 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 525 | uint8_t ChannelPlan_AS923::HandlePingSlotChannelReq(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status) { |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 526 | uint8_t datarate = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 527 | uint32_t freq = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 528 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 529 | status = 0x03; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 530 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 531 | freq = payload[index++]; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 532 | freq |= payload[index++] << 8; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 533 | freq |= payload[index++] << 16; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 534 | freq *= 100; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 535 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 536 | datarate = payload[index] & 0x0F; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 537 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 538 | if (freq == 0U) { |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 539 | logInfo("Received request to reset ping slot frequency to default"); |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 540 | freq = AS923_BEACON_FREQ; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 541 | } else if (!CheckRfFrequency(freq)) { |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 542 | logInfo("Freq KO"); |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 543 | status &= 0xFE; // Channel frequency KO |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 544 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 545 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 546 | if (datarate < _minRx2Datarate || datarate > _maxRx2Datarate) { |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 547 | logInfo("DR KO"); |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 548 | status &= 0xFD; // Datarate KO |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 549 | } |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 550 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 551 | if ((status & 0x03) == 0x03) { |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 552 | logInfo("PingSlotChannelReq accepted DR: %d Freq: %d", datarate, freq); |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 553 | GetSettings()->Session.PingSlotFrequency = freq; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 554 | GetSettings()->Session.PingSlotDatarateIndex = datarate; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 555 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 556 | logInfo("PingSlotChannelReq rejected DR: %d Freq: %d", datarate, freq); |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 557 | } |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 558 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 559 | return LORA_OK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 560 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 561 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 562 | uint8_t ChannelPlan_AS923::HandleBeaconFrequencyReq(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status) { |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 563 | uint32_t freq = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 564 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 565 | status = 0x01; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 566 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 567 | freq = payload[index++]; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 568 | freq |= payload[index++] << 8; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 569 | freq |= payload[index] << 16; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 570 | freq *= 100; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 571 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 572 | if (freq == 0U) { |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 573 | logInfo("Received request to reset beacon frequency to default"); |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 574 | freq = AS923_BEACON_FREQ; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 575 | } else if (!CheckRfFrequency(freq)) { |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 576 | logInfo("Freq KO"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 577 | status &= 0xFE; // Channel frequency KO |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 578 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 579 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 580 | if (status & 0x01) { |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 581 | logInfo("BeaconFrequencyReq accepted Freq: %d", freq); |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 582 | GetSettings()->Session.BeaconFrequency = freq; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 583 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 584 | logInfo("BeaconFrequencyReq rejected Freq: %d", freq); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 585 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 586 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 587 | return LORA_OK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 588 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 589 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 590 | uint8_t ChannelPlan_AS923::HandleAdrCommand(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 591 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 592 | uint8_t power = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 593 | uint8_t datarate = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 594 | uint16_t mask = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 595 | uint16_t new_mask = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 596 | uint8_t ctrl = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 597 | uint8_t nbRep = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 598 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 599 | status = 0x07; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 600 | datarate = payload[index++]; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 601 | power = datarate & 0x0F; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 602 | datarate = (datarate >> 4) & 0x0F; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 603 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 604 | mask = payload[index++]; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 605 | mask |= payload[index++] << 8; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 606 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 607 | nbRep = payload[index++]; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 608 | ctrl = (nbRep >> 4) & 0x07; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 609 | nbRep &= 0x0F; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 610 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 611 | if (nbRep == 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 612 | nbRep = 1; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 613 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 614 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 615 | if (datarate > _maxDatarate) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 616 | status &= 0xFD; // Datarate KO |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 617 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 618 | // |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 619 | // Remark MaxTxPower = 0 and MinTxPower = 7 |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 620 | // |
Jenkins@KEILDM1.dc.multitech.prv | 151:2242ecfd733a | 621 | if (power > 7) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 622 | status &= 0xFB; // TxPower KO |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 623 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 624 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 625 | switch (ctrl) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 626 | case 0: |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 627 | SetChannelMask(0, mask); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 628 | break; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 629 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 630 | case 6: |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 631 | // enable all currently defined channels |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 632 | // set bits 0 - N of a number by (2<<N)-1 |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 633 | new_mask = (1 << _channels.size()) - 1; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 634 | SetChannelMask(0, new_mask); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 635 | break; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 636 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 637 | default: |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 638 | logWarning("rejecting RFU or unknown control value %d", ctrl); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 639 | status &= 0xFE; // ChannelMask KO |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 640 | return LORA_ERROR; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 641 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 642 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 643 | if (GetSettings()->Network.ADREnabled) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 644 | GetSettings()->Session.TxDatarate = datarate; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 645 | GetSettings()->Session.TxPower = GetSettings()->Session.Max_EIRP - (power * 2); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 646 | GetSettings()->Session.Redundancy = nbRep; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 647 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 648 | logDebug("ADR is disabled, DR and Power not changed."); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 649 | status &= 0xFB; // TxPower KO |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 650 | status &= 0xFD; // Datarate KO |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 651 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 652 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 653 | logDebug("ADR DR: %u PWR: %u Ctrl: %02x Mask: %04x NbRep: %u Stat: %02x", datarate, power, ctrl, mask, nbRep, status); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 654 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 655 | return LORA_OK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 656 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 657 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 658 | uint8_t ChannelPlan_AS923::ValidateAdrConfiguration() { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 659 | uint8_t status = 0x07; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 660 | uint8_t datarate = GetSettings()->Session.TxDatarate; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 661 | uint8_t power = GetSettings()->Session.TxPower; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 662 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 663 | if (!GetSettings()->Network.ADREnabled) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 664 | logDebug("ADR disabled - no applied changes to validate"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 665 | return status; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 666 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 667 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 668 | if (datarate > _maxDatarate) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 669 | logWarning("ADR Datarate KO - outside allowed range"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 670 | status &= 0xFD; // Datarate KO |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 671 | } |
Jenkins@KEILDM1.dc.multitech.prv | 109:41d16d4ab0f0 | 672 | |
Jenkins@KEILDM1.dc.multitech.prv | 109:41d16d4ab0f0 | 673 | if (GetSettings()->Session.UplinkDwelltime != 0 && datarate < DR_2) { |
Jenkins@KEILDM1.dc.multitech.prv | 109:41d16d4ab0f0 | 674 | logWarning("ADR Datarate KO - TxDwelltime != 0 and DR < 2"); |
Jenkins@KEILDM1.dc.multitech.prv | 109:41d16d4ab0f0 | 675 | status &= 0xFD; // Datarate KO |
Jenkins@KEILDM1.dc.multitech.prv | 109:41d16d4ab0f0 | 676 | } |
Jenkins@KEILDM1.dc.multitech.prv | 109:41d16d4ab0f0 | 677 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 678 | if (power < _minTxPower || power > _maxTxPower) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 679 | logWarning("ADR TX Power KO - outside allowed range"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 680 | status &= 0xFB; // TxPower KO |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 681 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 682 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 683 | // mask must not contain any undefined channels |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 684 | for (int i = 2; i < 16; i++) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 685 | if ((_channelMask[0] & (1 << i)) && (_channels[i].Frequency == 0)) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 686 | logWarning("ADR Channel Mask KO - cannot enable undefined channel"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 687 | status &= 0xFE; // ChannelMask KO |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 688 | break; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 689 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 690 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 691 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 692 | return status; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 693 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 694 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 695 | uint8_t ChannelPlan_AS923::HandleAckTimeout() { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 696 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 697 | if (!GetSettings()->Network.ADREnabled) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 698 | return LORA_ADR_OFF; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 699 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 700 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 701 | if ((++(GetSettings()->Session.AckCounter) % 2) == 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 702 | if (GetSettings()->Session.TxPower < GetSettings()->Network.TxPowerMax) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 703 | logTrace("ADR Setting power to maximum"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 704 | GetSettings()->Session.TxPower = GetSettings()->Network.TxPowerMax; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 705 | } else if (GetSettings()->Session.TxDatarate > 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 706 | logTrace("ADR Lowering datarate"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 707 | GetSettings()->Session.TxDatarate--; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 708 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 709 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 710 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 711 | return LORA_OK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 712 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 713 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 714 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 715 | uint32_t ChannelPlan_AS923::GetTimeOffAir() |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 716 | { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 717 | if (GetSettings()->Test.DisableDutyCycle == lora::ON) |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 718 | return 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 719 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 720 | uint32_t min = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 721 | uint32_t now = _dutyCycleTimer.read_ms(); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 722 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 723 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 724 | min = UINT_MAX; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 725 | int8_t band = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 726 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 727 | if (P2PEnabled()) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 728 | int8_t band = GetDutyBand(GetSettings()->Network.TxFrequency); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 729 | if (_dutyBands[band].TimeOffEnd > now) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 730 | min = _dutyBands[band].TimeOffEnd - now; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 731 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 732 | min = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 733 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 734 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 735 | for (size_t i = 0; i < _channels.size(); i++) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 736 | if (IsChannelEnabled(i) && GetChannel(i).Frequency != 0 && |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 737 | !(GetSettings()->Session.TxDatarate < GetChannel(i).DrRange.Fields.Min || |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 738 | GetSettings()->Session.TxDatarate > GetChannel(i).DrRange.Fields.Max)) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 739 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 740 | band = GetDutyBand(GetChannel(i).Frequency); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 741 | if (band != -1) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 742 | // logDebug("band: %d time-off: %d now: %d", band, _dutyBands[band].TimeOffEnd, now); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 743 | if (_dutyBands[band].TimeOffEnd > now) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 744 | min = std::min < uint32_t > (min, _dutyBands[band].TimeOffEnd - now); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 745 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 746 | min = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 747 | break; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 748 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 749 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 750 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 751 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 752 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 753 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 754 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 755 | if (GetSettings()->Session.AggregatedTimeOffEnd > 0 && GetSettings()->Session.AggregatedTimeOffEnd > now) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 756 | min = std::max < uint32_t > (min, GetSettings()->Session.AggregatedTimeOffEnd - now); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 757 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 758 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 759 | now = time(NULL); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 760 | uint32_t join_time = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 761 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 762 | if (GetSettings()->Session.JoinFirstAttempt != 0 && now < GetSettings()->Session.JoinTimeOffEnd) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 763 | join_time = (GetSettings()->Session.JoinTimeOffEnd - now) * 1000; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 764 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 765 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 766 | min = std::max < uint32_t > (join_time, min); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 767 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 768 | return min; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 769 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 770 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 771 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 772 | void ChannelPlan_AS923::UpdateDutyCycle(uint32_t freq, uint32_t time_on_air_ms) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 773 | if (GetSettings()->Test.DisableDutyCycle == lora::ON) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 774 | _dutyCycleTimer.stop(); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 775 | for (size_t i = 0; i < _dutyBands.size(); i++) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 776 | _dutyBands[i].TimeOffEnd = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 777 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 778 | return; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 779 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 780 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 781 | _dutyCycleTimer.start(); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 782 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 783 | if (GetSettings()->Session.MaxDutyCycle > 0 && GetSettings()->Session.MaxDutyCycle <= 15) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 784 | GetSettings()->Session.AggregatedTimeOffEnd = _dutyCycleTimer.read_ms() + time_on_air_ms * GetSettings()->Session.AggregateDutyCycle; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 785 | logDebug("Updated Aggregate DCycle Time-off: %lu DC: %f%%", GetSettings()->Session.AggregatedTimeOffEnd, 1 / float(GetSettings()->Session.AggregateDutyCycle)); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 786 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 787 | GetSettings()->Session.AggregatedTimeOffEnd = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 788 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 789 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 790 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 791 | uint32_t time_off_air = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 792 | uint32_t now = _dutyCycleTimer.read_ms(); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 793 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 794 | for (size_t i = 0; i < _dutyBands.size(); i++) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 795 | if (_dutyBands[i].TimeOffEnd < now) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 796 | _dutyBands[i].TimeOffEnd = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 797 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 798 | _dutyBands[i].TimeOffEnd -= now; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 799 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 800 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 801 | if (freq >= _dutyBands[i].FrequencyMin && freq <= _dutyBands[i].FrequencyMax) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 802 | logDebug("update TOE: freq: %d i:%d toa: %d DC:%d", freq, i, time_on_air_ms, _dutyBands[i].DutyCycle); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 803 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 804 | if (freq > _minFrequency && freq < _maxFrequency && (GetSettings()->Session.TxPower + GetSettings()->Network.AntennaGain) <= 7) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 805 | _dutyBands[i].TimeOffEnd = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 806 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 807 | time_off_air = time_on_air_ms * _dutyBands[i].DutyCycle; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 808 | _dutyBands[i].TimeOffEnd = time_off_air; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 809 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 810 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 811 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 812 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 813 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 814 | ResetDutyCycleTimer(); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 815 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 816 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 817 | std::vector<uint32_t> lora::ChannelPlan_AS923::GetChannels() { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 818 | std::vector < uint32_t > chans; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 819 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 820 | for (int8_t i = 0; i < (int) _channels.size(); i++) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 821 | chans.push_back(_channels[i].Frequency); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 822 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 823 | chans.push_back(GetRxWindow(2).Frequency); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 824 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 825 | return chans; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 826 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 827 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 828 | std::vector<uint8_t> lora::ChannelPlan_AS923::GetChannelRanges() { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 829 | std::vector < uint8_t > ranges; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 830 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 831 | for (int8_t i = 0; i < (int) _channels.size(); i++) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 832 | ranges.push_back(_channels[i].DrRange.Value); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 833 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 834 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 835 | ranges.push_back(GetRxWindow(2).DatarateIndex); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 836 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 837 | return ranges; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 838 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 839 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 840 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 841 | void lora::ChannelPlan_AS923::EnableDefaultChannels() { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 842 | _channelMask[0] |= 0x0003; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 843 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 844 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 845 | uint8_t ChannelPlan_AS923::GetNextChannel() |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 846 | { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 847 | if (GetSettings()->Session.AggregatedTimeOffEnd != 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 848 | return LORA_AGGREGATED_DUTY_CYCLE; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 849 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 850 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 851 | if (P2PEnabled() || GetSettings()->Network.TxFrequency != 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 852 | logDebug("Using frequency %d", GetSettings()->Network.TxFrequency); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 853 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 854 | if (GetSettings()->Test.DisableDutyCycle != lora::ON) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 855 | int8_t band = GetDutyBand(GetSettings()->Network.TxFrequency); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 856 | logDebug("band: %d freq: %d", band, GetSettings()->Network.TxFrequency); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 857 | if (band != -1 && _dutyBands[band].TimeOffEnd != 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 858 | return LORA_NO_CHANS_ENABLED; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 859 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 860 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 861 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 862 | GetRadio()->SetChannel(GetSettings()->Network.TxFrequency); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 863 | return LORA_OK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 864 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 865 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 866 | uint8_t start = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 867 | uint8_t maxChannels = _numChans125k; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 868 | uint8_t nbEnabledChannels = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 869 | uint8_t *enabledChannels = new uint8_t[maxChannels]; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 870 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 871 | if (GetTxDatarate().Bandwidth == BW_500) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 872 | maxChannels = _numChans500k; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 873 | start = _numChans125k; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 874 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 875 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 876 | // Search how many channels are enabled |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 877 | DatarateRange range; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 878 | uint8_t dr_index = GetSettings()->Session.TxDatarate; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 879 | uint32_t now = _dutyCycleTimer.read_ms(); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 880 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 881 | for (size_t i = 0; i < _dutyBands.size(); i++) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 882 | if (_dutyBands[i].TimeOffEnd < now || GetSettings()->Test.DisableDutyCycle == lora::ON) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 883 | _dutyBands[i].TimeOffEnd = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 884 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 885 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 886 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 887 | for (uint8_t i = start; i < start + maxChannels; i++) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 888 | range = GetChannel(i).DrRange; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 889 | // logDebug("chan: %d freq: %d range:%02x", i, GetChannel(i).Frequency, range.Value); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 890 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 891 | if (IsChannelEnabled(i) && (dr_index >= range.Fields.Min && dr_index <= range.Fields.Max)) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 892 | int8_t band = GetDutyBand(GetChannel(i).Frequency); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 893 | // logDebug("band: %d freq: %d", band, _channels[i].Frequency); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 894 | if (band != -1 && _dutyBands[band].TimeOffEnd == 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 895 | enabledChannels[nbEnabledChannels++] = i; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 896 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 897 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 898 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 899 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 900 | logTrace("Number of available channels: %d", nbEnabledChannels); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 901 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 902 | uint32_t freq = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 903 | uint8_t sf = GetTxDatarate().SpreadingFactor; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 904 | uint8_t bw = GetTxDatarate().Bandwidth; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 905 | int16_t thres = DEFAULT_FREE_CHAN_RSSI_THRESHOLD; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 906 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 907 | if (nbEnabledChannels == 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 908 | delete [] enabledChannels; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 909 | return LORA_NO_CHANS_ENABLED; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 910 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 911 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 912 | if (GetSettings()->Network.CADEnabled) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 913 | // Search for free channel with ms timeout |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 914 | int16_t timeout = 10000; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 915 | Timer tmr; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 916 | tmr.start(); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 917 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 918 | for (uint8_t j = rand_r(0, nbEnabledChannels - 1); tmr.read_ms() < timeout; j++) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 919 | freq = GetChannel(enabledChannels[j]).Frequency; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 920 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 921 | // Listen before talk |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 922 | if (GetRadio()->IsChannelFree(SxRadio::MODEM_LORA, freq, sf, thres, bw)) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 923 | _txChannel = enabledChannels[j]; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 924 | break; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 925 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 926 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 927 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 928 | uint8_t j = rand_r(0, nbEnabledChannels - 1); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 929 | _txChannel = enabledChannels[j]; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 930 | freq = GetChannel(_txChannel).Frequency; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 931 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 932 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 933 | assert(freq != 0); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 934 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 935 | logDebug("Using channel %d : %d", _txChannel, freq); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 936 | GetRadio()->SetChannel(freq); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 937 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 938 | delete [] enabledChannels; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 939 | return LORA_OK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 940 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 941 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 942 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 943 | uint8_t lora::ChannelPlan_AS923::GetJoinDatarate() { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 944 | uint8_t dr = GetSettings()->Session.TxDatarate; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 945 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 946 | // Default join datarate is DR2:SF10BW125 |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 947 | dr = lora::DR_2; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 948 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 949 | return dr; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 950 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 951 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 952 | uint8_t ChannelPlan_AS923::CalculateJoinBackoff(uint8_t size) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 953 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 954 | time_t now = time(NULL); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 955 | uint32_t time_on_max = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 956 | static uint32_t time_off_max = 15; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 957 | uint32_t rand_time_off = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 958 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 959 | // TODO: calc time-off-max based on RTC time from JoinFirstAttempt, time-off-max is lost over sleep |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 960 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 961 | if ((time_t)GetSettings()->Session.JoinTimeOffEnd > now) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 962 | return LORA_JOIN_BACKOFF; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 963 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 964 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 965 | uint32_t secs_since_first_attempt = (now - GetSettings()->Session.JoinFirstAttempt); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 966 | uint16_t hours_since_first_attempt = secs_since_first_attempt / (60 * 60); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 967 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 968 | static uint8_t join_cnt = 0; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 969 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 970 | join_cnt = (join_cnt+1) % 8; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 971 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 972 | if (GetSettings()->Session.JoinFirstAttempt == 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 973 | /* 1 % duty-cycle for first hour |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 974 | * 0.1 % next 10 hours |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 975 | * 0.01 % upto 24 hours */ |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 976 | GetSettings()->Session.JoinFirstAttempt = now; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 977 | GetSettings()->Session.JoinTimeOnAir += GetTimeOnAir(size); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 978 | GetSettings()->Session.JoinTimeOffEnd = now + (GetTimeOnAir(size) / 10); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 979 | } else if (join_cnt == 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 980 | if (hours_since_first_attempt < 1) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 981 | time_on_max = 36000; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 982 | rand_time_off = rand_r(time_off_max - 1, time_off_max + 1); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 983 | // time off max 1 hour |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 984 | time_off_max = std::min < uint32_t > (time_off_max * 2, 60 * 60); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 985 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 986 | if (GetSettings()->Session.JoinTimeOnAir < time_on_max) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 987 | GetSettings()->Session.JoinTimeOnAir += GetTimeOnAir(size); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 988 | GetSettings()->Session.JoinTimeOffEnd = now + rand_time_off; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 989 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 990 | logWarning("Max time-on-air limit met for current join backoff period"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 991 | GetSettings()->Session.JoinTimeOffEnd = GetSettings()->Session.JoinFirstAttempt + 60 * 60; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 992 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 993 | } else if (hours_since_first_attempt < 11) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 994 | if (GetSettings()->Session.JoinTimeOnAir < 36000) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 995 | GetSettings()->Session.JoinTimeOnAir = 36000; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 996 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 997 | time_on_max = 72000; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 998 | rand_time_off = rand_r(time_off_max - 1, time_off_max + 1); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 999 | // time off max 1 hour |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1000 | time_off_max = std::min < uint32_t > (time_off_max * 2, 60 * 60); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1001 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1002 | if (GetSettings()->Session.JoinTimeOnAir < time_on_max) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1003 | GetSettings()->Session.JoinTimeOnAir += GetTimeOnAir(size); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1004 | GetSettings()->Session.JoinTimeOffEnd = now + rand_time_off; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1005 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1006 | logWarning("Max time-on-air limit met for current join backoff period"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1007 | GetSettings()->Session.JoinTimeOffEnd = GetSettings()->Session.JoinFirstAttempt + 11 * 60 * 60; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1008 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1009 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1010 | if (GetSettings()->Session.JoinTimeOnAir < 72000) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1011 | GetSettings()->Session.JoinTimeOnAir = 72000; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1012 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1013 | uint32_t join_time = 2500; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1014 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1015 | time_on_max = 80700; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1016 | time_off_max = 1 * 60 * 60; // 1 hour |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1017 | rand_time_off = rand_r(time_off_max - 1, time_off_max + 1); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1018 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1019 | if (GetSettings()->Session.JoinTimeOnAir < time_on_max - join_time) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1020 | GetSettings()->Session.JoinTimeOnAir += GetTimeOnAir(size); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1021 | GetSettings()->Session.JoinTimeOffEnd = now + rand_time_off; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1022 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1023 | logWarning("Max time-on-air limit met for current join backoff period"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1024 | // Reset the join time on air and set end of restriction to the next 24 hour period |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1025 | GetSettings()->Session.JoinTimeOnAir = 72000; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1026 | uint16_t days = (now - GetSettings()->Session.JoinFirstAttempt) / (24 * 60 * 60) + 1; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1027 | logWarning("days : %d", days); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1028 | GetSettings()->Session.JoinTimeOffEnd = GetSettings()->Session.JoinFirstAttempt + ((days * 24) + 11) * 60 * 60; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1029 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1030 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1031 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1032 | logWarning("JoinBackoff: %lu seconds Time On Air: %lu / %lu", GetSettings()->Session.JoinTimeOffEnd - now, GetSettings()->Session.JoinTimeOnAir, time_on_max); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1033 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1034 | GetSettings()->Session.JoinTimeOnAir += GetTimeOnAir(size); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1035 | GetSettings()->Session.JoinTimeOffEnd = now + (GetTimeOnAir(size) / 10); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1036 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1037 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1038 | return LORA_OK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1039 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1040 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1041 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1042 | uint8_t ChannelPlan_AS923::HandleMacCommand(uint8_t* payload, uint8_t& index) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1043 | logDebug("AS923 Handle Mac index: %d", index); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1044 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1045 | switch (payload[index++]) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1046 | case SRV_MAC_TX_PARAM_SETUP_REQ: { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1047 | uint8_t eirp_dwell = payload[index++]; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1048 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1049 | GetSettings()->Session.DownlinkDwelltime = eirp_dwell >> 5 & 0x01; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1050 | GetSettings()->Session.UplinkDwelltime = eirp_dwell >> 4 & 0x01; |
Jenkins@KEILDM1.dc.multitech.prv | 153:7c00843e4bba | 1051 | //change data rate with if dwell time changes |
Jenkins@KEILDM1.dc.multitech.prv | 153:7c00843e4bba | 1052 | if(GetSettings()->Session.UplinkDwelltime == 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 153:7c00843e4bba | 1053 | _minDatarate = lora::DR_0; |
Jenkins@KEILDM1.dc.multitech.prv | 153:7c00843e4bba | 1054 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 153:7c00843e4bba | 1055 | _minDatarate = lora::DR_2; |
Jenkins@KEILDM1.dc.multitech.prv | 153:7c00843e4bba | 1056 | if(GetSettings()->Session.TxDatarate < lora::DR_2) { |
Jenkins@KEILDM1.dc.multitech.prv | 153:7c00843e4bba | 1057 | GetSettings()->Session.TxDatarate = lora::DR_2; |
Jenkins@KEILDM1.dc.multitech.prv | 153:7c00843e4bba | 1058 | logDebug("Datarate is now DR%d",GetSettings()->Session.TxDatarate); |
Jenkins@KEILDM1.dc.multitech.prv | 153:7c00843e4bba | 1059 | } |
Jenkins@KEILDM1.dc.multitech.prv | 153:7c00843e4bba | 1060 | } |
Jenkins@KEILDM1.dc.multitech.prv | 153:7c00843e4bba | 1061 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1062 | GetSettings()->Session.Max_EIRP = MAX_ERP_VALUES[(eirp_dwell & 0x0F)]; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1063 | logDebug("buffer index %d", GetSettings()->Session.CommandBufferIndex); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1064 | if (GetSettings()->Session.CommandBufferIndex < COMMANDS_BUFFER_SIZE) { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1065 | logDebug("Add tx param setup mac cmd to buffer"); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1066 | GetSettings()->Session.CommandBuffer[GetSettings()->Session.CommandBufferIndex++] = MOTE_MAC_TX_PARAM_SETUP_ANS; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1067 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1068 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1069 | logDebug("TX PARAM DWELL UL: %d DL: %d Max EIRP: %d", GetSettings()->Session.UplinkDwelltime, GetSettings()->Session.DownlinkDwelltime, GetSettings()->Session.Max_EIRP); |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1070 | break; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1071 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1072 | default: { |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1073 | return LORA_ERROR; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1074 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1075 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1076 | |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1077 | return LORA_OK; |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1078 | } |
Jenkins@KEILDM1.dc.multitech.prv | 82:0f5a742a08cd | 1079 | |
Jenkins@KEILDM1.dc.multitech.prv | 109:41d16d4ab0f0 | 1080 | void ChannelPlan_AS923::DecrementDatarate() { |
Jenkins@KEILDM1.dc.multitech.prv | 109:41d16d4ab0f0 | 1081 | if(GetSettings()->Session.UplinkDwelltime == 0) { |
Jenkins@KEILDM1.dc.multitech.prv | 109:41d16d4ab0f0 | 1082 | _minDatarate = lora::DR_0; |
Jenkins@KEILDM1.dc.multitech.prv | 109:41d16d4ab0f0 | 1083 | } else { |
Jenkins@KEILDM1.dc.multitech.prv | 109:41d16d4ab0f0 | 1084 | _minDatarate = lora::DR_2; |
Jenkins@KEILDM1.dc.multitech.prv | 109:41d16d4ab0f0 | 1085 | } |
Jenkins@KEILDM1.dc.multitech.prv | 109:41d16d4ab0f0 | 1086 | |
Jenkins@KEILDM1.dc.multitech.prv | 109:41d16d4ab0f0 | 1087 | if (GetSettings()->Session.TxDatarate > _minDatarate) { |
Jenkins@KEILDM1.dc.multitech.prv | 109:41d16d4ab0f0 | 1088 | GetSettings()->Session.TxDatarate--; |
Jenkins@KEILDM1.dc.multitech.prv | 109:41d16d4ab0f0 | 1089 | } |
Jenkins@KEILDM1.dc.multitech.prv | 109:41d16d4ab0f0 | 1090 | } |
Jenkins@KEILDM1.dc.multitech.prv | 109:41d16d4ab0f0 | 1091 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1092 | bool ChannelPlan_AS923::DecodeBeacon(const uint8_t* payload, size_t size, BeaconData_t& data) { |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1093 | uint16_t crc1, crc1_rx, crc2, crc2_rx; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1094 | const BCNPayload* beacon = (const BCNPayload*)payload; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1095 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1096 | // First check the size of the packet |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1097 | if (size != sizeof(BCNPayload)) |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1098 | return false; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1099 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1100 | // Next we verify the CRCs are correct |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1101 | crc1 = CRC16(beacon->RFU, sizeof(beacon->RFU) + sizeof(beacon->Time)); |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1102 | memcpy((uint8_t*)&crc1_rx, beacon->CRC1, sizeof(uint16_t)); |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1103 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1104 | if (crc1 != crc1_rx) |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1105 | return false; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1106 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1107 | crc2 = CRC16(beacon->GwSpecific, sizeof(beacon->GwSpecific)); |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1108 | memcpy((uint8_t*)&crc2_rx, beacon->CRC2, sizeof(uint16_t)); |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1109 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1110 | if (crc2 != crc2_rx) |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1111 | return false; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1112 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1113 | // Now that we have confirmed this packet is a beacon, parse and complete the output struct |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1114 | memcpy(&data.Time, beacon->Time, sizeof(beacon->Time)); |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1115 | data.InfoDesc = beacon->GwSpecific[0]; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1116 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1117 | // Update the GPS fields if we have a gps info descriptor |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1118 | if (data.InfoDesc == GPS_FIRST_ANTENNA || |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1119 | data.InfoDesc == GPS_SECOND_ANTENNA || |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1120 | data.InfoDesc == GPS_THIRD_ANTENNA) { |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1121 | // Latitude and Longitude 3 bytes in length |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1122 | memcpy(&data.Latitude, &beacon->GwSpecific[1], 3); |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1123 | memcpy(&data.Longitude, &beacon->GwSpecific[4], 3); |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1124 | } |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1125 | |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1126 | return true; |
Jenkins@KEILDM1.dc.multitech.prv | 172:7ec44396a51b | 1127 | } |