Skip to content

Commit 8dc200b

Browse files
author
Jarkko Paso
committed
FHSS: Created statistics for WS
1 parent 3608153 commit 8dc200b

File tree

14 files changed

+71
-19
lines changed

14 files changed

+71
-19
lines changed

nanostack/fhss_config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ typedef struct fhss_statistics {
183183

184184
/** FHSS synchronization lost counter. */
185185
uint32_t fhss_synch_lost;
186+
187+
/** FHSS TX to unknown neighbour counter. */
188+
uint32_t fhss_unknown_neighbor;
189+
190+
/** FHSS channel retry counter. */
191+
uint32_t fhss_channel_retry;
186192
} fhss_statistics_t;
187193

188194
/**

nanostack/net_fhss.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ extern int ns_fhss_ws_configuration_set(const fhss_api_t *fhss_api, const fhss_w
7676
*/
7777
extern int ns_fhss_delete(fhss_api_t *fhss_api);
7878

79+
/**
80+
* @brief Starts collecting FHSS statistics.
81+
* @param fhss_api FHSS instance.
82+
* @param fhss_statistics Pointer to stored statistics.
83+
* @return 0 on success, -1 on fail.
84+
*/
85+
extern int ns_fhss_statistics_start(const fhss_api_t *fhss_api, fhss_statistics_t *fhss_statistics);
86+
7987

8088
#ifdef __cplusplus
8189
}

source/MAC/IEEE802_15_4/mac_pd_sap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,8 @@ static int8_t mac_data_interface_tx_done_cb(protocol_interface_rf_mac_setup_s *r
487487
return 0;
488488
} else {
489489
// Do not update CCA count when Ack is received, it was already updated with PHY_LINK_TX_SUCCESS event
490-
if ((status != PHY_LINK_TX_DONE) && (status != PHY_LINK_TX_DONE_PENDING)) {
490+
// Do not update CCA count when CCA_OK is received, PHY_LINK_TX_SUCCESS will update it
491+
if ((status != PHY_LINK_TX_DONE) && (status != PHY_LINK_TX_DONE_PENDING) && (status != PHY_LINK_CCA_OK)) {
491492
/* For PHY_LINK_TX_SUCCESS and PHY_LINK_CCA_FAIL cca_retry must always be > 0.
492493
* PHY_LINK_TX_FAIL either happened during transmission or when waiting Ack -> we must use the CCA count given by PHY.
493494
*/

source/Service_Libs/fhss/fhss.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fhss_structure_t *fhss_enable(fhss_api_t *fhss_api, const fhss_configuration_t *
7171

7272
fhss_struct->fhss_event_timer = eventOS_callback_timer_register(fhss_event_timer_cb);
7373
fhss_struct->bs->fhss_configuration = *fhss_configuration;
74-
fhss_struct->bs->fhss_stats_ptr = fhss_statistics;
74+
fhss_struct->fhss_stats_ptr = fhss_statistics;
7575
fhss_struct->number_of_channels = channel_count;
7676

7777
// set a invalid id to tasklet_id, so we know that one is not started yet

source/Service_Libs/fhss/fhss.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ struct fhss_bs {
9797
uint16_t channel_list_counter;
9898
uint16_t synch_panid;
9999
uint32_t synch_interval;
100-
struct fhss_statistics *fhss_stats_ptr;
101100
struct fhss_beacon_info *fhss_beacon_info_store;
102101
struct fhss_configuration fhss_configuration;
103102
struct fhss_synch_configuration synch_configuration;

source/Service_Libs/fhss/fhss_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct fhss_structure {
4848
struct fhss_ws *ws;
4949
struct fhss_timer platform_functions;
5050
struct fhss_callback callbacks;
51+
struct fhss_statistics *fhss_stats_ptr;
5152
fhss_failed_tx_list_t fhss_failed_tx_list;
5253
uint8_t synch_parent[8];
5354
};

source/Service_Libs/fhss/fhss_configuration_interface.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "Service_Libs/fhss/fhss.h"
2525
#include "Service_Libs/fhss/fhss_common.h"
2626
#include "Service_Libs/fhss/fhss_ws.h"
27+
#include "Service_Libs/fhss/fhss_statistics.h"
2728
#include "ns_trace.h"
2829

2930
#define TRACE_GROUP "fhss"
@@ -138,3 +139,12 @@ int ns_fhss_ws_set_hop_count(const fhss_api_t *fhss_api, const uint8_t hop_count
138139
}
139140
return fhss_ws_set_hop_count(fhss_structure, hop_count);
140141
}
142+
143+
int ns_fhss_statistics_start(const fhss_api_t *fhss_api, fhss_statistics_t *fhss_statistics)
144+
{
145+
fhss_structure_t *fhss_structure = fhss_get_object_with_api(fhss_api);
146+
if (!fhss_structure) {
147+
return -1;
148+
}
149+
return fhss_statistics_start(fhss_structure, fhss_statistics);
150+
}

source/Service_Libs/fhss/fhss_statistics.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,35 @@
2424

2525
void fhss_stats_update(fhss_structure_t *fhss_structure, fhss_stats_type_t type, uint32_t update_val)
2626
{
27-
if (fhss_structure->bs->fhss_stats_ptr) {
27+
if (fhss_structure->fhss_stats_ptr) {
2828
switch (type) {
2929
case STATS_FHSS_DRIFT_COMP:
30-
fhss_structure->bs->fhss_stats_ptr->fhss_drift_compensation = update_val;
30+
fhss_structure->fhss_stats_ptr->fhss_drift_compensation = update_val;
3131
break;
3232
case STATS_FHSS_HOP_COUNT:
33-
fhss_structure->bs->fhss_stats_ptr->fhss_hop_count = update_val;
33+
fhss_structure->fhss_stats_ptr->fhss_hop_count = update_val;
3434
break;
3535
case STATS_FHSS_SYNCH_INTERVAL:
36-
fhss_structure->bs->fhss_stats_ptr->fhss_synch_interval = update_val;
36+
fhss_structure->fhss_stats_ptr->fhss_synch_interval = update_val;
3737
break;
3838
case STATS_FHSS_AVG_SYNCH_FIX:
39-
fhss_structure->bs->fhss_stats_ptr->fhss_prev_avg_synch_fix = update_val;
39+
fhss_structure->fhss_stats_ptr->fhss_prev_avg_synch_fix = update_val;
4040
break;
4141
case STATS_FHSS_SYNCH_LOST:
42-
fhss_structure->bs->fhss_stats_ptr->fhss_synch_lost += update_val;
42+
fhss_structure->fhss_stats_ptr->fhss_synch_lost += update_val;
43+
break;
44+
case STATS_FHSS_UNKNOWN_NEIGHBOR:
45+
fhss_structure->fhss_stats_ptr->fhss_unknown_neighbor += update_val;
46+
break;
47+
case STATS_FHSS_CHANNEL_RETRY:
48+
fhss_structure->fhss_stats_ptr->fhss_channel_retry += update_val;
4349
break;
4450
}
4551
}
4652
}
53+
54+
int fhss_statistics_start(fhss_structure_t *fhss_structure, fhss_statistics_t *fhss_statistics)
55+
{
56+
fhss_structure->fhss_stats_ptr = fhss_statistics;
57+
return 0;
58+
}

source/Service_Libs/fhss/fhss_statistics.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ typedef enum {
2323
STATS_FHSS_SYNCH_INTERVAL,
2424
STATS_FHSS_AVG_SYNCH_FIX,
2525
STATS_FHSS_SYNCH_LOST,
26+
STATS_FHSS_UNKNOWN_NEIGHBOR,
27+
STATS_FHSS_CHANNEL_RETRY
2628
} fhss_stats_type_t;
2729

2830
void fhss_stats_update(fhss_structure_t *fhss_structure, fhss_stats_type_t type, uint32_t update_val);
31+
int fhss_statistics_start(fhss_structure_t *fhss_structure, fhss_statistics_t *fhss_statistics);
2932

3033
#endif /* FHSS_STATISTICS_H_ */

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "fhss_config.h"
2121
#include "fhss.h"
2222
#include "fhss_common.h"
23+
#include "fhss_statistics.h"
2324
#include "channel_list.h"
2425
#include "channel_functions.h"
2526
#include "fhss_ws.h"
@@ -143,7 +144,7 @@ fhss_structure_t *fhss_ws_enable(fhss_api_t *fhss_api, const fhss_ws_configurati
143144
fhss_struct->fhss_event_timer = eventOS_callback_timer_register(fhss_event_timer_cb);
144145
fhss_struct->ws->fhss_configuration = *fhss_configuration;
145146
fhss_struct->number_of_channels = channel_count;
146-
fhss_struct->own_hop = 0xff;
147+
fhss_ws_set_hop_count(fhss_struct, 0xff);
147148
fhss_struct->rx_channel = fhss_configuration->unicast_fixed_channel;
148149
fhss_struct->ws->min_synch_interval = DEFAULT_MIN_SYNCH_INTERVAL;
149150
fhss_set_txrx_slot_length(fhss_struct);
@@ -472,6 +473,7 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
472473
if (fhss_structure->fhss_state == FHSS_SYNCHRONIZED) {
473474
fhss_ws_neighbor_timing_info_t *neighbor_timing_info = fhss_structure->ws->get_neighbor_info(api, destination_address);
474475
if (!neighbor_timing_info) {
476+
fhss_stats_update(fhss_structure, STATS_FHSS_UNKNOWN_NEIGHBOR, 1);
475477
return -2;
476478
}
477479
// TODO: WS bootstrap has to store neighbors number of channels
@@ -687,6 +689,7 @@ static bool fhss_ws_data_tx_fail_callback(const fhss_api_t *api, uint8_t handle,
687689
// Create new failure handle and return true to retransmit
688690
fhss_failed_handle_add(fhss_structure, handle, fhss_structure->rx_channel);
689691
}
692+
fhss_stats_update(fhss_structure, STATS_FHSS_CHANNEL_RETRY, 1);
690693
return true;
691694
}
692695

@@ -858,9 +861,11 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8],
858861
drift_per_ms_tmp = -MAX_DRIFT_COMPENSATION_STEP;
859862
}
860863
fhss_structure->ws->drift_per_millisecond_ns += drift_per_ms_tmp;
864+
fhss_stats_update(fhss_structure, STATS_FHSS_DRIFT_COMP, fhss_structure->ws->drift_per_millisecond_ns * bc_timing_info->broadcast_dwell_interval);
861865
}
862866
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);
863867
}
868+
fhss_stats_update(fhss_structure, STATS_FHSS_SYNCH_INTERVAL, US_TO_S(time_since_last_synch_us));
864869
return 0;
865870
}
866871

@@ -915,6 +920,8 @@ int fhss_ws_configuration_set(fhss_structure_t *fhss_structure, const fhss_ws_co
915920
int fhss_ws_set_hop_count(fhss_structure_t *fhss_structure, const uint8_t hop_count)
916921
{
917922
fhss_structure->own_hop = hop_count;
923+
fhss_stats_update(fhss_structure, STATS_FHSS_HOP_COUNT, fhss_structure->own_hop);
918924
return 0;
919925
}
926+
920927
#endif // HAVE_WS

test/nanostack/unittest/service_libs/fhss_config/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ TEST_SRC_FILES = \
1616
../../stub/fhss_stub.c \
1717
../../stub/fhss_common_stub.c \
1818
../../stub/fhss_ws_stub.c \
19+
../../stub/fhss_statistics_stub.c \
1920

2021
include ../../MakefileWorker.mk
2122

test/nanostack/unittest/service_libs/fhss_statistics/test_fhss_statistics.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,41 @@
2424
#include "Service_Libs/fhss/fhss_statistics.h"
2525

2626
static fhss_structure_t fhss_struct;
27-
static fhss_bs_t bs;
2827
static fhss_statistics_t fhss_stats_ptr;
2928

3029
static init_fhss_struct(void)
3130
{
3231
memset(&fhss_stats_ptr, 0, sizeof(fhss_statistics_t));
33-
bs.fhss_stats_ptr = &fhss_stats_ptr;
34-
fhss_struct.bs = &bs;
32+
fhss_struct.fhss_stats_ptr = &fhss_stats_ptr;
3533
}
3634

3735
bool test_fhss_stats_update()
3836
{
3937
init_fhss_struct();
4038
// Test drift compensation
4139
fhss_stats_update(&fhss_struct, STATS_FHSS_DRIFT_COMP, 10);
42-
if (fhss_struct.bs->fhss_stats_ptr->fhss_drift_compensation != 10) {
40+
if (fhss_struct.fhss_stats_ptr->fhss_drift_compensation != 10) {
4341
return false;
4442
}
4543
// Test hop count
4644
fhss_stats_update(&fhss_struct, STATS_FHSS_HOP_COUNT, 1);
47-
if (fhss_struct.bs->fhss_stats_ptr->fhss_hop_count != 1) {
45+
if (fhss_struct.fhss_stats_ptr->fhss_hop_count != 1) {
4846
return false;
4947
}
5048
// Test synch interval
5149
fhss_stats_update(&fhss_struct, STATS_FHSS_SYNCH_INTERVAL, 960);
52-
if (fhss_struct.bs->fhss_stats_ptr->fhss_synch_interval != 960) {
50+
if (fhss_struct.fhss_stats_ptr->fhss_synch_interval != 960) {
5351
return false;
5452
}
5553
// Test average synch fix
5654
fhss_stats_update(&fhss_struct, STATS_FHSS_AVG_SYNCH_FIX, 1000);
57-
if (fhss_struct.bs->fhss_stats_ptr->fhss_prev_avg_synch_fix != 1000) {
55+
if (fhss_struct.fhss_stats_ptr->fhss_prev_avg_synch_fix != 1000) {
5856
return false;
5957
}
6058
// Test synch lost count
61-
fhss_struct.bs->fhss_stats_ptr->fhss_synch_lost = 1;
59+
fhss_struct.fhss_stats_ptr->fhss_synch_lost = 1;
6260
fhss_stats_update(&fhss_struct, STATS_FHSS_SYNCH_LOST, 1);
63-
if (fhss_struct.bs->fhss_stats_ptr->fhss_synch_lost != 2) {
61+
if (fhss_struct.fhss_stats_ptr->fhss_synch_lost != 2) {
6462
return false;
6563
}
6664
return true;

test/nanostack/unittest/service_libs/fhss_ws/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ TEST_SRC_FILES = \
2323
../../stub/fhss_common_stub.c \
2424
../../stub/fhss_callbacks_stub.c \
2525
../../stub/fhss_platform_stub.c \
26+
../../stub/fhss_statistics_stub.c \
2627
../../stub/platform_stub.c \
2728

2829
include ../../MakefileWorker.mk

test/nanostack/unittest/stub/fhss_statistics_stub.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ void fhss_stats_update(fhss_structure_t *fhss_structure, fhss_stats_type_t type,
2727
{
2828

2929
}
30+
31+
int fhss_statistics_start(fhss_structure_t *fhss_structure, fhss_statistics_t *fhss_statistics)
32+
{
33+
return 0;
34+
}

0 commit comments

Comments
 (0)