MultiTech / libxDot-Custom

Fork of libxDot-dev-mbed5-deprecated by MultiTech

The Connect example can be used as a starting point for an xDot application.

Import programmDot_LoRa_Connect_Example_CUSTOM_AS923

Example configuration of frequencies and datarates for AS923 channel plan.

Change the libmDot-Custom library to libxDot-Custom after importing the above example.

Change the platform for the project to xDot in upper right corner of the compiler page.

Ensure the mbed-os version matches the with the library commit.

Currently the AT Firmware cannot be built online for the xDot.

Creating new channel plans

Copy EU868 or US915 custom channel plan as a starting point

Import librarymDot_Channel_Plans

Channel plans to enable libmDot-Custom

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:
Mon Oct 31 14:51:55 2016 +0000
Revision:
23:17a25e16ccf1
update to mbed-os 5.2.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jreiss 23:17a25e16ccf1 1 /** __ ___ ____ _ ______ __ ____ __ ____
jreiss 23:17a25e16ccf1 2 * / |/ /_ __/ / /_(_)__/_ __/__ ____/ / / __/_ _____ / /____ __ _ ___ / _/__ ____
jreiss 23:17a25e16ccf1 3 * / /|_/ / // / / __/ /___// / / -_) __/ _ \ _\ \/ // (_-</ __/ -_) ' \(_-< _/ // _ \/ __/ __
jreiss 23:17a25e16ccf1 4 * /_/ /_/\_,_/_/\__/_/ /_/ \__/\__/_//_/ /___/\_, /___/\__/\__/_/_/_/___/ /___/_//_/\__/ /_/
jreiss 23:17a25e16ccf1 5 * Copyright (C) 2015 by Multi-Tech Systems /___/
jreiss 23:17a25e16ccf1 6 *
jreiss 23:17a25e16ccf1 7 *
jreiss 23:17a25e16ccf1 8 * @author Jason Reiss
jreiss 23:17a25e16ccf1 9 * @date 10-31-2015
jreiss 23:17a25e16ccf1 10 * @brief lora::ChannelPlan provides an interface for LoRaWAN channel schemes
jreiss 23:17a25e16ccf1 11 *
jreiss 23:17a25e16ccf1 12 * @details
jreiss 23:17a25e16ccf1 13 *
jreiss 23:17a25e16ccf1 14 */
jreiss 23:17a25e16ccf1 15
jreiss 23:17a25e16ccf1 16 #ifndef __CUSTOM_CHANNEL_PLAN_AU915_H__
jreiss 23:17a25e16ccf1 17 #define __CUSTOM_CHANNEL_PLAN_AU915_H__
jreiss 23:17a25e16ccf1 18
jreiss 23:17a25e16ccf1 19 #include "Lora.h"
jreiss 23:17a25e16ccf1 20 #include "SxRadio.h"
jreiss 23:17a25e16ccf1 21 #include "ChannelPlan.h"
jreiss 23:17a25e16ccf1 22 #include <vector>
jreiss 23:17a25e16ccf1 23
jreiss 23:17a25e16ccf1 24 namespace lora {
jreiss 23:17a25e16ccf1 25
jreiss 23:17a25e16ccf1 26 class CustomChannelPlan_AU915 : public lora::ChannelPlan {
jreiss 23:17a25e16ccf1 27 public:
jreiss 23:17a25e16ccf1 28
jreiss 23:17a25e16ccf1 29 /**
jreiss 23:17a25e16ccf1 30 * ChannelPlan constructor
jreiss 23:17a25e16ccf1 31 * @param radio SxRadio object used to set Tx/Rx config
jreiss 23:17a25e16ccf1 32 * @param settings Settings object
jreiss 23:17a25e16ccf1 33 */
jreiss 23:17a25e16ccf1 34 CustomChannelPlan_AU915(SxRadio& radio, Settings& settings);
jreiss 23:17a25e16ccf1 35
jreiss 23:17a25e16ccf1 36 /**
jreiss 23:17a25e16ccf1 37 * ChannelPlan destructor
jreiss 23:17a25e16ccf1 38 */
jreiss 23:17a25e16ccf1 39 virtual ~CustomChannelPlan_AU915();
jreiss 23:17a25e16ccf1 40
jreiss 23:17a25e16ccf1 41 /**
jreiss 23:17a25e16ccf1 42 * Initialize channels, datarates and duty cycle bands according to current channel plan in settings
jreiss 23:17a25e16ccf1 43 */
jreiss 23:17a25e16ccf1 44 virtual void Init();
jreiss 23:17a25e16ccf1 45
jreiss 23:17a25e16ccf1 46 /**
jreiss 23:17a25e16ccf1 47 * Get the next channel to use to transmit
jreiss 23:17a25e16ccf1 48 * @return LORA_OK if channel was found
jreiss 23:17a25e16ccf1 49 * @return LORA_NO_CHANS_ENABLED
jreiss 23:17a25e16ccf1 50 */
jreiss 23:17a25e16ccf1 51 virtual uint8_t GetNextChannel();
jreiss 23:17a25e16ccf1 52
jreiss 23:17a25e16ccf1 53 /**
jreiss 23:17a25e16ccf1 54 * Set the number of channels in the plan
jreiss 23:17a25e16ccf1 55 */
jreiss 23:17a25e16ccf1 56 virtual void SetNumberOfChannels(uint8_t channels, bool resize = true);
jreiss 23:17a25e16ccf1 57
jreiss 23:17a25e16ccf1 58 /**
jreiss 23:17a25e16ccf1 59 * Check if channel is enabled
jreiss 23:17a25e16ccf1 60 * @return true if enabled
jreiss 23:17a25e16ccf1 61 */
jreiss 23:17a25e16ccf1 62 virtual bool IsChannelEnabled(uint8_t channel);
jreiss 23:17a25e16ccf1 63
jreiss 23:17a25e16ccf1 64
jreiss 23:17a25e16ccf1 65 /**
jreiss 23:17a25e16ccf1 66 * Add a channel to the ChannelPlan
jreiss 23:17a25e16ccf1 67 * @param index of channel, use -1 to add to end
jreiss 23:17a25e16ccf1 68 * @param channel settings to add
jreiss 23:17a25e16ccf1 69 */
jreiss 23:17a25e16ccf1 70 virtual uint8_t AddChannel(int8_t index, Channel channel);
jreiss 23:17a25e16ccf1 71
jreiss 23:17a25e16ccf1 72 /**
jreiss 23:17a25e16ccf1 73 * Get channel at index
jreiss 23:17a25e16ccf1 74 * @return Channel
jreiss 23:17a25e16ccf1 75 */
jreiss 23:17a25e16ccf1 76 virtual Channel GetChannel(int8_t index);
jreiss 23:17a25e16ccf1 77
jreiss 23:17a25e16ccf1 78 /**
jreiss 23:17a25e16ccf1 79 * Get rx window settings for requested window
jreiss 23:17a25e16ccf1 80 * RX_1, RX_2, RX_BEACON, RX_SLOT
jreiss 23:17a25e16ccf1 81 * @param window
jreiss 23:17a25e16ccf1 82 * @return RxWindow
jreiss 23:17a25e16ccf1 83 */
jreiss 23:17a25e16ccf1 84 virtual RxWindow GetRxWindow(uint8_t window);
jreiss 23:17a25e16ccf1 85
jreiss 23:17a25e16ccf1 86 /**
jreiss 23:17a25e16ccf1 87 * Get datarate to use on the join request
jreiss 23:17a25e16ccf1 88 * @return datarate index
jreiss 23:17a25e16ccf1 89 */
jreiss 23:17a25e16ccf1 90 virtual uint8_t GetJoinDatarate();
jreiss 23:17a25e16ccf1 91
jreiss 23:17a25e16ccf1 92 /**
jreiss 23:17a25e16ccf1 93 * Calculate the next time a join request is possible
jreiss 23:17a25e16ccf1 94 * @param size of join frame
jreiss 23:17a25e16ccf1 95 * @returns LORA_OK
jreiss 23:17a25e16ccf1 96 */
jreiss 23:17a25e16ccf1 97 virtual uint8_t CalculateJoinBackoff(uint8_t size);
jreiss 23:17a25e16ccf1 98
jreiss 23:17a25e16ccf1 99 /**
jreiss 23:17a25e16ccf1 100 * Set the datarate offset used for first receive window
jreiss 23:17a25e16ccf1 101 * @param offset
jreiss 23:17a25e16ccf1 102 * @return LORA_OK
jreiss 23:17a25e16ccf1 103 */
jreiss 23:17a25e16ccf1 104 virtual uint8_t SetRx1Offset(uint8_t offset);
jreiss 23:17a25e16ccf1 105
jreiss 23:17a25e16ccf1 106 /**
jreiss 23:17a25e16ccf1 107 * Set the frequency for second receive window
jreiss 23:17a25e16ccf1 108 * @param freq
jreiss 23:17a25e16ccf1 109 * @return LORA_OK
jreiss 23:17a25e16ccf1 110 */
jreiss 23:17a25e16ccf1 111 virtual uint8_t SetRx2Frequency(uint32_t freq);
jreiss 23:17a25e16ccf1 112
jreiss 23:17a25e16ccf1 113 /**
jreiss 23:17a25e16ccf1 114 * Set the datarate index used for second receive window
jreiss 23:17a25e16ccf1 115 * @param index
jreiss 23:17a25e16ccf1 116 * @return LORA_OK
jreiss 23:17a25e16ccf1 117 */
jreiss 23:17a25e16ccf1 118 virtual uint8_t SetRx2DatarateIndex(uint8_t index);
jreiss 23:17a25e16ccf1 119
jreiss 23:17a25e16ccf1 120 /**
jreiss 23:17a25e16ccf1 121 * Get next channel and set the SxRadio tx config with current settings
jreiss 23:17a25e16ccf1 122 * @return LORA_OK
jreiss 23:17a25e16ccf1 123 */
jreiss 23:17a25e16ccf1 124 virtual uint8_t SetTxConfig();
jreiss 23:17a25e16ccf1 125
jreiss 23:17a25e16ccf1 126 /**
jreiss 23:17a25e16ccf1 127 * Set the SxRadio rx config provided window
jreiss 23:17a25e16ccf1 128 * @param window to be opened
jreiss 23:17a25e16ccf1 129 * @param continuous keep window open
jreiss 23:17a25e16ccf1 130 * @return LORA_OK
jreiss 23:17a25e16ccf1 131 */
jreiss 23:17a25e16ccf1 132 virtual uint8_t SetRxConfig(uint8_t window, bool continuous);
jreiss 23:17a25e16ccf1 133
jreiss 23:17a25e16ccf1 134 /**
jreiss 23:17a25e16ccf1 135 * Set channel group if supported by plan
jreiss 23:17a25e16ccf1 136 * @param group
jreiss 23:17a25e16ccf1 137 * @return LORA_OK
jreiss 23:17a25e16ccf1 138 */
jreiss 23:17a25e16ccf1 139 virtual uint8_t SetChannelGroup(uint8_t group);
jreiss 23:17a25e16ccf1 140
jreiss 23:17a25e16ccf1 141 /**
jreiss 23:17a25e16ccf1 142 * Callback for Join Accept packet to load optional channels
jreiss 23:17a25e16ccf1 143 * @return LORA_OK
jreiss 23:17a25e16ccf1 144 */
jreiss 23:17a25e16ccf1 145 virtual uint8_t HandleJoinAccept(const uint8_t* buffer, uint8_t size);
jreiss 23:17a25e16ccf1 146
jreiss 23:17a25e16ccf1 147 /**
jreiss 23:17a25e16ccf1 148 * Callback to for rx parameter setup ServerCommand
jreiss 23:17a25e16ccf1 149 * @param payload packet data
jreiss 23:17a25e16ccf1 150 * @param index of start of command buffer
jreiss 23:17a25e16ccf1 151 * @param size number of bytes in command buffer
jreiss 23:17a25e16ccf1 152 * @param[out] status to be returned in MoteCommand answer
jreiss 23:17a25e16ccf1 153 * @return LORA_OK
jreiss 23:17a25e16ccf1 154 */
jreiss 23:17a25e16ccf1 155 virtual uint8_t HandleRxParamSetup(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status);
jreiss 23:17a25e16ccf1 156
jreiss 23:17a25e16ccf1 157 /**
jreiss 23:17a25e16ccf1 158 * Callback to for new channel ServerCommand
jreiss 23:17a25e16ccf1 159 * @param payload packet data
jreiss 23:17a25e16ccf1 160 * @param index of start of command buffer
jreiss 23:17a25e16ccf1 161 * @param size number of bytes in command buffer
jreiss 23:17a25e16ccf1 162 * @param[out] status to be returned in MoteCommand answer
jreiss 23:17a25e16ccf1 163 * @return LORA_OK
jreiss 23:17a25e16ccf1 164 */
jreiss 23:17a25e16ccf1 165 virtual uint8_t HandleNewChannel(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status);
jreiss 23:17a25e16ccf1 166
jreiss 23:17a25e16ccf1 167 /**
jreiss 23:17a25e16ccf1 168 * Callback to for ping slot channel request ServerCommand
jreiss 23:17a25e16ccf1 169 * @param payload packet data
jreiss 23:17a25e16ccf1 170 * @param index of start of command buffer
jreiss 23:17a25e16ccf1 171 * @param size number of bytes in command buffer
jreiss 23:17a25e16ccf1 172 * @param[out] status to be returned in MoteCommand answer
jreiss 23:17a25e16ccf1 173 * @return LORA_OK
jreiss 23:17a25e16ccf1 174 */
jreiss 23:17a25e16ccf1 175 virtual uint8_t HandlePingSlotChannelReq(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status);
jreiss 23:17a25e16ccf1 176
jreiss 23:17a25e16ccf1 177 /**
jreiss 23:17a25e16ccf1 178 * Callback to for beacon frequency request ServerCommand
jreiss 23:17a25e16ccf1 179 * @param payload packet data
jreiss 23:17a25e16ccf1 180 * @param index of start of command buffer
jreiss 23:17a25e16ccf1 181 * @param size number of bytes in command buffer
jreiss 23:17a25e16ccf1 182 * @param[out] status to be returned in MoteCommand answer
jreiss 23:17a25e16ccf1 183 * @return LORA_OK
jreiss 23:17a25e16ccf1 184 */
jreiss 23:17a25e16ccf1 185 virtual uint8_t HandleBeaconFrequencyReq(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status);
jreiss 23:17a25e16ccf1 186
jreiss 23:17a25e16ccf1 187 /**
jreiss 23:17a25e16ccf1 188 * Callback to for adaptive datarate ServerCommand
jreiss 23:17a25e16ccf1 189 * @param payload packet data
jreiss 23:17a25e16ccf1 190 * @param index of start of command buffer
jreiss 23:17a25e16ccf1 191 * @param size number of bytes in command buffer
jreiss 23:17a25e16ccf1 192 * @param[out] status to be returned in MoteCommand answer
jreiss 23:17a25e16ccf1 193 * @return LORA_OK
jreiss 23:17a25e16ccf1 194 */
jreiss 23:17a25e16ccf1 195 virtual uint8_t HandleAdrCommand(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status);
jreiss 23:17a25e16ccf1 196
jreiss 23:17a25e16ccf1 197 /**
jreiss 23:17a25e16ccf1 198 * Flag if ADR ACK should be sent in next packet
jreiss 23:17a25e16ccf1 199 * @return true when flag should be set
jreiss 23:17a25e16ccf1 200 */
jreiss 23:17a25e16ccf1 201 virtual bool AdrAckReq();
jreiss 23:17a25e16ccf1 202
jreiss 23:17a25e16ccf1 203 /**
jreiss 23:17a25e16ccf1 204 * Get the time the radio must be off air to comply with regulations
jreiss 23:17a25e16ccf1 205 * Time to wait may be dependent on duty-cycle restrictions per channel
jreiss 23:17a25e16ccf1 206 * Or duty-cycle of join requests if OTAA is being attempted
jreiss 23:17a25e16ccf1 207 * @return ms of time to wait for next tx opportunity
jreiss 23:17a25e16ccf1 208 */
jreiss 23:17a25e16ccf1 209 virtual uint32_t GetTimeOffAir();
jreiss 23:17a25e16ccf1 210
jreiss 23:17a25e16ccf1 211 /**
jreiss 23:17a25e16ccf1 212 * Get the channels in use by current channel plan
jreiss 23:17a25e16ccf1 213 * @return channel frequencies
jreiss 23:17a25e16ccf1 214 */
jreiss 23:17a25e16ccf1 215 virtual std::vector<uint32_t> GetChannels();
jreiss 23:17a25e16ccf1 216
jreiss 23:17a25e16ccf1 217 /**
jreiss 23:17a25e16ccf1 218 * Get the channel datarate ranges in use by current channel plan
jreiss 23:17a25e16ccf1 219 * @return channel datarate ranges
jreiss 23:17a25e16ccf1 220 */
jreiss 23:17a25e16ccf1 221 virtual std::vector<uint8_t> GetChannelRanges();
jreiss 23:17a25e16ccf1 222
jreiss 23:17a25e16ccf1 223
jreiss 23:17a25e16ccf1 224 /**
jreiss 23:17a25e16ccf1 225 * Print log message for given rx window
jreiss 23:17a25e16ccf1 226 * @param wnd 1 or 2
jreiss 23:17a25e16ccf1 227 */
jreiss 23:17a25e16ccf1 228 virtual void LogRxWindow(uint8_t wnd);
jreiss 23:17a25e16ccf1 229
jreiss 23:17a25e16ccf1 230 /**
jreiss 23:17a25e16ccf1 231 * Enable the default channels of the channel plan
jreiss 23:17a25e16ccf1 232 */
jreiss 23:17a25e16ccf1 233 virtual void EnableDefaultChannels();
jreiss 23:17a25e16ccf1 234
jreiss 23:17a25e16ccf1 235 protected:
jreiss 23:17a25e16ccf1 236
jreiss 23:17a25e16ccf1 237 static const uint8_t AU915_TX_POWERS[11]; //!< List of available tx powers
jreiss 23:17a25e16ccf1 238 static const uint8_t AU915_RADIO_POWERS[21]; //!< List of calibrated tx powers
jreiss 23:17a25e16ccf1 239 static const uint8_t AU915_MAX_PAYLOAD_SIZE[]; //!< List of max payload sizes for each datarate
jreiss 23:17a25e16ccf1 240 static const uint8_t AU915_MAX_PAYLOAD_SIZE_REPEATER[]; //!< List of repeater compatible max payload sizes for each datarate
jreiss 23:17a25e16ccf1 241
jreiss 23:17a25e16ccf1 242 };
jreiss 23:17a25e16ccf1 243 }
jreiss 23:17a25e16ccf1 244
jreiss 23:17a25e16ccf1 245 #endif // __CUSTOM_CHANNEL_PLAN_AU915_H__
jreiss 23:17a25e16ccf1 246