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