Nicolas Borla / Mbed OS BBR_1Ebene
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LoRaMacCommand.h Source File

LoRaMacCommand.h

Go to the documentation of this file.
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 resent.
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 MAC commands in next TX.
00102      */
00103     void clear_mac_commands_in_next_tx();
00104 
00105     /**
00106      * @brief Check if MAC command buffer has commands to be sent in next TX
00107      *
00108      * @return status  True: buffer has MAC commands to be sent, false: no commands in buffer
00109      */
00110     bool is_mac_command_in_next_tx() const;
00111 
00112     /**
00113      * @brief Clear sticky MAC commands.
00114      */
00115     void clear_sticky_mac_cmd();
00116 
00117     /**
00118      * @brief Check if MAC command buffer contains sticky commands
00119      *
00120      * @return status  True: buffer has sticky MAC commands in it, false: no sticky commands in buffer
00121      */
00122     bool has_sticky_mac_cmd() const;
00123 
00124     /**
00125      * @brief Decodes MAC commands in the fOpts field and in the payload
00126      *
00127      * @return status  Function status. LORAWAN_STATUS_OK if command successful.
00128      */
00129     lorawan_status_t process_mac_commands(const uint8_t *payload, uint8_t mac_index,
00130                                           uint8_t commands_size, uint8_t snr,
00131                                           loramac_mlme_confirm_t & mlme_conf,
00132                                           lora_mac_system_params_t & mac_params,
00133                                           LoRaPHY& lora_phy);
00134 
00135     /**
00136      * @brief Verifies if sticky MAC commands are pending.
00137      *
00138      * @return [true: sticky MAC commands pending, false: No MAC commands pending]
00139      */
00140     bool is_sticky_mac_command_pending();
00141 
00142     /**
00143      * @brief Adds a new LinkCheckReq MAC command to be sent.
00144      *
00145      * @return status  Function status: LORAWAN_STATUS_OK: OK,
00146      *                                  LORAWAN_STATUS_LENGTH_ERROR: Buffer full
00147      */
00148     lorawan_status_t add_link_check_req();
00149 
00150 private:
00151     /**
00152      * @brief Get the remaining size of the MAC command buffer
00153      *
00154      * @return      Remaining free space in buffer (bytes).
00155      */
00156     int32_t cmd_buffer_remaining() const;
00157 
00158     /**
00159      * @brief Adds a new LinkAdrAns MAC command to be sent.
00160      *
00161      * @param [in] status Status bits
00162      *
00163      * @return status  Function status: LORAWAN_STATUS_OK: OK,
00164      *                                  LORAWAN_STATUS_LENGTH_ERROR: Buffer full
00165      */
00166     lorawan_status_t add_link_adr_ans(uint8_t status);
00167 
00168     /**
00169      * @brief Adds a new DutyCycleAns MAC command to be sent.
00170      *
00171      * @return status  Function status: LORAWAN_STATUS_OK: OK,
00172      *                                  LORAWAN_STATUS_LENGTH_ERROR: Buffer full
00173      */
00174     lorawan_status_t add_duty_cycle_ans();
00175 
00176     /**
00177      * @brief Adds a new RXParamSetupAns MAC command to be sent.
00178      *
00179      * @param [in] status Status bits
00180      *
00181      * @return status  Function status: LORAWAN_STATUS_OK: OK,
00182      *                                  LORAWAN_STATUS_LENGTH_ERROR: Buffer full
00183      */
00184     lorawan_status_t add_rx_param_setup_ans(uint8_t status);
00185 
00186     /**
00187      * @brief Adds a new DevStatusAns MAC command to be sent.
00188      *
00189      * @param [in] battery  Battery level
00190      * @param [in] margin   Demodulation signal-to-noise ratio (dB)
00191      *
00192      * @return status  Function status: LORAWAN_STATUS_OK: OK,
00193      *                                  LORAWAN_STATUS_LENGTH_ERROR: Buffer full
00194      */
00195     lorawan_status_t add_dev_status_ans(uint8_t battery, uint8_t margin);
00196 
00197     /**
00198      * @brief Adds a new NewChannelAns MAC command to be sent.
00199      *
00200      * @param [in] status Status bits
00201      *
00202      * @return status  Function status: LORAWAN_STATUS_OK: OK,
00203      *                                  LORAWAN_STATUS_LENGTH_ERROR: Buffer full
00204      */
00205     lorawan_status_t add_new_channel_ans(uint8_t status);
00206 
00207     /**
00208      * @brief Adds a new RXTimingSetupAns MAC command to be sent.
00209      *
00210      * @return status  Function status: LORAWAN_STATUS_OK: OK,
00211      *                                  LORAWAN_STATUS_LENGTH_ERROR: Buffer full
00212      */
00213     lorawan_status_t add_rx_timing_setup_ans();
00214 
00215     /**
00216      * @brief Adds a new TXParamSetupAns MAC command to be sent.
00217      *
00218      * @return status  Function status: LORAWAN_STATUS_OK: OK,
00219      *                                  LORAWAN_STATUS_LENGTH_ERROR: Buffer full
00220      */
00221     lorawan_status_t add_tx_param_setup_ans();
00222 
00223     /**
00224      * @brief Adds a new DlChannelAns MAC command to be sent.
00225      *
00226      * @param [in] status Status bits
00227      *
00228      * @return status  Function status: LORAWAN_STATUS_OK: OK,
00229      *                                  LORAWAN_STATUS_LENGTH_ERROR: Buffer full
00230      */
00231     lorawan_status_t add_dl_channel_ans(uint8_t status);
00232 
00233 private:
00234     /**
00235      * Indicates if the MAC layer wants to send MAC commands
00236      */
00237     bool mac_cmd_in_next_tx;
00238 
00239     /**
00240       * Indicates if there are any pending sticky MAC commands
00241       */
00242     bool sticky_mac_cmd;
00243 
00244     /**
00245      * Contains the current Mac command buffer index in 'mac_cmd_buffer'
00246      */
00247     uint8_t mac_cmd_buf_idx;
00248 
00249     /**
00250      * Contains the current Mac command buffer index for MAC commands to repeat in
00251      * 'mac_cmd_buffer_to_repeat'
00252      */
00253     uint8_t mac_cmd_buf_idx_to_repeat;
00254 
00255     /**
00256      * Buffer containing the MAC layer commands
00257      */
00258     uint8_t mac_cmd_buffer[LORA_MAC_COMMAND_MAX_LENGTH];
00259 
00260     /**
00261      * Buffer containing the MAC layer commands which must be repeated
00262      */
00263     uint8_t mac_cmd_buffer_to_repeat[LORA_MAC_COMMAND_MAX_LENGTH];
00264 };
00265 
00266 #endif //__LORAMACCOMMAND_H__