forked from Leapus/hamcreek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.cpp
75 lines (61 loc) · 2.26 KB
/
config.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <string>
#include "config.hpp"
#include "main.hpp"
using namespace std::string_literals;
using namespace leapus::configuration;
const std::filesystem::path leapus::configuration::Config::stdout_path{"/dev/stdout"};
//leapus::configuration::Config leapus::configuration::config = {};
void Config::usage(){
print_info("hamcreek radio config exchanger");
//print_info("Usage: hamcreek [-C <chirp.csv>] [-R <rptrs.json>]");
print_info("Usage: hamcreek [-C <chirp.csv>] [-i ordinal] [-MEX]");
print_info(" -C CHIRP channel data to import");
print_info(" -i Specify the first ordinal number to prefer for generated channels");
print_info(" -MEX Generate channels for Mexican open bands having MD5-compatible 12.5kHz bandwidth");
print_info(" (see https://www.ift.org.mx/sites/default/files/contenidogeneral/espectro-radioelectrico/inventariodebandasdefrecuenciasdeusolibrev.pdf)");
//print_info(" -R DMR digital repeater settings to merge, obtainable from radioid.net"); //unimplemented
print_info("");
}
int Config::argc() const{ return m_argc; }
const char **Config::argv() const{ return m_argv; }
void Config::parse(int argc_, const char *argv_[]){
//if(argc>1)
// chirp_channels_in = argv[1];
m_argc = argc_;
m_argv = argv_;
for(int i=1;i<argc_;++i){
auto a=argv_[i];
if("-C"s == a)
handle_chirp_channel_flag(i);
else if("-R"s == a)
handle_radioid_repeater_flag(i);
else if("-MEX"s == a)
handle_mexico_flag(i);
else if("-i"s == a)
handle_ordinal_flag(i);
else{
throw config_exception("Invalid flag: "s + argv_[i]);
}
}
}
void Config::require_next_arg(int &argi){
++argi;
if(argi >= m_argc){
throw config_exception("Missing expecteed argument");
}
}
void Config::handle_mexico_flag(int &argi){
mexico=true;
}
void Config::handle_chirp_channel_flag(int &argi){
require_next_arg(argi);
chirp_channels_in = argv()[argi];
}
void Config::handle_radioid_repeater_flag(int &argi){
require_next_arg(argi);
radioid_repeaters_in = argv()[argi];
}
void Config::handle_ordinal_flag(int &argi){
require_next_arg(argi);
max_ordinal=std::stoi(argv()[argi]);
}