diff --git a/.gitmodules b/.gitmodules index c96040c..9ca3e48 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,7 @@ [submodule "third-party/c-flags"] path = third-party/c-flags url = https://github.com/DieTime/c-flags.git +[submodule "third-party/cxxopts"] + path = third-party/cxxopts + url = https://github.com/jarro2783/cxxopts.git + branch = v3.2.1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 10e2a29..74aae13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,11 @@ project(pico-radio) set(CMAKE_EXPORT_COMPILE_COMMANDS true) -include_directories(include /opt/picoscope/include third-party/c-flags/single-header) +include_directories(include + /opt/picoscope/include + third-party/c-flags/single-header + third-party/cxxopts/include) + link_directories(/opt/picoscope/lib) add_subdirectory(src/recorder) diff --git a/src/filter/main.cpp b/src/filter/main.cpp index bd50f55..e5e5bfa 100644 --- a/src/filter/main.cpp +++ b/src/filter/main.cpp @@ -6,15 +6,30 @@ #include #include -#include +#include const std::size_t BUFFER_SIZE = 256; using namespace Filter; int main(int argc, char** argv) { - (void)argc; - (void)argv; + // parse arguments + cxxopts::Options options("filter", "filter signals; stdin->stdout"); + options.add_options()("c,cutoff", "Cutoff frequency in Hz.", cxxopts::value()->no_implicit_value())("s,sample_rate", "Sample rate of input in Hz.", + cxxopts::value()->no_implicit_value()); + + cxxopts::ParseResult result; + try { + result = options.parse(argc, argv); + } catch (cxxopts::exceptions::exception e) { + std::cerr << e.what() << std::endl; + return -1; + } + + if (result.count("cutoff") + result.count("sample_rate") != 2) { + std::cerr << options.help() << std::endl; + return -1; + } // prepare pipes for binary data std::freopen(nullptr, "rb", stdin); @@ -30,7 +45,7 @@ int main(int argc, char** argv) { } // create low pass filter - LowPassFilter lpf(BUFFER_SIZE, 1000, 10000, HammingWindow(BUFFER_SIZE).getWindow()); + LowPassFilter lpf(BUFFER_SIZE, result["cutoff"].as(), result["sample_rate"].as(), HammingWindow(BUFFER_SIZE).getWindow()); // read data std::vector inputBuffer; diff --git a/third-party/cxxopts b/third-party/cxxopts new file mode 160000 index 0000000..4bf61f0 --- /dev/null +++ b/third-party/cxxopts @@ -0,0 +1 @@ +Subproject commit 4bf61f08697b110d9e3991864650a405b3dd515d