fix(firmware+frontend): remove binary_parser_reset() re-deploy wipes CRC + tighten INIT poll

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
This commit is contained in:
a2nr 2026-06-30 19:21:35 +07:00
parent 6ccbb88678
commit 1d3a48940e
3 changed files with 12 additions and 5 deletions

View File

@ -367,8 +367,11 @@ export class BLEHardwareDeployer {
/* INIT: any non-IDLE(0), non-ERROR(5/6) state means command was processed. /* INIT: any non-IDLE(0), non-ERROR(5/6) state means command was processed.
* DATA: state must stay RECEIVING(1) error if >=5. */ * DATA: state must stay RECEIVING(1) error if >=5. */
if (cmd === CMD_INIT) { if (cmd === CMD_INIT) {
if (state >= 1 && state <= 4) { /* Only RECEIVING(1) means INIT was processed.
console.log(`[BLE-CMD] ${cmdName}: state=${state} — INIT confirmed via read poll`); * 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; return 'ok' as const;
} }
} else { /* DATA */ } else { /* DATA */

View File

@ -1,5 +1,5 @@
// static/sw.js // static/sw.js
const CACHE_VERSION = 'elemes-v9'; const CACHE_VERSION = 'elemes-v10';
const STATIC_CACHE = `${CACHE_VERSION}-static`; const STATIC_CACHE = `${CACHE_VERSION}-static`;
const API_CACHE = `${CACHE_VERSION}-api`; const API_CACHE = `${CACHE_VERSION}-api`;
const ASSET_CACHE = `${CACHE_VERSION}-assets`; const ASSET_CACHE = `${CACHE_VERSION}-assets`;

View File

@ -168,7 +168,11 @@ void state_machine_process_event(sm_event_t event, void *data)
case STATE_SERIAL_BRIDGE: case STATE_SERIAL_BRIDGE:
if (event == EVENT_BLE_INIT) { if (event == EVENT_BLE_INIT) {
serial_bridge_stop(); 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; current_state = STATE_RECEIVING;
led_set_pattern(LED_BLUE_BLINK); led_set_pattern(LED_BLUE_BLINK);
ESP_LOGI(TAG, "Transition: SERIAL_BRIDGE -> RECEIVING (re-deploy)"); 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) { if (event == EVENT_BLE_INIT) {
ESP_LOGI(TAG, "Re-deploy from ERROR state — transition to RECEIVING"); ESP_LOGI(TAG, "Re-deploy from ERROR state — transition to RECEIVING");
serial_bridge_stop(); serial_bridge_stop();
binary_parser_reset(); /* Parser resets itself on INIT — see note in SERIAL_BRIDGE handler. */
current_state = STATE_RECEIVING; current_state = STATE_RECEIVING;
led_set_pattern(LED_BLUE_BLINK); led_set_pattern(LED_BLUE_BLINK);
} else if (event == EVENT_BUTTON_RETRY) { } else if (event == EVENT_BUTTON_RETRY) {