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:
@@ -441,16 +441,30 @@ static bool wait_ack(uint8_t cmd, uint32_t timeout_ms) {
|
||||
return payload_len >= 1 && payload[0] == 0x01;
|
||||
}
|
||||
|
||||
static void reset_transport_after_timeout(void) {
|
||||
if (printer_protocol_is_stopping()) {
|
||||
return;
|
||||
}
|
||||
if (printer_protocol_get_backend() == PRINTER_BACKEND_BLE) {
|
||||
ble_printer_client_disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
bool printer_protocol_send_cmd_with_ack(uint8_t cmd,
|
||||
const uint8_t *payload,
|
||||
uint16_t payload_len,
|
||||
bool with_checksum,
|
||||
uint32_t timeout_ms) {
|
||||
uint32_t timeout_ms,
|
||||
bool reset_transport_on_timeout) {
|
||||
clear_ack_signal();
|
||||
if (printer_protocol_send_frame(cmd, payload, payload_len, with_checksum) != ESP_OK) {
|
||||
return false;
|
||||
}
|
||||
return wait_ack(cmd, timeout_ms);
|
||||
bool ok = wait_ack(cmd, timeout_ms);
|
||||
if (!ok && reset_transport_on_timeout) {
|
||||
reset_transport_after_timeout();
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
esp_err_t printer_protocol_send_cmd_wait_response(uint8_t cmd,
|
||||
@@ -459,6 +473,7 @@ esp_err_t printer_protocol_send_cmd_wait_response(uint8_t cmd,
|
||||
bool with_checksum,
|
||||
uint32_t timeout_ms,
|
||||
bool expect_ack,
|
||||
bool reset_transport_on_timeout,
|
||||
uint8_t *out_payload,
|
||||
size_t out_payload_cap,
|
||||
uint16_t *out_payload_len,
|
||||
@@ -475,14 +490,21 @@ esp_err_t printer_protocol_send_cmd_wait_response(uint8_t cmd,
|
||||
uint8_t rsp[252];
|
||||
uint16_t rsp_len = 0;
|
||||
if (!printer_protocol_wait_response(cmd, rsp, sizeof(rsp), &rsp_len, timeout_ms)) {
|
||||
bool stopping = printer_protocol_is_stopping();
|
||||
if (!stopping && reset_transport_on_timeout) {
|
||||
reset_transport_after_timeout();
|
||||
}
|
||||
if (err != NULL && err_len > 0) {
|
||||
if (printer_protocol_is_stopping()) {
|
||||
if (stopping) {
|
||||
snprintf(err, err_len, "protocol stopping");
|
||||
} else {
|
||||
snprintf(err, err_len, "response timeout");
|
||||
snprintf(err,
|
||||
err_len,
|
||||
reset_transport_on_timeout ? "response timeout, transport reset"
|
||||
: "response timeout");
|
||||
}
|
||||
}
|
||||
return printer_protocol_is_stopping() ? ESP_ERR_INVALID_STATE : ESP_ERR_TIMEOUT;
|
||||
return stopping ? ESP_ERR_INVALID_STATE : ESP_ERR_TIMEOUT;
|
||||
}
|
||||
|
||||
if (expect_ack && (rsp_len < 1 || rsp[0] != 0x01)) {
|
||||
|
||||
Reference in New Issue
Block a user