refactor(architecture): enforce component layering constraints

- move runtime policy/diag contracts to domain-owned facade and remove control_plane leapfrog usage

- enforce single declaration point for direct debug config in domain public API (constraint #6)

- harden timeout/idempotent semantics in REST/voice/printer/wifi/ble paths
This commit is contained in:
admin
2026-02-28 14:21:17 +08:00
parent 8a55ca0005
commit a549989332
23 changed files with 718 additions and 331 deletions

View File

@@ -5,7 +5,6 @@
#include <stdint.h>
#include "esp_err.h"
#include "platform.h"
#ifdef __cplusplus
extern "C" {
@@ -19,6 +18,81 @@ esp_err_t system_runtime_bootstrap(void);
bool system_runtime_wifi_ready(void);
void system_runtime_get_ip(char *buf, size_t buf_len);
// ---------- domain_policy ----------
uint32_t domain_policy_lifecycle_start_retry_count(void);
uint32_t domain_policy_lifecycle_retry_backoff_ms(uint32_t attempt);
bool domain_policy_is_retryable_error(esp_err_t err);
uint32_t domain_policy_printer_stop_timeout_ms(void);
uint32_t domain_policy_rest_printer_connect_timeout_ms(void);
uint32_t domain_policy_rest_printer_connect_timeout_min_ms(void);
uint32_t domain_policy_rest_printer_connect_timeout_max_ms(void);
uint32_t domain_policy_rest_label_timeout_ms(void);
uint32_t domain_policy_rest_label_timeout_min_ms(void);
uint32_t domain_policy_rest_label_timeout_max_ms(void);
uint32_t domain_policy_rest_ota_timeout_ms(void);
uint32_t domain_policy_rest_ota_timeout_min_ms(void);
uint32_t domain_policy_rest_ota_timeout_max_ms(void);
uint32_t domain_policy_image_generation_timeout_default_ms(void);
uint32_t domain_policy_image_generation_timeout_min_ms(void);
uint32_t domain_policy_image_generation_timeout_max_ms(void);
uint32_t domain_policy_image_download_timeout_default_ms(void);
uint32_t domain_policy_image_download_timeout_min_ms(void);
uint32_t domain_policy_image_download_timeout_max_ms(void);
// ---------- domain_diagnostics ----------
typedef enum {
DOMAIN_DIAG_COUNTER_LIFECYCLE_START_ATTEMPT = 0,
DOMAIN_DIAG_COUNTER_LIFECYCLE_START_SUCCESS,
DOMAIN_DIAG_COUNTER_LIFECYCLE_START_FAILED,
DOMAIN_DIAG_COUNTER_LIFECYCLE_START_RETRY,
DOMAIN_DIAG_COUNTER_LIFECYCLE_STOP_ATTEMPT,
DOMAIN_DIAG_COUNTER_LIFECYCLE_STOP_SUCCESS,
DOMAIN_DIAG_COUNTER_LIFECYCLE_STOP_FAILED,
DOMAIN_DIAG_COUNTER_WIFI_CONNECT_SUCCESS,
DOMAIN_DIAG_COUNTER_WIFI_CONNECT_FAILED,
DOMAIN_DIAG_COUNTER_WIFI_CONNECT_TIMEOUT,
DOMAIN_DIAG_COUNTER_PRINTER_JOB_SUBMITTED,
DOMAIN_DIAG_COUNTER_PRINTER_JOB_SUCCESS,
DOMAIN_DIAG_COUNTER_PRINTER_JOB_FAILED,
DOMAIN_DIAG_COUNTER_PRINTER_JOB_CANCELED,
DOMAIN_DIAG_COUNTER_IMAGE_GENERATE_ATTEMPT,
DOMAIN_DIAG_COUNTER_IMAGE_GENERATE_SUCCESS,
DOMAIN_DIAG_COUNTER_IMAGE_GENERATE_FAILED,
DOMAIN_DIAG_COUNTER_IMAGE_GENERATE_TIMEOUT,
DOMAIN_DIAG_COUNTER_REST_RESPONSES_TOTAL,
DOMAIN_DIAG_COUNTER_REST_ERRORS_TOTAL,
DOMAIN_DIAG_COUNTER_MAX,
} domain_diag_counter_t;
typedef enum {
DOMAIN_DIAG_GAUGE_LIFECYCLE_STATE = 0,
DOMAIN_DIAG_GAUGE_STATUS_POLL_PAUSE_DEPTH,
DOMAIN_DIAG_GAUGE_PRINTER_QUEUE_DEPTH,
DOMAIN_DIAG_GAUGE_MAX,
} domain_diag_gauge_t;
typedef struct {
uint64_t counters[DOMAIN_DIAG_COUNTER_MAX];
int32_t gauges[DOMAIN_DIAG_GAUGE_MAX];
int64_t last_error_ms;
esp_err_t last_error_code;
char last_error_source[32];
char last_error_message[96];
} domain_diag_snapshot_t;
void domain_diag_counter_add(domain_diag_counter_t counter, uint32_t delta);
void domain_diag_set_gauge(domain_diag_gauge_t gauge, int32_t value);
void domain_diag_record_error(const char *source, esp_err_t code, const char *message);
void domain_diag_get_snapshot(domain_diag_snapshot_t *out_snapshot);
const char *domain_diag_counter_name(domain_diag_counter_t counter);
const char *domain_diag_gauge_name(domain_diag_gauge_t gauge);
// ---------- raster_tools ----------
esp_err_t raster_tools_render_text_384(const char *text,
uint8_t scale,
@@ -286,7 +360,9 @@ typedef struct {
} voice_interaction_status_t;
esp_err_t voice_interaction_init(void);
esp_err_t voice_interaction_start_with_timeout(uint32_t timeout_ms, char *err, size_t err_len);
esp_err_t voice_interaction_start(char *err, size_t err_len);
esp_err_t voice_interaction_stop_with_timeout(uint32_t timeout_ms, char *err, size_t err_len);
esp_err_t voice_interaction_stop(char *err, size_t err_len);
esp_err_t voice_interaction_tap_start(char *err, size_t err_len);