qnitap uses QnetConfigure

pull/12/head
Tom Early 7 years ago
parent 93ec44e055
commit 1563af8e27

@ -43,6 +43,7 @@
#include "versions.h" #include "versions.h"
#include "QnetITAP.h" #include "QnetITAP.h"
#include "QnetTypeDefs.h" #include "QnetTypeDefs.h"
#include "QnetConfigure.h"
std::atomic<bool> CQnetITAP::keep_running(true); std::atomic<bool> CQnetITAP::keep_running(true);
@ -403,9 +404,9 @@ bool CQnetITAP::ProcessITAP(const unsigned char *buf)
////////////////// Terminal or Access ///////////////////////// ////////////////// Terminal or Access /////////////////////////
if (0 == memcmp(itap.header.r1, "DIRECT", 6)) { if (0 == memcmp(itap.header.r1, "DIRECT", 6)) {
// Terminal Mode! // Terminal Mode!
memcpy(dstr.vpkt.hdr.r1, RPTR, 7); // build r1 memcpy(dstr.vpkt.hdr.r1, RPTR.c_str(), 7); // build r1
dstr.vpkt.hdr.r1[7] = RPTR_MOD; // with module dstr.vpkt.hdr.r1[7] = RPTR_MOD; // with module
memcpy(dstr.vpkt.hdr.r2, RPTR, 7); // build r2 memcpy(dstr.vpkt.hdr.r2, RPTR.c_str(), 7); // build r2
dstr.vpkt.hdr.r2[7] = 'G'; // with gateway dstr.vpkt.hdr.r2[7] = 'G'; // with gateway
if (' '==itap.header.ur[2] && ' '!=itap.header.ur[0]) { if (' '==itap.header.ur[2] && ' '!=itap.header.ur[0]) {
// it's a command because it has as space in the 3rd position, we have to right-justify it! // it's a command because it has as space in the 3rd position, we have to right-justify it!
@ -452,74 +453,21 @@ bool CQnetITAP::ProcessITAP(const unsigned char *buf)
return false; return false;
} }
bool CQnetITAP::GetValue(const Config &cfg, const char *path, int &value, const int min, const int max, const int default_value)
{
if (cfg.lookupValue(path, value)) {
if (value < min || value > max)
value = default_value;
} else
value = default_value;
printf("%s = [%d]\n", path, value);
return true;
}
bool CQnetITAP::GetValue(const Config &cfg, const char *path, double &value, const double min, const double max, const double default_value)
{
if (cfg.lookupValue(path, value)) {
if (value < min || value > max)
value = default_value;
} else
value = default_value;
printf("%s = [%lg]\n", path, value);
return true;
}
bool CQnetITAP::GetValue(const Config &cfg, const char *path, bool &value, const bool default_value)
{
if (! cfg.lookupValue(path, value))
value = default_value;
printf("%s = [%s]\n", path, value ? "true" : "false");
return true;
}
bool CQnetITAP::GetValue(const Config &cfg, const char *path, std::string &value, int min, int max, const char *default_value)
{
if (cfg.lookupValue(path, value)) {
int l = value.length();
if (l<min || l>max) {
printf("%s value '%s' is wrong size\n", path, value.c_str());
return false;
}
} else
value = default_value;
printf("%s = [%s]\n", path, value.c_str());
return true;
}
// process configuration file and return true if there was a problem // process configuration file and return true if there was a problem
bool CQnetITAP::ReadConfig(const char *cfgFile) bool CQnetITAP::ReadConfig(const char *cfgFile)
{ {
Config cfg; CQnetConfigure cfg;
printf("Reading file %s\n", cfgFile); printf("Reading file %s\n", cfgFile);
// Read the file. If there is an error, report it and exit. if (cfg.Initialize(cfgFile))
try {
cfg.readFile(cfgFile);
}
catch(const FileIOException &fioex) {
fprintf(stderr, "Can't read %s\n", cfgFile);
return true;
}
catch(const ParseException &pex) {
fprintf(stderr, "Parse error at %s:%d - %s\n", pex.getFile(), pex.getLine(), pex.getError());
return true; return true;
}
std::string value; const std::string estr; // an empty string
std::string itap_path("module."); std::string type;
std::string itap_path("module_");
itap_path.append(1, 'a' + assigned_module); itap_path.append(1, 'a' + assigned_module);
if (cfg.lookupValue(itap_path + ".type", value)) { if (cfg.KeyExists(itap_path)) {
if (value.compare("itap")) { cfg.GetValue(itap_path, estr, type, 1, 16);
if (type.compare("itap")) {
fprintf(stderr, "assigned module %c is not 'itap'\n", 'a' + assigned_module); fprintf(stderr, "assigned module %c is not 'itap'\n", 'a' + assigned_module);
return true; return true;
} }
@ -529,55 +477,34 @@ bool CQnetITAP::ReadConfig(const char *cfgFile)
} }
RPTR_MOD = 'A' + assigned_module; RPTR_MOD = 'A' + assigned_module;
char unixsockname[16]; cfg.GetValue(itap_path+"_device", type, ITAP_DEVICE, 7, FILENAME_MAX);
snprintf(unixsockname, 16, "gate2modem%d", assigned_module); cfg.GetValue(itap_path+"_gate2modem"+std::to_string(assigned_module), type, gate2modem, 1, FILENAME_MAX);
GetValue(cfg, std::string(itap_path+".togateway").c_str(), modem2gate, 1, FILENAME_MAX, unixsockname); cfg.GetValue(itap_path+"_modem2gate"+std::to_string(assigned_module), type, modem2gate, 1, FILENAME_MAX);
snprintf(unixsockname, 16, "modem2gate%d", assigned_module);
GetValue(cfg, std::string(itap_path+".fromgateway").c_str(), gate2modem, 1, FILENAME_MAX, unixsockname);
if (cfg.lookupValue(std::string(itap_path+".callsign").c_str(), value) || cfg.lookupValue("ircddb.login", value)) { itap_path.append("_callsign");
int l = value.length(); if (cfg.KeyExists(itap_path)) {
if (l<3 || l>CALL_SIZE-2) { if (cfg.GetValue(itap_path, type, RPTR, 3, 6))
printf("Call '%s' is invalid length!\n", value.c_str());
return true; return true;
} else { } else {
for (int i=0; i<l; i++) { itap_path.assign("ircddb_login");
if (islower(value[i])) if (cfg.KeyExists(itap_path)) {
value[i] = toupper(value[i]); if (cfg.GetValue(itap_path, estr, RPTR, 3, 6))
}
value.resize(CALL_SIZE, ' ');
}
strcpy(RPTR, value.c_str());
} else {
printf("%s.login is not defined!\n", itap_path.c_str());
return true; return true;
} }
}
if (cfg.lookupValue("ircddb.login", value)) { int l = RPTR.length();
int l = value.length(); if (l<3 || l>6) {
if (l<3 || l>CALL_SIZE-2) { printf("Call '%s' is invalid length!\n", RPTR.c_str());
printf("Call '%s' is invalid length!\n", value.c_str());
return true; return true;
} else { } else {
for (int i=0; i<l; i++) { for (int i=0; i<l; i++) {
if (islower(value[i])) if (islower(RPTR[i]))
value[i] = toupper(value[i]); RPTR[i] = toupper(RPTR[i]);
} }
value.resize(CALL_SIZE, ' '); RPTR.resize(CALL_SIZE, ' ');
} }
strcpy(OWNER, value.c_str());
printf("ircddb.login = [%s]\n", OWNER);
} else {
printf("ircddb.login is not defined!\n");
return true;
}
if (GetValue(cfg, std::string(itap_path+".device").c_str(), value, 7, 25, "/dev/ttyUSB0")) {
ITAP_DEVICE = value;
} else
return true;
GetValue(cfg, "log.qso", log_qso, false); cfg.GetValue("log_qso", estr, log_qso);
return false; return false;
} }

@ -20,14 +20,11 @@
#include <atomic> #include <atomic>
#include <string> #include <string>
#include <libconfig.h++>
#include <netinet/in.h> #include <netinet/in.h>
#include "Random.h" // for streamid generation #include "Random.h" // for streamid generation
#include "UnixDgramSocket.h" #include "UnixDgramSocket.h"
using namespace libconfig;
#define CALL_SIZE 8 #define CALL_SIZE 8
#define IP_SIZE 15 #define IP_SIZE 15
@ -104,16 +101,10 @@ private:
// read configuration file // read configuration file
bool ReadConfig(const char *); bool ReadConfig(const char *);
bool GetValue(const Config &cfg, const char *path, int &value, const int min, const int max, const int default_value);
bool GetValue(const Config &cfg, const char *path, double &value, const double min, const double max, const double default_value);
bool GetValue(const Config &cfg, const char *path, bool &value, const bool default_value);
bool GetValue(const Config &cfg, const char *path, std::string &value, const int min, const int max, const char *default_value);
// config data // config data
char RPTR_MOD; char RPTR_MOD;
char RPTR[CALL_SIZE + 1]; std::string ITAP_DEVICE, RPTR;
char OWNER[CALL_SIZE + 1];
std::string ITAP_DEVICE;
bool log_qso; bool log_qso;
// parameters // parameters

@ -379,7 +379,7 @@ bool CQnetRelay::ReadConfig(const char *cfgFile)
cfg.GetValue(mmdvm_path+"+gateway_port", type, i, 10000, 65535); cfg.GetValue(mmdvm_path+"+gateway_port", type, i, 10000, 65535);
MMDVM_OUT_PORT = (unsigned short)i; MMDVM_OUT_PORT = (unsigned short)i;
cfg.GetValue("log.qso", estr, log_qso); cfg.GetValue("log_qso", estr, log_qso);
return false; return false;
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.