Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit d2957a1

Browse files
author
Jarkko Paso
committed
FHSS: fhss tx conditions callbacks added
1 parent c1e7300 commit d2957a1

File tree

12 files changed

+82
-93
lines changed

12 files changed

+82
-93
lines changed

source/Service_Libs/fhss/fhss.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,30 @@ static int fhss_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_addr
787787
return 0;
788788
}
789789

790+
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)
791+
{
792+
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
793+
if (!fhss_structure) {
794+
return false;
795+
}
796+
// This condition will check that message is not sent on bad channel
797+
if (fhss_check_bad_channel(fhss_structure, handle) == false) {
798+
return false;
799+
}
800+
801+
// This condition will check that broadcast messages are sent only broadcast channels
802+
if (fhss_check_channel_type(fhss_structure, is_broadcast_addr, frame_type) == false) {
803+
return false;
804+
}
805+
806+
// This condition will check that FHSS is on TX slot and there is enough time to transmit before channel or slot change
807+
if (fhss_check_tx_allowed(fhss_structure, is_broadcast_addr, frame_length, frame_type, phy_header_length, phy_tail_length) == false) {
808+
return false;
809+
}
810+
811+
return true;
812+
}
813+
790814
static void fhss_update_channel_callback(fhss_structure_t *fhss_structure)
791815
{
792816
if (fhss_structure->current_channel_index == 0) {
@@ -814,7 +838,7 @@ int fhss_set_callbacks(fhss_structure_t *fhss_structure)
814838
fhss_structure->fhss_api->is_broadcast_channel = &fhss_is_broadcast_channel_cb;
815839
fhss_structure->fhss_api->use_broadcast_queue = &fhss_use_broadcast_queue_cb;
816840
fhss_structure->fhss_api->tx_handle = &fhss_tx_handle_callback;
817-
fhss_structure->fhss_api->check_tx_conditions = &fhss_check_tx_conditions_cb;
841+
fhss_structure->fhss_api->check_tx_conditions = &fhss_check_tx_conditions_callback;
818842
fhss_structure->fhss_api->receive_frame = &fhss_receive_frame_cb;
819843
fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_cb;
820844
fhss_structure->fhss_api->data_tx_fail = &fhss_data_tx_fail_cb;

source/Service_Libs/fhss/fhss_mac_interface.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,6 @@ bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr,
5858
return is_broadcast_addr;
5959
}
6060

61-
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)
62-
{
63-
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
64-
if (!fhss_structure) {
65-
return false;
66-
}
67-
// This condition will check that message is not sent on bad channel
68-
if (fhss_check_bad_channel(fhss_structure, handle) == false) {
69-
return false;
70-
}
71-
72-
// This condition will check that broadcast messages are sent only broadcast channels
73-
if (fhss_check_channel_type(fhss_structure, is_broadcast_addr, frame_type) == false) {
74-
return false;
75-
}
76-
77-
// This condition will check that FHSS is on TX slot and there is enough time to transmit before channel or slot change
78-
if (fhss_check_tx_allowed(fhss_structure, is_broadcast_addr, frame_length, frame_type, phy_header_length, phy_tail_length) == false) {
79-
return false;
80-
}
81-
82-
return true;
83-
}
84-
8561
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)
8662
{
8763
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);

source/Service_Libs/fhss/fhss_mac_interface.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
bool fhss_is_broadcast_channel_cb(const fhss_api_t *api);
2222
bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr, int frame_type);
23-
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);
2423
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);
2524
void fhss_data_tx_done_cb(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle);
2625
bool fhss_data_tx_fail_cb(const fhss_api_t *api, uint8_t handle, int frame_type);

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,18 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
7575
return 0;
7676
}
7777

78+
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)
79+
{
80+
return true;
81+
}
82+
7883
int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure)
7984
{
8085
// Set external API
8186
fhss_structure->fhss_api->is_broadcast_channel = &fhss_is_broadcast_channel_cb;
8287
fhss_structure->fhss_api->use_broadcast_queue = &fhss_use_broadcast_queue_cb;
8388
fhss_structure->fhss_api->tx_handle = &fhss_ws_tx_handle_callback;
84-
fhss_structure->fhss_api->check_tx_conditions = &fhss_check_tx_conditions_cb;
89+
fhss_structure->fhss_api->check_tx_conditions = &fhss_ws_check_tx_conditions_callback;
8590
fhss_structure->fhss_api->receive_frame = &fhss_receive_frame_cb;
8691
fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_cb;
8792
fhss_structure->fhss_api->data_tx_fail = &fhss_data_tx_fail_cb;

test/nanostack/unittest/service_libs/fhss/fhsstest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,8 @@ TEST(fhss, test_fhss_tx_handle_callback)
138138
{
139139
CHECK(test_fhss_tx_handle_callback());
140140
}
141+
142+
TEST(fhss, test_fhss_check_tx_conditions_callback)
143+
{
144+
CHECK(test_fhss_check_tx_conditions_callback());
145+
}

test/nanostack/unittest/service_libs/fhss/test_fhss.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,5 +1037,49 @@ bool test_fhss_tx_handle_callback()
10371037
return false;
10381038
}
10391039
free(fhss_struct);
1040+
fhss_struct = NULL;
1041+
return true;
1042+
}
1043+
1044+
bool test_fhss_check_tx_conditions_callback()
1045+
{
1046+
fhss_api_t fhss_api;
1047+
fhss_struct = malloc(sizeof(fhss_structure_t));
1048+
memset(&fhss_struct->fhss_failed_tx_list, 0, sizeof(fhss_failed_tx_list_t));
1049+
fhss_struct->fhss_api = &fhss_api;
1050+
fhss_set_callbacks(fhss_struct);
1051+
1052+
uint8_t handle = 10;
1053+
fhss_struct->rx_channel = 40;
1054+
ns_list_init(&fhss_struct->fhss_failed_tx_list);
1055+
nsdynmemlib_stub.returnCounter = 1;
1056+
1057+
if (fhss_failed_handle_add(fhss_struct, handle) != 0) {
1058+
return false;
1059+
}
1060+
1061+
// Test failing bad channel check
1062+
if (fhss_struct->fhss_api->check_tx_conditions(&fhss_api, true, handle, FHSS_DATA_FRAME, 100, 0, 0) == true) {
1063+
return false;
1064+
}
1065+
if (fhss_failed_handle_remove(fhss_struct, handle) != 0) {
1066+
return false;
1067+
}
1068+
// Test failing channel type check
1069+
1070+
fhss_struct->fhss_state = FHSS_SYNCHRONIZED;
1071+
if (fhss_struct->fhss_api->check_tx_conditions(&fhss_api, true, 1, FHSS_DATA_FRAME, 100, 0, 0) == true) {
1072+
return false;
1073+
}
1074+
// Test failing TX allowed check
1075+
if (fhss_struct->fhss_api->check_tx_conditions(&fhss_api, false, 1, FHSS_DATA_FRAME, 100, 0, 0) == true) {
1076+
return false;
1077+
}
1078+
// Test TX allowed
1079+
if (fhss_struct->fhss_api->check_tx_conditions(&fhss_api, true, 1, FHSS_SYNCH_FRAME, 100, 0, 0) == false) {
1080+
return false;
1081+
}
1082+
free(fhss_struct);
1083+
fhss_struct = NULL;
10401084
return true;
10411085
}

test/nanostack/unittest/service_libs/fhss/test_fhss.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ bool test_fhss_failed_handle();
6767
bool test_fhss_is_synch_root();
6868
// Test TX handle callback
6969
bool test_fhss_tx_handle_callback();
70+
// Test TX conditions check callback
71+
bool test_fhss_check_tx_conditions_callback();
7072

7173
#ifdef __cplusplus
7274
}

test/nanostack/unittest/service_libs/fhss_mac_interface/fhssmaciftest.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ TEST(fhss_mac_if, test_fhss_use_broadcast_queue_cb)
3939
CHECK(test_fhss_use_broadcast_queue_cb());
4040
}
4141

42-
TEST(fhss_mac_if, test_fhss_check_tx_conditions_cb)
43-
{
44-
CHECK(test_fhss_check_tx_conditions_cb());
45-
}
46-
4742
TEST(fhss_mac_if, test_fhss_receive_frame_cb)
4843
{
4944
CHECK(test_fhss_receive_frame_cb());

test/nanostack/unittest/service_libs/fhss_mac_interface/test_fhss_mac_interface.c

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -79,48 +79,6 @@ bool test_fhss_use_broadcast_queue_cb()
7979
return true;
8080
}
8181

82-
bool test_fhss_check_tx_conditions_cb()
83-
{
84-
fhss_api_t fhss_api;
85-
86-
// By setting bool value false, fhss_struct can not be found
87-
fhss_stub.bool_value = false;
88-
if (fhss_check_tx_conditions_cb(&fhss_api, true, 1, FHSS_DATA_FRAME, 100, 0, 0) == true) {
89-
return false;
90-
}
91-
// By setting bool value true, fhss_struct can be found
92-
fhss_stub.bool_value = true;
93-
94-
// Test failing bad channel check
95-
fhss_stub.bad_channel_bool_value = false;
96-
fhss_stub.channel_type_bool_value = true;
97-
fhss_stub.tx_allowed_bool_value = true;
98-
if (fhss_check_tx_conditions_cb(&fhss_api, true, 1, FHSS_DATA_FRAME, 100, 0, 0) == true) {
99-
return false;
100-
}
101-
// Test failing channel type check
102-
fhss_stub.bad_channel_bool_value = true;
103-
fhss_stub.channel_type_bool_value = false;
104-
fhss_stub.tx_allowed_bool_value = true;
105-
if (fhss_check_tx_conditions_cb(&fhss_api, true, 1, FHSS_DATA_FRAME, 100, 0, 0) == true) {
106-
return false;
107-
}
108-
// Test failing TX allowed check
109-
fhss_stub.bad_channel_bool_value = true;
110-
fhss_stub.channel_type_bool_value = true;
111-
fhss_stub.tx_allowed_bool_value = false;
112-
if (fhss_check_tx_conditions_cb(&fhss_api, true, 1, FHSS_DATA_FRAME, 100, 0, 0) == true) {
113-
return false;
114-
}
115-
// Test TX allowed
116-
fhss_stub.bad_channel_bool_value = true;
117-
fhss_stub.channel_type_bool_value = true;
118-
fhss_stub.tx_allowed_bool_value = true;
119-
if (fhss_check_tx_conditions_cb(&fhss_api, true, 1, FHSS_DATA_FRAME, 100, 0, 0) == false) {
120-
return false;
121-
}
122-
return true;
123-
}
12482
bool test_fhss_receive_frame_cb()
12583
{
12684
fhss_api_t fhss_api;

test/nanostack/unittest/service_libs/fhss_mac_interface/test_fhss_mac_interface.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ extern "C" {
2626
bool test_fhss_is_broadcast_channel_cb();
2727
// Test broadcast queue check callback
2828
bool test_fhss_use_broadcast_queue_cb();
29-
// Test TX conditions check callback
30-
bool test_fhss_check_tx_conditions_cb();
3129
// Test frame receive callback
3230
bool test_fhss_receive_frame_cb();
3331
// Test TX done callback

test/nanostack/unittest/stub/fhss_config_stub.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ fhss_api_t *ns_fhss_create(const fhss_configuration_t *fhss_configuration, const
2828
{
2929
fhss_config_stub.fhss_api_ptr.is_broadcast_channel = &fhss_is_broadcast_channel_cb;
3030
fhss_config_stub.fhss_api_ptr.use_broadcast_queue = &fhss_use_broadcast_queue_cb;
31-
fhss_config_stub.fhss_api_ptr.tx_handle = &fhss_tx_handle_cb;
32-
fhss_config_stub.fhss_api_ptr.check_tx_conditions = &fhss_check_tx_conditions_cb;
3331
fhss_config_stub.fhss_api_ptr.receive_frame = &fhss_receive_frame_cb;
3432
fhss_config_stub.fhss_api_ptr.data_tx_done = &fhss_data_tx_done_cb;
3533
fhss_config_stub.fhss_api_ptr.data_tx_fail = &fhss_data_tx_fail_cb;

test/nanostack/unittest/stub/fhss_mac_interface_stub.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,6 @@ bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr,
3333
return fhss_mac_interface_stub.queue_bool_value;
3434
}
3535

36-
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)
37-
{
38-
fhss_mac_interface_stub.int8_value++;
39-
return fhss_mac_interface_stub.handle_value;
40-
}
41-
42-
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)
43-
{
44-
fhss_mac_interface_stub.int8_value++;
45-
if (frame_type == FHSS_SYNCH_REQUEST_FRAME) {
46-
return false;
47-
}
48-
return fhss_mac_interface_stub.cond_bool_value;
49-
}
50-
5136
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)
5237
{
5338
fhss_mac_interface_stub.int8_value++;

0 commit comments

Comments
 (0)