Skip to content

Commit

Permalink
FHSS: fhss tx conditions callbacks added
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Jan 29, 2018
1 parent c1e7300 commit d2957a1
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 93 deletions.
26 changes: 25 additions & 1 deletion source/Service_Libs/fhss/fhss.c
Expand Up @@ -787,6 +787,30 @@ static int fhss_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_addr
return 0;
}

static bool fhss_check_tx_conditions_callback(const fhss_api_t *api, bool is_broadcast_addr, uint8_t handle, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
if (!fhss_structure) {
return false;
}
// This condition will check that message is not sent on bad channel
if (fhss_check_bad_channel(fhss_structure, handle) == false) {
return false;
}

// This condition will check that broadcast messages are sent only broadcast channels
if (fhss_check_channel_type(fhss_structure, is_broadcast_addr, frame_type) == false) {
return false;
}

// This condition will check that FHSS is on TX slot and there is enough time to transmit before channel or slot change
if (fhss_check_tx_allowed(fhss_structure, is_broadcast_addr, frame_length, frame_type, phy_header_length, phy_tail_length) == false) {
return false;
}

return true;
}

static void fhss_update_channel_callback(fhss_structure_t *fhss_structure)
{
if (fhss_structure->current_channel_index == 0) {
Expand Down Expand Up @@ -814,7 +838,7 @@ int fhss_set_callbacks(fhss_structure_t *fhss_structure)
fhss_structure->fhss_api->is_broadcast_channel = &fhss_is_broadcast_channel_cb;
fhss_structure->fhss_api->use_broadcast_queue = &fhss_use_broadcast_queue_cb;
fhss_structure->fhss_api->tx_handle = &fhss_tx_handle_callback;
fhss_structure->fhss_api->check_tx_conditions = &fhss_check_tx_conditions_cb;
fhss_structure->fhss_api->check_tx_conditions = &fhss_check_tx_conditions_callback;
fhss_structure->fhss_api->receive_frame = &fhss_receive_frame_cb;
fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_cb;
fhss_structure->fhss_api->data_tx_fail = &fhss_data_tx_fail_cb;
Expand Down
24 changes: 0 additions & 24 deletions source/Service_Libs/fhss/fhss_mac_interface.c
Expand Up @@ -58,30 +58,6 @@ bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr,
return is_broadcast_addr;
}

bool fhss_check_tx_conditions_cb(const fhss_api_t *api, bool is_broadcast_addr, uint8_t handle, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
if (!fhss_structure) {
return false;
}
// This condition will check that message is not sent on bad channel
if (fhss_check_bad_channel(fhss_structure, handle) == false) {
return false;
}

// This condition will check that broadcast messages are sent only broadcast channels
if (fhss_check_channel_type(fhss_structure, is_broadcast_addr, frame_type) == false) {
return false;
}

// This condition will check that FHSS is on TX slot and there is enough time to transmit before channel or slot change
if (fhss_check_tx_allowed(fhss_structure, is_broadcast_addr, frame_length, frame_type, phy_header_length, phy_tail_length) == false) {
return false;
}

return true;
}

void fhss_receive_frame_cb(const fhss_api_t *api, uint16_t pan_id, uint8_t *source_address, uint32_t timestamp, uint8_t *synch_info, int frame_type)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
Expand Down
1 change: 0 additions & 1 deletion source/Service_Libs/fhss/fhss_mac_interface.h
Expand Up @@ -20,7 +20,6 @@

bool fhss_is_broadcast_channel_cb(const fhss_api_t *api);
bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr, int frame_type);
bool fhss_check_tx_conditions_cb(const fhss_api_t *api, bool is_broadcast_addr, uint8_t handle, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length);
void fhss_receive_frame_cb(const fhss_api_t *api, uint16_t pan_id, uint8_t *source_address, uint32_t timestamp, uint8_t *synch_info, int frame_type);
void fhss_data_tx_done_cb(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle);
bool fhss_data_tx_fail_cb(const fhss_api_t *api, uint8_t handle, int frame_type);
Expand Down
7 changes: 6 additions & 1 deletion source/Service_Libs/fhss/fhss_ws.c
Expand Up @@ -75,13 +75,18 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
return 0;
}

static bool fhss_ws_check_tx_conditions_callback(const fhss_api_t *api, bool is_broadcast_addr, uint8_t handle, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
{
return true;
}

int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure)
{
// Set external API
fhss_structure->fhss_api->is_broadcast_channel = &fhss_is_broadcast_channel_cb;
fhss_structure->fhss_api->use_broadcast_queue = &fhss_use_broadcast_queue_cb;
fhss_structure->fhss_api->tx_handle = &fhss_ws_tx_handle_callback;
fhss_structure->fhss_api->check_tx_conditions = &fhss_check_tx_conditions_cb;
fhss_structure->fhss_api->check_tx_conditions = &fhss_ws_check_tx_conditions_callback;
fhss_structure->fhss_api->receive_frame = &fhss_receive_frame_cb;
fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_cb;
fhss_structure->fhss_api->data_tx_fail = &fhss_data_tx_fail_cb;
Expand Down
5 changes: 5 additions & 0 deletions test/nanostack/unittest/service_libs/fhss/fhsstest.cpp
Expand Up @@ -138,3 +138,8 @@ TEST(fhss, test_fhss_tx_handle_callback)
{
CHECK(test_fhss_tx_handle_callback());
}

TEST(fhss, test_fhss_check_tx_conditions_callback)
{
CHECK(test_fhss_check_tx_conditions_callback());
}
44 changes: 44 additions & 0 deletions test/nanostack/unittest/service_libs/fhss/test_fhss.c
Expand Up @@ -1037,5 +1037,49 @@ bool test_fhss_tx_handle_callback()
return false;
}
free(fhss_struct);
fhss_struct = NULL;
return true;
}

bool test_fhss_check_tx_conditions_callback()
{
fhss_api_t fhss_api;
fhss_struct = malloc(sizeof(fhss_structure_t));
memset(&fhss_struct->fhss_failed_tx_list, 0, sizeof(fhss_failed_tx_list_t));
fhss_struct->fhss_api = &fhss_api;
fhss_set_callbacks(fhss_struct);

uint8_t handle = 10;
fhss_struct->rx_channel = 40;
ns_list_init(&fhss_struct->fhss_failed_tx_list);
nsdynmemlib_stub.returnCounter = 1;

if (fhss_failed_handle_add(fhss_struct, handle) != 0) {
return false;
}

// Test failing bad channel check
if (fhss_struct->fhss_api->check_tx_conditions(&fhss_api, true, handle, FHSS_DATA_FRAME, 100, 0, 0) == true) {
return false;
}
if (fhss_failed_handle_remove(fhss_struct, handle) != 0) {
return false;
}
// Test failing channel type check

fhss_struct->fhss_state = FHSS_SYNCHRONIZED;
if (fhss_struct->fhss_api->check_tx_conditions(&fhss_api, true, 1, FHSS_DATA_FRAME, 100, 0, 0) == true) {
return false;
}
// Test failing TX allowed check
if (fhss_struct->fhss_api->check_tx_conditions(&fhss_api, false, 1, FHSS_DATA_FRAME, 100, 0, 0) == true) {
return false;
}
// Test TX allowed
if (fhss_struct->fhss_api->check_tx_conditions(&fhss_api, true, 1, FHSS_SYNCH_FRAME, 100, 0, 0) == false) {
return false;
}
free(fhss_struct);
fhss_struct = NULL;
return true;
}
2 changes: 2 additions & 0 deletions test/nanostack/unittest/service_libs/fhss/test_fhss.h
Expand Up @@ -67,6 +67,8 @@ bool test_fhss_failed_handle();
bool test_fhss_is_synch_root();
// Test TX handle callback
bool test_fhss_tx_handle_callback();
// Test TX conditions check callback
bool test_fhss_check_tx_conditions_callback();

#ifdef __cplusplus
}
Expand Down
Expand Up @@ -39,11 +39,6 @@ TEST(fhss_mac_if, test_fhss_use_broadcast_queue_cb)
CHECK(test_fhss_use_broadcast_queue_cb());
}

TEST(fhss_mac_if, test_fhss_check_tx_conditions_cb)
{
CHECK(test_fhss_check_tx_conditions_cb());
}

TEST(fhss_mac_if, test_fhss_receive_frame_cb)
{
CHECK(test_fhss_receive_frame_cb());
Expand Down
Expand Up @@ -79,48 +79,6 @@ bool test_fhss_use_broadcast_queue_cb()
return true;
}

bool test_fhss_check_tx_conditions_cb()
{
fhss_api_t fhss_api;

// By setting bool value false, fhss_struct can not be found
fhss_stub.bool_value = false;
if (fhss_check_tx_conditions_cb(&fhss_api, true, 1, FHSS_DATA_FRAME, 100, 0, 0) == true) {
return false;
}
// By setting bool value true, fhss_struct can be found
fhss_stub.bool_value = true;

// Test failing bad channel check
fhss_stub.bad_channel_bool_value = false;
fhss_stub.channel_type_bool_value = true;
fhss_stub.tx_allowed_bool_value = true;
if (fhss_check_tx_conditions_cb(&fhss_api, true, 1, FHSS_DATA_FRAME, 100, 0, 0) == true) {
return false;
}
// Test failing channel type check
fhss_stub.bad_channel_bool_value = true;
fhss_stub.channel_type_bool_value = false;
fhss_stub.tx_allowed_bool_value = true;
if (fhss_check_tx_conditions_cb(&fhss_api, true, 1, FHSS_DATA_FRAME, 100, 0, 0) == true) {
return false;
}
// Test failing TX allowed check
fhss_stub.bad_channel_bool_value = true;
fhss_stub.channel_type_bool_value = true;
fhss_stub.tx_allowed_bool_value = false;
if (fhss_check_tx_conditions_cb(&fhss_api, true, 1, FHSS_DATA_FRAME, 100, 0, 0) == true) {
return false;
}
// Test TX allowed
fhss_stub.bad_channel_bool_value = true;
fhss_stub.channel_type_bool_value = true;
fhss_stub.tx_allowed_bool_value = true;
if (fhss_check_tx_conditions_cb(&fhss_api, true, 1, FHSS_DATA_FRAME, 100, 0, 0) == false) {
return false;
}
return true;
}
bool test_fhss_receive_frame_cb()
{
fhss_api_t fhss_api;
Expand Down
Expand Up @@ -26,8 +26,6 @@ extern "C" {
bool test_fhss_is_broadcast_channel_cb();
// Test broadcast queue check callback
bool test_fhss_use_broadcast_queue_cb();
// Test TX conditions check callback
bool test_fhss_check_tx_conditions_cb();
// Test frame receive callback
bool test_fhss_receive_frame_cb();
// Test TX done callback
Expand Down
2 changes: 0 additions & 2 deletions test/nanostack/unittest/stub/fhss_config_stub.c
Expand Up @@ -28,8 +28,6 @@ fhss_api_t *ns_fhss_create(const fhss_configuration_t *fhss_configuration, const
{
fhss_config_stub.fhss_api_ptr.is_broadcast_channel = &fhss_is_broadcast_channel_cb;
fhss_config_stub.fhss_api_ptr.use_broadcast_queue = &fhss_use_broadcast_queue_cb;
fhss_config_stub.fhss_api_ptr.tx_handle = &fhss_tx_handle_cb;
fhss_config_stub.fhss_api_ptr.check_tx_conditions = &fhss_check_tx_conditions_cb;
fhss_config_stub.fhss_api_ptr.receive_frame = &fhss_receive_frame_cb;
fhss_config_stub.fhss_api_ptr.data_tx_done = &fhss_data_tx_done_cb;
fhss_config_stub.fhss_api_ptr.data_tx_fail = &fhss_data_tx_fail_cb;
Expand Down
15 changes: 0 additions & 15 deletions test/nanostack/unittest/stub/fhss_mac_interface_stub.c
Expand Up @@ -33,21 +33,6 @@ bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr,
return fhss_mac_interface_stub.queue_bool_value;
}

int fhss_tx_handle_cb(const fhss_api_t *api, bool is_broadcast_addr, uint8_t *destination_address, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
{
fhss_mac_interface_stub.int8_value++;
return fhss_mac_interface_stub.handle_value;
}

bool fhss_check_tx_conditions_cb(const fhss_api_t *api, bool is_broadcast_addr, uint8_t handle, int frame_type, uint16_t frame_length, uint8_t phy_header_length, uint8_t phy_tail_length)
{
fhss_mac_interface_stub.int8_value++;
if (frame_type == FHSS_SYNCH_REQUEST_FRAME) {
return false;
}
return fhss_mac_interface_stub.cond_bool_value;
}

void fhss_receive_frame_cb(const fhss_api_t *api, uint16_t pan_id, uint8_t *source_address, uint32_t timestamp, uint8_t *synch_info, int frame_type)
{
fhss_mac_interface_stub.int8_value++;
Expand Down

0 comments on commit d2957a1

Please sign in to comment.