Add options parsing module

This commit is contained in:
Thomas Kolb 2024-03-30 21:50:54 +01:00
parent 07555edfdf
commit dd5712eada
4 changed files with 61 additions and 1 deletions

View file

@ -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

View file

@ -12,6 +12,7 @@
#include <signal.h>
#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);

37
impl/src/options.c Normal file
View file

@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#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;
}

14
impl/src/options.h Normal file
View file

@ -0,0 +1,14 @@
#ifndef OPTIONS_H
#define OPTIONS_H
#include <stdbool.h>
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