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