From 67a457dd1fabbeb0312e6336f20c88217b90a76c Mon Sep 17 00:00:00 2001 From: Nikita Vostokov Date: Fri, 21 Apr 2023 04:10:32 +0300 Subject: [PATCH] SubGhz - Add date of signal to *.sub files header --- applications/external/protoview/signal_file.c | 16 +++++++++++++++ lib/subghz/blocks/generic.c | 20 +++++++++++++++++++ lib/subghz/protocols/bin_raw.c | 19 ++++++++++++++++++ lib/subghz/protocols/raw.c | 13 ++++++++++++ 4 files changed, 68 insertions(+) diff --git a/applications/external/protoview/signal_file.c b/applications/external/protoview/signal_file.c index c60a6a181..c16423f69 100644 --- a/applications/external/protoview/signal_file.c +++ b/applications/external/protoview/signal_file.c @@ -28,12 +28,28 @@ bool save_signal(ProtoViewApp* app, const char* filename) { FuriString* file_content = furi_string_alloc(); const char* preset_id = ProtoViewModulations[app->modulation].id; + char str_date[30]; + FuriHalRtcDateTime now; + furi_hal_rtc_get_datetime(&now); + snprintf( + str_date, + sizeof(str_date), + "%.4d/%.2d/%.2d %.2d:%.2d:%.2d", + now.year, + now.month, + now.day, + now.hour, + now.minute, + now.second); + furi_string_printf( file_content, "Filetype: Flipper SubGhz RAW File\n" "Version: 1\n" + "Date: %s\n" "Frequency: %ld\n" "Preset: %s\n", + str_date, app->frequency, preset_id ? preset_id : "FuriHalSubGhzPresetCustom"); diff --git a/lib/subghz/blocks/generic.c b/lib/subghz/blocks/generic.c index 1827388af..696a97e04 100644 --- a/lib/subghz/blocks/generic.c +++ b/lib/subghz/blocks/generic.c @@ -37,6 +37,25 @@ SubGhzProtocolStatus subghz_block_generic_serialize( break; } + FuriHalRtcDateTime now; + furi_hal_rtc_get_datetime(&now); + // Format should be locale independent for transfer across devices with different locales + furi_string_printf( + temp_str, + "%.4d/%.2d/%.2d %.2d:%.2d:%.2d", + now.year, + now.month, + now.day, + now.hour, + now.minute, + now.second); + if(!flipper_format_write_string_cstr( + flipper_format, "Date", furi_string_get_cstr(temp_str))) { + FURI_LOG_E(TAG, "Unable to add Date"); + res = SubGhzProtocolStatusError; + break; + } + if(!flipper_format_write_uint32(flipper_format, "Frequency", &preset->frequency, 1)) { FURI_LOG_E(TAG, "Unable to add Frequency"); res = SubGhzProtocolStatusErrorParserFrequency; @@ -93,6 +112,7 @@ SubGhzProtocolStatus subghz_block_generic_serialize( uint32_t temp = (instance->data_2 >> 4) & 0xFFFFF; if(!flipper_format_write_uint32(flipper_format, "Data", &temp, 1)) { FURI_LOG_E(TAG, "Unable to add Data"); + res = SubGhzProtocolStatusError; break; } } diff --git a/lib/subghz/protocols/bin_raw.c b/lib/subghz/protocols/bin_raw.c index 003cc5edd..702bb8fd7 100644 --- a/lib/subghz/protocols/bin_raw.c +++ b/lib/subghz/protocols/bin_raw.c @@ -987,6 +987,25 @@ SubGhzProtocolStatus subghz_protocol_decoder_bin_raw_serialize( break; } + FuriHalRtcDateTime now; + furi_hal_rtc_get_datetime(&now); + // Format should be locale independent for transfer across devices with different locales + furi_string_printf( + temp_str, + "%.4d/%.2d/%.2d %.2d:%.2d:%.2d", + now.year, + now.month, + now.day, + now.hour, + now.minute, + now.second); + if(!flipper_format_write_string_cstr( + flipper_format, "Date", furi_string_get_cstr(temp_str))) { + FURI_LOG_E(TAG, "Unable to add Date"); + res = SubGhzProtocolStatusError; + break; + } + if(!flipper_format_write_uint32(flipper_format, "Frequency", &preset->frequency, 1)) { FURI_LOG_E(TAG, "Unable to add Frequency"); res = SubGhzProtocolStatusErrorParserFrequency; diff --git a/lib/subghz/protocols/raw.c b/lib/subghz/protocols/raw.c index a82c9cf83..bbd777aa5 100644 --- a/lib/subghz/protocols/raw.c +++ b/lib/subghz/protocols/raw.c @@ -126,6 +126,19 @@ bool subghz_protocol_raw_save_to_file_init( break; } + FuriHalRtcDateTime now; + furi_hal_rtc_get_datetime(&now); + // Format should be locale independent for transfer across devices with different locales + furi_string_printf( + temp_str, + "%.4d/%.2d/%.2d %.2d:%.2d:%.2d", + now.year, + now.month, + now.day, + now.hour, + now.minute, + now.second); + if(!flipper_format_write_uint32( instance->flipper_file, "Frequency", &preset->frequency, 1)) { FURI_LOG_E(TAG, "Unable to add Frequency");