Skip to content

Commit

Permalink
FHSS: Few FHSS functions to static
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Jan 30, 2018
1 parent 7237796 commit 958991a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 301 deletions.
10 changes: 5 additions & 5 deletions source/Service_Libs/fhss/fhss.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static bool fhss_is_bc_sending_superframe(fhss_structure_t *fhss_structure)
return false;
}

bool fhss_check_bad_channel(fhss_structure_t *fhss_structure, uint8_t handle)
static bool fhss_check_bad_channel(fhss_structure_t *fhss_structure, uint8_t handle)
{
if (!fhss_structure) {
return false;
Expand All @@ -71,7 +71,7 @@ bool fhss_check_bad_channel(fhss_structure_t *fhss_structure, uint8_t handle)
return true;
}

bool fhss_check_channel_type(fhss_structure_t *fhss_structure, bool is_bc, int frame_type)
static bool fhss_check_channel_type(fhss_structure_t *fhss_structure, bool is_bc, int frame_type)
{
if (!fhss_structure) {
return false;
Expand Down Expand Up @@ -127,7 +127,7 @@ bool fhss_check_channel_type(fhss_structure_t *fhss_structure, bool is_bc, int f

}

bool fhss_check_tx_allowed(fhss_structure_t *fhss_structure, bool is_bc, uint16_t frame_length, int frame_type, uint8_t phy_header_length, uint8_t phy_tail_length)
static bool fhss_check_tx_allowed(fhss_structure_t *fhss_structure, bool is_bc, uint16_t frame_length, int frame_type, uint8_t phy_header_length, uint8_t phy_tail_length)
{
if (!fhss_structure) {
return false;
Expand Down Expand Up @@ -495,7 +495,7 @@ static int fhss_generate_scramble_table(fhss_structure_t *fhss_structure)
return 0;
}

fhss_beacon_info_t *fhss_get_beacon_info(fhss_structure_t *fhss_structure, uint16_t pan_id)
static fhss_beacon_info_t *fhss_get_beacon_info(fhss_structure_t *fhss_structure, uint16_t pan_id)
{
fhss_beacon_info_t *beacon_info;
beacon_info = fhss_structure->fhss_beacon_info_store;
Expand Down Expand Up @@ -570,7 +570,7 @@ static int fhss_remove_beacon_info(fhss_structure_t *fhss_structure, uint16_t pa
return -1;
}

int fhss_flush_beacon_info_storage(fhss_structure_t *fhss_structure)
static int fhss_flush_beacon_info_storage(fhss_structure_t *fhss_structure)
{
if (!fhss_structure) {
return -1;
Expand Down
5 changes: 0 additions & 5 deletions source/Service_Libs/fhss/fhss.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ struct fhss_failed_tx
};

bool fhss_is_synch_root(fhss_structure_t *fhss_structure);
bool fhss_check_bad_channel(fhss_structure_t *fhss_structure, uint8_t handle);
bool fhss_check_channel_type(fhss_structure_t *fhss_structure, bool is_bc, int frame_type);
bool fhss_check_tx_allowed(fhss_structure_t *fhss_structure, bool is_bc, uint16_t frame_length, int frame_type, uint8_t phy_header_length, uint8_t phy_tail_length);
fhss_beacon_info_t *fhss_get_beacon_info(fhss_structure_t *fhss_structure, uint16_t pan_id);
int fhss_flush_beacon_info_storage(fhss_structure_t *fhss_structure);
int fhss_add_beacon_info(fhss_structure_t *fhss_structure, uint16_t pan_id, uint8_t *source_address, uint32_t timestamp, uint8_t *synch_info);
void fhss_update_beacon_info_lifetimes(fhss_structure_t *fhss_structure, uint32_t timestamp);
uint32_t fhss_get_tx_time(fhss_structure_t *fhss_structure, uint16_t bytes_to_send, uint8_t phy_header_length, uint8_t phy_tail_length);
Expand Down
15 changes: 0 additions & 15 deletions test/nanostack/unittest/service_libs/fhss/fhsstest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,6 @@ TEST(fhss, test_fhss_set_synch_configuration)
CHECK(test_fhss_set_synch_configuration());
}

TEST(fhss, test_fhss_check_bad_channel)
{
CHECK(test_fhss_check_bad_channel());
}

TEST(fhss, test_fhss_check_tx_allowed)
{
CHECK(test_fhss_check_tx_allowed());
}

TEST(fhss, test_fhss_check_channel_type)
{
CHECK(test_fhss_check_channel_type());
}

TEST(fhss, test_fhss_disable)
{
CHECK(test_fhss_disable());
Expand Down
273 changes: 3 additions & 270 deletions test/nanostack/unittest/service_libs/fhss/test_fhss.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,268 +101,6 @@ bool test_fhss_disable()
return true;
}

bool test_fhss_check_channel_type()
{
fhss_struct = malloc(sizeof(fhss_structure_t));

// Test NULL API
if (fhss_check_channel_type(NULL, true, FHSS_DATA_FRAME) == true) {
return false;
}
// Test unsynchronized state. (Should allow transmission)
fhss_struct->fhss_state = FHSS_UNSYNCHRONIZED;
if (fhss_check_channel_type(fhss_struct, true, FHSS_DATA_FRAME) == false) {
return false;
}
// Change to synchronized mode
fhss_struct->fhss_state = FHSS_SYNCHRONIZED;

// Test data frame, broadcast destination, unicast channel. (Should deny transmission)
fhss_channel_stub.channel_bool_value = false;
if (fhss_check_channel_type(fhss_struct, true, FHSS_DATA_FRAME) == true) {
return false;
}

// Test data frame, unicast destination, broadcast channel, waiting synchronization Beacon. (Should deny transmission)
fhss_channel_stub.channel_bool_value = true;
fhss_struct->beacons_received_timer = 1;
if (fhss_check_channel_type(fhss_struct, false, FHSS_DATA_FRAME) == true) {
return false;
}

// Test synch request frame, currently on broadcast channel. (Should deny transmission)
fhss_channel_stub.channel_bool_value = true;
fhss_struct->synch_configuration.fhss_number_of_bc_channels = 10;
fhss_struct->number_of_channels = 50;
if (fhss_check_channel_type(fhss_struct, true, FHSS_SYNCH_REQUEST_FRAME) == true) {
return false;
}

// Test synch request frame, currently on unicast channel, superframe is 0. (Should deny transmission)
fhss_channel_stub.channel_bool_value = false;
fhss_struct->current_superframe = 0;
fhss_struct->beacons_received_timer = 1;
fhss_struct->synch_configuration.fhss_number_of_superframes = 8;
if (fhss_check_channel_type(fhss_struct, true, FHSS_SYNCH_REQUEST_FRAME) == true) {
return false;
}

// Test data frame, broadcast destination, broadcast channel. (Should allow transmission)
fhss_struct->synch_configuration.fhss_number_of_superframes = 8;
fhss_struct->broadcast_start_superframe = 2;
fhss_struct->current_superframe = 3;
fhss_channel_stub.channel_bool_value = true;
if (fhss_check_channel_type(fhss_struct, true, FHSS_DATA_FRAME) == false) {
return false;
}

// Test data frame, unicast destination, unicast channel. (Should allow transmission)
fhss_channel_stub.channel_bool_value = false;
if (fhss_check_channel_type(fhss_struct, false, FHSS_DATA_FRAME) == false) {
return false;
}

// Test data frame, unicast destination, broadcast channel, not waiting synchronization Beacon. (Should allow transmission)
fhss_channel_stub.channel_bool_value = true;
fhss_struct->beacons_received_timer = 0;
if (fhss_check_channel_type(fhss_struct, false, FHSS_DATA_FRAME) == false) {
return false;
}

// Test immediate synch frame, sent on any channel. (Should allow transmission)
fhss_channel_stub.channel_bool_value = false;
fhss_struct->current_superframe = 1;
if (fhss_check_channel_type(fhss_struct, true, FHSS_SYNCH_FRAME) == false) {
return false;
}

// Test synch request frame, currently on broadcast channel, number of BC channel equals number of channels, current superframe is 1. (Should allow transmission)
fhss_channel_stub.channel_bool_value = true;
fhss_struct->synch_configuration.fhss_number_of_bc_channels = 50;
fhss_struct->number_of_channels = 50;
fhss_struct->current_superframe = 1;
if (fhss_check_channel_type(fhss_struct, true, FHSS_SYNCH_REQUEST_FRAME) == false) {
return false;
}

// Test sending broadcast when number of superframes is low.
fhss_channel_stub.channel_bool_value = true;
fhss_struct->broadcast_start_superframe = 0;
fhss_struct->current_superframe = 0;
fhss_struct->synch_configuration.fhss_number_of_superframes = 4;
if (fhss_check_channel_type(fhss_struct, true, FHSS_DATA_FRAME) == false) {
return false;
}

// Test sending broadcast when not on broadcast sending superframe.
fhss_channel_stub.channel_bool_value = true;
fhss_struct->synch_configuration.fhss_number_of_superframes = 8;
fhss_struct->broadcast_start_superframe = 2;
fhss_struct->current_superframe = 0;
if (fhss_check_channel_type(fhss_struct, true, FHSS_DATA_FRAME) == true) {
return false;
}

// Test sending broadcast when on broadcast sending superframe.
fhss_channel_stub.channel_bool_value = true;
fhss_struct->synch_configuration.fhss_number_of_superframes = 8;
fhss_struct->broadcast_start_superframe = 2;
fhss_struct->current_superframe = 2;
if (fhss_check_channel_type(fhss_struct, true, FHSS_DATA_FRAME) == false) {
return false;
}

// Test synch request frame, above the middle of superframes, should return false
fhss_channel_stub.channel_bool_value = false;
fhss_struct->current_superframe = 5;
fhss_struct->beacons_received_timer = 0;
fhss_struct->synch_configuration.fhss_number_of_superframes = 8;
if (fhss_check_channel_type(fhss_struct, true, FHSS_SYNCH_REQUEST_FRAME) == true) {
return false;
}

// Test synch request frame, when number of TX slots 1 and on first superframe, should return false
fhss_channel_stub.channel_bool_value = false;
fhss_struct->current_superframe = 0;
fhss_struct->beacons_received_timer = 0;
fhss_struct->synch_configuration.fhss_number_of_superframes = 8;
fhss_struct->synch_configuration.fhss_number_of_tx_slots = 1;
if (fhss_check_channel_type(fhss_struct, true, FHSS_SYNCH_REQUEST_FRAME) == true) {
return false;
}

free(fhss_struct);
fhss_struct = NULL;
return true;
}

bool test_fhss_check_tx_allowed()
{
fhss_struct = malloc(sizeof(fhss_structure_t));
// Initialize FHSS configuration
fhss_struct->datarate = 250000;
fhss_struct->fhss_configuration.fhss_tuning_parameters.tx_processing_delay = 1000;
fhss_struct->fhss_configuration.fhss_tuning_parameters.ack_processing_delay = 1000;
/*...| TX | TX | RX | RX | TX | TX | RX | RX |...
*...| SF n | SF n+1 | SF n+2 | SF n+3 | SF n+4 | SF n+5 | SF n+6 | SF n+7 |...
*/
fhss_struct->current_superframe = 1; // SF n+1
fhss_struct->synch_configuration.fhss_number_of_tx_slots = 2;
fhss_struct->synch_configuration.fhss_number_of_superframes = 8;
fhss_struct->synch_configuration.fhss_superframe_length = 50000;
fhss_struct->own_hop = 2; // For even hop count TX superframes are 0, 1 and 4, 5
fhss_struct->platform_functions.fhss_get_remaining_slots = &fhss_get_remaining_slots_stub;
fhss_struct->platform_functions.fhss_resolution_divider = 1;

// Remaining time(us) to next superframe change. This is what get_remaining_slot -call returns
fhss_platform_stub.uint32_value = 40000;

// When transmitting 100 bytes + Ack (+ processing delays), needed transmission time is around 7.4ms

// FHSS is on RX slot
fhss_struct->tx_allowed = false;
// Test NULL API
if (fhss_check_tx_allowed(NULL, true, 100, FHSS_DATA_FRAME, 0, 0) == true) {
return false;
}

// Test unsynchronized state. (Should allow transmission)
fhss_struct->fhss_state = FHSS_UNSYNCHRONIZED;
if (fhss_check_tx_allowed(fhss_struct, false, 100, FHSS_DATA_FRAME, 0, 0) == false) {
return false;
}

// Change to synchronized mode
fhss_struct->fhss_state = FHSS_SYNCHRONIZED;

// Test synchronization frame. (Should allow transmission)
if (fhss_check_tx_allowed(fhss_struct, false, 100, FHSS_SYNCH_FRAME, 0, 0) == false) {
return false;
}

// Test broadcast frame. (Should allow transmission)
if (fhss_check_tx_allowed(fhss_struct, true, 100, FHSS_DATA_FRAME, 0, 0) == false) {
return false;
}

// Test TX allowed flag. (Should deny transmission)
if (fhss_check_tx_allowed(fhss_struct, false, 100, FHSS_DATA_FRAME, 0, 0) == true) {
return false;
}

// FHSS is on TX slot
fhss_struct->tx_allowed = true;
// Test TX allowed flag. (Should allow transmission)
if (fhss_check_tx_allowed(fhss_struct, false, 100, FHSS_DATA_FRAME, 0, 0) == false) {
return false;
}

// Return too small remaining time(us). (Should deny transmission)
fhss_platform_stub.uint32_value = 7000;
if (fhss_check_tx_allowed(fhss_struct, false, 100, FHSS_DATA_FRAME, 0, 0) == true) {
return false;
}

// Use higher datarate. (Should allow transmission)
fhss_struct->datarate = 300000;
if (fhss_check_tx_allowed(fhss_struct, false, 100, FHSS_DATA_FRAME, 0, 0) == false) {
return false;
}

// Test adding header and tail bytes (100 bytes for data and ack frame means 6.4ms more TX time needed. 13.8ms total). (Should deny transmission)
fhss_struct->datarate = 250000;
fhss_platform_stub.uint32_value = 13700;
if (fhss_check_tx_allowed(fhss_struct, false, 100, FHSS_DATA_FRAME, 50, 50) == true) {
return false;
}

// Test odd hop count. (Should deny transmission)
fhss_struct->own_hop = 1;
if (fhss_check_tx_allowed(fhss_struct, false, 100, FHSS_DATA_FRAME, 0, 0) == true) {
return false;
}

free(fhss_struct);
fhss_struct = NULL;
return true;
}

bool test_fhss_check_bad_channel()
{
fhss_struct = malloc(sizeof(fhss_structure_t));
memset(&fhss_struct->fhss_failed_tx_list, 0, sizeof(fhss_failed_tx_list_t));
// Test NULL API
if (fhss_check_bad_channel(NULL, 0) == true) {
return false;
}
// Test with proper API
if (fhss_check_bad_channel(fhss_struct, 0) == false) {
return false;
}
// Test when bad channel is found
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;
}
if (fhss_check_bad_channel(fhss_struct, handle) == true) {
return false;
}
// After channel change should return false
fhss_struct->rx_channel = 41;
if (fhss_check_bad_channel(fhss_struct, handle) == false) {
return false;
}
if (fhss_failed_handle_remove(fhss_struct, handle) != 0) {
return false;
}
free(fhss_struct);
fhss_struct = NULL;
}

bool test_fhss_set_synch_configuration()
{
fhss_struct = malloc(sizeof(fhss_structure_t));
Expand Down Expand Up @@ -509,14 +247,9 @@ bool test_fhss_add_beacon_info()
if ((fhss_struct->fhss_beacon_info_store->next->pan_id != panid + 1) || memcmp(fhss_struct->fhss_beacon_info_store->next->source_address, compare_array, 8)) {
return false;
}
// Test flushing Beacon storage without FHSS structure
if (fhss_flush_beacon_info_storage(NULL) != -1) {
return false;
}
// Test flushing Beacon storage
if (fhss_flush_beacon_info_storage(fhss_struct) != 0) {
return false;
}
free(fhss_struct->fhss_beacon_info_store->next->next);
free(fhss_struct->fhss_beacon_info_store->next);
free(fhss_struct->fhss_beacon_info_store);
free(fhss_struct);
fhss_struct = 0;
return true;
Expand Down
6 changes: 0 additions & 6 deletions test/nanostack/unittest/service_libs/fhss/test_fhss.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ extern "C" {
bool test_fhss_enable();
// Test disabling FHSS
bool test_fhss_disable();
// Test channel type TX condition
bool test_fhss_check_channel_type();
// Test TX allowed TX condition
bool test_fhss_check_tx_allowed();
// Test bad channel TX condition
bool test_fhss_check_bad_channel();
// Test synchronization time configuration
bool test_fhss_set_synch_configuration();
// Test storing Beacon info
Expand Down

0 comments on commit 958991a

Please sign in to comment.