7 static const char *
const TAG =
"rdm6300";
9 static const uint8_t RDM6300_START_BYTE = 0x02;
10 static const uint8_t RDM6300_END_BYTE = 0x03;
11 static const int8_t RDM6300_STATE_WAITING_FOR_START = -1;
14 while (this->available() > 0) {
16 if (!this->read_byte(&data)) {
17 ESP_LOGW(TAG,
"Reading data from RDM6300 failed!");
18 this->status_set_warning();
22 if (this->read_state_ == RDM6300_STATE_WAITING_FOR_START) {
23 if (data == RDM6300_START_BYTE) {
24 this->read_state_ = 0;
28 }
else if (this->read_state_ < 12) {
29 uint8_t value = (data >
'9') ? data -
'7' : data -
'0';
30 if (this->read_state_ % 2 == 0) {
31 this->buffer_[this->read_state_ / 2] = value << 4;
33 this->buffer_[this->read_state_ / 2] += value;
36 }
else if (data != RDM6300_END_BYTE) {
37 ESP_LOGW(TAG,
"Invalid end byte from RDM6300!");
38 this->read_state_ = RDM6300_STATE_WAITING_FOR_START;
41 for (uint8_t i = 0; i < 5; i++)
42 checksum ^= this->buffer_[i];
43 this->read_state_ = RDM6300_STATE_WAITING_FOR_START;
44 if (checksum != this->buffer_[5]) {
45 ESP_LOGW(TAG,
"Checksum from RDM6300 doesn't match! (0x%02X!=0x%02X)", checksum, this->buffer_[5]);
48 this->status_clear_warning();
49 const uint32_t result =
encode_uint32(this->buffer_[1], this->buffer_[2], this->buffer_[3], this->buffer_[4]);
50 bool report = result != last_id_;
51 for (
auto *card : this->cards_) {
52 if (card->process(result)) {
56 for (
auto *trig : this->triggers_)
57 trig->process(result);
60 ESP_LOGD(TAG,
"Found new tag with ID %" PRIu32, result);
constexpr uint32_t encode_uint32(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
Encode a 32-bit value given four bytes in most to least significant byte order.
Implementation of SPI Controller mode.