@@ -198,11 +198,46 @@ static esp_err_t cli_route_table(esp_zb_cli_cmd_t *self, int argc, char **argv)
198198 return ESP_OK ;
199199}
200200
201+ static esp_err_t cli_memory_diag (esp_zb_cli_cmd_t * self , int argc , char * * argv )
202+ {
203+ struct {
204+ arg_str_t * memory_type ;
205+ arg_end_t * end ;
206+ } argtable = {
207+ .memory_type = arg_strn (NULL , NULL , "<heap|stack>" , 1 , 1 , "Memory type" ),
208+ .end = arg_end (2 ),
209+ };
210+ esp_err_t ret = ESP_OK ;
211+
212+ /* Parse command line arguments */
213+ EXIT_ON_FALSE (argc > 1 , ESP_OK , arg_print_help ((void * * )& argtable , argv [0 ]));
214+ int nerrors = arg_parse (argc , argv , (void * * )& argtable );
215+ EXIT_ON_FALSE (nerrors == 0 , ESP_ERR_INVALID_ARG , arg_print_errors (stdout , argtable .end , argv [0 ]));
216+
217+ if (!strcmp (argtable .memory_type -> sval [0 ], "heap" )) {
218+ cli_output ("Cur Free Heap: %d bytes\n" , heap_caps_get_free_size (MALLOC_CAP_DEFAULT ));
219+ cli_output ("Min Free Heap: %d bytes\n" , heap_caps_get_minimum_free_size (MALLOC_CAP_DEFAULT ));
220+ cli_output ("Max Free Heap: %d bytes\n" , heap_caps_get_total_size (MALLOC_CAP_DEFAULT ));
221+ } else if (!strcmp (argtable .memory_type -> sval [0 ], "stack" )) {
222+ const char * task_name = "Zigbee_main" ;
223+ TaskHandle_t task_handle ;
224+ EXIT_ON_FALSE ((task_handle = xTaskGetHandle (task_name )) != NULL , ESP_ERR_NOT_FOUND );
225+ cli_output ("Min Free Stack: %d bytes\n" , uxTaskGetStackHighWaterMark (task_handle ));
226+ } else {
227+ EXIT_ON_ERROR (ESP_ERR_INVALID_ARG );
228+ }
229+
230+ exit :
231+ ESP_ZB_CLI_FREE_ARGSTRUCT (& argtable );
232+ return ret ;
233+ }
234+
201235DECLARE_ESP_ZB_CLI_CMD (factoryreset , cli_factoryreset ,, "Reset the device to factory new immediately" );
202236DECLARE_ESP_ZB_CLI_CMD (reboot , cli_reboot ,, "Reboot the device immediately" );
203237DECLARE_ESP_ZB_CLI_CMD (radio , cli_radio ,, "Enable/Disable the radio" );
204238DECLARE_ESP_ZB_CLI_CMD (start , cli_start ,, "Start Zigbee stack" );
205239DECLARE_ESP_ZB_CLI_CMD (trace , cli_trace ,, "Configure Zigbee stack trace log" );
240+ DECLARE_ESP_ZB_CLI_CMD (memdiag , cli_memory_diag ,, "Diagnose memory usages" );
206241DECLARE_ESP_ZB_CLI_CMD_WITH_SUB (macfilter , "Zigbee stack mac filter management" ,
207242 ESP_ZB_CLI_SUBCMD (add , cli_macfilter_add , "Add device ieee addr for filter in" ),
208243 ESP_ZB_CLI_SUBCMD (clear , cli_macfilter_clear , "Clear all entries in the filter" ),
0 commit comments