@@ -91,10 +91,10 @@ uint8_t fhss_add_channel_list_counter(uint8_t index, uint16_t number_of_channels
91
91
static void fhss_generate_broadcast_start_superframe (fhss_structure_t * fhss_structure )
92
92
{
93
93
// If the number of superframes is low, allow broadcast on any superframe
94
- if (fhss_structure -> synch_configuration .fhss_number_of_superframes < 8 ) {
95
- fhss_structure -> broadcast_start_superframe = 0 ;
94
+ if (fhss_structure -> bs -> synch_configuration .fhss_number_of_superframes < 8 ) {
95
+ fhss_structure -> bs -> broadcast_start_superframe = 0 ;
96
96
} else {
97
- fhss_structure -> broadcast_start_superframe = randLIB_get_random_in_range (0 , NUMBER_OF_BC_START_SUPERFRAMES - 1 );
97
+ fhss_structure -> bs -> broadcast_start_superframe = randLIB_get_random_in_range (0 , NUMBER_OF_BC_START_SUPERFRAMES - 1 );
98
98
}
99
99
}
100
100
@@ -113,8 +113,8 @@ bool fhss_change_to_next_channel(fhss_structure_t *fhss_structure)
113
113
bool broadcast_channel = false;
114
114
115
115
uint16_t number_of_channels = fhss_structure -> number_of_channels ;
116
- uint8_t number_of_broadcast_channels = fhss_structure -> synch_configuration .fhss_number_of_bc_channels ;
117
- uint8_t unicast_channel_index = fhss_structure -> uc_channel_index ;
116
+ uint8_t number_of_broadcast_channels = fhss_structure -> bs -> synch_configuration .fhss_number_of_bc_channels ;
117
+ uint8_t unicast_channel_index = fhss_structure -> bs -> uc_channel_index ;
118
118
uint8_t channel_index_tmp ;
119
119
120
120
/* Get the channel number using channel index. Latter (number_of_broadcast_channels) indexes in channel table are broadcast channels and
@@ -124,20 +124,19 @@ bool fhss_change_to_next_channel(fhss_structure_t *fhss_structure)
124
124
*/
125
125
/* Get broadcast channel */
126
126
if (fhss_is_current_channel_broadcast (fhss_structure ) == true) {
127
- channel_index_tmp = fhss_calc_channel_shuffle ((number_of_channels - number_of_broadcast_channels ) + fhss_get_bc_index (fhss_structure ), fhss_structure -> number_of_channels , fhss_structure -> synch_configuration .fhss_number_of_bc_channels );
127
+ channel_index_tmp = fhss_calc_channel_shuffle ((number_of_channels - number_of_broadcast_channels ) + fhss_get_bc_index (fhss_structure ), fhss_structure -> number_of_channels , fhss_structure -> bs -> synch_configuration .fhss_number_of_bc_channels );
128
128
fhss_generate_broadcast_start_superframe (fhss_structure );
129
129
broadcast_channel = true;
130
130
} else { /* Get unicast channel */
131
- channel_index_tmp = fhss_calc_channel_shuffle (unicast_channel_index , fhss_structure -> number_of_channels , fhss_structure -> synch_configuration .fhss_number_of_bc_channels );
132
- fhss_structure -> uc_channel_index ++ ;
133
- if (fhss_structure -> uc_channel_index >= number_of_channels - number_of_broadcast_channels ) {
134
- fhss_structure -> uc_channel_index = 0 ;
131
+ channel_index_tmp = fhss_calc_channel_shuffle (unicast_channel_index , fhss_structure -> number_of_channels , fhss_structure -> bs -> synch_configuration .fhss_number_of_bc_channels );
132
+ if (++ fhss_structure -> bs -> uc_channel_index >= number_of_channels - number_of_broadcast_channels ) {
133
+ fhss_structure -> bs -> uc_channel_index = 0 ;
135
134
}
136
135
}
137
136
// Reset Beacon received flag when channel has changed
138
- fhss_structure -> beacon_received_on_this_bc_channel = false;
139
- channel_index_tmp = fhss_add_channel_list_counter (channel_index_tmp , fhss_structure -> number_of_channels , fhss_structure -> channel_list_counter , fhss_structure -> fhss_scramble_table );
140
- next_channel = channel_list_get_channel (fhss_structure -> fhss_conf . fhss_configuration .channel_mask , channel_index_tmp );
137
+ fhss_structure -> bs -> beacon_received_on_this_bc_channel = false;
138
+ channel_index_tmp = fhss_add_channel_list_counter (channel_index_tmp , fhss_structure -> number_of_channels , fhss_structure -> bs -> channel_list_counter , fhss_structure -> bs -> fhss_scramble_table );
139
+ next_channel = channel_list_get_channel (fhss_structure -> bs -> fhss_configuration .channel_mask , channel_index_tmp );
141
140
142
141
fhss_structure -> rx_channel = next_channel ;
143
142
#ifdef FHSS_CHANNEL_DEBUG
@@ -154,8 +153,8 @@ bool fhss_change_to_next_channel(fhss_structure_t *fhss_structure)
154
153
static uint8_t fhss_get_bc_index (const fhss_structure_t * fhss_structure )
155
154
{
156
155
uint16_t number_of_channels = fhss_structure -> number_of_channels ;
157
- uint8_t number_of_bc_channels = fhss_structure -> synch_configuration .fhss_number_of_bc_channels ;
158
- uint8_t cur_channel_index = fhss_structure -> current_channel_index ;
156
+ uint8_t number_of_bc_channels = fhss_structure -> bs -> synch_configuration .fhss_number_of_bc_channels ;
157
+ uint8_t cur_channel_index = fhss_structure -> bs -> current_channel_index ;
159
158
160
159
return cur_channel_index / (number_of_channels /number_of_bc_channels );
161
160
}
@@ -165,7 +164,7 @@ uint8_t fhss_get_offset(fhss_structure_t *fhss_structure, const uint8_t *ptr)
165
164
uint8_t i ;
166
165
uint8_t index = * ptr ++ ;
167
166
168
- if (fhss_structure -> number_of_channels == fhss_structure -> synch_configuration .fhss_number_of_bc_channels ) {
167
+ if (fhss_structure -> number_of_channels == fhss_structure -> bs -> synch_configuration .fhss_number_of_bc_channels ) {
169
168
// If all channels are defined as broadcast channels then return 0 to avoid division by 0.
170
169
// This could happen e.g. in OTA case when fast download is needed.
171
170
return 0 ;
@@ -177,7 +176,7 @@ uint8_t fhss_get_offset(fhss_structure_t *fhss_structure, const uint8_t *ptr)
177
176
index ^= * ptr ++ ;
178
177
}
179
178
// Offset must be < number of unicast channels
180
- index %= (fhss_structure -> number_of_channels - fhss_structure -> synch_configuration .fhss_number_of_bc_channels );
179
+ index %= (fhss_structure -> number_of_channels - fhss_structure -> bs -> synch_configuration .fhss_number_of_bc_channels );
181
180
182
181
return index ;
183
182
}
@@ -190,13 +189,13 @@ bool fhss_is_current_channel_broadcast(fhss_structure_t *fhss_structure)
190
189
}
191
190
192
191
// Should always have broadcast channels with FHSS
193
- if (!fhss_structure -> synch_configuration .fhss_number_of_bc_channels ) {
192
+ if (!fhss_structure -> bs -> synch_configuration .fhss_number_of_bc_channels ) {
194
193
return true;
195
194
}
196
195
197
- uint8_t channel_index = fhss_structure -> current_channel_index ;
196
+ uint8_t channel_index = fhss_structure -> bs -> current_channel_index ;
198
197
uint16_t number_of_channels = fhss_structure -> number_of_channels ;
199
- uint8_t number_of_broadcast_channels = fhss_structure -> synch_configuration .fhss_number_of_bc_channels ;
198
+ uint8_t number_of_broadcast_channels = fhss_structure -> bs -> synch_configuration .fhss_number_of_bc_channels ;
200
199
201
200
if (!(channel_index % (number_of_channels / number_of_broadcast_channels ))) {
202
201
return true;
@@ -212,15 +211,15 @@ static uint8_t fhss_get_destination_channel(fhss_structure_t *fhss_structure, ui
212
211
if (fhss_structure ) {
213
212
if (fhss_is_current_channel_broadcast (fhss_structure ) == false) {
214
213
destination_offset = fhss_get_offset (fhss_structure , destination_address );
215
- uc_index = fhss_calculate_uc_index (fhss_structure -> current_channel_index , fhss_structure -> number_of_channels ,
216
- fhss_structure -> synch_configuration .fhss_number_of_bc_channels ) + destination_offset ;
217
- if (uc_index >= (fhss_structure -> number_of_channels - fhss_structure -> synch_configuration .fhss_number_of_bc_channels )) {
218
- uc_index -= (fhss_structure -> number_of_channels - fhss_structure -> synch_configuration .fhss_number_of_bc_channels );
214
+ uc_index = fhss_calculate_uc_index (fhss_structure -> bs -> current_channel_index , fhss_structure -> number_of_channels ,
215
+ fhss_structure -> bs -> synch_configuration .fhss_number_of_bc_channels ) + destination_offset ;
216
+ if (uc_index >= (fhss_structure -> number_of_channels - fhss_structure -> bs -> synch_configuration .fhss_number_of_bc_channels )) {
217
+ uc_index -= (fhss_structure -> number_of_channels - fhss_structure -> bs -> synch_configuration .fhss_number_of_bc_channels );
219
218
}
220
219
221
- uc_index = fhss_calc_channel_shuffle (uc_index , fhss_structure -> number_of_channels , fhss_structure -> synch_configuration .fhss_number_of_bc_channels );
222
- uc_index = fhss_add_channel_list_counter (uc_index , fhss_structure -> number_of_channels , fhss_structure -> channel_list_counter , fhss_structure -> fhss_scramble_table );
223
- return channel_list_get_channel (fhss_structure -> fhss_conf . fhss_configuration .channel_mask , uc_index );
220
+ uc_index = fhss_calc_channel_shuffle (uc_index , fhss_structure -> number_of_channels , fhss_structure -> bs -> synch_configuration .fhss_number_of_bc_channels );
221
+ uc_index = fhss_add_channel_list_counter (uc_index , fhss_structure -> number_of_channels , fhss_structure -> bs -> channel_list_counter , fhss_structure -> bs -> fhss_scramble_table );
222
+ return channel_list_get_channel (fhss_structure -> bs -> fhss_configuration .channel_mask , uc_index );
224
223
}
225
224
return fhss_structure -> rx_channel ;
226
225
}
@@ -247,22 +246,22 @@ int fhss_change_to_parent_channel(fhss_structure_t *fhss_structure)
247
246
uint8_t destination_channel ;
248
247
uint8_t destination_offset ;
249
248
if (fhss_structure ) {
250
- if (fhss_structure -> number_of_channels != fhss_structure -> synch_configuration .fhss_number_of_bc_channels ) {
249
+ if (fhss_structure -> number_of_channels != fhss_structure -> bs -> synch_configuration .fhss_number_of_bc_channels ) {
251
250
uint8_t parent_address [8 ];
252
251
if (fhss_get_parent_address (fhss_structure , parent_address )) {
253
252
return -1 ;
254
253
}
255
254
256
255
destination_offset = fhss_get_offset (fhss_structure , parent_address );
257
256
258
- uc_index = fhss_calculate_uc_index (fhss_structure -> current_channel_index , fhss_structure -> number_of_channels ,
259
- fhss_structure -> synch_configuration .fhss_number_of_bc_channels ) + destination_offset ;
260
- if (uc_index >= (fhss_structure -> number_of_channels - fhss_structure -> synch_configuration .fhss_number_of_bc_channels )) {
261
- uc_index -= (fhss_structure -> number_of_channels - fhss_structure -> synch_configuration .fhss_number_of_bc_channels );
257
+ uc_index = fhss_calculate_uc_index (fhss_structure -> bs -> current_channel_index , fhss_structure -> number_of_channels ,
258
+ fhss_structure -> bs -> synch_configuration .fhss_number_of_bc_channels ) + destination_offset ;
259
+ if (uc_index >= (fhss_structure -> number_of_channels - fhss_structure -> bs -> synch_configuration .fhss_number_of_bc_channels )) {
260
+ uc_index -= (fhss_structure -> number_of_channels - fhss_structure -> bs -> synch_configuration .fhss_number_of_bc_channels );
262
261
}
263
- uc_index = fhss_calc_channel_shuffle (uc_index , fhss_structure -> number_of_channels , fhss_structure -> synch_configuration .fhss_number_of_bc_channels );
264
- uc_index = fhss_add_channel_list_counter (uc_index , fhss_structure -> number_of_channels , fhss_structure -> channel_list_counter , fhss_structure -> fhss_scramble_table );
265
- destination_channel = channel_list_get_channel (fhss_structure -> fhss_conf . fhss_configuration .channel_mask , uc_index );
262
+ uc_index = fhss_calc_channel_shuffle (uc_index , fhss_structure -> number_of_channels , fhss_structure -> bs -> synch_configuration .fhss_number_of_bc_channels );
263
+ uc_index = fhss_add_channel_list_counter (uc_index , fhss_structure -> number_of_channels , fhss_structure -> bs -> channel_list_counter , fhss_structure -> bs -> fhss_scramble_table );
264
+ destination_channel = channel_list_get_channel (fhss_structure -> bs -> fhss_configuration .channel_mask , uc_index );
266
265
fhss_structure -> callbacks .change_channel (fhss_structure -> fhss_api , destination_channel );
267
266
#ifdef FHSS_CHANNEL_DEBUG
268
267
tr_info ("Parent channel: %u" , destination_channel );
0 commit comments