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.
Fork of libmDot-mbed5 by
Mote.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::Mote provides a user level class that abstracts the complexity of the Mac layer 00011 * 00012 * @details 00013 * 00014 */ 00015 00016 #ifndef __LORA_MOTE_H__ 00017 #define __LORA_MOTE_H__ 00018 00019 #include "rtos.h" 00020 #include "MacEvents.h" 00021 #include <vector> 00022 00023 class SxRadio; 00024 class SxRadio1272; 00025 00026 namespace lora { 00027 00028 class Mac; 00029 class ChannelPlan; 00030 00031 class MoteEvents: public MacEvents { 00032 00033 /** 00034 * Fired at end of TX 00035 * @param dr datarate used for TX 00036 */ 00037 virtual void TxDone(uint8_t dr); 00038 00039 /** 00040 * Fired if TX timed out 00041 */ 00042 virtual void TxTimeout(void); 00043 00044 /** 00045 * Fired when JoinAccept message is received and MIC is validated 00046 * @param payload received bytes 00047 * @param size number of received bytes 00048 * @param rssi of received packet 00049 * @param snr of received packet 00050 */ 00051 virtual void JoinAccept(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr); 00052 00053 /** 00054 * Fired when JoinAccept message is received and MIC is not valid 00055 * @param payload received bytes 00056 * @param size number of received bytes 00057 * @param rssi of received packet 00058 * @param snr of received packet 00059 */ 00060 virtual void JoinFailed(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr); 00061 00062 /** 00063 * Fired when non duplicate packet is received and MIC is valid 00064 * @param port of packet 00065 * @param payload received bytes 00066 * @param size number of received bytes 00067 * @param rssi of received packet 00068 * @param snr of received packet 00069 * @param ctrl Downlink control field of packet 00070 * @param slot rx window packet was received 00071 * @param retries number of attempts before ack was received 00072 */ 00073 virtual void PacketRx(uint8_t port, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, lora::DownlinkControl ctrl, uint8_t slot, uint8_t retries = 0); 00074 00075 /** 00076 * Fired when radio has received a packet, packet is not validated 00077 * @param payload received bytes 00078 * @param size number of received bytes 00079 * @param rssi of received packet 00080 * @param snr of received packet 00081 * @param ctrl Downlink control field of packet 00082 * @param slot rx window packet was received 00083 */ 00084 virtual void RxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, lora::DownlinkControl ctrl, uint8_t slot); 00085 00086 /** 00087 * Fired if rx window times out 00088 * @param slot rx window that timed out 00089 */ 00090 virtual void RxTimeout(uint8_t slot); 00091 00092 /** 00093 * Fired if rx CRC error 00094 * @param slot rx window that errored 00095 */ 00096 virtual void RxError(uint8_t slot); 00097 00098 /** 00099 * Fired if pong packet is received 00100 * @param m_rssi of received packet at mote 00101 * @param m_snr of received packet at mote 00102 * @param s_rssi of received packet at server 00103 * @param s_snr of received packet at server 00104 */ 00105 virtual void Pong(int16_t m_rssi, int8_t m_snr, int16_t s_rssi, int8_t s_snr); 00106 00107 /** 00108 * Fired if network link check answer is received 00109 * @param m_rssi of received packet at mote 00110 * @param m_snr of received packet at mote 00111 * @param s_snr margin of received packet at server 00112 * @param s_gateways number of gateways reporting the packet 00113 */ 00114 virtual void NetworkLinkCheck(int16_t m_rssi, int8_t m_snr, int8_t s_snr, uint8_t s_gateways); 00115 00116 /** 00117 * Callback to for device to measure the battery level and report to server 00118 * @return battery level 0-255, 0 - external power, 1-254 level min-max, 255 device unable to measure battery 00119 */ 00120 virtual uint8_t MeasureBattery(); 00121 00122 /** 00123 * Fired when ack attempts are exhausted and RxTimeout or RxError occur 00124 * @param retries number of attempts to resend the packet 00125 */ 00126 virtual void MissedAck(uint8_t retries); 00127 }; 00128 00129 class Mote { 00130 public: 00131 Mote(Settings* settings); 00132 virtual ~Mote(); 00133 00134 /** 00135 * Indicator for network session join status 00136 * @return true if joined to network 00137 */ 00138 bool Joined(); 00139 00140 /** 00141 * Send join request 00142 * @return LORA_OK if request was sent 00143 */ 00144 uint8_t Join(); 00145 00146 /** 00147 * Send a packet 00148 * @param port to send packet 00149 * @param payload of packet 00150 * @param size in bytes 00151 * @return LORA_OK if successful 00152 * @return LORA_MAX_PAYLOAD_EXCEEDED if payload size exceeds datarate maximum 00153 * @return LORA_NO_CHANS_ENABLED if there is not an available channel that supports the current datarate 00154 * @return LORA_LINK_BUSY if link was busy 00155 * @return LORA_RADIO_BUSY if radio was busy 00156 * @return LORA_BUFFER_FULL if mac commands filled the packet, client should resend the packet 00157 */ 00158 uint8_t Send(uint8_t port, const uint8_t* payload, uint8_t size); 00159 00160 /** 00161 * Configure the channel plan 00162 * @param freqBand EU868, US915, AU915 00163 * @return LORA_OK 00164 */ 00165 uint8_t SetChannelPlan(uint8_t freqBand); 00166 00167 /** 00168 * Get the channel mask of currently enabled channels 00169 * @return vector containing channel bit masks 00170 */ 00171 std::vector<uint16_t> GetChannelMask(); 00172 00173 /** 00174 * Set a 16 bit channel mask with index 00175 * @param index of mask to set 0:0-15, 1:16-31 ... 00176 * @param mask 16 bit mask of enabled channels 00177 * @return true 00178 */ 00179 virtual uint8_t SetChannelMask(uint8_t index, uint16_t mask); 00180 00181 /** 00182 * Set the current channel group for hybrid operation 1-8 else 0 for 64 channel operation 00183 * @param group 0-8 00184 */ 00185 uint8_t SetChannelGroup(uint8_t group); 00186 00187 /** 00188 * Get the current channel group 00189 * @return group 0-8 00190 */ 00191 uint8_t GetChannelGroup(); 00192 00193 /** 00194 * Add a channel to the channel plan 00195 * EU868 allows additional channels to be added 00196 * Channels 0-2 are fixed default channels 00197 * 00198 * @param index of the channel 00199 * @param frequency of the channel or 0 to remove channel 00200 * @param range of datarates allowed by the channel 00201 * @return LORA_OK if channel was added 00202 */ 00203 uint8_t AddChannel(uint8_t index, uint32_t frequency, lora::DatarateRange range); 00204 00205 /** 00206 * Set network mode 00207 * Choose Public LoRaWAN mode or Private Multitech mode 00208 * 00209 * Public mode uses 0x34 sync word with 5/6 second join windows 00210 * Private mode uses 0x12 sync word with 1/2 second join windows 00211 * US915/AU915 Rx1 and Rx2 are fixed per Channel Group setting 00212 * 00213 * @param mode public or private 00214 * @return LORA_OK 00215 */ 00216 uint8_t SetNetworkMode(uint8_t mode); 00217 00218 /** 00219 * Get a pointer to the mac layer 00220 * @return Mac mac 00221 */ 00222 Mac* GetMac(); 00223 00224 /** 00225 * Get a pointer to the radio 00226 * Can be used to read radio registers or get a random value based on RSSI 00227 * 00228 * @return SxRadio pointer 00229 */ 00230 SxRadio* GetRadio(); 00231 00232 /** 00233 * Get the current statistics for the device 00234 * @return Statistics 00235 */ 00236 Statistics& GetStats(); 00237 00238 /** 00239 * Get time on air with current settings for provided payload bytes 00240 * 13 overhead bytes will be added to payload 00241 * @param bytes of payload data 00242 * @return time-on-air in ms 00243 */ 00244 uint32_t GetTimeOnAir(uint8_t bytes); 00245 00246 /** 00247 * Call before setting device in sleep mode to place radio in sleep 00248 */ 00249 void Sleep(); 00250 00251 protected: 00252 SxRadio1272* _radio; 00253 Settings* _settings; 00254 Mac* _mac; 00255 00256 private: 00257 ChannelPlan* _plan; 00258 MoteEvents _events; 00259 }; 00260 00261 } 00262 #endif
Generated on Sat Jul 16 2022 05:44:25 by
1.7.2
