mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Merge branch 'feat/nfc-type-4-final' into mntm-dev
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <bit_lib/bit_lib.h>
|
||||
#include "lfrfid_protocols.h"
|
||||
#include <furi_hal_rtc.h>
|
||||
#include <tools/iso_3166.h>
|
||||
|
||||
#define FDX_B_ENCODED_BIT_SIZE (128)
|
||||
#define FDX_B_ENCODED_BYTE_SIZE (((FDX_B_ENCODED_BIT_SIZE) / 8))
|
||||
@@ -287,15 +288,21 @@ void protocol_fdx_b_render_data(ProtocolFDXB* protocol, FuriString* result) {
|
||||
uint8_t user_info = bit_lib_get_bits(protocol->data, 55, 5);
|
||||
uint8_t replacement_number = bit_lib_get_bits(protocol->data, 60, 3);
|
||||
bool animal_flag = bit_lib_get_bit(protocol->data, 63);
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FuriString* country_full_name = furi_string_alloc();
|
||||
bool country_found = iso_3166_get_full_name(storage, country_code, country_full_name);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
furi_string_printf(
|
||||
result,
|
||||
"ID: %03hu-%012llu\n"
|
||||
"Country Code: %hu\n"
|
||||
"Country: %s\n"
|
||||
"Temperature: ",
|
||||
country_code,
|
||||
national_code,
|
||||
country_code);
|
||||
country_code,
|
||||
(country_found) ? furi_string_get_cstr(country_full_name) : "Unknown");
|
||||
|
||||
float temperature;
|
||||
if(protocol_fdx_b_get_temp(protocol->data, &temperature)) {
|
||||
@@ -320,6 +327,8 @@ void protocol_fdx_b_render_data(ProtocolFDXB* protocol, FuriString* result) {
|
||||
reserved,
|
||||
user_info,
|
||||
replacement_number);
|
||||
|
||||
furi_string_free(country_full_name);
|
||||
}
|
||||
|
||||
void protocol_fdx_b_render_brief_data(ProtocolFDXB* protocol, FuriString* result) {
|
||||
@@ -328,14 +337,18 @@ void protocol_fdx_b_render_brief_data(ProtocolFDXB* protocol, FuriString* result
|
||||
|
||||
// 10 bit of country code
|
||||
uint16_t country_code = protocol_fdx_b_get_country_code(protocol->data);
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FuriString* country_two_letter = furi_string_alloc();
|
||||
bool country_found = iso_3166_get_two_letter(storage, country_code, country_two_letter);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
furi_string_printf(
|
||||
result,
|
||||
"ID: %03hu-%012llu\n"
|
||||
"Country: %hu; Temp.: ",
|
||||
"Country: %hu %s; Temp.: ",
|
||||
country_code,
|
||||
national_code,
|
||||
country_code);
|
||||
country_code,
|
||||
(country_found) ? furi_string_get_cstr(country_two_letter) : "Unknown");
|
||||
|
||||
float temperature;
|
||||
if(protocol_fdx_b_get_temp(protocol->data, &temperature)) {
|
||||
@@ -348,6 +361,8 @@ void protocol_fdx_b_render_brief_data(ProtocolFDXB* protocol, FuriString* result
|
||||
} else {
|
||||
furi_string_cat(result, "---");
|
||||
}
|
||||
|
||||
furi_string_free(country_two_letter);
|
||||
}
|
||||
|
||||
bool protocol_fdx_b_write_data(ProtocolFDXB* protocol, void* data) {
|
||||
|
||||
98
lib/lfrfid/tools/iso_3166.c
Normal file
98
lib/lfrfid/tools/iso_3166.c
Normal file
@@ -0,0 +1,98 @@
|
||||
#include "iso_3166.h"
|
||||
|
||||
#include <flipper_format.h>
|
||||
|
||||
#define RESOURCE_FILE_PATH (EXT_PATH("lfrfid/assets/iso3166.lfrfid"))
|
||||
|
||||
static bool lfrfid_search_data(Storage* storage, uint16_t country_code, FuriString* out_line) {
|
||||
static const char* lfrfid_resources_header = "Flipper LFRFID resources";
|
||||
static const uint32_t lfrfid_resources_file_version = 1;
|
||||
|
||||
FuriString* key = furi_string_alloc_printf("%04d", country_code);
|
||||
bool found = false;
|
||||
furi_string_reset(out_line);
|
||||
FlipperFormat* file = flipper_format_file_alloc(storage);
|
||||
FuriString* temp_str = furi_string_alloc();
|
||||
|
||||
do {
|
||||
// Open file
|
||||
if(!flipper_format_file_open_existing(file, RESOURCE_FILE_PATH)) break;
|
||||
// Read file header and version
|
||||
uint32_t version = 0;
|
||||
if(!flipper_format_read_header(file, temp_str, &version)) break;
|
||||
if(furi_string_cmp_str(temp_str, lfrfid_resources_header) ||
|
||||
(version != lfrfid_resources_file_version))
|
||||
break;
|
||||
if(!flipper_format_read_string(file, furi_string_get_cstr(key), out_line)) break;
|
||||
found = true;
|
||||
} while(false);
|
||||
|
||||
furi_string_free(key);
|
||||
furi_string_free(temp_str);
|
||||
flipper_format_free(file);
|
||||
|
||||
if(found) {
|
||||
furi_string_replace_all(out_line, " ", "");
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
bool iso_3166_get_two_letter(Storage* storage, uint16_t country_code, FuriString* out_two_letter) {
|
||||
// We'll fetch the entire line from iso3166.lfrfid
|
||||
FuriString* line = furi_string_alloc();
|
||||
bool found = lfrfid_search_data(storage, country_code, line);
|
||||
|
||||
if(found) {
|
||||
if(furi_string_size(line) < 2) {
|
||||
furi_string_free(line);
|
||||
FURI_LOG_E("Lfrifd:Iso_3166", "Not enough data for two-letter code");
|
||||
return false; // Not enough data for a two-letter code
|
||||
}
|
||||
// AFAFGAfghanistan
|
||||
furi_string_left(line, 2); // AF
|
||||
furi_string_set(out_two_letter, line);
|
||||
}
|
||||
furi_string_free(line);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool iso_3166_get_three_letter(
|
||||
Storage* storage,
|
||||
uint16_t country_code,
|
||||
FuriString* out_three_letter) {
|
||||
FuriString* line = furi_string_alloc();
|
||||
bool found = lfrfid_search_data(storage, country_code, line);
|
||||
|
||||
if(found) {
|
||||
if(furi_string_size(line) < 5) {
|
||||
furi_string_free(line);
|
||||
FURI_LOG_E("Lfrifd:Iso_3166", "Not enough data for three-letter code");
|
||||
return false; // Not enough data for a three-letter code
|
||||
}
|
||||
// AFAFGAfghanistan
|
||||
furi_string_left(line, 5); // AFAFG
|
||||
furi_string_right(line, 2); // AFG
|
||||
furi_string_set(out_three_letter, line);
|
||||
}
|
||||
furi_string_free(line);
|
||||
return found;
|
||||
}
|
||||
|
||||
bool iso_3166_get_full_name(Storage* storage, uint16_t country_code, FuriString* out_full_name) {
|
||||
FuriString* line = furi_string_alloc();
|
||||
bool found = lfrfid_search_data(storage, country_code, line);
|
||||
|
||||
if(found) {
|
||||
if(furi_string_size(line) < 6) {
|
||||
furi_string_free(line);
|
||||
FURI_LOG_E("Lfrifd:Iso_3166", "Not enough data for full name");
|
||||
return false; // Not enough data for a full name
|
||||
}
|
||||
// AFAFGAfghanistan
|
||||
furi_string_right(line, 5); // Afghanistan
|
||||
furi_string_set(out_full_name, line);
|
||||
}
|
||||
furi_string_free(line);
|
||||
return found;
|
||||
}
|
||||
43
lib/lfrfid/tools/iso_3166.h
Normal file
43
lib/lfrfid/tools/iso_3166.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <storage/storage.h>
|
||||
#include <furi.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Look up a country's 2-letter code (ISO 3166-1 Alpha-2).
|
||||
*
|
||||
* @param storage Pointer to a valid Storage.
|
||||
* @param country_code Numeric ISO3166 code. e.g., 4 for Afghanistan.
|
||||
* @param out_two_letter A caller-allocated FuriString to fill with the 2-letter code, if found.
|
||||
*/
|
||||
bool iso_3166_get_two_letter(Storage* storage, uint16_t country_code, FuriString* out_two_letter);
|
||||
|
||||
/**
|
||||
* @brief Look up a country's 3-letter code (ISO 3166-1 Alpha-3).
|
||||
*
|
||||
* @param storage Pointer to a valid Storage.
|
||||
* @param country_code Numeric ISO3166 code.
|
||||
* @param out_three_letter A caller-allocated FuriString to fill with the 3-letter code, if found.
|
||||
*/
|
||||
bool iso_3166_get_three_letter(
|
||||
Storage* storage,
|
||||
uint16_t country_code,
|
||||
FuriString* out_three_letter);
|
||||
|
||||
/**
|
||||
* @brief Look up a country's full name.
|
||||
*
|
||||
* @param storage Pointer to a valid Storage.
|
||||
* @param country_code Numeric ISO3166 code.
|
||||
* @param out_full_name A caller-allocated FuriString to fill with the country's full name.
|
||||
*/
|
||||
bool iso_3166_get_full_name(Storage* storage, uint16_t country_code, FuriString* out_full_name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user