improved assigned_module treatment

pull/12/head
Tom Early 7 years ago
parent 7adfc39cd1
commit 5c70a67ac4

@ -167,17 +167,40 @@ static bool read_config(const char *cfgFile)
const std::string estr; // an empty string const std::string estr; // an empty string
std::string type; std::string type;
std::string dvap_path("module_"); std::string dvap_path("module_");
if (0 > assigned_module) {
// we need to find the lone dvap module
for (int i=0; i<3; i++) {
std::string test(dvap_path);
test.append(1, 'a'+i);
if (cfg.KeyExists(test)) {
cfg.GetValue(test, estr, type, 1, 16);
if (type.compare("dvap")) {
fprintf(stderr, "%s = '%s', expecting 'dvap'!\n", test.c_str(), type.c_str());
return true;
}
dvap_path.assign(test);
assigned_module = i;
break;
}
}
if (0 > assigned_module) {
fprintf(stderr, "Error: no 'dvap' module found\n!");
return true;
}
} else {
// make sure dvap module is defined
dvap_path.append(1, 'a' + assigned_module); dvap_path.append(1, 'a' + assigned_module);
if (cfg.KeyExists(dvap_path)) { if (cfg.KeyExists(dvap_path)) {
cfg.GetValue(dvap_path, estr, type, 1, 16); cfg.GetValue(dvap_path, estr, type, 1, 16);
if (type.compare("dvap")) { if (type.compare("dvap")) {
fprintf(stderr, "assigned module '%c' type is not 'dvap'\n", 'a' + assigned_module); fprintf(stderr, "%s = %s is not 'dvap' type!\n", dvap_path.c_str(), type.c_str());
return true; return true;
} }
} else { } else {
fprintf(stderr, "%s is not defined!\n", dvap_path.c_str()); fprintf(stderr, "Module '%c' is not defined.\n", 'a'+assigned_module);
return true; return true;
} }
}
RPTR_MOD = 'A' + assigned_module; RPTR_MOD = 'A' + assigned_module;
cfg.GetValue(dvap_path+"_gate2modem"+std::to_string(assigned_module), type, gate2modem, 1, FILENAME_MAX); cfg.GetValue(dvap_path+"_gate2modem"+std::to_string(assigned_module), type, gate2modem, 1, FILENAME_MAX);
cfg.GetValue(dvap_path+"_modem2gate"+std::to_string(assigned_module), type, modem2gate, 1, FILENAME_MAX); cfg.GetValue(dvap_path+"_modem2gate"+std::to_string(assigned_module), type, modem2gate, 1, FILENAME_MAX);
@ -502,33 +525,44 @@ int main(int argc, const char **argv)
setvbuf(stdout, NULL, _IOLBF, 0); setvbuf(stdout, NULL, _IOLBF, 0);
printf("dvap_rptr VERSION %s\n", VERSION); printf("dvap_rptr VERSION %s\n", VERSION);
if (argc != 3) { if (argc != 2) {
fprintf(stderr, "Usage: %s assigned_module dvap_rptr.cfg\n", argv[0]); fprintf(stderr, "Usage: %s dvap_rptr.cfg\n", argv[0]);
return 1;
}
if ('-' == argv[1][0]) {
printf("\nQnetDVAP Version #%s Copyright (C) 2018-2019 by Thomas A. Early N7TAE\n", DVAP_VERSION);
printf("QnetDVAP comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n");
printf("This is free software, and you are welcome to distribute it\nunder certain conditions that are discussed in the LICENSE file.\n\n");
return 0;
}
const char *qn = strstr(argv[0], "qndvap");
if (NULL == qn) {
fprintf(stderr, "Error finding 'qndvap' in %s!\n", argv[0]);
return 1; return 1;
} }
qn += 6;
switch (argv[1][0]) { switch (argv[1][0]) {
case '0': case NULL:
assigned_module = -1;
break;
case 'a': case 'a':
case 'A':
assigned_module = 0; assigned_module = 0;
break; break;
case '1':
case 'b': case 'b':
case 'B':
assigned_module = 1; assigned_module = 1;
break; break;
case '2':
case 'c': case 'c':
case 'C':
assigned_module = 2; assigned_module = 2;
break; break;
default: default:
fprintf(stderr, "ERROR: '%s' is not a valid module\nassigned module must be 0, a, A, 1, b, B, 2, c or C\n", argv[1]); fprintf(stderr, "ERROR: '%s' is not a valid module\nassigned module must be a, b or c\n", argv[1]);
return 1; return 1;
} }
if (read_config(argv[2])) { if (read_config(argv[1])) {
printf("Failed to process config file %s\n", argv[2]); printf("Failed to process config file %s\n", argv[2]);
return 1; return 1;
} }

@ -1820,15 +1820,39 @@ static bool read_config(const char *cfgFile)
const std::string estr; // an empty string const std::string estr; // an empty string
std::string type; std::string type;
std::string path("module_"); std::string path("module_");
path += ('a' + assigned_module); if (0 > assigned_module) {
// we need to find the lone dvrptr module
for (int i=0; i<3; i++) {
std::string test(path);
test.append(1, 'a'+i);
if (cfg.KeyExists(test)) {
cfg.GetValue(test, estr, type, 1, 16);
if (type.compare("dvrptr")) {
fprintf(stderr, "%s = '%s', expecting 'dvrptr'!\n", test.c_str(), type.c_str());
return true;
}
path.assign(test);
assigned_module = i;
break;
}
}
if (0 > assigned_module) {
fprintf(stderr, "Error: no 'dvrptr' module found\n!");
return true;
}
} else {
// make sure dvrptr module is defined
path.append(1, 'a' + assigned_module);
if (cfg.KeyExists(path)) { if (cfg.KeyExists(path)) {
if (cfg.GetValue(path, estr, type, 1, 16) || type.compare("dvrptr")) { cfg.GetValue(path, estr, type, 1, 16);
fprintf(stderr, "%s = %s is not 'dvrptr'!\n", path.c_str(), type.c_str()); if (type.compare("dvrptr")) {
fprintf(stderr, "%s = %s is not 'dvrptr' type!\n", path.c_str(), type.c_str());
return true; return true;
} }
} else { } else {
fprintf(stderr, "module %c is not defined\n", 'a' + assigned_module); fprintf(stderr, "Module '%c' is not defined.\n", 'a'+assigned_module);
return 1; return true;
}
} }
DVRPTR_MOD = 'A' + assigned_module; DVRPTR_MOD = 'A' + assigned_module;
cfg.GetValue(path+"_gate2modem"+std::to_string(assigned_module), type, gate2modem, 1, FILENAME_MAX); cfg.GetValue(path+"_gate2modem"+std::to_string(assigned_module), type, gate2modem, 1, FILENAME_MAX);
@ -2473,33 +2497,37 @@ int main(int argc, const char **argv)
setvbuf(stdout, NULL, _IOLBF, 0); setvbuf(stdout, NULL, _IOLBF, 0);
printf("dvrptr VERSION %s\n", VERSION); printf("dvrptr VERSION %s\n", VERSION);
if (argc != 3) { if (argc != 2) {
fprintf(stderr, "Usage: %s assigned_module dvrptr.cfg\n", argv[0]); fprintf(stderr, "Usage: %s dvrptr.cfg\n", argv[0]);
return 1; return 1;
} }
if ('-' == argv[1][0]) {
printf("\nQnetDVRPTR Version #%s Copyright (C) 2018-2019 by Thomas A. Early N7TAE\n", DVRPTR_VERSION);
printf("QnetDVRPTR comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n");
printf("This is free software, and you are welcome to distribute it\nunder certain conditions that are discussed in the LICENSE file.\n\n");
return 0;
}
switch (argv[1][0]) { switch (argv[1][0]) {
case '0': case NULL:
assigned_module = -1;
break;
case 'a': case 'a':
case 'A':
assigned_module = 0; assigned_module = 0;
break; break;
case '1':
case 'b': case 'b':
case 'B':
assigned_module = 1; assigned_module = 1;
break; break;
case '2':
case 'c': case 'c':
case 'C':
assigned_module = 2; assigned_module = 2;
break; break;
default: default:
fprintf(stderr, "ERROR: '%s' is not a valid module\nassigned module must be 0, a, A, 1, b, B, 2, c or C\n", argv[1]); fprintf(stderr, "ERROR: '%s' is not a valid module\nassigned module must be a, b or c\n", argv[1]);
return 1; return 1;
} }
if (read_config(argv[2])) { if (read_config(argv[1])) {
fprintf(stderr, "Failed to process config file %s\n", argv[2]); fprintf(stderr, "Failed to process config file %s\n", argv[2]);
return 1; return 1;
} }

@ -464,17 +464,40 @@ bool CQnetITAP::ReadConfig(const char *cfgFile)
const std::string estr; // an empty string const std::string estr; // an empty string
std::string type; std::string type;
std::string itap_path("module_"); std::string itap_path("module_");
if (0 > assigned_module) {
// we need to find the lone itap module
for (int i=0; i<3; i++) {
std::string test(itap_path);
test.append(1, 'a'+i);
if (cfg.KeyExists(test)) {
cfg.GetValue(test, estr, type, 1, 16);
if (type.compare("itap")) {
fprintf(stderr, "%s = '%s', expecting 'itap'!\n", test.c_str(), type.c_str());
return true;
}
itap_path.assign(test);
assigned_module = i;
break;
}
}
if (0 > assigned_module) {
fprintf(stderr, "Error: no 'itap' module found\n!");
return true;
}
} else {
// make sure itap module is defined
itap_path.append(1, 'a' + assigned_module); itap_path.append(1, 'a' + assigned_module);
if (cfg.KeyExists(itap_path)) { if (cfg.KeyExists(itap_path)) {
cfg.GetValue(itap_path, estr, type, 1, 16); cfg.GetValue(itap_path, estr, type, 1, 16);
if (type.compare("itap")) { if (type.compare("itap")) {
fprintf(stderr, "assigned module %c is not 'itap'\n", 'a' + assigned_module); fprintf(stderr, "%s = %s is not 'itap' type!\n", itap_path.c_str(), type.c_str());
return true; return true;
} }
} else { } else {
fprintf(stderr, "assigned module %c not defined\n", 'a' + assigned_module); fprintf(stderr, "Module '%c' is not defined.\n", 'a'+assigned_module);
return true; return true;
} }
}
RPTR_MOD = 'A' + assigned_module; RPTR_MOD = 'A' + assigned_module;
cfg.GetValue(itap_path+"_device", type, ITAP_DEVICE, 7, FILENAME_MAX); cfg.GetValue(itap_path+"_device", type, ITAP_DEVICE, 7, FILENAME_MAX);
@ -556,41 +579,46 @@ void CQnetITAP::calcPFCS(const unsigned char *packet, unsigned char *pfcs)
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
setbuf(stdout, NULL); setbuf(stdout, NULL);
if (3 != argc) { if (2 != argc) {
fprintf(stderr, "usage: %s assigned_module path_to_config_file\n", argv[0]); fprintf(stderr, "usage: %s path_to_config_file\n", argv[0]);
return 1; return 1;
} else { }
printf("\nQnetITAP Version #%s Copyright (C) 2018 by Thomas A. Early N7TAE\n", ITAP_VERSION);
if ('-' == argv[1][0]) {
printf("\nQnetITAP Version #%s Copyright (C) 2018-2019 by Thomas A. Early N7TAE\n", ITAP_VERSION);
printf("QnetITAP comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n"); printf("QnetITAP comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n");
printf("This is free software, and you are welcome to distribute it\nunder certain conditions that are discussed in the LICENSE file.\n\n"); printf("This is free software, and you are welcome to distribute it\nunder certain conditions that are discussed in the LICENSE file.\n\n");
return 0; return 0;
} }
const char *qn = strstr(argv[0], "qnitap");
if (NULL == qn) {
fprintf(stderr, "Error finding 'qnitap' in %s!\n", argv[0]);
return 1;
}
qn += 6;
int assigned_module; int assigned_module;
switch (argv[1][0]) { switch (argv[1][0]) {
case '0': case NULL:
assigned_module = -1;
break;
case 'a': case 'a':
case 'A':
assigned_module = 0; assigned_module = 0;
break; break;
case '1':
case 'b': case 'b':
case 'B':
assigned_module = 1; assigned_module = 1;
break; break;
case '2':
case 'c': case 'c':
case 'C':
assigned_module = 2; assigned_module = 2;
break; break;
default: default:
fprintf(stderr, "assigned module must be 0, a, A, 1, b, B, 2, c or C\n"); fprintf(stderr, "assigned module must be a, b or c\n");
return 1; return 1;
} }
CQnetITAP qnitap(assigned_module); CQnetITAP qnitap(assigned_module);
qnitap.Run(argv[2]); qnitap.Run(argv[1]);
printf("%s is closing.\n", argv[0]); printf("%s is closing.\n", argv[0]);

@ -355,8 +355,31 @@ bool CQnetRelay::ReadConfig(const char *cfgFile)
return true; return true;
const std::string estr; // an empty GetDefaultString const std::string estr; // an empty GetDefaultString
std::string type;
std::string mmdvm_path("module_"); std::string mmdvm_path("module_");
std::string type;
if (0 > assigned_module) {
// we need to find the lone mmdvm module
for (int i=0; i<3; i++) {
std::string test(mmdvm_path);
test.append(1, 'a'+i);
if (cfg.KeyExists(test)) {
cfg.GetValue(test, estr, type, 1, 16);
if (type.compare("mmdvm")) {
fprintf(stderr, "%s = '%s', expecting 'mmdvm'!\n", test.c_str(), type.c_str());
return true;
}
mmdvm_path.assign(test);
assigned_module = i;
break;
}
}
if (0 > assigned_module) {
fprintf(stderr, "Error: no 'mmdvm' module found\n!");
return true;
}
} else {
// make sure mmdvm module is defined
mmdvm_path.append(1, 'a' + assigned_module); mmdvm_path.append(1, 'a' + assigned_module);
if (cfg.KeyExists(mmdvm_path)) { if (cfg.KeyExists(mmdvm_path)) {
cfg.GetValue(mmdvm_path, estr, type, 1, 16); cfg.GetValue(mmdvm_path, estr, type, 1, 16);
@ -368,6 +391,7 @@ bool CQnetRelay::ReadConfig(const char *cfgFile)
fprintf(stderr, "Module '%c' is not defined.\n", 'a'+assigned_module); fprintf(stderr, "Module '%c' is not defined.\n", 'a'+assigned_module);
return true; return true;
} }
}
RPTR_MOD = 'A' + assigned_module; RPTR_MOD = 'A' + assigned_module;
cfg.GetValue(mmdvm_path+"_gate2modem"+std::to_string(assigned_module), type, gate2modem, 1, FILENAME_MAX); cfg.GetValue(mmdvm_path+"_gate2modem"+std::to_string(assigned_module), type, gate2modem, 1, FILENAME_MAX);
@ -394,41 +418,46 @@ void CQnetRelay::SignalCatch(const int signum)
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
setbuf(stdout, NULL); setbuf(stdout, NULL);
if (3 != argc) { if (2 != argc) {
fprintf(stderr, "usage: %s assigned_module path_to_config_file\n", argv[0]); fprintf(stderr, "usage: %s path_to_config_file\n", argv[0]);
return 1; return 1;
} else { }
printf("\nQnetRelay Version #%s Copyright (C) 2018 by Thomas A. Early N7TAE\n", RELAY_VERSION);
if ('-' == argv[1][0]) {
printf("\nQnetRelay Version #%s Copyright (C) 2018-2019 by Thomas A. Early N7TAE\n", RELAY_VERSION);
printf("QnetRelay comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n"); printf("QnetRelay comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n");
printf("This is free software, and you are welcome to distribute it\nunder certain conditions that are discussed in the LICENSE file.\n\n"); printf("This is free software, and you are welcome to distribute it\nunder certain conditions that are discussed in the LICENSE file.\n\n");
return 0; return 0;
} }
const char *qn = strstr(argv[0], "qnrelay");
if (NULL == qn) {
fprintf(stderr, "Error finding 'qnrelay' in %s!\n", argv[0]);
return 1;
}
qn += 7;
int module; int module;
switch (argv[1][0]) { switch (*qn) {
case '0': case NULL:
module = -1;
break;
case 'a': case 'a':
case 'A':
module = 0; module = 0;
break; break;
case '1':
case 'b': case 'b':
case 'B':
module = 1; module = 1;
break; break;
case '2':
case 'c': case 'c':
case 'C':
module = 2; module = 2;
break; break;
default: default:
fprintf(stderr, "assigned module must be 0, a, A, 1, b, B, 2, c or C\n"); fprintf(stderr, "assigned module must be a, b or c\n");
return 1; return 1;
} }
CQnetRelay qnmmdvm(module); CQnetRelay qnmmdvm(module);
bool trouble = qnmmdvm.Run(argv[2]); bool trouble = qnmmdvm.Run(argv[1]);
printf("%s is closing.\n", argv[0]); printf("%s is closing.\n", argv[0]);

Loading…
Cancel
Save

Powered by TurnKey Linux.