aboutsummaryrefslogtreecommitdiffstats
path: root/arguments.hpp
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2016-01-04 21:35:41 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2016-01-04 22:28:29 +0100
commitee098a9db6c2984fe91245422d93f16def55c851 (patch)
tree2e0480d32c882defacc04348ed73c1bdcc20bdbf /arguments.hpp
downloadgr-scan-20160104.tar.xz
gr-scan-20160104.zip
Initial import20160104
Diffstat (limited to 'arguments.hpp')
-rw-r--r--arguments.hpp220
1 files changed, 220 insertions, 0 deletions
diff --git a/arguments.hpp b/arguments.hpp
new file mode 100644
index 0000000..adc818e
--- /dev/null
+++ b/arguments.hpp
@@ -0,0 +1,220 @@
+/*
+ gr-scan - A GNU Radio signal scanner
+ Copyright (C) 2015 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
+ Copyright (C) 2012 Nicholas Tomlinson
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdlib.h>
+#include <argp.h>
+#include <string>
+
+class Arguments
+{
+public:
+ Arguments(int argc, char **argv) :
+ avg_size(1000),
+ bandwidth1(25000.0),
+ bandwidth2(-1.0),
+ spread(50000.0),
+ threshold(3.0),
+ centre_freq_1(87000000.0),
+ centre_freq_2(108000000.0),
+ sample_rate(2000000.0),
+ fft_width(1000.0),
+ step(-1.0),
+ ptime(1.0)
+ {
+ argp_parse (&argp_i, argc, argv, 0, 0, this);
+ }
+
+ unsigned int get_avg_size()
+ {
+ return avg_size;
+ }
+
+ double get_bandwidth1()
+ {
+ return bandwidth1;
+ }
+
+ double get_bandwidth2()
+ {
+ if (bandwidth2 < 0.0)/* User did not specify a coarse band */
+ return bandwidth1 * 8.0; /* I've found this to be a good choice for the coarse band */
+ else
+ return bandwidth2; /* If the user specified a bandwidth for this, use it */
+ }
+
+ double get_spread()
+ {
+ return spread;
+ }
+
+ double get_threshold()
+ {
+ return threshold;
+ }
+
+ double get_centre_freq_1()
+ {
+ return centre_freq_1;
+ }
+
+ double get_centre_freq_2()
+ {
+ return centre_freq_2;
+ }
+
+ double get_sample_rate()
+ {
+ return sample_rate;
+ }
+
+ double get_fft_width()
+ {
+ return fft_width;
+ }
+
+ double get_step()
+ {
+ if (step < 0.0)
+ return sample_rate / 4.0; // I've found this to be a good choice (slightly faster might be / 3.0)
+ else
+ return step;
+ }
+
+ double get_time()
+ {
+ return ptime;
+ }
+
+ std::string get_outcsv()
+ {
+ return outcsv;
+ }
+
+private:
+ static error_t s_parse_opt(int key, char *arg, struct argp_state *state)
+ {
+ Arguments *arguments = static_cast<Arguments *>(state->input);
+ return arguments->parse_opt(key, arg, state);
+ }
+
+ error_t parse_opt(int key, char *arg, struct argp_state *state)
+ {
+ switch (key)
+ {
+ case 'a':
+ avg_size = atoi(arg);
+ break;
+ case 'f':
+ bandwidth1 = atof(arg) * 1000.0; //kHz
+ break;
+ case 'c':
+ bandwidth2 = atof(arg) * 1000.0; //kHz
+ break;
+ case 's':
+ spread = atof(arg) * 1000.0; //kHz
+ break;
+ case 't':
+ threshold = atof(arg);
+ break;
+ case 'x':
+ centre_freq_1 = atof(arg) * 1000000.0; //MHz
+ break;
+ case 'y':
+ centre_freq_2 = atof(arg) * 1000000.0; //MHz
+ break;
+ case 'r':
+ sample_rate = atof(arg) * 1000000.0; //MSamples/s
+ break;
+ case 'w':
+ fft_width = atoi(arg);
+ break;
+ case 'z':
+ step = atof(arg) * 1000000.0; //MHz
+ break;
+ case 'p':
+ ptime = atof(arg);
+ break;
+ case 'o':
+ outcsv = std::string(arg);
+ break;
+ case ARGP_KEY_ARG:
+ if (state->arg_num > 0)
+ argp_usage(state);
+ break;
+ case ARGP_KEY_END:
+ break;
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+ return 0;
+ }
+
+ static argp_option options[];
+ static argp argp_i;
+
+ unsigned int avg_size;
+ double bandwidth1;
+ double bandwidth2;
+ double spread;
+ double threshold;
+ double centre_freq_1;
+ double centre_freq_2;
+ double sample_rate;
+ double fft_width;
+ double step;
+ double ptime;
+ std::string outcsv;
+};
+
+argp_option Arguments::options[] = {
+ {"average", 'a', "COUNT", 0, "Average over COUNT samples (default: 1000)"},
+ {"fine-bandwidth", 'f', "FREQ", 0, "Bandwidth of the fine window in kHz (default: 25)"},
+ {"coarse-bandwidth", 'c', "FREQ", 0, "Bandwidth of the coarse window in kHz (default: fine-bandwidth * 8)"},
+ {"spread", 's', "FREQ", 0, "Minimum frequency between detected signals in kHz (default: 50)"},
+ {"threshold", 't', "POWER", 0, "Threshold for the difference between the coarse and fine filtered signals in dB (default: 3)"},
+ {"start-frequency", 'x', "FREQ", 0, "Start frequency in MHz (default: 87)"},
+ {"end-frequency", 'y', "FREQ", 0, "End frequency in MHz (default: 108)"},
+ {"sample-rate", 'r', "RATE", 0, "Samplerate in Msamples/s (default: 2)"},
+ {"fft-width", 'w', "COUNT", 0, "Width of FFT in samples (default: 1000)"},
+ {"step", 'z', "FREQ", 0, "Increment step in MHz (default: sample_rate / 4)"},
+ {"time", 'p', "TIME", 0, "Time in seconds to scan on each frequency (default: 1)"},
+ {"output-csv", 'o', "OUTCSV", 0, "Output results to CSV file (default: [none])"},
+ {0}
+};
+
+argp Arguments::argp_i = {options, s_parse_opt, 0, 0};
+
+const char *argp_program_bug_address = "Jason@zx2c4.com";
+const char *argp_program_version =
+ "gr-scan " VERSION " - A GNU Radio signal scanner\n"
+ "Copyright (C) 2015 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.\n"
+ "Copyright (C) 2012 Nicholas Tomlinson\n"
+ "\n"
+ "This program is free software: you can redistribute it and/or modify\n"
+ "it under the terms of the GNU General Public License as published by\n"
+ "the Free Software Foundation, either version 3 of the License, or\n"
+ "(at your option) any later version.\n"
+ "\n"
+ "This program is distributed in the hope that it will be useful,\n"
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
+ "GNU General Public License for more details.\n"
+ "\n"
+ "You should have received a copy of the GNU General Public License\n"
+ "along with this program. If not, see <http://www.gnu.org/licenses/>.";