Skip to content

Commit f6d1299

Browse files
author
Jarkko Paso
committed
FHSS WS: Fixed compensation when on BC channel
1 parent a0e893b commit f6d1299

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static int32_t fhss_ws_calc_bc_channel(fhss_structure_t *fhss_structure)
197197
}
198198
}
199199
#ifdef FHSS_CHANNEL_DEBUG
200-
tr_info("%"PRIu32" BC %u %u", fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api), next_channel, fhss_structure->ws->bc_slot);
200+
tr_info("%"PRIu32" BC %u %u %u", fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api), next_channel, fhss_structure->ws->bc_slot, fhss_structure->ws->fhss_configuration.bsi);
201201
#endif /*FHSS_CHANNEL_DEBUG*/
202202
return next_channel;
203203
}
@@ -486,7 +486,7 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
486486
}
487487
}
488488
#ifdef FHSS_CHANNEL_DEBUG
489-
tr_debug("TX channel: %u %u", tx_channel, destination_slot + 1);
489+
tr_debug("TX channel: %u %u %s", tx_channel, destination_slot + 1, trace_array(destination_address, 8));
490490
#endif /*FHSS_CHANNEL_DEBUG*/
491491
fhss_structure->callbacks.change_channel(fhss_structure->fhss_api, tx_channel);
492492
}
@@ -772,6 +772,7 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8],
772772
return 0;
773773
}
774774
platform_enter_critical();
775+
uint16_t own_bc_slot = fhss_structure->ws->bc_slot;
775776
uint32_t prev_synchronization_time = fhss_structure->ws->synchronization_time;
776777
fhss_structure->ws->synchronization_time = fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api);
777778
uint32_t time_since_last_synch_us = fhss_structure->ws->synchronization_time - prev_synchronization_time;
@@ -803,9 +804,9 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8],
803804
if (prev_synchronization_time) {
804805
if (SYNCH_COMPENSATION_MIN_INTERVAL <= US_TO_S(time_since_last_synch_us)) {
805806
// Update clock drift
806-
fhss_structure->ws->drift_per_millisecond_ns += divide_integer(MS_TO_NS(true_bc_interval_offset - own_bc_interval_offset), US_TO_MS(time_since_last_synch_us));
807+
fhss_structure->ws->drift_per_millisecond_ns += divide_integer(MS_TO_NS((true_bc_interval_offset - own_bc_interval_offset) + ((int32_t)(fhss_structure->ws->bc_slot - own_bc_slot) * bc_timing_info->broadcast_interval)), US_TO_MS(time_since_last_synch_us));
807808
}
808-
tr_debug("synch to parent: %s, drift: %"PRIi32"ms in %"PRIu32" seconds, compensation: %"PRIi32"ns per ms", trace_array(eui64, 8), true_bc_interval_offset - own_bc_interval_offset, US_TO_S(time_since_last_synch_us), fhss_structure->ws->drift_per_millisecond_ns);
809+
tr_debug("synch to parent: %s, drift: %"PRIi32"ms in %"PRIu32" seconds, compensation: %"PRIi32"ns per ms", trace_array(eui64, 8), true_bc_interval_offset - own_bc_interval_offset + ((int32_t)(fhss_structure->ws->bc_slot - own_bc_slot) * bc_timing_info->broadcast_interval), US_TO_S(time_since_last_synch_us), fhss_structure->ws->drift_per_millisecond_ns);
809810
}
810811
return 0;
811812
}
@@ -859,5 +860,4 @@ int fhss_ws_set_hop_count(fhss_structure_t *fhss_structure, const uint8_t hop_co
859860
fhss_structure->own_hop = hop_count;
860861
return 0;
861862
}
862-
863863
#endif // HAVE_WS

0 commit comments

Comments
 (0)