9 static const char *
const TAG =
"wl_134.sensor";
10 static const uint8_t ASCII_CR = 0x0D;
11 static const uint8_t ASCII_NBSP = 0xFF;
12 static const int MAX_DATA_LENGTH_BYTES = 6;
17 while (this->
available() >= RFID134_PACKET_SIZE) {
20 ESP_LOGW(TAG,
"Error: %d", error);
26 uint8_t packet[RFID134_PACKET_SIZE];
27 packet[RFID134_PACKET_START_CODE] = this->
read();
30 if (packet[RFID134_PACKET_START_CODE] != 0x02) {
35 if (!this->
read_array(&(packet[RFID134_PACKET_ID]), RFID134_PACKET_SIZE - 1)) {
39 if (packet[RFID134_PACKET_END_CODE] != 0x03) {
45 for (uint8_t i = RFID134_PACKET_ID; i < RFID134_PACKET_CHECKSUM; i++) {
46 checksum = checksum ^ packet[i];
50 if (checksum != packet[RFID134_PACKET_CHECKSUM]) {
54 if (static_cast<uint8_t>(~checksum) != static_cast<uint8_t>(packet[RFID134_PACKET_CHECKSUM_INVERT])) {
61 reading.
id = this->hex_lsb_ascii_to_uint64_(&(packet[RFID134_PACKET_ID]), RFID134_PACKET_COUNTRY - RFID134_PACKET_ID);
62 reading.
country = this->hex_lsb_ascii_to_uint64_(&(packet[RFID134_PACKET_COUNTRY]),
63 RFID134_PACKET_DATA_FLAG - RFID134_PACKET_COUNTRY);
64 reading.
isData = packet[RFID134_PACKET_DATA_FLAG] ==
'1';
65 reading.
isAnimal = packet[RFID134_PACKET_ANIMAL_FLAG] ==
'1';
66 reading.
reserved0 = this->hex_lsb_ascii_to_uint64_(&(packet[RFID134_PACKET_RESERVED0]),
67 RFID134_PACKET_RESERVED1 - RFID134_PACKET_RESERVED0);
68 reading.
reserved1 = this->hex_lsb_ascii_to_uint64_(&(packet[RFID134_PACKET_RESERVED1]),
69 RFID134_PACKET_CHECKSUM - RFID134_PACKET_RESERVED1);
71 ESP_LOGV(TAG,
"Tag id: %012lld", reading.
id);
72 ESP_LOGV(TAG,
"Country: %03d", reading.
country);
73 ESP_LOGV(TAG,
"isData: %s", reading.
isData ?
"true" :
"false");
74 ESP_LOGV(TAG,
"isAnimal: %s", reading.
isAnimal ?
"true" :
"false");
75 ESP_LOGV(TAG,
"Reserved0: %d", reading.
reserved0);
76 ESP_LOGV(TAG,
"Reserved1: %" PRId32, reading.
reserved1);
79 sprintf(buf,
"%03d%012lld", reading.
country, reading.
id);
81 if (this->do_reset_) {
88 uint64_t Wl134Component::hex_lsb_ascii_to_uint64_(
const uint8_t *text, uint8_t text_size) {
90 uint8_t i = text_size;
94 uint8_t digit = text[i];
96 digit = digit -
'A' + 10;
100 value = (value << 4) + digit;
107 ESP_LOGCONFIG(TAG,
"WL-134 Sensor:");
108 LOG_TEXT_SENSOR(
"",
"Tag",
this);
optional< std::array< uint8_t, N > > read_array()
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
void dump_config() override
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...
Implementation of SPI Controller mode.