@@ -101,268 +101,6 @@ bool test_fhss_disable()
101
101
return true;
102
102
}
103
103
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
-
366
104
bool test_fhss_set_synch_configuration ()
367
105
{
368
106
fhss_struct = malloc (sizeof (fhss_structure_t ));
@@ -509,14 +247,9 @@ bool test_fhss_add_beacon_info()
509
247
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 )) {
510
248
return false;
511
249
}
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 );
520
253
free (fhss_struct );
521
254
fhss_struct = 0 ;
522
255
return true;
0 commit comments