[FL-1371] New LF-RFID app. Second encounter. (#547)
* File worker: file operations helper. * Notification app: removed yield * File worker: write operations, calls to system file widgets * App ibutton: use file worker * Lfrfid: generic key loading, add path helper and hex conversion to lib * FileWorker: plain C verison * FileWorker: add to lib.mk * FileWorker: add to C sources, instead of CPP * Lfrfid: save scene * App lfrfid: add key scene, saved key menu * App lfrfid: saved key info scene * App lfrfid: delete key scene
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "key-info.h"
|
||||
#include <string.h>
|
||||
|
||||
const char* lfrfid_key_get_type_string(LfrfidKeyType type) {
|
||||
switch(type) {
|
||||
@@ -16,6 +17,22 @@ const char* lfrfid_key_get_type_string(LfrfidKeyType type) {
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
bool lfrfid_key_get_string_type(const char* string, LfrfidKeyType* type) {
|
||||
bool result = true;
|
||||
|
||||
if(strcmp("EM4100", string) == 0) {
|
||||
*type = LfrfidKeyType::KeyEM4100;
|
||||
} else if(strcmp("H10301", string) == 0) {
|
||||
*type = LfrfidKeyType::KeyH10301;
|
||||
} else if(strcmp("I40134", string) == 0) {
|
||||
*type = LfrfidKeyType::KeyI40134;
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint8_t lfrfid_key_get_type_data_count(LfrfidKeyType type) {
|
||||
switch(type) {
|
||||
case LfrfidKeyType::KeyEM4100:
|
||||
|
@@ -11,4 +11,5 @@ enum class LfrfidKeyType : uint8_t {
|
||||
};
|
||||
|
||||
const char* lfrfid_key_get_type_string(LfrfidKeyType type);
|
||||
bool lfrfid_key_get_string_type(const char* string, LfrfidKeyType* type);
|
||||
uint8_t lfrfid_key_get_type_data_count(LfrfidKeyType type);
|
@@ -1,12 +1,9 @@
|
||||
#include "rfid-key.h"
|
||||
#include <furi/check.h>
|
||||
#include <string.h>
|
||||
|
||||
RfidKey::RfidKey() {
|
||||
data.fill(0);
|
||||
|
||||
for(uint8_t i = 0; i < (LFRFID_KEY_NAME_SIZE + 1); i++) {
|
||||
name[i] = 0;
|
||||
}
|
||||
clear();
|
||||
}
|
||||
|
||||
RfidKey::~RfidKey() {
|
||||
@@ -16,18 +13,22 @@ void RfidKey::set_type(LfrfidKeyType _type) {
|
||||
type = _type;
|
||||
}
|
||||
|
||||
void RfidKey::set_data(uint8_t* _data, const uint8_t _data_size) {
|
||||
void RfidKey::set_data(const uint8_t* _data, const uint8_t _data_size) {
|
||||
furi_assert(_data_size <= data.size());
|
||||
for(uint8_t i = 0; i < _data_size; i++) {
|
||||
data[i] = _data[i];
|
||||
}
|
||||
}
|
||||
|
||||
void RfidKey::set_name(const char* _name) {
|
||||
strlcpy(name, _name, get_name_length());
|
||||
}
|
||||
|
||||
LfrfidKeyType RfidKey::get_type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
uint8_t* RfidKey::get_data() {
|
||||
const uint8_t* RfidKey::get_data() {
|
||||
return &data[0];
|
||||
}
|
||||
|
||||
@@ -42,3 +43,23 @@ const uint8_t RfidKey::get_type_data_count() {
|
||||
char* RfidKey::get_name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
uint8_t RfidKey::get_name_length() {
|
||||
return LFRFID_KEY_NAME_SIZE;
|
||||
}
|
||||
|
||||
void RfidKey::clear() {
|
||||
set_name("");
|
||||
set_type(LfrfidKeyType::KeyEM4100);
|
||||
data.fill(0);
|
||||
}
|
||||
|
||||
RfidKey& RfidKey::operator=(const RfidKey& rhs) {
|
||||
if(this == &rhs) return *this;
|
||||
|
||||
set_type(rhs.type);
|
||||
set_name(rhs.name);
|
||||
set_data(&rhs.data[0], get_type_data_count());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
@@ -8,15 +8,17 @@ public:
|
||||
~RfidKey();
|
||||
|
||||
void set_type(LfrfidKeyType type);
|
||||
void set_data(uint8_t* data, const uint8_t data_size);
|
||||
void set_data(const uint8_t* data, const uint8_t data_size);
|
||||
void set_name(const char* name);
|
||||
|
||||
LfrfidKeyType get_type();
|
||||
uint8_t* get_data();
|
||||
|
||||
const uint8_t* get_data();
|
||||
const char* get_type_text();
|
||||
const uint8_t get_type_data_count();
|
||||
|
||||
char* get_name();
|
||||
uint8_t get_name_length();
|
||||
void clear();
|
||||
RfidKey& operator=(const RfidKey& rhs);
|
||||
|
||||
private:
|
||||
std::array<uint8_t, LFRFID_KEY_SIZE> data;
|
||||
|
@@ -111,7 +111,7 @@ void RfidWriter::write_reset() {
|
||||
write_bit(0);
|
||||
}
|
||||
|
||||
void RfidWriter::write_em(uint8_t em_data[5]) {
|
||||
void RfidWriter::write_em(const uint8_t em_data[5]) {
|
||||
ProtocolEMMarin em_card;
|
||||
uint64_t em_encoded_data;
|
||||
em_card.encode(em_data, 5, reinterpret_cast<uint8_t*>(&em_encoded_data), sizeof(uint64_t));
|
||||
@@ -125,7 +125,7 @@ void RfidWriter::write_em(uint8_t em_data[5]) {
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
void RfidWriter::write_hid(uint8_t hid_data[3]) {
|
||||
void RfidWriter::write_hid(const uint8_t hid_data[3]) {
|
||||
ProtocolHID10301 hid_card;
|
||||
uint32_t card_data[3];
|
||||
hid_card.encode(hid_data, 3, reinterpret_cast<uint8_t*>(&card_data), sizeof(card_data) * 3);
|
||||
|
@@ -7,8 +7,8 @@ public:
|
||||
~RfidWriter();
|
||||
void start();
|
||||
void stop();
|
||||
void write_em(uint8_t em_data[5]);
|
||||
void write_hid(uint8_t hid_data[3]);
|
||||
void write_em(const uint8_t em_data[5]);
|
||||
void write_hid(const uint8_t hid_data[3]);
|
||||
|
||||
private:
|
||||
void write_gap(uint32_t gap_time);
|
||||
|
Reference in New Issue
Block a user