1
0
Fork 0

Allow for an optional local Parrot entry.

ycs232-kbc
Jonathan Naylor 8 years ago
parent 6f6d27ebf3
commit 20485f5d02

@ -64,6 +64,8 @@ m_networkEnabled(false),
m_networkDataPort(0U),
m_networkHosts(),
m_networkReloadTime(0U),
m_networkParrotAddress("127.0.0.1"),
m_networkParrotPort(0U),
m_networkStartup(),
m_networkDebug(false)
{
@ -175,6 +177,10 @@ bool CConf::read()
m_networkHosts = value;
else if (::strcmp(key, "ReloadTime") == 0)
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)
m_networkStartup = value;
else if (::strcmp(key, "Debug") == 0)
@ -322,6 +328,16 @@ unsigned int CConf::getNetworkReloadTime() const
return m_networkReloadTime;
}
std::string CConf::getNetworkParrotAddress() const
{
return m_networkParrotAddress;
}
unsigned int CConf::getNetworkParrotPort() const
{
return m_networkParrotPort;
}
std::string CConf::getNetworkStartup() const
{
return m_networkStartup;

@ -66,6 +66,8 @@ public:
unsigned int getNetworkDataPort() const;
std::string getNetworkHosts() const;
unsigned int getNetworkReloadTime() const;
std::string getNetworkParrotAddress() const;
unsigned int getNetworkParrotPort() const;
std::string getNetworkStartup() const;
bool getNetworkDebug() const;
@ -102,6 +104,8 @@ private:
unsigned int m_networkDataPort;
std::string m_networkHosts;
unsigned int m_networkReloadTime;
std::string m_networkParrotAddress;
unsigned int m_networkParrotPort;
std::string m_networkStartup;
bool m_networkDebug;
};

@ -28,6 +28,8 @@
CReflectors::CReflectors(const std::string& hostsFile, unsigned int reloadTime) :
m_hostsFile(hostsFile),
m_parrotAddress(),
m_parrotPort(0U),
m_reflectors(),
m_search(),
m_timer(1000U, reloadTime * 60U)
@ -61,20 +63,22 @@ static bool refComparison(const CYSFReflector* r1, const CYSFReflector* r2)
return false;
}
bool CReflectors::load()
void CReflectors::setParrot(const std::string& address, unsigned int port)
{
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;
m_parrotAddress = address;
m_parrotPort = port;
}
bool CReflectors::load()
{
// Clear out the old reflector list
for (std::vector<CYSFReflector*>::iterator it = m_reflectors.begin(); it != m_reflectors.end(); ++it)
delete *it;
m_reflectors.clear();
FILE* fp = ::fopen(m_hostsFile.c_str(), "rt");
if (fp != NULL) {
char buffer[100U];
while (::fgets(buffer, 100U, fp) != NULL) {
if (buffer[0U] == '#')
@ -109,6 +113,19 @@ bool CReflectors::load()
}
::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();
if (size == 0U)

@ -50,6 +50,8 @@ public:
CReflectors(const std::string& hostsFile, unsigned int reloadTime);
~CReflectors();
void setParrot(const std::string& address, unsigned int port);
bool load();
CYSFReflector* find(const std::string& id);
@ -62,6 +64,8 @@ public:
private:
std::string m_hostsFile;
std::string m_parrotAddress;
unsigned int m_parrotPort;
std::vector<CYSFReflector*> m_reflectors;
std::vector<CYSFReflector*> m_search;
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);
}
void CWiresX::setParrot(const std::string& address, unsigned int port)
{
m_reflectors.setParrot(address, port);
}
bool CWiresX::start()
{
return m_reflectors.load();

@ -46,6 +46,7 @@ public:
~CWiresX();
void setInfo(const std::string& name, unsigned int txFrequency, unsigned int rxFrequency);
void setParrot(const std::string& address, unsigned int port);
bool start();

@ -205,6 +205,12 @@ int CYSFGateway::run()
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_startup = m_conf.getNetworkStartup();

@ -37,5 +37,7 @@ Enable=1
DataPort=42000
Hosts=./YSFHosts.txt
ReloadTime=60
ParrotAddress=127.0.0.1
ParrotPort=42000
# Startup=
Debug=0

Loading…
Cancel
Save