MultiTech / libmDot-Custom

Fork of libmDot-custom by Jason Reiss

Information

Library has been updated to mbed 5.x

The LoRaWAN Certification test mode implementation is built-in to libmDot code. When a start test mode packet is received the library will not return until test mode has ended.

Warning

This library is currently in BETA release. Unresolved issues may be experienced. Software is provided as is with no expectation of support of bug fixes in the future. Please report issues found through the mbed website or directly to support.multitech.com.

Changing of channel plan parameters may cause the device to no longer respect local RF regulations. Please use caution and respect your local regulations.

In AT Command Firmware remove line 803.

CommandTerminal/CommandTerminal.cpp

        delete[] info->RxBuffer;

Likewise, if your application is handling events from the library asynchronously.

Creating new channel plans

Copy EU868 or US915 custom channel plan as a starting point

Import programmDot_AT_firmware_CUSTOM

AT Firmware with custom channel plan support

EU868 provides a framework for a DYNAMIC channel plan with duty-cycle limitations

US915 provides a framework for a FIXED channel plan

RADIO_POWERS are measured output in dBm for each radio tx power setting.

Additional MAC Commands can be implemented by overriding the HandleMacCommand function.

Steps

  1. Setup datarates, duty-cycle bands and channels in ChannelPlan_* constructor
  2. Modify GetJoinDatarate and CalculateJoinBackoff to change join datarates and backoff
  3. Customize HandleJoinAccept datarates
  4. Use GetRxWindow(int) to define how the device open Rx window 1 and 2
  5. GetNextChannel will pick a channel from the enabled channel at the current datarate before each TX
Committer:
jreiss
Date:
Fri Jan 06 17:21:04 2017 +0000
Revision:
23:3830a5f61f09
Parent:
21:f77f883a080e
update to mbed-os 5.3.2; AS923: add DL channel and tx param MAC commands; KR920: add LBT

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jreiss 21:f77f883a080e 1 /** __ ___ ____ _ ______ __ ____ __ ____
jreiss 21:f77f883a080e 2 * / |/ /_ __/ / /_(_)__/_ __/__ ____/ / / __/_ _____ / /____ __ _ ___ / _/__ ____
jreiss 21:f77f883a080e 3 * / /|_/ / // / / __/ /___// / / -_) __/ _ \ _\ \/ // (_-</ __/ -_) ' \(_-< _/ // _ \/ __/ __
jreiss 21:f77f883a080e 4 * /_/ /_/\_,_/_/\__/_/ /_/ \__/\__/_//_/ /___/\_, /___/\__/\__/_/_/_/___/ /___/_//_/\__/ /_/
jreiss 21:f77f883a080e 5 * Copyright (C) 2015 by Multi-Tech Systems /___/
jreiss 21:f77f883a080e 6 *
jreiss 21:f77f883a080e 7 *
jreiss 21:f77f883a080e 8 * @author Jason Reiss
jreiss 21:f77f883a080e 9 * @date 10-31-2015
jreiss 23:3830a5f61f09 10 * @brief lora::ChannelPlan provides an interface for LoRaWAN channel schemes
jreiss 21:f77f883a080e 11 *
jreiss 21:f77f883a080e 12 * @details
jreiss 21:f77f883a080e 13 *
jreiss 21:f77f883a080e 14 */
jreiss 21:f77f883a080e 15
jreiss 21:f77f883a080e 16 #ifndef __CHANNEL_STRATEGY_H__
jreiss 21:f77f883a080e 17 #define __CHANNEL_STRATEGY_H__
jreiss 21:f77f883a080e 18
jreiss 21:f77f883a080e 19 #include "Lora.h"
jreiss 21:f77f883a080e 20 #include "SxRadio.h"
jreiss 21:f77f883a080e 21 #include <vector>
jreiss 21:f77f883a080e 22
jreiss 21:f77f883a080e 23 namespace lora {
jreiss 21:f77f883a080e 24
jreiss 21:f77f883a080e 25 class ChannelPlan {
jreiss 21:f77f883a080e 26 public:
jreiss 21:f77f883a080e 27
jreiss 21:f77f883a080e 28 enum PlanType {
jreiss 21:f77f883a080e 29 DYNAMIC,
jreiss 21:f77f883a080e 30 FIXED,
jreiss 21:f77f883a080e 31 };
jreiss 21:f77f883a080e 32
jreiss 21:f77f883a080e 33 /**
jreiss 21:f77f883a080e 34 * ChannelPlan constructor
jreiss 21:f77f883a080e 35 * @param radio SxRadio object used to set Tx/Rx config
jreiss 21:f77f883a080e 36 * @param settings Settings object
jreiss 21:f77f883a080e 37 */
jreiss 21:f77f883a080e 38 ChannelPlan(SxRadio& radio, Settings& settings);
jreiss 21:f77f883a080e 39
jreiss 21:f77f883a080e 40 /**
jreiss 21:f77f883a080e 41 * ChannelPlan destructor
jreiss 21:f77f883a080e 42 */
jreiss 21:f77f883a080e 43 virtual ~ChannelPlan();
jreiss 21:f77f883a080e 44
jreiss 21:f77f883a080e 45 /**
jreiss 21:f77f883a080e 46 * Initialize channels, datarates and duty cycle bands according to current channel plan in settings
jreiss 21:f77f883a080e 47 */
jreiss 21:f77f883a080e 48 virtual void Init();
jreiss 21:f77f883a080e 49
jreiss 21:f77f883a080e 50 /**
jreiss 21:f77f883a080e 51 * Get the next channel to use to transmit
jreiss 21:f77f883a080e 52 * @return LORA_OK if channel was found
jreiss 21:f77f883a080e 53 * @return LORA_NO_CHANS_ENABLED
jreiss 21:f77f883a080e 54 */
jreiss 21:f77f883a080e 55 virtual uint8_t GetNextChannel();
jreiss 21:f77f883a080e 56
jreiss 21:f77f883a080e 57 /**
jreiss 21:f77f883a080e 58 * Set the number of channels in the plan
jreiss 21:f77f883a080e 59 */
jreiss 21:f77f883a080e 60 virtual void SetNumberOfChannels(uint8_t channels, bool resize = true);
jreiss 21:f77f883a080e 61
jreiss 21:f77f883a080e 62 /**
jreiss 21:f77f883a080e 63 * Get the number of channels in the plan
jreiss 21:f77f883a080e 64 */
jreiss 21:f77f883a080e 65 virtual uint8_t GetNumberOfChannels();
jreiss 21:f77f883a080e 66
jreiss 21:f77f883a080e 67 /**
jreiss 21:f77f883a080e 68 * Check if channel is enabled
jreiss 21:f77f883a080e 69 * @return true if enabled
jreiss 21:f77f883a080e 70 */
jreiss 21:f77f883a080e 71 virtual bool IsChannelEnabled(uint8_t channel);
jreiss 21:f77f883a080e 72
jreiss 21:f77f883a080e 73 /**
jreiss 21:f77f883a080e 74 * Set a 16 bit channel mask with offset
jreiss 21:f77f883a080e 75 * @param index of mask to set 0:0-15, 1:16-31 ...
jreiss 21:f77f883a080e 76 * @param mask 16 bit mask of enabled channels
jreiss 21:f77f883a080e 77 * @return true
jreiss 21:f77f883a080e 78 */
jreiss 21:f77f883a080e 79 virtual bool SetChannelMask(uint8_t index, uint16_t mask);
jreiss 21:f77f883a080e 80
jreiss 21:f77f883a080e 81 /**
jreiss 21:f77f883a080e 82 * Get the channel mask of currently enabled channels
jreiss 21:f77f883a080e 83 * @return vector containing channel bit masks
jreiss 21:f77f883a080e 84 */
jreiss 21:f77f883a080e 85 virtual std::vector<uint16_t> GetChannelMask();
jreiss 21:f77f883a080e 86
jreiss 21:f77f883a080e 87 /**
jreiss 21:f77f883a080e 88 * Add a channel to the ChannelPlan
jreiss 21:f77f883a080e 89 * @param index of channel, use -1 to add to end
jreiss 21:f77f883a080e 90 * @param channel settings to add
jreiss 21:f77f883a080e 91 */
jreiss 21:f77f883a080e 92 virtual uint8_t AddChannel(int8_t index, Channel channel);
jreiss 21:f77f883a080e 93
jreiss 21:f77f883a080e 94 /**
jreiss 21:f77f883a080e 95 * Get channel at index
jreiss 21:f77f883a080e 96 * @return Channel
jreiss 21:f77f883a080e 97 */
jreiss 23:3830a5f61f09 98 virtual Channel GetChannel(uint8_t index);
jreiss 23:3830a5f61f09 99
jreiss 23:3830a5f61f09 100 /**
jreiss 23:3830a5f61f09 101 * Add a downlink channel to the ChannelPlan
jreiss 23:3830a5f61f09 102 * Set to 0 to use the default uplink channel frequency
jreiss 23:3830a5f61f09 103 * @param index of channel, use -1 to add to end
jreiss 23:3830a5f61f09 104 * @param channel settings to add
jreiss 23:3830a5f61f09 105 */
jreiss 23:3830a5f61f09 106 virtual uint8_t AddDownlinkChannel(int8_t index, Channel channel);
jreiss 23:3830a5f61f09 107
jreiss 23:3830a5f61f09 108 /**
jreiss 23:3830a5f61f09 109 * Get channel at index
jreiss 23:3830a5f61f09 110 * @return Channel
jreiss 23:3830a5f61f09 111 */
jreiss 23:3830a5f61f09 112 virtual Channel GetDownlinkChannel(uint8_t index);
jreiss 21:f77f883a080e 113
jreiss 21:f77f883a080e 114 /**
jreiss 21:f77f883a080e 115 * Set number of datarates in ChannelPlan
jreiss 21:f77f883a080e 116 * @param datarates
jreiss 21:f77f883a080e 117 */
jreiss 21:f77f883a080e 118 virtual void SetNumberOfDatarates(uint8_t datarates);
jreiss 21:f77f883a080e 119
jreiss 21:f77f883a080e 120 /**
jreiss 21:f77f883a080e 121 * Add a datarate to the ChannelPlan
jreiss 21:f77f883a080e 122 * @param index of datarate, use -1 to add to end
jreiss 21:f77f883a080e 123 * @param datarate settings to add
jreiss 21:f77f883a080e 124 */
jreiss 21:f77f883a080e 125 virtual uint8_t AddDatarate(int8_t index, Datarate datarate);
jreiss 21:f77f883a080e 126
jreiss 21:f77f883a080e 127 /**
jreiss 21:f77f883a080e 128 * Get datarate at index
jreiss 21:f77f883a080e 129 * @return Datarate
jreiss 21:f77f883a080e 130 */
jreiss 21:f77f883a080e 131 virtual Datarate GetDatarate(int8_t index);
jreiss 21:f77f883a080e 132
jreiss 21:f77f883a080e 133 /**
jreiss 21:f77f883a080e 134 * Get max payload size for current datarate
jreiss 21:f77f883a080e 135 * @return size in bytes
jreiss 21:f77f883a080e 136 */
jreiss 21:f77f883a080e 137 virtual uint8_t GetMaxPayloadSize();
jreiss 21:f77f883a080e 138
jreiss 21:f77f883a080e 139 /**
jreiss 21:f77f883a080e 140 * Get rx window settings for requested window
jreiss 21:f77f883a080e 141 * RX_1, RX_2, RX_BEACON, RX_SLOT
jreiss 21:f77f883a080e 142 * @param window
jreiss 21:f77f883a080e 143 * @return RxWindow
jreiss 21:f77f883a080e 144 */
jreiss 21:f77f883a080e 145 virtual RxWindow GetRxWindow(uint8_t window);
jreiss 21:f77f883a080e 146
jreiss 21:f77f883a080e 147 /**
jreiss 21:f77f883a080e 148 * Get current channel to use for transmitting
jreiss 21:f77f883a080e 149 * @param channel index of channel
jreiss 21:f77f883a080e 150 * @return LORA_OK
jreiss 21:f77f883a080e 151 */
jreiss 21:f77f883a080e 152 virtual uint8_t SetTxChannel(uint8_t channel);
jreiss 21:f77f883a080e 153
jreiss 21:f77f883a080e 154 /**
jreiss 21:f77f883a080e 155 * Get datarate to use on the join request
jreiss 21:f77f883a080e 156 * @return datarate index
jreiss 21:f77f883a080e 157 */
jreiss 21:f77f883a080e 158 virtual uint8_t GetJoinDatarate();
jreiss 21:f77f883a080e 159
jreiss 21:f77f883a080e 160
jreiss 21:f77f883a080e 161 /**
jreiss 21:f77f883a080e 162 * Calculate the next time a join request is possible
jreiss 21:f77f883a080e 163 * @param size of join frame
jreiss 21:f77f883a080e 164 * @returns LORA_OK
jreiss 21:f77f883a080e 165 */
jreiss 21:f77f883a080e 166 virtual uint8_t CalculateJoinBackoff(uint8_t size);
jreiss 21:f77f883a080e 167
jreiss 21:f77f883a080e 168 /**
jreiss 21:f77f883a080e 169 * Get the current datarate
jreiss 21:f77f883a080e 170 * @return Datarate
jreiss 21:f77f883a080e 171 */
jreiss 21:f77f883a080e 172 virtual Datarate GetTxDatarate();
jreiss 21:f77f883a080e 173
jreiss 21:f77f883a080e 174 /**
jreiss 21:f77f883a080e 175 * Set the current datarate
jreiss 21:f77f883a080e 176 * @param index of datarate
jreiss 21:f77f883a080e 177 * @return LORA_OK
jreiss 21:f77f883a080e 178 */
jreiss 21:f77f883a080e 179 virtual uint8_t SetTxDatarate(uint8_t index);
jreiss 21:f77f883a080e 180
jreiss 21:f77f883a080e 181 /**
jreiss 21:f77f883a080e 182 * Set the datarate offset used for first receive window
jreiss 21:f77f883a080e 183 * @param offset
jreiss 21:f77f883a080e 184 * @return LORA_OK
jreiss 21:f77f883a080e 185 */
jreiss 21:f77f883a080e 186 virtual uint8_t SetRx1Offset(uint8_t offset);
jreiss 21:f77f883a080e 187
jreiss 21:f77f883a080e 188 /**
jreiss 21:f77f883a080e 189 * Set the frequency for second receive window
jreiss 21:f77f883a080e 190 * @param freq
jreiss 21:f77f883a080e 191 * @return LORA_OK
jreiss 21:f77f883a080e 192 */
jreiss 21:f77f883a080e 193 virtual uint8_t SetRx2Frequency(uint32_t freq);
jreiss 21:f77f883a080e 194
jreiss 21:f77f883a080e 195 /**
jreiss 21:f77f883a080e 196 * Set the datarate index used for second receive window
jreiss 21:f77f883a080e 197 * @param index
jreiss 21:f77f883a080e 198 * @return LORA_OK
jreiss 21:f77f883a080e 199 */
jreiss 21:f77f883a080e 200 virtual uint8_t SetRx2DatarateIndex(uint8_t index);
jreiss 21:f77f883a080e 201
jreiss 21:f77f883a080e 202 /**
jreiss 21:f77f883a080e 203 * Get next channel and set the SxRadio tx config with current settings
jreiss 21:f77f883a080e 204 * @return LORA_OK
jreiss 21:f77f883a080e 205 */
jreiss 21:f77f883a080e 206 virtual uint8_t SetTxConfig();
jreiss 21:f77f883a080e 207
jreiss 21:f77f883a080e 208 /**
jreiss 21:f77f883a080e 209 * Set the SxRadio rx config provided window
jreiss 21:f77f883a080e 210 * @param window to be opened
jreiss 21:f77f883a080e 211 * @param continuous keep window open
jreiss 21:f77f883a080e 212 * @return LORA_OK
jreiss 21:f77f883a080e 213 */
jreiss 21:f77f883a080e 214 virtual uint8_t SetRxConfig(uint8_t window, bool continuous);
jreiss 21:f77f883a080e 215
jreiss 21:f77f883a080e 216 /**
jreiss 21:f77f883a080e 217 * Set channel group if supported by plan
jreiss 21:f77f883a080e 218 * @param group
jreiss 21:f77f883a080e 219 * @return LORA_OK
jreiss 21:f77f883a080e 220 */
jreiss 21:f77f883a080e 221 virtual uint8_t SetChannelGroup(uint8_t group);
jreiss 21:f77f883a080e 222
jreiss 21:f77f883a080e 223 /**
jreiss 21:f77f883a080e 224 * Get channel group if supported by plan
jreiss 21:f77f883a080e 225 * @param group 0-8 or 0 if not supported
jreiss 21:f77f883a080e 226 * @return LORA_OK
jreiss 21:f77f883a080e 227 */
jreiss 21:f77f883a080e 228 virtual uint8_t GetChannelGroup();
jreiss 21:f77f883a080e 229
jreiss 21:f77f883a080e 230 /**
jreiss 21:f77f883a080e 231 * Reset the ack counter used to lower datarate if ACK's are missed
jreiss 21:f77f883a080e 232 */
jreiss 21:f77f883a080e 233 virtual void ResetAckCounter();
jreiss 21:f77f883a080e 234
jreiss 21:f77f883a080e 235 /**
jreiss 21:f77f883a080e 236 * Callback for radio to request channel change when frequency hopping
jreiss 21:f77f883a080e 237 * @param currentChannel
jreiss 21:f77f883a080e 238 */
jreiss 21:f77f883a080e 239 virtual void FhssChangeChannel(uint8_t currentChannel);
jreiss 21:f77f883a080e 240
jreiss 21:f77f883a080e 241 /**
jreiss 21:f77f883a080e 242 * Callback for ACK timeout event
jreiss 21:f77f883a080e 243 * @return LORA_OK
jreiss 21:f77f883a080e 244 */
jreiss 21:f77f883a080e 245 virtual uint8_t HandleAckTimeout();
jreiss 21:f77f883a080e 246
jreiss 21:f77f883a080e 247 /**
jreiss 21:f77f883a080e 248 * Callback for Join Accept packet to load optional channels
jreiss 21:f77f883a080e 249 * @return LORA_OK
jreiss 21:f77f883a080e 250 */
jreiss 21:f77f883a080e 251 virtual uint8_t HandleJoinAccept(const uint8_t* buffer, uint8_t size);
jreiss 21:f77f883a080e 252
jreiss 21:f77f883a080e 253 /**
jreiss 21:f77f883a080e 254 * Callback to for rx parameter setup ServerCommand
jreiss 21:f77f883a080e 255 * @param payload packet data
jreiss 21:f77f883a080e 256 * @param index of start of command buffer
jreiss 21:f77f883a080e 257 * @param size number of bytes in command buffer
jreiss 21:f77f883a080e 258 * @param[out] status to be returned in MoteCommand answer
jreiss 21:f77f883a080e 259 * @return LORA_OK
jreiss 21:f77f883a080e 260 */
jreiss 21:f77f883a080e 261 virtual uint8_t HandleRxParamSetup(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status);
jreiss 21:f77f883a080e 262
jreiss 21:f77f883a080e 263 /**
jreiss 21:f77f883a080e 264 * Callback to for new channel ServerCommand
jreiss 21:f77f883a080e 265 * @param payload packet data
jreiss 21:f77f883a080e 266 * @param index of start of command buffer
jreiss 21:f77f883a080e 267 * @param size number of bytes in command buffer
jreiss 21:f77f883a080e 268 * @param[out] status to be returned in MoteCommand answer
jreiss 21:f77f883a080e 269 * @return LORA_OK
jreiss 21:f77f883a080e 270 */
jreiss 21:f77f883a080e 271 virtual uint8_t HandleNewChannel(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status);
jreiss 16:9bd6cacde447 272
jreiss 21:f77f883a080e 273 /**
jreiss 21:f77f883a080e 274 * Callback to for ping slot channel request ServerCommand
jreiss 21:f77f883a080e 275 * @param payload packet data
jreiss 21:f77f883a080e 276 * @param index of start of command buffer
jreiss 21:f77f883a080e 277 * @param size number of bytes in command buffer
jreiss 21:f77f883a080e 278 * @param[out] status to be returned in MoteCommand answer
jreiss 21:f77f883a080e 279 * @return LORA_OK
jreiss 21:f77f883a080e 280 */
jreiss 21:f77f883a080e 281 virtual uint8_t HandlePingSlotChannelReq(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status);
jreiss 21:f77f883a080e 282
jreiss 21:f77f883a080e 283 /**
jreiss 21:f77f883a080e 284 * Callback to for beacon frequency request ServerCommand
jreiss 21:f77f883a080e 285 * @param payload packet data
jreiss 21:f77f883a080e 286 * @param index of start of command buffer
jreiss 21:f77f883a080e 287 * @param size number of bytes in command buffer
jreiss 21:f77f883a080e 288 * @param[out] status to be returned in MoteCommand answer
jreiss 21:f77f883a080e 289 * @return LORA_OK
jreiss 21:f77f883a080e 290 */
jreiss 21:f77f883a080e 291 virtual uint8_t HandleBeaconFrequencyReq(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status);
jreiss 21:f77f883a080e 292
jreiss 21:f77f883a080e 293 /**
jreiss 21:f77f883a080e 294 * Callback to for adaptive datarate ServerCommand
jreiss 21:f77f883a080e 295 * @param payload packet data
jreiss 21:f77f883a080e 296 * @param index of start of command buffer
jreiss 21:f77f883a080e 297 * @param size number of bytes in command buffer
jreiss 21:f77f883a080e 298 * @param[out] status to be returned in MoteCommand answer
jreiss 21:f77f883a080e 299 * @return LORA_OK
jreiss 21:f77f883a080e 300 */
jreiss 21:f77f883a080e 301 virtual uint8_t HandleAdrCommand(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status);
jreiss 21:f77f883a080e 302
jreiss 21:f77f883a080e 303 /**
jreiss 21:f77f883a080e 304 * Check that Rf Frequency is within channel plan range
jreiss 21:f77f883a080e 305 * @param freq frequency in Hz
jreiss 21:f77f883a080e 306 * @return true if valid frequency
jreiss 21:f77f883a080e 307 */
jreiss 21:f77f883a080e 308 virtual bool CheckRfFrequency(uint32_t freq);
jreiss 21:f77f883a080e 309
jreiss 21:f77f883a080e 310 /**
jreiss 21:f77f883a080e 311 * Flag for ADR
jreiss 21:f77f883a080e 312 * @return true if ADR is enable in settings
jreiss 21:f77f883a080e 313 */
jreiss 21:f77f883a080e 314 virtual bool IsAdrEnabled();
jreiss 21:f77f883a080e 315
jreiss 21:f77f883a080e 316 /**
jreiss 21:f77f883a080e 317 * Flag if ADR ACK should be sent in next packet
jreiss 21:f77f883a080e 318 * @return true when flag should be set
jreiss 21:f77f883a080e 319 */
jreiss 21:f77f883a080e 320 virtual bool AdrAckReq();
jreiss 21:f77f883a080e 321
jreiss 21:f77f883a080e 322 /**
jreiss 21:f77f883a080e 323 * Increment the ADR counter to track when ADR ACK request should be sent
jreiss 21:f77f883a080e 324 * @return current value
jreiss 21:f77f883a080e 325 */
jreiss 21:f77f883a080e 326 virtual uint8_t IncAdrCounter();
jreiss 21:f77f883a080e 327
jreiss 21:f77f883a080e 328 /**
jreiss 21:f77f883a080e 329 * Reset the ADR counter when valid downlink is received from network server
jreiss 21:f77f883a080e 330 */
jreiss 21:f77f883a080e 331 virtual void ResetAdrCounter();
jreiss 21:f77f883a080e 332
jreiss 21:f77f883a080e 333 /**
jreiss 21:f77f883a080e 334 * Get the time the radio must be off air to comply with regulations
jreiss 21:f77f883a080e 335 * Time to wait may be dependent on duty-cycle restrictions per channel
jreiss 21:f77f883a080e 336 * Or duty-cycle of join requests if OTAA is being attempted
jreiss 21:f77f883a080e 337 * @return ms of time to wait for next tx opportunity
jreiss 21:f77f883a080e 338 */
jreiss 21:f77f883a080e 339 virtual uint32_t GetTimeOffAir();
jreiss 21:f77f883a080e 340
jreiss 21:f77f883a080e 341 /**
jreiss 21:f77f883a080e 342 * Get the channels in use by current channel plan
jreiss 21:f77f883a080e 343 * @return channel frequencies
jreiss 21:f77f883a080e 344 */
jreiss 21:f77f883a080e 345 virtual std::vector<uint32_t> GetChannels();
jreiss 21:f77f883a080e 346
jreiss 21:f77f883a080e 347 /**
jreiss 23:3830a5f61f09 348 * Get the downlink channels in use by current channel plan
jreiss 23:3830a5f61f09 349 * @return channel frequencies
jreiss 23:3830a5f61f09 350 */
jreiss 23:3830a5f61f09 351 virtual std::vector<uint32_t> GetDownlinkChannels();
jreiss 23:3830a5f61f09 352
jreiss 23:3830a5f61f09 353 /**
jreiss 21:f77f883a080e 354 * Get the channel datarate ranges in use by current channel plan
jreiss 21:f77f883a080e 355 * @return channel datarate ranges
jreiss 21:f77f883a080e 356 */
jreiss 21:f77f883a080e 357 virtual std::vector<uint8_t> GetChannelRanges();
jreiss 21:f77f883a080e 358
jreiss 21:f77f883a080e 359 /**
jreiss 21:f77f883a080e 360 * Set the time off air for the given duty band
jreiss 21:f77f883a080e 361 * @param band index
jreiss 21:f77f883a080e 362 * @param time off air in ms
jreiss 21:f77f883a080e 363 */
jreiss 21:f77f883a080e 364 virtual void SetDutyBandTimeOff(uint8_t band, uint32_t timeoff);
jreiss 21:f77f883a080e 365
jreiss 21:f77f883a080e 366 /**
jreiss 21:f77f883a080e 367 * Get the time off air for the given duty band
jreiss 21:f77f883a080e 368 * @param band index
jreiss 21:f77f883a080e 369 * @return time off air in ms
jreiss 21:f77f883a080e 370 */
jreiss 21:f77f883a080e 371 virtual uint32_t GetDutyBandTimeOff(uint8_t band);
jreiss 21:f77f883a080e 372
jreiss 21:f77f883a080e 373 /**
jreiss 21:f77f883a080e 374 * Get the number of duty bands in the current channel plan
jreiss 21:f77f883a080e 375 * @return number of bands
jreiss 21:f77f883a080e 376 */
jreiss 21:f77f883a080e 377 virtual uint8_t GetNumDutyBands();
jreiss 21:f77f883a080e 378
jreiss 21:f77f883a080e 379 /**
jreiss 21:f77f883a080e 380 * Get the duty band index for the given frequency
jreiss 21:f77f883a080e 381 * @param freq frequency in Hz
jreiss 21:f77f883a080e 382 * @return index of duty band
jreiss 21:f77f883a080e 383 */
jreiss 21:f77f883a080e 384 virtual int8_t GetDutyBand(uint32_t freq);
jreiss 21:f77f883a080e 385
jreiss 21:f77f883a080e 386 /**
jreiss 21:f77f883a080e 387 * Add duty band
jreiss 21:f77f883a080e 388 * @param index of duty band or -1 to append
jreiss 21:f77f883a080e 389 * @param band DutyBand definition
jreiss 21:f77f883a080e 390 * @return LORA_OK
jreiss 21:f77f883a080e 391 */
jreiss 21:f77f883a080e 392 virtual uint8_t AddDutyBand(int8_t index, DutyBand band);
jreiss 21:f77f883a080e 393
jreiss 21:f77f883a080e 394 /**
jreiss 21:f77f883a080e 395 * Update duty cycle with current settings
jreiss 21:f77f883a080e 396 */
jreiss 21:f77f883a080e 397 virtual void UpdateDutyCycle(uint8_t bytes);
jreiss 21:f77f883a080e 398
jreiss 21:f77f883a080e 399 /**
jreiss 21:f77f883a080e 400 * Update duty cycle with at given frequency and time on air
jreiss 21:f77f883a080e 401 * @param freq frequency
jreiss 21:f77f883a080e 402 * @param time_on_air_ms tx time on air
jreiss 21:f77f883a080e 403 */
jreiss 21:f77f883a080e 404 virtual void UpdateDutyCycle(uint32_t freq, uint32_t time_on_air_ms);
jreiss 21:f77f883a080e 405
jreiss 21:f77f883a080e 406 /**
jreiss 21:f77f883a080e 407 * Get time on air with current settings
jreiss 21:f77f883a080e 408 * @param bytes number of bytes to be sent
jreiss 21:f77f883a080e 409 */
jreiss 21:f77f883a080e 410 virtual uint32_t GetTimeOnAir(uint8_t bytes);
jreiss 21:f77f883a080e 411
jreiss 21:f77f883a080e 412 /**
jreiss 21:f77f883a080e 413 * Reset the duty timers with the current time off air
jreiss 21:f77f883a080e 414 */
jreiss 21:f77f883a080e 415 virtual void ResetDutyCycleTimer();
jreiss 21:f77f883a080e 416
jreiss 21:f77f883a080e 417 /**
jreiss 21:f77f883a080e 418 * Print log message for given rx window
jreiss 21:f77f883a080e 419 * @param wnd 1 or 2
jreiss 21:f77f883a080e 420 */
jreiss 21:f77f883a080e 421 virtual void LogRxWindow(uint8_t wnd);
jreiss 21:f77f883a080e 422
jreiss 21:f77f883a080e 423 /**
jreiss 21:f77f883a080e 424 * Indicator of P2P mode
jreiss 21:f77f883a080e 425 * @return true if enabled
jreiss 21:f77f883a080e 426 */
jreiss 21:f77f883a080e 427 virtual bool P2PEnabled();
jreiss 21:f77f883a080e 428
jreiss 21:f77f883a080e 429 /**
jreiss 21:f77f883a080e 430 * Ack timeout for P2P mode
jreiss 21:f77f883a080e 431 * @return timeout in ms
jreiss 21:f77f883a080e 432 */
jreiss 21:f77f883a080e 433 virtual uint16_t P2PTimeout();
jreiss 21:f77f883a080e 434
jreiss 21:f77f883a080e 435 /**
jreiss 21:f77f883a080e 436 * Ack backoff for P2P mode
jreiss 21:f77f883a080e 437 * @return backoff in ms
jreiss 21:f77f883a080e 438 */
jreiss 21:f77f883a080e 439 virtual uint16_t P2PBackoff();
jreiss 21:f77f883a080e 440
jreiss 21:f77f883a080e 441 /**
jreiss 21:f77f883a080e 442 * Enable the default channels of the channel plan
jreiss 21:f77f883a080e 443 */
jreiss 21:f77f883a080e 444 virtual void EnableDefaultChannels();
jreiss 21:f77f883a080e 445
jreiss 21:f77f883a080e 446 /**
jreiss 21:f77f883a080e 447 * Callback for radio thread to signal
jreiss 21:f77f883a080e 448 */
jreiss 21:f77f883a080e 449 virtual void MacEvent();
jreiss 21:f77f883a080e 450
jreiss 23:3830a5f61f09 451 /**
jreiss 23:3830a5f61f09 452 * Called before Mac layer handles command buffer.
jreiss 23:3830a5f61f09 453 * Use to add custom or new mac command handling
jreiss 23:3830a5f61f09 454 * @return LORA_OK
jreiss 23:3830a5f61f09 455 */
jreiss 23:3830a5f61f09 456 virtual uint8_t HandleMacCommands(uint8_t* payload, uint8_t index, uint8_t end_index);
jreiss 23:3830a5f61f09 457
jreiss 21:f77f883a080e 458 virtual void DecrementDatarate();
jreiss 21:f77f883a080e 459 virtual void IncrementDatarate();
jreiss 21:f77f883a080e 460
jreiss 23:3830a5f61f09 461 virtual std::string GetPlanName();
jreiss 21:f77f883a080e 462 virtual uint8_t GetPlanType();
jreiss 23:3830a5f61f09 463 virtual uint32_t GetMinFrequency();
jreiss 23:3830a5f61f09 464 virtual uint32_t GetMaxFrequency();
jreiss 23:3830a5f61f09 465
jreiss 23:3830a5f61f09 466 virtual uint8_t GetMinDatarate();
jreiss 23:3830a5f61f09 467 virtual uint8_t GetMaxDatarate();
jreiss 23:3830a5f61f09 468 virtual uint8_t GetMinDatarateOffset();
jreiss 23:3830a5f61f09 469 virtual uint8_t GetMaxDatarateOffset();
jreiss 23:3830a5f61f09 470
jreiss 23:3830a5f61f09 471 virtual uint8_t GetMinRx2Datarate();
jreiss 23:3830a5f61f09 472 virtual uint8_t GetMaxRx2Datarate();
jreiss 23:3830a5f61f09 473 virtual uint8_t GetMaxTxPower();
jreiss 23:3830a5f61f09 474
jreiss 23:3830a5f61f09 475 virtual uint32_t GetLBT_TimeMs();
jreiss 23:3830a5f61f09 476 virtual void SetLBT_TimeMs(uint32_t ms);
jreiss 23:3830a5f61f09 477
jreiss 23:3830a5f61f09 478 virtual int32_t GetLBT_Threshold();
jreiss 23:3830a5f61f09 479 virtual void SetLBT_Threshold(int32_t rssi);
jreiss 23:3830a5f61f09 480
jreiss 23:3830a5f61f09 481 bool ListenBeforeTalk();
jreiss 21:f77f883a080e 482
jreiss 21:f77f883a080e 483 protected:
jreiss 21:f77f883a080e 484
jreiss 21:f77f883a080e 485 SxRadio& _radio; //!< Injected SxRadio dependency
jreiss 21:f77f883a080e 486 Settings& _settings; //!< Current settings
jreiss 21:f77f883a080e 487
jreiss 21:f77f883a080e 488 uint8_t _txChannel; //!< Current channel for transmit
jreiss 21:f77f883a080e 489 uint8_t _txChannelGroup; //!< Current channel group for hybrid operation
jreiss 21:f77f883a080e 490
jreiss 21:f77f883a080e 491 std::vector<Datarate> _datarates; //!< List of datarates
jreiss 21:f77f883a080e 492
jreiss 21:f77f883a080e 493 std::vector<Channel> _channels; //!< List of channels for transmit
jreiss 23:3830a5f61f09 494 std::vector<Channel> _dlChannels; //!< List of channels for receive if changed from default
jreiss 21:f77f883a080e 495
jreiss 21:f77f883a080e 496 std::vector<DutyBand> _dutyBands; //!< List of duty bands to limit radio time on air
jreiss 21:f77f883a080e 497
jreiss 21:f77f883a080e 498 uint8_t _maxTxPower; //!< Max Tx power for channel Plan
jreiss 21:f77f883a080e 499 uint8_t _minTxPower;
jreiss 21:f77f883a080e 500
jreiss 21:f77f883a080e 501 uint32_t _minFrequency; //!< Minimum Frequency
jreiss 21:f77f883a080e 502 uint32_t _maxFrequency; //!< Maximum Frequency
jreiss 21:f77f883a080e 503
jreiss 21:f77f883a080e 504 Channel _beaconChannel; //!< Beacon window settings
jreiss 21:f77f883a080e 505 Channel _beaconRxChannel; //!< Beacon slot rx window settings
jreiss 21:f77f883a080e 506
jreiss 21:f77f883a080e 507 uint8_t _minDatarate; //!< Minimum datarate to accept in ADR request
jreiss 21:f77f883a080e 508 uint8_t _maxDatarate; //!< Maximum datarate to accept in ADR request
jreiss 21:f77f883a080e 509
jreiss 21:f77f883a080e 510 uint8_t _minRx2Datarate; //!< Minimum datarate to accept in for Rx2
jreiss 21:f77f883a080e 511 uint8_t _maxRx2Datarate; //!< Maximum datarate to accept in for Rx2
jreiss 21:f77f883a080e 512 uint8_t _minDatarateOffset; //!< Minimum datarate offset to accept
jreiss 21:f77f883a080e 513 uint8_t _maxDatarateOffset; //!< Maximum datarate offset to accept
jreiss 21:f77f883a080e 514
jreiss 21:f77f883a080e 515 uint32_t _freqUBase125k; //!< Start of 125K uplink channels
jreiss 21:f77f883a080e 516 uint32_t _freqUStep125k; //!< Step between 125K uplink channels
jreiss 21:f77f883a080e 517 uint32_t _freqUBase500k; //!< Start of 500K uplink channels
jreiss 21:f77f883a080e 518 uint32_t _freqUStep500k; //!< Step between 500K uplink channels
jreiss 21:f77f883a080e 519 uint32_t _freqDBase500k; //!< Start of 500K downlink channels
jreiss 21:f77f883a080e 520 uint32_t _freqDStep500k; //!< Step between 500K downlink channels
jreiss 21:f77f883a080e 521
jreiss 21:f77f883a080e 522 uint8_t _numChans; //!< Number of total channels in plan
jreiss 21:f77f883a080e 523 uint8_t _numChans125k; //!< Number of 125K channels in plan
jreiss 21:f77f883a080e 524 uint8_t _numChans500k; //!< Number of 500K channels in plan
jreiss 21:f77f883a080e 525
jreiss 23:3830a5f61f09 526 uint32_t _LBT_TimeMs; //!<
jreiss 23:3830a5f61f09 527 int32_t _LBT_Threshold; //!<
jreiss 23:3830a5f61f09 528
jreiss 21:f77f883a080e 529 std::vector<uint16_t> _channelMask; //!< Bit mask for currently enabled channels
jreiss 21:f77f883a080e 530
jreiss 21:f77f883a080e 531 Timer _dutyCycleTimer; //!< Timer for tracking time-off-air
jreiss 21:f77f883a080e 532 RtosTimer _txDutyTimer; //!< Event timer for expiration of time-off-air
jreiss 21:f77f883a080e 533
jreiss 21:f77f883a080e 534 bool _txDutyCyclePending; //!< Flag for pending duty cycle event
jreiss 21:f77f883a080e 535
jreiss 21:f77f883a080e 536 static void OnTxDutyCycleEvent(const void* arg); //!< Rtos callback for duty cycle event
jreiss 21:f77f883a080e 537 void OnTxDutyCycleEventBottom(); //!< Callback for duty cycle event
jreiss 21:f77f883a080e 538
jreiss 21:f77f883a080e 539 static const uint8_t* TX_POWERS; //!< List of available tx powers
jreiss 21:f77f883a080e 540 static const uint8_t* RADIO_POWERS; //!< List of available tx powers
jreiss 21:f77f883a080e 541 static const uint8_t* MAX_PAYLOAD_SIZE; //!< List of max payload sizes for each datarate
jreiss 21:f77f883a080e 542 static const uint8_t* MAX_PAYLOAD_SIZE_REPEATER; //!< List of repeater compatible max payload sizes for each datarate
jreiss 21:f77f883a080e 543
jreiss 21:f77f883a080e 544 static const uint8_t EU868_TX_POWERS[6]; //!< List of available tx powers
jreiss 21:f77f883a080e 545 static const uint8_t EU868_RADIO_POWERS[21]; //!< List of calibrated tx powers
jreiss 21:f77f883a080e 546 static const uint8_t EU868_MAX_PAYLOAD_SIZE[]; //!< List of max payload sizes for each datarate
jreiss 21:f77f883a080e 547 static const uint8_t EU868_MAX_PAYLOAD_SIZE_REPEATER[]; //!< List of repeater compatible max payload sizes for each datarate
jreiss 21:f77f883a080e 548
jreiss 21:f77f883a080e 549 static const uint8_t US915_TX_POWERS[11]; //!< List of available tx powers
jreiss 21:f77f883a080e 550 static const uint8_t US915_RADIO_POWERS[21]; //!< List of calibrated tx powers
jreiss 21:f77f883a080e 551 static const uint8_t US915_MAX_PAYLOAD_SIZE[]; //!< List of max payload sizes for each datarate
jreiss 21:f77f883a080e 552 static const uint8_t US915_MAX_PAYLOAD_SIZE_REPEATER[]; //!< List of repeater compatible max payload sizes for each datarate
jreiss 21:f77f883a080e 553
jreiss 21:f77f883a080e 554 static const uint8_t AU915_TX_POWERS[11]; //!< List of available tx powers
jreiss 21:f77f883a080e 555 static const uint8_t AU915_RADIO_POWERS[21]; //!< List of calibrated tx powers
jreiss 21:f77f883a080e 556 static const uint8_t AU915_MAX_PAYLOAD_SIZE[]; //!< List of max payload sizes for each datarate
jreiss 21:f77f883a080e 557 static const uint8_t AU915_MAX_PAYLOAD_SIZE_REPEATER[]; //!< List of repeater compatible max payload sizes for each datarate
jreiss 21:f77f883a080e 558
jreiss 21:f77f883a080e 559 PlanType _type;
jreiss 23:3830a5f61f09 560 std::string _planName;
jreiss 21:f77f883a080e 561 };
jreiss 21:f77f883a080e 562 }
jreiss 21:f77f883a080e 563
jreiss 21:f77f883a080e 564 #endif
jreiss 21:f77f883a080e 565