Monitor the XIAO's battery and make the XIAO the production board
The production OBU is now a Seeed XIAO ESP32-C5 (8 MB flash, one native USB-C port) on a LiPo with no protection board. The firmware reads the cell on GPIO6 (divider switched by GPIO26) every 5 s, sends it in STATUS (battery_mv and battery_flags, octets 103-105; decoders accept 103 or >= 106 octets), warns below 3.50 V and deep-sleeps below 3.30 V when no phone is on USB, waking every 5 min to check the cell again. Thresholds are in Kconfig; host test `make battery`. The app shows voltage, a rough percentage and the low/critical state on the ESP32-C5 card and in the top bar. With several bonded micrOBUs (a replaced board stays bonded), the BLE link tries the one that last connected first and moves on to the next after each failure. tools/station_status_watch.py reads STATUS from the native port.
This commit is contained in:
@@ -292,9 +292,22 @@ struct Status {
|
||||
std::uint32_t radio_submitted = 0, radio_failed = 0, radio_received = 0, radio_dropped = 0;
|
||||
std::uint32_t link_rx_frames = 0, link_crc_errors = 0, link_malformed = 0, poti_updates = 0;
|
||||
std::uint64_t its_time_ms = 0;
|
||||
// MicrOBU extension, appended after the colleague's 103 octets: [103] battery_mv u16 (0: not
|
||||
// measured, no cell or no sensor), [105] battery_flags u8. A 103-octet body (the colleague's
|
||||
// layout, and this firmware before the battery) still decodes, with these two left at 0.
|
||||
std::uint16_t battery_mv = 0;
|
||||
std::uint8_t battery_flags = 0;
|
||||
};
|
||||
/// battery_flags bits of Status.
|
||||
constexpr std::uint8_t battery_flag_low = 0x01; ///< cell below the warning threshold
|
||||
constexpr std::uint8_t battery_flag_critical = 0x02; ///< cell below the shutdown threshold: the board powers down unless a phone is on USB
|
||||
/// Octets of the STATUS body without / with the MicrOBU battery extension.
|
||||
constexpr std::size_t status_size_base = 103;
|
||||
constexpr std::size_t status_size_battery = 106;
|
||||
/// @param body Raw message body bytes.
|
||||
/// @param out Receives the decoded status.
|
||||
/// @param out Receives the decoded status. Accepts the 103-octet base body and any body of at
|
||||
/// least 106 octets (trailing octets after the known fields are ignored, so a later
|
||||
/// extension does not break this decoder); 104 or 105 octets are malformed.
|
||||
/// @return false if malformed.
|
||||
bool decode(const Bytes& body, Status& out);
|
||||
/// @param value Status to encode.
|
||||
|
||||
Reference in New Issue
Block a user