MCP2515 has two RX buffers; reading only one frame per interrupt left
RX1IF set, keeping INT LOW with no new falling edge — poll() would not
wake until the 100ms timeout, causing frames to pile up and RXOVR at
high cycle rates (20ms).
Changes:
- can_rx_thread: replace single readMessage call with a drain loop that
reads all available frames before returning to poll(), then clears
ERRIF/MERRF so INT can deassert cleanly
- can_rx_thread: startup drain + clear all CANINTF flags before the
initial GPIO edge-consume, so INT is HIGH on first poll() after a
crash restart (prevents "no interrupt after restart" symptom)
- mcp2515/spi_send: add NULL checks on tx_buffer and rx_buffer malloc
to prevent segfault when memory is tight under high SPI load
- mcp2515/spi_send: replace exit(0) on ioctl failure with return NULL
so callers can handle the error gracefully (committed in previous fix)
- mcp2515/read_register, read_status: add NULL guard on spi_send return
bt_uart.c:
- Reader thread: accept plain-text (non-JSON) lines from BLE app;
routes directly to extra_cmd_cb — test commands no longer need
JSON wrapping
- bt_uart_probe_and_upgrade(): fix AT+BAUD7 sequence — reopen fd at
115200 before sending AT+NAME/AT+RESET (was sending on stale 9600 fd)
- bt_uart_send_json(): replace blocking mutex_lock with 200 ms trylock
retry to avoid deadlock if writer thread dies holding the queue mutex
- Reader select timeout 500 ms → 200 ms for faster plain-text flush
buzzer.c:
- buzzer_set_pattern(): write s_pattern directly then trylock+signal,
so callers never block on the buzzer thread's mutex
can_bus.c:
- Add debug printf in can_bus_send_control_cmd() (temporary)
event_recorder.c:
- TEST_MODE_TIMEOUT_SEC 60 → 300 (5 min, enough for full test run)
kp_firmware.c:
- Persist INI keys via sed in-place instead of iniparser_dump_ini,
preserving comments and original file structure
- setvbuf stdout/stderr to line-buffered so tee log appears immediately
Add GF_AI_Box_Test_Guide (.md/.docx/.pdf) and uclibc_compat.c
test_can_event() no longer controls buzzer; new TEST_BUZZER_ALL
thread tests all buzzer patterns independently. TEST_ALL now
runs three sequential groups: BLE, CAN-only, Buzzer-only.
Add TEST_ENTER/TEST_EXIT commands via BLE to enter/exit test mode.
In test mode, inference results are suppressed; testers can directly
trigger BLE JSON (TEST_BLE *), CAN+Buzzer actions (TEST_CAN *),
or run sequenced full-coverage tests (TEST_BLE_ALL, TEST_CAN_ALL,
TEST_ALL). Auto-exits after 60s idle. Routes unrecognised BLE
commands through new bt_uart_set_extra_cmd_cb() hook.
New buzzer.h/buzzer.c: background pthread drives gpio64 with three
patterns (GRASS 500/500ms, ALERT 300/200ms, COLLISION 100/100ms).
Integrated into fire_collision_warning(), fire_alert(), and grass
state machine in event_recorder.c; buzzer_init() called after
can_bus_init() in kp_firmware.c.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- app_header_init: detect vehicle(class=2) in print_yolo_result(),
send CAN speed=10 on detection, speed=240 on clear;
only triggers on state change, keepalive maintains cmd
- app_header_init: on speed state change, send BLE JSON
{response_type:can_status, content:{vehicle_detected, speed_cmd}}
- app_header_init: add #include can_bus.h / bt_uart.h
- event_recorder: wrap legacy MsgBroker IPC path in #if 0;
setSpeed now goes directly through can_bus_send_control_cmd()