ESPHome 2026.11.0-dev
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..14] not decoded,
18// [15] error code (zero for no error), [16..23] not decoded.
19static constexpr uint16_t MESSAGE_TYPE_AQUA_SENSOR_DATA = 0xfc16;
20
21// The bus only buffers known message types, so the buffer is sized by the longest of them
22static constexpr size_t MAX_MESSAGE_SIZE = (MESSAGE_TYPE_AQUA_SENSOR_DATA & 0xff) + FRAME_OVERHEAD;
23
24inline uint16_t get_message_type(std::span<const uint8_t> message) { return encode_uint16(message[0], message[1]); }
25
27 public:
28 // Called with every frame that passed the checksum; listeners pick their message type
29 virtual void handle_message(std::span<const uint8_t> message) = 0;
30};
31
32class SystaBus : public uart::UARTDevice, public Component {
33 public:
34 void dump_config() override;
35 void loop() override;
36
37#ifdef SYSTA_BUS_LISTENER_COUNT
38 void register_listener(SystaBusListener *listener) { this->listeners_.push_back(listener); }
39#endif
40
41 protected:
42 void handle_byte_(uint8_t c);
43 void resync_();
44
45#ifdef SYSTA_BUS_LISTENER_COUNT
47#endif
49};
50
51} // namespace esphome::systa_bus
Minimal static vector - saves memory by avoiding std::vector overhead.
Definition helpers.h:286
void dump_config() override
Definition systa_bus.cpp:11
void register_listener(SystaBusListener *listener)
Definition systa_bus.h:38
void handle_byte_(uint8_t c)
Definition systa_bus.cpp:21
StaticVector< uint8_t, MAX_MESSAGE_SIZE > buffer_
Definition systa_bus.h:48
StaticVector< SystaBusListener *, SYSTA_BUS_LISTENER_COUNT > listeners_
Definition systa_bus.h:46
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:24
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:980