13 #include <dsmr/parser.h> 14 #include <dsmr/fields.h> 21 using namespace ::dsmr::fields;
25 #if !defined(DSMR_SENSOR_LIST) && !defined(DSMR_TEXT_SENSOR_LIST) 27 #define DSMR_TEXT_SENSOR_LIST(F, SEP) F(identification) 30 #if defined(DSMR_SENSOR_LIST) && defined(DSMR_TEXT_SENSOR_LIST) 36 #ifndef DSMR_SENSOR_LIST 37 #define DSMR_SENSOR_LIST(F, SEP) 40 #ifndef DSMR_TEXT_SENSOR_LIST 41 #define DSMR_TEXT_SENSOR_LIST(F, SEP) 44 #define DSMR_DATA_SENSOR(s) s 47 using MyData = ::dsmr::ParsedData<DSMR_TEXT_SENSOR_LIST(DSMR_DATA_SENSOR, DSMR_COMMA)
48 DSMR_BOTH DSMR_SENSOR_LIST(DSMR_DATA_SENSOR, DSMR_COMMA)>;
54 void setup()
override;
57 bool parse_telegram();
60 #define DSMR_PUBLISH_SENSOR(s) \ 61 if (data.s##_present && this->s_##s##_ != nullptr) \ 62 s_##s##_->publish_state(data.s); 63 DSMR_SENSOR_LIST(DSMR_PUBLISH_SENSOR, )
65 #define DSMR_PUBLISH_TEXT_SENSOR(s) \ 66 if (data.s##_present && this->s_##s##_ != nullptr) \ 67 s_##s##_->publish_state(data.s.c_str()); 68 DSMR_TEXT_SENSOR_LIST(DSMR_PUBLISH_TEXT_SENSOR, )
71 void dump_config()
override;
73 void set_decryption_key(
const std::string &decryption_key);
80 #define DSMR_SET_SENSOR(s) \ 81 void set_##s(sensor::Sensor *sensor) { s_##s##_ = sensor; } 82 DSMR_SENSOR_LIST(DSMR_SET_SENSOR, )
84 #define DSMR_SET_TEXT_SENSOR(s) \ 85 void set_##s(text_sensor::TextSensor *sensor) { s_##s##_ = sensor; } 86 DSMR_TEXT_SENSOR_LIST(DSMR_SET_TEXT_SENSOR, )
89 void set_telegram(text_sensor::TextSensor *
sensor) { s_telegram_ =
sensor; }
92 void receive_telegram_();
93 void receive_encrypted_telegram_();
94 void reset_telegram_();
105 bool available_within_timeout_();
109 bool request_interval_reached_();
111 uint32_t last_request_time_{0};
112 bool requesting_data_{
false};
113 bool ready_to_request_data_();
114 void start_requesting_data_();
115 void stop_requesting_data_();
119 bool receive_timeout_reached_();
121 char *telegram_{
nullptr};
122 size_t bytes_read_{0};
123 uint8_t *crypt_telegram_{
nullptr};
124 size_t crypt_telegram_len_{0};
125 size_t crypt_bytes_read_{0};
126 uint32_t last_read_time_{0};
127 bool header_found_{
false};
128 bool footer_found_{
false};
134 #define DSMR_DECLARE_SENSOR(s) sensor::Sensor *s_##s##_{nullptr}; 135 DSMR_SENSOR_LIST(DSMR_DECLARE_SENSOR, )
137 #define DSMR_DECLARE_TEXT_SENSOR(s) text_sensor::TextSensor *s_##s##_{nullptr}; 138 DSMR_TEXT_SENSOR_LIST(DSMR_DECLARE_TEXT_SENSOR, )
140 std::vector<uint8_t> decryption_key_{};
146 #endif // USE_ARDUINO
::dsmr::ParsedData< DSMR_TEXT_SENSOR_LIST(DSMR_DATA_SENSOR, DSMR_COMMA) DSMR_BOTH DSMR_SENSOR_LIST(DSMR_DATA_SENSOR, DSMR_COMMA)> MyData
uint32_t receive_timeout_
void set_request_interval(uint32_t interval)
void set_receive_timeout(uint32_t timeout)
void publish_sensors(MyData &data)
uint32_t request_interval_
void set_max_telegram_length(size_t length)
Dsmr(uart::UARTComponent *uart, bool crc_check)
Implementation of SPI Controller mode.
esphome::sensor::Sensor * sensor
void set_request_pin(GPIOPin *request_pin)