Skip to content

Commit

Permalink
Sub-GHz: Fix GPS "Latitute" typo, switch to "Lat" and "Lon" in .sub f…
Browse files Browse the repository at this point in the history
…iles (#246)

* fix(subghz): s/Latitute/Latitude/

* feat(subghz): using Lat,Lon with fallback to older values

* Some speedup and fix fallbacks

* Update changelog

---------

Co-authored-by: Willy-JL <49810075+Willy-JL@users.noreply.github.com>
  • Loading branch information
m7i-org and Willy-JL authored Oct 8, 2024
1 parent ff87fbe commit ae70945
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 22 additions & 6 deletions applications/main/subghz/subghz_i.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ 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;

Expand Down Expand Up @@ -156,15 +157,30 @@ 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 fail if next key doesn't match, instead of reading whole file
flipper_format_set_strict_mode(fff_data_file, true);
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 Latitude and Longitude (optional)");
flipper_format_rewind(fff_data_file);
//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)");
stream_seek(fff_raw_stream, pos_before_lat_lon, StreamOffsetFromStart);
}
}
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(
Expand Down
8 changes: 4 additions & 4 deletions lib/subghz/blocks/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ 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, "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;
}
Expand Down

0 comments on commit ae70945

Please sign in to comment.