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