@@ -83,6 +83,7 @@ static void fhss_event_timer_cb(int8_t timer_id, uint16_t slots);
8383static void fhss_ws_update_uc_channel_callback (fhss_structure_t * fhss_structure );
8484static void fhss_unicast_handler (const fhss_api_t * fhss_api , uint16_t delay );
8585static bool fhss_ws_check_tx_allowed (fhss_structure_t * fhss_structure );
86+ static int32_t fhss_channel_index_from_mask (const uint32_t * channel_mask , int32_t channel_index , uint16_t number_of_channels );
8687
8788// This function supports rounding up
8889static int64_t divide_integer (int64_t dividend , int32_t divisor )
@@ -235,12 +236,14 @@ static int32_t fhss_ws_calc_bc_channel(fhss_structure_t *fhss_structure)
235236
236237 if (fhss_structure -> ws -> fhss_configuration .ws_bc_channel_function == WS_TR51CF ) {
237238 next_channel = tr51_get_bc_channel_index (fhss_structure -> ws -> tr51_channel_table , fhss_structure -> ws -> tr51_output_table , fhss_structure -> ws -> bc_slot , fhss_structure -> ws -> fhss_configuration .bsi , fhss_structure -> number_of_channels , NULL );
239+ next_channel = fhss_channel_index_from_mask (fhss_structure -> ws -> fhss_configuration .channel_mask , next_channel , fhss_structure -> number_of_channels );
238240 if (++ fhss_structure -> ws -> bc_slot == fhss_structure -> number_of_channels ) {
239241 fhss_structure -> ws -> bc_slot = 0 ;
240242 }
241243 } else if (fhss_structure -> ws -> fhss_configuration .ws_bc_channel_function == WS_DH1CF ) {
242244 fhss_structure -> ws -> bc_slot ++ ;
243245 next_channel = dh1cf_get_bc_channel_index (fhss_structure -> ws -> bc_slot , fhss_structure -> ws -> fhss_configuration .bsi , fhss_structure -> number_of_channels );
246+ next_channel = fhss_channel_index_from_mask (fhss_structure -> ws -> fhss_configuration .channel_mask , next_channel , fhss_structure -> number_of_channels );
244247 } else if (fhss_structure -> ws -> fhss_configuration .ws_bc_channel_function == WS_VENDOR_DEF_CF ) {
245248 if (fhss_structure -> ws -> fhss_configuration .vendor_defined_cf ) {
246249 next_channel = fhss_structure -> ws -> fhss_configuration .vendor_defined_cf (fhss_structure -> fhss_api , fhss_structure -> ws -> bc_slot , NULL , fhss_structure -> ws -> fhss_configuration .bsi , fhss_structure -> number_of_channels );
@@ -264,6 +267,22 @@ static uint8_t calc_own_tx_trig_slot(uint8_t own_hop)
264267 return (own_hop & 1 );
265268}
266269
270+ static int32_t fhss_channel_index_from_mask (const uint32_t * channel_mask , int32_t channel_index , uint16_t number_of_channels )
271+ {
272+ //Function will return real active channel index at list
273+ int32_t active_channels = 0 ;
274+ // Set channel maks outside excluded channels
275+ for (int32_t i = 0 ; i < number_of_channels ; i ++ ) {
276+ if (channel_mask [0 + (i / 32 )] & (1 << (i % 32 ))) {
277+ if (channel_index == active_channels ) {
278+ return i ;
279+ }
280+ active_channels ++ ;
281+ }
282+ }
283+ return 0 ;
284+ }
285+
267286static void fhss_broadcast_handler (const fhss_api_t * fhss_api , uint16_t delay )
268287{
269288 int32_t next_channel ;
@@ -477,12 +496,14 @@ static void fhss_ws_update_uc_channel_callback(fhss_structure_t *fhss_structure)
477496 if (fhss_structure -> ws -> fhss_configuration .ws_uc_channel_function == WS_FIXED_CHANNEL ) {
478497 return ;
479498 } else if (fhss_structure -> ws -> fhss_configuration .ws_uc_channel_function == WS_TR51CF ) {
480- next_channel = fhss_structure -> rx_channel = tr51_get_uc_channel_index (fhss_structure -> ws -> tr51_channel_table , fhss_structure -> ws -> tr51_output_table , fhss_structure -> ws -> uc_slot , mac_address , fhss_structure -> number_of_uc_channels , NULL );
499+ next_channel = tr51_get_uc_channel_index (fhss_structure -> ws -> tr51_channel_table , fhss_structure -> ws -> tr51_output_table , fhss_structure -> ws -> uc_slot , mac_address , fhss_structure -> number_of_uc_channels , NULL );
500+ next_channel = fhss_structure -> rx_channel = fhss_channel_index_from_mask (fhss_structure -> ws -> fhss_configuration .unicast_channel_mask , next_channel , fhss_structure -> number_of_channels );
481501 if (++ fhss_structure -> ws -> uc_slot == fhss_structure -> number_of_uc_channels ) {
482502 fhss_structure -> ws -> uc_slot = 0 ;
483503 }
484504 } else if (fhss_structure -> ws -> fhss_configuration .ws_uc_channel_function == WS_DH1CF ) {
485- next_channel = fhss_structure -> rx_channel = dh1cf_get_uc_channel_index (fhss_structure -> ws -> uc_slot , mac_address , fhss_structure -> number_of_uc_channels );
505+ next_channel = dh1cf_get_uc_channel_index (fhss_structure -> ws -> uc_slot , mac_address , fhss_structure -> number_of_uc_channels );
506+ next_channel = fhss_structure -> rx_channel = fhss_channel_index_from_mask (fhss_structure -> ws -> fhss_configuration .unicast_channel_mask , next_channel , fhss_structure -> number_of_channels );
486507 fhss_structure -> ws -> uc_slot ++ ;
487508 } else if (fhss_structure -> ws -> fhss_configuration .ws_uc_channel_function == WS_VENDOR_DEF_CF ) {
488509 if (fhss_structure -> ws -> fhss_configuration .vendor_defined_cf ) {
@@ -540,8 +561,10 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
540561 int32_t tx_channel = neighbor_timing_info -> uc_timing_info .fixed_channel ;
541562 if (neighbor_timing_info -> uc_timing_info .unicast_channel_function == WS_TR51CF ) {
542563 tx_channel = tr51_get_uc_channel_index (fhss_structure -> ws -> tr51_channel_table , fhss_structure -> ws -> tr51_output_table , destination_slot , destination_address , neighbor_timing_info -> uc_timing_info .unicast_number_of_channels , NULL );
564+ tx_channel = fhss_channel_index_from_mask (neighbor_timing_info -> uc_channel_list .channel_mask , tx_channel , fhss_structure -> number_of_channels );
543565 } else if (neighbor_timing_info -> uc_timing_info .unicast_channel_function == WS_DH1CF ) {
544566 tx_channel = dh1cf_get_uc_channel_index (destination_slot , destination_address , neighbor_timing_info -> uc_channel_list .channel_count );
567+ tx_channel = fhss_channel_index_from_mask (neighbor_timing_info -> uc_channel_list .channel_mask , tx_channel , fhss_structure -> number_of_channels );
545568 } else if (neighbor_timing_info -> uc_timing_info .unicast_channel_function == WS_VENDOR_DEF_CF ) {
546569 if (fhss_structure -> ws -> fhss_configuration .vendor_defined_cf ) {
547570 tx_channel = fhss_structure -> ws -> fhss_configuration .vendor_defined_cf (fhss_structure -> fhss_api , fhss_structure -> ws -> bc_slot , destination_address , fhss_structure -> ws -> fhss_configuration .bsi , neighbor_timing_info -> uc_timing_info .unicast_number_of_channels );
0 commit comments