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:
Thu Mar 16 13:23:56 2017 +0000
Revision:
28:3234d66ebb05
Parent:
25:4c9011fa3b87
remove weak attribute from printMessage

Who changed what in which revision?

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