7 static const char *
const TAG =
"teleinfo";
10 static int get_field(
char *dest,
char *buf_start,
char *buf_end,
int sep,
int max_len) {
14 field_end =
static_cast<char *
>(memchr(buf_start, sep, buf_end - buf_start));
17 len = field_end - buf_start;
20 strncpy(dest, buf_start, len);
27 int grp_len = grp_end - grp;
28 uint8_t raw_crc = grp[grp_len - 1];
37 if (raw_crc != crc_tmp) {
38 ESP_LOGE(TAG,
"bad crc: got %d except %d", raw_crc, crc_tmp);
60 ESP_LOGW(TAG,
"Internal buffer full");
120 while ((buf_finger = static_cast<char *>(memchr(buf_finger, (
int) 0xa, buf_index_ - 1))) &&
121 ((buf_finger -
buf_) < buf_index_)) {
131 grp_end =
static_cast<char *
>(memchr(buf_finger, 0xd, buf_end - buf_finger));
133 ESP_LOGE(TAG,
"No group found");
141 field_len = get_field(
tag_, buf_finger, grp_end,
separator_, MAX_TAG_SIZE);
142 if (!field_len || field_len >= MAX_TAG_SIZE) {
143 ESP_LOGE(TAG,
"Invalid tag.");
148 buf_finger += field_len + 1;
157 if (!field_len || field_len >= MAX_TIMESTAMP_SIZE) {
158 ESP_LOGE(TAG,
"Invalid timestamp for tag %s",
timestamp_);
163 buf_finger += field_len + 1;
166 field_len = get_field(
val_, buf_finger, grp_end,
separator_, MAX_VAL_SIZE);
167 if (!field_len || field_len >= MAX_VAL_SIZE) {
168 ESP_LOGE(TAG,
"Invalid value for tag %s",
tag_);
173 buf_finger += field_len + 1 + 1 + 1;
183 if (tag != element->tag)
185 element->publish_val(val);
189 ESP_LOGCONFIG(TAG,
"TeleInfo:");
193 if (historical_mode) {
TeleInfo(bool historical_mode)
enum esphome::teleinfo::TeleInfo::State OFF
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...
void register_teleinfo_listener(TeleInfoListener *listener)
char timestamp_[MAX_TIMESTAMP_SIZE]
bool read_chars_until_(bool drop, uint8_t c)
bool check_crc_(const char *grp, const char *grp_end)
std::vector< TeleInfoListener * > teleinfo_listeners_
Implementation of SPI Controller mode.
void publish_value_(const std::string &tag, const std::string &val)
void dump_config() override