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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
LoRaMac Class Reference
LoRaMac Class Implementation of LoRaWAN MAC layer. More...
#include <LoRaMac.h>
Public Member Functions | |
LoRaMac () | |
Constructor. | |
~LoRaMac () | |
Destructor. | |
lorawan_status_t | initialize (events::EventQueue *queue, mbed::Callback< void(void)>scheduling_failure_handler) |
LoRaMAC layer initialization. | |
void | disconnect (void) |
Disconnect LoRaMac layer. | |
bool | nwk_joined () |
nwk_joined Checks if device has joined to network | |
lorawan_status_t | add_channel_plan (const lorawan_channelplan_t &plan) |
Adds a channel plan to the system. | |
lorawan_status_t | remove_channel_plan () |
Removes a channel plan from the system. | |
lorawan_status_t | get_channel_plan (lorawan_channelplan_t &plan) |
Access active channel plan. | |
lorawan_status_t | remove_single_channel (uint8_t id) |
Remove a given channel from the active plan. | |
lorawan_status_t | multicast_channel_link (multicast_params_t *channel_param) |
LoRaMAC multicast channel link service. | |
lorawan_status_t | multicast_channel_unlink (multicast_params_t *channel_param) |
LoRaMAC multicast channel unlink service. | |
void | bind_phy (LoRaPHY &phy) |
Binds phy layer to MAC. | |
lorawan_status_t | send (loramac_mhdr_t *mac_hdr, const uint8_t fport, const void *fbuffer, uint16_t fbuffer_size) |
Schedules the frame for sending. | |
uint8_t | get_default_tx_datarate () |
get_default_tx_datarate Gets the default TX datarate | |
void | enable_adaptive_datarate (bool adr_enabled) |
enable_adaptive_datarate Enables or disables adaptive datarate. | |
lorawan_status_t | set_channel_data_rate (uint8_t data_rate) |
Sets up the data rate. | |
bool | tx_ongoing () |
tx_ongoing Check whether a prepare is done or not. | |
void | set_tx_ongoing (bool ongoing) |
set_tx_ongoing Changes the ongoing status for prepared message. | |
void | reset_ongoing_tx (bool reset_pending=false) |
reset_ongoing_tx Resets _ongoing_tx_msg. | |
int16_t | prepare_ongoing_tx (const uint8_t port, const uint8_t *data, uint16_t length, uint8_t flags, uint8_t num_retries) |
prepare_ongoing_tx This will prepare (and override) ongoing_tx_msg. | |
lorawan_status_t | send_ongoing_tx (void) |
send_ongoing_tx Sends the ongoing_tx_msg | |
device_class_t | get_device_class () const |
device_class Returns active device class | |
void | set_device_class (const device_class_t &device_class, mbed::Callback< void(void)>rx2_would_be_closure_handler) |
set_device_class Sets active device class. | |
void | setup_link_check_request () |
setup_link_check_request Adds link check request command to be put on next outgoing message (when it fits) | |
lorawan_status_t | prepare_join (const lorawan_connect_t *params, bool is_otaa) |
prepare_join prepares arguments to be ready for join() call. | |
lorawan_status_t | join (bool is_otaa) |
join Joins the network. | |
void | on_radio_tx_done (lorawan_time_t timestamp) |
MAC operations upon successful transmission. | |
void | on_radio_rx_done (const uint8_t *const payload, uint16_t size, int16_t rssi, int8_t snr) |
MAC operations upon reception. | |
void | on_radio_tx_timeout (void) |
MAC operations upon transmission timeout. | |
void | on_radio_rx_timeout (bool is_timeout) |
MAC operations upon empty reception slots. | |
bool | continue_joining_process (void) |
Handles retransmissions of Join requests if an Accept was not received. | |
bool | continue_sending_process (void) |
Checks if the CONFIRMED data can be sent again or not. | |
const loramac_mcps_confirm_t * | get_mcps_confirmation () const |
Read-only access to MAC primitive blocks. | |
void | post_process_mcps_req (void) |
Post processing steps in response to actions carried out by controller layer and Mac. | |
void | set_batterylevel_callback (mbed::Callback< uint8_t(void)> battery_level) |
Set battery level query callback. | |
int | get_backoff_timer_event_id (void) |
Returns the event ID of backoff timer. | |
lorawan_status_t | clear_tx_pipe (void) |
Clears out the TX pipe by discarding any outgoing message if the backoff timer is still running. | |
lorawan_time_t | get_current_time (void) |
Gets the current time. | |
rx_slot_t | get_current_slot (void) |
Gets the current receive slot. | |
uint8_t | get_QOS_level (void) |
Indicates what level of QOS is set by network server. | |
uint8_t | get_prev_QOS_level (void) |
Indicates level of QOS used for the previous outgoing message. | |
void | lock (void) |
These locks trample through to the upper layers and make the stack thread safe. |
Detailed Description
LoRaMac Class Implementation of LoRaWAN MAC layer.
Definition at line 62 of file LoRaMac.h.
Constructor & Destructor Documentation
LoRaMac | ( | ) |
Constructor.
Definition at line 68 of file LoRaMac.cpp.
~LoRaMac | ( | ) |
Destructor.
Definition at line 97 of file LoRaMac.cpp.
Member Function Documentation
lorawan_status_t add_channel_plan | ( | const lorawan_channelplan_t & | plan ) |
Adds a channel plan to the system.
Adds a whole channel plan or a single new channel if the plan contains only one channel and 'plan.nb_channels' is set to 1. Please note that this functionality is not available in all regions. Information on the allowed ranges is available at the LoRaWAN Regional Parameters V1.0.2rB.
- Parameters:
-
plan [in] A reference to application provided channel plan.
- Returns:
- `lorawan_status_t` The status of the operation. The possible values are: LORAWAN_STATUS_OK LORAWAN_STATUS_BUSY LORAWAN_STATUS_PARAMETER_INVALID
Definition at line 1886 of file LoRaMac.cpp.
void bind_phy | ( | LoRaPHY & | phy ) |
lorawan_status_t clear_tx_pipe | ( | void | ) |
Clears out the TX pipe by discarding any outgoing message if the backoff timer is still running.
Definition at line 1064 of file LoRaMac.cpp.
bool continue_joining_process | ( | void | ) |
Handles retransmissions of Join requests if an Accept was not received.
- Returns:
- true if a retry will be made
Definition at line 789 of file LoRaMac.cpp.
bool continue_sending_process | ( | void | ) |
Checks if the CONFIRMED data can be sent again or not.
Definition at line 803 of file LoRaMac.cpp.
void disconnect | ( | void | ) |
Disconnect LoRaMac layer.
Cancels all outstanding requests and sets LoRaMac's internal state to idle.
Definition at line 1824 of file LoRaMac.cpp.
void enable_adaptive_datarate | ( | bool | adr_enabled ) |
enable_adaptive_datarate Enables or disables adaptive datarate.
- Parameters:
-
adr_enabled Flag indicating is adr enabled or disabled.
Definition at line 1260 of file LoRaMac.cpp.
int get_backoff_timer_event_id | ( | void | ) |
Returns the event ID of backoff timer.
Definition at line 1059 of file LoRaMac.cpp.
lorawan_status_t get_channel_plan | ( | lorawan_channelplan_t & | plan ) |
Access active channel plan.
Provides access to the current active channel plan.
- Parameters:
-
plan [out] A reference to application provided channel plan data structure which will be filled in with active channel plan.
- Returns:
- `lorawan_status_t` The status of the operation. The possible values are: LORAWAN_STATUS_OK LORAWAN_STATUS_BUSY LORAWAN_STATUS_PARAMETER_INVALID
Definition at line 1904 of file LoRaMac.cpp.
rx_slot_t get_current_slot | ( | void | ) |
Gets the current receive slot.
Definition at line 172 of file LoRaMac.cpp.
lorawan_time_t get_current_time | ( | void | ) |
Gets the current time.
Definition at line 167 of file LoRaMac.cpp.
uint8_t get_default_tx_datarate | ( | ) |
get_default_tx_datarate Gets the default TX datarate
- Returns:
- default TX datarate.
Definition at line 1255 of file LoRaMac.cpp.
device_class_t get_device_class | ( | ) | const |
device_class Returns active device class
- Returns:
- Device class in use.
Definition at line 1410 of file LoRaMac.cpp.
const loramac_mcps_confirm_t * get_mcps_confirmation | ( | ) | const |
Read-only access to MAC primitive blocks.
Definition at line 105 of file LoRaMac.cpp.
uint8_t get_prev_QOS_level | ( | void | ) |
Indicates level of QOS used for the previous outgoing message.
Definition at line 1986 of file LoRaMac.cpp.
uint8_t get_QOS_level | ( | void | ) |
Indicates what level of QOS is set by network server.
QOS level is set in response to a LinkADRReq for UNCONFIRMED messages
Definition at line 1977 of file LoRaMac.cpp.
lorawan_status_t initialize | ( | events::EventQueue * | queue, |
mbed::Callback< void(void)> | scheduling_failure_handler | ||
) |
LoRaMAC layer initialization.
Initializes the LoRaMAC layer,
- Parameters:
-
queue [in] A pointer to the application provided EventQueue. scheduling_failure_handler A callback to inform upper layer if a deferred transmission (after backoff or retry) fails to schedule.
- Returns:
- `lorawan_status_t` The status of the operation. The possible values are: LORAWAN_STATUS_OK LORAWAN_STATUS_PARAMETER_INVALID
Definition at line 1774 of file LoRaMac.cpp.
lorawan_status_t join | ( | bool | is_otaa ) |
join Joins the network.
- Parameters:
-
is_otaa True if joining is to be done using OTAA, false for ABP.
- Returns:
- LORAWAN_STATUS_OK or a negative error code on failure.
Definition at line 1528 of file LoRaMac.cpp.
void lock | ( | void | ) |
lorawan_status_t multicast_channel_link | ( | multicast_params_t * | channel_param ) |
LoRaMAC multicast channel link service.
Links a multicast channel into the linked list.
- Parameters:
-
[in] channel_param The multicast channel parameters to link.
- Returns:
- `lorawan_status_t` The status of the operation. The possible values are: LORAWAN_STATUS_OK LORAWAN_STATUS_BUSY LORAWAN_STATUS_PARAMETER_INVALID
Definition at line 1918 of file LoRaMac.cpp.
lorawan_status_t multicast_channel_unlink | ( | multicast_params_t * | channel_param ) |
LoRaMAC multicast channel unlink service.
Unlinks a multicast channel from the linked list.
- Parameters:
-
[in] channel_param The multicast channel parameters to unlink.
- Returns:
- `lorawan_status_t` The status of the operation. The possible values are: LORAWAN_STATUS_OK LORAWAN_STATUS_BUSY LORAWAN_STATUS_PARAMETER_INVALID
Definition at line 1942 of file LoRaMac.cpp.
bool nwk_joined | ( | ) |
nwk_joined Checks if device has joined to network
- Returns:
- True if joined to network, false otherwise
Definition at line 1876 of file LoRaMac.cpp.
void on_radio_rx_done | ( | const uint8_t *const | payload, |
uint16_t | size, | ||
int16_t | rssi, | ||
int8_t | snr | ||
) |
MAC operations upon reception.
Definition at line 674 of file LoRaMac.cpp.
void on_radio_rx_timeout | ( | bool | is_timeout ) |
MAC operations upon empty reception slots.
- Parameters:
-
is_timeout false when radio encountered an error true when the an RX slot went empty
- Returns:
- current RX slot
Definition at line 754 of file LoRaMac.cpp.
void on_radio_tx_done | ( | lorawan_time_t | timestamp ) |
MAC operations upon successful transmission.
Definition at line 619 of file LoRaMac.cpp.
void on_radio_tx_timeout | ( | void | ) |
MAC operations upon transmission timeout.
Definition at line 726 of file LoRaMac.cpp.
void post_process_mcps_req | ( | void | ) |
Post processing steps in response to actions carried out by controller layer and Mac.
Definition at line 130 of file LoRaMac.cpp.
lorawan_status_t prepare_join | ( | const lorawan_connect_t * | params, |
bool | is_otaa | ||
) |
prepare_join prepares arguments to be ready for join() call.
- Parameters:
-
params Join parameters to use, if NULL, the default will be used. is_otaa True if joining is to be done using OTAA, false for ABP.
- Returns:
- LORAWAN_STATUS_OK or a negative error code on failure.
Definition at line 1450 of file LoRaMac.cpp.
int16_t prepare_ongoing_tx | ( | const uint8_t | port, |
const uint8_t * | data, | ||
uint16_t | length, | ||
uint8_t | flags, | ||
uint8_t | num_retries | ||
) |
prepare_ongoing_tx This will prepare (and override) ongoing_tx_msg.
- Parameters:
-
port The application port number. data A pointer to the data being sent. The ownership of the buffer is not transferred. length The size of data in bytes. flags A flag used to determine what type of message is being sent. num_retries Number of retries for a confirmed type message
- Returns:
- The number of bytes prepared for sending.
Definition at line 1302 of file LoRaMac.cpp.
lorawan_status_t remove_channel_plan | ( | ) |
Removes a channel plan from the system.
Removes the whole active channel plan except the 'Default Channels'. Please note that this functionality is not available in all regions. Information on the allowed ranges is available at the LoRaWAN Regional Parameters V1.0.2rB.
- Returns:
- `lorawan_status_t` The status of the operation. The possible values are: LORAWAN_STATUS_OK LORAWAN_STATUS_BUSY LORAWAN_STATUS_PARAMETER_INVALID
Definition at line 1895 of file LoRaMac.cpp.
lorawan_status_t remove_single_channel | ( | uint8_t | id ) |
Remove a given channel from the active plan.
Deactivates the given channel.
- Parameters:
-
id Id of the channel.
- Returns:
- `lorawan_status_t` The status of the operation. The possible values are: LORAWAN_STATUS_OK LORAWAN_STATUS_BUSY LORAWAN_STATUS_PARAMETER_INVALID
Definition at line 1909 of file LoRaMac.cpp.
void reset_ongoing_tx | ( | bool | reset_pending = false ) |
reset_ongoing_tx Resets _ongoing_tx_msg.
- Parameters:
-
reset_pending If true resets pending size also.
Definition at line 1292 of file LoRaMac.cpp.
lorawan_status_t send | ( | loramac_mhdr_t * | mac_hdr, |
const uint8_t | fport, | ||
const void * | fbuffer, | ||
uint16_t | fbuffer_size | ||
) |
Schedules the frame for sending.
Prepares a full MAC frame and schedules it for physical transmission.
- Parameters:
-
[in] mac_hdr MAC frame header field [in] fport Payload port [in] fbuffer MAC frame data buffer to be sent [in] fbuffer_size MAC frame data buffer size
- Returns:
- status Status of the operation. LORAWAN_STATUS_OK in case of success and a negative error code in case of failure.
Definition at line 1030 of file LoRaMac.cpp.
lorawan_status_t send_ongoing_tx | ( | void | ) |
send_ongoing_tx Sends the ongoing_tx_msg
- Returns:
- LORAWAN_STATUS_OK or a negative error code on failure.
Definition at line 1365 of file LoRaMac.cpp.
void set_batterylevel_callback | ( | mbed::Callback< uint8_t(void)> | battery_level ) |
Set battery level query callback.
Definition at line 614 of file LoRaMac.cpp.
lorawan_status_t set_channel_data_rate | ( | uint8_t | data_rate ) |
Sets up the data rate.
`set_datarate()` first verifies whether the data rate given is valid or not. If it is valid, the system sets the given data rate to the channel.
- Parameters:
-
data_rate The intended data rate, for example DR_0 or DR_1. Note that the macro DR_* can mean different things in different regions.
- Returns:
- LORAWAN_STATUS_OK if everything goes well, otherwise a negative error code.
Definition at line 1265 of file LoRaMac.cpp.
void set_device_class | ( | const device_class_t & | device_class, |
mbed::Callback< void(void)> | rx2_would_be_closure_handler | ||
) |
set_device_class Sets active device class.
- Parameters:
-
device_class Device class to use. rx2_would_be_closure_handler callback function to inform about would be closure of RX2 window
Definition at line 1415 of file LoRaMac.cpp.
void set_tx_ongoing | ( | bool | ongoing ) |
set_tx_ongoing Changes the ongoing status for prepared message.
- Parameters:
-
ongoing The value indicating the status.
Definition at line 1286 of file LoRaMac.cpp.
void setup_link_check_request | ( | ) |
setup_link_check_request Adds link check request command to be put on next outgoing message (when it fits)
Definition at line 1441 of file LoRaMac.cpp.
bool tx_ongoing | ( | ) |
tx_ongoing Check whether a prepare is done or not.
- Returns:
- True if prepare_ongoing_tx is called, false otherwise.
Definition at line 1281 of file LoRaMac.cpp.
Generated on Tue Jul 12 2022 13:55:32 by
