mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #6938 from hasnainvirk/style_and_bug_fixes
LoRaWAN: Style and bug fixespull/7151/head
commit
b00a91d15b
|
|
@ -217,7 +217,7 @@ public:
|
||||||
* LORAWAN_STATUS_WOULD_BLOCK if another TX is
|
* LORAWAN_STATUS_WOULD_BLOCK if another TX is
|
||||||
* ongoing, or a negative error code on failure.
|
* ongoing, or a negative error code on failure.
|
||||||
*/
|
*/
|
||||||
virtual int16_t send(uint8_t port, const uint8_t* data,
|
virtual int16_t send(uint8_t port, const uint8_t *data,
|
||||||
uint16_t length, int flags) = 0;
|
uint16_t length, int flags) = 0;
|
||||||
|
|
||||||
/** Receives a message from the Network Server on a specific port.
|
/** Receives a message from the Network Server on a specific port.
|
||||||
|
|
@ -259,7 +259,7 @@ public:
|
||||||
* nothing available to read at the moment.
|
* nothing available to read at the moment.
|
||||||
* iv) A negative error code on failure.
|
* iv) A negative error code on failure.
|
||||||
*/
|
*/
|
||||||
virtual int16_t receive(uint8_t port, uint8_t* data, uint16_t length, int flags) = 0;
|
virtual int16_t receive(uint8_t port, uint8_t *data, uint16_t length, int flags) = 0;
|
||||||
|
|
||||||
/** Receives a message from the Network Server from any port.
|
/** Receives a message from the Network Server from any port.
|
||||||
*
|
*
|
||||||
|
|
@ -283,7 +283,7 @@ public:
|
||||||
* nothing available to read at the moment.
|
* nothing available to read at the moment.
|
||||||
* iv) A negative error code on failure.
|
* iv) A negative error code on failure.
|
||||||
*/
|
*/
|
||||||
virtual int16_t receive(uint8_t* data, uint16_t length, uint8_t& port, int& flags) = 0;
|
virtual int16_t receive(uint8_t *data, uint16_t length, uint8_t &port, int &flags) = 0;
|
||||||
|
|
||||||
/** Add application callbacks to the stack.
|
/** Add application callbacks to the stack.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
using namespace events;
|
using namespace events;
|
||||||
|
|
||||||
LoRaWANInterface::LoRaWANInterface(LoRaRadio& radio)
|
LoRaWANInterface::LoRaWANInterface(LoRaRadio &radio)
|
||||||
{
|
{
|
||||||
_lw_stack.bind_radio_driver(radio);
|
_lw_stack.bind_radio_driver(radio);
|
||||||
}
|
}
|
||||||
|
|
@ -116,7 +116,7 @@ lorawan_status_t LoRaWANInterface::remove_channel_plan()
|
||||||
return _lw_stack.drop_channel_list();
|
return _lw_stack.drop_channel_list();
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t LoRaWANInterface::send(uint8_t port, const uint8_t* data, uint16_t length, int flags)
|
int16_t LoRaWANInterface::send(uint8_t port, const uint8_t *data, uint16_t length, int flags)
|
||||||
{
|
{
|
||||||
Lock lock(*this);
|
Lock lock(*this);
|
||||||
return _lw_stack.handle_tx(port, data, length, flags);
|
return _lw_stack.handle_tx(port, data, length, flags);
|
||||||
|
|
@ -146,13 +146,13 @@ lorawan_status_t LoRaWANInterface::get_backoff_metadata(int &backoff)
|
||||||
return _lw_stack.acquire_backoff_metadata(backoff);
|
return _lw_stack.acquire_backoff_metadata(backoff);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t LoRaWANInterface::receive(uint8_t port, uint8_t* data, uint16_t length, int flags)
|
int16_t LoRaWANInterface::receive(uint8_t port, uint8_t *data, uint16_t length, int flags)
|
||||||
{
|
{
|
||||||
Lock lock(*this);
|
Lock lock(*this);
|
||||||
return _lw_stack.handle_rx(data, length, port, flags, true);
|
return _lw_stack.handle_rx(data, length, port, flags, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t LoRaWANInterface::receive(uint8_t* data, uint16_t length, uint8_t& port, int& flags)
|
int16_t LoRaWANInterface::receive(uint8_t *data, uint16_t length, uint8_t &port, int &flags)
|
||||||
{
|
{
|
||||||
Lock lock(*this);
|
Lock lock(*this);
|
||||||
return _lw_stack.handle_rx(data, length, port, flags, false);
|
return _lw_stack.handle_rx(data, length, port, flags, false);
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ public:
|
||||||
* construct a single instance of LoRaWANInterface.
|
* construct a single instance of LoRaWANInterface.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
LoRaWANInterface(LoRaRadio& radio);
|
LoRaWANInterface(LoRaRadio &radio);
|
||||||
|
|
||||||
virtual ~LoRaWANInterface();
|
virtual ~LoRaWANInterface();
|
||||||
|
|
||||||
|
|
@ -315,7 +315,7 @@ public:
|
||||||
* LORAWAN_STATUS_WOULD_BLOCK if another TX is
|
* LORAWAN_STATUS_WOULD_BLOCK if another TX is
|
||||||
* ongoing, or a negative error code on failure.
|
* ongoing, or a negative error code on failure.
|
||||||
*/
|
*/
|
||||||
virtual int16_t send(uint8_t port, const uint8_t* data, uint16_t length,
|
virtual int16_t send(uint8_t port, const uint8_t *data, uint16_t length,
|
||||||
int flags);
|
int flags);
|
||||||
|
|
||||||
/** Receives a message from the Network Server on a specific port.
|
/** Receives a message from the Network Server on a specific port.
|
||||||
|
|
@ -357,7 +357,7 @@ public:
|
||||||
* nothing available to read at the moment.
|
* nothing available to read at the moment.
|
||||||
* iv) A negative error code on failure.
|
* iv) A negative error code on failure.
|
||||||
*/
|
*/
|
||||||
virtual int16_t receive(uint8_t port, uint8_t* data, uint16_t length, int flags);
|
virtual int16_t receive(uint8_t port, uint8_t *data, uint16_t length, int flags);
|
||||||
|
|
||||||
/** Receives a message from the Network Server on any port.
|
/** Receives a message from the Network Server on any port.
|
||||||
*
|
*
|
||||||
|
|
@ -381,7 +381,7 @@ public:
|
||||||
* nothing available to read at the moment.
|
* nothing available to read at the moment.
|
||||||
* iv) A negative error code on failure.
|
* iv) A negative error code on failure.
|
||||||
*/
|
*/
|
||||||
virtual int16_t receive(uint8_t* data, uint16_t length, uint8_t& port, int& flags);
|
virtual int16_t receive(uint8_t *data, uint16_t length, uint8_t &port, int &flags);
|
||||||
|
|
||||||
/** Add application callbacks to the stack.
|
/** Add application callbacks to the stack.
|
||||||
*
|
*
|
||||||
|
|
@ -502,8 +502,14 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual lorawan_status_t cancel_sending(void);
|
virtual lorawan_status_t cancel_sending(void);
|
||||||
|
|
||||||
void lock(void) { _lw_stack.lock(); }
|
void lock(void)
|
||||||
void unlock(void) { _lw_stack.unlock(); }
|
{
|
||||||
|
_lw_stack.lock();
|
||||||
|
}
|
||||||
|
void unlock(void)
|
||||||
|
{
|
||||||
|
_lw_stack.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -49,14 +49,14 @@ using namespace mbed;
|
||||||
using namespace events;
|
using namespace events;
|
||||||
|
|
||||||
#if defined(LORAWAN_COMPLIANCE_TEST)
|
#if defined(LORAWAN_COMPLIANCE_TEST)
|
||||||
#if (MBED_CONF_LORA_PHY == 0 || MBED_CONF_LORA_PHY == 4 || MBED_CONF_LORA_PHY == 6 || MBED_CONF_LORA_PHY == 7)
|
#if (MBED_CONF_LORA_PHY == 0 || MBED_CONF_LORA_PHY == 4 || MBED_CONF_LORA_PHY == 6 || MBED_CONF_LORA_PHY == 7)
|
||||||
#define LORAWAN_COMPLIANCE_TEST_DATA_SIZE 16
|
#define LORAWAN_COMPLIANCE_TEST_DATA_SIZE 16
|
||||||
#elif (MBED_CONF_LORA_PHY == 1 || MBED_CONF_LORA_PHY == 2 || MBED_CONF_LORA_PHY == 8 || MBED_CONF_LORA_PHY == 9)
|
#elif (MBED_CONF_LORA_PHY == 1 || MBED_CONF_LORA_PHY == 2 || MBED_CONF_LORA_PHY == 8 || MBED_CONF_LORA_PHY == 9)
|
||||||
#define LORAWAN_COMPLIANCE_TEST_DATA_SIZE 11
|
#define LORAWAN_COMPLIANCE_TEST_DATA_SIZE 11
|
||||||
#else
|
#else
|
||||||
#error "Must set LoRa PHY layer parameters."
|
#error "Must set LoRa PHY layer parameters."
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif //defined(LORAWAN_COMPLIANCE_TEST)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bit mask for message flags
|
* Bit mask for message flags
|
||||||
|
|
@ -98,7 +98,7 @@ LoRaWANStack::LoRaWANStack()
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Public Methods *
|
* Public Methods *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
void LoRaWANStack::bind_radio_driver(LoRaRadio& radio)
|
void LoRaWANStack::bind_radio_driver(LoRaRadio &radio)
|
||||||
{
|
{
|
||||||
radio_events.tx_done = mbed::callback(this, &LoRaWANStack::tx_interrupt_handler);
|
radio_events.tx_done = mbed::callback(this, &LoRaWANStack::tx_interrupt_handler);
|
||||||
radio_events.rx_done = mbed::callback(this, &LoRaWANStack::rx_interrupt_handler);
|
radio_events.rx_done = mbed::callback(this, &LoRaWANStack::rx_interrupt_handler);
|
||||||
|
|
@ -115,7 +115,7 @@ void LoRaWANStack::bind_radio_driver(LoRaRadio& radio)
|
||||||
|
|
||||||
lorawan_status_t LoRaWANStack::initialize_mac_layer(EventQueue *queue)
|
lorawan_status_t LoRaWANStack::initialize_mac_layer(EventQueue *queue)
|
||||||
{
|
{
|
||||||
if(!queue) {
|
if (!queue) {
|
||||||
return LORAWAN_STATUS_PARAMETER_INVALID;
|
return LORAWAN_STATUS_PARAMETER_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,6 +127,10 @@ lorawan_status_t LoRaWANStack::initialize_mac_layer(EventQueue *queue)
|
||||||
|
|
||||||
lorawan_status_t LoRaWANStack::set_lora_callbacks(const lorawan_app_callbacks_t *callbacks)
|
lorawan_status_t LoRaWANStack::set_lora_callbacks(const lorawan_app_callbacks_t *callbacks)
|
||||||
{
|
{
|
||||||
|
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
|
||||||
|
return LORAWAN_STATUS_NOT_INITIALIZED;
|
||||||
|
}
|
||||||
|
|
||||||
if (!callbacks || !callbacks->events) {
|
if (!callbacks || !callbacks->events) {
|
||||||
return LORAWAN_STATUS_PARAMETER_INVALID;
|
return LORAWAN_STATUS_PARAMETER_INVALID;
|
||||||
}
|
}
|
||||||
|
|
@ -148,7 +152,6 @@ lorawan_status_t LoRaWANStack::set_lora_callbacks(const lorawan_app_callbacks_t
|
||||||
lorawan_status_t LoRaWANStack::connect()
|
lorawan_status_t LoRaWANStack::connect()
|
||||||
{
|
{
|
||||||
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
|
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
|
||||||
tr_error("Stack not initialized!");
|
|
||||||
return LORAWAN_STATUS_NOT_INITIALIZED;
|
return LORAWAN_STATUS_NOT_INITIALIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,14 +167,14 @@ lorawan_status_t LoRaWANStack::connect()
|
||||||
lorawan_status_t LoRaWANStack::connect(const lorawan_connect_t &connect)
|
lorawan_status_t LoRaWANStack::connect(const lorawan_connect_t &connect)
|
||||||
{
|
{
|
||||||
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
|
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
|
||||||
tr_error("Stack not initialized!");
|
|
||||||
return LORAWAN_STATUS_NOT_INITIALIZED;
|
return LORAWAN_STATUS_NOT_INITIALIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(connect.connect_type == LORAWAN_CONNECTION_OTAA) &&
|
if (!(connect.connect_type == LORAWAN_CONNECTION_OTAA)
|
||||||
!(connect.connect_type == LORAWAN_CONNECTION_ABP)) {
|
&& !(connect.connect_type == LORAWAN_CONNECTION_ABP)) {
|
||||||
return LORAWAN_STATUS_PARAMETER_INVALID;
|
return LORAWAN_STATUS_PARAMETER_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_otaa = (connect.connect_type == LORAWAN_CONNECTION_OTAA);
|
bool is_otaa = (connect.connect_type == LORAWAN_CONNECTION_OTAA);
|
||||||
|
|
||||||
lorawan_status_t status = _loramac.prepare_join(&connect, is_otaa);
|
lorawan_status_t status = _loramac.prepare_join(&connect, is_otaa);
|
||||||
|
|
@ -186,7 +189,6 @@ lorawan_status_t LoRaWANStack::connect(const lorawan_connect_t &connect)
|
||||||
lorawan_status_t LoRaWANStack::add_channels(const lorawan_channelplan_t &channel_plan)
|
lorawan_status_t LoRaWANStack::add_channels(const lorawan_channelplan_t &channel_plan)
|
||||||
{
|
{
|
||||||
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
|
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
|
||||||
tr_error("Stack not initialized!");
|
|
||||||
return LORAWAN_STATUS_NOT_INITIALIZED;
|
return LORAWAN_STATUS_NOT_INITIALIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -196,7 +198,6 @@ lorawan_status_t LoRaWANStack::add_channels(const lorawan_channelplan_t &channel
|
||||||
lorawan_status_t LoRaWANStack::remove_a_channel(uint8_t channel_id)
|
lorawan_status_t LoRaWANStack::remove_a_channel(uint8_t channel_id)
|
||||||
{
|
{
|
||||||
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
|
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
|
||||||
tr_error("Stack not initialized!");
|
|
||||||
return LORAWAN_STATUS_NOT_INITIALIZED;
|
return LORAWAN_STATUS_NOT_INITIALIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,17 +207,15 @@ lorawan_status_t LoRaWANStack::remove_a_channel(uint8_t channel_id)
|
||||||
lorawan_status_t LoRaWANStack::drop_channel_list()
|
lorawan_status_t LoRaWANStack::drop_channel_list()
|
||||||
{
|
{
|
||||||
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
|
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
|
||||||
tr_error("Stack not initialized!");
|
|
||||||
return LORAWAN_STATUS_NOT_INITIALIZED;
|
return LORAWAN_STATUS_NOT_INITIALIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _loramac.remove_channel_plan();
|
return _loramac.remove_channel_plan();
|
||||||
}
|
}
|
||||||
|
|
||||||
lorawan_status_t LoRaWANStack::get_enabled_channels(lorawan_channelplan_t& channel_plan)
|
lorawan_status_t LoRaWANStack::get_enabled_channels(lorawan_channelplan_t &channel_plan)
|
||||||
{
|
{
|
||||||
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
|
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
|
||||||
tr_error("Stack not initialized!");
|
|
||||||
return LORAWAN_STATUS_NOT_INITIALIZED;
|
return LORAWAN_STATUS_NOT_INITIALIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -225,6 +224,10 @@ lorawan_status_t LoRaWANStack::get_enabled_channels(lorawan_channelplan_t& chann
|
||||||
|
|
||||||
lorawan_status_t LoRaWANStack::set_confirmed_msg_retry(uint8_t count)
|
lorawan_status_t LoRaWANStack::set_confirmed_msg_retry(uint8_t count)
|
||||||
{
|
{
|
||||||
|
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
|
||||||
|
return LORAWAN_STATUS_NOT_INITIALIZED;
|
||||||
|
}
|
||||||
|
|
||||||
if (count >= MAX_CONFIRMED_MSG_RETRIES) {
|
if (count >= MAX_CONFIRMED_MSG_RETRIES) {
|
||||||
return LORAWAN_STATUS_PARAMETER_INVALID;
|
return LORAWAN_STATUS_PARAMETER_INVALID;
|
||||||
}
|
}
|
||||||
|
|
@ -236,9 +239,7 @@ lorawan_status_t LoRaWANStack::set_confirmed_msg_retry(uint8_t count)
|
||||||
|
|
||||||
lorawan_status_t LoRaWANStack::set_channel_data_rate(uint8_t data_rate)
|
lorawan_status_t LoRaWANStack::set_channel_data_rate(uint8_t data_rate)
|
||||||
{
|
{
|
||||||
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state)
|
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
|
||||||
{
|
|
||||||
tr_error("Stack not initialized!");
|
|
||||||
return LORAWAN_STATUS_NOT_INITIALIZED;
|
return LORAWAN_STATUS_NOT_INITIALIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -248,11 +249,10 @@ lorawan_status_t LoRaWANStack::set_channel_data_rate(uint8_t data_rate)
|
||||||
|
|
||||||
lorawan_status_t LoRaWANStack::enable_adaptive_datarate(bool adr_enabled)
|
lorawan_status_t LoRaWANStack::enable_adaptive_datarate(bool adr_enabled)
|
||||||
{
|
{
|
||||||
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED)
|
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
|
||||||
{
|
|
||||||
tr_error("Stack not initialized!");
|
|
||||||
return LORAWAN_STATUS_NOT_INITIALIZED;
|
return LORAWAN_STATUS_NOT_INITIALIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
_loramac.enable_adaptive_datarate(adr_enabled);
|
_loramac.enable_adaptive_datarate(adr_enabled);
|
||||||
return LORAWAN_STATUS_OK;
|
return LORAWAN_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
@ -272,7 +272,7 @@ lorawan_status_t LoRaWANStack::stop_sending(void)
|
||||||
return LORAWAN_STATUS_BUSY;
|
return LORAWAN_STATUS_BUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t* data,
|
int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t *data,
|
||||||
uint16_t length, uint8_t flags,
|
uint16_t length, uint8_t flags,
|
||||||
bool null_allowed, bool allow_port_0)
|
bool null_allowed, bool allow_port_0)
|
||||||
{
|
{
|
||||||
|
|
@ -289,7 +289,7 @@ int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t* data,
|
||||||
return LORAWAN_STATUS_NO_ACTIVE_SESSIONS;
|
return LORAWAN_STATUS_NO_ACTIVE_SESSIONS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_loramac.tx_ongoing()) {
|
if (_loramac.tx_ongoing()) {
|
||||||
return LORAWAN_STATUS_WOULD_BLOCK;
|
return LORAWAN_STATUS_WOULD_BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -334,7 +334,7 @@ int16_t LoRaWANStack::handle_tx(const uint8_t port, const uint8_t* data,
|
||||||
return (status == LORAWAN_STATUS_OK) ? len : (int16_t) status;
|
return (status == LORAWAN_STATUS_OK) ? len : (int16_t) status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t LoRaWANStack::handle_rx(uint8_t* data, uint16_t length, uint8_t& port, int& flags, bool validate_params)
|
int16_t LoRaWANStack::handle_rx(uint8_t *data, uint16_t length, uint8_t &port, int &flags, bool validate_params)
|
||||||
{
|
{
|
||||||
if (!_lw_session.active) {
|
if (!_lw_session.active) {
|
||||||
return LORAWAN_STATUS_NO_ACTIVE_SESSIONS;
|
return LORAWAN_STATUS_NO_ACTIVE_SESSIONS;
|
||||||
|
|
@ -375,8 +375,8 @@ int16_t LoRaWANStack::handle_rx(uint8_t* data, uint16_t length, uint8_t& port, i
|
||||||
|
|
||||||
// check the length of received message whether we can fit into user
|
// check the length of received message whether we can fit into user
|
||||||
// buffer completely or not
|
// buffer completely or not
|
||||||
if (_rx_msg.msg.mcps_indication.buffer_size > length &&
|
if (_rx_msg.msg.mcps_indication.buffer_size > length
|
||||||
_rx_msg.prev_read_size == 0) {
|
&& _rx_msg.prev_read_size == 0) {
|
||||||
// we can't fit into user buffer. Invoke counter measures
|
// we can't fit into user buffer. Invoke counter measures
|
||||||
_rx_msg.pending_size = _rx_msg.msg.mcps_indication.buffer_size - length;
|
_rx_msg.pending_size = _rx_msg.msg.mcps_indication.buffer_size - length;
|
||||||
base_size = length;
|
base_size = length;
|
||||||
|
|
@ -393,7 +393,7 @@ int16_t LoRaWANStack::handle_rx(uint8_t* data, uint16_t length, uint8_t& port, i
|
||||||
// the buffer. Due to checks above, in case of a pending read, this block
|
// the buffer. Due to checks above, in case of a pending read, this block
|
||||||
// will be the only one to get invoked
|
// will be the only one to get invoked
|
||||||
if (_rx_msg.pending_size > 0 && _rx_msg.prev_read_size > 0) {
|
if (_rx_msg.pending_size > 0 && _rx_msg.prev_read_size > 0) {
|
||||||
memcpy(data, base_ptr+_rx_msg.prev_read_size, base_size);
|
memcpy(data, base_ptr + _rx_msg.prev_read_size, base_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// we are done handing over received buffer to user. check if there is
|
// we are done handing over received buffer to user. check if there is
|
||||||
|
|
@ -410,6 +410,10 @@ int16_t LoRaWANStack::handle_rx(uint8_t* data, uint16_t length, uint8_t& port, i
|
||||||
|
|
||||||
lorawan_status_t LoRaWANStack::set_link_check_request()
|
lorawan_status_t LoRaWANStack::set_link_check_request()
|
||||||
{
|
{
|
||||||
|
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
|
||||||
|
return LORAWAN_STATUS_NOT_INITIALIZED;
|
||||||
|
}
|
||||||
|
|
||||||
_link_check_requested = true;
|
_link_check_requested = true;
|
||||||
if (!_callbacks.link_check_resp) {
|
if (!_callbacks.link_check_resp) {
|
||||||
tr_error("Must assign a callback function for link check request. ");
|
tr_error("Must assign a callback function for link check request. ");
|
||||||
|
|
@ -427,11 +431,19 @@ void LoRaWANStack::remove_link_check_request()
|
||||||
|
|
||||||
lorawan_status_t LoRaWANStack::shutdown()
|
lorawan_status_t LoRaWANStack::shutdown()
|
||||||
{
|
{
|
||||||
|
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
|
||||||
|
return LORAWAN_STATUS_NOT_INITIALIZED;
|
||||||
|
}
|
||||||
|
|
||||||
return state_controller(DEVICE_STATE_SHUTDOWN);
|
return state_controller(DEVICE_STATE_SHUTDOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
lorawan_status_t LoRaWANStack::set_device_class(const device_class_t& device_class)
|
lorawan_status_t LoRaWANStack::set_device_class(const device_class_t &device_class)
|
||||||
{
|
{
|
||||||
|
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
|
||||||
|
return LORAWAN_STATUS_NOT_INITIALIZED;
|
||||||
|
}
|
||||||
|
|
||||||
if (device_class == CLASS_B) {
|
if (device_class == CLASS_B) {
|
||||||
return LORAWAN_STATUS_UNSUPPORTED;
|
return LORAWAN_STATUS_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
@ -593,7 +605,7 @@ void LoRaWANStack::handle_ack_expiry_for_class_c(void)
|
||||||
state_controller(DEVICE_STATE_STATUS_CHECK);
|
state_controller(DEVICE_STATE_STATUS_CHECK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoRaWANStack::process_reception(const uint8_t* const payload, uint16_t size,
|
void LoRaWANStack::process_reception(const uint8_t *const payload, uint16_t size,
|
||||||
int16_t rssi, int8_t snr)
|
int16_t rssi, int8_t snr)
|
||||||
{
|
{
|
||||||
_device_current_state = DEVICE_STATE_RECEIVING;
|
_device_current_state = DEVICE_STATE_RECEIVING;
|
||||||
|
|
@ -965,7 +977,7 @@ void LoRaWANStack::mcps_indication_handler()
|
||||||
*/
|
*/
|
||||||
if ((_loramac.get_device_class() != CLASS_C && mcps_indication->fpending_status)
|
if ((_loramac.get_device_class() != CLASS_C && mcps_indication->fpending_status)
|
||||||
||
|
||
|
||||||
(_loramac.get_device_class() == CLASS_C && mcps_indication->type == MCPS_CONFIRMED)) {
|
(_loramac.get_device_class() == CLASS_C && mcps_indication->type == MCPS_CONFIRMED)) {
|
||||||
#if (MBED_CONF_LORA_AUTOMATIC_UPLINK_MESSAGE)
|
#if (MBED_CONF_LORA_AUTOMATIC_UPLINK_MESSAGE)
|
||||||
tr_debug("Sending empty uplink message...");
|
tr_debug("Sending empty uplink message...");
|
||||||
_automatic_uplink_ongoing = true;
|
_automatic_uplink_ongoing = true;
|
||||||
|
|
@ -1012,7 +1024,7 @@ lorawan_status_t LoRaWANStack::state_controller(device_states_t new_state)
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoRaWANStack::process_shutdown_state(lorawan_status_t& op_status)
|
void LoRaWANStack::process_shutdown_state(lorawan_status_t &op_status)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Remove channels
|
* Remove channels
|
||||||
|
|
@ -1030,7 +1042,7 @@ void LoRaWANStack::process_shutdown_state(lorawan_status_t& op_status)
|
||||||
void LoRaWANStack::process_status_check_state()
|
void LoRaWANStack::process_status_check_state()
|
||||||
{
|
{
|
||||||
if (_device_current_state == DEVICE_STATE_SENDING ||
|
if (_device_current_state == DEVICE_STATE_SENDING ||
|
||||||
_device_current_state == DEVICE_STATE_AWAITING_ACK) {
|
_device_current_state == DEVICE_STATE_AWAITING_ACK) {
|
||||||
// this happens after RX2 slot is exhausted
|
// this happens after RX2 slot is exhausted
|
||||||
// we may or may not have a successful UNCONFIRMED transmission
|
// we may or may not have a successful UNCONFIRMED transmission
|
||||||
// here. In CONFIRMED case this block is invoked only
|
// here. In CONFIRMED case this block is invoked only
|
||||||
|
|
@ -1070,11 +1082,11 @@ void LoRaWANStack::process_status_check_state()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoRaWANStack::process_scheduling_state(lorawan_status_t& op_status)
|
void LoRaWANStack::process_scheduling_state(lorawan_status_t &op_status)
|
||||||
{
|
{
|
||||||
if (_device_current_state != DEVICE_STATE_IDLE) {
|
if (_device_current_state != DEVICE_STATE_IDLE) {
|
||||||
if (_device_current_state != DEVICE_STATE_RECEIVING
|
if (_device_current_state != DEVICE_STATE_RECEIVING
|
||||||
&& _loramac.get_device_class() != CLASS_C) {
|
&& _loramac.get_device_class() != CLASS_C) {
|
||||||
op_status = LORAWAN_STATUS_BUSY;
|
op_status = LORAWAN_STATUS_BUSY;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1089,7 +1101,7 @@ void LoRaWANStack::process_scheduling_state(lorawan_status_t& op_status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoRaWANStack::process_joining_state(lorawan_status_t& op_status)
|
void LoRaWANStack::process_joining_state(lorawan_status_t &op_status)
|
||||||
{
|
{
|
||||||
if (_device_current_state == DEVICE_STATE_CONNECTING) {
|
if (_device_current_state == DEVICE_STATE_CONNECTING) {
|
||||||
_device_current_state = DEVICE_STATE_JOINING;
|
_device_current_state = DEVICE_STATE_JOINING;
|
||||||
|
|
@ -1124,11 +1136,10 @@ void LoRaWANStack::process_connected_state()
|
||||||
_device_current_state = DEVICE_STATE_IDLE;
|
_device_current_state = DEVICE_STATE_IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoRaWANStack::process_connecting_state(lorawan_status_t& op_status)
|
void LoRaWANStack::process_connecting_state(lorawan_status_t &op_status)
|
||||||
{
|
{
|
||||||
if (_device_current_state != DEVICE_STATE_IDLE
|
if (_device_current_state != DEVICE_STATE_IDLE
|
||||||
&&
|
&& _device_current_state != DEVICE_STATE_SHUTDOWN) {
|
||||||
_device_current_state != DEVICE_STATE_SHUTDOWN) {
|
|
||||||
op_status = LORAWAN_STATUS_BUSY;
|
op_status = LORAWAN_STATUS_BUSY;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1151,7 +1162,7 @@ void LoRaWANStack::process_connecting_state(lorawan_status_t& op_status)
|
||||||
process_connected_state();
|
process_connected_state();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoRaWANStack::process_idle_state(lorawan_status_t& op_status)
|
void LoRaWANStack::process_idle_state(lorawan_status_t &op_status)
|
||||||
{
|
{
|
||||||
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
|
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
|
||||||
_device_current_state = DEVICE_STATE_IDLE;
|
_device_current_state = DEVICE_STATE_IDLE;
|
||||||
|
|
@ -1163,7 +1174,7 @@ void LoRaWANStack::process_idle_state(lorawan_status_t& op_status)
|
||||||
op_status = LORAWAN_STATUS_OK;
|
op_status = LORAWAN_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoRaWANStack::process_uninitialized_state(lorawan_status_t& op_status)
|
void LoRaWANStack::process_uninitialized_state(lorawan_status_t &op_status)
|
||||||
{
|
{
|
||||||
op_status = _loramac.initialize(_queue);
|
op_status = _loramac.initialize(_queue);
|
||||||
|
|
||||||
|
|
@ -1192,19 +1203,19 @@ lorawan_status_t LoRaWANStack::send_compliance_test_frame_to_mac()
|
||||||
test_req.f_buffer[2] = _compliance_test.nb_gateways;
|
test_req.f_buffer[2] = _compliance_test.nb_gateways;
|
||||||
} else {
|
} else {
|
||||||
switch (_compliance_test.state) {
|
switch (_compliance_test.state) {
|
||||||
case 4:
|
case 4:
|
||||||
_compliance_test.state = 1;
|
_compliance_test.state = 1;
|
||||||
test_req.f_buffer_size = _compliance_test.app_data_size;
|
test_req.f_buffer_size = _compliance_test.app_data_size;
|
||||||
test_req.f_buffer[0] = _compliance_test.app_data_buffer[0];
|
test_req.f_buffer[0] = _compliance_test.app_data_buffer[0];
|
||||||
for(uint8_t i = 1; i < MIN(_compliance_test.app_data_size, MBED_CONF_LORA_TX_MAX_SIZE); ++i) {
|
for (uint8_t i = 1; i < MIN(_compliance_test.app_data_size, MBED_CONF_LORA_TX_MAX_SIZE); ++i) {
|
||||||
test_req.f_buffer[i] = _compliance_test.app_data_buffer[i];
|
test_req.f_buffer[i] = _compliance_test.app_data_buffer[i];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
test_req.f_buffer_size = 2;
|
test_req.f_buffer_size = 2;
|
||||||
test_req.f_buffer[0] = _compliance_test.downlink_counter >> 8;
|
test_req.f_buffer[0] = _compliance_test.downlink_counter >> 8;
|
||||||
test_req.f_buffer[1] = _compliance_test.downlink_counter;
|
test_req.f_buffer[1] = _compliance_test.downlink_counter;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1220,7 +1231,7 @@ lorawan_status_t LoRaWANStack::send_compliance_test_frame_to_mac()
|
||||||
tr_info("Transmit unconfirmed compliance test frame %d bytes.", test_req.f_buffer_size);
|
tr_info("Transmit unconfirmed compliance test frame %d bytes.", test_req.f_buffer_size);
|
||||||
|
|
||||||
for (uint8_t i = 0; i < test_req.f_buffer_size; ++i) {
|
for (uint8_t i = 0; i < test_req.f_buffer_size; ++i) {
|
||||||
tr_info("Byte %d, data is 0x%x", i+1, ((uint8_t*)test_req.f_buffer)[i]);
|
tr_info("Byte %d, data is 0x%x", i + 1, ((uint8_t *)test_req.f_buffer)[i]);
|
||||||
}
|
}
|
||||||
} else if (_compliance_test.is_tx_confirmed) {
|
} else if (_compliance_test.is_tx_confirmed) {
|
||||||
test_req.type = MCPS_CONFIRMED;
|
test_req.type = MCPS_CONFIRMED;
|
||||||
|
|
@ -1231,7 +1242,7 @@ lorawan_status_t LoRaWANStack::send_compliance_test_frame_to_mac()
|
||||||
tr_info("Transmit confirmed compliance test frame %d bytes.", test_req.f_buffer_size);
|
tr_info("Transmit confirmed compliance test frame %d bytes.", test_req.f_buffer_size);
|
||||||
|
|
||||||
for (uint8_t i = 0; i < test_req.f_buffer_size; ++i) {
|
for (uint8_t i = 0; i < test_req.f_buffer_size; ++i) {
|
||||||
tr_info("Byte %d, data is 0x%x", i+1, ((uint8_t*)test_req.f_buffer)[i]);
|
tr_info("Byte %d, data is 0x%x", i + 1, ((uint8_t *)test_req.f_buffer)[i]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return LORAWAN_STATUS_SERVICE_UNKNOWN;
|
return LORAWAN_STATUS_SERVICE_UNKNOWN;
|
||||||
|
|
@ -1245,10 +1256,10 @@ void LoRaWANStack::compliance_test_handler(loramac_mcps_indication_t *mcps_indic
|
||||||
if (_compliance_test.running == false) {
|
if (_compliance_test.running == false) {
|
||||||
// Check compliance test enable command (i)
|
// Check compliance test enable command (i)
|
||||||
if ((mcps_indication->buffer_size == 4) &&
|
if ((mcps_indication->buffer_size == 4) &&
|
||||||
(mcps_indication->buffer[0] == 0x01) &&
|
(mcps_indication->buffer[0] == 0x01) &&
|
||||||
(mcps_indication->buffer[1] == 0x01) &&
|
(mcps_indication->buffer[1] == 0x01) &&
|
||||||
(mcps_indication->buffer[2] == 0x01) &&
|
(mcps_indication->buffer[2] == 0x01) &&
|
||||||
(mcps_indication->buffer[3] == 0x01)) {
|
(mcps_indication->buffer[3] == 0x01)) {
|
||||||
_compliance_test.is_tx_confirmed = false;
|
_compliance_test.is_tx_confirmed = false;
|
||||||
_compliance_test.app_port = 224;
|
_compliance_test.app_port = 224;
|
||||||
_compliance_test.app_data_size = 2;
|
_compliance_test.app_data_size = 2;
|
||||||
|
|
@ -1275,82 +1286,82 @@ void LoRaWANStack::compliance_test_handler(loramac_mcps_indication_t *mcps_indic
|
||||||
} else {
|
} else {
|
||||||
_compliance_test.state = mcps_indication->buffer[0];
|
_compliance_test.state = mcps_indication->buffer[0];
|
||||||
switch (_compliance_test.state) {
|
switch (_compliance_test.state) {
|
||||||
case 0: // Check compliance test disable command (ii)
|
case 0: // Check compliance test disable command (ii)
|
||||||
_compliance_test.is_tx_confirmed = true;
|
_compliance_test.is_tx_confirmed = true;
|
||||||
_compliance_test.app_port = MBED_CONF_LORA_APP_PORT;
|
_compliance_test.app_port = MBED_CONF_LORA_APP_PORT;
|
||||||
_compliance_test.app_data_size = LORAWAN_COMPLIANCE_TEST_DATA_SIZE;
|
_compliance_test.app_data_size = LORAWAN_COMPLIANCE_TEST_DATA_SIZE;
|
||||||
_compliance_test.downlink_counter = 0;
|
_compliance_test.downlink_counter = 0;
|
||||||
_compliance_test.running = false;
|
_compliance_test.running = false;
|
||||||
|
|
||||||
_loramac.enable_adaptive_datarate(MBED_CONF_LORA_ADR_ON);
|
_loramac.enable_adaptive_datarate(MBED_CONF_LORA_ADR_ON);
|
||||||
|
|
||||||
#if MBED_CONF_LORA_PHY == 0
|
#if MBED_CONF_LORA_PHY == 0
|
||||||
_loramac.LoRaMacTestSetDutyCycleOn(MBED_CONF_LORA_DUTY_CYCLE_ON);
|
_loramac.LoRaMacTestSetDutyCycleOn(MBED_CONF_LORA_DUTY_CYCLE_ON);
|
||||||
#endif
|
#endif
|
||||||
// Go to idle state after compliance test mode.
|
// Go to idle state after compliance test mode.
|
||||||
tr_debug("Compliance test disabled.");
|
tr_debug("Compliance test disabled.");
|
||||||
_loramac.LoRaMacStopTxTimer();
|
_loramac.LoRaMacStopTxTimer();
|
||||||
|
|
||||||
// Clear any compliance test message stuff before going back to normal operation.
|
// Clear any compliance test message stuff before going back to normal operation.
|
||||||
_loramac.reset_ongoing_tx();
|
_loramac.reset_ongoing_tx();
|
||||||
lora_state_machine(DEVICE_STATE_IDLE);
|
lora_state_machine(DEVICE_STATE_IDLE);
|
||||||
break;
|
break;
|
||||||
case 1: // (iii, iv)
|
case 1: // (iii, iv)
|
||||||
_compliance_test.app_data_size = 2;
|
_compliance_test.app_data_size = 2;
|
||||||
break;
|
break;
|
||||||
case 2: // Enable confirmed messages (v)
|
case 2: // Enable confirmed messages (v)
|
||||||
_compliance_test.is_tx_confirmed = true;
|
_compliance_test.is_tx_confirmed = true;
|
||||||
_compliance_test.state = 1;
|
_compliance_test.state = 1;
|
||||||
break;
|
break;
|
||||||
case 3: // Disable confirmed messages (vi)
|
case 3: // Disable confirmed messages (vi)
|
||||||
_compliance_test.is_tx_confirmed = false;
|
_compliance_test.is_tx_confirmed = false;
|
||||||
_compliance_test.state = 1;
|
_compliance_test.state = 1;
|
||||||
break;
|
break;
|
||||||
case 4: // (vii)
|
case 4: // (vii)
|
||||||
_compliance_test.app_data_size = mcps_indication->buffer_size;
|
_compliance_test.app_data_size = mcps_indication->buffer_size;
|
||||||
|
|
||||||
_compliance_test.app_data_buffer[0] = 4;
|
_compliance_test.app_data_buffer[0] = 4;
|
||||||
for(uint8_t i = 1; i < MIN(_compliance_test.app_data_size, LORAMAC_PHY_MAXPAYLOAD); ++i) {
|
for (uint8_t i = 1; i < MIN(_compliance_test.app_data_size, LORAMAC_PHY_MAXPAYLOAD); ++i) {
|
||||||
_compliance_test.app_data_buffer[i] = mcps_indication->buffer[i] + 1;
|
_compliance_test.app_data_buffer[i] = mcps_indication->buffer[i] + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
send_compliance_test_frame_to_mac();
|
send_compliance_test_frame_to_mac();
|
||||||
break;
|
break;
|
||||||
case 5: // (viii)
|
case 5: // (viii)
|
||||||
_loramac.setup_link_check_request();
|
_loramac.setup_link_check_request();
|
||||||
break;
|
break;
|
||||||
case 6: // (ix)
|
case 6: // (ix)
|
||||||
// Disable TestMode and revert back to normal operation
|
// Disable TestMode and revert back to normal operation
|
||||||
_compliance_test.is_tx_confirmed = true;
|
_compliance_test.is_tx_confirmed = true;
|
||||||
_compliance_test.app_port = MBED_CONF_LORA_APP_PORT;
|
_compliance_test.app_port = MBED_CONF_LORA_APP_PORT;
|
||||||
_compliance_test.app_data_size = LORAWAN_COMPLIANCE_TEST_DATA_SIZE;
|
_compliance_test.app_data_size = LORAWAN_COMPLIANCE_TEST_DATA_SIZE;
|
||||||
_compliance_test.downlink_counter = 0;
|
_compliance_test.downlink_counter = 0;
|
||||||
_compliance_test.running = false;
|
_compliance_test.running = false;
|
||||||
|
|
||||||
_loramac.enable_adaptive_datarate(MBED_CONF_LORA_ADR_ON);
|
_loramac.enable_adaptive_datarate(MBED_CONF_LORA_ADR_ON);
|
||||||
|
|
||||||
#if MBED_CONF_LORA_PHY == 0
|
#if MBED_CONF_LORA_PHY == 0
|
||||||
_loramac.LoRaMacTestSetDutyCycleOn(MBED_CONF_LORA_DUTY_CYCLE_ON);
|
_loramac.LoRaMacTestSetDutyCycleOn(MBED_CONF_LORA_DUTY_CYCLE_ON);
|
||||||
#endif
|
#endif
|
||||||
_loramac.join(true);
|
_loramac.join(true);
|
||||||
break;
|
break;
|
||||||
case 7: // (x)
|
case 7: // (x)
|
||||||
if (mcps_indication->buffer_size == 3) {
|
if (mcps_indication->buffer_size == 3) {
|
||||||
loramac_mlme_req_t mlme_req;
|
loramac_mlme_req_t mlme_req;
|
||||||
mlme_req.type = MLME_TXCW;
|
mlme_req.type = MLME_TXCW;
|
||||||
mlme_req.cw_tx_mode.timeout = (uint16_t)((mcps_indication->buffer[1] << 8) | mcps_indication->buffer[2]);
|
mlme_req.cw_tx_mode.timeout = (uint16_t)((mcps_indication->buffer[1] << 8) | mcps_indication->buffer[2]);
|
||||||
_loramac.mlme_request(&mlme_req);
|
_loramac.mlme_request(&mlme_req);
|
||||||
} else if (mcps_indication->buffer_size == 7) {
|
} else if (mcps_indication->buffer_size == 7) {
|
||||||
loramac_mlme_req_t mlme_req;
|
loramac_mlme_req_t mlme_req;
|
||||||
mlme_req.type = MLME_TXCW_1;
|
mlme_req.type = MLME_TXCW_1;
|
||||||
mlme_req.cw_tx_mode.timeout = (uint16_t)((mcps_indication->buffer[1] << 8) | mcps_indication->buffer[2]);
|
mlme_req.cw_tx_mode.timeout = (uint16_t)((mcps_indication->buffer[1] << 8) | mcps_indication->buffer[2]);
|
||||||
mlme_req.cw_tx_mode.frequency = (uint32_t)((mcps_indication->buffer[3] << 16) | (mcps_indication->buffer[4] << 8)
|
mlme_req.cw_tx_mode.frequency = (uint32_t)((mcps_indication->buffer[3] << 16) | (mcps_indication->buffer[4] << 8)
|
||||||
| mcps_indication->buffer[5]) * 100;
|
| mcps_indication->buffer[5]) * 100;
|
||||||
mlme_req.cw_tx_mode.power = mcps_indication->buffer[6];
|
mlme_req.cw_tx_mode.power = mcps_indication->buffer[6];
|
||||||
_loramac.mlme_request(&mlme_req);
|
_loramac.mlme_request(&mlme_req);
|
||||||
}
|
}
|
||||||
_compliance_test.state = 1;
|
_compliance_test.state = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ public:
|
||||||
* @param radio LoRaRadio object, i.e., the radio driver
|
* @param radio LoRaRadio object, i.e., the radio driver
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void bind_radio_driver(LoRaRadio& radio);
|
void bind_radio_driver(LoRaRadio &radio);
|
||||||
|
|
||||||
/** End device initialization.
|
/** End device initialization.
|
||||||
* @param queue A pointer to an EventQueue passed from the application.
|
* @param queue A pointer to an EventQueue passed from the application.
|
||||||
|
|
@ -281,7 +281,7 @@ public:
|
||||||
* LORAWAN_STATUS_WOULD_BLOCK if another TX is
|
* LORAWAN_STATUS_WOULD_BLOCK if another TX is
|
||||||
* ongoing, or a negative error code on failure.
|
* ongoing, or a negative error code on failure.
|
||||||
*/
|
*/
|
||||||
int16_t handle_tx(uint8_t port, const uint8_t* data,
|
int16_t handle_tx(uint8_t port, const uint8_t *data,
|
||||||
uint16_t length, uint8_t flags,
|
uint16_t length, uint8_t flags,
|
||||||
bool null_allowed = false, bool allow_port_0 = false);
|
bool null_allowed = false, bool allow_port_0 = false);
|
||||||
|
|
||||||
|
|
@ -334,7 +334,7 @@ public:
|
||||||
* nothing available to read at the moment.
|
* nothing available to read at the moment.
|
||||||
* iv) A negative error code on failure.
|
* iv) A negative error code on failure.
|
||||||
*/
|
*/
|
||||||
int16_t handle_rx(uint8_t* data, uint16_t length, uint8_t& port, int& flags, bool validate_params);
|
int16_t handle_rx(uint8_t *data, uint16_t length, uint8_t &port, int &flags, bool validate_params);
|
||||||
|
|
||||||
/** Send Link Check Request MAC command.
|
/** Send Link Check Request MAC command.
|
||||||
*
|
*
|
||||||
|
|
@ -377,7 +377,7 @@ public:
|
||||||
* LORAWAN_STATUS_UNSUPPORTED is requested class is not supported,
|
* LORAWAN_STATUS_UNSUPPORTED is requested class is not supported,
|
||||||
* or other negative error code if request failed.
|
* or other negative error code if request failed.
|
||||||
*/
|
*/
|
||||||
lorawan_status_t set_device_class(const device_class_t& device_class);
|
lorawan_status_t set_device_class(const device_class_t &device_class);
|
||||||
|
|
||||||
/** Acquire TX meta-data
|
/** Acquire TX meta-data
|
||||||
*
|
*
|
||||||
|
|
@ -425,8 +425,14 @@ public:
|
||||||
*/
|
*/
|
||||||
lorawan_status_t stop_sending(void);
|
lorawan_status_t stop_sending(void);
|
||||||
|
|
||||||
void lock(void) { _loramac.lock(); }
|
void lock(void)
|
||||||
void unlock(void) { _loramac.unlock(); }
|
{
|
||||||
|
_loramac.lock();
|
||||||
|
}
|
||||||
|
void unlock(void)
|
||||||
|
{
|
||||||
|
_loramac.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef mbed::ScopedLock<LoRaWANStack> Lock;
|
typedef mbed::ScopedLock<LoRaWANStack> Lock;
|
||||||
|
|
@ -443,14 +449,14 @@ private:
|
||||||
/**
|
/**
|
||||||
* Helpers for state controller
|
* Helpers for state controller
|
||||||
*/
|
*/
|
||||||
void process_uninitialized_state(lorawan_status_t& op_status);
|
void process_uninitialized_state(lorawan_status_t &op_status);
|
||||||
void process_idle_state(lorawan_status_t& op_status);
|
void process_idle_state(lorawan_status_t &op_status);
|
||||||
void process_connected_state();
|
void process_connected_state();
|
||||||
void process_connecting_state(lorawan_status_t& op_status);
|
void process_connecting_state(lorawan_status_t &op_status);
|
||||||
void process_joining_state(lorawan_status_t& op_status);
|
void process_joining_state(lorawan_status_t &op_status);
|
||||||
void process_scheduling_state(lorawan_status_t& op_status);
|
void process_scheduling_state(lorawan_status_t &op_status);
|
||||||
void process_status_check_state();
|
void process_status_check_state();
|
||||||
void process_shutdown_state(lorawan_status_t& op_status);
|
void process_shutdown_state(lorawan_status_t &op_status);
|
||||||
void state_machine_run_to_completion(void);
|
void state_machine_run_to_completion(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -72,19 +72,19 @@ using namespace mbed;
|
||||||
|
|
||||||
|
|
||||||
LoRaMac::LoRaMac()
|
LoRaMac::LoRaMac()
|
||||||
: _lora_time(),
|
: _lora_time(),
|
||||||
_lora_phy(_lora_time),
|
_lora_phy(_lora_time),
|
||||||
_mac_commands(),
|
_mac_commands(),
|
||||||
_channel_plan(),
|
_channel_plan(),
|
||||||
_lora_crypto(),
|
_lora_crypto(),
|
||||||
_ev_queue(NULL),
|
_ev_queue(NULL),
|
||||||
_mcps_indication(),
|
_mcps_indication(),
|
||||||
_mcps_confirmation(),
|
_mcps_confirmation(),
|
||||||
_mlme_indication(),
|
_mlme_indication(),
|
||||||
_mlme_confirmation(),
|
_mlme_confirmation(),
|
||||||
_is_nwk_joined(false),
|
_is_nwk_joined(false),
|
||||||
_continuous_rx2_window_open(false),
|
_continuous_rx2_window_open(false),
|
||||||
_device_class(CLASS_A)
|
_device_class(CLASS_A)
|
||||||
{
|
{
|
||||||
_params.keys.dev_eui = NULL;
|
_params.keys.dev_eui = NULL;
|
||||||
_params.keys.app_eui = NULL;
|
_params.keys.app_eui = NULL;
|
||||||
|
|
@ -202,7 +202,7 @@ void LoRaMac::on_radio_tx_done(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_params.is_rx_window_enabled == true) {
|
if (_params.is_rx_window_enabled == true) {
|
||||||
// start timer after which rx1_window will get opened
|
// start timer after which rx1_window will get opened
|
||||||
_lora_time.start(_params.timers.rx_window1_timer, _params.rx_window1_delay);
|
_lora_time.start(_params.timers.rx_window1_timer, _params.rx_window1_delay);
|
||||||
|
|
||||||
|
|
@ -237,8 +237,8 @@ void LoRaMac::handle_join_accept_frame(const uint8_t *payload, uint16_t size)
|
||||||
_mlme_confirmation.nb_retries = _params.join_request_trial_counter;
|
_mlme_confirmation.nb_retries = _params.join_request_trial_counter;
|
||||||
|
|
||||||
if (0 != _lora_crypto.decrypt_join_frame(payload + 1, size - 1,
|
if (0 != _lora_crypto.decrypt_join_frame(payload + 1, size - 1,
|
||||||
_params.keys.app_key, APPKEY_KEY_LENGTH,
|
_params.keys.app_key, APPKEY_KEY_LENGTH,
|
||||||
_params.rx_buffer + 1)) {
|
_params.rx_buffer + 1)) {
|
||||||
_mlme_confirmation.status = LORAMAC_EVENT_INFO_STATUS_CRYPTO_FAIL;
|
_mlme_confirmation.status = LORAMAC_EVENT_INFO_STATUS_CRYPTO_FAIL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -317,11 +317,11 @@ void LoRaMac::check_frame_size(uint16_t size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoRaMac::message_integrity_check(const uint8_t * const payload,
|
bool LoRaMac::message_integrity_check(const uint8_t *const payload,
|
||||||
const uint16_t size,
|
const uint16_t size,
|
||||||
uint8_t * const ptr_pos,
|
uint8_t *const ptr_pos,
|
||||||
uint32_t address,
|
uint32_t address,
|
||||||
uint32_t* downlink_counter,
|
uint32_t *downlink_counter,
|
||||||
const uint8_t *nwk_skey)
|
const uint8_t *nwk_skey)
|
||||||
{
|
{
|
||||||
uint32_t mic = 0;
|
uint32_t mic = 0;
|
||||||
|
|
@ -349,7 +349,7 @@ bool LoRaMac::message_integrity_check(const uint8_t * const payload,
|
||||||
// sizeof nws_skey must be the same as _params.keys.nwk_skey,
|
// sizeof nws_skey must be the same as _params.keys.nwk_skey,
|
||||||
_lora_crypto.compute_mic(payload, size - LORAMAC_MFR_LEN,
|
_lora_crypto.compute_mic(payload, size - LORAMAC_MFR_LEN,
|
||||||
nwk_skey,
|
nwk_skey,
|
||||||
sizeof(_params.keys.nwk_skey)*8,
|
sizeof(_params.keys.nwk_skey) * 8,
|
||||||
address, DOWN_LINK, *downlink_counter, &mic);
|
address, DOWN_LINK, *downlink_counter, &mic);
|
||||||
|
|
||||||
if (mic_rx != mic) {
|
if (mic_rx != mic) {
|
||||||
|
|
@ -367,14 +367,14 @@ bool LoRaMac::message_integrity_check(const uint8_t * const payload,
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoRaMac::extract_data_and_mac_commands(const uint8_t *payload,
|
void LoRaMac::extract_data_and_mac_commands(const uint8_t *payload,
|
||||||
uint16_t size,
|
uint16_t size,
|
||||||
uint8_t fopts_len,
|
uint8_t fopts_len,
|
||||||
uint8_t *nwk_skey,
|
uint8_t *nwk_skey,
|
||||||
uint8_t *app_skey,
|
uint8_t *app_skey,
|
||||||
uint32_t address,
|
uint32_t address,
|
||||||
uint32_t downlink_counter,
|
uint32_t downlink_counter,
|
||||||
int16_t rssi,
|
int16_t rssi,
|
||||||
int8_t snr)
|
int8_t snr)
|
||||||
{
|
{
|
||||||
uint8_t frame_len = 0;
|
uint8_t frame_len = 0;
|
||||||
uint8_t payload_start_index = 8 + fopts_len;
|
uint8_t payload_start_index = 8 + fopts_len;
|
||||||
|
|
@ -390,7 +390,7 @@ void LoRaMac::extract_data_and_mac_commands(const uint8_t *payload,
|
||||||
if (_lora_crypto.decrypt_payload(payload + payload_start_index,
|
if (_lora_crypto.decrypt_payload(payload + payload_start_index,
|
||||||
frame_len,
|
frame_len,
|
||||||
nwk_skey,
|
nwk_skey,
|
||||||
sizeof(_params.keys.nwk_skey)*8,
|
sizeof(_params.keys.nwk_skey) * 8,
|
||||||
address,
|
address,
|
||||||
DOWN_LINK,
|
DOWN_LINK,
|
||||||
downlink_counter,
|
downlink_counter,
|
||||||
|
|
@ -399,8 +399,8 @@ void LoRaMac::extract_data_and_mac_commands(const uint8_t *payload,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_mac_commands.process_mac_commands(_params.rx_buffer, 0, frame_len,
|
if (_mac_commands.process_mac_commands(_params.rx_buffer, 0, frame_len,
|
||||||
snr, _mlme_confirmation,
|
snr, _mlme_confirmation,
|
||||||
_params.sys_params, _lora_phy)
|
_params.sys_params, _lora_phy)
|
||||||
!= LORAWAN_STATUS_OK) {
|
!= LORAWAN_STATUS_OK) {
|
||||||
_mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
|
_mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
|
||||||
return;
|
return;
|
||||||
|
|
@ -425,10 +425,11 @@ void LoRaMac::extract_data_and_mac_commands(const uint8_t *payload,
|
||||||
if (fopts_len > 0) {
|
if (fopts_len > 0) {
|
||||||
// Decode Options field MAC commands. Omit the fPort.
|
// Decode Options field MAC commands. Omit the fPort.
|
||||||
if (_mac_commands.process_mac_commands(payload, 8,
|
if (_mac_commands.process_mac_commands(payload, 8,
|
||||||
payload_start_index - 1, snr,
|
payload_start_index - 1,
|
||||||
_mlme_confirmation,
|
snr,
|
||||||
_params.sys_params, _lora_phy)
|
_mlme_confirmation,
|
||||||
!= LORAWAN_STATUS_OK) {
|
_params.sys_params,
|
||||||
|
_lora_phy) != LORAWAN_STATUS_OK) {
|
||||||
_mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
|
_mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -463,8 +464,8 @@ void LoRaMac::extract_mac_commands_only(const uint8_t *payload,
|
||||||
uint8_t payload_start_index = 8 + fopts_len;
|
uint8_t payload_start_index = 8 + fopts_len;
|
||||||
if (fopts_len > 0) {
|
if (fopts_len > 0) {
|
||||||
if (_mac_commands.process_mac_commands(payload, 8, payload_start_index,
|
if (_mac_commands.process_mac_commands(payload, 8, payload_start_index,
|
||||||
snr, _mlme_confirmation,
|
snr, _mlme_confirmation,
|
||||||
_params.sys_params, _lora_phy)
|
_params.sys_params, _lora_phy)
|
||||||
!= LORAWAN_STATUS_OK) {
|
!= LORAWAN_STATUS_OK) {
|
||||||
_mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
|
_mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
|
||||||
return;
|
return;
|
||||||
|
|
@ -477,7 +478,7 @@ void LoRaMac::extract_mac_commands_only(const uint8_t *payload,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoRaMac::handle_data_frame(const uint8_t* const payload,
|
void LoRaMac::handle_data_frame(const uint8_t *const payload,
|
||||||
const uint16_t size,
|
const uint16_t size,
|
||||||
uint8_t ptr_pos,
|
uint8_t ptr_pos,
|
||||||
uint8_t msg_type,
|
uint8_t msg_type,
|
||||||
|
|
@ -655,7 +656,7 @@ void LoRaMac::set_batterylevel_callback(mbed::Callback<uint8_t(void)> battery_le
|
||||||
_mac_commands.set_batterylevel_callback(battery_level);
|
_mac_commands.set_batterylevel_callback(battery_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoRaMac::on_radio_rx_done(const uint8_t* const payload, uint16_t size,
|
void LoRaMac::on_radio_rx_done(const uint8_t *const payload, uint16_t size,
|
||||||
int16_t rssi, int8_t snr)
|
int16_t rssi, int8_t snr)
|
||||||
{
|
{
|
||||||
// stop the RX1 timer here if its the first RX slot.
|
// stop the RX1 timer here if its the first RX slot.
|
||||||
|
|
@ -706,7 +707,7 @@ void LoRaMac::on_radio_rx_done(const uint8_t* const payload, uint16_t size,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoRaMac::on_radio_tx_timeout( void )
|
void LoRaMac::on_radio_tx_timeout(void)
|
||||||
{
|
{
|
||||||
_lora_time.stop(_params.timers.rx_window1_timer);
|
_lora_time.stop(_params.timers.rx_window1_timer);
|
||||||
_lora_time.stop(_params.timers.rx_window2_timer);
|
_lora_time.stop(_params.timers.rx_window2_timer);
|
||||||
|
|
@ -738,29 +739,33 @@ rx_slot_t LoRaMac::on_radio_rx_timeout(bool is_timeout)
|
||||||
|
|
||||||
if (_params.rx_slot == RX_SLOT_WIN_1) {
|
if (_params.rx_slot == RX_SLOT_WIN_1) {
|
||||||
if (_params.is_node_ack_requested == true) {
|
if (_params.is_node_ack_requested == true) {
|
||||||
_mcps_confirmation.status = is_timeout ? LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT
|
_mcps_confirmation.status = is_timeout ?
|
||||||
: LORAMAC_EVENT_INFO_STATUS_RX1_ERROR;
|
LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT :
|
||||||
|
LORAMAC_EVENT_INFO_STATUS_RX1_ERROR;
|
||||||
}
|
}
|
||||||
_mlme_confirmation.status = is_timeout ? LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT
|
_mlme_confirmation.status = is_timeout ?
|
||||||
: LORAMAC_EVENT_INFO_STATUS_RX1_ERROR;
|
LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT :
|
||||||
|
LORAMAC_EVENT_INFO_STATUS_RX1_ERROR;
|
||||||
|
|
||||||
if (_device_class != CLASS_C) {
|
if (_device_class != CLASS_C) {
|
||||||
if (_lora_time.get_elapsed_time(_params.timers.aggregated_last_tx_time ) >= _params.rx_window2_delay) {
|
if (_lora_time.get_elapsed_time(_params.timers.aggregated_last_tx_time) >= _params.rx_window2_delay) {
|
||||||
_lora_time.stop(_params.timers.rx_window2_timer);
|
_lora_time.stop(_params.timers.rx_window2_timer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (_params.is_node_ack_requested == true) {
|
if (_params.is_node_ack_requested == true) {
|
||||||
_mcps_confirmation.status = is_timeout ? LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT
|
_mcps_confirmation.status = is_timeout ?
|
||||||
: LORAMAC_EVENT_INFO_STATUS_RX2_ERROR;
|
LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT :
|
||||||
|
LORAMAC_EVENT_INFO_STATUS_RX2_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
_mlme_confirmation.status = is_timeout ? LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT
|
_mlme_confirmation.status = is_timeout ?
|
||||||
: LORAMAC_EVENT_INFO_STATUS_RX2_ERROR;
|
LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT :
|
||||||
|
LORAMAC_EVENT_INFO_STATUS_RX2_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_device_class == CLASS_C) {
|
if (_device_class == CLASS_C) {
|
||||||
open_rx2_window();
|
open_rx2_window();
|
||||||
}
|
}
|
||||||
|
|
||||||
return _params.rx_slot;
|
return _params.rx_slot;
|
||||||
|
|
@ -929,8 +934,7 @@ void LoRaMac::on_ack_timeout_timer_event(void)
|
||||||
if ((_params.ack_timeout_retry_counter % 2)
|
if ((_params.ack_timeout_retry_counter % 2)
|
||||||
&& (_params.sys_params.adr_on)) {
|
&& (_params.sys_params.adr_on)) {
|
||||||
tr_debug("Trading datarate for range");
|
tr_debug("Trading datarate for range");
|
||||||
_params.sys_params.channel_data_rate = _lora_phy.get_next_lower_tx_datarate(
|
_params.sys_params.channel_data_rate = _lora_phy.get_next_lower_tx_datarate(_params.sys_params.channel_data_rate);
|
||||||
_params.sys_params.channel_data_rate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_mcps_confirmation.nb_retries = _params.ack_timeout_retry_counter;
|
_mcps_confirmation.nb_retries = _params.ack_timeout_retry_counter;
|
||||||
|
|
@ -945,6 +949,7 @@ void LoRaMac::on_ack_timeout_timer_event(void)
|
||||||
_mac_commands.clear_command_buffer();
|
_mac_commands.clear_command_buffer();
|
||||||
_params.is_node_ack_requested = false;
|
_params.is_node_ack_requested = false;
|
||||||
_mcps_confirmation.ack_received = false;
|
_mcps_confirmation.ack_received = false;
|
||||||
|
_mcps_confirmation.nb_retries = _params.ack_timeout_retry_counter;
|
||||||
|
|
||||||
// now that is a critical failure
|
// now that is a critical failure
|
||||||
lorawan_status_t status = handle_retransmission();
|
lorawan_status_t status = handle_retransmission();
|
||||||
|
|
@ -969,7 +974,7 @@ bool LoRaMac::validate_payload_length(uint16_t length,
|
||||||
|
|
||||||
// Validation of the application payload size
|
// Validation of the application payload size
|
||||||
if ((payloadSize <= max_value) &&
|
if ((payloadSize <= max_value) &&
|
||||||
(payloadSize <= LORAMAC_PHY_MAXPAYLOAD)) {
|
(payloadSize <= LORAMAC_PHY_MAXPAYLOAD)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -978,7 +983,7 @@ bool LoRaMac::validate_payload_length(uint16_t length,
|
||||||
void LoRaMac::set_mlme_schedule_ul_indication(void)
|
void LoRaMac::set_mlme_schedule_ul_indication(void)
|
||||||
{
|
{
|
||||||
_mlme_indication.indication_type = MLME_SCHEDULE_UPLINK;
|
_mlme_indication.indication_type = MLME_SCHEDULE_UPLINK;
|
||||||
_mlme_indication.pending= true;
|
_mlme_indication.pending = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is not actual transmission. It just schedules a message in response
|
// This is not actual transmission. It just schedules a message in response
|
||||||
|
|
@ -1213,7 +1218,7 @@ void LoRaMac::reset_ongoing_tx(bool reset_pending)
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t LoRaMac::prepare_ongoing_tx(const uint8_t port,
|
int16_t LoRaMac::prepare_ongoing_tx(const uint8_t port,
|
||||||
const uint8_t* const data,
|
const uint8_t *const data,
|
||||||
uint16_t length,
|
uint16_t length,
|
||||||
uint8_t flags,
|
uint8_t flags,
|
||||||
uint8_t num_retries)
|
uint8_t num_retries)
|
||||||
|
|
@ -1306,7 +1311,7 @@ lorawan_status_t LoRaMac::send_ongoing_tx()
|
||||||
}
|
}
|
||||||
|
|
||||||
status = send(&machdr, _ongoing_tx_msg.fport, _ongoing_tx_msg.f_buffer,
|
status = send(&machdr, _ongoing_tx_msg.fport, _ongoing_tx_msg.f_buffer,
|
||||||
_ongoing_tx_msg.f_buffer_size);
|
_ongoing_tx_msg.f_buffer_size);
|
||||||
if (status == LORAWAN_STATUS_OK) {
|
if (status == LORAWAN_STATUS_OK) {
|
||||||
_mcps_confirmation.req_type = _ongoing_tx_msg.type;
|
_mcps_confirmation.req_type = _ongoing_tx_msg.type;
|
||||||
}
|
}
|
||||||
|
|
@ -1319,7 +1324,7 @@ device_class_t LoRaMac::get_device_class() const
|
||||||
return _device_class;
|
return _device_class;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoRaMac::set_device_class(const device_class_t& device_class,
|
void LoRaMac::set_device_class(const device_class_t &device_class,
|
||||||
mbed::Callback<void(void)>ack_expiry_handler)
|
mbed::Callback<void(void)>ack_expiry_handler)
|
||||||
{
|
{
|
||||||
_device_class = device_class;
|
_device_class = device_class;
|
||||||
|
|
@ -1331,12 +1336,12 @@ void LoRaMac::set_device_class(const device_class_t& device_class,
|
||||||
} else if (CLASS_C == _device_class) {
|
} else if (CLASS_C == _device_class) {
|
||||||
_params.is_node_ack_requested = false;
|
_params.is_node_ack_requested = false;
|
||||||
_lora_phy.put_radio_to_sleep();
|
_lora_phy.put_radio_to_sleep();
|
||||||
_lora_phy.compute_rx_win_params(
|
_lora_phy.compute_rx_win_params(_params.sys_params.rx2_channel.datarate,
|
||||||
_params.sys_params.rx2_channel.datarate,
|
_params.sys_params.min_rx_symb,
|
||||||
_params.sys_params.min_rx_symb,
|
_params.sys_params.max_sys_rx_error,
|
||||||
_params.sys_params.max_sys_rx_error,
|
&_params.rx_window2_config);
|
||||||
&_params.rx_window2_config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CLASS_C == _device_class) {
|
if (CLASS_C == _device_class) {
|
||||||
tr_debug("Changing device class to -> CLASS_C");
|
tr_debug("Changing device class to -> CLASS_C");
|
||||||
open_rx2_window();
|
open_rx2_window();
|
||||||
|
|
@ -1358,10 +1363,10 @@ lorawan_status_t LoRaMac::prepare_join(const lorawan_connect_t *params, bool is_
|
||||||
{
|
{
|
||||||
if (params) {
|
if (params) {
|
||||||
if (is_otaa) {
|
if (is_otaa) {
|
||||||
if ((params->connection_u.otaa.dev_eui == NULL) ||
|
if ((params->connection_u.otaa.dev_eui == NULL)
|
||||||
(params->connection_u.otaa.app_eui == NULL) ||
|
|| (params->connection_u.otaa.app_eui == NULL)
|
||||||
(params->connection_u.otaa.app_key == NULL) ||
|
|| (params->connection_u.otaa.app_key == NULL)
|
||||||
(params->connection_u.otaa.nb_trials == 0)) {
|
|| (params->connection_u.otaa.nb_trials == 0)) {
|
||||||
return LORAWAN_STATUS_PARAMETER_INVALID;
|
return LORAWAN_STATUS_PARAMETER_INVALID;
|
||||||
}
|
}
|
||||||
_params.keys.dev_eui = params->connection_u.otaa.dev_eui;
|
_params.keys.dev_eui = params->connection_u.otaa.dev_eui;
|
||||||
|
|
@ -1376,6 +1381,13 @@ lorawan_status_t LoRaMac::prepare_join(const lorawan_connect_t *params, bool is_
|
||||||
// Reset variable JoinRequestTrials
|
// Reset variable JoinRequestTrials
|
||||||
_params.join_request_trial_counter = 0;
|
_params.join_request_trial_counter = 0;
|
||||||
} else {
|
} else {
|
||||||
|
if ((params->connection_u.abp.dev_addr == 0)
|
||||||
|
|| (params->connection_u.abp.nwk_id == 0)
|
||||||
|
|| (params->connection_u.abp.nwk_skey == NULL)
|
||||||
|
|| (params->connection_u.abp.app_skey == NULL)) {
|
||||||
|
return LORAWAN_STATUS_PARAMETER_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
_params.net_id = params->connection_u.abp.nwk_id;
|
_params.net_id = params->connection_u.abp.nwk_id;
|
||||||
_params.dev_addr = params->connection_u.abp.dev_addr;
|
_params.dev_addr = params->connection_u.abp.dev_addr;
|
||||||
|
|
||||||
|
|
@ -1387,37 +1399,36 @@ lorawan_status_t LoRaMac::prepare_join(const lorawan_connect_t *params, bool is_
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#if MBED_CONF_LORA_OVER_THE_AIR_ACTIVATION
|
#if MBED_CONF_LORA_OVER_THE_AIR_ACTIVATION
|
||||||
const static uint8_t dev_eui[] = MBED_CONF_LORA_DEVICE_EUI;
|
const static uint8_t dev_eui[] = MBED_CONF_LORA_DEVICE_EUI;
|
||||||
const static uint8_t app_eui[] = MBED_CONF_LORA_APPLICATION_EUI;
|
const static uint8_t app_eui[] = MBED_CONF_LORA_APPLICATION_EUI;
|
||||||
const static uint8_t app_key[] = MBED_CONF_LORA_APPLICATION_KEY;
|
const static uint8_t app_key[] = MBED_CONF_LORA_APPLICATION_KEY;
|
||||||
|
|
||||||
_params.keys.app_eui = const_cast<uint8_t *>(app_eui);
|
_params.keys.app_eui = const_cast<uint8_t *>(app_eui);
|
||||||
_params.keys.dev_eui = const_cast<uint8_t *>(dev_eui);
|
_params.keys.dev_eui = const_cast<uint8_t *>(dev_eui);
|
||||||
_params.keys.app_key = const_cast<uint8_t *>(app_key);
|
_params.keys.app_key = const_cast<uint8_t *>(app_key);
|
||||||
_params.max_join_request_trials = MBED_CONF_LORA_NB_TRIALS;
|
_params.max_join_request_trials = MBED_CONF_LORA_NB_TRIALS;
|
||||||
|
|
||||||
// Reset variable JoinRequestTrials
|
// Reset variable JoinRequestTrials
|
||||||
_params.join_request_trial_counter = 0;
|
_params.join_request_trial_counter = 0;
|
||||||
|
|
||||||
reset_mac_parameters();
|
reset_mac_parameters();
|
||||||
|
|
||||||
_params.sys_params.channel_data_rate =
|
_params.sys_params.channel_data_rate =
|
||||||
_lora_phy.get_alternate_DR(_params.join_request_trial_counter + 1);
|
_lora_phy.get_alternate_DR(_params.join_request_trial_counter + 1);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
const static uint8_t nwk_skey[] = MBED_CONF_LORA_NWKSKEY;
|
const static uint8_t nwk_skey[] = MBED_CONF_LORA_NWKSKEY;
|
||||||
const static uint8_t app_skey[] = MBED_CONF_LORA_APPSKEY;
|
const static uint8_t app_skey[] = MBED_CONF_LORA_APPSKEY;
|
||||||
|
|
||||||
_params.net_id = (MBED_CONF_LORA_DEVICE_ADDRESS & LORAWAN_NETWORK_ID_MASK);
|
_params.net_id = (MBED_CONF_LORA_DEVICE_ADDRESS & LORAWAN_NETWORK_ID_MASK);
|
||||||
_params.dev_addr = MBED_CONF_LORA_DEVICE_ADDRESS;
|
_params.dev_addr = MBED_CONF_LORA_DEVICE_ADDRESS;
|
||||||
|
|
||||||
memcpy(_params.keys.nwk_skey, nwk_skey,
|
memcpy(_params.keys.nwk_skey, nwk_skey, sizeof(_params.keys.nwk_skey));
|
||||||
sizeof(_params.keys.nwk_skey));
|
|
||||||
|
|
||||||
memcpy(_params.keys.app_skey, app_skey,
|
memcpy(_params.keys.app_skey, app_skey, sizeof(_params.keys.app_skey));
|
||||||
sizeof(_params.keys.app_skey));
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return LORAWAN_STATUS_OK;
|
return LORAWAN_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1453,7 +1464,7 @@ lorawan_status_t LoRaMac::prepare_frame(loramac_mhdr_t *machdr,
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
uint8_t pkt_header_len = 0;
|
uint8_t pkt_header_len = 0;
|
||||||
uint32_t mic = 0;
|
uint32_t mic = 0;
|
||||||
const void* payload = fbuffer;
|
const void *payload = fbuffer;
|
||||||
uint8_t frame_port = fport;
|
uint8_t frame_port = fport;
|
||||||
lorawan_status_t status = LORAWAN_STATUS_OK;
|
lorawan_status_t status = LORAWAN_STATUS_OK;
|
||||||
|
|
||||||
|
|
@ -1502,7 +1513,7 @@ lorawan_status_t LoRaMac::prepare_frame(loramac_mhdr_t *machdr,
|
||||||
break;
|
break;
|
||||||
case FRAME_TYPE_DATA_CONFIRMED_UP:
|
case FRAME_TYPE_DATA_CONFIRMED_UP:
|
||||||
_params.is_node_ack_requested = true;
|
_params.is_node_ack_requested = true;
|
||||||
//Intentional fallthrough
|
//Intentional fallthrough
|
||||||
case FRAME_TYPE_DATA_UNCONFIRMED_UP: {
|
case FRAME_TYPE_DATA_UNCONFIRMED_UP: {
|
||||||
if (!_is_nwk_joined) {
|
if (!_is_nwk_joined) {
|
||||||
return LORAWAN_STATUS_NO_NETWORK_JOINED;
|
return LORAWAN_STATUS_NO_NETWORK_JOINED;
|
||||||
|
|
@ -1605,7 +1616,7 @@ lorawan_status_t LoRaMac::prepare_frame(loramac_mhdr_t *machdr,
|
||||||
break;
|
break;
|
||||||
case FRAME_TYPE_PROPRIETARY:
|
case FRAME_TYPE_PROPRIETARY:
|
||||||
if ((fbuffer != NULL) && (_params.tx_buffer_len > 0)) {
|
if ((fbuffer != NULL) && (_params.tx_buffer_len > 0)) {
|
||||||
memcpy(_params.tx_buffer + pkt_header_len, (uint8_t*) fbuffer,
|
memcpy(_params.tx_buffer + pkt_header_len, (uint8_t *) fbuffer,
|
||||||
_params.tx_buffer_len);
|
_params.tx_buffer_len);
|
||||||
_params.tx_buffer_len = pkt_header_len + _params.tx_buffer_len;
|
_params.tx_buffer_len = pkt_header_len + _params.tx_buffer_len;
|
||||||
}
|
}
|
||||||
|
|
@ -1654,19 +1665,19 @@ lorawan_status_t LoRaMac::send_frame_on_channel(uint8_t channel)
|
||||||
|
|
||||||
void LoRaMac::reset_mcps_confirmation()
|
void LoRaMac::reset_mcps_confirmation()
|
||||||
{
|
{
|
||||||
memset((uint8_t*) &_mcps_confirmation, 0, sizeof(_mcps_confirmation));
|
memset((uint8_t *) &_mcps_confirmation, 0, sizeof(_mcps_confirmation));
|
||||||
_mcps_confirmation.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
|
_mcps_confirmation.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoRaMac::reset_mlme_confirmation()
|
void LoRaMac::reset_mlme_confirmation()
|
||||||
{
|
{
|
||||||
memset((uint8_t*) &_mlme_confirmation, 0, sizeof(_mlme_confirmation));
|
memset((uint8_t *) &_mlme_confirmation, 0, sizeof(_mlme_confirmation));
|
||||||
_mlme_confirmation.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
|
_mlme_confirmation.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoRaMac::reset_mcps_indication()
|
void LoRaMac::reset_mcps_indication()
|
||||||
{
|
{
|
||||||
memset((uint8_t*) &_mcps_indication, 0, sizeof(_mcps_indication));
|
memset((uint8_t *) &_mcps_indication, 0, sizeof(_mcps_indication));
|
||||||
_mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
|
_mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1800,7 +1811,7 @@ void LoRaMac::set_nwk_joined(bool joined)
|
||||||
_is_nwk_joined = joined;
|
_is_nwk_joined = joined;
|
||||||
}
|
}
|
||||||
|
|
||||||
lorawan_status_t LoRaMac::add_channel_plan(const lorawan_channelplan_t& plan)
|
lorawan_status_t LoRaMac::add_channel_plan(const lorawan_channelplan_t &plan)
|
||||||
{
|
{
|
||||||
if (tx_ongoing()) {
|
if (tx_ongoing()) {
|
||||||
return LORAWAN_STATUS_BUSY;
|
return LORAWAN_STATUS_BUSY;
|
||||||
|
|
@ -1818,7 +1829,7 @@ lorawan_status_t LoRaMac::remove_channel_plan()
|
||||||
return _channel_plan.remove_plan();
|
return _channel_plan.remove_plan();
|
||||||
}
|
}
|
||||||
|
|
||||||
lorawan_status_t LoRaMac::get_channel_plan(lorawan_channelplan_t& plan)
|
lorawan_status_t LoRaMac::get_channel_plan(lorawan_channelplan_t &plan)
|
||||||
{
|
{
|
||||||
return _channel_plan.get_plan(plan, _lora_phy.get_phy_channels());
|
return _channel_plan.get_plan(plan, _lora_phy.get_phy_channels());
|
||||||
}
|
}
|
||||||
|
|
@ -1856,8 +1867,7 @@ lorawan_status_t LoRaMac::multicast_channel_link(multicast_params_t *channel_par
|
||||||
return LORAWAN_STATUS_OK;
|
return LORAWAN_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
lorawan_status_t LoRaMac::multicast_channel_unlink(
|
lorawan_status_t LoRaMac::multicast_channel_unlink(multicast_params_t *channel_param)
|
||||||
multicast_params_t *channel_param)
|
|
||||||
{
|
{
|
||||||
if (channel_param == NULL) {
|
if (channel_param == NULL) {
|
||||||
return LORAWAN_STATUS_PARAMETER_INVALID;
|
return LORAWAN_STATUS_PARAMETER_INVALID;
|
||||||
|
|
@ -1887,7 +1897,7 @@ lorawan_status_t LoRaMac::multicast_channel_unlink(
|
||||||
return LORAWAN_STATUS_OK;
|
return LORAWAN_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoRaMac::bind_radio_driver(LoRaRadio& radio)
|
void LoRaMac::bind_radio_driver(LoRaRadio &radio)
|
||||||
{
|
{
|
||||||
_lora_phy.set_radio_instance(radio);
|
_lora_phy.set_radio_instance(radio);
|
||||||
}
|
}
|
||||||
|
|
@ -1898,7 +1908,7 @@ void LoRaMac::bind_radio_driver(LoRaRadio& radio)
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
lorawan_status_t LoRaMac::mlme_request( loramac_mlme_req_t *mlmeRequest )
|
lorawan_status_t LoRaMac::mlme_request(loramac_mlme_req_t *mlmeRequest)
|
||||||
{
|
{
|
||||||
if (LORAMAC_IDLE != _params.mac_state) {
|
if (LORAMAC_IDLE != _params.mac_state) {
|
||||||
return LORAWAN_STATUS_BUSY;
|
return LORAWAN_STATUS_BUSY;
|
||||||
|
|
@ -1913,16 +1923,16 @@ lorawan_status_t LoRaMac::mlme_request( loramac_mlme_req_t *mlmeRequest )
|
||||||
|
|
||||||
if (MLME_TXCW == mlmeRequest->type) {
|
if (MLME_TXCW == mlmeRequest->type) {
|
||||||
set_tx_continuous_wave(_params.channel, _params.sys_params.channel_data_rate, _params.sys_params.channel_tx_power,
|
set_tx_continuous_wave(_params.channel, _params.sys_params.channel_data_rate, _params.sys_params.channel_tx_power,
|
||||||
_params.sys_params.max_eirp, _params.sys_params.antenna_gain, mlmeRequest->cw_tx_mode.timeout);
|
_params.sys_params.max_eirp, _params.sys_params.antenna_gain, mlmeRequest->cw_tx_mode.timeout);
|
||||||
_lora_time.start(_params.timers.mac_state_check_timer,
|
_lora_time.start(_params.timers.mac_state_check_timer,
|
||||||
MAC_STATE_CHECK_TIMEOUT);
|
MAC_STATE_CHECK_TIMEOUT);
|
||||||
|
|
||||||
_params.mac_state |= LORAMAC_TX_RUNNING;
|
_params.mac_state |= LORAMAC_TX_RUNNING;
|
||||||
status = LORAWAN_STATUS_OK;
|
status = LORAWAN_STATUS_OK;
|
||||||
} else if (MLME_TXCW_1 == mlmeRequest->type) {
|
} else if (MLME_TXCW_1 == mlmeRequest->type) {
|
||||||
set_tx_continuous_wave(0, 0, mlmeRequest->cw_tx_mode.power, 0, 0, mlmeRequest->cw_tx_mode.timeout);
|
set_tx_continuous_wave(0, 0, mlmeRequest->cw_tx_mode.power, 0, 0, mlmeRequest->cw_tx_mode.timeout);
|
||||||
_lora_time.start(_params.timers.mac_state_check_timer,
|
_lora_time.start(_params.timers.mac_state_check_timer,
|
||||||
MAC_STATE_CHECK_TIMEOUT);
|
MAC_STATE_CHECK_TIMEOUT);
|
||||||
|
|
||||||
_params.mac_state |= LORAMAC_TX_RUNNING;
|
_params.mac_state |= LORAMAC_TX_RUNNING;
|
||||||
status = LORAWAN_STATUS_OK;
|
status = LORAWAN_STATUS_OK;
|
||||||
|
|
@ -1933,7 +1943,6 @@ lorawan_status_t LoRaMac::mlme_request( loramac_mlme_req_t *mlmeRequest )
|
||||||
_params.flags.bits.mlme_req = 0;
|
_params.flags.bits.mlme_req = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1972,7 +1981,7 @@ lorawan_status_t LoRaMac::test_request( loramac_compliance_test_req_t *mcpsReque
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return LORAWAN_STATUS_PARAMETER_INVALID;
|
return LORAWAN_STATUS_PARAMETER_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter fPorts
|
// Filter fPorts
|
||||||
|
|
@ -1990,7 +1999,7 @@ lorawan_status_t LoRaMac::test_request( loramac_compliance_test_req_t *mcpsReque
|
||||||
}
|
}
|
||||||
|
|
||||||
lorawan_status_t status = send(&machdr, mcpsRequest->fport, mcpsRequest->f_buffer,
|
lorawan_status_t status = send(&machdr, mcpsRequest->fport, mcpsRequest->f_buffer,
|
||||||
mcpsRequest->f_buffer_size);
|
mcpsRequest->f_buffer_size);
|
||||||
if (status == LORAWAN_STATUS_OK) {
|
if (status == LORAWAN_STATUS_OK) {
|
||||||
_mcps_confirmation.req_type = mcpsRequest->type;
|
_mcps_confirmation.req_type = mcpsRequest->type;
|
||||||
_params.flags.bits.mcps_req = 1;
|
_params.flags.bits.mcps_req = 1;
|
||||||
|
|
@ -2007,7 +2016,7 @@ lorawan_status_t LoRaMac::LoRaMacSetTxTimer( uint32_t TxDutyCycleTime )
|
||||||
return LORAWAN_STATUS_OK;
|
return LORAWAN_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
lorawan_status_t LoRaMac::LoRaMacStopTxTimer( )
|
lorawan_status_t LoRaMac::LoRaMacStopTxTimer( )
|
||||||
{
|
{
|
||||||
_lora_time.stop(tx_next_packet_timer);
|
_lora_time.stop(tx_next_packet_timer);
|
||||||
return LORAWAN_STATUS_OK;
|
return LORAWAN_STATUS_OK;
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ public:
|
||||||
* \ref LORAWAN_STATUS_BUSY
|
* \ref LORAWAN_STATUS_BUSY
|
||||||
* \ref LORAWAN_STATUS_PARAMETER_INVALID
|
* \ref LORAWAN_STATUS_PARAMETER_INVALID
|
||||||
*/
|
*/
|
||||||
lorawan_status_t add_channel_plan(const lorawan_channelplan_t& plan);
|
lorawan_status_t add_channel_plan(const lorawan_channelplan_t &plan);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Removes a channel plan from the system.
|
* @brief Removes a channel plan from the system.
|
||||||
|
|
@ -166,7 +166,7 @@ public:
|
||||||
* \ref LORAWAN_STATUS_BUSY
|
* \ref LORAWAN_STATUS_BUSY
|
||||||
* \ref LORAWAN_STATUS_PARAMETER_INVALID
|
* \ref LORAWAN_STATUS_PARAMETER_INVALID
|
||||||
*/
|
*/
|
||||||
lorawan_status_t get_channel_plan(lorawan_channelplan_t& plan);
|
lorawan_status_t get_channel_plan(lorawan_channelplan_t &plan);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Remove a given channel from the active plan.
|
* @brief Remove a given channel from the active plan.
|
||||||
|
|
@ -221,7 +221,7 @@ public:
|
||||||
* @param radio LoRaRadio object, i.e., the radio driver
|
* @param radio LoRaRadio object, i.e., the radio driver
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void bind_radio_driver(LoRaRadio& radio);
|
void bind_radio_driver(LoRaRadio &radio);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Configures the events to trigger an MLME-Indication with
|
* @brief Configures the events to trigger an MLME-Indication with
|
||||||
|
|
@ -333,7 +333,7 @@ public:
|
||||||
* @param num_retries Number of retries for a confirmed type message
|
* @param num_retries Number of retries for a confirmed type message
|
||||||
* @return The number of bytes prepared for sending.
|
* @return The number of bytes prepared for sending.
|
||||||
*/
|
*/
|
||||||
int16_t prepare_ongoing_tx(const uint8_t port, const uint8_t* data,
|
int16_t prepare_ongoing_tx(const uint8_t port, const uint8_t *data,
|
||||||
uint16_t length, uint8_t flags, uint8_t num_retries);
|
uint16_t length, uint8_t flags, uint8_t num_retries);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -353,7 +353,7 @@ public:
|
||||||
* @param device_class Device class to use.
|
* @param device_class Device class to use.
|
||||||
* @param ack_expiry_handler callback function to inform about ack expiry
|
* @param ack_expiry_handler callback function to inform about ack expiry
|
||||||
*/
|
*/
|
||||||
void set_device_class(const device_class_t& device_class,
|
void set_device_class(const device_class_t &device_class,
|
||||||
mbed::Callback<void(void)>ack_expiry_handler);
|
mbed::Callback<void(void)>ack_expiry_handler);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -391,7 +391,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* MAC operations upon reception
|
* MAC operations upon reception
|
||||||
*/
|
*/
|
||||||
void on_radio_rx_done(const uint8_t* const payload, uint16_t size,
|
void on_radio_rx_done(const uint8_t *const payload, uint16_t size,
|
||||||
int16_t rssi, int8_t snr);
|
int16_t rssi, int8_t snr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -460,8 +460,16 @@ public:
|
||||||
* the stack thread safe.
|
* the stack thread safe.
|
||||||
*/
|
*/
|
||||||
#if MBED_CONF_RTOS_PRESENT
|
#if MBED_CONF_RTOS_PRESENT
|
||||||
void lock(void) { osStatus status = _mutex.lock(); MBED_ASSERT(status == osOK); }
|
void lock(void)
|
||||||
void unlock(void) { osStatus status = _mutex.unlock(); MBED_ASSERT(status == osOK); }
|
{
|
||||||
|
osStatus status = _mutex.lock();
|
||||||
|
MBED_ASSERT(status == osOK);
|
||||||
|
}
|
||||||
|
void unlock(void)
|
||||||
|
{
|
||||||
|
osStatus status = _mutex.unlock();
|
||||||
|
MBED_ASSERT(status == osOK);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
void lock(void) { }
|
void lock(void) { }
|
||||||
void unlock(void) { }
|
void unlock(void) { }
|
||||||
|
|
@ -511,10 +519,10 @@ private:
|
||||||
* payload
|
* payload
|
||||||
*/
|
*/
|
||||||
void extract_data_and_mac_commands(const uint8_t *payload, uint16_t size,
|
void extract_data_and_mac_commands(const uint8_t *payload, uint16_t size,
|
||||||
uint8_t fopts_len, uint8_t *nwk_skey,
|
uint8_t fopts_len, uint8_t *nwk_skey,
|
||||||
uint8_t *app_skey, uint32_t address,
|
uint8_t *app_skey, uint32_t address,
|
||||||
uint32_t downlink_frame_counter,
|
uint32_t downlink_frame_counter,
|
||||||
int16_t rssi, int8_t snr);
|
int16_t rssi, int8_t snr);
|
||||||
/**
|
/**
|
||||||
* Decrypts and extracts MAC commands from the received encrypted
|
* Decrypts and extracts MAC commands from the received encrypted
|
||||||
* payload if there is no data
|
* payload if there is no data
|
||||||
|
|
|
||||||
|
|
@ -65,261 +65,6 @@
|
||||||
*/
|
*/
|
||||||
#define LC( channelIndex ) ( uint16_t )( 1 << ( channelIndex - 1 ) )
|
#define LC( channelIndex ) ( uint16_t )( 1 << ( channelIndex - 1 ) )
|
||||||
|
|
||||||
/*!
|
|
||||||
* Region | SF
|
|
||||||
* ------------ | :-----:
|
|
||||||
* AS923 | SF12 - BW125
|
|
||||||
* AU915 | SF10 - BW125
|
|
||||||
* CN470 | SF12 - BW125
|
|
||||||
* CN779 | SF12 - BW125
|
|
||||||
* EU433 | SF12 - BW125
|
|
||||||
* EU868 | SF12 - BW125
|
|
||||||
* IN865 | SF12 - BW125
|
|
||||||
* KR920 | SF12 - BW125
|
|
||||||
* US915 | SF10 - BW125
|
|
||||||
* US915_HYBRID | SF10 - BW125
|
|
||||||
*/
|
|
||||||
#define DR_0 0
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Region | SF
|
|
||||||
* ------------ | :-----:
|
|
||||||
* AS923 | SF11 - BW125
|
|
||||||
* AU915 | SF9 - BW125
|
|
||||||
* CN470 | SF11 - BW125
|
|
||||||
* CN779 | SF11 - BW125
|
|
||||||
* EU433 | SF11 - BW125
|
|
||||||
* EU868 | SF11 - BW125
|
|
||||||
* IN865 | SF11 - BW125
|
|
||||||
* KR920 | SF11 - BW125
|
|
||||||
* US915 | SF9 - BW125
|
|
||||||
* US915_HYBRID | SF9 - BW125
|
|
||||||
*/
|
|
||||||
#define DR_1 1
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Region | SF
|
|
||||||
* ------------ | :-----:
|
|
||||||
* AS923 | SF10 - BW125
|
|
||||||
* AU915 | SF8 - BW125
|
|
||||||
* CN470 | SF10 - BW125
|
|
||||||
* CN779 | SF10 - BW125
|
|
||||||
* EU433 | SF10 - BW125
|
|
||||||
* EU868 | SF10 - BW125
|
|
||||||
* IN865 | SF10 - BW125
|
|
||||||
* KR920 | SF10 - BW125
|
|
||||||
* US915 | SF8 - BW125
|
|
||||||
* US915_HYBRID | SF8 - BW125
|
|
||||||
*/
|
|
||||||
#define DR_2 2
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Region | SF
|
|
||||||
* ------------ | :-----:
|
|
||||||
* AS923 | SF9 - BW125
|
|
||||||
* AU915 | SF7 - BW125
|
|
||||||
* CN470 | SF9 - BW125
|
|
||||||
* CN779 | SF9 - BW125
|
|
||||||
* EU433 | SF9 - BW125
|
|
||||||
* EU868 | SF9 - BW125
|
|
||||||
* IN865 | SF9 - BW125
|
|
||||||
* KR920 | SF9 - BW125
|
|
||||||
* US915 | SF7 - BW125
|
|
||||||
* US915_HYBRID | SF7 - BW125
|
|
||||||
*/
|
|
||||||
#define DR_3 3
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Region | SF
|
|
||||||
* ------------ | :-----:
|
|
||||||
* AS923 | SF8 - BW125
|
|
||||||
* AU915 | SF8 - BW500
|
|
||||||
* CN470 | SF8 - BW125
|
|
||||||
* CN779 | SF8 - BW125
|
|
||||||
* EU433 | SF8 - BW125
|
|
||||||
* EU868 | SF8 - BW125
|
|
||||||
* IN865 | SF8 - BW125
|
|
||||||
* KR920 | SF8 - BW125
|
|
||||||
* US915 | SF8 - BW500
|
|
||||||
* US915_HYBRID | SF8 - BW500
|
|
||||||
*/
|
|
||||||
#define DR_4 4
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Region | SF
|
|
||||||
* ------------ | :-----:
|
|
||||||
* AS923 | SF7 - BW125
|
|
||||||
* AU915 | RFU
|
|
||||||
* CN470 | SF7 - BW125
|
|
||||||
* CN779 | SF7 - BW125
|
|
||||||
* EU433 | SF7 - BW125
|
|
||||||
* EU868 | SF7 - BW125
|
|
||||||
* IN865 | SF7 - BW125
|
|
||||||
* KR920 | SF7 - BW125
|
|
||||||
* US915 | RFU
|
|
||||||
* US915_HYBRID | RFU
|
|
||||||
*/
|
|
||||||
#define DR_5 5
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Region | SF
|
|
||||||
* ------------ | :-----:
|
|
||||||
* AS923 | SF7 - BW250
|
|
||||||
* AU915 | RFU
|
|
||||||
* CN470 | SF12 - BW125
|
|
||||||
* CN779 | SF7 - BW250
|
|
||||||
* EU433 | SF7 - BW250
|
|
||||||
* EU868 | SF7 - BW250
|
|
||||||
* IN865 | SF7 - BW250
|
|
||||||
* KR920 | RFU
|
|
||||||
* US915 | RFU
|
|
||||||
* US915_HYBRID | RFU
|
|
||||||
*/
|
|
||||||
#define DR_6 6
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Region | SF
|
|
||||||
* ------------ | :-----:
|
|
||||||
* AS923 | FSK
|
|
||||||
* AU915 | RFU
|
|
||||||
* CN470 | SF12 - BW125
|
|
||||||
* CN779 | FSK
|
|
||||||
* EU433 | FSK
|
|
||||||
* EU868 | FSK
|
|
||||||
* IN865 | FSK
|
|
||||||
* KR920 | RFU
|
|
||||||
* US915 | RFU
|
|
||||||
* US915_HYBRID | RFU
|
|
||||||
*/
|
|
||||||
#define DR_7 7
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Region | SF
|
|
||||||
* ------------ | :-----:
|
|
||||||
* AS923 | RFU
|
|
||||||
* AU915 | SF12 - BW500
|
|
||||||
* CN470 | RFU
|
|
||||||
* CN779 | RFU
|
|
||||||
* EU433 | RFU
|
|
||||||
* EU868 | RFU
|
|
||||||
* IN865 | RFU
|
|
||||||
* KR920 | RFU
|
|
||||||
* US915 | SF12 - BW500
|
|
||||||
* US915_HYBRID | SF12 - BW500
|
|
||||||
*/
|
|
||||||
#define DR_8 8
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Region | SF
|
|
||||||
* ------------ | :-----:
|
|
||||||
* AS923 | RFU
|
|
||||||
* AU915 | SF11 - BW500
|
|
||||||
* CN470 | RFU
|
|
||||||
* CN779 | RFU
|
|
||||||
* EU433 | RFU
|
|
||||||
* EU868 | RFU
|
|
||||||
* IN865 | RFU
|
|
||||||
* KR920 | RFU
|
|
||||||
* US915 | SF11 - BW500
|
|
||||||
* US915_HYBRID | SF11 - BW500
|
|
||||||
*/
|
|
||||||
#define DR_9 9
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Region | SF
|
|
||||||
* ------------ | :-----:
|
|
||||||
* AS923 | RFU
|
|
||||||
* AU915 | SF10 - BW500
|
|
||||||
* CN470 | RFU
|
|
||||||
* CN779 | RFU
|
|
||||||
* EU433 | RFU
|
|
||||||
* EU868 | RFU
|
|
||||||
* IN865 | RFU
|
|
||||||
* KR920 | RFU
|
|
||||||
* US915 | SF10 - BW500
|
|
||||||
* US915_HYBRID | SF10 - BW500
|
|
||||||
*/
|
|
||||||
#define DR_10 10
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Region | SF
|
|
||||||
* ------------ | :-----:
|
|
||||||
* AS923 | RFU
|
|
||||||
* AU915 | SF9 - BW500
|
|
||||||
* CN470 | RFU
|
|
||||||
* CN779 | RFU
|
|
||||||
* EU433 | RFU
|
|
||||||
* EU868 | RFU
|
|
||||||
* IN865 | RFU
|
|
||||||
* KR920 | RFU
|
|
||||||
* US915 | SF9 - BW500
|
|
||||||
* US915_HYBRID | SF9 - BW500
|
|
||||||
*/
|
|
||||||
#define DR_11 11
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Region | SF
|
|
||||||
* ------------ | :-----:
|
|
||||||
* AS923 | RFU
|
|
||||||
* AU915 | SF8 - BW500
|
|
||||||
* CN470 | RFU
|
|
||||||
* CN779 | RFU
|
|
||||||
* EU433 | RFU
|
|
||||||
* EU868 | RFU
|
|
||||||
* IN865 | RFU
|
|
||||||
* KR920 | RFU
|
|
||||||
* US915 | SF8 - BW500
|
|
||||||
* US915_HYBRID | SF8 - BW500
|
|
||||||
*/
|
|
||||||
#define DR_12 12
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Region | SF
|
|
||||||
* ------------ | :-----:
|
|
||||||
* AS923 | RFU
|
|
||||||
* AU915 | SF7 - BW500
|
|
||||||
* CN470 | RFU
|
|
||||||
* CN779 | RFU
|
|
||||||
* EU433 | RFU
|
|
||||||
* EU868 | RFU
|
|
||||||
* IN865 | RFU
|
|
||||||
* KR920 | RFU
|
|
||||||
* US915 | SF7 - BW500
|
|
||||||
* US915_HYBRID | SF7 - BW500
|
|
||||||
*/
|
|
||||||
#define DR_13 13
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Region | SF
|
|
||||||
* ------------ | :-----:
|
|
||||||
* AS923 | RFU
|
|
||||||
* AU915 | RFU
|
|
||||||
* CN470 | RFU
|
|
||||||
* CN779 | RFU
|
|
||||||
* EU433 | RFU
|
|
||||||
* EU868 | RFU
|
|
||||||
* IN865 | RFU
|
|
||||||
* KR920 | RFU
|
|
||||||
* US915 | RFU
|
|
||||||
* US915_HYBRID | RFU
|
|
||||||
*/
|
|
||||||
#define DR_14 14
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Region | SF
|
|
||||||
* ------------ | :-----:
|
|
||||||
* AS923 | RFU
|
|
||||||
* AU915 | RFU
|
|
||||||
* CN470 | RFU
|
|
||||||
* CN779 | RFU
|
|
||||||
* EU433 | RFU
|
|
||||||
* EU868 | RFU
|
|
||||||
* IN865 | RFU
|
|
||||||
* KR920 | RFU
|
|
||||||
* US915 | RFU
|
|
||||||
* US915_HYBRID | RFU
|
|
||||||
*/
|
|
||||||
#define DR_15 15
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -527,8 +272,7 @@
|
||||||
/**
|
/**
|
||||||
* TX configuration parameters.
|
* TX configuration parameters.
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* The TX channel.
|
* The TX channel.
|
||||||
*/
|
*/
|
||||||
|
|
@ -559,8 +303,7 @@ typedef struct
|
||||||
* This structure contains parameters for ADR request coming from
|
* This structure contains parameters for ADR request coming from
|
||||||
* network server.
|
* network server.
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
/*!
|
/*!
|
||||||
* A pointer to the payload containing the MAC commands.
|
* A pointer to the payload containing the MAC commands.
|
||||||
*/
|
*/
|
||||||
|
|
@ -594,8 +337,7 @@ typedef struct
|
||||||
/**
|
/**
|
||||||
* Structure containing data for local ADR settings
|
* Structure containing data for local ADR settings
|
||||||
*/
|
*/
|
||||||
typedef struct link_adr_params_s
|
typedef struct link_adr_params_s {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* The number of repetitions.
|
* The number of repetitions.
|
||||||
*/
|
*/
|
||||||
|
|
@ -622,8 +364,7 @@ typedef struct link_adr_params_s
|
||||||
* Structure used to store ADR values received from network
|
* Structure used to store ADR values received from network
|
||||||
* for verification (legality) purposes.
|
* for verification (legality) purposes.
|
||||||
*/
|
*/
|
||||||
typedef struct verify_adr_params_s
|
typedef struct verify_adr_params_s {
|
||||||
{
|
|
||||||
/*!
|
/*!
|
||||||
* The current status of the AdrLinkRequest.
|
* The current status of the AdrLinkRequest.
|
||||||
*/
|
*/
|
||||||
|
|
@ -667,8 +408,7 @@ typedef struct verify_adr_params_s
|
||||||
* Contains rx parameter setup request coming from
|
* Contains rx parameter setup request coming from
|
||||||
* network server.
|
* network server.
|
||||||
*/
|
*/
|
||||||
typedef struct rx_param_setup_req_s
|
typedef struct rx_param_setup_req_s {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* The datarate to set up.
|
* The datarate to set up.
|
||||||
*/
|
*/
|
||||||
|
|
@ -686,8 +426,7 @@ typedef struct rx_param_setup_req_s
|
||||||
/**
|
/**
|
||||||
* The parameter structure for the function RegionNextChannel.
|
* The parameter structure for the function RegionNextChannel.
|
||||||
*/
|
*/
|
||||||
typedef struct channel_selection_params_s
|
typedef struct channel_selection_params_s {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* The aggregated time-off time.
|
* The aggregated time-off time.
|
||||||
*/
|
*/
|
||||||
|
|
@ -713,8 +452,7 @@ typedef struct channel_selection_params_s
|
||||||
/*!
|
/*!
|
||||||
* The parameter structure for the function RegionContinuousWave.
|
* The parameter structure for the function RegionContinuousWave.
|
||||||
*/
|
*/
|
||||||
typedef struct continuous_wave_mode_params_s
|
typedef struct continuous_wave_mode_params_s {
|
||||||
{
|
|
||||||
/*!
|
/*!
|
||||||
* The current channel index.
|
* The current channel index.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,7 @@ typedef struct lorawan_connect {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef enum lora_events {
|
typedef enum lora_events {
|
||||||
CONNECTED=0,
|
CONNECTED = 0,
|
||||||
DISCONNECTED,
|
DISCONNECTED,
|
||||||
TX_DONE,
|
TX_DONE,
|
||||||
TX_TIMEOUT,
|
TX_TIMEOUT,
|
||||||
|
|
@ -244,26 +244,26 @@ typedef enum lora_events {
|
||||||
* the stack about the battery level by calling a function provided
|
* the stack about the battery level by calling a function provided
|
||||||
* by the upper layers.
|
* by the upper layers.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/**
|
/**
|
||||||
* Mandatory. Event Callback must be provided
|
* Mandatory. Event Callback must be provided
|
||||||
*/
|
*/
|
||||||
mbed::Callback<void(lorawan_event_t)> events;
|
mbed::Callback<void(lorawan_event_t)> events;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional
|
* Optional
|
||||||
*/
|
*/
|
||||||
mbed::Callback<void(uint8_t, uint8_t)> link_check_resp;
|
mbed::Callback<void(uint8_t, uint8_t)> link_check_resp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Battery level return value must follow the specification
|
* Battery level return value must follow the specification
|
||||||
* for DevStatusAns MAC command:
|
* for DevStatusAns MAC command:
|
||||||
*
|
*
|
||||||
* 0 The end-device is connected to an external power source
|
* 0 The end-device is connected to an external power source
|
||||||
* 1 - 254 The battery level, 1 being at minimum and 254 being at maximum
|
* 1 - 254 The battery level, 1 being at minimum and 254 being at maximum
|
||||||
* 255 The end-device was not able to measure the battery level.
|
* 255 The end-device was not able to measure the battery level.
|
||||||
*/
|
*/
|
||||||
mbed::Callback<uint8_t(void)> battery_level;
|
mbed::Callback<uint8_t(void)> battery_level;
|
||||||
} lorawan_app_callbacks_t;
|
} lorawan_app_callbacks_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -275,7 +275,7 @@ typedef union {
|
||||||
/**
|
/**
|
||||||
* Byte-access to the bits.
|
* Byte-access to the bits.
|
||||||
*/
|
*/
|
||||||
int8_t value;
|
uint8_t value;
|
||||||
/**
|
/**
|
||||||
* The structure to store the minimum and the maximum datarate.
|
* The structure to store the minimum and the maximum datarate.
|
||||||
*/
|
*/
|
||||||
|
|
@ -288,7 +288,7 @@ typedef union {
|
||||||
* The allowed ranges are region-specific.
|
* The allowed ranges are region-specific.
|
||||||
* Please refer to \ref DR_0 to \ref DR_15 for details.
|
* Please refer to \ref DR_0 to \ref DR_15 for details.
|
||||||
*/
|
*/
|
||||||
int8_t min :4;
|
uint8_t min : 4;
|
||||||
/**
|
/**
|
||||||
* The maximum data rate.
|
* The maximum data rate.
|
||||||
*
|
*
|
||||||
|
|
@ -297,7 +297,7 @@ typedef union {
|
||||||
* The allowed ranges are region-specific.
|
* The allowed ranges are region-specific.
|
||||||
* Please refer to \ref DR_0 to \ref DR_15 for details.
|
* Please refer to \ref DR_0 to \ref DR_15 for details.
|
||||||
*/
|
*/
|
||||||
int8_t max :4;
|
uint8_t max : 4;
|
||||||
} fields;
|
} fields;
|
||||||
} dr_range_t;
|
} dr_range_t;
|
||||||
|
|
||||||
|
|
@ -346,6 +346,271 @@ typedef struct lora_channelplan {
|
||||||
loramac_channel_t *channels;
|
loramac_channel_t *channels;
|
||||||
} lorawan_channelplan_t;
|
} lorawan_channelplan_t;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Region | SF
|
||||||
|
* ------------ | :-----:
|
||||||
|
* AS923 | SF12 - BW125
|
||||||
|
* AU915 | SF10 - BW125
|
||||||
|
* CN470 | SF12 - BW125
|
||||||
|
* CN779 | SF12 - BW125
|
||||||
|
* EU433 | SF12 - BW125
|
||||||
|
* EU868 | SF12 - BW125
|
||||||
|
* IN865 | SF12 - BW125
|
||||||
|
* KR920 | SF12 - BW125
|
||||||
|
* US915 | SF10 - BW125
|
||||||
|
* US915_HYBRID | SF10 - BW125
|
||||||
|
*/
|
||||||
|
#define DR_0 0
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Region | SF
|
||||||
|
* ------------ | :-----:
|
||||||
|
* AS923 | SF11 - BW125
|
||||||
|
* AU915 | SF9 - BW125
|
||||||
|
* CN470 | SF11 - BW125
|
||||||
|
* CN779 | SF11 - BW125
|
||||||
|
* EU433 | SF11 - BW125
|
||||||
|
* EU868 | SF11 - BW125
|
||||||
|
* IN865 | SF11 - BW125
|
||||||
|
* KR920 | SF11 - BW125
|
||||||
|
* US915 | SF9 - BW125
|
||||||
|
* US915_HYBRID | SF9 - BW125
|
||||||
|
*/
|
||||||
|
#define DR_1 1
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Region | SF
|
||||||
|
* ------------ | :-----:
|
||||||
|
* AS923 | SF10 - BW125
|
||||||
|
* AU915 | SF8 - BW125
|
||||||
|
* CN470 | SF10 - BW125
|
||||||
|
* CN779 | SF10 - BW125
|
||||||
|
* EU433 | SF10 - BW125
|
||||||
|
* EU868 | SF10 - BW125
|
||||||
|
* IN865 | SF10 - BW125
|
||||||
|
* KR920 | SF10 - BW125
|
||||||
|
* US915 | SF8 - BW125
|
||||||
|
* US915_HYBRID | SF8 - BW125
|
||||||
|
*/
|
||||||
|
#define DR_2 2
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Region | SF
|
||||||
|
* ------------ | :-----:
|
||||||
|
* AS923 | SF9 - BW125
|
||||||
|
* AU915 | SF7 - BW125
|
||||||
|
* CN470 | SF9 - BW125
|
||||||
|
* CN779 | SF9 - BW125
|
||||||
|
* EU433 | SF9 - BW125
|
||||||
|
* EU868 | SF9 - BW125
|
||||||
|
* IN865 | SF9 - BW125
|
||||||
|
* KR920 | SF9 - BW125
|
||||||
|
* US915 | SF7 - BW125
|
||||||
|
* US915_HYBRID | SF7 - BW125
|
||||||
|
*/
|
||||||
|
#define DR_3 3
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Region | SF
|
||||||
|
* ------------ | :-----:
|
||||||
|
* AS923 | SF8 - BW125
|
||||||
|
* AU915 | SF8 - BW500
|
||||||
|
* CN470 | SF8 - BW125
|
||||||
|
* CN779 | SF8 - BW125
|
||||||
|
* EU433 | SF8 - BW125
|
||||||
|
* EU868 | SF8 - BW125
|
||||||
|
* IN865 | SF8 - BW125
|
||||||
|
* KR920 | SF8 - BW125
|
||||||
|
* US915 | SF8 - BW500
|
||||||
|
* US915_HYBRID | SF8 - BW500
|
||||||
|
*/
|
||||||
|
#define DR_4 4
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Region | SF
|
||||||
|
* ------------ | :-----:
|
||||||
|
* AS923 | SF7 - BW125
|
||||||
|
* AU915 | RFU
|
||||||
|
* CN470 | SF7 - BW125
|
||||||
|
* CN779 | SF7 - BW125
|
||||||
|
* EU433 | SF7 - BW125
|
||||||
|
* EU868 | SF7 - BW125
|
||||||
|
* IN865 | SF7 - BW125
|
||||||
|
* KR920 | SF7 - BW125
|
||||||
|
* US915 | RFU
|
||||||
|
* US915_HYBRID | RFU
|
||||||
|
*/
|
||||||
|
#define DR_5 5
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Region | SF
|
||||||
|
* ------------ | :-----:
|
||||||
|
* AS923 | SF7 - BW250
|
||||||
|
* AU915 | RFU
|
||||||
|
* CN470 | SF12 - BW125
|
||||||
|
* CN779 | SF7 - BW250
|
||||||
|
* EU433 | SF7 - BW250
|
||||||
|
* EU868 | SF7 - BW250
|
||||||
|
* IN865 | SF7 - BW250
|
||||||
|
* KR920 | RFU
|
||||||
|
* US915 | RFU
|
||||||
|
* US915_HYBRID | RFU
|
||||||
|
*/
|
||||||
|
#define DR_6 6
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Region | SF
|
||||||
|
* ------------ | :-----:
|
||||||
|
* AS923 | FSK
|
||||||
|
* AU915 | RFU
|
||||||
|
* CN470 | SF12 - BW125
|
||||||
|
* CN779 | FSK
|
||||||
|
* EU433 | FSK
|
||||||
|
* EU868 | FSK
|
||||||
|
* IN865 | FSK
|
||||||
|
* KR920 | RFU
|
||||||
|
* US915 | RFU
|
||||||
|
* US915_HYBRID | RFU
|
||||||
|
*/
|
||||||
|
#define DR_7 7
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Region | SF
|
||||||
|
* ------------ | :-----:
|
||||||
|
* AS923 | RFU
|
||||||
|
* AU915 | SF12 - BW500
|
||||||
|
* CN470 | RFU
|
||||||
|
* CN779 | RFU
|
||||||
|
* EU433 | RFU
|
||||||
|
* EU868 | RFU
|
||||||
|
* IN865 | RFU
|
||||||
|
* KR920 | RFU
|
||||||
|
* US915 | SF12 - BW500
|
||||||
|
* US915_HYBRID | SF12 - BW500
|
||||||
|
*/
|
||||||
|
#define DR_8 8
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Region | SF
|
||||||
|
* ------------ | :-----:
|
||||||
|
* AS923 | RFU
|
||||||
|
* AU915 | SF11 - BW500
|
||||||
|
* CN470 | RFU
|
||||||
|
* CN779 | RFU
|
||||||
|
* EU433 | RFU
|
||||||
|
* EU868 | RFU
|
||||||
|
* IN865 | RFU
|
||||||
|
* KR920 | RFU
|
||||||
|
* US915 | SF11 - BW500
|
||||||
|
* US915_HYBRID | SF11 - BW500
|
||||||
|
*/
|
||||||
|
#define DR_9 9
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Region | SF
|
||||||
|
* ------------ | :-----:
|
||||||
|
* AS923 | RFU
|
||||||
|
* AU915 | SF10 - BW500
|
||||||
|
* CN470 | RFU
|
||||||
|
* CN779 | RFU
|
||||||
|
* EU433 | RFU
|
||||||
|
* EU868 | RFU
|
||||||
|
* IN865 | RFU
|
||||||
|
* KR920 | RFU
|
||||||
|
* US915 | SF10 - BW500
|
||||||
|
* US915_HYBRID | SF10 - BW500
|
||||||
|
*/
|
||||||
|
#define DR_10 10
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Region | SF
|
||||||
|
* ------------ | :-----:
|
||||||
|
* AS923 | RFU
|
||||||
|
* AU915 | SF9 - BW500
|
||||||
|
* CN470 | RFU
|
||||||
|
* CN779 | RFU
|
||||||
|
* EU433 | RFU
|
||||||
|
* EU868 | RFU
|
||||||
|
* IN865 | RFU
|
||||||
|
* KR920 | RFU
|
||||||
|
* US915 | SF9 - BW500
|
||||||
|
* US915_HYBRID | SF9 - BW500
|
||||||
|
*/
|
||||||
|
#define DR_11 11
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Region | SF
|
||||||
|
* ------------ | :-----:
|
||||||
|
* AS923 | RFU
|
||||||
|
* AU915 | SF8 - BW500
|
||||||
|
* CN470 | RFU
|
||||||
|
* CN779 | RFU
|
||||||
|
* EU433 | RFU
|
||||||
|
* EU868 | RFU
|
||||||
|
* IN865 | RFU
|
||||||
|
* KR920 | RFU
|
||||||
|
* US915 | SF8 - BW500
|
||||||
|
* US915_HYBRID | SF8 - BW500
|
||||||
|
*/
|
||||||
|
#define DR_12 12
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Region | SF
|
||||||
|
* ------------ | :-----:
|
||||||
|
* AS923 | RFU
|
||||||
|
* AU915 | SF7 - BW500
|
||||||
|
* CN470 | RFU
|
||||||
|
* CN779 | RFU
|
||||||
|
* EU433 | RFU
|
||||||
|
* EU868 | RFU
|
||||||
|
* IN865 | RFU
|
||||||
|
* KR920 | RFU
|
||||||
|
* US915 | SF7 - BW500
|
||||||
|
* US915_HYBRID | SF7 - BW500
|
||||||
|
*/
|
||||||
|
#define DR_13 13
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Region | SF
|
||||||
|
* ------------ | :-----:
|
||||||
|
* AS923 | RFU
|
||||||
|
* AU915 | RFU
|
||||||
|
* CN470 | RFU
|
||||||
|
* CN779 | RFU
|
||||||
|
* EU433 | RFU
|
||||||
|
* EU868 | RFU
|
||||||
|
* IN865 | RFU
|
||||||
|
* KR920 | RFU
|
||||||
|
* US915 | RFU
|
||||||
|
* US915_HYBRID | RFU
|
||||||
|
*/
|
||||||
|
#define DR_14 14
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Region | SF
|
||||||
|
* ------------ | :-----:
|
||||||
|
* AS923 | RFU
|
||||||
|
* AU915 | RFU
|
||||||
|
* CN470 | RFU
|
||||||
|
* CN779 | RFU
|
||||||
|
* EU433 | RFU
|
||||||
|
* EU868 | RFU
|
||||||
|
* IN865 | RFU
|
||||||
|
* KR920 | RFU
|
||||||
|
* US915 | RFU
|
||||||
|
* US915_HYBRID | RFU
|
||||||
|
*/
|
||||||
|
#define DR_15 15
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration for LoRaWAN connection type.
|
||||||
|
*/
|
||||||
|
typedef enum lorawan_connect_type {
|
||||||
|
LORAWAN_CONNECTION_OTAA = 0, /**< Over The Air Activation */
|
||||||
|
LORAWAN_CONNECTION_ABP /**< Activation By Personalization */
|
||||||
|
} lorawan_connect_type_t;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Meta-data collection for a transmission
|
* Meta-data collection for a transmission
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -431,20 +431,19 @@ typedef union {
|
||||||
/*!
|
/*!
|
||||||
* The structure containing single access to header bits.
|
* The structure containing single access to header bits.
|
||||||
*/
|
*/
|
||||||
struct hdr_bits_s
|
struct hdr_bits_s {
|
||||||
{
|
|
||||||
/*!
|
/*!
|
||||||
* Major version.
|
* Major version.
|
||||||
*/
|
*/
|
||||||
uint8_t major : 2;
|
uint8_t major : 2;
|
||||||
/*!
|
/*!
|
||||||
* RFU
|
* RFU
|
||||||
*/
|
*/
|
||||||
uint8_t RFU : 3;
|
uint8_t RFU : 3;
|
||||||
/*!
|
/*!
|
||||||
* Message type
|
* Message type
|
||||||
*/
|
*/
|
||||||
uint8_t mtype : 3;
|
uint8_t mtype : 3;
|
||||||
} bits;
|
} bits;
|
||||||
} loramac_mhdr_t;
|
} loramac_mhdr_t;
|
||||||
|
|
||||||
|
|
@ -461,28 +460,27 @@ typedef union {
|
||||||
/*!
|
/*!
|
||||||
* The structure containing single access to bits.
|
* The structure containing single access to bits.
|
||||||
*/
|
*/
|
||||||
struct ctrl_bits_s
|
struct ctrl_bits_s {
|
||||||
{
|
|
||||||
/*!
|
/*!
|
||||||
* Frame options length.
|
* Frame options length.
|
||||||
*/
|
*/
|
||||||
uint8_t fopts_len : 4;
|
uint8_t fopts_len : 4;
|
||||||
/*!
|
/*!
|
||||||
* Frame pending bit.
|
* Frame pending bit.
|
||||||
*/
|
*/
|
||||||
uint8_t fpending : 1;
|
uint8_t fpending : 1;
|
||||||
/*!
|
/*!
|
||||||
* Message acknowledge bit.
|
* Message acknowledge bit.
|
||||||
*/
|
*/
|
||||||
uint8_t ack : 1;
|
uint8_t ack : 1;
|
||||||
/*!
|
/*!
|
||||||
* ADR acknowledgment request bit.
|
* ADR acknowledgment request bit.
|
||||||
*/
|
*/
|
||||||
uint8_t adr_ack_req : 1;
|
uint8_t adr_ack_req : 1;
|
||||||
/*!
|
/*!
|
||||||
* ADR control in the frame header.
|
* ADR control in the frame header.
|
||||||
*/
|
*/
|
||||||
uint8_t adr : 1;
|
uint8_t adr : 1;
|
||||||
} bits;
|
} bits;
|
||||||
} loramac_frame_ctrl_t;
|
} loramac_frame_ctrl_t;
|
||||||
|
|
||||||
|
|
@ -857,14 +855,6 @@ typedef enum device_states {
|
||||||
DEVICE_STATE_SHUTDOWN
|
DEVICE_STATE_SHUTDOWN
|
||||||
} device_states_t;
|
} device_states_t;
|
||||||
|
|
||||||
/**
|
|
||||||
* Enumeration for LoRaWAN connection type.
|
|
||||||
*/
|
|
||||||
typedef enum lorawan_connect_type {
|
|
||||||
LORAWAN_CONNECTION_OTAA = 0, /**< Over The Air Activation */
|
|
||||||
LORAWAN_CONNECTION_ABP /**< Activation By Personalization */
|
|
||||||
} lorawan_connect_type_t;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stack level TX message structure
|
* Stack level TX message structure
|
||||||
*/
|
*/
|
||||||
|
|
@ -1023,7 +1013,7 @@ typedef struct {
|
||||||
/*!
|
/*!
|
||||||
* The RX window timeout
|
* The RX window timeout
|
||||||
*/
|
*/
|
||||||
uint32_t window_timeout;
|
uint32_t window_timeout;
|
||||||
/*!
|
/*!
|
||||||
* The RX window offset
|
* The RX window offset
|
||||||
*/
|
*/
|
||||||
|
|
@ -1085,39 +1075,39 @@ typedef struct {
|
||||||
} loramac_keys;
|
} loramac_keys;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/*!
|
/*!
|
||||||
* Aggregated duty cycle management
|
* Aggregated duty cycle management
|
||||||
*/
|
*/
|
||||||
lorawan_time_t aggregated_last_tx_time;
|
lorawan_time_t aggregated_last_tx_time;
|
||||||
lorawan_time_t aggregated_timeoff;
|
lorawan_time_t aggregated_timeoff;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Stores the time at LoRaMac initialization.
|
* Stores the time at LoRaMac initialization.
|
||||||
*
|
*
|
||||||
* \remark Used for the BACKOFF_DC computation.
|
* \remark Used for the BACKOFF_DC computation.
|
||||||
*/
|
*/
|
||||||
lorawan_time_t mac_init_time;
|
lorawan_time_t mac_init_time;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Last transmission time on air
|
* Last transmission time on air
|
||||||
*/
|
*/
|
||||||
lorawan_time_t tx_toa;
|
lorawan_time_t tx_toa;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* LoRaMac duty cycle backoff timer
|
* LoRaMac duty cycle backoff timer
|
||||||
*/
|
*/
|
||||||
timer_event_t backoff_timer;
|
timer_event_t backoff_timer;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* LoRaMac reception windows timers
|
* LoRaMac reception windows timers
|
||||||
*/
|
*/
|
||||||
timer_event_t rx_window1_timer;
|
timer_event_t rx_window1_timer;
|
||||||
timer_event_t rx_window2_timer;
|
timer_event_t rx_window2_timer;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Acknowledge timeout timer. Used for packet retransmissions.
|
* Acknowledge timeout timer. Used for packet retransmissions.
|
||||||
*/
|
*/
|
||||||
timer_event_t ack_timeout_timer;
|
timer_event_t ack_timeout_timer;
|
||||||
|
|
||||||
} lorawan_timers;
|
} lorawan_timers;
|
||||||
|
|
||||||
|
|
@ -1126,7 +1116,7 @@ typedef struct {
|
||||||
/*!
|
/*!
|
||||||
* Holds the type of current Receive window slot
|
* Holds the type of current Receive window slot
|
||||||
*/
|
*/
|
||||||
rx_slot_t rx_slot;
|
rx_slot_t rx_slot;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Indicates if the node is connected to a private or public network
|
* Indicates if the node is connected to a private or public network
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue