Skip to content

Commit d73d210

Browse files
author
Jarkko Paso
committed
FHSS: Moved own hop to common FHSS structure
1 parent caafff0 commit d73d210

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

source/Service_Libs/fhss/fhss.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fhss_structure_t *fhss_enable(fhss_api_t *fhss_api, const fhss_configuration_t *
7979
fhss_struct->bs->fhss_configuration.fhss_max_synch_interval = 240;
8080
}
8181
ns_list_init(&fhss_struct->fhss_failed_tx_list);
82-
fhss_struct->bs->own_hop = 0xff;
82+
fhss_struct->own_hop = 0xff;
8383
fhss_reset(fhss_struct);
8484

8585
if (fhss_beacon_create_tasklet(fhss_struct) < 0) {
@@ -93,7 +93,7 @@ fhss_structure_t *fhss_enable(fhss_api_t *fhss_api, const fhss_configuration_t *
9393

9494
bool fhss_is_synch_root(fhss_structure_t *fhss_structure)
9595
{
96-
if (fhss_structure->bs->own_hop > 0) {
96+
if (fhss_structure->own_hop > 0) {
9797
return false;
9898
}
9999
return true;
@@ -241,7 +241,7 @@ static int fhss_update_txrx_slots(fhss_structure_t *fhss_structure)
241241
*
242242
*/
243243

244-
if ((fhss_structure->bs->own_hop % 2)) {
244+
if ((fhss_structure->own_hop % 2)) {
245245
tx_slot_up_limit += tx_slot_length;
246246
}
247247
while(number_of_tx_slots--)
@@ -367,12 +367,12 @@ static int fhss_sync_with_beacon(fhss_structure_t *fhss_structure,
367367
configuration->fhss_number_of_superframes = payload->number_of_superframes_per_channel;
368368
// todo:
369369
// * payload->time_since_last_beacon
370-
uint8_t own_hop_tmp = fhss_structure->bs->own_hop;
370+
uint8_t own_hop_tmp = fhss_structure->own_hop;
371371
if (fhss_is_synch_root(fhss_structure) == false) {
372372
// my own hop count is one more than the parent's
373-
fhss_structure->bs->own_hop = payload->hop_count + 1;
373+
fhss_structure->own_hop = payload->hop_count + 1;
374374
}
375-
fhss_stats_update(fhss_structure, STATS_FHSS_HOP_COUNT, fhss_structure->bs->own_hop);
375+
fhss_stats_update(fhss_structure, STATS_FHSS_HOP_COUNT, fhss_structure->own_hop);
376376
fhss_structure->bs->channel_list_counter = payload->channel_list_counter;
377377
fhss_structure->bs->current_channel_index = payload->channel_index;
378378
uint8_t mac_address[8];
@@ -427,7 +427,7 @@ static int fhss_sync_with_beacon(fhss_structure_t *fhss_structure,
427427
fhss_beacon_periodic_start(fhss_structure, fhss_structure->bs->synch_interval + beacon_interval_random);
428428
}
429429
// Our hop has changed, needs to inform possible children by sending Beacon
430-
if ((own_hop_tmp != 0) && (own_hop_tmp != fhss_structure->bs->own_hop)) {
430+
if ((own_hop_tmp != 0) && (own_hop_tmp != fhss_structure->own_hop)) {
431431
fhss_structure->bs->send_synch_info_on_next_broadcast_channel = true;
432432
}
433433
ret_val = 0;
@@ -458,7 +458,7 @@ static uint32_t fhss_get_remaining_tx_time(fhss_structure_t *fhss_structure)
458458
uint8_t tx_slot_up_limit = tx_slot_length;
459459
uint16_t superframe_length = fhss_structure->bs->synch_configuration.fhss_superframe_length;
460460

461-
if ((fhss_structure->bs->own_hop % 2)) {
461+
if ((fhss_structure->own_hop % 2)) {
462462
tx_slot_up_limit += tx_slot_length;
463463
}
464464
while(number_of_tx_slots--)
@@ -645,7 +645,7 @@ static int fhss_reset(fhss_structure_t *fhss_structure)
645645
fhss_structure->bs->current_channel_index = 0;
646646
fhss_structure->bs->channel_list_counter = 0;
647647
if (fhss_is_synch_root(fhss_structure) == false) {
648-
fhss_structure->bs->own_hop = 0xff;
648+
fhss_structure->own_hop = 0xff;
649649
}
650650
fhss_structure->bs->tx_allowed = false;
651651
fhss_structure->bs->synch_interval = (uint32_t) (fhss_structure->bs->fhss_configuration.fhss_max_synch_interval/BEACON_INTERVAL_INIT_DIVIDER) * 1000;
@@ -1031,7 +1031,7 @@ static void fhss_update_channel_callback(fhss_structure_t *fhss_structure)
10311031
// If channel is broadcast channel (true), send event
10321032
if (fhss_change_to_next_channel(fhss_structure) == true) {
10331033
// Only if device is border router
1034-
if (fhss_structure->bs->own_hop == 0) {
1034+
if (fhss_structure->own_hop == 0) {
10351035
fhss_trig_event(fhss_structure, FHSS_BROADCAST_CHANNEL);
10361036
}
10371037
}
@@ -1068,7 +1068,7 @@ static void fhss_beacon_build(fhss_structure_t *fhss_structure, uint8_t* dest)
10681068
// should be the case as the superframe length field is also in that range.
10691069
temp_payload.remaining_slots = (uint16_t) fhss_get_remaining_time_to_next_superframe(fhss_structure);
10701070
temp_payload.channel_list_counter = fhss_structure->bs->channel_list_counter;
1071-
temp_payload.hop_count = fhss_structure->bs->own_hop;
1071+
temp_payload.hop_count = fhss_structure->own_hop;
10721072
temp_payload.number_of_broadcast_channels = config->fhss_number_of_bc_channels;
10731073
temp_payload.number_of_tx_slots = config->fhss_number_of_tx_slots;
10741074
temp_payload.time_since_last_beacon = 0; // XXX not available yet
@@ -1303,7 +1303,7 @@ int8_t fhss_set_synch_configuration(fhss_structure_t *fhss_structure, const fhss
13031303
return -4;
13041304
}
13051305
fhss_structure->bs->synch_configuration = *fhss_synch_configuration;
1306-
fhss_structure->bs->own_hop = 0;
1306+
fhss_structure->own_hop = 0;
13071307
return 0;
13081308
}
13091309

source/Service_Libs/fhss/fhss.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ struct fhss_bs
9292
uint8_t uc_channel_index;
9393
uint8_t current_superframe;
9494
uint8_t current_channel_index;
95-
uint8_t own_hop;
9695
uint8_t beacons_received_timer;
9796
uint8_t broadcast_start_superframe;
9897
uint8_t synch_infos_sent_counter;

source/Service_Libs/fhss/fhss_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ typedef NS_LIST_HEAD(fhss_failed_tx_t, link) fhss_failed_tx_list_t;
3535

3636
struct fhss_structure
3737
{
38+
uint8_t own_hop;
3839
uint8_t fhss_resolution_divider;
3940
uint8_t rx_channel;
4041
int8_t beacon_tasklet_id;

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static void test_set_fhss_default_configs(void)
118118
FHSS.rx_channel = DEFAULT_CHANNEL;
119119
FHSS.fhss_state = FHSS_UNSYNCHRONIZED;
120120
FHSS.datarate = 250000;
121-
FHSS.bs->own_hop = 2;
121+
FHSS.own_hop = 2;
122122
}
123123

124124
static fhss_api_t *test_generate_fhss_api(void)
@@ -454,15 +454,15 @@ bool test_fhss_synch_state_set_callback()
454454
// Test when device is synch root
455455
FHSS.fhss_state = FHSS_UNSYNCHRONIZED;
456456
FHSS.bs->synch_panid = 0xffff;
457-
FHSS.bs->own_hop = 0;
457+
FHSS.own_hop = 0;
458458
FHSS.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
459459
if (FHSS.fhss_state != DEFAULT_FHSS_STATE) {
460460
return false;
461461
}
462462
// Test when synch info not found
463463
FHSS.fhss_state = FHSS_UNSYNCHRONIZED;
464464
FHSS.bs->synch_panid = 0xffff;
465-
FHSS.bs->own_hop = 1;
465+
FHSS.own_hop = 1;
466466
FHSS.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
467467
if (FHSS.fhss_state != FHSS_UNSYNCHRONIZED) {
468468
return false;
@@ -524,7 +524,7 @@ bool test_fhss_superframe_handler()
524524
fhss_api_t *api = test_generate_fhss_api();
525525
// Set superframe handler callback
526526
enable_fhss_struct();
527-
FHSS.bs->own_hop = 0;
527+
FHSS.own_hop = 0;
528528
FHSS.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
529529

530530
// Test when FHSS struct not found
@@ -533,7 +533,7 @@ bool test_fhss_superframe_handler()
533533

534534
// Test updating channel for node
535535
enable_fhss_struct();
536-
FHSS.bs->own_hop = 1;
536+
FHSS.own_hop = 1;
537537
FHSS.bs->synch_infos_sent_counter = 1;
538538
FHSS.bs->current_superframe = FHSS.bs->synch_configuration.fhss_number_of_superframes - 1;
539539
FHSS.bs->current_channel_index = FHSS.number_of_channels - 1;
@@ -544,7 +544,7 @@ bool test_fhss_superframe_handler()
544544
}
545545

546546
// Test updating channel for synch root
547-
FHSS.bs->own_hop = 0;
547+
FHSS.own_hop = 0;
548548
FHSS.bs->tx_allowed = false;
549549
fhss_channel_stub.channel_bool_value = true;
550550
FHSS.bs->synch_infos_sent_counter = 1;
@@ -560,7 +560,7 @@ bool test_fhss_superframe_handler()
560560
fhss_channel_stub.channel_bool_value = true;
561561
fhss_callbacks_stub.uint8_value = 1;
562562
FHSS.bs->send_synch_info_on_next_broadcast_channel = true;
563-
FHSS.bs->own_hop = 1;
563+
FHSS.own_hop = 1;
564564
FHSS.bs->tx_allowed = false;
565565
FHSS.bs->synch_infos_sent_counter = 0;
566566
FHSS.bs->current_superframe = FHSS.bs->synch_configuration.fhss_number_of_superframes - 2;
@@ -689,13 +689,13 @@ bool test_fhss_set_synch_configuration()
689689
return false;
690690
}
691691
// Test success
692-
FHSS.bs->own_hop = 0xff;
692+
FHSS.own_hop = 0xff;
693693
FHSS.number_of_channels = 25;
694694
fhss_synch_configuration.fhss_number_of_bc_channels = 5;
695695
fhss_synch_configuration.fhss_number_of_superframes = 4;
696696
fhss_synch_configuration.fhss_number_of_tx_slots = 1;
697697
fhss_synch_configuration.fhss_superframe_length = 25000;
698-
if ((fhss_set_synch_configuration(&FHSS, &fhss_synch_configuration) != 0) || memcmp(&fhss_synch_configuration, &FHSS.bs->synch_configuration, sizeof(fhss_synch_configuration_t)) || FHSS.bs->own_hop) {
698+
if ((fhss_set_synch_configuration(&FHSS, &fhss_synch_configuration) != 0) || memcmp(&fhss_synch_configuration, &FHSS.bs->synch_configuration, sizeof(fhss_synch_configuration_t)) || FHSS.own_hop) {
699699
return false;
700700
}
701701

0 commit comments

Comments
 (0)