From 1d3a48940ec5884dff435c8206fe90779bb27d84 Mon Sep 17 00:00:00 2001 From: a2nr Date: Tue, 30 Jun 2026 19:21:35 +0700 Subject: [PATCH] fix(firmware+frontend): remove binary_parser_reset() re-deploy wipes CRC + tighten INIT poll MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Firmware (state_machine.c): - Remove binary_parser_reset() from SERIAL_BRIDGE→RECEIVING handler - Remove binary_parser_reset() from ERROR→RECEIVING handler - Parser's INIT handler already resets itself; calling reset AFTER INIT payload processing wipes expected_total_crc to 0 → CRC fail Frontend (ble-deployer.ts): - Tighten INIT readValue poll: state===1 (RECEIVING) only Previously accepted state >= 1 && <= 4 which could false-positive on FLASHING(3) or SERIAL_BRIDGE(4) stale states Cache v9 → v10 --- frontend/src/lib/services/ble-deployer.ts | 7 +++++-- frontend/static/sw.js | 2 +- velxio-deployer-firmware/main/state_machine.c | 8 ++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/frontend/src/lib/services/ble-deployer.ts b/frontend/src/lib/services/ble-deployer.ts index 66feb20..04c1b76 100644 --- a/frontend/src/lib/services/ble-deployer.ts +++ b/frontend/src/lib/services/ble-deployer.ts @@ -367,8 +367,11 @@ export class BLEHardwareDeployer { /* INIT: any non-IDLE(0), non-ERROR(5/6) state means command was processed. * DATA: state must stay RECEIVING(1) — error if >=5. */ if (cmd === CMD_INIT) { - if (state >= 1 && state <= 4) { - console.log(`[BLE-CMD] ${cmdName}: state=${state} — INIT confirmed via read poll`); + /* Only RECEIVING(1) means INIT was processed. + * Don't accept FLASHING(3) or SERIAL_BRIDGE(4) — + * those are stale states from a previous deploy. */ + if (state === 1) { + console.log(`[BLE-CMD] ${cmdName}: state=1 (RECEIVING) — INIT confirmed via read poll`); return 'ok' as const; } } else { /* DATA */ diff --git a/frontend/static/sw.js b/frontend/static/sw.js index 09ca5e6..eade4f8 100644 --- a/frontend/static/sw.js +++ b/frontend/static/sw.js @@ -1,5 +1,5 @@ // static/sw.js -const CACHE_VERSION = 'elemes-v9'; +const CACHE_VERSION = 'elemes-v10'; const STATIC_CACHE = `${CACHE_VERSION}-static`; const API_CACHE = `${CACHE_VERSION}-api`; const ASSET_CACHE = `${CACHE_VERSION}-assets`; diff --git a/velxio-deployer-firmware/main/state_machine.c b/velxio-deployer-firmware/main/state_machine.c index 2775a01..af74d06 100644 --- a/velxio-deployer-firmware/main/state_machine.c +++ b/velxio-deployer-firmware/main/state_machine.c @@ -168,7 +168,11 @@ void state_machine_process_event(sm_event_t event, void *data) case STATE_SERIAL_BRIDGE: if (event == EVENT_BLE_INIT) { serial_bridge_stop(); - binary_parser_reset(); + /* Don't call binary_parser_reset() here — the parser's INIT + * handler (binary_parser.c:51-68) already resets buffer_offset, + * buffer_size, memset, and state. Calling reset here wipes + * expected_total_crc to 0 AFTER the parser already set it + * from the INIT payload, causing END CRC verification to fail. */ current_state = STATE_RECEIVING; led_set_pattern(LED_BLUE_BLINK); ESP_LOGI(TAG, "Transition: SERIAL_BRIDGE -> RECEIVING (re-deploy)"); @@ -185,7 +189,7 @@ void state_machine_process_event(sm_event_t event, void *data) if (event == EVENT_BLE_INIT) { ESP_LOGI(TAG, "Re-deploy from ERROR state — transition to RECEIVING"); serial_bridge_stop(); - binary_parser_reset(); + /* Parser resets itself on INIT — see note in SERIAL_BRIDGE handler. */ current_state = STATE_RECEIVING; led_set_pattern(LED_BLUE_BLINK); } else if (event == EVENT_BUTTON_RETRY) {