10static const char *
const TAG =
"wl_134.sensor";
11static const uint8_t ASCII_CR = 0x0D;
12static const uint8_t ASCII_NBSP = 0xFF;
13static const int MAX_DATA_LENGTH_BYTES = 6;
18 while (this->
available() >= RFID134_PACKET_SIZE) {
21 ESP_LOGW(TAG,
"Error: %d", error);
27 uint8_t packet[RFID134_PACKET_SIZE];
28 packet[RFID134_PACKET_START_CODE] = this->
read();
31 if (packet[RFID134_PACKET_START_CODE] != 0x02) {
36 if (!this->
read_array(&(packet[RFID134_PACKET_ID]), RFID134_PACKET_SIZE - 1)) {
40 if (packet[RFID134_PACKET_END_CODE] != 0x03) {
46 for (uint8_t i = RFID134_PACKET_ID; i < RFID134_PACKET_CHECKSUM; i++) {
51 if (
checksum != packet[RFID134_PACKET_CHECKSUM]) {
55 if (
static_cast<uint8_t
>(~
checksum) !=
static_cast<uint8_t
>(packet[RFID134_PACKET_CHECKSUM_INVERT])) {
59 Rfid134Reading reading;
62 reading.id = this->hex_lsb_ascii_to_uint64_(&(packet[RFID134_PACKET_ID]), RFID134_PACKET_COUNTRY - RFID134_PACKET_ID);
63 reading.country = this->hex_lsb_ascii_to_uint64_(&(packet[RFID134_PACKET_COUNTRY]),
64 RFID134_PACKET_DATA_FLAG - RFID134_PACKET_COUNTRY);
65 reading.isData = packet[RFID134_PACKET_DATA_FLAG] ==
'1';
66 reading.isAnimal = packet[RFID134_PACKET_ANIMAL_FLAG] ==
'1';
67 reading.reserved0 = this->hex_lsb_ascii_to_uint64_(&(packet[RFID134_PACKET_RESERVED0]),
68 RFID134_PACKET_RESERVED1 - RFID134_PACKET_RESERVED0);
69 reading.reserved1 = this->hex_lsb_ascii_to_uint64_(&(packet[RFID134_PACKET_RESERVED1]),
70 RFID134_PACKET_CHECKSUM - RFID134_PACKET_RESERVED1);
78 "Reserved1: %" PRId32,
79 reading.id, reading.country, reading.isData ?
"true" :
"false", reading.isAnimal ?
"true" :
"false",
80 reading.reserved0, reading.reserved1);
83 buf_append_printf(buf,
sizeof(buf), 0,
"%03d%012" PRId64, reading.country, reading.id);
85 if (this->do_reset_) {
92uint64_t Wl134Component::hex_lsb_ascii_to_uint64_(
const uint8_t *text, uint8_t text_size) {
94 uint8_t i = text_size;
98 uint8_t digit = text[i];
100 digit = digit -
'A' + 10;
104 value = (value << 4) + digit;
111 ESP_LOGCONFIG(TAG,
"WL-134 Sensor:");
112 LOG_TEXT_SENSOR(
"",
"Tag",
this);
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_timeout(const std voi set_timeout)(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
void publish_state(const std::string &state)
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...