From 410fedbcd99abce6df44bd3aa93f58b1225d89d5 Mon Sep 17 00:00:00 2001 From: Andrea Micheloni <64315540+m7i-org@users.noreply.github.com> Date: Sun, 6 Oct 2024 08:48:26 +0200 Subject: [PATCH 1/4] fix(subghz): s/Latitute/Latitude/ --- applications/main/subghz/subghz_i.c | 4 ++-- lib/subghz/blocks/generic.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index e39b92ec7c..9e5a4b3e8a 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -156,9 +156,9 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { } } - //Load latitute and longitude if present, strict mode to avoid reading the whole file twice + //Load latitude and longitude if present, strict mode to avoid reading the whole file twice flipper_format_set_strict_mode(fff_data_file, true); - if(!flipper_format_read_float(fff_data_file, "Latitute", (float*)&temp_lat, 1) || + if(!flipper_format_read_float(fff_data_file, "Latitude", (float*)&temp_lat, 1) || !flipper_format_read_float(fff_data_file, "Longitude", (float*)&temp_lon, 1)) { FURI_LOG_W(TAG, "Missing Latitude and Longitude (optional)"); flipper_format_rewind(fff_data_file); diff --git a/lib/subghz/blocks/generic.c b/lib/subghz/blocks/generic.c index 6e64b9bc15..5c26b7cf8f 100644 --- a/lib/subghz/blocks/generic.c +++ b/lib/subghz/blocks/generic.c @@ -63,8 +63,8 @@ SubGhzProtocolStatus subghz_block_generic_serialize_common( break; } } - if(!flipper_format_write_float(flipper_format, "Latitute", &preset->latitude, 1)) { - FURI_LOG_E(TAG, "Unable to add Latitute"); + if(!flipper_format_write_float(flipper_format, "Latitude", &preset->latitude, 1)) { + FURI_LOG_E(TAG, "Unable to add Latitude"); res = SubGhzProtocolStatusErrorParserLatitude; break; } From f5624920dfde640217bde3bcd3fee63d07dc9be2 Mon Sep 17 00:00:00 2001 From: Andrea Micheloni <64315540+m7i-org@users.noreply.github.com> Date: Mon, 7 Oct 2024 09:16:31 -0400 Subject: [PATCH 2/4] feat(subghz): using Lat,Lon with fallback to older values --- applications/main/subghz/subghz_i.c | 22 +++++++++++++++++----- lib/subghz/blocks/generic.c | 8 ++++---- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index 9e5a4b3e8a..b306458f89 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -86,7 +86,9 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { SubGhzLoadKeyState load_key_state = SubGhzLoadKeyStateParseErr; FuriString* temp_str = furi_string_alloc(); uint32_t temp_data32; - float temp_lat = NAN; // NAN or 0.0?? because 0.0 is valid value + + //Using NAN in order to avoid the null island problem + float temp_lat = NAN; float temp_lon = NAN; SubGhzTx can_tx = SubGhzTxUnsupported; @@ -158,13 +160,23 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { //Load latitude and longitude if present, strict mode to avoid reading the whole file twice flipper_format_set_strict_mode(fff_data_file, true); - if(!flipper_format_read_float(fff_data_file, "Latitude", (float*)&temp_lat, 1) || - !flipper_format_read_float(fff_data_file, "Longitude", (float*)&temp_lon, 1)) { - FURI_LOG_W(TAG, "Missing Latitude and Longitude (optional)"); - flipper_format_rewind(fff_data_file); + if(!flipper_format_read_float(fff_data_file, "Lat", (float*)&temp_lat, 1) || + !flipper_format_read_float(fff_data_file, "Lon", (float*)&temp_lon, 1)) { + //Fallback to older keys "Latitute", "Longitude" + if(!flipper_format_read_float(fff_data_file, "Latitute", (float*)&temp_lat, 1) || + !flipper_format_read_float(fff_data_file, "Longitude", (float*)&temp_lon, 1)) { + FURI_LOG_W(TAG, "Missing Lat and Lon (optional)"); + flipper_format_rewind(fff_data_file); + } } flipper_format_set_strict_mode(fff_data_file, false); + //Avoid null island when reading + if(temp_lat == 0.0 && temp_lon == 0.0) { + temp_lat = NAN; + temp_lon = NAN; + } + size_t preset_index = subghz_setting_get_inx_preset_by_name(setting, furi_string_get_cstr(temp_str)); subghz_txrx_set_preset( diff --git a/lib/subghz/blocks/generic.c b/lib/subghz/blocks/generic.c index 5c26b7cf8f..dacb017724 100644 --- a/lib/subghz/blocks/generic.c +++ b/lib/subghz/blocks/generic.c @@ -63,13 +63,13 @@ SubGhzProtocolStatus subghz_block_generic_serialize_common( break; } } - if(!flipper_format_write_float(flipper_format, "Latitude", &preset->latitude, 1)) { - FURI_LOG_E(TAG, "Unable to add Latitude"); + if(!flipper_format_write_float(flipper_format, "Lat", &preset->latitude, 1)) { + FURI_LOG_E(TAG, "Unable to add Lat"); res = SubGhzProtocolStatusErrorParserLatitude; break; } - if(!flipper_format_write_float(flipper_format, "Longitude", &preset->longitude, 1)) { - FURI_LOG_E(TAG, "Unable to add Longitude"); + if(!flipper_format_write_float(flipper_format, "Lon", &preset->longitude, 1)) { + FURI_LOG_E(TAG, "Unable to add Lon"); res = SubGhzProtocolStatusErrorParserLongitude; break; } From be79c386e4c521fc39ef9c1a6817289a5c6110a2 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 8 Oct 2024 04:49:03 +0100 Subject: [PATCH 3/4] Some speedup and fix fallbacks --- applications/main/subghz/subghz_i.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index b306458f89..9b5e26bdf1 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -86,7 +86,6 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { SubGhzLoadKeyState load_key_state = SubGhzLoadKeyStateParseErr; FuriString* temp_str = furi_string_alloc(); uint32_t temp_data32; - //Using NAN in order to avoid the null island problem float temp_lat = NAN; float temp_lon = NAN; @@ -158,15 +157,20 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) { } } - //Load latitude and longitude if present, strict mode to avoid reading the whole file twice + //Load latitude and longitude if present + //Strict mode to fail if next key doesn't match, instead of reading whole file flipper_format_set_strict_mode(fff_data_file, true); + //Save position and seek instead of rewinding whole file when keys aren't found + Stream* fff_raw_stream = flipper_format_get_raw_stream(fff_data_file); + size_t pos_before_lat_lon = stream_tell(fff_raw_stream); if(!flipper_format_read_float(fff_data_file, "Lat", (float*)&temp_lat, 1) || !flipper_format_read_float(fff_data_file, "Lon", (float*)&temp_lon, 1)) { + stream_seek(fff_raw_stream, pos_before_lat_lon, StreamOffsetFromStart); //Fallback to older keys "Latitute", "Longitude" if(!flipper_format_read_float(fff_data_file, "Latitute", (float*)&temp_lat, 1) || !flipper_format_read_float(fff_data_file, "Longitude", (float*)&temp_lon, 1)) { FURI_LOG_W(TAG, "Missing Lat and Lon (optional)"); - flipper_format_rewind(fff_data_file); + stream_seek(fff_raw_stream, pos_before_lat_lon, StreamOffsetFromStart); } } flipper_format_set_strict_mode(fff_data_file, false); From bcb1a942d851530f644777e876c532125ac23d4c Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 8 Oct 2024 04:53:43 +0100 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e7272f606..e8cd712e69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -92,6 +92,7 @@ - OFW: GProxII Fix Writing and Rendering Conflict (by @zinongli) - Desktop: - Fallback Poweroff prompt when power settings is unavailable (by @Willy-JL) +- Sub-GHz: Fix GPS "Latitute" typo, switch to "Lat" and "Lon" in .sub files (#246 by @m7i-org) - Storage: - Fallback SD format prompt when storage settings is unavailable (by @Willy-JL) - OFW: Fix folder rename fails (by @portasynthinca3)