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:
Mon Oct 17 14:43:21 2016 +0000
Revision:
21:f77f883a080e
add channel plans folder; update libraries to include compiled channel plan objects

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