29
29
#include "sw_mac.h"
30
30
#include "ns_list.h"
31
31
#include "net_interface.h"
32
+ #include "nwk_stats_api.h"
32
33
#include "ws_management_api.h" //ws_management_node_init
33
34
#ifdef MBED_CONF_MBED_MESH_API_CERTIFICATE_HEADER
34
35
#if !defined(MBED_CONF_MBED_MESH_API_ROOT_CERTIFICATE ) || !defined(MBED_CONF_MBED_MESH_API_OWN_CERTIFICATE ) || \
@@ -118,6 +119,15 @@ static wisun_network_settings_t wisun_settings_str = {
118
119
};
119
120
static mac_api_t * mac_api = NULL ;
120
121
122
+ typedef struct {
123
+ nwk_stats_t nwk_stats ;
124
+ mac_statistics_t mac_statistics ;
125
+ ws_statistics_t ws_statistics ;
126
+ } wisun_statistics_t ;
127
+
128
+ static bool statistics_started = false;
129
+ static wisun_statistics_t * statistics = NULL ;
130
+
121
131
extern fhss_timer_t fhss_functions ;
122
132
123
133
/* private function prototypes */
@@ -128,6 +138,7 @@ static void wisun_tasklet_configure_and_connect_to_network(void);
128
138
static void wisun_tasklet_clear_stored_certificates (void ) ;
129
139
static int wisun_tasklet_store_certificate_data (const uint8_t * cert , uint16_t cert_len , const uint8_t * cert_key , uint16_t cert_key_len , bool remove_own , bool remove_trusted , bool trusted_cert );
130
140
static int wisun_tasklet_add_stored_certificates (void ) ;
141
+ static void wisun_tasklet_statistics_do_start (void );
131
142
132
143
/*
133
144
* \brief A function which will be eventually called by NanoStack OS when ever the OS has an event to deliver.
@@ -257,7 +268,6 @@ static void wisun_tasklet_configure_and_connect_to_network(void)
257
268
} else {
258
269
wisun_tasklet_data_ptr -> operating_mode = NET_6LOWPAN_ROUTER ;
259
270
}
260
-
261
271
wisun_tasklet_data_ptr -> operating_mode_extension = NET_6LOWPAN_WS ;
262
272
263
273
arm_nwk_interface_configure_6lowpan_bootstrap_set (
@@ -367,6 +377,10 @@ static void wisun_tasklet_configure_and_connect_to_network(void)
367
377
arm_network_own_certificate_add ((const arm_certificate_entry_s * )& own_cert );
368
378
#endif
369
379
380
+ if (statistics_started ) {
381
+ wisun_tasklet_statistics_do_start ();
382
+ }
383
+
370
384
status = arm_nwk_interface_up (wisun_tasklet_data_ptr -> network_interface_id );
371
385
if (status >= 0 ) {
372
386
wisun_tasklet_data_ptr -> tasklet_state = TASKLET_STATE_BOOTSTRAP_STARTED ;
@@ -681,3 +695,66 @@ int wisun_tasklet_set_trusted_certificate(uint8_t *cert, uint16_t cert_len)
681
695
}
682
696
return wisun_tasklet_store_certificate_data (cert , cert_len , NULL , 0 , false, false, true);
683
697
}
698
+
699
+ int wisun_tasklet_statistics_start (void )
700
+ {
701
+ statistics_started = true;
702
+
703
+ if (statistics == NULL ) {
704
+ statistics = ns_dyn_mem_alloc (sizeof (wisun_statistics_t ));
705
+ }
706
+ if (statistics == NULL ) {
707
+ return -1 ;
708
+ }
709
+ memset (statistics , 0 , sizeof (wisun_statistics_t ));
710
+
711
+ wisun_tasklet_statistics_do_start ();
712
+
713
+ return 0 ;
714
+ }
715
+
716
+ static void wisun_tasklet_statistics_do_start (void )
717
+ {
718
+ if (!wisun_tasklet_data_ptr || wisun_tasklet_data_ptr -> network_interface_id < 0 || !mac_api ) {
719
+ return ;
720
+ }
721
+
722
+ protocol_stats_start (& statistics -> nwk_stats );
723
+ ns_sw_mac_statistics_start (mac_api , & statistics -> mac_statistics );
724
+ ws_statistics_start (wisun_tasklet_data_ptr -> network_interface_id , & statistics -> ws_statistics );
725
+ }
726
+
727
+ int wisun_tasklet_statistics_nw_read (mesh_nw_statistics_t * stats )
728
+ {
729
+ if (!statistics || !stats ) {
730
+ return -1 ;
731
+ }
732
+
733
+ stats -> rpl_total_memory = statistics -> nwk_stats .rpl_total_memory ;
734
+ stats -> etx_1st_parent = statistics -> nwk_stats .etx_1st_parent ;
735
+ stats -> etx_2nd_parent = statistics -> nwk_stats .etx_2nd_parent ;
736
+ stats -> asynch_tx_count = statistics -> ws_statistics .asynch_tx_count ;
737
+ stats -> asynch_rx_count = statistics -> ws_statistics .asynch_rx_count ;
738
+
739
+ return 0 ;
740
+ }
741
+
742
+ int wisun_tasklet_statistics_mac_read (mesh_mac_statistics_t * stats )
743
+ {
744
+ if (!statistics || !stats ) {
745
+ return -1 ;
746
+ }
747
+
748
+ stats -> mac_rx_count = statistics -> mac_statistics .mac_rx_count ;
749
+ stats -> mac_tx_count = statistics -> mac_statistics .mac_tx_count ;
750
+ stats -> mac_bc_rx_count = statistics -> mac_statistics .mac_bc_rx_count ;
751
+ stats -> mac_bc_tx_count = statistics -> mac_statistics .mac_bc_tx_count ;
752
+ stats -> mac_tx_bytes = statistics -> mac_statistics .mac_tx_bytes ;
753
+ stats -> mac_rx_bytes = statistics -> mac_statistics .mac_rx_bytes ;
754
+ stats -> mac_tx_failed_count = statistics -> mac_statistics .mac_tx_failed_count ;
755
+ stats -> mac_retry_count = statistics -> mac_statistics .mac_retry_count ;
756
+ stats -> mac_cca_attempts_count = statistics -> mac_statistics .mac_cca_attempts_count ;
757
+ stats -> mac_failed_cca_count = statistics -> mac_statistics .mac_failed_cca_count ;
758
+
759
+ return 0 ;
760
+ }
0 commit comments