/* * can_bus.h — MCP2515 CAN bus wrapper for KL630 (J15 SPI connector) * * API mirrors bt_uart.h: both channels carry the same JSON payload. * BLE channel: bt_uart_send_json(json) * CAN channel: can_bus_send_json(json) * * The same JSON string {"class":"car","level":1} is transmitted on both * channels simultaneously from fire_json_async() in event_recorder.c. * * MCP2515 is classic CAN (max 8 bytes per frame). Long JSON strings are * split into sequential 8-byte frames automatically: * Frame N: bytes [N*8 .. N*8+7] of the JSON string (padded with 0x00) * The receiver reassembles by concatenating frames until a null byte. * If a CAN FD controller is fitted later, switch to single-frame send. */ #ifndef CAN_BUS_H #define CAN_BUS_H #include /* * can_bus_init — open MCP2515 via SPI and start writer thread. * spidev : e.g. "/dev/spidev1.0" * can_speed_kbps: 250 (typical) or 125, 500, 1000 * can_id : 11-bit standard frame ID for outbound frames * Returns 0 on success, -1 on error. */ int can_bus_init(const char *spidev, int can_speed_kbps, uint32_t can_id); /* * can_bus_send_json — non-blocking: enqueue a JSON string for CAN transmission. * Same signature as bt_uart_send_json(); call both from fire_json_async(). * Long strings are split into multiple 8-byte CAN frames automatically. */ void can_bus_send_json(const char *json); /* * can_bus_send_control_cmd — send one classic-CAN control frame. * Frame format (compatible with bt_proc.c reference): * CAN ID : 0x75 (11-bit) * DLC : 8 * DATA : [cmd, 0, 0, 0, 0, 0, 0, 0] */ void can_bus_send_control_cmd(uint8_t cmd); /* can_bus_close — drain queue, join writer thread, close SPI device. */ void can_bus_close(void); #endif /* CAN_BUS_H */