5.3.1.3.4.1. cli.cmd_bootloader.bootloader_can.BootloaderInterfaceCan

class cli.cmd_bootloader.bootloader_can.BootloaderInterfaceCan(can_bus: BusABC, app_dbc: Path = WindowsPath('D:/_github/foxbms-2/tools/dbc/foxbms.dbc'), bootloader_dbc: Path = WindowsPath('D:/_github/foxbms-2/tools/dbc/foxbms-bootloader.dbc'))

Bases: BootloaderInterface

Implement CAN-specific bootloader interface for higher-level operations.

This class provides all CAN-related functions required to interact with the bootloader. It wraps low-level CAN messaging to send commands, wait for and receive specific messages on the CAN bus, and control the transfer and validation of application data.

get_bootloader_state() → tuple[str | None, str | None]

Ask bootloader for its current state.

Returns:

CanFsmState, BootFsmState.

get_bootloader_version_num() → tuple[int | None, int | None, int | None]

Get the bootloader’s version number.

Returns:

Current version number (MajorVersionNumber, MinorVersionNumber, PatchVersionNumber) of the bootloader.

get_current_num_of_loops() → int | None

Ask the bootloader to get its current number of data transfer loops.

Returns:

The current number of data transfer loops on bootloader.

get_foxbms_state() → str | None

Get the current state of foxBMS application if it is running.

Returns:

None if no application is running, otherwise the current bms state.

reset_bootloader(time_to_wait: float = 15.0, num_of_repeat: int = 5) → bool

Reset bootloader.

Parameters:
  • time_to_wait – time to wait for bootloader to reset itself.

  • num_of_repeat – number of retries while polling for bootloader state.

Returns:

True if the bootloader has been successfully reset, False otherwise.

run_app_on_bootloader() → bool

Run the BMS application on the BMS-Master (i.e., jump from the bootloader into the application via BMS state request.)

Returns:

True if the application has been started successfully, False otherwise.

send_crc(crc_8_bytes: int, is_crc_of_vector_table: bool = False) → tuple[bool, bool]

Send CRC signature to the bootloader and evaluate its acknowledgement.

This method transmits an 8-byte CRC value to the bootloader and waits for the corresponding acknowledgement message. It can handle CRCs for both regular data sectors and the vector table, depending on the is_crc_of_vector_table flag.

Parameters:
  • crc_8_bytes – CRC value as a 64-bit integer.

  • is_crc_of_vector_table – True if the CRC belongs to the vector table, False if it belongs to a regular data sector.

Returns:

(is_ack_received, is_crc_valid). is_ack_received is True if an ACK message was received. is_crc_valid is True if the ACK indicates a valid CRC (YesNoFlag == "Yes").

Return type:

tuple[bool, bool]

send_data_to_bootloader(data_8_bytes: int) → None

Send data in 8 bytes to bootloader.

Parameters:

data_8_bytes – data in 8 bytes.

send_loop_number_to_bootloader(num_of_loop: int) → None

Send the current loop number of the to-be-transferred data to bootloader.

Parameters:

num_of_loop – the current loop number (starting from 1).

send_program_info(len_of_program_in_bytes: int, num_of_transfer_loops: int) → bool

Send program info to bootloader and check its states.

Parameters:
  • len_of_program_in_bytes – the length of the program in bytes.

  • num_of_transfer_loops – the number of total transfer loops.

Returns:

True if bootloader has received info, False otherwise.

start_transfer() → bool

Inform bootloader to start the transfer program process.

Returns:

True if the bootloader has successfully started the process, False otherwise.

wait_can_ack_msg(acknowledge_msg: Enum, timeout_total: float = 1.0, timeout_ack: float = 0.3, processed_level: Enum = StatusCode.ReceivedAndProcessed) → AcknowledgeMessageType | None

Wait for a certain ACK message.

Parameters:
  • acknowledge_msg – the type of ACK message.

  • timeout_total – total time to wait.

  • timeout_ack – time to wait for a single message.

  • processed_level – the ACK message needs to have at least this processed_level.

Returns:

acknowledged message from bootloader