mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	[nfc] Update code to use `format_hex_pretty` (#9384)
				
					
				
			This commit is contained in:
		| @@ -1,5 +1,6 @@ | |||||||
| #include "nfc.h" | #include "nfc.h" | ||||||
| #include <cstdio> | #include <cstdio> | ||||||
|  | #include "esphome/core/helpers.h" | ||||||
| #include "esphome/core/log.h" | #include "esphome/core/log.h" | ||||||
|  |  | ||||||
| namespace esphome { | namespace esphome { | ||||||
| @@ -7,29 +8,9 @@ namespace nfc { | |||||||
|  |  | ||||||
| static const char *const TAG = "nfc"; | static const char *const TAG = "nfc"; | ||||||
|  |  | ||||||
| std::string format_uid(std::vector<uint8_t> &uid) { | std::string format_uid(const std::vector<uint8_t> &uid) { return format_hex_pretty(uid, '-', false); } | ||||||
|   char buf[(uid.size() * 2) + uid.size() - 1]; |  | ||||||
|   int offset = 0; |  | ||||||
|   for (size_t i = 0; i < uid.size(); i++) { |  | ||||||
|     const char *format = "%02X"; |  | ||||||
|     if (i + 1 < uid.size()) |  | ||||||
|       format = "%02X-"; |  | ||||||
|     offset += sprintf(buf + offset, format, uid[i]); |  | ||||||
|   } |  | ||||||
|   return std::string(buf); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| std::string format_bytes(std::vector<uint8_t> &bytes) { | std::string format_bytes(const std::vector<uint8_t> &bytes) { return format_hex_pretty(bytes, ' ', false); } | ||||||
|   char buf[(bytes.size() * 2) + bytes.size() - 1]; |  | ||||||
|   int offset = 0; |  | ||||||
|   for (size_t i = 0; i < bytes.size(); i++) { |  | ||||||
|     const char *format = "%02X"; |  | ||||||
|     if (i + 1 < bytes.size()) |  | ||||||
|       format = "%02X "; |  | ||||||
|     offset += sprintf(buf + offset, format, bytes[i]); |  | ||||||
|   } |  | ||||||
|   return std::string(buf); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| uint8_t guess_tag_type(uint8_t uid_length) { | uint8_t guess_tag_type(uint8_t uid_length) { | ||||||
|   if (uid_length == 4) { |   if (uid_length == 4) { | ||||||
|   | |||||||
| @@ -2,8 +2,8 @@ | |||||||
|  |  | ||||||
| #include "esphome/core/helpers.h" | #include "esphome/core/helpers.h" | ||||||
| #include "esphome/core/log.h" | #include "esphome/core/log.h" | ||||||
| #include "ndef_record.h" |  | ||||||
| #include "ndef_message.h" | #include "ndef_message.h" | ||||||
|  | #include "ndef_record.h" | ||||||
| #include "nfc_tag.h" | #include "nfc_tag.h" | ||||||
|  |  | ||||||
| #include <vector> | #include <vector> | ||||||
| @@ -53,8 +53,8 @@ static const uint8_t DEFAULT_KEY[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; | |||||||
| static const uint8_t NDEF_KEY[6] = {0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7}; | static const uint8_t NDEF_KEY[6] = {0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7}; | ||||||
| static const uint8_t MAD_KEY[6] = {0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5}; | static const uint8_t MAD_KEY[6] = {0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5}; | ||||||
|  |  | ||||||
| std::string format_uid(std::vector<uint8_t> &uid); | std::string format_uid(const std::vector<uint8_t> &uid); | ||||||
| std::string format_bytes(std::vector<uint8_t> &bytes); | std::string format_bytes(const std::vector<uint8_t> &bytes); | ||||||
|  |  | ||||||
| uint8_t guess_tag_type(uint8_t uid_length); | uint8_t guess_tag_type(uint8_t uid_length); | ||||||
| uint8_t get_mifare_classic_ndef_start_index(std::vector<uint8_t> &data); | uint8_t get_mifare_classic_ndef_start_index(std::vector<uint8_t> &data); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user