ESPHome  2024.12.2
vbus.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 namespace esphome {
7 namespace vbus {
8 
9 using message_parser_t = std::function<float(std::vector<uint8_t> &)>;
10 
11 class VBus;
12 
13 class VBusListener {
14  public:
15  void set_command(uint16_t command) { this->command_ = command; }
16  void set_source(uint16_t source) { this->source_ = source; }
17  void set_dest(uint16_t dest) { this->dest_ = dest; }
18 
19  void on_message(uint16_t command, uint16_t source, uint16_t dest, std::vector<uint8_t> &message);
20 
21  protected:
22  uint16_t command_{0xffff};
23  uint16_t source_{0xffff};
24  uint16_t dest_{0xffff};
25 
26  virtual void handle_message(std::vector<uint8_t> &message) = 0;
27 };
28 
29 class VBus : public uart::UARTDevice, public Component {
30  public:
31  void dump_config() override;
32  void loop() override;
33  float get_setup_priority() const override { return setup_priority::DATA; }
34 
35  void register_listener(VBusListener *listener) { this->listeners_.push_back(listener); }
36 
37  protected:
38  int state_{0};
39  std::vector<uint8_t> buffer_;
40  uint8_t protocol_;
41  uint16_t source_;
42  uint16_t dest_;
43  uint16_t command_;
44  uint8_t frames_;
45  uint8_t cframe_;
46  uint8_t fbytes_[6];
47  int fbcount_;
48  std::vector<VBusListener *> listeners_{};
49 };
50 
51 } // namespace vbus
52 } // namespace esphome
void set_dest(uint16_t dest)
Definition: vbus.h:17
void loop()
uint16_t command_
Definition: vbus.h:43
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
uint8_t protocol_
Definition: vbus.h:40
void on_message(uint16_t command, uint16_t source, uint16_t dest, std::vector< uint8_t > &message)
Definition: vbus.cpp:114
uint8_t frames_
Definition: vbus.h:44
std::function< float(std::vector< uint8_t > &)> message_parser_t
Definition: vbus.h:9
uint16_t dest_
Definition: vbus.h:42
std::vector< uint8_t > buffer_
Definition: vbus.h:39
void set_source(uint16_t source)
Definition: vbus.h:16
float get_setup_priority() const override
Definition: vbus.h:33
void set_command(uint16_t command)
Definition: vbus.h:15
uint8_t cframe_
Definition: vbus.h:45
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
virtual void handle_message(std::vector< uint8_t > &message)=0
uint16_t source_
Definition: vbus.h:41
void register_listener(VBusListener *listener)
Definition: vbus.h:35