mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	PN532 - don't read extra page and fix size (#1565)
Co-authored-by: Samuel Sieb <samuel@sieb.net>
This commit is contained in:
		| @@ -17,12 +17,12 @@ nfc::NfcTag *PN532::read_mifare_ultralight_tag_(std::vector<uint8_t> &uid) { | |||||||
|   if (!this->find_mifare_ultralight_ndef_(message_length, message_start_index)) { |   if (!this->find_mifare_ultralight_ndef_(message_length, message_start_index)) { | ||||||
|     return new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2); |     return new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2); | ||||||
|   } |   } | ||||||
|  |   ESP_LOGVV(TAG, "message length: %d, start: %d", message_length, message_start_index); | ||||||
|  |  | ||||||
|   if (message_length == 0) { |   if (message_length == 0) { | ||||||
|     return new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2); |     return new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2); | ||||||
|   } |   } | ||||||
|   std::vector<uint8_t> data; |   std::vector<uint8_t> data; | ||||||
|   uint8_t index = 0; |  | ||||||
|   for (uint8_t page = nfc::MIFARE_ULTRALIGHT_DATA_START_PAGE; page < nfc::MIFARE_ULTRALIGHT_MAX_PAGE; page++) { |   for (uint8_t page = nfc::MIFARE_ULTRALIGHT_DATA_START_PAGE; page < nfc::MIFARE_ULTRALIGHT_MAX_PAGE; page++) { | ||||||
|     std::vector<uint8_t> page_data; |     std::vector<uint8_t> page_data; | ||||||
|     if (!this->read_mifare_ultralight_page_(page, page_data)) { |     if (!this->read_mifare_ultralight_page_(page, page_data)) { | ||||||
| @@ -31,13 +31,12 @@ nfc::NfcTag *PN532::read_mifare_ultralight_tag_(std::vector<uint8_t> &uid) { | |||||||
|     } |     } | ||||||
|     data.insert(data.end(), page_data.begin(), page_data.end()); |     data.insert(data.end(), page_data.begin(), page_data.end()); | ||||||
|  |  | ||||||
|     if (index >= (message_length + message_start_index)) |     if (data.size() >= (message_length + message_start_index)) | ||||||
|       break; |       break; | ||||||
|  |  | ||||||
|     index += page_data.size(); |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   data.erase(data.begin(), data.begin() + message_start_index); |   data.erase(data.begin(), data.begin() + message_start_index); | ||||||
|  |   data.erase(data.begin() + message_length, data.end()); | ||||||
|  |  | ||||||
|   return new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2, data); |   return new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2, data); | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user