ESPHome  2024.12.2
teleinfo.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 #include <vector>
7 
8 namespace esphome {
9 namespace teleinfo {
10 /*
11  * 198 bytes should be enough to contain a full session in historical mode with
12  * three phases. But go with 1024 just to be sure.
13  */
14 static const uint8_t MAX_TAG_SIZE = 64;
15 static const uint16_t MAX_VAL_SIZE = 256;
16 static const uint16_t MAX_BUF_SIZE = 2048;
17 static const uint16_t MAX_TIMESTAMP_SIZE = 14;
18 
20  public:
21  std::string tag;
22  virtual void publish_val(const std::string &val){};
23 };
24 class TeleInfo : public PollingComponent, public uart::UARTDevice {
25  public:
26  TeleInfo(bool historical_mode);
27  void register_teleinfo_listener(TeleInfoListener *listener);
28  void loop() override;
29  void setup() override;
30  void update() override;
31  void dump_config() override;
32  std::vector<TeleInfoListener *> teleinfo_listeners_{};
33 
34  protected:
35  uint32_t baud_rate_;
38  char buf_[MAX_BUF_SIZE];
39  uint32_t buf_index_{0};
40  char tag_[MAX_TAG_SIZE];
41  char val_[MAX_VAL_SIZE];
42  char timestamp_[MAX_TIMESTAMP_SIZE];
43  enum State {
44  OFF,
45  ON,
48  } state_{OFF};
49  bool read_chars_until_(bool drop, uint8_t c);
50  bool check_crc_(const char *grp, const char *grp_end);
51  void publish_value_(const std::string &tag, const std::string &val);
52 };
53 } // namespace teleinfo
54 } // namespace esphome
void setup()
void loop()
mopeka_std_values val[4]
This class simplifies creating components that periodically check a state.
Definition: component.h:283
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
virtual void publish_val(const std::string &val)
Definition: teleinfo.h:22