ESPHome 2026.10.0
Loading...
Searching...
No Matches
systa_bus.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <span>
8
9namespace esphome::systa_bus {
10
11// A frame is a start byte, the payload length, the payload and an 8-bit checksum that makes all bytes sum to
12// zero. The first two bytes together are the message type, so the type also fixes the frame length.
13static constexpr uint8_t START_BYTE = 0xfc;
14static constexpr uint8_t FRAME_OVERHEAD = 3; // start byte, length, checksum
15
16// SystaSolar Aqua sensor data, 25 bytes: [0..1] type, [2..3] not decoded, big-endian int16 in 0.1 degrees at
17// [4..5] TSA, [6..7] TSE, [8..9] TWU and [10..11] TW2, pump speed in percent at [12], [13..23] not decoded.
18static constexpr uint16_t MESSAGE_TYPE_AQUA_SENSOR_DATA = 0xfc16;
19
20// The bus only buffers known message types, so the buffer is sized by the longest of them
21static constexpr size_t MAX_MESSAGE_SIZE = (MESSAGE_TYPE_AQUA_SENSOR_DATA & 0xff) + FRAME_OVERHEAD;
22
23inline uint16_t get_message_type(std::span<const uint8_t> message) { return encode_uint16(message[0], message[1]); }
24
26 public:
27 // Called with every frame that passed the checksum; listeners pick their message type
28 virtual void handle_message(std::span<const uint8_t> message) = 0;
29};
30
31class SystaBus : public uart::UARTDevice, public Component {
32 public:
33 void dump_config() override;
34 void loop() override;
35
36#ifdef SYSTA_BUS_LISTENER_COUNT
37 void register_listener(SystaBusListener *listener) { this->listeners_.push_back(listener); }
38#endif
39
40 protected:
41 void handle_byte_(uint8_t c);
42 void resync_();
43
44#ifdef SYSTA_BUS_LISTENER_COUNT
46#endif
48};
49
50} // namespace esphome::systa_bus
Minimal static vector - saves memory by avoiding std::vector overhead.
Definition helpers.h:291
void dump_config() override
Definition systa_bus.cpp:11
void register_listener(SystaBusListener *listener)
Definition systa_bus.h:37
void handle_byte_(uint8_t c)
Definition systa_bus.cpp:26
StaticVector< uint8_t, MAX_MESSAGE_SIZE > buffer_
Definition systa_bus.h:47
StaticVector< SystaBusListener *, SYSTA_BUS_LISTENER_COUNT > listeners_
Definition systa_bus.h:45
virtual void handle_message(std::span< const uint8_t > message)=0
const LogString * message
Definition component.cpp:35
uint16_t get_message_type(std::span< const uint8_t > message)
Definition systa_bus.h:23
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
Definition helpers.h:978