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

Commit 958991a

Browse files
author
Jarkko Paso
committed
FHSS: Few FHSS functions to static
1 parent 7237796 commit 958991a

File tree

5 files changed

+8
-301
lines changed

5 files changed

+8
-301
lines changed

source/Service_Libs/fhss/fhss.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static bool fhss_is_bc_sending_superframe(fhss_structure_t *fhss_structure)
5656
return false;
5757
}
5858

59-
bool fhss_check_bad_channel(fhss_structure_t *fhss_structure, uint8_t handle)
59+
static bool fhss_check_bad_channel(fhss_structure_t *fhss_structure, uint8_t handle)
6060
{
6161
if (!fhss_structure) {
6262
return false;
@@ -71,7 +71,7 @@ bool fhss_check_bad_channel(fhss_structure_t *fhss_structure, uint8_t handle)
7171
return true;
7272
}
7373

74-
bool fhss_check_channel_type(fhss_structure_t *fhss_structure, bool is_bc, int frame_type)
74+
static bool fhss_check_channel_type(fhss_structure_t *fhss_structure, bool is_bc, int frame_type)
7575
{
7676
if (!fhss_structure) {
7777
return false;
@@ -127,7 +127,7 @@ bool fhss_check_channel_type(fhss_structure_t *fhss_structure, bool is_bc, int f
127127

128128
}
129129

130-
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)
130+
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)
131131
{
132132
if (!fhss_structure) {
133133
return false;
@@ -495,7 +495,7 @@ static int fhss_generate_scramble_table(fhss_structure_t *fhss_structure)
495495
return 0;
496496
}
497497

498-
fhss_beacon_info_t *fhss_get_beacon_info(fhss_structure_t *fhss_structure, uint16_t pan_id)
498+
static fhss_beacon_info_t *fhss_get_beacon_info(fhss_structure_t *fhss_structure, uint16_t pan_id)
499499
{
500500
fhss_beacon_info_t *beacon_info;
501501
beacon_info = fhss_structure->fhss_beacon_info_store;
@@ -570,7 +570,7 @@ static int fhss_remove_beacon_info(fhss_structure_t *fhss_structure, uint16_t pa
570570
return -1;
571571
}
572572

573-
int fhss_flush_beacon_info_storage(fhss_structure_t *fhss_structure)
573+
static int fhss_flush_beacon_info_storage(fhss_structure_t *fhss_structure)
574574
{
575575
if (!fhss_structure) {
576576
return -1;

source/Service_Libs/fhss/fhss.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ struct fhss_failed_tx
5858
};
5959

6060
bool fhss_is_synch_root(fhss_structure_t *fhss_structure);
61-
bool fhss_check_bad_channel(fhss_structure_t *fhss_structure, uint8_t handle);
62-
bool fhss_check_channel_type(fhss_structure_t *fhss_structure, bool is_bc, int frame_type);
63-
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);
64-
fhss_beacon_info_t *fhss_get_beacon_info(fhss_structure_t *fhss_structure, uint16_t pan_id);
65-
int fhss_flush_beacon_info_storage(fhss_structure_t *fhss_structure);
6661
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);
6762
void fhss_update_beacon_info_lifetimes(fhss_structure_t *fhss_structure, uint32_t timestamp);
6863
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);

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,6 @@ TEST(fhss, test_fhss_set_synch_configuration)
8989
CHECK(test_fhss_set_synch_configuration());
9090
}
9191

92-
TEST(fhss, test_fhss_check_bad_channel)
93-
{
94-
CHECK(test_fhss_check_bad_channel());
95-
}
96-
97-
TEST(fhss, test_fhss_check_tx_allowed)
98-
{
99-
CHECK(test_fhss_check_tx_allowed());
100-
}
101-
102-
TEST(fhss, test_fhss_check_channel_type)
103-
{
104-
CHECK(test_fhss_check_channel_type());
105-
}
106-
10792
TEST(fhss, test_fhss_disable)
10893
{
10994
CHECK(test_fhss_disable());

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

Lines changed: 3 additions & 270 deletions
Original file line numberDiff line numberDiff line change
@@ -101,268 +101,6 @@ bool test_fhss_disable()
101101
return true;
102102
}
103103

104-
bool test_fhss_check_channel_type()
105-
{
106-
fhss_struct = malloc(sizeof(fhss_structure_t));
107-
108-
// Test NULL API
109-
if (fhss_check_channel_type(NULL, true, FHSS_DATA_FRAME) == true) {
110-
return false;
111-
}
112-
// Test unsynchronized state. (Should allow transmission)
113-
fhss_struct->fhss_state = FHSS_UNSYNCHRONIZED;
114-
if (fhss_check_channel_type(fhss_struct, true, FHSS_DATA_FRAME) == false) {
115-
return false;
116-
}
117-
// Change to synchronized mode
118-
fhss_struct->fhss_state = FHSS_SYNCHRONIZED;
119-
120-
// Test data frame, broadcast destination, unicast channel. (Should deny transmission)
121-
fhss_channel_stub.channel_bool_value = false;
122-
if (fhss_check_channel_type(fhss_struct, true, FHSS_DATA_FRAME) == true) {
123-
return false;
124-
}
125-
126-
// Test data frame, unicast destination, broadcast channel, waiting synchronization Beacon. (Should deny transmission)
127-
fhss_channel_stub.channel_bool_value = true;
128-
fhss_struct->beacons_received_timer = 1;
129-
if (fhss_check_channel_type(fhss_struct, false, FHSS_DATA_FRAME) == true) {
130-
return false;
131-
}
132-
133-
// Test synch request frame, currently on broadcast channel. (Should deny transmission)
134-
fhss_channel_stub.channel_bool_value = true;
135-
fhss_struct->synch_configuration.fhss_number_of_bc_channels = 10;
136-
fhss_struct->number_of_channels = 50;
137-
if (fhss_check_channel_type(fhss_struct, true, FHSS_SYNCH_REQUEST_FRAME) == true) {
138-
return false;
139-
}
140-
141-
// Test synch request frame, currently on unicast channel, superframe is 0. (Should deny transmission)
142-
fhss_channel_stub.channel_bool_value = false;
143-
fhss_struct->current_superframe = 0;
144-
fhss_struct->beacons_received_timer = 1;
145-
fhss_struct->synch_configuration.fhss_number_of_superframes = 8;
146-
if (fhss_check_channel_type(fhss_struct, true, FHSS_SYNCH_REQUEST_FRAME) == true) {
147-
return false;
148-
}
149-
150-
// Test data frame, broadcast destination, broadcast channel. (Should allow transmission)
151-
fhss_struct->synch_configuration.fhss_number_of_superframes = 8;
152-
fhss_struct->broadcast_start_superframe = 2;
153-
fhss_struct->current_superframe = 3;
154-
fhss_channel_stub.channel_bool_value = true;
155-
if (fhss_check_channel_type(fhss_struct, true, FHSS_DATA_FRAME) == false) {
156-
return false;
157-
}
158-
159-
// Test data frame, unicast destination, unicast channel. (Should allow transmission)
160-
fhss_channel_stub.channel_bool_value = false;
161-
if (fhss_check_channel_type(fhss_struct, false, FHSS_DATA_FRAME) == false) {
162-
return false;
163-
}
164-
165-
// Test data frame, unicast destination, broadcast channel, not waiting synchronization Beacon. (Should allow transmission)
166-
fhss_channel_stub.channel_bool_value = true;
167-
fhss_struct->beacons_received_timer = 0;
168-
if (fhss_check_channel_type(fhss_struct, false, FHSS_DATA_FRAME) == false) {
169-
return false;
170-
}
171-
172-
// Test immediate synch frame, sent on any channel. (Should allow transmission)
173-
fhss_channel_stub.channel_bool_value = false;
174-
fhss_struct->current_superframe = 1;
175-
if (fhss_check_channel_type(fhss_struct, true, FHSS_SYNCH_FRAME) == false) {
176-
return false;
177-
}
178-
179-
// Test synch request frame, currently on broadcast channel, number of BC channel equals number of channels, current superframe is 1. (Should allow transmission)
180-
fhss_channel_stub.channel_bool_value = true;
181-
fhss_struct->synch_configuration.fhss_number_of_bc_channels = 50;
182-
fhss_struct->number_of_channels = 50;
183-
fhss_struct->current_superframe = 1;
184-
if (fhss_check_channel_type(fhss_struct, true, FHSS_SYNCH_REQUEST_FRAME) == false) {
185-
return false;
186-
}
187-
188-
// Test sending broadcast when number of superframes is low.
189-
fhss_channel_stub.channel_bool_value = true;
190-
fhss_struct->broadcast_start_superframe = 0;
191-
fhss_struct->current_superframe = 0;
192-
fhss_struct->synch_configuration.fhss_number_of_superframes = 4;
193-
if (fhss_check_channel_type(fhss_struct, true, FHSS_DATA_FRAME) == false) {
194-
return false;
195-
}
196-
197-
// Test sending broadcast when not on broadcast sending superframe.
198-
fhss_channel_stub.channel_bool_value = true;
199-
fhss_struct->synch_configuration.fhss_number_of_superframes = 8;
200-
fhss_struct->broadcast_start_superframe = 2;
201-
fhss_struct->current_superframe = 0;
202-
if (fhss_check_channel_type(fhss_struct, true, FHSS_DATA_FRAME) == true) {
203-
return false;
204-
}
205-
206-
// Test sending broadcast when on broadcast sending superframe.
207-
fhss_channel_stub.channel_bool_value = true;
208-
fhss_struct->synch_configuration.fhss_number_of_superframes = 8;
209-
fhss_struct->broadcast_start_superframe = 2;
210-
fhss_struct->current_superframe = 2;
211-
if (fhss_check_channel_type(fhss_struct, true, FHSS_DATA_FRAME) == false) {
212-
return false;
213-
}
214-
215-
// Test synch request frame, above the middle of superframes, should return false
216-
fhss_channel_stub.channel_bool_value = false;
217-
fhss_struct->current_superframe = 5;
218-
fhss_struct->beacons_received_timer = 0;
219-
fhss_struct->synch_configuration.fhss_number_of_superframes = 8;
220-
if (fhss_check_channel_type(fhss_struct, true, FHSS_SYNCH_REQUEST_FRAME) == true) {
221-
return false;
222-
}
223-
224-
// Test synch request frame, when number of TX slots 1 and on first superframe, should return false
225-
fhss_channel_stub.channel_bool_value = false;
226-
fhss_struct->current_superframe = 0;
227-
fhss_struct->beacons_received_timer = 0;
228-
fhss_struct->synch_configuration.fhss_number_of_superframes = 8;
229-
fhss_struct->synch_configuration.fhss_number_of_tx_slots = 1;
230-
if (fhss_check_channel_type(fhss_struct, true, FHSS_SYNCH_REQUEST_FRAME) == true) {
231-
return false;
232-
}
233-
234-
free(fhss_struct);
235-
fhss_struct = NULL;
236-
return true;
237-
}
238-
239-
bool test_fhss_check_tx_allowed()
240-
{
241-
fhss_struct = malloc(sizeof(fhss_structure_t));
242-
// Initialize FHSS configuration
243-
fhss_struct->datarate = 250000;
244-
fhss_struct->fhss_configuration.fhss_tuning_parameters.tx_processing_delay = 1000;
245-
fhss_struct->fhss_configuration.fhss_tuning_parameters.ack_processing_delay = 1000;
246-
/*...| TX | TX | RX | RX | TX | TX | RX | RX |...
247-
*...| SF n | SF n+1 | SF n+2 | SF n+3 | SF n+4 | SF n+5 | SF n+6 | SF n+7 |...
248-
*/
249-
fhss_struct->current_superframe = 1; // SF n+1
250-
fhss_struct->synch_configuration.fhss_number_of_tx_slots = 2;
251-
fhss_struct->synch_configuration.fhss_number_of_superframes = 8;
252-
fhss_struct->synch_configuration.fhss_superframe_length = 50000;
253-
fhss_struct->own_hop = 2; // For even hop count TX superframes are 0, 1 and 4, 5
254-
fhss_struct->platform_functions.fhss_get_remaining_slots = &fhss_get_remaining_slots_stub;
255-
fhss_struct->platform_functions.fhss_resolution_divider = 1;
256-
257-
// Remaining time(us) to next superframe change. This is what get_remaining_slot -call returns
258-
fhss_platform_stub.uint32_value = 40000;
259-
260-
// When transmitting 100 bytes + Ack (+ processing delays), needed transmission time is around 7.4ms
261-
262-
// FHSS is on RX slot
263-
fhss_struct->tx_allowed = false;
264-
// Test NULL API
265-
if (fhss_check_tx_allowed(NULL, true, 100, FHSS_DATA_FRAME, 0, 0) == true) {
266-
return false;
267-
}
268-
269-
// Test unsynchronized state. (Should allow transmission)
270-
fhss_struct->fhss_state = FHSS_UNSYNCHRONIZED;
271-
if (fhss_check_tx_allowed(fhss_struct, false, 100, FHSS_DATA_FRAME, 0, 0) == false) {
272-
return false;
273-
}
274-
275-
// Change to synchronized mode
276-
fhss_struct->fhss_state = FHSS_SYNCHRONIZED;
277-
278-
// Test synchronization frame. (Should allow transmission)
279-
if (fhss_check_tx_allowed(fhss_struct, false, 100, FHSS_SYNCH_FRAME, 0, 0) == false) {
280-
return false;
281-
}
282-
283-
// Test broadcast frame. (Should allow transmission)
284-
if (fhss_check_tx_allowed(fhss_struct, true, 100, FHSS_DATA_FRAME, 0, 0) == false) {
285-
return false;
286-
}
287-
288-
// Test TX allowed flag. (Should deny transmission)
289-
if (fhss_check_tx_allowed(fhss_struct, false, 100, FHSS_DATA_FRAME, 0, 0) == true) {
290-
return false;
291-
}
292-
293-
// FHSS is on TX slot
294-
fhss_struct->tx_allowed = true;
295-
// Test TX allowed flag. (Should allow transmission)
296-
if (fhss_check_tx_allowed(fhss_struct, false, 100, FHSS_DATA_FRAME, 0, 0) == false) {
297-
return false;
298-
}
299-
300-
// Return too small remaining time(us). (Should deny transmission)
301-
fhss_platform_stub.uint32_value = 7000;
302-
if (fhss_check_tx_allowed(fhss_struct, false, 100, FHSS_DATA_FRAME, 0, 0) == true) {
303-
return false;
304-
}
305-
306-
// Use higher datarate. (Should allow transmission)
307-
fhss_struct->datarate = 300000;
308-
if (fhss_check_tx_allowed(fhss_struct, false, 100, FHSS_DATA_FRAME, 0, 0) == false) {
309-
return false;
310-
}
311-
312-
// 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)
313-
fhss_struct->datarate = 250000;
314-
fhss_platform_stub.uint32_value = 13700;
315-
if (fhss_check_tx_allowed(fhss_struct, false, 100, FHSS_DATA_FRAME, 50, 50) == true) {
316-
return false;
317-
}
318-
319-
// Test odd hop count. (Should deny transmission)
320-
fhss_struct->own_hop = 1;
321-
if (fhss_check_tx_allowed(fhss_struct, false, 100, FHSS_DATA_FRAME, 0, 0) == true) {
322-
return false;
323-
}
324-
325-
free(fhss_struct);
326-
fhss_struct = NULL;
327-
return true;
328-
}
329-
330-
bool test_fhss_check_bad_channel()
331-
{
332-
fhss_struct = malloc(sizeof(fhss_structure_t));
333-
memset(&fhss_struct->fhss_failed_tx_list, 0, sizeof(fhss_failed_tx_list_t));
334-
// Test NULL API
335-
if (fhss_check_bad_channel(NULL, 0) == true) {
336-
return false;
337-
}
338-
// Test with proper API
339-
if (fhss_check_bad_channel(fhss_struct, 0) == false) {
340-
return false;
341-
}
342-
// Test when bad channel is found
343-
uint8_t handle = 10;
344-
fhss_struct->rx_channel = 40;
345-
ns_list_init(&fhss_struct->fhss_failed_tx_list);
346-
nsdynmemlib_stub.returnCounter = 1;
347-
348-
if (fhss_failed_handle_add(fhss_struct, handle) != 0) {
349-
return false;
350-
}
351-
if (fhss_check_bad_channel(fhss_struct, handle) == true) {
352-
return false;
353-
}
354-
// After channel change should return false
355-
fhss_struct->rx_channel = 41;
356-
if (fhss_check_bad_channel(fhss_struct, handle) == false) {
357-
return false;
358-
}
359-
if (fhss_failed_handle_remove(fhss_struct, handle) != 0) {
360-
return false;
361-
}
362-
free(fhss_struct);
363-
fhss_struct = NULL;
364-
}
365-
366104
bool test_fhss_set_synch_configuration()
367105
{
368106
fhss_struct = malloc(sizeof(fhss_structure_t));
@@ -509,14 +247,9 @@ bool test_fhss_add_beacon_info()
509247
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)) {
510248
return false;
511249
}
512-
// Test flushing Beacon storage without FHSS structure
513-
if (fhss_flush_beacon_info_storage(NULL) != -1) {
514-
return false;
515-
}
516-
// Test flushing Beacon storage
517-
if (fhss_flush_beacon_info_storage(fhss_struct) != 0) {
518-
return false;
519-
}
250+
free(fhss_struct->fhss_beacon_info_store->next->next);
251+
free(fhss_struct->fhss_beacon_info_store->next);
252+
free(fhss_struct->fhss_beacon_info_store);
520253
free(fhss_struct);
521254
fhss_struct = 0;
522255
return true;

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ extern "C" {
2727
bool test_fhss_enable();
2828
// Test disabling FHSS
2929
bool test_fhss_disable();
30-
// Test channel type TX condition
31-
bool test_fhss_check_channel_type();
32-
// Test TX allowed TX condition
33-
bool test_fhss_check_tx_allowed();
34-
// Test bad channel TX condition
35-
bool test_fhss_check_bad_channel();
3630
// Test synchronization time configuration
3731
bool test_fhss_set_synch_configuration();
3832
// Test storing Beacon info

0 commit comments

Comments
 (0)