Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ChannelPlan_IN865.h
00001 /** __ ___ ____ _ ______ __ ____ __ ____ 00002 * / |/ /_ __/ / /_(_)__/_ __/__ ____/ / / __/_ _____ / /____ __ _ ___ / _/__ ____ 00003 * / /|_/ / // / / __/ /___// / / -_) __/ _ \ _\ \/ // (_-</ __/ -_) ' \(_-< _/ // _ \/ __/ __ 00004 * /_/ /_/\_,_/_/\__/_/ /_/ \__/\__/_//_/ /___/\_, /___/\__/\__/_/_/_/___/ /___/_//_/\__/ /_/ 00005 * Copyright (C) 2015 by Multi-Tech Systems /___/ 00006 * 00007 * 00008 * @author Jason Reiss 00009 * @date 10-31-2015 00010 * @brief lora::ChannelPlan provides an interface for LoRaWAN channel schemes 00011 * 00012 * @details 00013 * 00014 */ 00015 00016 #ifndef __CHANNEL_PLAN_IN865_H__ 00017 #define __CHANNEL_PLAN_IN865_H__ 00018 00019 #include "Lora.h" 00020 #include "SxRadio.h" 00021 #include <vector> 00022 #include "ChannelPlan.h" 00023 00024 namespace lora { 00025 00026 const uint8_t IN865_125K_NUM_CHANS = 16; //!< Number of 125k channels in IN865 channel plan 00027 const uint8_t IN865_DEFAULT_NUM_CHANS = 3; //!< Number of default channels in IN865 channel plan 00028 const uint32_t IN865_125K_DEF_FREQ_1 = 865062500; 00029 const uint32_t IN865_125K_DEF_FREQ_2 = 865402500; 00030 const uint32_t IN865_125K_DEF_FREQ_3 = 865985000; 00031 const uint32_t IN865_RX2_FREQ = 866550000; //!< Frequency default for second rx window in IN865 00032 const uint8_t IN865_TX_POWER_MAX = 30; //!< Max power for IN865 channel plan 00033 const uint8_t IN865_BEACON_DR = DR_4; //!< Default beacon datarate 00034 const uint32_t IN865_BEACON_FREQ = 866550000U; //!< Default beacon broadcast frequency 00035 00036 class ChannelPlan_IN865 : public lora::ChannelPlan { 00037 public: 00038 /** 00039 * ChannelPlan constructor 00040 * @param radio SxRadio object used to set Tx/Rx config 00041 * @param settings Settings object 00042 */ 00043 ChannelPlan_IN865(); 00044 ChannelPlan_IN865(Settings* settings); 00045 ChannelPlan_IN865(SxRadio* radio, Settings* settings); 00046 00047 /** 00048 * ChannelPlan destructor 00049 */ 00050 virtual ~ChannelPlan_IN865(); 00051 00052 /** 00053 * Initialize channels, datarates and duty cycle bands according to current channel plan in settings 00054 */ 00055 virtual void Init(); 00056 00057 /** 00058 * Get the next channel to use to transmit 00059 * @return LORA_OK if channel was found 00060 * @return LORA_NO_CHANS_ENABLED 00061 */ 00062 virtual uint8_t GetNextChannel(); 00063 00064 /** 00065 * Add a channel to the ChannelPlan 00066 * @param index of channel, use -1 to add to end 00067 * @param channel settings to add 00068 */ 00069 virtual uint8_t AddChannel(int8_t index, Channel channel); 00070 00071 /** 00072 * Get channel at index 00073 * @return Channel 00074 */ 00075 virtual Channel GetChannel(int8_t index); 00076 00077 /** 00078 * Get rx window settings for requested window 00079 * RX_1, RX_2, RX_BEACON, RX_SLOT 00080 * @param window 00081 * @return RxWindow 00082 */ 00083 virtual RxWindow GetRxWindow(uint8_t window); 00084 00085 /** 00086 * Get datarate to use on the join request 00087 * @return datarate index 00088 */ 00089 virtual uint8_t GetJoinDatarate(); 00090 00091 /** 00092 * Calculate the next time a join request is possible 00093 * @param size of join frame 00094 * @returns LORA_OK 00095 */ 00096 virtual uint8_t CalculateJoinBackoff(uint8_t size); 00097 00098 /** 00099 * Get next channel and set the SxRadio tx config with current settings 00100 * @return LORA_OK 00101 */ 00102 virtual uint8_t SetTxConfig(); 00103 00104 /** 00105 * Set the SxRadio rx config provided window 00106 * @param window to be opened 00107 * @param continuous keep window open 00108 * @param wnd_growth factor to increase the rx window by 00109 * @param pad_ms time in milliseconds to add to computed window size 00110 * @return LORA_OK 00111 */ 00112 virtual uint8_t SetRxConfig(uint8_t window, 00113 bool continuous, 00114 uint16_t wnd_growth, 00115 uint16_t pad_ms); 00116 00117 /** 00118 * Set frequency sub band if supported by plan 00119 * @param sub_band 00120 * @return LORA_OK 00121 */ 00122 virtual uint8_t SetFrequencySubBand(uint8_t sub_band); 00123 00124 /** 00125 * Callback for ACK timeout event 00126 * @return LORA_OK 00127 */ 00128 virtual uint8_t HandleAckTimeout(); 00129 00130 /** 00131 * Callback for Join Accept packet to load optional channels 00132 * @return LORA_OK 00133 */ 00134 virtual uint8_t HandleJoinAccept(const uint8_t* buffer, uint8_t size); 00135 00136 /** 00137 * Callback to for rx parameter setup ServerCommand 00138 * @param payload packet data 00139 * @param index of start of command buffer 00140 * @param size number of bytes in command buffer 00141 * @param[out] status to be returned in MoteCommand answer 00142 * @return LORA_OK 00143 */ 00144 virtual uint8_t HandleRxParamSetup(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status); 00145 00146 /** 00147 * Callback to for new channel ServerCommand 00148 * @param payload packet data 00149 * @param index of start of command buffer 00150 * @param size number of bytes in command buffer 00151 * @param[out] status to be returned in MoteCommand answer 00152 * @return LORA_OK 00153 */ 00154 virtual uint8_t HandleNewChannel(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status); 00155 00156 /** 00157 * Callback to for ping slot channel request ServerCommand 00158 * @param payload packet data 00159 * @param index of start of command buffer 00160 * @param size number of bytes in command buffer 00161 * @param[out] status to be returned in MoteCommand answer 00162 * @return LORA_OK 00163 */ 00164 virtual uint8_t HandlePingSlotChannelReq(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status); 00165 00166 /** 00167 * Callback to for beacon frequency request ServerCommand 00168 * @param payload packet data 00169 * @param index of start of command buffer 00170 * @param size number of bytes in command buffer 00171 * @param[out] status to be returned in MoteCommand answer 00172 * @return LORA_OK 00173 */ 00174 virtual uint8_t HandleBeaconFrequencyReq(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status); 00175 00176 /** 00177 * Callback to for adaptive datarate ServerCommand 00178 * @param payload packet data 00179 * @param index of start of command buffer 00180 * @param size number of bytes in command buffer 00181 * @param[out] status to be returned in MoteCommand answer 00182 * @return LORA_OK 00183 */ 00184 virtual uint8_t HandleAdrCommand(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status); 00185 00186 /** 00187 * Validate the configuration after multiple ADR commands have been applied 00188 * @return status to be returned in MoteCommand answer 00189 */ 00190 virtual uint8_t ValidateAdrConfiguration(); 00191 00192 /** 00193 * Update duty cycle with at given frequency and time on air 00194 * @param freq frequency 00195 * @param time_on_air_ms tx time on air 00196 */ 00197 virtual void UpdateDutyCycle(uint32_t freq, uint32_t time_on_air_ms); 00198 00199 /** 00200 * Get the time the radio must be off air to comply with regulations 00201 * Time to wait may be dependent on duty-cycle restrictions per channel 00202 * Or duty-cycle of join requests if OTAA is being attempted 00203 * @return ms of time to wait for next tx opportunity 00204 */ 00205 virtual uint32_t GetTimeOffAir(); 00206 00207 /** 00208 * Get the channels in use by current channel plan 00209 * @return channel frequencies 00210 */ 00211 virtual std::vector<uint32_t> GetChannels(); 00212 00213 /** 00214 * Get the channel datarate ranges in use by current channel plan 00215 * @return channel datarate ranges 00216 */ 00217 virtual std::vector<uint8_t> GetChannelRanges(); 00218 00219 /** 00220 * Print log message for given rx window 00221 * @param wnd 1 or 2 00222 */ 00223 virtual void LogRxWindow(uint8_t wnd); 00224 00225 /** 00226 * Enable the default channels of the channel plan 00227 */ 00228 virtual void EnableDefaultChannels(); 00229 00230 /** 00231 * Called when MAC layer doesn't know about a command. 00232 * Use to add custom or new mac command handling 00233 * @return LORA_OK 00234 */ 00235 virtual uint8_t HandleMacCommand(uint8_t* payload, uint8_t& index); 00236 00237 /** 00238 *Decrements the datarate based on TxDwellTime 00239 */ 00240 virtual void DecrementDatarate(); 00241 00242 /** 00243 *Decrements the datarate based on TxDwellTime 00244 */ 00245 virtual void IncrementDatarate(); 00246 00247 /** 00248 * Check if this packet is a beacon and if so extract parameters needed 00249 * @param payload of potential beacon 00250 * @param size of the packet 00251 * @param [out] data extracted from the beacon if this packet was indeed a beacon 00252 * @return true if this packet is beacon, false if not 00253 */ 00254 virtual bool DecodeBeacon(const uint8_t* payload, 00255 size_t size, 00256 BeaconData_t& data); 00257 00258 protected: 00259 00260 static const uint8_t IN865_TX_POWERS[11]; //!< List of available tx powers 00261 static const uint8_t IN865_RADIO_POWERS[21]; //!< List of calibrated tx powers 00262 static const uint8_t IN865_MAX_PAYLOAD_SIZE[]; //!< List of max payload sizes for each datarate 00263 static const uint8_t IN865_MAX_PAYLOAD_SIZE_REPEATER[]; //!< List of repeater compatible max payload sizes for each datarate 00264 00265 typedef struct __attribute__((packed)) { 00266 uint8_t RFU1[1]; 00267 uint8_t Time[4]; 00268 uint8_t CRC1[2]; 00269 uint8_t GwSpecific[7]; 00270 uint8_t RFU2[3]; 00271 uint8_t CRC2[2]; 00272 } BCNPayload; 00273 }; 00274 } 00275 00276 #endif //__CHANNEL_PLAN_IN865_H__
Generated on Fri Jul 15 2022 21:40:31 by
 1.7.2
 1.7.2