mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-01 18:48:28 +02:00
Activate owning-memory clang-tidy check (#1891)
* Activate owning-memory clang-tidy check * Lint * Lint * Fix issue with new NfcTag constructor * Update pointers for number and select * Add back the NOLINT to display buffer * Fix merge * DSMR fixes * Nextion fixes * Fix pipsolar * Fix lwip socket * Format * Change socket fix Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -104,7 +104,7 @@ void PN532::loop() {
|
||||
if (!success) {
|
||||
// Something failed
|
||||
if (!this->current_uid_.empty()) {
|
||||
auto tag = new nfc::NfcTag(this->current_uid_);
|
||||
auto tag = make_unique<nfc::NfcTag>(this->current_uid_);
|
||||
for (auto *trigger : this->triggers_ontagremoved_)
|
||||
trigger->process(tag);
|
||||
}
|
||||
@@ -117,7 +117,7 @@ void PN532::loop() {
|
||||
if (num_targets != 1) {
|
||||
// no tags found or too many
|
||||
if (!this->current_uid_.empty()) {
|
||||
auto tag = new nfc::NfcTag(this->current_uid_);
|
||||
auto tag = make_unique<nfc::NfcTag>(this->current_uid_);
|
||||
for (auto *trigger : this->triggers_ontagremoved_)
|
||||
trigger->process(tag);
|
||||
}
|
||||
@@ -158,10 +158,10 @@ void PN532::loop() {
|
||||
if (report) {
|
||||
ESP_LOGD(TAG, "Found new tag '%s'", nfc::format_uid(nfcid).c_str());
|
||||
if (tag->has_ndef_message()) {
|
||||
auto message = tag->get_ndef_message();
|
||||
auto records = message->get_records();
|
||||
const auto &message = tag->get_ndef_message();
|
||||
const auto &records = message->get_records();
|
||||
ESP_LOGD(TAG, " NDEF formatted records:");
|
||||
for (auto &record : records) {
|
||||
for (const auto &record : records) {
|
||||
ESP_LOGD(TAG, " %s - %s", record->get_type().c_str(), record->get_payload().c_str());
|
||||
}
|
||||
}
|
||||
@@ -270,7 +270,7 @@ void PN532::turn_off_rf_() {
|
||||
});
|
||||
}
|
||||
|
||||
nfc::NfcTag *PN532::read_tag_(std::vector<uint8_t> &uid) {
|
||||
std::unique_ptr<nfc::NfcTag> PN532::read_tag_(std::vector<uint8_t> &uid) {
|
||||
uint8_t type = nfc::guess_tag_type(uid.size());
|
||||
|
||||
if (type == nfc::TAG_TYPE_MIFARE_CLASSIC) {
|
||||
@@ -281,9 +281,9 @@ nfc::NfcTag *PN532::read_tag_(std::vector<uint8_t> &uid) {
|
||||
return this->read_mifare_ultralight_tag_(uid);
|
||||
} else if (type == nfc::TAG_TYPE_UNKNOWN) {
|
||||
ESP_LOGV(TAG, "Cannot determine tag type");
|
||||
return new nfc::NfcTag(uid);
|
||||
return make_unique<nfc::NfcTag>(uid);
|
||||
} else {
|
||||
return new nfc::NfcTag(uid);
|
||||
return make_unique<nfc::NfcTag>(uid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,7 +373,9 @@ bool PN532BinarySensor::process(std::vector<uint8_t> &data) {
|
||||
this->found_ = true;
|
||||
return true;
|
||||
}
|
||||
void PN532OnTagTrigger::process(nfc::NfcTag *tag) { this->trigger(nfc::format_uid(tag->get_uid()), *tag); }
|
||||
void PN532OnTagTrigger::process(const std::unique_ptr<nfc::NfcTag> &tag) {
|
||||
this->trigger(nfc::format_uid(tag->get_uid()), *tag);
|
||||
}
|
||||
|
||||
} // namespace pn532
|
||||
} // namespace esphome
|
||||
|
||||
@@ -54,13 +54,13 @@ class PN532 : public PollingComponent {
|
||||
virtual bool read_data(std::vector<uint8_t> &data, uint8_t len) = 0;
|
||||
virtual bool read_response(uint8_t command, std::vector<uint8_t> &data) = 0;
|
||||
|
||||
nfc::NfcTag *read_tag_(std::vector<uint8_t> &uid);
|
||||
std::unique_ptr<nfc::NfcTag> read_tag_(std::vector<uint8_t> &uid);
|
||||
|
||||
bool format_tag_(std::vector<uint8_t> &uid);
|
||||
bool clean_tag_(std::vector<uint8_t> &uid);
|
||||
bool write_tag_(std::vector<uint8_t> &uid, nfc::NdefMessage *message);
|
||||
|
||||
nfc::NfcTag *read_mifare_classic_tag_(std::vector<uint8_t> &uid);
|
||||
std::unique_ptr<nfc::NfcTag> read_mifare_classic_tag_(std::vector<uint8_t> &uid);
|
||||
bool read_mifare_classic_block_(uint8_t block_num, std::vector<uint8_t> &data);
|
||||
bool write_mifare_classic_block_(uint8_t block_num, std::vector<uint8_t> &data);
|
||||
bool auth_mifare_classic_block_(std::vector<uint8_t> &uid, uint8_t block_num, uint8_t key_num, const uint8_t *key);
|
||||
@@ -68,7 +68,7 @@ class PN532 : public PollingComponent {
|
||||
bool format_mifare_classic_ndef_(std::vector<uint8_t> &uid);
|
||||
bool write_mifare_classic_tag_(std::vector<uint8_t> &uid, nfc::NdefMessage *message);
|
||||
|
||||
nfc::NfcTag *read_mifare_ultralight_tag_(std::vector<uint8_t> &uid);
|
||||
std::unique_ptr<nfc::NfcTag> read_mifare_ultralight_tag_(std::vector<uint8_t> &uid);
|
||||
bool read_mifare_ultralight_page_(uint8_t page_num, std::vector<uint8_t> &data);
|
||||
bool is_mifare_ultralight_formatted_();
|
||||
uint16_t read_mifare_ultralight_capacity_();
|
||||
@@ -117,7 +117,7 @@ class PN532BinarySensor : public binary_sensor::BinarySensor {
|
||||
|
||||
class PN532OnTagTrigger : public Trigger<std::string, nfc::NfcTag> {
|
||||
public:
|
||||
void process(nfc::NfcTag *tag);
|
||||
void process(const std::unique_ptr<nfc::NfcTag> &tag);
|
||||
};
|
||||
|
||||
class PN532OnFinishedWriteTrigger : public Trigger<> {
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace pn532 {
|
||||
|
||||
static const char *const TAG = "pn532.mifare_classic";
|
||||
|
||||
nfc::NfcTag *PN532::read_mifare_classic_tag_(std::vector<uint8_t> &uid) {
|
||||
std::unique_ptr<nfc::NfcTag> PN532::read_mifare_classic_tag_(std::vector<uint8_t> &uid) {
|
||||
uint8_t current_block = 4;
|
||||
uint8_t message_start_index = 0;
|
||||
uint32_t message_length = 0;
|
||||
@@ -15,15 +15,15 @@ nfc::NfcTag *PN532::read_mifare_classic_tag_(std::vector<uint8_t> &uid) {
|
||||
std::vector<uint8_t> data;
|
||||
if (this->read_mifare_classic_block_(current_block, data)) {
|
||||
if (!nfc::decode_mifare_classic_tlv(data, message_length, message_start_index)) {
|
||||
return new nfc::NfcTag(uid, nfc::ERROR);
|
||||
return make_unique<nfc::NfcTag>(uid, nfc::ERROR);
|
||||
}
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to read block %d", current_block);
|
||||
return new nfc::NfcTag(uid, nfc::MIFARE_CLASSIC);
|
||||
return make_unique<nfc::NfcTag>(uid, nfc::MIFARE_CLASSIC);
|
||||
}
|
||||
} else {
|
||||
ESP_LOGV(TAG, "Tag is not NDEF formatted");
|
||||
return new nfc::NfcTag(uid, nfc::MIFARE_CLASSIC);
|
||||
return make_unique<nfc::NfcTag>(uid, nfc::MIFARE_CLASSIC);
|
||||
}
|
||||
|
||||
uint32_t index = 0;
|
||||
@@ -51,7 +51,7 @@ nfc::NfcTag *PN532::read_mifare_classic_tag_(std::vector<uint8_t> &uid) {
|
||||
}
|
||||
}
|
||||
buffer.erase(buffer.begin(), buffer.begin() + message_start_index);
|
||||
return new nfc::NfcTag(uid, nfc::MIFARE_CLASSIC, buffer);
|
||||
return make_unique<nfc::NfcTag>(uid, nfc::MIFARE_CLASSIC, buffer);
|
||||
}
|
||||
|
||||
bool PN532::read_mifare_classic_block_(uint8_t block_num, std::vector<uint8_t> &data) {
|
||||
|
||||
@@ -6,28 +6,28 @@ namespace pn532 {
|
||||
|
||||
static const char *const TAG = "pn532.mifare_ultralight";
|
||||
|
||||
nfc::NfcTag *PN532::read_mifare_ultralight_tag_(std::vector<uint8_t> &uid) {
|
||||
std::unique_ptr<nfc::NfcTag> PN532::read_mifare_ultralight_tag_(std::vector<uint8_t> &uid) {
|
||||
if (!this->is_mifare_ultralight_formatted_()) {
|
||||
ESP_LOGD(TAG, "Not NDEF formatted");
|
||||
return new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2);
|
||||
return make_unique<nfc::NfcTag>(uid, nfc::NFC_FORUM_TYPE_2);
|
||||
}
|
||||
|
||||
uint8_t message_length;
|
||||
uint8_t 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 make_unique<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) {
|
||||
return new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2);
|
||||
return make_unique<nfc::NfcTag>(uid, nfc::NFC_FORUM_TYPE_2);
|
||||
}
|
||||
std::vector<uint8_t> data;
|
||||
for (uint8_t page = nfc::MIFARE_ULTRALIGHT_DATA_START_PAGE; page < nfc::MIFARE_ULTRALIGHT_MAX_PAGE; page++) {
|
||||
std::vector<uint8_t> page_data;
|
||||
if (!this->read_mifare_ultralight_page_(page, page_data)) {
|
||||
ESP_LOGE(TAG, "Error reading page %d", page);
|
||||
return new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2);
|
||||
return make_unique<nfc::NfcTag>(uid, nfc::NFC_FORUM_TYPE_2);
|
||||
}
|
||||
data.insert(data.end(), page_data.begin(), page_data.end());
|
||||
|
||||
@@ -38,7 +38,7 @@ nfc::NfcTag *PN532::read_mifare_ultralight_tag_(std::vector<uint8_t> &uid) {
|
||||
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 make_unique<nfc::NfcTag>(uid, nfc::NFC_FORUM_TYPE_2, data);
|
||||
}
|
||||
|
||||
bool PN532::read_mifare_ultralight_page_(uint8_t page_num, std::vector<uint8_t> &data) {
|
||||
|
||||
Reference in New Issue
Block a user