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.
LoRaMacCommand.h
00001 /** 00002 * \file LoRaMacCommand.h 00003 * 00004 * \brief LoRa MAC layer implementation 00005 * 00006 * \copyright Revised BSD License, see LICENSE.TXT file include in the project 00007 * 00008 * \code 00009 * ______ _ 00010 * / _____) _ | | 00011 * ( (____ _____ ____ _| |_ _____ ____| |__ 00012 * \____ \| ___ | (_ _) ___ |/ ___) _ \ 00013 * _____) ) ____| | | || |_| ____( (___| | | | 00014 * (______/|_____)_|_|_| \__)_____)\____)_| |_| 00015 * (C)2013 Semtech 00016 * 00017 * ___ _____ _ ___ _ _____ ___ ___ ___ ___ 00018 * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| 00019 * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| 00020 * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| 00021 * embedded.connectivity.solutions=============== 00022 * 00023 * \endcode 00024 * 00025 * \author Miguel Luis ( Semtech ) 00026 * 00027 * \author Gregory Cristian ( Semtech ) 00028 * 00029 * \author Daniel Jaeckle ( STACKFORCE ) 00030 * 00031 * \defgroup LORAMAC LoRa MAC layer implementation 00032 * This module specifies the API implementation of the LoRaMAC layer. 00033 * This is a placeholder for a detailed description of the LoRaMac 00034 * layer and the supported features. 00035 * 00036 * Copyright (c) 2017, Arm Limited and affiliates. 00037 * SPDX-License-Identifier: BSD-3-Clause 00038 * 00039 */ 00040 #ifndef __LORAMACCOMMAND_H__ 00041 #define __LORAMACCOMMAND_H__ 00042 00043 #include <stdint.h> 00044 #include "system/lorawan_data_structures.h" 00045 #include "lorastack/phy/LoRaPHY.h" 00046 00047 /*! 00048 * Maximum MAC commands buffer size 00049 */ 00050 #define LORA_MAC_COMMAND_MAX_LENGTH 128 00051 00052 class LoRaMac; 00053 00054 class LoRaMacCommand { 00055 00056 public: 00057 LoRaMacCommand(); 00058 00059 /** 00060 * @brief Clear MAC command buffer. 00061 */ 00062 void clear_command_buffer(void); 00063 00064 /** 00065 * @brief Get the length of MAC commands 00066 * 00067 * @return status Length of used MAC buffer (bytes) 00068 */ 00069 uint8_t get_mac_cmd_length() const; 00070 00071 /** 00072 * @brief Get MAC command buffer 00073 * 00074 * @return Pointer to MAC command buffer 00075 */ 00076 uint8_t *get_mac_commands_buffer(); 00077 00078 /** 00079 * @brief Parses the MAC commands which must be re-sent. 00080 */ 00081 void parse_mac_commands_to_repeat(); 00082 00083 /** 00084 * @brief Clear MAC command repeat buffer. 00085 */ 00086 void clear_repeat_buffer(); 00087 00088 /** 00089 * @brief Copy MAC commands from repeat buffer to actual MAC command buffer. 00090 */ 00091 void copy_repeat_commands_to_buffer(); 00092 00093 /** 00094 * @brief Get the length of MAC commands in repeat buffer 00095 * 00096 * @return status Length of used MAC Repeat buffer (bytes) 00097 */ 00098 uint8_t get_repeat_commands_length() const; 00099 00100 /** 00101 * @brief Clear sticky MAC commands. 00102 */ 00103 void clear_sticky_mac_cmd(); 00104 00105 /** 00106 * @brief Check if MAC command buffer contains sticky commands 00107 * 00108 * @return status True: buffer has sticky MAC commands in it, false: no sticky commands in buffer 00109 */ 00110 bool has_sticky_mac_cmd() const; 00111 00112 /** 00113 * @brief Decodes MAC commands in the fOpts field and in the payload 00114 * 00115 * @return status Function status. LORAWAN_STATUS_OK if command successful. 00116 */ 00117 lorawan_status_t process_mac_commands(const uint8_t *payload, uint8_t mac_index, 00118 uint8_t commands_size, uint8_t snr, 00119 loramac_mlme_confirm_t & mlme_conf, 00120 lora_mac_system_params_t & mac_params, 00121 LoRaPHY& lora_phy); 00122 00123 /** 00124 * @brief Adds a new LinkCheckReq MAC command to be sent. 00125 * 00126 * @return status Function status: LORAWAN_STATUS_OK: OK, 00127 * LORAWAN_STATUS_LENGTH_ERROR: Buffer full 00128 */ 00129 lorawan_status_t add_link_check_req(); 00130 00131 /** 00132 * @brief Set battery level query callback method 00133 * If callback is not set, BAT_LEVEL_NO_MEASURE is returned. 00134 */ 00135 void set_batterylevel_callback(mbed::Callback<uint8_t(void)> battery_level); 00136 00137 private: 00138 /** 00139 * @brief Get the remaining size of the MAC command buffer 00140 * 00141 * @return Remaining free space in buffer (bytes). 00142 */ 00143 int32_t cmd_buffer_remaining() const; 00144 00145 /** 00146 * @brief Adds a new LinkAdrAns MAC command to be sent. 00147 * 00148 * @param [in] status Status bits 00149 * 00150 * @return status Function status: LORAWAN_STATUS_OK: OK, 00151 * LORAWAN_STATUS_LENGTH_ERROR: Buffer full 00152 */ 00153 lorawan_status_t add_link_adr_ans(uint8_t status); 00154 00155 /** 00156 * @brief Adds a new DutyCycleAns MAC command to be sent. 00157 * 00158 * @return status Function status: LORAWAN_STATUS_OK: OK, 00159 * LORAWAN_STATUS_LENGTH_ERROR: Buffer full 00160 */ 00161 lorawan_status_t add_duty_cycle_ans(); 00162 00163 /** 00164 * @brief Adds a new RXParamSetupAns MAC command to be sent. 00165 * 00166 * @param [in] status Status bits 00167 * 00168 * @return status Function status: LORAWAN_STATUS_OK: OK, 00169 * LORAWAN_STATUS_LENGTH_ERROR: Buffer full 00170 */ 00171 lorawan_status_t add_rx_param_setup_ans(uint8_t status); 00172 00173 /** 00174 * @brief Adds a new DevStatusAns MAC command to be sent. 00175 * 00176 * @param [in] battery Battery level 00177 * @param [in] margin Demodulation signal-to-noise ratio (dB) 00178 * 00179 * @return status Function status: LORAWAN_STATUS_OK: OK, 00180 * LORAWAN_STATUS_LENGTH_ERROR: Buffer full 00181 */ 00182 lorawan_status_t add_dev_status_ans(uint8_t battery, uint8_t margin); 00183 00184 /** 00185 * @brief Adds a new NewChannelAns MAC command to be sent. 00186 * 00187 * @param [in] status Status bits 00188 * 00189 * @return status Function status: LORAWAN_STATUS_OK: OK, 00190 * LORAWAN_STATUS_LENGTH_ERROR: Buffer full 00191 */ 00192 lorawan_status_t add_new_channel_ans(uint8_t status); 00193 00194 /** 00195 * @brief Adds a new RXTimingSetupAns MAC command to be sent. 00196 * 00197 * @return status Function status: LORAWAN_STATUS_OK: OK, 00198 * LORAWAN_STATUS_LENGTH_ERROR: Buffer full 00199 */ 00200 lorawan_status_t add_rx_timing_setup_ans(); 00201 00202 /** 00203 * @brief Adds a new TXParamSetupAns MAC command to be sent. 00204 * 00205 * @return status Function status: LORAWAN_STATUS_OK: OK, 00206 * LORAWAN_STATUS_LENGTH_ERROR: Buffer full 00207 */ 00208 lorawan_status_t add_tx_param_setup_ans(); 00209 00210 /** 00211 * @brief Adds a new DlChannelAns MAC command to be sent. 00212 * 00213 * @param [in] status Status bits 00214 * 00215 * @return status Function status: LORAWAN_STATUS_OK: OK, 00216 * LORAWAN_STATUS_LENGTH_ERROR: Buffer full 00217 */ 00218 lorawan_status_t add_dl_channel_ans(uint8_t status); 00219 00220 private: 00221 /** 00222 * Indicates if there are any pending sticky MAC commands 00223 */ 00224 bool sticky_mac_cmd; 00225 00226 /** 00227 * Contains the current Mac command buffer index in 'mac_cmd_buffer' 00228 */ 00229 uint8_t mac_cmd_buf_idx; 00230 00231 /** 00232 * Contains the current Mac command buffer index for MAC commands to repeat in 00233 * 'mac_cmd_buffer_to_repeat' 00234 */ 00235 uint8_t mac_cmd_buf_idx_to_repeat; 00236 00237 /** 00238 * Buffer containing the MAC layer commands 00239 */ 00240 uint8_t mac_cmd_buffer[LORA_MAC_COMMAND_MAX_LENGTH]; 00241 00242 /** 00243 * Buffer containing the MAC layer commands which must be repeated 00244 */ 00245 uint8_t mac_cmd_buffer_to_repeat[LORA_MAC_COMMAND_MAX_LENGTH]; 00246 00247 mbed::Callback<uint8_t(void)> _battery_level_cb; 00248 }; 00249 00250 #endif //__LORAMACCOMMAND_H__
Generated on Tue Aug 9 2022 00:37:09 by
 1.7.2
 1.7.2