37
37
38
38
#define TRACE_GROUP "etx"
39
39
40
+ typedef struct {
41
+ uint8_t attribute_index ;
42
+ const uint8_t * mac64 ;
43
+ } ext_neigh_info_t ;
44
+
40
45
static uint16_t etx_current_calc (uint16_t etx , uint8_t accumulated_failures );
41
46
static uint16_t etx_dbm_lqi_calc (uint8_t lqi , int8_t dbm );
42
- static void etx_value_change_callback_needed_check (uint16_t etx , uint16_t * stored_diff_etx , uint8_t accumulated_failures , uint8_t attribute_index );
47
+ static void etx_value_change_callback_needed_check (uint16_t etx , uint16_t * stored_diff_etx , uint8_t accumulated_failures , ext_neigh_info_t * etx_neigh_info );
43
48
static void etx_accum_failures_callback_needed_check (etx_storage_t * entry , uint8_t attribute_index );
44
49
static void etx_cache_entry_init (uint8_t attribute_index );
45
50
@@ -90,7 +95,7 @@ static ext_info_t etx_info = {
90
95
.interface_id = -1
91
96
};
92
97
93
- static void etx_calculation (etx_storage_t * entry , uint16_t attempts , uint8_t acks_rx , uint8_t attribute_index )
98
+ static void etx_calculation (etx_storage_t * entry , uint16_t attempts , uint8_t acks_rx , ext_neigh_info_t * etx_neigh_info )
94
99
{
95
100
if (etx_info .hysteresis && !entry -> stored_diff_etx ) {
96
101
if (entry -> etx_samples >= etx_info .init_etx_sample_count ) {
@@ -130,9 +135,9 @@ static void etx_calculation(etx_storage_t *entry, uint16_t attempts, uint8_t ack
130
135
entry -> etx = etx ;
131
136
132
137
if (entry -> etx_samples >= etx_info .init_etx_sample_count ) {
133
- etx_cache_entry_init (attribute_index );
138
+ etx_cache_entry_init (etx_neigh_info -> attribute_index );
134
139
// Checks if ETX value change callback is needed
135
- etx_value_change_callback_needed_check (entry -> etx , & (entry -> stored_diff_etx ), entry -> accumulated_failures , attribute_index );
140
+ etx_value_change_callback_needed_check (entry -> etx , & (entry -> stored_diff_etx ), entry -> accumulated_failures , etx_neigh_info );
136
141
}
137
142
}
138
143
@@ -203,7 +208,7 @@ static etx_sample_storage_t *etx_cache_sample_update(uint8_t attribute_index, ui
203
208
* \param addr_type address type, ADDR_802_15_4_SHORT or ADDR_802_15_4_LONG
204
209
* \param addr_ptr PAN ID with 802.15.4 address
205
210
*/
206
- void etx_transm_attempts_update (int8_t interface_id , uint8_t attempts , bool success , uint8_t attribute_index )
211
+ void etx_transm_attempts_update (int8_t interface_id , uint8_t attempts , bool success , uint8_t attribute_index , const uint8_t * mac64_addr_ptr )
207
212
{
208
213
uint8_t accumulated_failures ;
209
214
// Gets table entry
@@ -212,6 +217,10 @@ void etx_transm_attempts_update(int8_t interface_id, uint8_t attempts, bool succ
212
217
return ;
213
218
}
214
219
220
+ ext_neigh_info_t etx_neigh_info ;
221
+ etx_neigh_info .attribute_index = attribute_index ;
222
+ etx_neigh_info .mac64 = mac64_addr_ptr ;
223
+
215
224
if (entry -> etx_samples < 7 ) {
216
225
entry -> etx_samples ++ ;
217
226
}
@@ -225,7 +234,7 @@ void etx_transm_attempts_update(int8_t interface_id, uint8_t attempts, bool succ
225
234
return ;
226
235
}
227
236
228
- etx_calculation (entry , storage -> attempts_count , storage -> received_acks , attribute_index );
237
+ etx_calculation (entry , storage -> attempts_count , storage -> received_acks , & etx_neigh_info );
229
238
230
239
if (entry -> etx_samples < 7 && !success ) {
231
240
entry -> etx_samples = 7 ; //Stop Probing to failure
@@ -254,7 +263,7 @@ void etx_transm_attempts_update(int8_t interface_id, uint8_t attempts, bool succ
254
263
if (entry -> etx ) {
255
264
256
265
if (success ) {
257
- etx_calculation (entry , attempts + accumulated_failures , 1 , attribute_index );
266
+ etx_calculation (entry , attempts + accumulated_failures , 1 , & etx_neigh_info );
258
267
}
259
268
}
260
269
}
@@ -268,35 +277,42 @@ void etx_transm_attempts_update(int8_t interface_id, uint8_t attempts, bool succ
268
277
* \param remote_incoming_idr Remote incoming IDR
269
278
* \param mac64_addr_ptr long MAC address
270
279
*/
271
- void etx_remote_incoming_idr_update (int8_t interface_id , uint8_t remote_incoming_idr , uint8_t attribute_index )
280
+ void etx_remote_incoming_idr_update (int8_t interface_id , uint8_t remote_incoming_idr , uint8_t attribute_index , const uint8_t * mac64_addr_ptr )
272
281
{
273
282
etx_storage_t * entry = etx_storage_entry_get (interface_id , attribute_index );
283
+ if (!entry ) {
284
+ return ;
285
+ }
274
286
275
- if (entry ) {
276
- // If ETX has been set
277
- if (entry -> etx ) {
278
- // If hysteresis is set stores ETX value to enable comparison
279
- if (etx_info .hysteresis && !entry -> stored_diff_etx ) {
280
- entry -> stored_diff_etx = entry -> etx ;
281
- }
282
- // remote EXT = remote incoming IDR^2 (12 bit fraction)
283
- uint32_t remote_ext = ((uint32_t )remote_incoming_idr * remote_incoming_idr ) << 2 ;
287
+ ext_neigh_info_t etx_neigh_info ;
288
+ etx_neigh_info .attribute_index = attribute_index ;
289
+ etx_neigh_info .mac64 = mac64_addr_ptr ;
284
290
285
- // ETX = 7/8 * current ETX + 1/8 * remote ETX */
286
- uint32_t etx = entry -> etx - (entry -> etx >> ETX_MOVING_AVERAGE_FRACTION );
287
- etx += remote_ext >> ETX_MOVING_AVERAGE_FRACTION ;
288
291
289
- if (etx > 0xffff ) {
290
- entry -> etx = 0xffff ;
291
- } else {
292
- entry -> etx = etx ;
293
- }
292
+ // If ETX has been set
293
+ if (entry -> etx ) {
294
+ // If hysteresis is set stores ETX value to enable comparison
295
+ if (etx_info .hysteresis && !entry -> stored_diff_etx ) {
296
+ entry -> stored_diff_etx = entry -> etx ;
297
+ }
298
+ // remote EXT = remote incoming IDR^2 (12 bit fraction)
299
+ uint32_t remote_ext = ((uint32_t )remote_incoming_idr * remote_incoming_idr ) << 2 ;
294
300
295
- // Checks if ETX value change callback is needed
296
- etx_value_change_callback_needed_check (entry -> etx , & (entry -> stored_diff_etx ), entry -> accumulated_failures , attribute_index );
301
+ // ETX = 7/8 * current ETX + 1/8 * remote ETX */
302
+ uint32_t etx = entry -> etx - (entry -> etx >> ETX_MOVING_AVERAGE_FRACTION );
303
+ etx += remote_ext >> ETX_MOVING_AVERAGE_FRACTION ;
304
+
305
+ if (etx > 0xffff ) {
306
+ entry -> etx = 0xffff ;
307
+ } else {
308
+ entry -> etx = etx ;
297
309
}
298
- entry -> remote_incoming_idr = remote_incoming_idr ;
310
+
311
+ // Checks if ETX value change callback is needed
312
+ etx_value_change_callback_needed_check (entry -> etx , & (entry -> stored_diff_etx ), entry -> accumulated_failures , & etx_neigh_info );
299
313
}
314
+ entry -> remote_incoming_idr = remote_incoming_idr ;
315
+
300
316
}
301
317
302
318
/**
@@ -442,14 +458,18 @@ static uint16_t etx_current_calc(uint16_t etx, uint8_t accumulated_failures)
442
458
*
443
459
* \return 0x0100 to 0xFFFF local incoming IDR value (8 bit fraction)
444
460
*/
445
- uint16_t etx_lqi_dbm_update (int8_t interface_id , uint8_t lqi , int8_t dbm , uint8_t attribute_index )
461
+ uint16_t etx_lqi_dbm_update (int8_t interface_id , uint8_t lqi , int8_t dbm , uint8_t attribute_index , const uint8_t * mac64_addr_ptr )
446
462
{
447
463
uint32_t local_incoming_idr = 0 ;
448
464
uint32_t etx = 0 ;
449
465
450
466
etx_storage_t * entry = etx_storage_entry_get (interface_id , attribute_index );
451
467
468
+
452
469
if (entry ) {
470
+ ext_neigh_info_t etx_neigh_info ;
471
+ etx_neigh_info .attribute_index = attribute_index ;
472
+ etx_neigh_info .mac64 = mac64_addr_ptr ;
453
473
// If local ETX is not set calculate it based on LQI and dBm
454
474
if (!entry -> etx ) {
455
475
etx = etx_dbm_lqi_calc (lqi , dbm );
@@ -458,7 +478,7 @@ uint16_t etx_lqi_dbm_update(int8_t interface_id, uint8_t lqi, int8_t dbm, uint8_
458
478
entry -> tmp_etx = true;
459
479
if (etx_info .callback_ptr ) {
460
480
etx_info .callback_ptr (etx_info .interface_id , 0 , entry -> etx >> 4 ,
461
- attribute_index );
481
+ attribute_index , mac64_addr_ptr );
462
482
}
463
483
}
464
484
// If local ETX has been calculated without remote incoming IDR and
@@ -474,7 +494,7 @@ uint16_t etx_lqi_dbm_update(int8_t interface_id, uint8_t lqi, int8_t dbm, uint8_
474
494
entry -> etx = etx >> 12 ;
475
495
476
496
local_incoming_idr >>= 4 ;
477
- etx_value_change_callback_needed_check (entry -> etx , & (entry -> stored_diff_etx ), entry -> accumulated_failures , attribute_index );
497
+ etx_value_change_callback_needed_check (entry -> etx , & (entry -> stored_diff_etx ), entry -> accumulated_failures , & etx_neigh_info );
478
498
}
479
499
}
480
500
@@ -721,7 +741,7 @@ uint8_t etx_accum_failures_callback_register(nwk_interface_id nwk_id, int8_t int
721
741
*
722
742
* \return ETX value (12 bit fraction)
723
743
*/
724
- static void etx_value_change_callback_needed_check (uint16_t etx , uint16_t * stored_diff_etx , uint8_t accumulated_failures , uint8_t attribute_index )
744
+ static void etx_value_change_callback_needed_check (uint16_t etx , uint16_t * stored_diff_etx , uint8_t accumulated_failures , ext_neigh_info_t * etx_neigh_info )
725
745
{
726
746
uint16_t current_etx ;
727
747
bool callback = false;
@@ -747,7 +767,7 @@ static void etx_value_change_callback_needed_check(uint16_t etx, uint16_t *store
747
767
748
768
// Calls callback function
749
769
if (callback ) {
750
- etx_info .callback_ptr (etx_info .interface_id , (* stored_diff_etx ) >> 4 , current_etx >> 4 , attribute_index );
770
+ etx_info .callback_ptr (etx_info .interface_id , (* stored_diff_etx ) >> 4 , current_etx >> 4 , etx_neigh_info -> attribute_index , etx_neigh_info -> mac64 );
751
771
* stored_diff_etx = current_etx ;
752
772
}
753
773
}
@@ -782,7 +802,7 @@ static void etx_accum_failures_callback_needed_check(etx_storage_t *entry, uint8
782
802
* \param mac64_addr_ptr long MAC address
783
803
*
784
804
*/
785
- void etx_neighbor_remove (int8_t interface_id , uint8_t attribute_index )
805
+ void etx_neighbor_remove (int8_t interface_id , uint8_t attribute_index , const uint8_t * mac64_addr_ptr )
786
806
{
787
807
788
808
//tr_debug("Remove attribute %u", attribute_index);
@@ -795,7 +815,8 @@ void etx_neighbor_remove(int8_t interface_id, uint8_t attribute_index)
795
815
if (!stored_diff_etx ) {
796
816
stored_diff_etx = 0xffff ;
797
817
}
798
- etx_info .callback_ptr (etx_info .interface_id , stored_diff_etx , 0xffff , attribute_index );
818
+
819
+ etx_info .callback_ptr (etx_info .interface_id , stored_diff_etx , 0xffff , attribute_index , mac64_addr_ptr );
799
820
}
800
821
801
822
if (etx_info .cache_sample_requested ) {
@@ -829,7 +850,10 @@ void etx_cache_timer(int8_t interface_id, uint16_t seconds_update)
829
850
etx_sample_storage_t * storage = etx_info .etx_cache_storage_list + neighbour -> index ;
830
851
831
852
if (etx_update_possible (storage , etx_entry , seconds_update )) {
832
- etx_calculation (etx_entry , storage -> attempts_count , storage -> received_acks , neighbour -> index );
853
+ ext_neigh_info_t etx_neigh_info ;
854
+ etx_neigh_info .attribute_index = neighbour -> index ;
855
+ etx_neigh_info .mac64 = neighbour -> mac64 ;
856
+ etx_calculation (etx_entry , storage -> attempts_count , storage -> received_acks , & etx_neigh_info );
833
857
}
834
858
}
835
859
0 commit comments