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 ) || \
@@ -89,6 +90,15 @@ static wisun_tasklet_data_str_t *wisun_tasklet_data_ptr = NULL;
89
90
static wisun_certificates_t * wisun_certificates_ptr = NULL ;
90
91
static mac_api_t * mac_api = NULL ;
91
92
93
+ typedef struct {
94
+ nwk_stats_t nwk_stats ;
95
+ mac_statistics_t mac_statistics ;
96
+ ws_statistics_t ws_statistics ;
97
+ } wisun_statistics_t ;
98
+
99
+ static bool statistics_started = false;
100
+ static wisun_statistics_t * statistics = NULL ;
101
+
92
102
extern fhss_timer_t fhss_functions ;
93
103
94
104
/* private function prototypes */
@@ -99,6 +109,7 @@ static void wisun_tasklet_configure_and_connect_to_network(void);
99
109
static void wisun_tasklet_clear_stored_certificates (void ) ;
100
110
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 );
101
111
static int wisun_tasklet_add_stored_certificates (void ) ;
112
+ static void wisun_tasklet_statistics_do_start (void );
102
113
103
114
/*
104
115
* \brief A function which will be eventually called by NanoStack OS when ever the OS has an event to deliver.
@@ -300,6 +311,10 @@ static void wisun_tasklet_configure_and_connect_to_network(void)
300
311
arm_network_own_certificate_add ((const arm_certificate_entry_s * )& own_cert );
301
312
#endif
302
313
314
+ if (statistics_started ) {
315
+ wisun_tasklet_statistics_do_start ();
316
+ }
317
+
303
318
status = arm_nwk_interface_up (wisun_tasklet_data_ptr -> network_interface_id );
304
319
if (status >= 0 ) {
305
320
wisun_tasklet_data_ptr -> tasklet_state = TASKLET_STATE_BOOTSTRAP_STARTED ;
@@ -566,3 +581,66 @@ int wisun_tasklet_set_trusted_certificate(uint8_t *cert, uint16_t cert_len)
566
581
}
567
582
return wisun_tasklet_store_certificate_data (cert , cert_len , NULL , 0 , false, false, true);
568
583
}
584
+
585
+ int wisun_tasklet_statistics_start (void )
586
+ {
587
+ statistics_started = true;
588
+
589
+ if (statistics == NULL ) {
590
+ statistics = ns_dyn_mem_alloc (sizeof (wisun_statistics_t ));
591
+ }
592
+ if (statistics == NULL ) {
593
+ return -1 ;
594
+ }
595
+ memset (statistics , 0 , sizeof (wisun_statistics_t ));
596
+
597
+ wisun_tasklet_statistics_do_start ();
598
+
599
+ return 0 ;
600
+ }
601
+
602
+ static void wisun_tasklet_statistics_do_start (void )
603
+ {
604
+ if (!wisun_tasklet_data_ptr || wisun_tasklet_data_ptr -> network_interface_id < 0 || !mac_api ) {
605
+ return ;
606
+ }
607
+
608
+ protocol_stats_start (& statistics -> nwk_stats );
609
+ ns_sw_mac_statistics_start (mac_api , & statistics -> mac_statistics );
610
+ ws_statistics_start (wisun_tasklet_data_ptr -> network_interface_id , & statistics -> ws_statistics );
611
+ }
612
+
613
+ int wisun_tasklet_statistics_nw_read (mesh_nw_statistics_t * stats )
614
+ {
615
+ if (!statistics || !stats ) {
616
+ return -1 ;
617
+ }
618
+
619
+ stats -> rpl_total_memory = statistics -> nwk_stats .rpl_total_memory ;
620
+ stats -> etx_1st_parent = statistics -> nwk_stats .etx_1st_parent ;
621
+ stats -> etx_2nd_parent = statistics -> nwk_stats .etx_2nd_parent ;
622
+ stats -> asynch_tx_count = statistics -> ws_statistics .asynch_tx_count ;
623
+ stats -> asynch_rx_count = statistics -> ws_statistics .asynch_rx_count ;
624
+
625
+ return 0 ;
626
+ }
627
+
628
+ int wisun_tasklet_statistics_mac_read (mesh_mac_statistics_t * stats )
629
+ {
630
+ if (!statistics || !stats ) {
631
+ return -1 ;
632
+ }
633
+
634
+ stats -> mac_rx_count = statistics -> mac_statistics .mac_rx_count ;
635
+ stats -> mac_tx_count = statistics -> mac_statistics .mac_tx_count ;
636
+ stats -> mac_bc_rx_count = statistics -> mac_statistics .mac_bc_rx_count ;
637
+ stats -> mac_bc_tx_count = statistics -> mac_statistics .mac_bc_tx_count ;
638
+ stats -> mac_tx_bytes = statistics -> mac_statistics .mac_tx_bytes ;
639
+ stats -> mac_rx_bytes = statistics -> mac_statistics .mac_rx_bytes ;
640
+ stats -> mac_tx_failed_count = statistics -> mac_statistics .mac_tx_failed_count ;
641
+ stats -> mac_retry_count = statistics -> mac_statistics .mac_retry_count ;
642
+ stats -> mac_cca_attempts_count = statistics -> mac_statistics .mac_cca_attempts_count ;
643
+ stats -> mac_failed_cca_count = statistics -> mac_statistics .mac_failed_cca_count ;
644
+
645
+ return 0 ;
646
+ }
0 commit comments