6static const char *
const TAG =
"teleinfo";
9static int get_field(
char *dest,
char *buf_start,
char *buf_end,
int sep,
int max_len) {
13 field_end =
static_cast<char *
>(memchr(buf_start, sep, buf_end - buf_start));
16 len = field_end - buf_start;
19 strncpy(dest, buf_start,
len);
26 int grp_len = grp_end - grp;
27 uint8_t raw_crc = grp[grp_len - 1];
36 if (raw_crc != crc_tmp) {
37 ESP_LOGE(TAG,
"bad crc: got %d except %d", raw_crc, crc_tmp);
59 ESP_LOGW(TAG,
"Internal buffer full");
119 while ((buf_finger =
static_cast<char *
>(memchr(buf_finger, (
int) 0xa,
buf_index_ - 1))) &&
130 grp_end =
static_cast<char *
>(memchr(buf_finger, 0xd, buf_end - buf_finger));
132 ESP_LOGE(TAG,
"No group found");
140 field_len = get_field(
tag_, buf_finger, grp_end,
separator_, MAX_TAG_SIZE);
141 if (!field_len || field_len >= MAX_TAG_SIZE) {
142 ESP_LOGE(TAG,
"Invalid tag.");
147 buf_finger += field_len + 1;
156 if (!field_len || field_len >= MAX_TIMESTAMP_SIZE) {
157 ESP_LOGE(TAG,
"Invalid timestamp for tag %s",
timestamp_);
162 buf_finger += field_len + 1;
165 field_len = get_field(
val_, buf_finger, grp_end,
separator_, MAX_VAL_SIZE);
166 if (!field_len || field_len >= MAX_VAL_SIZE) {
167 ESP_LOGE(TAG,
"Invalid value for tag %s",
tag_);
172 buf_finger += field_len + 1 + 1 + 1;
182 if (
tag != element->tag)
184 element->publish_val(
val);
188 ESP_LOGCONFIG(TAG,
"TeleInfo:");
192 if (historical_mode) {
void publish_value_(const std::string &tag, const std::string &val)
char timestamp_[MAX_TIMESTAMP_SIZE]
TeleInfo(bool historical_mode)
void register_teleinfo_listener(TeleInfoListener *listener)
bool check_crc_(const char *grp, const char *grp_end)
enum esphome::teleinfo::TeleInfo::State OFF
std::vector< TeleInfoListener * > teleinfo_listeners_
void dump_config() override
bool read_chars_until_(bool drop, uint8_t c)
void check_uart_settings(uint32_t baud_rate, uint8_t stop_bits=1, UARTParityOptions parity=UART_CONFIG_PARITY_NONE, uint8_t data_bits=8)
Check that the configuration of the UART bus matches the provided values and otherwise print a warnin...
@ UART_CONFIG_PARITY_EVEN