Skip to content

Commit 1d54c7d

Browse files
author
Jarkko Paso
committed
FHSS: fhss tx handle callbacks added
1 parent 0cc1889 commit 1d54c7d

File tree

10 files changed

+77
-73
lines changed

10 files changed

+77
-73
lines changed

source/Service_Libs/fhss/fhss.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,33 @@ static void fhss_superframe_callback(fhss_structure_t *fhss_structure)
760760
}
761761
}
762762

763+
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)
764+
{
765+
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
766+
if (!fhss_structure) {
767+
return -2;
768+
}
769+
// TODO: needs some more logic to push buffer back to queue
770+
if (frame_type == FHSS_DATA_FRAME) {
771+
if (is_broadcast_addr == true) {
772+
if (fhss_is_current_channel_broadcast(fhss_structure) == false) {
773+
tr_info("Broadcast on UC channel -> Back to queue");
774+
return -3;
775+
}
776+
}
777+
}
778+
if (fhss_check_tx_allowed(fhss_structure, is_broadcast_addr, frame_length, frame_type, phy_header_length, phy_tail_length) == false) {
779+
return -1;
780+
}
781+
// If sending Beacon request on parents Unicast channel
782+
if (frame_type == FHSS_SYNCH_REQUEST_FRAME && fhss_structure->fhss_state == FHSS_SYNCHRONIZED) {
783+
fhss_change_to_parent_channel(fhss_structure);
784+
} else if (frame_type == FHSS_DATA_FRAME) {
785+
fhss_change_to_tx_channel(fhss_structure, destination_address);
786+
}
787+
return 0;
788+
}
789+
763790
static void fhss_update_channel_callback(fhss_structure_t *fhss_structure)
764791
{
765792
if (fhss_structure->current_channel_index == 0) {
@@ -786,7 +813,7 @@ int fhss_set_callbacks(fhss_structure_t *fhss_structure)
786813
// Set external API
787814
fhss_structure->fhss_api->is_broadcast_channel = &fhss_is_broadcast_channel_cb;
788815
fhss_structure->fhss_api->use_broadcast_queue = &fhss_use_broadcast_queue_cb;
789-
fhss_structure->fhss_api->tx_handle = &fhss_tx_handle_cb;
816+
fhss_structure->fhss_api->tx_handle = &fhss_tx_handle_callback;
790817
fhss_structure->fhss_api->check_tx_conditions = &fhss_check_tx_conditions_cb;
791818
fhss_structure->fhss_api->receive_frame = &fhss_receive_frame_cb;
792819
fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_cb;

source/Service_Libs/fhss/fhss_mac_interface.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,33 +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-
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)
62-
{
63-
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
64-
if (!fhss_structure) {
65-
return -2;
66-
}
67-
// TODO: needs some more logic to push buffer back to queue
68-
if (frame_type == FHSS_DATA_FRAME) {
69-
if (is_broadcast_addr == true) {
70-
if (fhss_is_current_channel_broadcast(fhss_structure) == false) {
71-
tr_info("Broadcast on UC channel -> Back to queue");
72-
return -3;
73-
}
74-
}
75-
}
76-
if (fhss_check_tx_allowed(fhss_structure, is_broadcast_addr, frame_length, frame_type, phy_header_length, phy_tail_length) == false) {
77-
return -1;
78-
}
79-
// If sending Beacon request on parents Unicast channel
80-
if (frame_type == FHSS_SYNCH_REQUEST_FRAME && fhss_structure->fhss_state == FHSS_SYNCHRONIZED) {
81-
fhss_change_to_parent_channel(fhss_structure);
82-
} else if (frame_type == FHSS_DATA_FRAME) {
83-
fhss_change_to_tx_channel(fhss_structure, destination_address);
84-
}
85-
return 0;
86-
}
87-
8861
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)
8962
{
9063
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-
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);
2423
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);
2524
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);
2625
void fhss_data_tx_done_cb(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle);

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,17 @@ static void fhss_ws_update_channel_callback(fhss_structure_t *fhss_structure)
6868
fhss_structure->callbacks.change_channel(fhss_structure->fhss_api, next_channel);
6969
}
7070

71+
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)
72+
{
73+
return 0;
74+
}
75+
7176
int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure)
7277
{
7378
// Set external API
7479
fhss_structure->fhss_api->is_broadcast_channel = &fhss_is_broadcast_channel_cb;
7580
fhss_structure->fhss_api->use_broadcast_queue = &fhss_use_broadcast_queue_cb;
76-
fhss_structure->fhss_api->tx_handle = &fhss_tx_handle_cb;
81+
fhss_structure->fhss_api->tx_handle = &fhss_ws_tx_handle_callback;
7782
fhss_structure->fhss_api->check_tx_conditions = &fhss_check_tx_conditions_cb;
7883
fhss_structure->fhss_api->receive_frame = &fhss_receive_frame_cb;
7984
fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_cb;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,8 @@ TEST(fhss, test_fhss_is_synch_root)
133133
{
134134
CHECK(test_fhss_is_synch_root());
135135
}
136+
137+
TEST(fhss, test_fhss_tx_handle_callback)
138+
{
139+
CHECK(test_fhss_tx_handle_callback());
140+
}

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,3 +1003,39 @@ bool test_fhss_is_synch_root()
10031003
fhss_struct = NULL;
10041004
return true;
10051005
}
1006+
1007+
bool test_fhss_tx_handle_callback()
1008+
{
1009+
fhss_api_t fhss_api;
1010+
fhss_struct = malloc(sizeof(fhss_structure_t));
1011+
fhss_struct->fhss_api = &fhss_api;
1012+
fhss_struct->datarate = 250000;
1013+
fhss_struct->synch_configuration.fhss_number_of_tx_slots = 1;
1014+
fhss_set_callbacks(fhss_struct);
1015+
// Broadcast data on unicast channel should return -3
1016+
if (fhss_struct->fhss_api->tx_handle(&fhss_api, true, NULL, FHSS_DATA_FRAME, 0, 0, 0) != -3) {
1017+
return false;
1018+
}
1019+
// Test sending of Beacon
1020+
if (fhss_struct->fhss_api->tx_handle(&fhss_api, true, NULL, FHSS_SYNCH_FRAME, 0, 0, 0) != 0) {
1021+
return false;
1022+
}
1023+
// When TX is not allowed, should return -1 for data frame
1024+
fhss_struct->tx_allowed = false;
1025+
fhss_struct->fhss_state = FHSS_SYNCHRONIZED;
1026+
if (fhss_struct->fhss_api->tx_handle(&fhss_api, false, NULL, FHSS_DATA_FRAME, 0, 0, 0) != -1) {
1027+
return false;
1028+
}
1029+
// When TX is allowed, should return 0 for data frame
1030+
fhss_struct->tx_allowed = true;
1031+
fhss_struct->fhss_state = FHSS_UNSYNCHRONIZED;
1032+
if (fhss_struct->fhss_api->tx_handle(&fhss_api, false, NULL, FHSS_DATA_FRAME, 0, 0, 0) != 0) {
1033+
return false;
1034+
}
1035+
// Test changing to parent channel to send synch request
1036+
if (fhss_struct->fhss_api->tx_handle(&fhss_api, false, NULL, FHSS_SYNCH_REQUEST_FRAME, 0, 0, 0) != 0) {
1037+
return false;
1038+
}
1039+
free(fhss_struct);
1040+
return true;
1041+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ bool test_fhss_update_beacon_info_lifetimes();
6565
bool test_fhss_failed_handle();
6666
// Test synch root check
6767
bool test_fhss_is_synch_root();
68+
// Test TX handle callback
69+
bool test_fhss_tx_handle_callback();
6870

6971
#ifdef __cplusplus
7072
}

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_tx_handle_cb)
43-
{
44-
CHECK(test_fhss_tx_handle_cb());
45-
}
46-
4742
TEST(fhss_mac_if, test_fhss_check_tx_conditions_cb)
4843
{
4944
CHECK(test_fhss_check_tx_conditions_cb());

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

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -78,43 +78,7 @@ bool test_fhss_use_broadcast_queue_cb()
7878
}
7979
return true;
8080
}
81-
bool test_fhss_tx_handle_cb()
82-
{
83-
fhss_api_t fhss_api;
8481

85-
// By setting bool value false, fhss_struct can not be found
86-
fhss_stub.bool_value = false;
87-
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_DATA_FRAME, 0, 0, 0) != -2) {
88-
return false;
89-
}
90-
// By setting bool value true, fhss_struct can be found
91-
fhss_stub.bool_value = true;
92-
// Broadcast data on unicast channel should return -3
93-
fhss_channel_stub.channel_bool_value = false;
94-
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_DATA_FRAME, 0, 0, 0) != -3) {
95-
return false;
96-
}
97-
// Test sending of Beacon
98-
if (fhss_tx_handle_cb(&fhss_api, true, NULL, FHSS_SYNCH_FRAME, 0, 0, 0) != 0) {
99-
return false;
100-
}
101-
// When TX is not allowed, should return -1 for data frame
102-
fhss_stub.tx_allowed_bool_value = false;
103-
if (fhss_tx_handle_cb(&fhss_api, false, NULL, FHSS_DATA_FRAME, 0, 0, 0) != -1) {
104-
return false;
105-
}
106-
// When TX is allowed, should return 0 for data frame
107-
fhss_stub.tx_allowed_bool_value = true;
108-
if (fhss_tx_handle_cb(&fhss_api, false, NULL, FHSS_DATA_FRAME, 0, 0, 0) != 0) {
109-
return false;
110-
}
111-
// Test changing to parent channel to send synch request
112-
fhss_stub.fhss_struct.fhss_state = FHSS_SYNCHRONIZED;
113-
if (fhss_tx_handle_cb(&fhss_api, false, NULL, FHSS_SYNCH_REQUEST_FRAME, 0, 0, 0) != 0) {
114-
return false;
115-
}
116-
return true;
117-
}
11882
bool test_fhss_check_tx_conditions_cb()
11983
{
12084
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 handle callback
30-
bool test_fhss_tx_handle_cb();
3129
// Test TX conditions check callback
3230
bool test_fhss_check_tx_conditions_cb();
3331
// Test frame receive callback

0 commit comments

Comments
 (0)