LoRaMac Class Implementation of LoRaWAN MAC layer. More...
#include <LoRaMac.h>
Public Member Functions | |
LoRaMac () | |
Constructor. More... | |
~LoRaMac () | |
Destructor. More... | |
lorawan_status_t | initialize (events::EventQueue *queue, mbed::Callback< void(void)>scheduling_failure_handler) |
LoRaMAC layer initialization. More... | |
void | disconnect (void) |
Disconnect LoRaMac layer. More... | |
bool | nwk_joined () |
nwk_joined Checks if device has joined to network More... | |
lorawan_status_t | add_channel_plan (const lorawan_channelplan_t &plan) |
Adds a channel plan to the system. More... | |
lorawan_status_t | remove_channel_plan () |
Removes a channel plan from the system. More... | |
lorawan_status_t | get_channel_plan (lorawan_channelplan_t &plan) |
Access active channel plan. More... | |
lorawan_status_t | remove_single_channel (uint8_t id) |
Remove a given channel from the active plan. More... | |
lorawan_status_t | multicast_channel_link (multicast_params_t *channel_param) |
LoRaMAC multicast channel link service. More... | |
lorawan_status_t | multicast_channel_unlink (multicast_params_t *channel_param) |
LoRaMAC multicast channel unlink service. More... | |
void | bind_phy (LoRaPHY &phy) |
Binds phy layer to MAC. More... | |
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. More... | |
uint8_t | get_default_tx_datarate () |
get_default_tx_datarate Gets the default TX datarate More... | |
void | enable_adaptive_datarate (bool adr_enabled) |
enable_adaptive_datarate Enables or disables adaptive datarate. More... | |
lorawan_status_t | set_channel_data_rate (uint8_t data_rate) |
Sets up the data rate. More... | |
bool | tx_ongoing () |
tx_ongoing Check whether a prepare is done or not. More... | |
void | set_tx_ongoing (bool ongoing) |
set_tx_ongoing Changes the ongoing status for prepared message. More... | |
void | reset_ongoing_tx (bool reset_pending=false) |
reset_ongoing_tx Resets _ongoing_tx_msg. More... | |
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. More... | |
lorawan_status_t | send_ongoing_tx (void) |
send_ongoing_tx Sends the ongoing_tx_msg More... | |
device_class_t | get_device_class () const |
device_class Returns active device class More... | |
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. More... | |
void | setup_link_check_request () |
setup_link_check_request Adds link check request command to be put on next outgoing message (when it fits) More... | |
lorawan_status_t | prepare_join (const lorawan_connect_t *params, bool is_otaa) |
prepare_join prepares arguments to be ready for join() call. More... | |
lorawan_status_t | join (bool is_otaa) |
join Joins the network. More... | |
void | on_radio_tx_done (lorawan_time_t timestamp) |
MAC operations upon successful transmission. More... | |
void | on_radio_rx_done (const uint8_t *const payload, uint16_t size, int16_t rssi, int8_t snr) |
MAC operations upon reception. More... | |
void | on_radio_tx_timeout (void) |
MAC operations upon transmission timeout. More... | |
void | on_radio_rx_timeout (bool is_timeout) |
MAC operations upon empty reception slots. More... | |
bool | continue_joining_process (void) |
Handles retransmissions of Join requests if an Accept was not received. More... | |
bool | continue_sending_process (void) |
Checks if the CONFIRMED data can be sent again or not. More... | |
const loramac_mcps_confirm_t * | get_mcps_confirmation () const |
Read-only access to MAC primitive blocks. More... | |
void | post_process_mcps_req (void) |
Post processing steps in response to actions carried out by controller layer and Mac. More... | |
void | set_batterylevel_callback (mbed::Callback< uint8_t(void)> battery_level) |
Set battery level query callback. More... | |
int | get_backoff_timer_event_id (void) |
Returns the event ID of backoff timer. More... | |
lorawan_status_t | clear_tx_pipe (void) |
Clears out the TX pipe by discarding any outgoing message if the backoff timer is still running. More... | |
lorawan_time_t | get_current_time (void) |
Gets the current time. More... | |
rx_slot_t | get_current_slot (void) |
Gets the current receive slot. More... | |
uint8_t | get_QOS_level (void) |
Indicates what level of QOS is set by network server. More... | |
uint8_t | get_prev_QOS_level (void) |
Indicates level of QOS used for the previous outgoing message. More... | |
void | lock (void) |
These locks trample through to the upper layers and make the stack thread safe. More... | |
LoRaMac | ( | ) |
Constructor.
~LoRaMac | ( | ) |
Destructor.
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.
plan | [in] A reference to application provided channel plan. |
lorawan_status_t
The status of the operation. The possible values are: LORAWAN_STATUS_OK LORAWAN_STATUS_BUSY LORAWAN_STATUS_PARAMETER_INVALID lorawan_status_t clear_tx_pipe | ( | void | ) |
Clears out the TX pipe by discarding any outgoing message if the backoff timer is still running.
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.
void disconnect | ( | void | ) |
void enable_adaptive_datarate | ( | bool | adr_enabled | ) |
enable_adaptive_datarate Enables or disables adaptive datarate.
adr_enabled | Flag indicating is adr enabled or disabled. |
int get_backoff_timer_event_id | ( | void | ) |
Returns the event ID of backoff timer.
lorawan_status_t get_channel_plan | ( | lorawan_channelplan_t & | plan | ) |
Access active channel plan.
Provides access to the current active channel plan.
plan | [out] A reference to application provided channel plan data structure which will be filled in with active channel plan. |
lorawan_status_t
The status of the operation. The possible values are: LORAWAN_STATUS_OK LORAWAN_STATUS_BUSY LORAWAN_STATUS_PARAMETER_INVALID rx_slot_t get_current_slot | ( | void | ) |
Gets the current receive slot.
lorawan_time_t get_current_time | ( | void | ) |
Gets the current time.
uint8_t get_default_tx_datarate | ( | ) |
get_default_tx_datarate Gets the default TX datarate
device_class_t get_device_class | ( | ) | const |
device_class Returns active device class
const loramac_mcps_confirm_t* get_mcps_confirmation | ( | ) | const |
Read-only access to MAC primitive blocks.
uint8_t get_prev_QOS_level | ( | void | ) |
Indicates level of QOS used for the previous outgoing message.
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
lorawan_status_t initialize | ( | events::EventQueue * | queue, |
mbed::Callback< void(void)> | scheduling_failure_handler | ||
) |
LoRaMAC layer initialization.
Initializes the LoRaMAC layer,
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. |
lorawan_status_t
The status of the operation. The possible values are: LORAWAN_STATUS_OK LORAWAN_STATUS_PARAMETER_INVALID lorawan_status_t join | ( | bool | is_otaa | ) |
join Joins the network.
is_otaa | True if joining is to be done using OTAA, false for ABP. |
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.
[in] | channel_param | The multicast channel parameters to link. |
lorawan_status_t
The status of the operation. The possible values are: LORAWAN_STATUS_OK LORAWAN_STATUS_BUSY LORAWAN_STATUS_PARAMETER_INVALID lorawan_status_t multicast_channel_unlink | ( | multicast_params_t * | channel_param | ) |
LoRaMAC multicast channel unlink service.
Unlinks a multicast channel from the linked list.
[in] | channel_param | The multicast channel parameters to unlink. |
lorawan_status_t
The status of the operation. The possible values are: LORAWAN_STATUS_OK LORAWAN_STATUS_BUSY LORAWAN_STATUS_PARAMETER_INVALID bool nwk_joined | ( | ) |
nwk_joined Checks if device has joined to network
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_rx_timeout | ( | bool | is_timeout | ) |
MAC operations upon empty reception slots.
is_timeout | false when radio encountered an error true when the an RX slot went empty |
void on_radio_tx_done | ( | lorawan_time_t | timestamp | ) |
MAC operations upon successful transmission.
void on_radio_tx_timeout | ( | void | ) |
MAC operations upon transmission timeout.
void post_process_mcps_req | ( | void | ) |
Post processing steps in response to actions carried out by controller layer and Mac.
lorawan_status_t prepare_join | ( | const lorawan_connect_t * | params, |
bool | is_otaa | ||
) |
prepare_join prepares arguments to be ready for join() call.
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. |
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.
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 |
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.
lorawan_status_t
The status of the operation. The possible values are: LORAWAN_STATUS_OK LORAWAN_STATUS_BUSY LORAWAN_STATUS_PARAMETER_INVALID lorawan_status_t remove_single_channel | ( | uint8_t | id | ) |
Remove a given channel from the active plan.
Deactivates the given channel.
id | Id of the channel. |
lorawan_status_t
The status of the operation. The possible values are: LORAWAN_STATUS_OK LORAWAN_STATUS_BUSY LORAWAN_STATUS_PARAMETER_INVALID void reset_ongoing_tx | ( | bool | reset_pending = false | ) |
reset_ongoing_tx Resets _ongoing_tx_msg.
reset_pending | If true resets pending size also. |
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.
[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 |
lorawan_status_t send_ongoing_tx | ( | void | ) |
send_ongoing_tx Sends the ongoing_tx_msg
void set_batterylevel_callback | ( | mbed::Callback< uint8_t(void)> | battery_level | ) |
Set battery level query callback.
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.
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. |
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.
device_class | Device class to use. |
rx2_would_be_closure_handler | callback function to inform about would be closure of RX2 window |
void set_tx_ongoing | ( | bool | ongoing | ) |
set_tx_ongoing Changes the ongoing status for prepared message.
ongoing | The value indicating the status. |
void setup_link_check_request | ( | ) |
setup_link_check_request Adds link check request command to be put on next outgoing message (when it fits)
bool tx_ongoing | ( | ) |
tx_ongoing Check whether a prepare is done or not.