From 4f72f284ce7e900cda63ebdb8996ddf60114d218 Mon Sep 17 00:00:00 2001 From: Sebastien Date: Tue, 3 Mar 2020 11:42:25 -0500 Subject: [PATCH] Additional messages added to messaging bus, increase dft size --- components/services/component.mk | 1 + components/services/messaging.c | 17 +++++++------ components/services/monitor.c | 35 ++++++++++++-------------- components/telnet/telnet.c | 4 +++ components/wifi-manager/code.js | 3 ++- components/wifi-manager/wifi_manager.c | 3 +++ main/platform_esp32.h | 1 - 7 files changed, 36 insertions(+), 28 deletions(-) diff --git a/components/services/component.mk b/components/services/component.mk index ace79fdb..0bf7bd7a 100644 --- a/components/services/component.mk +++ b/components/services/component.mk @@ -9,3 +9,4 @@ COMPONENT_SRCDIRS := . COMPONENT_ADD_INCLUDEDIRS := . +CFLAGS += -D LOG_LOCAL_LEVEL=ESP_LOG_DEBUG \ No newline at end of file diff --git a/components/services/messaging.c b/components/services/messaging.c index 3d1d9ff6..065de8d3 100644 --- a/components/services/messaging.c +++ b/components/services/messaging.c @@ -27,7 +27,7 @@ typedef struct { RingbufHandle_t buf_handle; } messaging_list_t; static messaging_list_t top; -#define MSG_LENGTH_AVG 201 +#define MSG_LENGTH_AVG 1024 messaging_list_t * get_struct_ptr(messaging_handle_t handle){ return (messaging_list_t *)handle; @@ -176,21 +176,24 @@ esp_err_t messaging_post_to_queue(messaging_handle_t subscriber_handle, single_m return ESP_FAIL; } void * pItem=NULL; - int passes=0; UBaseType_t res=pdFALSE; - while(passes++<3){ - res = xRingbufferSendAcquire(subscriber->buf_handle, &pItem, message_size, pdMS_TO_TICKS(100)); + while(1){ + ESP_LOGD(tag,"Attempting to reserve %d bytes for %s",message_size, str_or_unknown(subscriber->subscriber_name)); + res = xRingbufferSendAcquire(subscriber->buf_handle, &pItem, message_size, pdMS_TO_TICKS(50)); if(res == pdTRUE && pItem){ + ESP_LOGD(tag,"Reserving complete for %s", str_or_unknown(subscriber->subscriber_name)); memcpy(pItem,message,message_size); xRingbufferSendComplete(subscriber->buf_handle, pItem); break; } - ESP_LOGD(tag,"messaged dropped for %s",str_or_unknown(subscriber->subscriber_name)); + ESP_LOGD(tag,"Dropping for %s",str_or_unknown(subscriber->subscriber_name)); single_message_t * dummy = (single_message_t *)xRingbufferReceive(subscriber->buf_handle, &item_size, pdMS_TO_TICKS(50)); if (dummy== NULL) { - ESP_LOGE(tag,"receive from buffer failed"); + ESP_LOGE(tag,"Dropping message failed"); + break; } else { + ESP_LOGD(tag,"Dropping message of %d bytes for %s",item_size, str_or_unknown(subscriber->subscriber_name)); vRingbufferReturnItem(subscriber->buf_handle, (void *)dummy); } } @@ -216,7 +219,7 @@ void messaging_post_message(messaging_types type,messaging_classes msg_class, ch message->type = type; message->msg_class = msg_class; message->sent_time = esp_timer_get_time() / 1000; - ESP_LOGI(tag,"Post: %s",message->message); + ESP_LOGD(tag,"Post: %s",message->message); while(cur){ messaging_post_to_queue(get_handle_ptr(cur), message, msg_size); cur = get_struct_ptr(cur->next); diff --git a/components/services/monitor.c b/components/services/monitor.c index 04199895..15e861ad 100644 --- a/components/services/monitor.c +++ b/components/services/monitor.c @@ -46,13 +46,12 @@ bool spkfault_svc(void); /**************************************************************************************** * */ -static void task_stats( void ) { +static void task_stats( cJSON* top ) { #ifdef CONFIG_FREERTOS_USE_TRACE_FACILITY static struct { TaskStatus_t *tasks; uint32_t total, n; } current, previous; - cJSON * top=cJSON_CreateObject(); cJSON * tlist=cJSON_CreateArray(); current.n = uxTaskGetNumberOfTasks(); current.tasks = malloc( current.n * sizeof( TaskStatus_t ) ); @@ -80,11 +79,6 @@ static void task_stats( void ) { cJSON_AddNumberToObject(t,"st",current.tasks[i].eCurrentState); cJSON_AddNumberToObject(t,"num",current.tasks[i].xTaskNumber); cJSON_AddItemToArray(tlist,t); - char * topsts = cJSON_PrintUnformatted(t); - if(topsts){ - ESP_LOGI(TAG,"task detail: %s",topsts); - FREE_AND_NULL(topsts); - } if (i % 3 == 2 || i == current.n - 1) { ESP_LOGI(TAG, "%s", scratch); n = 0; @@ -104,11 +98,6 @@ static void task_stats( void ) { cJSON_AddStringToObject(t,"st",current.tasks[i].eCurrentState); cJSON_AddNumberToObject(t,"num",current.tasks[i].xTaskNumber); cJSON_AddItemToArray(tlist,t); - char * topsts = cJSON_PrintUnformatted(t); - if(topsts){ - ESP_LOGI(TAG,"task detail: %s",topsts); - FREE_AND_NULL(topsts); - } if (i % 3 == 2 || i == current.n - 1) { ESP_LOGI(TAG, "%s", scratch); n = 0; @@ -116,12 +105,6 @@ static void task_stats( void ) { } #endif cJSON_AddItemToObject(top,"tasks",tlist); - char * top_a= cJSON_PrintUnformatted(top); - if(top_a){ - messaging_post_message(MESSAGING_INFO, MESSAGING_CLASS_STATS,top_a); - FREE_AND_NULL(top_a); - } - cJSON_free(top); if (previous.tasks) free(previous.tasks); previous = current; #endif @@ -131,13 +114,26 @@ static void task_stats( void ) { * */ static void monitor_callback(TimerHandle_t xTimer) { + cJSON * top=cJSON_CreateObject(); + cJSON_AddNumberToObject(top,"free_iram",heap_caps_get_free_size(MALLOC_CAP_INTERNAL)); + cJSON_AddNumberToObject(top,"min_free_iram",heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL)); + cJSON_AddNumberToObject(top,"free_spiram",heap_caps_get_free_size(MALLOC_CAP_SPIRAM)); + cJSON_AddNumberToObject(top,"min_free_spiram",heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM)); + ESP_LOGI(TAG, "Heap internal:%zu (min:%zu) external:%zu (min:%zu)", heap_caps_get_free_size(MALLOC_CAP_INTERNAL), heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL), heap_caps_get_free_size(MALLOC_CAP_SPIRAM), heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM)); - task_stats(); + task_stats(top); + char * top_a= cJSON_PrintUnformatted(top); + if(top_a){ + messaging_post_message(MESSAGING_INFO, MESSAGING_CLASS_STATS,top_a); + FREE_AND_NULL(top_a); + } + cJSON_free(top); + } /**************************************************************************************** @@ -145,6 +141,7 @@ static void monitor_callback(TimerHandle_t xTimer) { */ static void jack_handler_default(void *id, button_event_e event, button_press_e mode, bool long_press) { ESP_LOGD(TAG, "Jack %s", event == BUTTON_PRESSED ? "inserted" : "removed"); + messaging_post_message(MESSAGING_INFO, MESSAGING_CLASS_SYSTEM,"jack is %s",BUTTON_PRESSED ? "inserted" : "removed"); if (jack_handler_svc) (*jack_handler_svc)(event == BUTTON_PRESSED); } diff --git a/components/telnet/telnet.c b/components/telnet/telnet.c index 526ed468..03bab437 100644 --- a/components/telnet/telnet.c +++ b/components/telnet/telnet.c @@ -38,8 +38,10 @@ #include "config.h" #include "nvs_utilities.h" #include "platform_esp32.h" +#include "messaging.h" #include "trace.h" + /************************************ * Globals */ @@ -119,6 +121,8 @@ void init_telnet(){ buf_handle = xRingbufferCreateStatic(log_buf_size, RINGBUF_TYPE_BYTEBUF, buffer_storage, buffer_struct); if (buf_handle == NULL) { ESP_LOGE(TAG,"Failed to create ring buffer for telnet!"); + messaging_post_message(MESSAGING_ERROR,MESSAGING_CLASS_SYSTEM,"Failed to allocate memory for telnet buffer"); + return; } diff --git a/components/wifi-manager/code.js b/components/wifi-manager/code.js index 58ca2f01..6a6f12f5 100644 --- a/components/wifi-manager/code.js +++ b/components/wifi-manager/code.js @@ -683,8 +683,9 @@ function getMessages() { var stats_data = JSON.parse(msg["message"]); console.log(msg_time + " - Number of tasks on the ESP32: " + stats_data["ntasks"]); var stats_tasks = stats_data["tasks"]; + console.log(msg_time + '\tname' + '\tcpu' + '\tstate'+ '\tminstk'+ '\tbprio'+ '\tcprio'+ '\tnum' ); stats_tasks.forEach(function(task) { - console.log(msg_time + " - " + task["nme"] + ' - '+ task["cpu"]); + console.log(msg_time + '\t' + task["nme"] + '\t'+ task["cpu"] + '\t'+ task_state_t[task["st"]]+ '\t'+ task["minstk"]+ '\t'+ task["bprio"]+ '\t'+ task["cprio"]+ '\t'+ task["num"]); }); break; case "MESSAGING_CLASS_SYSTEM": diff --git a/components/wifi-manager/wifi_manager.c b/components/wifi-manager/wifi_manager.c index 667d01d6..430ffd6f 100644 --- a/components/wifi-manager/wifi_manager.c +++ b/components/wifi-manager/wifi_manager.c @@ -361,6 +361,7 @@ esp_err_t wifi_manager_save_sta_config(){ esp_err = nvs_commit(handle); if (esp_err != ESP_OK) { ESP_LOGE(TAG, "Unable to commit changes. Error %s", esp_err_to_name(esp_err)); + messaging_post_message(MESSAGING_ERROR,MESSAGING_CLASS_SYSTEM,"Unable to save wifi credentials. %s",esp_err_to_name(esp_err)); return esp_err; } nvs_close(handle); @@ -1335,6 +1336,8 @@ void wifi_manager( void * pvParameters ){ else{ /* lost connection ? */ ESP_LOGE(TAG, "WiFi Connection lost."); + messaging_post_message(MESSAGING_WARNING,MESSAGING_CLASS_SYSTEM,"WiFi Connection lost"); + if(wifi_manager_lock_json_buffer( portMAX_DELAY )){ wifi_manager_generate_ip_info_json( UPDATE_LOST_CONNECTION ); wifi_manager_unlock_json_buffer(); diff --git a/main/platform_esp32.h b/main/platform_esp32.h index 3443e069..f0fff28a 100644 --- a/main/platform_esp32.h +++ b/main/platform_esp32.h @@ -20,7 +20,6 @@ */ #pragma once - #include "esp_pthread.h" #ifndef SQUEEZELITE_ESP32_RELEASE_URL #define SQUEEZELITE_ESP32_RELEASE_URL "https://github.com/sle118/squeezelite-esp32/releases"