EduArt Sensor Ring Library 4.0.0
Loading...
Searching...
No Matches
FirmwareUpdater.hpp
Go to the documentation of this file.
1// Copyright (c) 2026 EduArt Robotik GmbH
2
9
10#pragma once
11
12#include <chrono>
13#include <cstddef>
14#include <cstdint>
15#include <functional>
16#include <optional>
17#include <string>
18
20#include "sensorring/platform/SensorringExport.hpp"
21
22namespace eduart {
23namespace sensorring {
24namespace firmware_update {
25
30struct SENSORRING_EXPORT UpdateConfig {
31 std::chrono::milliseconds can_timeout{ 500 };
32 std::chrono::milliseconds bootloader_start_ack_timeout{ 1000 };
33 std::chrono::milliseconds settle_delay_after_flash{ 2000 };
34 std::chrono::milliseconds bootloader_detect_retry_delay{ 500 };
35 unsigned int bootloader_detect_retries{ 5 };
37};
38
40using LogCallback = std::function<void(const std::string&)>;
41
51class SENSORRING_EXPORT FirmwareUpdater {
52public:
57 explicit FirmwareUpdater(UpdateConfig config = {});
58
67 bool flashSingleBoard(const com::ComInterfaceID& interface, std::uint8_t node_id, const std::string& hex_file_path, LogCallback log_callback = {}) const;
68
76 bool enterSingleBoardBootloader(const com::ComInterfaceID& interface, std::size_t board_index, LogCallback log_callback = {}) const;
77
85 bool flashAllBoardsSequential(const com::ComInterfaceID& interface, const std::string& hex_file_path, LogCallback log_callback = {}) const;
86
92 std::optional<std::uint8_t> detectBootloaderNode(const com::ComInterfaceID& interface) const;
93
99 std::optional<std::uint8_t> detectBootloaderNodeWithRetries(const com::ComInterfaceID& interface);
100
101private:
102 UpdateConfig _config;
103
104 bool flashSingleBoardImpl(const com::ComInterfaceID& interface, std::uint8_t node_id, const std::string& hex_file_path, const std::string& display_node_label, LogCallback log_callback) const;
105};
106
107} // namespace firmware_update
108} // namespace sensorring
109} // namespace eduart
Interface type definition.
std::function< void(const std::string &)> LogCallback
Callback invoked by the updater to emit human-readable log messages.
Definition FirmwareUpdater.hpp:40
bool flashAllBoardsSequential(const com::ComInterfaceID &interface, const std::string &hex_file_path, LogCallback log_callback={}) const
Flashes every board on the ring sequentially with the same firmware image.
FirmwareUpdater(UpdateConfig config={})
Constructs a FirmwareUpdater with the given timing/retry configuration.
bool flashSingleBoard(const com::ComInterfaceID &interface, std::uint8_t node_id, const std::string &hex_file_path, LogCallback log_callback={}) const
Flashes a single board identified by its CAN node ID.
std::optional< std::uint8_t > detectBootloaderNode(const com::ComInterfaceID &interface) const
Detects whether any board on the ring is currently in bootloader mode.
bool enterSingleBoardBootloader(const com::ComInterfaceID &interface, std::size_t board_index, LogCallback log_callback={}) const
Requests a single board to enter bootloader mode.
std::optional< std::uint8_t > detectBootloaderNodeWithRetries(const com::ComInterfaceID &interface)
Detects whether any board on the ring is currently in bootloader mode, with retries....
Uniquely identifies a communication interface by type and name.
Definition ComInterfaceID.hpp:51
Timing and retry parameters that control the firmware-update procedure.
Definition FirmwareUpdater.hpp:30
unsigned int no_progress_cycles_before_done
Number of consecutive cycles without progress that signal a completed flash operation.
Definition FirmwareUpdater.hpp:36
std::chrono::milliseconds bootloader_detect_retry_delay
Pause between consecutive bootloader-detection attempts.
Definition FirmwareUpdater.hpp:34
unsigned int bootloader_detect_retries
Number of bootloader-detection attempts before giving up.
Definition FirmwareUpdater.hpp:35
std::chrono::milliseconds bootloader_start_ack_timeout
Maximum time to wait for the bootloader-start acknowledgement after a reset.
Definition FirmwareUpdater.hpp:32
std::chrono::milliseconds can_timeout
Maximum time to wait for a CAN response before declaring a timeout.
Definition FirmwareUpdater.hpp:31
std::chrono::milliseconds settle_delay_after_flash
Delay inserted after the last flash packet to let the board settle before verification.
Definition FirmwareUpdater.hpp:33