Skip to content

Commit

Permalink
FHSS: fhss tx handle callbacks added
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Jan 29, 2018
1 parent 0cc1889 commit 1d54c7d
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 73 deletions.
29 changes: 28 additions & 1 deletion source/Service_Libs/fhss/fhss.c
Expand Up @@ -760,6 +760,33 @@ static void fhss_superframe_callback(fhss_structure_t *fhss_structure)
}
}

static int fhss_tx_handle_callback(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_structure_t *fhss_structure = fhss_get_object_with_api(api);
if (!fhss_structure) {
return -2;
}
// TODO: needs some more logic to push buffer back to queue
if (frame_type == FHSS_DATA_FRAME) {
if (is_broadcast_addr == true) {
if (fhss_is_current_channel_broadcast(fhss_structure) == false) {
tr_info("Broadcast on UC channel -> Back to queue");
return -3;
}
}
}
if (fhss_check_tx_allowed(fhss_structure, is_broadcast_addr, frame_length, frame_type, phy_header_length, phy_tail_length) == false) {
return -1;
}
// If sending Beacon request on parents Unicast channel
if (frame_type == FHSS_SYNCH_REQUEST_FRAME && fhss_structure->fhss_state == FHSS_SYNCHRONIZED) {
fhss_change_to_parent_channel(fhss_structure);
} else if (frame_type == FHSS_DATA_FRAME) {
fhss_change_to_tx_channel(fhss_structure, destination_address);
}
return 0;
}

static void fhss_update_channel_callback(fhss_structure_t *fhss_structure)
{
if (fhss_structure->current_channel_index == 0) {
Expand All @@ -786,7 +813,7 @@ int fhss_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_tx_handle_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->receive_frame = &fhss_receive_frame_cb;
fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_cb;
Expand Down
27 changes: 0 additions & 27 deletions source/Service_Libs/fhss/fhss_mac_interface.c
Expand Up @@ -58,33 +58,6 @@ bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr,
return is_broadcast_addr;
}

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_structure_t *fhss_structure = fhss_get_object_with_api(api);
if (!fhss_structure) {
return -2;
}
// TODO: needs some more logic to push buffer back to queue
if (frame_type == FHSS_DATA_FRAME) {
if (is_broadcast_addr == true) {
if (fhss_is_current_channel_broadcast(fhss_structure) == false) {
tr_info("Broadcast on UC channel -> Back to queue");
return -3;
}
}
}
if (fhss_check_tx_allowed(fhss_structure, is_broadcast_addr, frame_length, frame_type, phy_header_length, phy_tail_length) == false) {
return -1;
}
// If sending Beacon request on parents Unicast channel
if (frame_type == FHSS_SYNCH_REQUEST_FRAME && fhss_structure->fhss_state == FHSS_SYNCHRONIZED) {
fhss_change_to_parent_channel(fhss_structure);
} else if (frame_type == FHSS_DATA_FRAME) {
fhss_change_to_tx_channel(fhss_structure, destination_address);
}
return 0;
}

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);
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);
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);
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);
Expand Down
7 changes: 6 additions & 1 deletion source/Service_Libs/fhss/fhss_ws.c
Expand Up @@ -68,12 +68,17 @@ static void fhss_ws_update_channel_callback(fhss_structure_t *fhss_structure)
fhss_structure->callbacks.change_channel(fhss_structure->fhss_api, next_channel);
}

static int fhss_ws_tx_handle_callback(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)
{
return 0;
}

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_tx_handle_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->receive_frame = &fhss_receive_frame_cb;
fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_cb;
Expand Down
5 changes: 5 additions & 0 deletions test/nanostack/unittest/service_libs/fhss/fhsstest.cpp
Expand Up @@ -133,3 +133,8 @@ TEST(fhss, test_fhss_is_synch_root)
{
CHECK(test_fhss_is_synch_root());
}

TEST(fhss, test_fhss_tx_handle_callback)
{
CHECK(test_fhss_tx_handle_callback());
}
36 changes: 36 additions & 0 deletions test/nanostack/unittest/service_libs/fhss/test_fhss.c
Expand Up @@ -1003,3 +1003,39 @@ bool test_fhss_is_synch_root()
fhss_struct = NULL;
return true;
}

bool test_fhss_tx_handle_callback()
{
fhss_api_t fhss_api;
fhss_struct = malloc(sizeof(fhss_structure_t));
fhss_struct->fhss_api = &fhss_api;
fhss_struct->datarate = 250000;
fhss_struct->synch_configuration.fhss_number_of_tx_slots = 1;
fhss_set_callbacks(fhss_struct);
// Broadcast data on unicast channel should return -3
if (fhss_struct->fhss_api->tx_handle(&fhss_api, true, NULL, FHSS_DATA_FRAME, 0, 0, 0) != -3) {
return false;
}
// Test sending of Beacon
if (fhss_struct->fhss_api->tx_handle(&fhss_api, true, NULL, FHSS_SYNCH_FRAME, 0, 0, 0) != 0) {
return false;
}
// When TX is not allowed, should return -1 for data frame
fhss_struct->tx_allowed = false;
fhss_struct->fhss_state = FHSS_SYNCHRONIZED;
if (fhss_struct->fhss_api->tx_handle(&fhss_api, false, NULL, FHSS_DATA_FRAME, 0, 0, 0) != -1) {
return false;
}
// When TX is allowed, should return 0 for data frame
fhss_struct->tx_allowed = true;
fhss_struct->fhss_state = FHSS_UNSYNCHRONIZED;
if (fhss_struct->fhss_api->tx_handle(&fhss_api, false, NULL, FHSS_DATA_FRAME, 0, 0, 0) != 0) {
return false;
}
// Test changing to parent channel to send synch request
if (fhss_struct->fhss_api->tx_handle(&fhss_api, false, NULL, FHSS_SYNCH_REQUEST_FRAME, 0, 0, 0) != 0) {
return false;
}
free(fhss_struct);
return true;
}
2 changes: 2 additions & 0 deletions test/nanostack/unittest/service_libs/fhss/test_fhss.h
Expand Up @@ -65,6 +65,8 @@ bool test_fhss_update_beacon_info_lifetimes();
bool test_fhss_failed_handle();
// Test synch root check
bool test_fhss_is_synch_root();
// Test TX handle callback
bool test_fhss_tx_handle_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_tx_handle_cb)
{
CHECK(test_fhss_tx_handle_cb());
}

TEST(fhss_mac_if, test_fhss_check_tx_conditions_cb)
{
CHECK(test_fhss_check_tx_conditions_cb());
Expand Down
Expand Up @@ -78,43 +78,7 @@ bool test_fhss_use_broadcast_queue_cb()
}
return true;
}
bool test_fhss_tx_handle_cb()
{
fhss_api_t fhss_api;

// By setting bool value false, fhss_struct can not be found
fhss_stub.bool_value = false;
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_DATA_FRAME, 0, 0, 0) != -2) {
return false;
}
// By setting bool value true, fhss_struct can be found
fhss_stub.bool_value = true;
// Broadcast data on unicast channel should return -3
fhss_channel_stub.channel_bool_value = false;
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_DATA_FRAME, 0, 0, 0) != -3) {
return false;
}
// Test sending of Beacon
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_SYNCH_FRAME, 0, 0, 0) != 0) {
return false;
}
// When TX is not allowed, should return -1 for data frame
fhss_stub.tx_allowed_bool_value = false;
if (fhss_tx_handle_cb(&fhss_api, false, NULL, FHSS_DATA_FRAME, 0, 0, 0) != -1) {
return false;
}
// When TX is allowed, should return 0 for data frame
fhss_stub.tx_allowed_bool_value = true;
if (fhss_tx_handle_cb(&fhss_api, false, NULL, FHSS_DATA_FRAME, 0, 0, 0) != 0) {
return false;
}
// Test changing to parent channel to send synch request
fhss_stub.fhss_struct.fhss_state = FHSS_SYNCHRONIZED;
if (fhss_tx_handle_cb(&fhss_api, false, NULL, FHSS_SYNCH_REQUEST_FRAME, 0, 0, 0) != 0) {
return false;
}
return true;
}
bool test_fhss_check_tx_conditions_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 handle callback
bool test_fhss_tx_handle_cb();
// Test TX conditions check callback
bool test_fhss_check_tx_conditions_cb();
// Test frame receive callback
Expand Down

0 comments on commit 1d54c7d

Please sign in to comment.