The Modified Dot Library for SX1272
Embed:
(wiki syntax)
Show/hide line numbers
ChannelPlan_RU864.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_RU864_H__ 00017 #define __CHANNEL_PLAN_RU864_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 RU864_125K_NUM_CHANS = 16; //!< Number of 125k channels in RU864 channel plan 00027 const uint8_t RU864_DEFAULT_NUM_CHANS = 2; //!< Number of defualt channels in RU864 channel plan 00028 const uint32_t RU864_125K_FREQ_BASE = 868900000; //!< Frequency base for 125k RU864 uplink channels 00029 const uint32_t RU864_125K_FREQ_STEP = 200000; //!< Frequency step for 125k RU864 uplink channels 00030 const uint32_t RU864_RX2_FREQ = 869100000; //!< Frequency default for second rx window in RU864 00031 00032 const uint8_t RU864_TX_POWER_MAX = 16; //!< Max power for RU864 channel plan 00033 00034 // 0.1% duty cycle 864-866 00035 const uint32_t RU864_MILLI_FREQ_MIN = 864000000; 00036 const uint32_t RU864_MILLI_FREQ_MAX = 865000000; 00037 00038 00039 const uint32_t RU864_FREQ_MIN = 864000000; 00040 const uint32_t RU864_FREQ_MAX = 870000000; 00041 00042 const uint8_t RU864_MIN_DATARATE = (uint8_t) DR_0; //!< Minimum transmit datarate for RU864 00043 const uint8_t RU864_MAX_DATARATE = (uint8_t) DR_7; //!< Maximum transmit datarate for RU864 00044 00045 const uint8_t RU864_MIN_DATARATE_OFFSET = (uint8_t) 0; //!< Minimum transmit datarate for US915 00046 const uint8_t RU864_MAX_DATARATE_OFFSET = (uint8_t) 5; //!< Maximum transmit datarate for US915 00047 00048 const uint8_t RU864_BEACON_DR = DR_3; //!< Default beacon datarate 00049 const uint32_t RU864_BEACON_FREQ = 869100000U; //!< Default beacon broadcast frequency 00050 const uint32_t RU864_PING_SLOT_FREQ = 868900000U; //!< Default ping slot frequency 00051 00052 class ChannelPlan_RU864 : public lora::ChannelPlan { 00053 public: 00054 /** 00055 * ChannelPlan constructor 00056 * @param radio SxRadio object used to set Tx/Rx config 00057 * @param settings Settings object 00058 */ 00059 ChannelPlan_RU864(); 00060 ChannelPlan_RU864(Settings* settings); 00061 ChannelPlan_RU864(SxRadio* radio, Settings* settings); 00062 00063 /** 00064 * ChannelPlan destructor 00065 */ 00066 virtual ~ChannelPlan_RU864(); 00067 00068 /** 00069 * Initialize channels, datarates and duty cycle bands according to current channel plan in settings 00070 */ 00071 virtual void Init(); 00072 00073 /** 00074 * Get the next channel to use to transmit 00075 * @return LORA_OK if channel was found 00076 * @return LORA_NO_CHANS_ENABLED 00077 */ 00078 virtual uint8_t GetNextChannel(); 00079 00080 /** 00081 * Add a channel to the ChannelPlan 00082 * @param index of channel, use -1 to add to end 00083 * @param channel settings to add 00084 */ 00085 virtual uint8_t AddChannel(int8_t index, Channel channel); 00086 00087 /** 00088 * Get channel at index 00089 * @return Channel 00090 */ 00091 virtual Channel GetChannel(int8_t index); 00092 00093 /** 00094 * Get rx window settings for requested window 00095 * RX_1, RX_2, RX_BEACON, RX_SLOT 00096 * @param window 00097 * @return RxWindow 00098 */ 00099 virtual RxWindow GetRxWindow(uint8_t window); 00100 00101 /** 00102 * Get datarate to use on the join request 00103 * @return datarate index 00104 */ 00105 virtual uint8_t GetJoinDatarate(); 00106 00107 /** 00108 * Calculate the next time a join request is possible 00109 * @param size of join frame 00110 * @returns LORA_OK 00111 */ 00112 virtual uint8_t CalculateJoinBackoff(uint8_t size); 00113 00114 /** 00115 * Get next channel and set the SxRadio tx config with current settings 00116 * @return LORA_OK 00117 */ 00118 virtual uint8_t SetTxConfig(); 00119 00120 /** 00121 * Set the SxRadio rx config provided window 00122 * @param window to be opened 00123 * @param continuous keep window open 00124 * @param wnd_growth factor to increase the rx window by 00125 * @param pad_ms time in milliseconds to add to computed window size 00126 * @return LORA_OK 00127 */ 00128 virtual uint8_t SetRxConfig(uint8_t window, 00129 bool continuous, 00130 uint16_t wnd_growth, 00131 uint16_t pad_ms); 00132 00133 /** 00134 * Set frequency sub band if supported by plan 00135 * @param sub_band 00136 * @return LORA_OK 00137 */ 00138 virtual uint8_t SetFrequencySubBand(uint8_t sub_band); 00139 00140 /** 00141 * Callback for ACK timeout event 00142 * @return LORA_OK 00143 */ 00144 virtual uint8_t HandleAckTimeout(); 00145 00146 /** 00147 * Callback for Join Accept packet to load optional channels 00148 * @return LORA_OK 00149 */ 00150 virtual uint8_t HandleJoinAccept(const uint8_t* buffer, uint8_t size); 00151 00152 /** 00153 * Callback to for rx parameter setup ServerCommand 00154 * @param payload packet data 00155 * @param index of start of command buffer 00156 * @param size number of bytes in command buffer 00157 * @param[out] status to be returned in MoteCommand answer 00158 * @return LORA_OK 00159 */ 00160 virtual uint8_t HandleRxParamSetup(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status); 00161 00162 /** 00163 * Callback to for new channel ServerCommand 00164 * @param payload packet data 00165 * @param index of start of command buffer 00166 * @param size number of bytes in command buffer 00167 * @param[out] status to be returned in MoteCommand answer 00168 * @return LORA_OK 00169 */ 00170 virtual uint8_t HandleNewChannel(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status); 00171 00172 /** 00173 * Callback to for ping slot channel request ServerCommand 00174 * @param payload packet data 00175 * @param index of start of command buffer 00176 * @param size number of bytes in command buffer 00177 * @param[out] status to be returned in MoteCommand answer 00178 * @return LORA_OK 00179 */ 00180 virtual uint8_t HandlePingSlotChannelReq(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status); 00181 00182 /** 00183 * Callback to for beacon frequency request ServerCommand 00184 * @param payload packet data 00185 * @param index of start of command buffer 00186 * @param size number of bytes in command buffer 00187 * @param[out] status to be returned in MoteCommand answer 00188 * @return LORA_OK 00189 */ 00190 virtual uint8_t HandleBeaconFrequencyReq(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status); 00191 00192 /** 00193 * Callback to for adaptive datarate ServerCommand 00194 * @param payload packet data 00195 * @param index of start of command buffer 00196 * @param size number of bytes in command buffer 00197 * @param[out] status to be returned in MoteCommand answer 00198 * @return LORA_OK 00199 */ 00200 virtual uint8_t HandleAdrCommand(const uint8_t* payload, uint8_t index, uint8_t size, uint8_t& status); 00201 00202 /** 00203 * Validate the configuration after multiple ADR commands have been applied 00204 * @return status to be returned in MoteCommand answer 00205 */ 00206 virtual uint8_t ValidateAdrConfiguration(); 00207 00208 /** 00209 * Update duty cycle with at given frequency and time on air 00210 * @param freq frequency 00211 * @param time_on_air_ms tx time on air 00212 */ 00213 virtual void UpdateDutyCycle(uint32_t freq, uint32_t time_on_air_ms); 00214 00215 /** 00216 * Get the time the radio must be off air to comply with regulations 00217 * Time to wait may be dependent on duty-cycle restrictions per channel 00218 * Or duty-cycle of join requests if OTAA is being attempted 00219 * @return ms of time to wait for next tx opportunity 00220 */ 00221 virtual uint32_t GetTimeOffAir(); 00222 00223 /** 00224 * Get the channels in use by current channel plan 00225 * @return channel frequencies 00226 */ 00227 virtual std::vector<uint32_t> GetChannels(); 00228 00229 /** 00230 * Get the channel datarate ranges in use by current channel plan 00231 * @return channel datarate ranges 00232 */ 00233 virtual std::vector<uint8_t> GetChannelRanges(); 00234 00235 /** 00236 * Print log message for given rx window 00237 * @param wnd 1 or 2 00238 */ 00239 virtual void LogRxWindow(uint8_t wnd); 00240 00241 /** 00242 * Enable the default channels of the channel plan 00243 */ 00244 virtual void EnableDefaultChannels(); 00245 00246 /** 00247 * Check if this packet is a beacon and if so extract parameters needed 00248 * @param payload of potential beacon 00249 * @param size of the packet 00250 * @param [out] data extracted from the beacon if this packet was indeed a beacon 00251 * @return true if this packet is beacon, false if not 00252 */ 00253 virtual bool DecodeBeacon(const uint8_t* payload, 00254 size_t size, 00255 BeaconData_t& data); 00256 00257 protected: 00258 00259 static const uint8_t RU864_TX_POWERS[8]; //!< List of available tx powers 00260 static const uint8_t RU864_RADIO_POWERS[21]; //!< List of calibrated tx powers 00261 static const uint8_t RU864_MAX_PAYLOAD_SIZE[]; //!< List of max payload sizes for each datarate 00262 static const uint8_t RU864_MAX_PAYLOAD_SIZE_REPEATER[]; //!< List of repeater compatible max payload sizes for each datarate 00263 00264 typedef struct __attribute__((packed)) { 00265 uint8_t RFU[2]; 00266 uint8_t Time[4]; 00267 uint8_t CRC1[2]; 00268 uint8_t GwSpecific[7]; 00269 uint8_t CRC2[2]; 00270 } BCNPayload; 00271 }; 00272 } 00273 00274 #endif //__CHANNEL_PLAN_RU864_H__
Generated on Wed Jul 13 2022 16:42:53 by 1.7.2