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