ESPHome  2024.11.0
sml.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <vector>
6 #include "esphome/core/helpers.h"
8 #include "sml_parser.h"
9 
10 namespace esphome {
11 namespace sml {
12 
13 class SmlListener {
14  public:
15  std::string server_id;
16  std::string obis_code;
17  SmlListener(std::string server_id, std::string obis_code);
18  virtual void publish_val(const ObisInfo &obis_info){};
19 };
20 
21 class Sml : public Component, public uart::UARTDevice {
22  public:
23  void register_sml_listener(SmlListener *listener);
24  void loop() override;
25  void dump_config() override;
26  std::vector<SmlListener *> sml_listeners_{};
27  void add_on_data_callback(std::function<void(std::vector<uint8_t>, bool)> &&callback);
28 
29  protected:
30  void process_sml_file_(const bytes &sml_data);
31  void log_obis_info_(const std::vector<ObisInfo> &obis_info_vec);
32  void publish_obis_info_(const std::vector<ObisInfo> &obis_info_vec);
33  char check_start_end_bytes_(uint8_t byte);
34  void publish_value_(const ObisInfo &obis_info);
35 
36  // Serial parser
37  bool record_ = false;
38  uint16_t incoming_mask_ = 0;
40 
42 };
43 
44 bool check_sml_data(const bytes &buffer);
45 
46 uint8_t get_code(uint8_t byte);
47 } // namespace sml
48 } // namespace esphome
void loop()
bytes sml_data_
Definition: sml.h:39
SmlListener(std::string server_id, std::string obis_code)
Definition: sml.cpp:14
std::string server_id
Definition: sml.h:15
uint8_t get_code(uint8_t byte)
Definition: sml.cpp:132
virtual void publish_val(const ObisInfo &obis_info)
Definition: sml.h:18
std::string obis_code
Definition: sml.h:16
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
std::vector< uint8_t > bytes
Definition: sml_parser.h:12
bool check_sml_data(const bytes &buffer)
Definition: sml.cpp:108