-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rffft] Add -P option to parse params from SatDump and GQRX filenames
Signed-off-by: Martin Herren (HB9FXX) <[email protected]>
- Loading branch information
1 parent
96d4ac3
commit 2aaaa6e
Showing
10 changed files
with
311 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
#include "rffft_internal.h" | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <libgen.h> | ||
|
||
|
||
// Filename formats: | ||
// - SatDump | ||
// - 2023-08-05_08-02-00_16000000SPS_2274000000Hz.s8 | ||
// - 2023-08-05_18-02-45-534_16000000SPS_2284000000Hz.s16 | ||
// - 2023-08-05_18-02-45-1691258565.534000_16000000SPS_2284000000Hz.f32 | ||
// s8: char, s16 short int, f32 float. | ||
// SatDump also supports .wav and compressed versions of s8/s16/f32 with .ziq | ||
// extension. Those are not yet supported | ||
// timestamp can have an added milliseconds field, configurable. This feature | ||
// was broken during some time so files with this convention still exists. | ||
// - GQRX: | ||
// - gqrx_20230806_151838_428000000_200000_fc.raw | ||
// format always float32 | ||
int rffft_params_from_filename(char * filename, double * samplerate, double * frequency, char * format, char * starttime) { | ||
// Temp vars to hold parsed values | ||
int p_year, p_month, p_day, p_hours, p_minutes, p_seconds, p_fractal_seconds; | ||
int p_dummy_int; | ||
double p_samplerate, p_frequency; | ||
char p_format[16]; | ||
char p_dummy_string[128]; | ||
int parsed_tokens; | ||
|
||
char * base_filename = basename(filename); | ||
|
||
// Broken SatDump string with milliseconds activated | ||
parsed_tokens = sscanf( | ||
base_filename, | ||
"%04d-%02d-%02d_%02d-%02d-%02d-%d.%06d_%lfSPS_%lfHz.%s", | ||
&p_year, | ||
&p_month, | ||
&p_day, | ||
&p_hours, | ||
&p_minutes, | ||
&p_seconds, | ||
&p_dummy_int, | ||
&p_fractal_seconds, | ||
&p_samplerate, | ||
&p_frequency, | ||
p_format); | ||
|
||
if (parsed_tokens == 11) { | ||
*samplerate = p_samplerate; | ||
*frequency = p_frequency; | ||
|
||
if ((strlen(p_format) == 2) && (strncmp("s8", p_format, 2) == 0)) { | ||
*format = 'c'; | ||
} else if ((strlen(p_format) == 3) && (strncmp("s16", p_format, 3) == 0)) { | ||
*format = 'i'; | ||
} else if ((strlen(p_format) == 3) && (strncmp("f32", p_format, 3) == 0)) { | ||
*format = 'f'; | ||
} else { | ||
printf("Unsupported SatDump format %s\n", p_format); | ||
return -1; | ||
} | ||
|
||
snprintf(starttime, 32, "%04d-%02d-%02dT%02d:%02d:%02d.%03d", p_year, p_month, p_day, p_hours, p_minutes, p_seconds, p_fractal_seconds / 1000); | ||
|
||
return 0; | ||
} | ||
|
||
// SatDump string with milliseconds activated | ||
parsed_tokens = sscanf( | ||
base_filename, | ||
"%04d-%02d-%02d_%02d-%02d-%02d-%03d_%lfSPS_%lfHz.%s", | ||
&p_year, | ||
&p_month, | ||
&p_day, | ||
&p_hours, | ||
&p_minutes, | ||
&p_seconds, | ||
&p_fractal_seconds, | ||
&p_samplerate, | ||
&p_frequency, | ||
p_format); | ||
|
||
if (parsed_tokens == 10) { | ||
*samplerate = p_samplerate; | ||
*frequency = p_frequency; | ||
|
||
if ((strlen(p_format) == 2) && (strncmp("s8", p_format, 2) == 0)) { | ||
*format = 'c'; | ||
} else if ((strlen(p_format) == 3) && (strncmp("s16", p_format, 3) == 0)) { | ||
*format = 'i'; | ||
} else if ((strlen(p_format) == 3) && (strncmp("f32", p_format, 3) == 0)) { | ||
*format = 'f'; | ||
} else { | ||
printf("Unsupported SatDump format %s\n", p_format); | ||
return -1; | ||
} | ||
|
||
snprintf(starttime, 32, "%04d-%02d-%02dT%02d:%02d:%02d.%03d", p_year, p_month, p_day, p_hours, p_minutes, p_seconds, p_fractal_seconds); | ||
|
||
return 0; | ||
} | ||
|
||
// SatDump string without milliseconds activated | ||
parsed_tokens = sscanf( | ||
base_filename, | ||
"%04d-%02d-%02d_%02d-%02d-%02d_%lfSPS_%lfHz.%s", | ||
&p_year, | ||
&p_month, | ||
&p_day, | ||
&p_hours, | ||
&p_minutes, | ||
&p_seconds, | ||
&p_samplerate, | ||
&p_frequency, | ||
p_format); | ||
|
||
if (parsed_tokens == 9) { | ||
*samplerate = p_samplerate; | ||
*frequency = p_frequency; | ||
|
||
if ((strlen(p_format) == 2) && (strncmp("s8", p_format, 2) == 0)) { | ||
*format = 'c'; | ||
} else if ((strlen(p_format) == 3) && (strncmp("s16", p_format, 3) == 0)) { | ||
*format = 'i'; | ||
} else if ((strlen(p_format) == 3) && (strncmp("f32", p_format, 3) == 0)) { | ||
*format = 'f'; | ||
} else { | ||
printf("Unsupported SatDump format %s\n", p_format); | ||
return -1; | ||
} | ||
|
||
snprintf(starttime, 32, "%04d-%02d-%02dT%02d:%02d:%02d", p_year, p_month, p_day, p_hours, p_minutes, p_seconds); | ||
|
||
return 0; | ||
} | ||
|
||
// GQRX | ||
parsed_tokens = sscanf( | ||
base_filename, | ||
"gqrx_%04d%02d%02d_%02d%02d%02d_%lf_%lf_%s.raw", | ||
&p_year, | ||
&p_month, | ||
&p_day, | ||
&p_hours, | ||
&p_minutes, | ||
&p_seconds, | ||
&p_frequency, | ||
&p_samplerate, | ||
p_dummy_string); | ||
|
||
if (parsed_tokens == 9) { | ||
*samplerate = p_samplerate; | ||
*frequency = p_frequency; | ||
*format = 'f'; | ||
|
||
snprintf(starttime, 32, "%04d-%02d-%02dT%02d:%02d:%02d", p_year, p_month, p_day, p_hours, p_minutes, p_seconds); | ||
|
||
return 0; | ||
} | ||
|
||
return -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef _RFFFT_INTERNAL_H | ||
#define _RFFFT_INTERNAL_H | ||
|
||
#include "sgdp4h.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
// input: | ||
// filename: filename string to parse | ||
// output: | ||
// samplerate: parsed samplerate | ||
// frequency: parsed frequency | ||
// format: parsed sample format: char: 'c', int: 'i', float: 'f' | ||
// starttime: parsed start time string formatted YYYY-MM-DDTHH:MM:SS.sss | ||
int rffft_params_from_filename(char * filename, double * samplerate, double * frequency, char * format, char * starttime); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* _RFFFT_INTERNAL_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include "tests_rffft_internal.h" | ||
|
||
#include <stdarg.h> | ||
#include <stddef.h> | ||
#include <setjmp.h> | ||
#include <stdlib.h> | ||
#include <cmocka.h> | ||
|
||
#include "../rffft_internal.h" | ||
|
||
// Tests | ||
|
||
// Test SatDump filenames | ||
void rffft_internal_parse_satdump_filenames(void **state) { | ||
double samplerate = 0; | ||
double frequency = 0; | ||
char format = '\0'; | ||
char starttime[] = "YYYY-mm-ddTHH:MM:SS.sss"; | ||
char ref_format = '\0'; | ||
|
||
// s8 file without milliseconds | ||
ref_format = 'c'; | ||
assert_int_equal(0, rffft_params_from_filename("2023-08-05_08-02-00_16000000SPS_2274000000Hz.s8", &samplerate, &frequency, &format, starttime)); | ||
// assert_double_equal has been introduced in cmocka 1.1.6 not available on most distribs yet | ||
assert_float_equal(16e6, samplerate, 1e-12); | ||
assert_float_equal(2.274e9, frequency, 1e-12); | ||
assert_memory_equal(&ref_format, &format, 1); | ||
assert_string_equal("2023-08-05T08:02:00", starttime); | ||
|
||
// f32 file with milliseconds | ||
ref_format = 'f'; | ||
assert_int_equal(0, rffft_params_from_filename("2023-08-17_11-41-14-373_1000000SPS_100000000Hz.f32", &samplerate, &frequency, &format, starttime)); | ||
assert_float_equal(1e6, samplerate, 1e-12); | ||
assert_float_equal(100e6, frequency, 1e-12); | ||
assert_memory_equal(&ref_format, &format, 1); | ||
assert_string_equal("2023-08-17T11:41:14.373", starttime); | ||
|
||
// s16 file with broken milliseconds format | ||
ref_format = 'i'; | ||
assert_int_equal(0, rffft_params_from_filename("2023-08-05_18-02-45-1691258565.534000_8000000SPS_2284000000Hz.s16", &samplerate, &frequency, &format, starttime)); | ||
assert_float_equal(8e6, samplerate, 1e-12); | ||
assert_float_equal(2.284e9, frequency, 1e-12); | ||
assert_memory_equal(&ref_format, &format, 1); | ||
assert_string_equal("2023-08-05T18:02:45.534", starttime); | ||
|
||
assert_int_equal(-1, rffft_params_from_filename("2023-08-05-19:59:30_16000000SPS_402000000Hz.f32", &samplerate, &frequency, &format, starttime)); | ||
} | ||
|
||
// Test GQRX filenames | ||
void rffft_internal_parse_gqrx_filenames(void **state) { | ||
double samplerate = 0; | ||
double frequency = 0; | ||
char format = '\0'; | ||
char starttime[] = "YYYY-mm-ddTHH:MM:SS.sss"; | ||
char ref_format = '\0'; | ||
|
||
ref_format = 'f'; | ||
assert_int_equal(0, rffft_params_from_filename("gqrx_20230806_151838_428000000_200000_fc.raw", &samplerate, &frequency, &format, starttime)); | ||
// assert_double_equal has been introduced in cmocka 1.1.6 not available on most distribs yet | ||
assert_float_equal(200e3, samplerate, 1e-12); | ||
assert_float_equal(428e6, frequency, 1e-12); | ||
assert_memory_equal(&ref_format, &format, 1); | ||
assert_string_equal("2023-08-06T15:18:38", starttime); | ||
|
||
assert_int_equal(-1, rffft_params_from_filename("gqrx_2023-08-06_15:18:38_428000000_200000_fc.raw", &samplerate, &frequency, &format, starttime)); | ||
} | ||
|
||
// Entry point to run all tests | ||
int run_rffft_internal_tests() { | ||
const struct CMUnitTest tests[] = { | ||
cmocka_unit_test(rffft_internal_parse_satdump_filenames), | ||
cmocka_unit_test(rffft_internal_parse_gqrx_filenames), | ||
}; | ||
|
||
return cmocka_run_group_tests_name("rffft internal", tests, NULL, NULL); | ||
} |
Oops, something went wrong.