LoRaWANStack unit tested

pull/8233/head
Antti Kauppila 2018-09-23 15:13:49 +03:00
parent e07940d5e7
commit bd9066431f
9 changed files with 803 additions and 131 deletions

View File

@ -69,7 +69,6 @@ TEST_F(Test_LoRaMacCommand, parse_mac_commands_to_repeat)
uint8_t buf[20];
object->parse_mac_commands_to_repeat();
EXPECT_TRUE(object->is_mac_command_in_next_tx() == false);
buf[0] = 2;
buf[1] = 16;
@ -120,7 +119,6 @@ TEST_F(Test_LoRaMacCommand, parse_mac_commands_to_repeat)
EXPECT_TRUE(object->process_mac_commands(buf, 0, 4, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
object->parse_mac_commands_to_repeat();
EXPECT_TRUE(object->is_mac_command_in_next_tx() == true);
}
TEST_F(Test_LoRaMacCommand, clear_repeat_buffer)
@ -158,42 +156,6 @@ TEST_F(Test_LoRaMacCommand, get_repeat_commands_length)
EXPECT_TRUE(object->get_repeat_commands_length() == 0 );
}
TEST_F(Test_LoRaMacCommand, clear_mac_commands_in_next_tx)
{
loramac_mlme_confirm_t mlme;
lora_mac_system_params_t params;
my_LoRaPHY phy;
uint8_t buf[20];
EXPECT_TRUE(object->is_mac_command_in_next_tx() == false);
buf[0] = 4;
buf[1] = 16;
buf[2] = 32;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
EXPECT_TRUE(object->is_mac_command_in_next_tx() == true);
object->clear_mac_commands_in_next_tx();
EXPECT_TRUE(object->is_mac_command_in_next_tx() == false);
}
TEST_F(Test_LoRaMacCommand, is_mac_command_in_next_tx)
{
loramac_mlme_confirm_t mlme;
lora_mac_system_params_t params;
my_LoRaPHY phy;
uint8_t buf[20];
EXPECT_TRUE(object->is_mac_command_in_next_tx() == false);
buf[0] = 4;
buf[1] = 16;
buf[2] = 32;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
EXPECT_TRUE(object->is_mac_command_in_next_tx() == true);
}
TEST_F(Test_LoRaMacCommand, clear_sticky_mac_cmd)
{
loramac_mlme_confirm_t mlme;
@ -375,27 +337,6 @@ TEST_F(Test_LoRaMacCommand, process_mac_commands)
EXPECT_TRUE(object->process_mac_commands(buf, 0, 1, 0, mlme, params, phy) == LORAWAN_STATUS_UNSUPPORTED);
}
TEST_F(Test_LoRaMacCommand, is_sticky_mac_command_pending)
{
loramac_mlme_confirm_t mlme;
lora_mac_system_params_t params;
my_LoRaPHY phy;
uint8_t buf[20];
EXPECT_TRUE(object->is_sticky_mac_command_pending() == false);
object->clear_command_buffer();
buf[0] = 5;
buf[1] = 2;
buf[2] = 2;
buf[3] = 2;
buf[4] = 2;
buf[5] = 2;
EXPECT_TRUE(object->process_mac_commands(buf, 0, 5, 0, mlme, params, phy) == LORAWAN_STATUS_OK);
object->parse_mac_commands_to_repeat();
EXPECT_TRUE(object->is_sticky_mac_command_pending() == true);
}
TEST_F(Test_LoRaMacCommand, add_link_check_req)
{
object->add_link_check_req();

View File

@ -20,6 +20,11 @@
#include "EventQueue.h"
#include "LoRaPHY_stub.h"
#include "LoRaMac_stub.h"
#include "equeue_stub.h"
#include "lorawan_data_structures.h"
static uint8_t batt_level = 0;
using namespace events;
@ -39,8 +44,9 @@ uint8_t my_cb()
class my_radio : public LoRaRadio
{
public:
radio_events_t *_ev;
virtual void init_radio(radio_events_t *events){};
virtual void init_radio(radio_events_t *events){_ev = events;};
virtual void radio_reset(){};
@ -105,6 +111,7 @@ protected:
virtual void SetUp()
{
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
object = new LoRaWANStack();
}
@ -132,62 +139,247 @@ TEST_F(Test_LoRaWANStack, initialize_mac_layer)
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
//Visit callback
if (LoRaMac_stub::_scheduling_failure_handler) {
LoRaMac_stub::_scheduling_failure_handler.call();
}
}
void events_cb(lorawan_event_t ev)
{
}
void lc_resp(uint8_t a, uint8_t b)
{
}
uint8_t batt_lvl()
{
return batt_level;
}
TEST_F(Test_LoRaWANStack, set_lora_callbacks)
{
lorawan_app_callbacks_t cb;
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->set_lora_callbacks(&cb));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->set_lora_callbacks(NULL));
cb.events = NULL;
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->set_lora_callbacks(&cb));
cb.events = events_cb;
cb.link_check_resp = lc_resp;
cb.battery_level = batt_lvl;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_lora_callbacks(&cb));
}
TEST_F(Test_LoRaWANStack, connect)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->connect());
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_BUSY;
EXPECT_TRUE(LORAWAN_STATUS_BUSY == object->connect());
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->connect());
//_ctrl_flags & CONN_IN_PROGRESS_FLAG
EXPECT_TRUE(LORAWAN_STATUS_BUSY == object->connect());
my_radio radio;
my_LoRaPHY phy;
object->bind_phy_and_radio_driver(radio, phy);
// struct equeue_event ptr;
// equeue_stub.void_ptr = &ptr;
// equeue_stub.call_cb_immediately = true;
loramac_mcps_confirm_t conf;
LoRaMac_stub::mcps_conf_ptr = &conf;
radio._ev->tx_done();
loramac_mcps_indication_t ind;
LoRaMac_stub::mcps_ind_ptr = &ind;
loramac_mlme_confirm_t mlme;
LoRaMac_stub::mlme_conf_ptr = &mlme;
mlme.pending = true;
mlme.req_type = MLME_JOIN;
mlme.status = LORAMAC_EVENT_INFO_STATUS_OK;
LoRaMac_stub::bool_value = false;
radio._ev->rx_done(NULL, 0, 0, 0);
//_ctrl_flags & CONNECTED_FLAG
EXPECT_TRUE(LORAWAN_STATUS_ALREADY_CONNECTED == object->connect());
//Visit rx_interrupt_handler's first if
radio._ev->rx_done(NULL, 65535, 0, 0);
}
TEST_F(Test_LoRaWANStack, connect_args)
{
lorawan_connect_t conn;
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->connect(conn));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
conn.connect_type = lorawan_connect_type_t(8);
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->connect(conn));
LoRaMac_stub::status_value = LORAWAN_STATUS_BUSY;
conn.connect_type = LORAWAN_CONNECTION_OTAA;
EXPECT_TRUE(LORAWAN_STATUS_BUSY == object->connect(conn));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->connect(conn));
//_ctrl_flags & CONN_IN_PROGRESS_FLAG
EXPECT_TRUE(LORAWAN_STATUS_BUSY == object->connect(conn));
object->shutdown();
conn.connect_type = LORAWAN_CONNECTION_ABP;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->connect(conn));
//_ctrl_flags & CONNECTED_FLAG
EXPECT_TRUE(LORAWAN_STATUS_ALREADY_CONNECTED == object->connect(conn));
}
TEST_F(Test_LoRaWANStack, add_channels)
{
lorawan_channelplan_t plan;
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->add_channels(plan));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->add_channels(plan));
}
TEST_F(Test_LoRaWANStack, remove_a_channel)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->remove_a_channel(1));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->remove_a_channel(1));
}
TEST_F(Test_LoRaWANStack, drop_channel_list)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->drop_channel_list());
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->drop_channel_list());
}
TEST_F(Test_LoRaWANStack, get_enabled_channels)
{
lorawan_channelplan_t plan;
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->get_enabled_channels(plan));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->get_enabled_channels(plan));
}
TEST_F(Test_LoRaWANStack, set_confirmed_msg_retry)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->set_confirmed_msg_retry(1));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->set_confirmed_msg_retry(255));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_confirmed_msg_retry(1));
}
TEST_F(Test_LoRaWANStack, set_channel_data_rate)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->set_channel_data_rate(4));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_channel_data_rate(4));
}
TEST_F(Test_LoRaWANStack, enable_adaptive_datarate)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->enable_adaptive_datarate(false));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->enable_adaptive_datarate(false));
}
TEST_F(Test_LoRaWANStack, handle_tx)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->handle_tx(0, NULL, 0, 0, true, false));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->handle_tx(0, NULL, 0, 0, false, false));
lorawan_app_callbacks_t cb;
cb.events = events_cb;
cb.link_check_resp = lc_resp;
cb.battery_level = batt_lvl;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_lora_callbacks(&cb));
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_link_check_request());
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_NO_ACTIVE_SESSIONS == object->handle_tx(0, NULL, 0, 0, true, false));
lorawan_connect_t conn;
conn.connect_type = LORAWAN_CONNECTION_ABP;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->connect(conn));
LoRaMac_stub::bool_value = false;
EXPECT_TRUE(LORAWAN_STATUS_NO_NETWORK_JOINED == object->handle_tx(0, NULL, 0, 0, true, false));
LoRaMac_stub::bool_value = true;
EXPECT_TRUE(LORAWAN_STATUS_WOULD_BLOCK == object->handle_tx(0, NULL, 0, 0, true, false));
LoRaMac_stub::bool_false_counter = 1;
LoRaMac_stub::bool_value = true;
//set_application_port fails
EXPECT_TRUE(LORAWAN_STATUS_PORT_INVALID == object->handle_tx(0, NULL, 0, 0, true, false));
LoRaMac_stub::bool_false_counter = 1;
LoRaMac_stub::bool_value = true;
//Wrong flags -> LORAWAN_STATUS_PARAMETER_INVALID
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->handle_tx(1, NULL, 0, 0x04, true, false));
LoRaMac_stub::bool_false_counter = 1;
//Actual sending
EXPECT_TRUE(LORAWAN_STATUS_OK == object->handle_tx(1, NULL, 0, 0x08, true, false));
}
TEST_F(Test_LoRaWANStack, handle_rx)
@ -195,11 +387,137 @@ TEST_F(Test_LoRaWANStack, handle_rx)
uint8_t port;
int flags;
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->handle_rx(NULL, 0, port, flags, false));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_NO_ACTIVE_SESSIONS == object->handle_rx(NULL, 0, port, flags, false));
lorawan_connect_t conn;
conn.connect_type = LORAWAN_CONNECTION_ABP;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->connect(conn));
EXPECT_TRUE(LORAWAN_STATUS_WOULD_BLOCK == object->handle_rx(NULL, 0, port, flags, false));
//Prepare ready for receive state
lorawan_app_callbacks_t cb;
cb.events = events_cb;
cb.link_check_resp = lc_resp;
cb.battery_level = batt_lvl;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_lora_callbacks(&cb));
my_radio radio;
my_LoRaPHY phy;
object->bind_phy_and_radio_driver(radio, phy);
// struct equeue_event ptr;
// equeue_stub.void_ptr = &ptr;
// equeue_stub.call_cb_immediately = true;
loramac_mcps_confirm_t conf;
LoRaMac_stub::mcps_conf_ptr = &conf;
radio._ev->tx_done();
loramac_mcps_indication_t ind;
LoRaMac_stub::mcps_ind_ptr = &ind;
loramac_mlme_confirm_t mlme;
LoRaMac_stub::mlme_conf_ptr = &mlme;
mlme.pending = false;
mlme.req_type = MLME_JOIN;
mlme.status = LORAMAC_EVENT_INFO_STATUS_OK;
LoRaMac_stub::bool_value = true;
conf.req_type = MCPS_PROPRIETARY;
ind.pending = true;
LoRaMac_stub::dev_class_value = CLASS_C;
loramac_mlme_indication_t mlme_ind;
mlme_ind.pending = false;
LoRaMac_stub::mlme_ind_ptr = &mlme_ind;
uint8_t ind_buf[150];
for (int i= 0; i < 110; i++) {
ind_buf[i] = i;
}
ind.buffer = ind_buf;
ind.buffer_size = 150;
ind.type = MCPS_UNCONFIRMED;
radio._ev->rx_done(NULL, 0, 0, 0);
//data == NULL || LENGTH == 0 (2 cases)
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->handle_rx(NULL, 0, port, flags, false));
uint8_t data[50];
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->handle_rx(data, 0, port, flags, false));
//validate_params returns Would block
port = 43;
EXPECT_TRUE(LORAWAN_STATUS_WOULD_BLOCK == object->handle_rx(data, 50, port, flags, true));
ind.type = MCPS_CONFIRMED;
radio._ev->rx_done(NULL, 0, 0, 0);
EXPECT_TRUE(LORAWAN_STATUS_WOULD_BLOCK == object->handle_rx(data, 50, port, flags, true));
//Call again to visit send_automatic_uplink_message error case
LoRaMac_stub::bool_true_counter = 1;
ind.type = MCPS_CONFIRMED;
ind.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
LoRaMac_stub::bool_value = false;
radio._ev->rx_done(NULL, 0, 0, 0);
ind.status = LORAMAC_EVENT_INFO_STATUS_OK;
LoRaMac_stub::bool_value = true;
//convert_to_msg_flag cases
ind.fpending_status = true;
ind.type = MCPS_PROPRIETARY;
radio._ev->rx_done(NULL, 0, 0, 0);
EXPECT_TRUE(LORAWAN_STATUS_WOULD_BLOCK == object->handle_rx(data, 50, port, flags, true));
ind.type = MCPS_MULTICAST;
radio._ev->rx_done(NULL, 0, 0, 0);
EXPECT_TRUE(LORAWAN_STATUS_WOULD_BLOCK == object->handle_rx(data, 50, port, flags, true));
ind.type = MCPS_UNCONFIRMED;
radio._ev->rx_done(NULL, 0, 0, 0);
//read not complete
EXPECT_TRUE(50 == object->handle_rx(data, 50, port, flags, false));
EXPECT_EQ(10, data[10]);
EXPECT_TRUE(50 == object->handle_rx(data, 50, port, flags, false));
EXPECT_EQ(60, data[10]);
//read complete
EXPECT_TRUE(50 == object->handle_rx(data, 50, port, flags, false));
EXPECT_EQ(100, data[0]);
//read can fit the buffer
for (int i= 0; i < 110; i++) {
ind_buf[i] = i;
}
ind.buffer = ind_buf;
ind.buffer_size = 50;
ind.type = mcps_type_t(66);
radio._ev->rx_done(NULL, 0, 0, 0);
EXPECT_TRUE(50 == object->handle_rx(data, 50, port, flags, false));
EXPECT_EQ(10, data[10]);
}
TEST_F(Test_LoRaWANStack, set_link_check_request)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->set_link_check_request());
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_PARAMETER_INVALID == object->set_link_check_request());
lorawan_app_callbacks_t cb;
cb.events = events_cb;
cb.link_check_resp = lc_resp;
cb.battery_level = batt_lvl;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_lora_callbacks(&cb));
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_link_check_request());
}
TEST_F(Test_LoRaWANStack, remove_link_check_request)
@ -210,34 +528,141 @@ TEST_F(Test_LoRaWANStack, remove_link_check_request)
TEST_F(Test_LoRaWANStack, shutdown)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->shutdown());
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
EXPECT_TRUE(LORAWAN_STATUS_DEVICE_OFF == object->shutdown());
}
TEST_F(Test_LoRaWANStack, set_device_class)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->set_device_class(CLASS_A));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_UNSUPPORTED == object->set_device_class(CLASS_B));
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_device_class(CLASS_A));
//Visit callback
if (LoRaMac_stub::_ack_expiry_handler_for_class_c) {
LoRaMac_stub::_ack_expiry_handler_for_class_c.call();
}
}
TEST_F(Test_LoRaWANStack, acquire_tx_metadata)
{
lorawan_tx_metadata data;
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->acquire_tx_metadata(data));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
// stale = true;
EXPECT_TRUE(LORAWAN_STATUS_METADATA_NOT_AVAILABLE == object->acquire_tx_metadata(data));
// stale = false;
my_radio radio;
my_LoRaPHY phy;
object->bind_phy_and_radio_driver(radio, phy);
// struct equeue_event ptr;
// equeue_stub.void_ptr = &ptr;
// equeue_stub.call_cb_immediately = true;
loramac_mcps_confirm_t conf;
LoRaMac_stub::mcps_conf_ptr = &conf;
radio._ev->tx_done();
EXPECT_TRUE(LORAWAN_STATUS_OK == object->acquire_tx_metadata(data));
}
TEST_F(Test_LoRaWANStack, acquire_rx_metadata)
{
lorawan_rx_metadata data;
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->acquire_rx_metadata(data));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
// stale = true;
EXPECT_TRUE(LORAWAN_STATUS_METADATA_NOT_AVAILABLE == object->acquire_rx_metadata(data));
// stale = false;
my_radio radio;
my_LoRaPHY phy;
object->bind_phy_and_radio_driver(radio, phy);
// struct equeue_event ptr;
// equeue_stub.void_ptr = &ptr;
// equeue_stub.call_cb_immediately = true;
loramac_mcps_confirm_t conf;
LoRaMac_stub::mcps_conf_ptr = &conf;
radio._ev->tx_done();
loramac_mcps_indication_t ind;
LoRaMac_stub::mcps_ind_ptr = &ind;
loramac_mlme_confirm_t mlme;
LoRaMac_stub::mlme_conf_ptr = &mlme;
mlme.pending = true;
mlme.req_type = MLME_JOIN;
//Visit mlme_confirm_handler here also
mlme.status = LORAMAC_EVENT_INFO_STATUS_CRYPTO_FAIL;
LoRaMac_stub::bool_value = false;
radio._ev->rx_done(NULL, 0, 0, 0);
mlme.status = LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT;
radio._ev->rx_done(NULL, 0, 0, 0);
mlme.status = LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT;
LoRaMac_stub::slot_value = RX_SLOT_WIN_2;
radio._ev->rx_done(NULL, 0, 0, 0);
lorawan_app_callbacks_t cb;
cb.events = events_cb;
cb.link_check_resp = lc_resp;
cb.battery_level = batt_lvl;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_lora_callbacks(&cb));
mlme.req_type = MLME_LINK_CHECK;
mlme.status = LORAMAC_EVENT_INFO_STATUS_OK;
radio._ev->rx_done(NULL, 0, 0, 0);
EXPECT_TRUE(LORAWAN_STATUS_OK == object->acquire_rx_metadata(data));
}
TEST_F(Test_LoRaWANStack, acquire_backoff_metadata)
{
int b;
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->acquire_backoff_metadata(b));
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::int_value = 2;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->acquire_backoff_metadata(b));
LoRaMac_stub::int_value = 0;
EXPECT_TRUE(LORAWAN_STATUS_METADATA_NOT_AVAILABLE == object->acquire_backoff_metadata(b));
}
TEST_F(Test_LoRaWANStack, stop_sending)
{
EXPECT_TRUE(LORAWAN_STATUS_NOT_INITIALIZED == object->stop_sending());
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
LoRaMac_stub::status_value = LORAWAN_STATUS_DEVICE_OFF;
EXPECT_TRUE(LORAWAN_STATUS_BUSY == object->stop_sending());
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->stop_sending());
}
TEST_F(Test_LoRaWANStack, lock)
@ -250,3 +675,191 @@ TEST_F(Test_LoRaWANStack, unlock)
object->unlock();
}
TEST_F(Test_LoRaWANStack, interrupt_functions)
{
lorawan_connect_t conn;
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
my_radio radio;
my_LoRaPHY phy;
object->bind_phy_and_radio_driver(radio, phy);
// struct equeue_event ptr;
// equeue_stub.void_ptr = &ptr;
// equeue_stub.call_cb_immediately = true;
loramac_mcps_confirm_t conf;
LoRaMac_stub::mcps_conf_ptr = &conf;
radio._ev->tx_done();
loramac_mcps_indication_t ind;
LoRaMac_stub::mcps_ind_ptr = &ind;
loramac_mlme_confirm_t mlme;
LoRaMac_stub::mlme_conf_ptr = &mlme;
mlme.pending = true;
mlme.req_type = MLME_JOIN;
mlme.status = LORAMAC_EVENT_INFO_STATUS_OK;
LoRaMac_stub::bool_value = false;
radio._ev->rx_done(NULL, 0, 0, 0);
radio._ev->rx_done(NULL, 0, 0, 0);
radio._ev->rx_error();
LoRaMac_stub::slot_value = RX_SLOT_WIN_2;
radio._ev->rx_error();
conf.req_type = MCPS_UNCONFIRMED;
LoRaMac_stub::bool_value = true;
radio._ev->rx_error();
conf.req_type = MCPS_CONFIRMED;
radio._ev->rx_error();
LoRaMac_stub::bool_value = false;
LoRaMac_stub::slot_value = RX_SLOT_WIN_1;
radio._ev->rx_timeout();
radio._ev->tx_timeout();
object->shutdown();
conn.connect_type = LORAWAN_CONNECTION_OTAA;
object->connect(conn);
LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
object->connect(conn);
radio._ev->tx_timeout();
}
TEST_F(Test_LoRaWANStack, process_transmission)
{
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
lorawan_app_callbacks_t cb;
cb.events = events_cb;
cb.link_check_resp = lc_resp;
cb.battery_level = batt_lvl;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_lora_callbacks(&cb));
my_radio radio;
my_LoRaPHY phy;
object->bind_phy_and_radio_driver(radio, phy);
object->connect();
// struct equeue_event ptr;
// equeue_stub.void_ptr = &ptr;
// equeue_stub.call_cb_immediately = true;
loramac_mcps_confirm_t conf;
LoRaMac_stub::mcps_conf_ptr = &conf;
radio._ev->tx_done();
loramac_mcps_indication_t ind;
LoRaMac_stub::mcps_ind_ptr = &ind;
loramac_mlme_confirm_t mlme;
LoRaMac_stub::mlme_conf_ptr = &mlme;
mlme.pending = true;
mlme.req_type = MLME_JOIN;
mlme.status = LORAMAC_EVENT_INFO_STATUS_OK;
LoRaMac_stub::bool_value = false;
radio._ev->rx_done(NULL, 0, 0, 0);
LoRaMac_stub::bool_value = true;
conf.req_type = MCPS_PROPRIETARY;
LoRaMac_stub::bool_false_counter = 1;
LoRaMac_stub::dev_class_value = CLASS_A;
object->handle_tx(1, NULL, 0, MSG_UNCONFIRMED_FLAG, true, false);
radio._ev->tx_done();
LoRaMac_stub::bool_false_counter = 1;
LoRaMac_stub::dev_class_value = CLASS_A;
object->handle_tx(1, NULL, 0, MSG_UNCONFIRMED_FLAG, true, false);
radio._ev->tx_done();
LoRaMac_stub::bool_false_counter = 1;
LoRaMac_stub::dev_class_value = CLASS_C;
object->handle_tx(1, NULL, 0, MSG_UNCONFIRMED_FLAG, true, false);
radio._ev->tx_done();
LoRaMac_stub::bool_false_counter = 1;
conf.req_type = MCPS_CONFIRMED;
object->handle_tx(1, NULL, 0, MSG_UNCONFIRMED_FLAG, true, false);
radio._ev->tx_done();
}
TEST_F(Test_LoRaWANStack, process_reception)
{
EventQueue queue;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->initialize_mac_layer(&queue));
//Prepare ready for receive state
lorawan_app_callbacks_t cb;
cb.events = events_cb;
cb.link_check_resp = lc_resp;
cb.battery_level = batt_lvl;
EXPECT_TRUE(LORAWAN_STATUS_OK == object->set_lora_callbacks(&cb));
my_radio radio;
my_LoRaPHY phy;
object->bind_phy_and_radio_driver(radio, phy);
// struct equeue_event ptr;
// equeue_stub.void_ptr = &ptr;
// equeue_stub.call_cb_immediately = true;
loramac_mcps_confirm_t conf;
LoRaMac_stub::mcps_conf_ptr = &conf;
radio._ev->tx_done();
loramac_mcps_indication_t ind;
LoRaMac_stub::mcps_ind_ptr = &ind;
loramac_mlme_confirm_t mlme;
LoRaMac_stub::mlme_conf_ptr = &mlme;
mlme.pending = false;
mlme.req_type = MLME_JOIN;
mlme.status = LORAMAC_EVENT_INFO_STATUS_OK;
LoRaMac_stub::bool_value = true;
conf.req_type = MCPS_PROPRIETARY;
ind.pending = true;
LoRaMac_stub::dev_class_value = CLASS_C;
loramac_mlme_indication_t mlme_ind;
mlme_ind.pending = false;
LoRaMac_stub::mlme_ind_ptr = &mlme_ind;
uint8_t ind_buf[150];
for (int i= 0; i < 110; i++) {
ind_buf[i] = i;
}
ind.buffer = ind_buf;
ind.buffer_size = 150;
//_loramac.get_mcps_confirmation()->req_type == MCPS_CONFIRMED
conf.req_type = MCPS_CONFIRMED;
conf.status = LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT;
radio._ev->rx_done(NULL, 0, 0, 0);
ind.is_ack_recvd = false;
LoRaMac_stub::bool_true_counter = 1;
LoRaMac_stub::bool_value = false;
LoRaMac_stub::slot_value = RX_SLOT_WIN_2;
conf.status = LORAMAC_EVENT_INFO_STATUS_TX_DR_PAYLOAD_SIZE_ERROR;
radio._ev->rx_done(NULL, 0, 0, 0);
conf.req_type = MCPS_UNCONFIRMED;
LoRaMac_stub::dev_class_value = CLASS_A;
LoRaMac_stub::bool_value = true;
mlme_ind.pending = true;
mlme_ind.indication_type = MLME_SCHEDULE_UPLINK;
conf.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
radio._ev->rx_done(NULL, 0, 0, 0);
ind.is_ack_recvd = true;
conf.req_type = MCPS_CONFIRMED;
conf.status = LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT;
radio._ev->rx_done(NULL, 0, 0, 0);
}

View File

@ -48,6 +48,8 @@ set(unittest-test-sources
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_OVER_THE_AIR_ACTIVATION=true -DMBED_CONF_LORA_DEVICE_EUI=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\"")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_OVER_THE_AIR_ACTIVATION=true -DMBED_CONF_LORA_DEVICE_EUI=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\"")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_AUTOMATIC_UPLINK_MESSAGE=true")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_AUTOMATIC_UPLINK_MESSAGE=true")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_APPLICATION_EUI=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\" -DMBED_CONF_LORA_APPLICATION_KEY=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\"")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_APPLICATION_EUI=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\" -DMBED_CONF_LORA_APPLICATION_KEY=\"{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}\"")

View File

@ -55,15 +55,6 @@ uint8_t LoRaMacCommand::get_repeat_commands_length() const
return 0;
}
void LoRaMacCommand::clear_mac_commands_in_next_tx()
{
}
bool LoRaMacCommand::is_mac_command_in_next_tx() const
{
return false;
}
void LoRaMacCommand::clear_sticky_mac_cmd()
{
}
@ -82,11 +73,6 @@ lorawan_status_t LoRaMacCommand::process_mac_commands(const uint8_t *payload, ui
return LORAWAN_STATUS_OK;
}
bool LoRaMacCommand::is_sticky_mac_command_pending()
{
return false;
}
int32_t LoRaMacCommand::cmd_buffer_remaining() const
{
return 0;

View File

@ -17,11 +17,25 @@
#include <stdlib.h>
#include "LoRaMac.h"
#include "LoRaMac_stub.h"
using namespace events;
using namespace mbed;
int LoRaMac_stub::bool_false_counter = 0;
int LoRaMac_stub::bool_true_counter = 0;
bool LoRaMac_stub::bool_value = false;
int LoRaMac_stub::int_value = 0;
rx_slot_t LoRaMac_stub::slot_value = RX_SLOT_WIN_1;
lorawan_status_t LoRaMac_stub::status_value = LORAWAN_STATUS_OK;
loramac_mcps_confirm_t *LoRaMac_stub::mcps_conf_ptr = NULL;
loramac_mcps_indication_t *LoRaMac_stub::mcps_ind_ptr = NULL;
loramac_mlme_confirm_t *LoRaMac_stub::mlme_conf_ptr = NULL;
loramac_mlme_indication_t *LoRaMac_stub::mlme_ind_ptr = NULL;
device_class_t LoRaMac_stub::dev_class_value = CLASS_A;
mbed::Callback<void(void)> LoRaMac_stub::_ack_expiry_handler_for_class_c = NULL;
mbed::Callback<void(void)> LoRaMac_stub::_scheduling_failure_handler = NULL;
LoRaMac::LoRaMac()
: _lora_time(),
@ -45,22 +59,22 @@ LoRaMac::~LoRaMac()
const loramac_mcps_confirm_t *LoRaMac::get_mcps_confirmation() const
{
return NULL;
return LoRaMac_stub::mcps_conf_ptr;
}
const loramac_mcps_indication_t *LoRaMac::get_mcps_indication() const
{
return NULL;
return LoRaMac_stub::mcps_ind_ptr;
}
const loramac_mlme_confirm_t *LoRaMac::get_mlme_confirmation() const
{
return NULL;
return LoRaMac_stub::mlme_conf_ptr;
}
const loramac_mlme_indication_t *LoRaMac::get_mlme_indication() const
{
return NULL;
return LoRaMac_stub::mlme_ind_ptr;
}
void LoRaMac::post_process_mlme_request()
@ -85,7 +99,7 @@ lorawan_time_t LoRaMac::get_current_time(void)
rx_slot_t LoRaMac::get_current_slot(void)
{
return RX_SLOT_WIN_1;
return LoRaMac_stub::slot_value;
}
void LoRaMac::handle_join_accept_frame(const uint8_t *payload, uint16_t size)
@ -103,7 +117,16 @@ bool LoRaMac::message_integrity_check(const uint8_t *const payload,
uint32_t *downlink_counter,
const uint8_t *nwk_skey)
{
return true;
if (LoRaMac_stub::bool_false_counter) {
LoRaMac_stub::bool_false_counter--;
return false;
}
if (LoRaMac_stub::bool_true_counter) {
LoRaMac_stub::bool_true_counter--;
return true;
}
return LoRaMac_stub::bool_value;
}
void LoRaMac::extract_data_and_mac_commands(const uint8_t *payload,
@ -156,22 +179,38 @@ void LoRaMac::on_radio_rx_timeout(bool is_timeout)
bool LoRaMac::continue_joining_process()
{
return true;
if (LoRaMac_stub::bool_false_counter) {
LoRaMac_stub::bool_false_counter--;
return false;
}
if (LoRaMac_stub::bool_true_counter) {
LoRaMac_stub::bool_true_counter--;
return true;
}
return LoRaMac_stub::bool_value;
}
bool LoRaMac::continue_sending_process()
{
return true;
if (LoRaMac_stub::bool_false_counter) {
LoRaMac_stub::bool_false_counter--;
return false;
}
if (LoRaMac_stub::bool_true_counter) {
LoRaMac_stub::bool_true_counter--;
return true;
}
return LoRaMac_stub::bool_value;
}
lorawan_status_t LoRaMac::send_join_request()
{
return LORAWAN_STATUS_OK;
return LoRaMac_stub::status_value;
}
lorawan_status_t LoRaMac::handle_retransmission()
{
return LORAWAN_STATUS_OK;
return LoRaMac_stub::status_value;
}
void LoRaMac::on_backoff_timer_expiry(void)
@ -194,7 +233,15 @@ bool LoRaMac::validate_payload_length(uint16_t length,
int8_t datarate,
uint8_t fopts_len)
{
return false;
if (LoRaMac_stub::bool_false_counter) {
LoRaMac_stub::bool_false_counter--;
return false;
}
if (LoRaMac_stub::bool_true_counter) {
LoRaMac_stub::bool_true_counter--;
return true;
}
return LoRaMac_stub::bool_value;
}
void LoRaMac::set_mlme_schedule_ul_indication(void)
@ -206,22 +253,22 @@ void LoRaMac::set_mlme_schedule_ul_indication(void)
lorawan_status_t LoRaMac::send(loramac_mhdr_t *machdr, const uint8_t fport,
const void *fbuffer, uint16_t fbuffer_size)
{
return LORAWAN_STATUS_OK;
return LoRaMac_stub::status_value;
}
int LoRaMac::get_backoff_timer_event_id(void)
{
return 0;
return LoRaMac_stub::int_value;
}
lorawan_status_t LoRaMac::clear_tx_pipe(void)
{
return LORAWAN_STATUS_OK;
return LoRaMac_stub::status_value;
}
lorawan_status_t LoRaMac::schedule_tx()
{
return LORAWAN_STATUS_OK;
return LoRaMac_stub::status_value;
}
void LoRaMac::calculate_backOff(uint8_t channel)
@ -243,12 +290,20 @@ void LoRaMac::enable_adaptive_datarate(bool adr_enabled)
lorawan_status_t LoRaMac::set_channel_data_rate(uint8_t data_rate)
{
return LORAWAN_STATUS_OK;
return LoRaMac_stub::status_value;
}
bool LoRaMac::tx_ongoing()
{
return false;
if (LoRaMac_stub::bool_false_counter) {
LoRaMac_stub::bool_false_counter--;
return false;
}
if (LoRaMac_stub::bool_true_counter) {
LoRaMac_stub::bool_true_counter--;
return true;
}
return LoRaMac_stub::bool_value;
}
void LoRaMac::set_tx_ongoing(bool ongoing)
@ -270,17 +325,18 @@ int16_t LoRaMac::prepare_ongoing_tx(const uint8_t port,
lorawan_status_t LoRaMac::send_ongoing_tx()
{
return LORAWAN_STATUS_OK;
return LoRaMac_stub::status_value;
}
device_class_t LoRaMac::get_device_class() const
{
return CLASS_A;
return LoRaMac_stub::dev_class_value;
}
void LoRaMac::set_device_class(const device_class_t &device_class,
mbed::Callback<void(void)>ack_expiry_handler)
{
LoRaMac_stub::_ack_expiry_handler_for_class_c = ack_expiry_handler;
}
void LoRaMac::setup_link_check_request()
@ -289,12 +345,12 @@ void LoRaMac::setup_link_check_request()
lorawan_status_t LoRaMac::prepare_join(const lorawan_connect_t *params, bool is_otaa)
{
return LORAWAN_STATUS_OK;
return LoRaMac_stub::status_value;
}
lorawan_status_t LoRaMac::join(bool is_otaa)
{
return LORAWAN_STATUS_OK;
return LoRaMac_stub::status_value;
}
static void memcpy_convert_endianess(uint8_t *dst,
@ -309,12 +365,12 @@ lorawan_status_t LoRaMac::prepare_frame(loramac_mhdr_t *machdr,
const void *fbuffer,
uint16_t fbuffer_size)
{
return LORAWAN_STATUS_OK;
return LoRaMac_stub::status_value;
}
lorawan_status_t LoRaMac::send_frame_on_channel(uint8_t channel)
{
return LORAWAN_STATUS_OK;
return LoRaMac_stub::status_value;
}
void LoRaMac::reset_mcps_confirmation()
@ -337,7 +393,8 @@ void LoRaMac::set_tx_continuous_wave(uint8_t channel, int8_t datarate, int8_t tx
lorawan_status_t LoRaMac::initialize(EventQueue *queue,
mbed::Callback<void(void)>scheduling_failure_handler)
{
return LORAWAN_STATUS_OK;
LoRaMac_stub::_scheduling_failure_handler = scheduling_failure_handler;
return LoRaMac_stub::status_value;
}
void LoRaMac::disconnect()
@ -351,7 +408,15 @@ uint8_t LoRaMac::get_max_possible_tx_size(uint8_t fopts_len)
bool LoRaMac::nwk_joined()
{
return false;
if (LoRaMac_stub::bool_false_counter) {
LoRaMac_stub::bool_false_counter--;
return false;
}
if (LoRaMac_stub::bool_true_counter) {
LoRaMac_stub::bool_true_counter--;
return true;
}
return LoRaMac_stub::bool_value;
}
void LoRaMac::set_nwk_joined(bool joined)
@ -360,32 +425,32 @@ void LoRaMac::set_nwk_joined(bool joined)
lorawan_status_t LoRaMac::add_channel_plan(const lorawan_channelplan_t &plan)
{
return LORAWAN_STATUS_OK;
return LoRaMac_stub::status_value;
}
lorawan_status_t LoRaMac::remove_channel_plan()
{
return LORAWAN_STATUS_OK;
return LoRaMac_stub::status_value;
}
lorawan_status_t LoRaMac::get_channel_plan(lorawan_channelplan_t &plan)
{
return LORAWAN_STATUS_OK;
return LoRaMac_stub::status_value;
}
lorawan_status_t LoRaMac::remove_single_channel(uint8_t id)
{
return LORAWAN_STATUS_OK;
return LoRaMac_stub::status_value;
}
lorawan_status_t LoRaMac::multicast_channel_link(multicast_params_t *channel_param)
{
return LORAWAN_STATUS_OK;
return LoRaMac_stub::status_value;
}
lorawan_status_t LoRaMac::multicast_channel_unlink(multicast_params_t *channel_param)
{
return LORAWAN_STATUS_OK;
return LoRaMac_stub::status_value;
}
void LoRaMac::bind_phy(LoRaPHY &phy)

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "stdint.h"
#include "stdbool.h"
#include <cstddef>
#include "lorawan_types.h"
#include "lorawan_data_structures.h"
namespace LoRaMac_stub
{
extern bool bool_value;
extern int bool_false_counter;
extern int bool_true_counter;
extern int int_value;
extern rx_slot_t slot_value;
extern lorawan_status_t status_value;
extern loramac_mcps_confirm_t *mcps_conf_ptr;
extern loramac_mcps_indication_t *mcps_ind_ptr;
extern loramac_mlme_confirm_t *mlme_conf_ptr;
extern loramac_mlme_indication_t *mlme_ind_ptr;
extern device_class_t dev_class_value;
extern mbed::Callback<void(void)> _ack_expiry_handler_for_class_c;
extern mbed::Callback<void(void)> _scheduling_failure_handler;
}

View File

@ -18,6 +18,10 @@
#include "equeue.h"
#include <stdlib.h>
#include "equeue_stub.h"
equeue_stub_def equeue_stub;
int equeue_create(equeue_t *queue, size_t size)
{
return 0;
@ -80,11 +84,10 @@ void equeue_event_dtor(void *event, void (*dtor)(void *))
int equeue_post(equeue_t *queue, void (*cb)(void *), void *event)
{
if (cb)
{
if (cb) {
cb(event);
free(event);
return 1; //Fake ID for calling cancel
return 1;
}
return 0;
}

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "stdint.h"
#include "stdbool.h"
typedef struct {
void *void_ptr;
bool call_cb_immediately;
} equeue_stub_def;
extern equeue_stub_def equeue_stub;

View File

@ -380,35 +380,31 @@ int16_t LoRaWANStack::handle_rx(uint8_t *data, uint16_t length, uint8_t &port, i
uint16_t base_size = _rx_msg.msg.mcps_indication.buffer_size;
bool read_complete = false;
if (_rx_msg.pending_size == 0) {
_rx_msg.pending_size = _rx_msg.msg.mcps_indication.buffer_size;
_rx_msg.prev_read_size = 0;
}
// check the length of received message whether we can fit into user
// buffer completely or not
if (_rx_msg.msg.mcps_indication.buffer_size > length
&& _rx_msg.prev_read_size == 0) {
// we can't fit into user buffer. Invoke counter measures
_rx_msg.pending_size = _rx_msg.msg.mcps_indication.buffer_size - length;
if (_rx_msg.prev_read_size == 0 && _rx_msg.msg.mcps_indication.buffer_size <= length) {
memcpy(data, base_ptr, base_size);
read_complete = true;
} else if (_rx_msg.pending_size > length) {
_rx_msg.pending_size = _rx_msg.pending_size - length;
base_size = length;
_rx_msg.prev_read_size = base_size;
memcpy(data, base_ptr, base_size);
} else if (_rx_msg.prev_read_size == 0) {
_rx_msg.pending_size = 0;
_rx_msg.prev_read_size = 0;
memcpy(data, base_ptr, base_size);
memcpy(data, base_ptr + _rx_msg.prev_read_size, base_size);
_rx_msg.prev_read_size += base_size;
} else {
base_size = _rx_msg.pending_size;
memcpy(data, base_ptr + _rx_msg.prev_read_size, base_size);
read_complete = true;
}
// If its the pending read then we should copy only the remaining part of
// the buffer. Due to checks above, in case of a pending read, this block
// will be the only one to get invoked
if (_rx_msg.pending_size > 0 && _rx_msg.prev_read_size > 0) {
memcpy(data, base_ptr + _rx_msg.prev_read_size, base_size);
}
// we are done handing over received buffer to user. check if there is
// anything pending. If not, memset the buffer to zero and indicate
// that no read is in progress
if (read_complete) {
_rx_msg.msg.mcps_indication.buffer = NULL;
_rx_msg.msg.mcps_indication.buffer_size = 0;
_rx_msg.pending_size = 0;
_rx_msg.receive_ready = false;
}
@ -1067,8 +1063,8 @@ lorawan_status_t LoRaWANStack::state_controller(device_states_t new_state)
process_shutdown_state(status);
break;
default:
tr_debug("state_controller: Unknown state!");
status = LORAWAN_STATUS_SERVICE_UNKNOWN;
//Because this is internal function only coding error causes this
MBED_ASSERT(false);
break;
}