Allow for an optional local Parrot entry.
This commit is contained in:
parent
6f6d27ebf3
commit
20485f5d02
8 changed files with 86 additions and 31 deletions
|
@ -64,6 +64,8 @@ m_networkEnabled(false),
|
||||||
m_networkDataPort(0U),
|
m_networkDataPort(0U),
|
||||||
m_networkHosts(),
|
m_networkHosts(),
|
||||||
m_networkReloadTime(0U),
|
m_networkReloadTime(0U),
|
||||||
|
m_networkParrotAddress("127.0.0.1"),
|
||||||
|
m_networkParrotPort(0U),
|
||||||
m_networkStartup(),
|
m_networkStartup(),
|
||||||
m_networkDebug(false)
|
m_networkDebug(false)
|
||||||
{
|
{
|
||||||
|
@ -175,6 +177,10 @@ bool CConf::read()
|
||||||
m_networkHosts = value;
|
m_networkHosts = value;
|
||||||
else if (::strcmp(key, "ReloadTime") == 0)
|
else if (::strcmp(key, "ReloadTime") == 0)
|
||||||
m_networkReloadTime = (unsigned int)::atoi(value);
|
m_networkReloadTime = (unsigned int)::atoi(value);
|
||||||
|
else if (::strcmp(key, "ParrotAddress") == 0)
|
||||||
|
m_networkParrotAddress = value;
|
||||||
|
else if (::strcmp(key, "ParrotPort") == 0)
|
||||||
|
m_networkParrotPort = (unsigned int)::atoi(value);
|
||||||
else if (::strcmp(key, "Startup") == 0)
|
else if (::strcmp(key, "Startup") == 0)
|
||||||
m_networkStartup = value;
|
m_networkStartup = value;
|
||||||
else if (::strcmp(key, "Debug") == 0)
|
else if (::strcmp(key, "Debug") == 0)
|
||||||
|
@ -322,6 +328,16 @@ unsigned int CConf::getNetworkReloadTime() const
|
||||||
return m_networkReloadTime;
|
return m_networkReloadTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CConf::getNetworkParrotAddress() const
|
||||||
|
{
|
||||||
|
return m_networkParrotAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int CConf::getNetworkParrotPort() const
|
||||||
|
{
|
||||||
|
return m_networkParrotPort;
|
||||||
|
}
|
||||||
|
|
||||||
std::string CConf::getNetworkStartup() const
|
std::string CConf::getNetworkStartup() const
|
||||||
{
|
{
|
||||||
return m_networkStartup;
|
return m_networkStartup;
|
||||||
|
|
|
@ -66,6 +66,8 @@ public:
|
||||||
unsigned int getNetworkDataPort() const;
|
unsigned int getNetworkDataPort() const;
|
||||||
std::string getNetworkHosts() const;
|
std::string getNetworkHosts() const;
|
||||||
unsigned int getNetworkReloadTime() const;
|
unsigned int getNetworkReloadTime() const;
|
||||||
|
std::string getNetworkParrotAddress() const;
|
||||||
|
unsigned int getNetworkParrotPort() const;
|
||||||
std::string getNetworkStartup() const;
|
std::string getNetworkStartup() const;
|
||||||
bool getNetworkDebug() const;
|
bool getNetworkDebug() const;
|
||||||
|
|
||||||
|
@ -102,6 +104,8 @@ private:
|
||||||
unsigned int m_networkDataPort;
|
unsigned int m_networkDataPort;
|
||||||
std::string m_networkHosts;
|
std::string m_networkHosts;
|
||||||
unsigned int m_networkReloadTime;
|
unsigned int m_networkReloadTime;
|
||||||
|
std::string m_networkParrotAddress;
|
||||||
|
unsigned int m_networkParrotPort;
|
||||||
std::string m_networkStartup;
|
std::string m_networkStartup;
|
||||||
bool m_networkDebug;
|
bool m_networkDebug;
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
|
|
||||||
CReflectors::CReflectors(const std::string& hostsFile, unsigned int reloadTime) :
|
CReflectors::CReflectors(const std::string& hostsFile, unsigned int reloadTime) :
|
||||||
m_hostsFile(hostsFile),
|
m_hostsFile(hostsFile),
|
||||||
|
m_parrotAddress(),
|
||||||
|
m_parrotPort(0U),
|
||||||
m_reflectors(),
|
m_reflectors(),
|
||||||
m_search(),
|
m_search(),
|
||||||
m_timer(1000U, reloadTime * 60U)
|
m_timer(1000U, reloadTime * 60U)
|
||||||
|
@ -61,54 +63,69 @@ static bool refComparison(const CYSFReflector* r1, const CYSFReflector* r2)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CReflectors::setParrot(const std::string& address, unsigned int port)
|
||||||
|
{
|
||||||
|
m_parrotAddress = address;
|
||||||
|
m_parrotPort = port;
|
||||||
|
}
|
||||||
|
|
||||||
bool CReflectors::load()
|
bool CReflectors::load()
|
||||||
{
|
{
|
||||||
FILE* fp = ::fopen(m_hostsFile.c_str(), "rt");
|
|
||||||
if (fp == NULL) {
|
|
||||||
LogWarning("Cannot open the YSF Hosts file - %s", m_hostsFile.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear out the old reflector list
|
// Clear out the old reflector list
|
||||||
for (std::vector<CYSFReflector*>::iterator it = m_reflectors.begin(); it != m_reflectors.end(); ++it)
|
for (std::vector<CYSFReflector*>::iterator it = m_reflectors.begin(); it != m_reflectors.end(); ++it)
|
||||||
delete *it;
|
delete *it;
|
||||||
|
|
||||||
m_reflectors.clear();
|
m_reflectors.clear();
|
||||||
|
|
||||||
char buffer[100U];
|
FILE* fp = ::fopen(m_hostsFile.c_str(), "rt");
|
||||||
while (::fgets(buffer, 100U, fp) != NULL) {
|
if (fp != NULL) {
|
||||||
if (buffer[0U] == '#')
|
char buffer[100U];
|
||||||
continue;
|
while (::fgets(buffer, 100U, fp) != NULL) {
|
||||||
|
if (buffer[0U] == '#')
|
||||||
|
continue;
|
||||||
|
|
||||||
char* p1 = ::strtok(buffer, ";\r\n");
|
char* p1 = ::strtok(buffer, ";\r\n");
|
||||||
char* p2 = ::strtok(NULL, ";\r\n");
|
char* p2 = ::strtok(NULL, ";\r\n");
|
||||||
char* p3 = ::strtok(NULL, ";\r\n");
|
char* p3 = ::strtok(NULL, ";\r\n");
|
||||||
char* p4 = ::strtok(NULL, ";\r\n");
|
char* p4 = ::strtok(NULL, ";\r\n");
|
||||||
char* p5 = ::strtok(NULL, ";\r\n");
|
char* p5 = ::strtok(NULL, ";\r\n");
|
||||||
char* p6 = ::strtok(NULL, "\r\n");
|
char* p6 = ::strtok(NULL, "\r\n");
|
||||||
|
|
||||||
if (p1 != NULL && p2 != NULL && p3 != NULL && p4 != NULL && p5 != NULL && p6 != NULL) {
|
if (p1 != NULL && p2 != NULL && p3 != NULL && p4 != NULL && p5 != NULL && p6 != NULL) {
|
||||||
std::string host = std::string(p4);
|
std::string host = std::string(p4);
|
||||||
|
|
||||||
in_addr address = CUDPSocket::lookup(host);
|
in_addr address = CUDPSocket::lookup(host);
|
||||||
if (address.s_addr != INADDR_NONE) {
|
if (address.s_addr != INADDR_NONE) {
|
||||||
CYSFReflector* refl = new CYSFReflector;
|
CYSFReflector* refl = new CYSFReflector;
|
||||||
refl->m_id = std::string(p1);
|
refl->m_id = std::string(p1);
|
||||||
refl->m_name = std::string(p2);
|
refl->m_name = std::string(p2);
|
||||||
refl->m_desc = std::string(p3);
|
refl->m_desc = std::string(p3);
|
||||||
refl->m_address = address;
|
refl->m_address = address;
|
||||||
refl->m_port = (unsigned int)::atoi(p5);
|
refl->m_port = (unsigned int)::atoi(p5);
|
||||||
refl->m_count = std::string(p6);;
|
refl->m_count = std::string(p6);;
|
||||||
|
|
||||||
refl->m_name.resize(16U, ' ');
|
refl->m_name.resize(16U, ' ');
|
||||||
refl->m_desc.resize(14U, ' ');
|
refl->m_desc.resize(14U, ' ');
|
||||||
|
|
||||||
m_reflectors.push_back(refl);
|
m_reflectors.push_back(refl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
::fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
::fclose(fp);
|
// Add the Parrot entry
|
||||||
|
if (m_parrotPort > 0U) {
|
||||||
|
CYSFReflector* refl = new CYSFReflector;
|
||||||
|
refl->m_id = "00001";
|
||||||
|
refl->m_name = "ZZ Parrot ";
|
||||||
|
refl->m_desc = "Parrot ";
|
||||||
|
refl->m_address = CUDPSocket::lookup(m_parrotAddress);
|
||||||
|
refl->m_port = m_parrotPort;
|
||||||
|
refl->m_count = "000";
|
||||||
|
m_reflectors.push_back(refl);
|
||||||
|
}
|
||||||
|
|
||||||
size_t size = m_reflectors.size();
|
size_t size = m_reflectors.size();
|
||||||
if (size == 0U)
|
if (size == 0U)
|
||||||
|
|
|
@ -50,6 +50,8 @@ public:
|
||||||
CReflectors(const std::string& hostsFile, unsigned int reloadTime);
|
CReflectors(const std::string& hostsFile, unsigned int reloadTime);
|
||||||
~CReflectors();
|
~CReflectors();
|
||||||
|
|
||||||
|
void setParrot(const std::string& address, unsigned int port);
|
||||||
|
|
||||||
bool load();
|
bool load();
|
||||||
|
|
||||||
CYSFReflector* find(const std::string& id);
|
CYSFReflector* find(const std::string& id);
|
||||||
|
@ -62,6 +64,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_hostsFile;
|
std::string m_hostsFile;
|
||||||
|
std::string m_parrotAddress;
|
||||||
|
unsigned int m_parrotPort;
|
||||||
std::vector<CYSFReflector*> m_reflectors;
|
std::vector<CYSFReflector*> m_reflectors;
|
||||||
std::vector<CYSFReflector*> m_search;
|
std::vector<CYSFReflector*> m_search;
|
||||||
CTimer m_timer;
|
CTimer m_timer;
|
||||||
|
|
|
@ -147,6 +147,11 @@ void CWiresX::setInfo(const std::string& name, unsigned int txFrequency, unsigne
|
||||||
m_header[i + 14U] = m_node.at(i);
|
m_header[i + 14U] = m_node.at(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CWiresX::setParrot(const std::string& address, unsigned int port)
|
||||||
|
{
|
||||||
|
m_reflectors.setParrot(address, port);
|
||||||
|
}
|
||||||
|
|
||||||
bool CWiresX::start()
|
bool CWiresX::start()
|
||||||
{
|
{
|
||||||
return m_reflectors.load();
|
return m_reflectors.load();
|
||||||
|
|
|
@ -46,6 +46,7 @@ public:
|
||||||
~CWiresX();
|
~CWiresX();
|
||||||
|
|
||||||
void setInfo(const std::string& name, unsigned int txFrequency, unsigned int rxFrequency);
|
void setInfo(const std::string& name, unsigned int txFrequency, unsigned int rxFrequency);
|
||||||
|
void setParrot(const std::string& address, unsigned int port);
|
||||||
|
|
||||||
bool start();
|
bool start();
|
||||||
|
|
||||||
|
|
|
@ -205,6 +205,12 @@ int CYSFGateway::run()
|
||||||
|
|
||||||
m_wiresX->setInfo(name, txFrequency, rxFrequency);
|
m_wiresX->setInfo(name, txFrequency, rxFrequency);
|
||||||
|
|
||||||
|
std::string address = m_conf.getNetworkParrotAddress();
|
||||||
|
unsigned int port = m_conf.getNetworkParrotPort();
|
||||||
|
|
||||||
|
if (port > 0U)
|
||||||
|
m_wiresX->setParrot(address, port);
|
||||||
|
|
||||||
m_wiresX->start();
|
m_wiresX->start();
|
||||||
|
|
||||||
m_startup = m_conf.getNetworkStartup();
|
m_startup = m_conf.getNetworkStartup();
|
||||||
|
|
|
@ -37,5 +37,7 @@ Enable=1
|
||||||
DataPort=42000
|
DataPort=42000
|
||||||
Hosts=./YSFHosts.txt
|
Hosts=./YSFHosts.txt
|
||||||
ReloadTime=60
|
ReloadTime=60
|
||||||
|
ParrotAddress=127.0.0.1
|
||||||
|
ParrotPort=42000
|
||||||
# Startup=
|
# Startup=
|
||||||
Debug=0
|
Debug=0
|
||||||
|
|
Loading…
Add table
Reference in a new issue