diff --git a/impl/CMakeLists.txt b/impl/CMakeLists.txt index fa46a75..b248034 100644 --- a/impl/CMakeLists.txt +++ b/impl/CMakeLists.txt @@ -10,6 +10,8 @@ include_directories(src) set(sources src/utils.c src/utils.h + src/options.c + src/options.h src/main.c src/results.h src/config.h diff --git a/impl/src/main.c b/impl/src/main.c index e1869e2..8b03446 100644 --- a/impl/src/main.c +++ b/impl/src/main.c @@ -12,6 +12,7 @@ #include #include "utils.h" +#include "options.h" #include "layer1/tx.h" #include "layer1/rx.h" @@ -200,13 +201,19 @@ static result_t transmit_in_chunks(sdr_ctx_t *sdr, const float complex *samples, } -int main(void) +int main(int argc, char **argv) { layer1_tx_t tx; layer1_rx_t rx; sdr_ctx_t sdr; + int parsed_options = options_parse(argc, argv); + fprintf(stderr, "%d options parsed.\n", parsed_options); + if(parsed_options < 0) { + return EXIT_FAILURE; + } + bool on_air = true; debug_fd = open("/tmp/dump.cf32", O_CREAT | O_WRONLY | O_TRUNC); diff --git a/impl/src/options.c b/impl/src/options.c new file mode 100644 index 0000000..9ece280 --- /dev/null +++ b/impl/src/options.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include + +#include "options.h" + +static uint32_t m_flags; + +int options_parse(int argc, char **argv) +{ + int opt; + int nparsed = 0; + while((opt = getopt(argc, argv, "c")) != -1) { + switch(opt) { + case 'c': + m_flags |= (1 << OPTIONS_FLAG_IS_CENTRAL_NODE); + break; + + default: + fprintf(stderr, + "Usage: %s [-c]\n\n" + " -c Makes this node a central node (base station).\n", + argv[0]); + exit(EXIT_FAILURE); + } + + nparsed++; + } + + return nparsed; +} + +bool options_is_flag_set(options_flag_t flag) +{ + return (m_flags & (1 << flag)) != 0; +} diff --git a/impl/src/options.h b/impl/src/options.h new file mode 100644 index 0000000..cce6103 --- /dev/null +++ b/impl/src/options.h @@ -0,0 +1,14 @@ +#ifndef OPTIONS_H +#define OPTIONS_H + +#include + +typedef enum { + OPTIONS_FLAG_IS_CENTRAL_NODE, +} options_flag_t; + +int options_parse(int argc, char **argv); + +bool options_is_flag_set(options_flag_t flag); + +#endif // OPTIONS_H