Mistake on this page?
Report an issue in GitHub or email us
LoRaMacCommand.h
Go to the documentation of this file.
1 /**
2  * \file LoRaMacCommand.h
3  *
4  * \brief LoRa MAC layer implementation
5  *
6  * \copyright Revised BSD License, see LICENSE.TXT file include in the project
7  *
8  * \code
9  * ______ _
10  * / _____) _ | |
11  * ( (____ _____ ____ _| |_ _____ ____| |__
12  * \____ \| ___ | (_ _) ___ |/ ___) _ \
13  * _____) ) ____| | | || |_| ____( (___| | | |
14  * (______/|_____)_|_|_| \__)_____)\____)_| |_|
15  * (C)2013 Semtech
16  *
17  * ___ _____ _ ___ _ _____ ___ ___ ___ ___
18  * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __|
19  * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _|
20  * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
21  * embedded.connectivity.solutions===============
22  *
23  * \endcode
24  *
25  * \author Miguel Luis ( Semtech )
26  *
27  * \author Gregory Cristian ( Semtech )
28  *
29  * \author Daniel Jaeckle ( STACKFORCE )
30  *
31  * \defgroup LORAMAC LoRa MAC layer implementation
32  * This module specifies the API implementation of the LoRaMAC layer.
33  * This is a placeholder for a detailed description of the LoRaMac
34  * layer and the supported features.
35  *
36  * Copyright (c) 2017, Arm Limited and affiliates.
37  * SPDX-License-Identifier: BSD-3-Clause
38  *
39  */
40 #ifndef __LORAMACCOMMAND_H__
41 #define __LORAMACCOMMAND_H__
42 
43 #include <stdint.h>
45 #include "lorastack/phy/LoRaPHY.h"
46 
47 /*!
48  * Maximum MAC commands buffer size
49  */
50 #define LORA_MAC_COMMAND_MAX_LENGTH 128
51 
52 class LoRaMac;
53 
54 /** LoRaMacCommand Class
55  * Helper class for LoRaMac layer to handle any MAC commands
56  */
58 
59 public:
61 
62  /**
63  * @brief Clear MAC command buffer.
64  */
65  void clear_command_buffer(void);
66 
67  /**
68  * @brief Get the length of MAC commands
69  *
70  * @return status Length of used MAC buffer (bytes)
71  */
72  uint8_t get_mac_cmd_length() const;
73 
74  /**
75  * @brief Get MAC command buffer
76  *
77  * @return Pointer to MAC command buffer
78  */
79  uint8_t *get_mac_commands_buffer();
80 
81  /**
82  * @brief Parses the MAC commands which must be re-sent.
83  */
85 
86  /**
87  * @brief Clear MAC command repeat buffer.
88  */
89  void clear_repeat_buffer();
90 
91  /**
92  * @brief Copy MAC commands from repeat buffer to actual MAC command buffer.
93  */
95 
96  /**
97  * @brief Get the length of MAC commands in repeat buffer
98  *
99  * @return status Length of used MAC Repeat buffer (bytes)
100  */
101  uint8_t get_repeat_commands_length() const;
102 
103  /**
104  * @brief Clear sticky MAC commands.
105  */
106  void clear_sticky_mac_cmd();
107 
108  /**
109  * @brief Check if MAC command buffer contains sticky commands
110  *
111  * @return status True: buffer has sticky MAC commands in it, false: no sticky commands in buffer
112  */
113  bool has_sticky_mac_cmd() const;
114 
115  /**
116  * @brief Decodes MAC commands in the fOpts field and in the payload
117  *
118  * @return status Function status. LORAWAN_STATUS_OK if command successful.
119  */
120  lorawan_status_t process_mac_commands(const uint8_t *payload, uint8_t mac_index,
121  uint8_t commands_size, uint8_t snr,
122  loramac_mlme_confirm_t &mlme_conf,
123  lora_mac_system_params_t &mac_params,
124  LoRaPHY &lora_phy);
125 
126  /**
127  * @brief Adds a new LinkCheckReq MAC command to be sent.
128  *
129  * @return status Function status: LORAWAN_STATUS_OK: OK,
130  * LORAWAN_STATUS_LENGTH_ERROR: Buffer full
131  */
133 
134  /**
135  * @brief Set battery level query callback method
136  * If callback is not set, BAT_LEVEL_NO_MEASURE is returned.
137  */
138  void set_batterylevel_callback(mbed::Callback<uint8_t(void)> battery_level);
139 
140 private:
141  /**
142  * @brief Get the remaining size of the MAC command buffer
143  *
144  * @return Remaining free space in buffer (bytes).
145  */
146  int32_t cmd_buffer_remaining() const;
147 
148  /**
149  * @brief Adds a new LinkAdrAns MAC command to be sent.
150  *
151  * @param [in] status Status bits
152  *
153  * @return status Function status: LORAWAN_STATUS_OK: OK,
154  * LORAWAN_STATUS_LENGTH_ERROR: Buffer full
155  */
156  lorawan_status_t add_link_adr_ans(uint8_t status);
157 
158  /**
159  * @brief Adds a new DutyCycleAns MAC command to be sent.
160  *
161  * @return status Function status: LORAWAN_STATUS_OK: OK,
162  * LORAWAN_STATUS_LENGTH_ERROR: Buffer full
163  */
164  lorawan_status_t add_duty_cycle_ans();
165 
166  /**
167  * @brief Adds a new RXParamSetupAns MAC command to be sent.
168  *
169  * @param [in] status Status bits
170  *
171  * @return status Function status: LORAWAN_STATUS_OK: OK,
172  * LORAWAN_STATUS_LENGTH_ERROR: Buffer full
173  */
174  lorawan_status_t add_rx_param_setup_ans(uint8_t status);
175 
176  /**
177  * @brief Adds a new DevStatusAns MAC command to be sent.
178  *
179  * @param [in] battery Battery level
180  * @param [in] margin Demodulation signal-to-noise ratio (dB)
181  *
182  * @return status Function status: LORAWAN_STATUS_OK: OK,
183  * LORAWAN_STATUS_LENGTH_ERROR: Buffer full
184  */
185  lorawan_status_t add_dev_status_ans(uint8_t battery, uint8_t margin);
186 
187  /**
188  * @brief Adds a new NewChannelAns MAC command to be sent.
189  *
190  * @param [in] status Status bits
191  *
192  * @return status Function status: LORAWAN_STATUS_OK: OK,
193  * LORAWAN_STATUS_LENGTH_ERROR: Buffer full
194  */
195  lorawan_status_t add_new_channel_ans(uint8_t status);
196 
197  /**
198  * @brief Adds a new RXTimingSetupAns MAC command to be sent.
199  *
200  * @return status Function status: LORAWAN_STATUS_OK: OK,
201  * LORAWAN_STATUS_LENGTH_ERROR: Buffer full
202  */
203  lorawan_status_t add_rx_timing_setup_ans();
204 
205  /**
206  * @brief Adds a new TXParamSetupAns MAC command to be sent.
207  *
208  * @return status Function status: LORAWAN_STATUS_OK: OK,
209  * LORAWAN_STATUS_LENGTH_ERROR: Buffer full
210  */
211  lorawan_status_t add_tx_param_setup_ans();
212 
213  /**
214  * @brief Adds a new DlChannelAns MAC command to be sent.
215  *
216  * @param [in] status Status bits
217  *
218  * @return status Function status: LORAWAN_STATUS_OK: OK,
219  * LORAWAN_STATUS_LENGTH_ERROR: Buffer full
220  */
221  lorawan_status_t add_dl_channel_ans(uint8_t status);
222 
223 private:
224  /**
225  * Indicates if there are any pending sticky MAC commands
226  */
227  bool sticky_mac_cmd;
228 
229  /**
230  * Contains the current Mac command buffer index in 'mac_cmd_buffer'
231  */
232  uint8_t mac_cmd_buf_idx;
233 
234  /**
235  * Contains the current Mac command buffer index for MAC commands to repeat in
236  * 'mac_cmd_buffer_to_repeat'
237  */
238  uint8_t mac_cmd_buf_idx_to_repeat;
239 
240  /**
241  * Buffer containing the MAC layer commands
242  */
243  uint8_t mac_cmd_buffer[LORA_MAC_COMMAND_MAX_LENGTH];
244 
245  /**
246  * Buffer containing the MAC layer commands which must be repeated
247  */
248  uint8_t mac_cmd_buffer_to_repeat[LORA_MAC_COMMAND_MAX_LENGTH];
249 
250  mbed::Callback<uint8_t(void)> _battery_level_cb;
251 };
252 
253 #endif //__LORAMACCOMMAND_H__
uint8_t * get_mac_commands_buffer()
Get MAC command buffer.
An abstract class providing radio object to children and provide base for implementing LoRa PHY layer...
LoRaMac Class Implementation of LoRaWAN MAC layer.
Definition: LoRaMac.h:62
void clear_sticky_mac_cmd()
Clear sticky MAC commands.
void clear_repeat_buffer()
Clear MAC command repeat buffer.
void copy_repeat_commands_to_buffer()
Copy MAC commands from repeat buffer to actual MAC command buffer.
lorawan_status_t add_link_check_req()
Adds a new LinkCheckReq MAC command to be sent.
void set_batterylevel_callback(mbed::Callback< uint8_t(void)> battery_level)
Set battery level query callback method If callback is not set, BAT_LEVEL_NO_MEASURE is returned...
LoRaPHY Class Parent class for LoRa regional PHY implementations.
Definition: LoRaPHY.h:46
void clear_command_buffer(void)
Clear MAC command buffer.
enum lorawan_status lorawan_status_t
lorawan_status_t contains status codes in response to stack operations
#define LORA_MAC_COMMAND_MAX_LENGTH
uint8_t get_mac_cmd_length() const
Get the length of MAC commands.
LoRaMacCommand Class Helper class for LoRaMac layer to handle any MAC commands.
lorawan_status_t process_mac_commands(const uint8_t *payload, uint8_t mac_index, uint8_t commands_size, uint8_t snr, loramac_mlme_confirm_t &mlme_conf, lora_mac_system_params_t &mac_params, LoRaPHY &lora_phy)
Decodes MAC commands in the fOpts field and in the payload.
uint8_t get_repeat_commands_length() const
Get the length of MAC commands in repeat buffer.
void parse_mac_commands_to_repeat()
Parses the MAC commands which must be re-sent.
Contains common data structures used by Mbed-OS LoRaWAN mplementation.
bool has_sticky_mac_cmd() const
Check if MAC command buffer contains sticky commands.
Callback class based on template specialization.
Definition: Callback.h:53
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.