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:
@@ -49,11 +49,23 @@ typedef struct {
|
||||
adc_channel_t channel;
|
||||
} adc_pin_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t shift_clock_high_us;
|
||||
uint16_t shift_clock_low_us;
|
||||
uint16_t latch_pulse_us;
|
||||
bool strobe_active_high;
|
||||
bool boost_active_high;
|
||||
uint16_t override_strobe_on_us;
|
||||
uint16_t override_strobe_interval_us;
|
||||
uint16_t override_motor_step_us;
|
||||
uint8_t override_steps_per_line;
|
||||
} direct_debug_config_t;
|
||||
|
||||
typedef struct {
|
||||
bool initialized;
|
||||
bool connected;
|
||||
uint8_t motor_phase;
|
||||
platform_direct_debug_config_t debug;
|
||||
direct_debug_config_t debug;
|
||||
SemaphoreHandle_t lock;
|
||||
adc_oneshot_unit_handle_t adc1_handle;
|
||||
adc_oneshot_unit_handle_t adc2_handle;
|
||||
@@ -567,8 +579,8 @@ void platform_direct_printer_deinit(void) {
|
||||
}
|
||||
|
||||
esp_err_t platform_direct_printer_connect(uint32_t timeout_ms) {
|
||||
(void)timeout_ms;
|
||||
#if !CONFIG_TQ_DIRECT_PRINTER_ENABLE
|
||||
(void)timeout_ms;
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#else
|
||||
esp_err_t err = platform_direct_printer_init();
|
||||
@@ -576,7 +588,12 @@ esp_err_t platform_direct_printer_connect(uint32_t timeout_ms) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (xSemaphoreTake(s_state.lock, pdMS_TO_TICKS(500)) != pdTRUE) {
|
||||
uint32_t lock_timeout_ms = timeout_ms == 0 ? 500 : timeout_ms;
|
||||
if (lock_timeout_ms > 5000) {
|
||||
lock_timeout_ms = 5000;
|
||||
}
|
||||
|
||||
if (xSemaphoreTake(s_state.lock, pdMS_TO_TICKS(lock_timeout_ms)) != pdTRUE) {
|
||||
return ESP_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
@@ -631,12 +648,31 @@ esp_err_t platform_direct_printer_get_sensors(platform_printer_sensors_t *out_se
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t platform_direct_printer_get_debug_config(platform_direct_debug_config_t *out_config) {
|
||||
esp_err_t platform_direct_printer_get_debug_config(uint16_t *out_shift_clock_high_us,
|
||||
uint16_t *out_shift_clock_low_us,
|
||||
uint16_t *out_latch_pulse_us,
|
||||
bool *out_strobe_active_high,
|
||||
bool *out_boost_active_high,
|
||||
uint16_t *out_override_strobe_on_us,
|
||||
uint16_t *out_override_strobe_interval_us,
|
||||
uint16_t *out_override_motor_step_us,
|
||||
uint8_t *out_override_steps_per_line) {
|
||||
#if !CONFIG_TQ_DIRECT_PRINTER_ENABLE
|
||||
(void)out_config;
|
||||
(void)out_shift_clock_high_us;
|
||||
(void)out_shift_clock_low_us;
|
||||
(void)out_latch_pulse_us;
|
||||
(void)out_strobe_active_high;
|
||||
(void)out_boost_active_high;
|
||||
(void)out_override_strobe_on_us;
|
||||
(void)out_override_strobe_interval_us;
|
||||
(void)out_override_motor_step_us;
|
||||
(void)out_override_steps_per_line;
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#else
|
||||
if (out_config == NULL) {
|
||||
if (out_shift_clock_high_us == NULL || out_shift_clock_low_us == NULL || out_latch_pulse_us == NULL ||
|
||||
out_strobe_active_high == NULL || out_boost_active_high == NULL || out_override_strobe_on_us == NULL ||
|
||||
out_override_strobe_interval_us == NULL || out_override_motor_step_us == NULL ||
|
||||
out_override_steps_per_line == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
esp_err_t init_rc = platform_direct_printer_init();
|
||||
@@ -646,23 +682,49 @@ esp_err_t platform_direct_printer_get_debug_config(platform_direct_debug_config_
|
||||
if (xSemaphoreTake(s_state.lock, pdMS_TO_TICKS(500)) != pdTRUE) {
|
||||
return ESP_ERR_TIMEOUT;
|
||||
}
|
||||
*out_config = s_state.debug;
|
||||
*out_shift_clock_high_us = s_state.debug.shift_clock_high_us;
|
||||
*out_shift_clock_low_us = s_state.debug.shift_clock_low_us;
|
||||
*out_latch_pulse_us = s_state.debug.latch_pulse_us;
|
||||
*out_strobe_active_high = s_state.debug.strobe_active_high;
|
||||
*out_boost_active_high = s_state.debug.boost_active_high;
|
||||
*out_override_strobe_on_us = s_state.debug.override_strobe_on_us;
|
||||
*out_override_strobe_interval_us = s_state.debug.override_strobe_interval_us;
|
||||
*out_override_motor_step_us = s_state.debug.override_motor_step_us;
|
||||
*out_override_steps_per_line = s_state.debug.override_steps_per_line;
|
||||
xSemaphoreGive(s_state.lock);
|
||||
return ESP_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
esp_err_t platform_direct_printer_set_debug_config(const platform_direct_debug_config_t *config,
|
||||
esp_err_t platform_direct_printer_set_debug_config(bool has_config,
|
||||
uint16_t shift_clock_high_us,
|
||||
uint16_t shift_clock_low_us,
|
||||
uint16_t latch_pulse_us,
|
||||
bool strobe_active_high,
|
||||
bool boost_active_high,
|
||||
uint16_t override_strobe_on_us,
|
||||
uint16_t override_strobe_interval_us,
|
||||
uint16_t override_motor_step_us,
|
||||
uint8_t override_steps_per_line,
|
||||
bool reset_defaults,
|
||||
char *err,
|
||||
size_t err_len) {
|
||||
#if !CONFIG_TQ_DIRECT_PRINTER_ENABLE
|
||||
(void)config;
|
||||
(void)has_config;
|
||||
(void)shift_clock_high_us;
|
||||
(void)shift_clock_low_us;
|
||||
(void)latch_pulse_us;
|
||||
(void)strobe_active_high;
|
||||
(void)boost_active_high;
|
||||
(void)override_strobe_on_us;
|
||||
(void)override_strobe_interval_us;
|
||||
(void)override_motor_step_us;
|
||||
(void)override_steps_per_line;
|
||||
(void)reset_defaults;
|
||||
write_err(err, err_len, "direct backend disabled");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#else
|
||||
if (config == NULL && !reset_defaults) {
|
||||
if (!has_config && !reset_defaults) {
|
||||
write_err(err, err_len, "invalid args");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
@@ -681,45 +743,48 @@ esp_err_t platform_direct_printer_set_debug_config(const platform_direct_debug_c
|
||||
set_debug_defaults_locked();
|
||||
}
|
||||
|
||||
if (config != NULL) {
|
||||
if (config->shift_clock_high_us < DEBUG_SHIFT_CLOCK_US_MIN ||
|
||||
config->shift_clock_high_us > DEBUG_SHIFT_CLOCK_US_MAX ||
|
||||
config->shift_clock_low_us < DEBUG_SHIFT_CLOCK_US_MIN ||
|
||||
config->shift_clock_low_us > DEBUG_SHIFT_CLOCK_US_MAX) {
|
||||
if (has_config) {
|
||||
if (shift_clock_high_us < DEBUG_SHIFT_CLOCK_US_MIN || shift_clock_high_us > DEBUG_SHIFT_CLOCK_US_MAX ||
|
||||
shift_clock_low_us < DEBUG_SHIFT_CLOCK_US_MIN || shift_clock_low_us > DEBUG_SHIFT_CLOCK_US_MAX) {
|
||||
xSemaphoreGive(s_state.lock);
|
||||
write_err(err, err_len, "shift clock us out of range (1..50)");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (config->latch_pulse_us < DEBUG_LATCH_PULSE_US_MIN ||
|
||||
config->latch_pulse_us > DEBUG_LATCH_PULSE_US_MAX) {
|
||||
if (latch_pulse_us < DEBUG_LATCH_PULSE_US_MIN || latch_pulse_us > DEBUG_LATCH_PULSE_US_MAX) {
|
||||
xSemaphoreGive(s_state.lock);
|
||||
write_err(err, err_len, "latch pulse us out of range (1..50)");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (config->override_strobe_on_us != 0 &&
|
||||
(config->override_strobe_on_us < 100 || config->override_strobe_on_us > 10000)) {
|
||||
if (override_strobe_on_us != 0 && (override_strobe_on_us < 100 || override_strobe_on_us > 10000)) {
|
||||
xSemaphoreGive(s_state.lock);
|
||||
write_err(err, err_len, "strobe_on_us must be 0 or 100..10000");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (config->override_strobe_interval_us > 10000) {
|
||||
if (override_strobe_interval_us > 10000) {
|
||||
xSemaphoreGive(s_state.lock);
|
||||
write_err(err, err_len, "strobe_interval_us must be 0..10000");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (config->override_motor_step_us != 0 &&
|
||||
(config->override_motor_step_us < 100 || config->override_motor_step_us > 20000)) {
|
||||
if (override_motor_step_us != 0 && (override_motor_step_us < 100 || override_motor_step_us > 20000)) {
|
||||
xSemaphoreGive(s_state.lock);
|
||||
write_err(err, err_len, "motor_step_us must be 0 or 100..20000");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (config->override_steps_per_line > 8) {
|
||||
if (override_steps_per_line > 8) {
|
||||
xSemaphoreGive(s_state.lock);
|
||||
write_err(err, err_len, "steps_per_line must be 0..8");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
s_state.debug = *config;
|
||||
s_state.debug.shift_clock_high_us = shift_clock_high_us;
|
||||
s_state.debug.shift_clock_low_us = shift_clock_low_us;
|
||||
s_state.debug.latch_pulse_us = latch_pulse_us;
|
||||
s_state.debug.strobe_active_high = strobe_active_high;
|
||||
s_state.debug.boost_active_high = boost_active_high;
|
||||
s_state.debug.override_strobe_on_us = override_strobe_on_us;
|
||||
s_state.debug.override_strobe_interval_us = override_strobe_interval_us;
|
||||
s_state.debug.override_motor_step_us = override_motor_step_us;
|
||||
s_state.debug.override_steps_per_line = override_steps_per_line;
|
||||
}
|
||||
|
||||
safe_drive_off_locked(s_state.connected);
|
||||
|
||||
Reference in New Issue
Block a user