[FL-1904] LFRFID: dedicated reading modes (#823)

* LFRFID: dedicated reading modes
* LFRFID: normal and indala mode
This commit is contained in:
SG 2021-11-16 18:47:49 +10:00 committed by GitHub
parent b3d8f0b950
commit 4cb986b534
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 10 deletions

View file

@ -102,7 +102,7 @@ void RfidReader::stop() {
stop_comparator();
}
bool RfidReader::read(LfrfidKeyType* _type, uint8_t* data, uint8_t data_size) {
bool RfidReader::read(LfrfidKeyType* _type, uint8_t* data, uint8_t data_size, bool switch_enable) {
bool result = false;
bool something_readed = false;
@ -140,7 +140,7 @@ bool RfidReader::read(LfrfidKeyType* _type, uint8_t* data, uint8_t data_size) {
}
// mode switching
if(switch_timer_elapsed()) {
if(switch_enable && switch_timer_elapsed()) {
switch_mode();
last_readed_count = 0;
}

View file

@ -19,7 +19,7 @@ public:
void start();
void start_forced(RfidReader::Type type);
void stop();
bool read(LfrfidKeyType* type, uint8_t* data, uint8_t data_size);
bool read(LfrfidKeyType* type, uint8_t* data, uint8_t data_size, bool switch_enable = true);
bool detect();
bool any_read();

View file

@ -18,7 +18,7 @@ extern "C" void lfrfid_cli_init() {
void lfrfid_cli_print_usage() {
printf("Usage:\r\n");
printf("rfid read\r\n");
printf("rfid read <optional: normal | indala>\r\n");
printf("rfid <write | emulate> <key_type> <key_data>\r\n");
printf("\t<key_type> choose from:\r\n");
printf("\tEM4100, EM-Marin (5 bytes key_data)\r\n");
@ -44,17 +44,39 @@ bool lfrfid_cli_get_key_type(string_t data, LfrfidKeyType* type) {
return result;
}
void lfrfid_cli_read(Cli* cli) {
void lfrfid_cli_read(Cli* cli, string_t args) {
RfidReader reader;
reader.start();
string_t type_string;
string_init(type_string);
bool simple_mode = true;
LfrfidKeyType type;
RfidReader::Type reader_type = RfidReader::Type::Normal;
static const uint8_t data_size = LFRFID_KEY_SIZE;
uint8_t data[data_size] = {0};
LfrfidKeyType type;
if(args_read_string_and_trim(args, type_string)) {
simple_mode = false;
if(string_cmp_str(type_string, "normal") == 0) {
reader_type = RfidReader::Type::Normal;
} else if(string_cmp_str(type_string, "indala") == 0) {
reader_type = RfidReader::Type::Indala;
} else {
lfrfid_cli_print_usage();
string_clear(type_string);
return;
}
}
if(simple_mode) {
reader.start();
} else {
reader.start_forced(reader_type);
}
printf("Reading RFID...\r\nPress Ctrl+C to abort\r\n");
while(!cli_cmd_interrupt_received(cli)) {
if(reader.read(&type, data, data_size)) {
if(reader.read(&type, data, data_size, simple_mode)) {
printf("%s", lfrfid_key_get_type_string(type));
printf(" ");
@ -69,6 +91,8 @@ void lfrfid_cli_read(Cli* cli) {
printf("Reading stopped\r\n");
reader.stop();
string_clear(type_string);
}
void lfrfid_cli_write(Cli* cli, string_t args) {
@ -129,7 +153,7 @@ void lfrfid_cli(Cli* cli, string_t args, void* context) {
}
if(string_cmp_str(cmd, "read") == 0) {
lfrfid_cli_read(cli);
lfrfid_cli_read(cli, args);
} else if(string_cmp_str(cmd, "write") == 0) {
lfrfid_cli_write(cli, args);
} else if(string_cmp_str(cmd, "emulate") == 0) {