chore(logging): trim firmware logs and remove runtime diagnostics scaffolding
This commit is contained in:
@@ -10,7 +10,6 @@ idf_component_register(
|
||||
"src/platform_mic_key.c"
|
||||
"src/voice_audio.c"
|
||||
"src/runtime_policy.c"
|
||||
"src/runtime_diagnostics.c"
|
||||
INCLUDE_DIRS
|
||||
"include"
|
||||
PRIV_INCLUDE_DIRS
|
||||
|
||||
@@ -150,40 +150,6 @@ uint32_t runtime_policy_image_download_timeout_default_ms(void);
|
||||
uint32_t runtime_policy_image_download_timeout_min_ms(void);
|
||||
uint32_t runtime_policy_image_download_timeout_max_ms(void);
|
||||
|
||||
// ---------- runtime_diagnostics ----------
|
||||
typedef enum {
|
||||
RUNTIME_DIAG_COUNTER_LIFECYCLE_START_ATTEMPT = 0,
|
||||
RUNTIME_DIAG_COUNTER_LIFECYCLE_START_SUCCESS,
|
||||
RUNTIME_DIAG_COUNTER_LIFECYCLE_START_FAILED,
|
||||
RUNTIME_DIAG_COUNTER_LIFECYCLE_START_RETRY,
|
||||
RUNTIME_DIAG_COUNTER_LIFECYCLE_STOP_ATTEMPT,
|
||||
RUNTIME_DIAG_COUNTER_LIFECYCLE_STOP_SUCCESS,
|
||||
RUNTIME_DIAG_COUNTER_LIFECYCLE_STOP_FAILED,
|
||||
RUNTIME_DIAG_COUNTER_WIFI_CONNECT_SUCCESS,
|
||||
RUNTIME_DIAG_COUNTER_WIFI_CONNECT_FAILED,
|
||||
RUNTIME_DIAG_COUNTER_WIFI_CONNECT_TIMEOUT,
|
||||
RUNTIME_DIAG_COUNTER_PRINTER_JOB_SUBMITTED,
|
||||
RUNTIME_DIAG_COUNTER_PRINTER_JOB_SUCCESS,
|
||||
RUNTIME_DIAG_COUNTER_PRINTER_JOB_FAILED,
|
||||
RUNTIME_DIAG_COUNTER_PRINTER_JOB_CANCELED,
|
||||
RUNTIME_DIAG_COUNTER_IMAGE_GENERATE_ATTEMPT,
|
||||
RUNTIME_DIAG_COUNTER_IMAGE_GENERATE_SUCCESS,
|
||||
RUNTIME_DIAG_COUNTER_IMAGE_GENERATE_FAILED,
|
||||
RUNTIME_DIAG_COUNTER_IMAGE_GENERATE_TIMEOUT,
|
||||
RUNTIME_DIAG_COUNTER_MAX,
|
||||
} runtime_diag_counter_t;
|
||||
|
||||
typedef enum {
|
||||
RUNTIME_DIAG_GAUGE_LIFECYCLE_STATE = 0,
|
||||
RUNTIME_DIAG_GAUGE_STATUS_POLL_PAUSE_DEPTH,
|
||||
RUNTIME_DIAG_GAUGE_PRINTER_QUEUE_DEPTH,
|
||||
RUNTIME_DIAG_GAUGE_MAX,
|
||||
} runtime_diag_gauge_t;
|
||||
|
||||
void runtime_diag_counter_add(runtime_diag_counter_t counter, uint32_t delta);
|
||||
void runtime_diag_set_gauge(runtime_diag_gauge_t gauge, int32_t value);
|
||||
void runtime_diag_record_error(const char *source, esp_err_t code, const char *message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
#include "platform.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_timer.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
static SemaphoreHandle_t s_lock;
|
||||
typedef struct {
|
||||
uint64_t counters[RUNTIME_DIAG_COUNTER_MAX];
|
||||
int32_t gauges[RUNTIME_DIAG_GAUGE_MAX];
|
||||
int64_t last_error_ms;
|
||||
esp_err_t last_error_code;
|
||||
char last_error_source[32];
|
||||
char last_error_message[96];
|
||||
} runtime_diag_state_t;
|
||||
|
||||
static runtime_diag_state_t s_snapshot;
|
||||
|
||||
static void runtime_diag_ensure_lock(void) {
|
||||
if (s_lock == NULL) {
|
||||
s_lock = xSemaphoreCreateMutex();
|
||||
}
|
||||
}
|
||||
|
||||
void runtime_diag_counter_add(runtime_diag_counter_t counter, uint32_t delta) {
|
||||
if (counter < 0 || counter >= RUNTIME_DIAG_COUNTER_MAX || delta == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
runtime_diag_ensure_lock();
|
||||
if (s_lock == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (xSemaphoreTake(s_lock, pdMS_TO_TICKS(50)) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
s_snapshot.counters[counter] += delta;
|
||||
xSemaphoreGive(s_lock);
|
||||
}
|
||||
|
||||
void runtime_diag_set_gauge(runtime_diag_gauge_t gauge, int32_t value) {
|
||||
if (gauge < 0 || gauge >= RUNTIME_DIAG_GAUGE_MAX) {
|
||||
return;
|
||||
}
|
||||
|
||||
runtime_diag_ensure_lock();
|
||||
if (s_lock == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (xSemaphoreTake(s_lock, pdMS_TO_TICKS(50)) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
s_snapshot.gauges[gauge] = value;
|
||||
xSemaphoreGive(s_lock);
|
||||
}
|
||||
|
||||
void runtime_diag_record_error(const char *source, esp_err_t code, const char *message) {
|
||||
runtime_diag_ensure_lock();
|
||||
if (s_lock == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (xSemaphoreTake(s_lock, pdMS_TO_TICKS(100)) != pdTRUE) {
|
||||
return;
|
||||
}
|
||||
|
||||
s_snapshot.last_error_ms = esp_timer_get_time() / 1000;
|
||||
s_snapshot.last_error_code = code;
|
||||
strlcpy(s_snapshot.last_error_source,
|
||||
source != NULL ? source : "unknown",
|
||||
sizeof(s_snapshot.last_error_source));
|
||||
strlcpy(s_snapshot.last_error_message,
|
||||
message != NULL ? message : "unknown",
|
||||
sizeof(s_snapshot.last_error_message));
|
||||
|
||||
xSemaphoreGive(s_lock);
|
||||
}
|
||||
@@ -150,21 +150,6 @@ static esp_err_t wifi_manager_load_credentials(wifi_sta_credentials_t *out_creds
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void wifi_manager_record_connect_result(esp_err_t err, const char *stage) {
|
||||
if (err == ESP_OK) {
|
||||
runtime_diag_counter_add(RUNTIME_DIAG_COUNTER_WIFI_CONNECT_SUCCESS, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (err == ESP_ERR_TIMEOUT) {
|
||||
runtime_diag_counter_add(RUNTIME_DIAG_COUNTER_WIFI_CONNECT_TIMEOUT, 1);
|
||||
} else {
|
||||
runtime_diag_counter_add(RUNTIME_DIAG_COUNTER_WIFI_CONNECT_FAILED, 1);
|
||||
}
|
||||
|
||||
runtime_diag_record_error("wifi_connect", err, stage);
|
||||
}
|
||||
|
||||
static void wifi_event_handler(void *arg,
|
||||
esp_event_base_t event_base,
|
||||
int32_t event_id,
|
||||
@@ -373,14 +358,12 @@ static esp_err_t wifi_manager_scan_get_handler(httpd_req_t *req) {
|
||||
|
||||
esp_err_t err = esp_wifi_scan_start(&scan_cfg, true);
|
||||
if (err != ESP_OK) {
|
||||
runtime_diag_record_error("wifi_scan", err, "esp_wifi_scan_start failed");
|
||||
return wifi_manager_send_prov_json(req, false, "scan_failed");
|
||||
}
|
||||
|
||||
uint16_t ap_count = 0;
|
||||
err = esp_wifi_scan_get_ap_num(&ap_count);
|
||||
if (err != ESP_OK) {
|
||||
runtime_diag_record_error("wifi_scan", err, "esp_wifi_scan_get_ap_num failed");
|
||||
return wifi_manager_send_prov_json(req, false, "scan_failed");
|
||||
}
|
||||
|
||||
@@ -399,7 +382,6 @@ static esp_err_t wifi_manager_scan_get_handler(httpd_req_t *req) {
|
||||
err = esp_wifi_scan_get_ap_records(&fetch_num, records);
|
||||
if (err != ESP_OK) {
|
||||
free(records);
|
||||
runtime_diag_record_error("wifi_scan", err, "esp_wifi_scan_get_ap_records failed");
|
||||
return wifi_manager_send_prov_json(req, false, "scan_failed");
|
||||
}
|
||||
ap_count = fetch_num;
|
||||
@@ -494,25 +476,21 @@ static esp_err_t wifi_manager_connect_sta(const wifi_sta_credentials_t *creds, b
|
||||
|
||||
err = esp_wifi_set_mode(keep_softap ? WIFI_MODE_APSTA : WIFI_MODE_STA);
|
||||
if (err != ESP_OK) {
|
||||
wifi_manager_record_connect_result(err, "set mode failed");
|
||||
return err;
|
||||
}
|
||||
|
||||
err = esp_wifi_set_config(WIFI_IF_STA, &wifi_config);
|
||||
if (err != ESP_OK) {
|
||||
wifi_manager_record_connect_result(err, "set sta config failed");
|
||||
return err;
|
||||
}
|
||||
|
||||
err = esp_wifi_start();
|
||||
if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) {
|
||||
wifi_manager_record_connect_result(err, "wifi start failed");
|
||||
return err;
|
||||
}
|
||||
|
||||
err = esp_wifi_connect();
|
||||
if (err != ESP_OK && err != ESP_ERR_WIFI_CONN) {
|
||||
wifi_manager_record_connect_result(err, "wifi connect failed");
|
||||
return err;
|
||||
}
|
||||
ESP_LOGI(TAG, "trying to connect to SSID:%s", creds->ssid);
|
||||
@@ -533,18 +511,15 @@ static esp_err_t wifi_manager_connect_sta(const wifi_sta_credentials_t *creds, b
|
||||
ESP_LOGW(TAG, "failed to set WIFI_PS_NONE, rc=0x%x", (unsigned)ps_rc);
|
||||
}
|
||||
s_ready = true;
|
||||
wifi_manager_record_connect_result(ESP_OK, "connect success");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
if (bits & WIFI_FAIL_BIT) {
|
||||
ESP_LOGW(TAG, "failed to connect to SSID:%s", creds->ssid);
|
||||
wifi_manager_record_connect_result(ESP_FAIL, "connect failed after retries");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
ESP_LOGW(TAG, "Wi-Fi connect timeout, SSID:%s", creds->ssid);
|
||||
wifi_manager_record_connect_result(ESP_ERR_TIMEOUT, "connect timeout");
|
||||
return ESP_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
@@ -555,6 +530,12 @@ static esp_err_t wifi_manager_prov_index_get_handler(httpd_req_t *req) {
|
||||
return httpd_resp_send(req, (const char *)s_provision_page_start, page_len);
|
||||
}
|
||||
|
||||
static esp_err_t wifi_manager_prov_favicon_get_handler(httpd_req_t *req) {
|
||||
httpd_resp_set_status(req, "204 No Content");
|
||||
httpd_resp_set_hdr(req, "Cache-Control", "max-age=86400");
|
||||
return httpd_resp_send(req, NULL, 0);
|
||||
}
|
||||
|
||||
static esp_err_t wifi_manager_prov_submit_post_handler(httpd_req_t *req) {
|
||||
if (req->content_len <= 0 || req->content_len >= WIFI_PROV_HTTP_BODY_MAX_LEN) {
|
||||
return wifi_manager_send_prov_json(req, false, "invalid_payload");
|
||||
@@ -597,7 +578,6 @@ static esp_err_t wifi_manager_prov_submit_post_handler(httpd_req_t *req) {
|
||||
|
||||
err = wifi_manager_save_credentials(&creds);
|
||||
if (err != ESP_OK) {
|
||||
runtime_diag_record_error("wifi_provision", err, "save credentials failed");
|
||||
s_ready = false;
|
||||
(void)esp_wifi_disconnect();
|
||||
return wifi_manager_send_prov_json(req, false, "save_failed");
|
||||
@@ -638,6 +618,19 @@ static esp_err_t wifi_manager_start_prov_http_server(void) {
|
||||
return err;
|
||||
}
|
||||
|
||||
const httpd_uri_t favicon_uri = {
|
||||
.uri = "/favicon.ico",
|
||||
.method = HTTP_GET,
|
||||
.handler = wifi_manager_prov_favicon_get_handler,
|
||||
.user_ctx = NULL,
|
||||
};
|
||||
err = httpd_register_uri_handler(s_prov_httpd, &favicon_uri);
|
||||
if (err != ESP_OK) {
|
||||
httpd_stop(s_prov_httpd);
|
||||
s_prov_httpd = NULL;
|
||||
return err;
|
||||
}
|
||||
|
||||
const httpd_uri_t scan_uri = {
|
||||
.uri = "/scan",
|
||||
.method = HTTP_GET,
|
||||
@@ -790,20 +783,17 @@ esp_err_t wifi_manager_start(void) {
|
||||
|
||||
esp_err_t err = esp_netif_init();
|
||||
if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) {
|
||||
runtime_diag_record_error("wifi_start", err, "esp_netif_init failed");
|
||||
return err;
|
||||
}
|
||||
|
||||
err = esp_event_loop_create_default();
|
||||
if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) {
|
||||
runtime_diag_record_error("wifi_start", err, "event loop init failed");
|
||||
return err;
|
||||
}
|
||||
|
||||
if (s_sta_netif == NULL) {
|
||||
s_sta_netif = esp_netif_create_default_wifi_sta();
|
||||
if (s_sta_netif == NULL) {
|
||||
runtime_diag_record_error("wifi_start", ESP_ERR_NO_MEM, "create sta netif failed");
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
}
|
||||
@@ -811,7 +801,6 @@ esp_err_t wifi_manager_start(void) {
|
||||
if (s_ap_netif == NULL) {
|
||||
s_ap_netif = esp_netif_create_default_wifi_ap();
|
||||
if (s_ap_netif == NULL) {
|
||||
runtime_diag_record_error("wifi_start", ESP_ERR_NO_MEM, "create ap netif failed");
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
}
|
||||
@@ -819,13 +808,11 @@ esp_err_t wifi_manager_start(void) {
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
err = esp_wifi_init(&cfg);
|
||||
if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) {
|
||||
runtime_diag_record_error("wifi_start", err, "esp_wifi_init failed");
|
||||
return err;
|
||||
}
|
||||
|
||||
err = esp_wifi_set_storage(WIFI_STORAGE_RAM);
|
||||
if (err != ESP_OK) {
|
||||
runtime_diag_record_error("wifi_start", err, "esp_wifi_set_storage RAM failed");
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -836,7 +823,6 @@ esp_err_t wifi_manager_start(void) {
|
||||
NULL,
|
||||
&s_wifi_event_inst);
|
||||
if (err != ESP_OK) {
|
||||
runtime_diag_record_error("wifi_start", err, "register WIFI event failed");
|
||||
return err;
|
||||
}
|
||||
}
|
||||
@@ -848,7 +834,6 @@ esp_err_t wifi_manager_start(void) {
|
||||
NULL,
|
||||
&s_ip_event_inst);
|
||||
if (err != ESP_OK) {
|
||||
runtime_diag_record_error("wifi_start", err, "register IP event failed");
|
||||
return err;
|
||||
}
|
||||
}
|
||||
@@ -870,7 +855,6 @@ esp_err_t wifi_manager_start(void) {
|
||||
|
||||
err = wifi_manager_run_softap_provisioning();
|
||||
if (err != ESP_OK) {
|
||||
runtime_diag_record_error("wifi_start", err, "SoftAP provisioning failed");
|
||||
(void)wifi_manager_stop();
|
||||
}
|
||||
|
||||
@@ -949,7 +933,6 @@ esp_err_t wifi_manager_stop(void) {
|
||||
s_started = false;
|
||||
|
||||
if (first_err != ESP_OK) {
|
||||
runtime_diag_record_error("wifi_stop", first_err, "wifi stop failed");
|
||||
}
|
||||
|
||||
return first_err;
|
||||
|
||||
Reference in New Issue
Block a user