Allow for info override.

This commit is contained in:
Jonathan Naylor
2017-10-08 14:13:52 +01:00
parent b4b9860ad9
commit fc2c027604
5 changed files with 173 additions and 6 deletions

View File

@@ -31,6 +31,7 @@ enum SECTION {
SECTION_GENERAL,
SECTION_LOG,
SECTION_VOICE,
SECTION_INFO,
SECTION_DMR_NETWORK_1,
SECTION_DMR_NETWORK_2,
SECTION_XLX_NETWORK
@@ -54,6 +55,16 @@ m_logDisplayLevel(0U),
m_logFileLevel(0U),
m_logFilePath(),
m_logFileRoot(),
m_infoEnabled(false),
m_infoRXFrequency(0U),
m_infoTXFrequency(0U),
m_infoPower(0U),
m_infoLatitude(0.0F),
m_infoLongitude(0.0F),
m_infoHeight(0),
m_infoLocation(),
m_infoDescription(),
m_infoURL(),
m_dmrNetwork1Enabled(false),
m_dmrNetwork1Name(),
m_dmrNetwork1Id(0U),
@@ -128,6 +139,8 @@ bool CConf::read()
section = SECTION_LOG;
else if (::strncmp(buffer, "[Voice]", 7U) == 0)
section = SECTION_VOICE;
else if (::strncmp(buffer, "[Info]", 6U) == 0)
section = SECTION_INFO;
else if (::strncmp(buffer, "[XLX Network]", 13U) == 0)
section = SECTION_XLX_NETWORK;
else if (::strncmp(buffer, "[DMR Network 1]", 15U) == 0)
@@ -185,6 +198,27 @@ bool CConf::read()
m_voiceLanguage = value;
else if (::strcmp(key, "Directory") == 0)
m_voiceDirectory = value;
} else if (section == SECTION_INFO) {
if (::strcmp(key, "Enabled") == 0)
m_infoEnabled = ::atoi(value) == 1;
else if (::strcmp(key, "TXFrequency") == 0)
m_infoTXFrequency = (unsigned int)::atoi(value);
else if (::strcmp(key, "RXFrequency") == 0)
m_infoRXFrequency = (unsigned int)::atoi(value);
else if (::strcmp(key, "Power") == 0)
m_infoPower = (unsigned int)::atoi(value);
else if (::strcmp(key, "Latitude") == 0)
m_infoLatitude = float(::atof(value));
else if (::strcmp(key, "Longitude") == 0)
m_infoLongitude = float(::atof(value));
else if (::strcmp(key, "Height") == 0)
m_infoHeight = ::atoi(value);
else if (::strcmp(key, "Location") == 0)
m_infoLocation = value;
else if (::strcmp(key, "Description") == 0)
m_infoDescription = value;
else if (::strcmp(key, "URL") == 0)
m_infoURL = value;
} else if (section == SECTION_XLX_NETWORK) {
if (::strcmp(key, "Enabled") == 0)
m_xlxNetworkEnabled = ::atoi(value) == 1;
@@ -472,6 +506,56 @@ std::string CConf::getVoiceDirectory() const
return m_voiceDirectory;
}
bool CConf::getInfoEnabled() const
{
return m_infoEnabled;
}
unsigned int CConf::getInfoRXFrequency() const
{
return m_infoRXFrequency;
}
unsigned int CConf::getInfoTXFrequency() const
{
return m_infoTXFrequency;
}
unsigned int CConf::getInfoPower() const
{
return m_infoPower;
}
float CConf::getInfoLatitude() const
{
return m_infoLatitude;
}
float CConf::getInfoLongitude() const
{
return m_infoLongitude;
}
int CConf::getInfoHeight() const
{
return m_infoHeight;
}
std::string CConf::getInfoLocation() const
{
return m_infoLocation;
}
std::string CConf::getInfoDescription() const
{
return m_infoDescription;
}
std::string CConf::getInfoURL() const
{
return m_infoURL;
}
bool CConf::getXLXNetworkEnabled() const
{
return m_xlxNetworkEnabled;

23
Conf.h
View File

@@ -83,6 +83,18 @@ public:
std::string getVoiceLanguage() const;
std::string getVoiceDirectory() const;
// The Info section
bool getInfoEnabled() const;
unsigned int getInfoRXFrequency() const;
unsigned int getInfoTXFrequency() const;
unsigned int getInfoPower() const;
float getInfoLatitude() const;
float getInfoLongitude() const;
int getInfoHeight() const;
std::string getInfoLocation() const;
std::string getInfoDescription() const;
std::string getInfoURL() const;
// The DMR Network 1 section
bool getDMRNetwork1Enabled() const;
std::string getDMRNetwork1Name() const;
@@ -155,6 +167,17 @@ private:
std::string m_logFilePath;
std::string m_logFileRoot;
bool m_infoEnabled;
unsigned int m_infoRXFrequency;
unsigned int m_infoTXFrequency;
unsigned int m_infoPower;
float m_infoLatitude;
float m_infoLongitude;
int m_infoHeight;
std::string m_infoLocation;
std::string m_infoDescription;
std::string m_infoURL;
bool m_dmrNetwork1Enabled;
std::string m_dmrNetwork1Name;
unsigned int m_dmrNetwork1Id;

View File

@@ -131,6 +131,8 @@ int main(int argc, char** argv)
CDMRGateway::CDMRGateway(const std::string& confFile) :
m_conf(confFile),
m_repeater(NULL),
m_config(NULL),
m_configLen(0U),
m_dmrNetwork1(NULL),
m_dmr1Name(),
m_dmrNetwork2(NULL),
@@ -160,6 +162,7 @@ m_dmr2RFRewrites(),
m_dmr1Passalls(),
m_dmr2Passalls()
{
m_config = new unsigned char[400U];
}
CDMRGateway::~CDMRGateway()
@@ -184,6 +187,8 @@ CDMRGateway::~CDMRGateway()
delete m_rptRewrite;
delete m_xlxRewrite;
delete[] m_config;
}
int CDMRGateway::run()
@@ -274,9 +279,8 @@ int CDMRGateway::run()
LogMessage("Waiting for MMDVM to connect.....");
while (!m_killed) {
unsigned char config[400U];
unsigned int len = m_repeater->getConfig(config);
if (len > 0U && m_repeater->getId() > 1000U)
m_configLen = m_repeater->getConfig(m_config);
if (m_configLen > 0U && m_repeater->getId() > 1000U)
break;
m_repeater->clock(10U);
@@ -878,7 +882,7 @@ bool CDMRGateway::createDMRNetwork1()
}
unsigned char config[400U];
unsigned int len = m_repeater->getConfig(config);
unsigned int len = getConfig(config);
if (!location)
::memcpy(config + 30U, "0.00000000.000000", 17U);
@@ -1005,7 +1009,7 @@ bool CDMRGateway::createDMRNetwork2()
}
unsigned char config[400U];
unsigned int len = m_repeater->getConfig(config);
unsigned int len = getConfig(config);
if (!location)
::memcpy(config + 30U, "0.00000000.000000", 17U);
@@ -1172,7 +1176,7 @@ bool CDMRGateway::linkXLX(unsigned int number)
m_xlxNetwork = new CDMRNetwork(reflector->m_address, m_xlxPort, m_xlxLocal, m_xlxId, m_xlxPassword, "XLX", m_xlxDebug);
unsigned char config[400U];
unsigned int len = m_repeater->getConfig(config);
unsigned int len = getConfig(config);
m_xlxNetwork->setConfig(config, len);
@@ -1258,3 +1262,43 @@ void CDMRGateway::writeXLXLink(unsigned int srcId, unsigned int dstId, CDMRNetwo
network->write(data);
}
}
unsigned int CDMRGateway::getConfig(unsigned char* buffer)
{
assert(buffer != NULL);
bool enabled = m_conf.getInfoEnabled();
if (!enabled) {
::memcpy(buffer, m_config, m_configLen);
return m_configLen;
}
char latitude[20U];
float lat = m_conf.getInfoLatitude();
::sprintf(latitude, "%08f", lat);
char longitude[20U];
float lon = m_conf.getInfoLongitude();
::sprintf(longitude, "%09f", lon);
unsigned int power = m_conf.getInfoPower();
if (power > 99U)
power = 99U;
int height = m_conf.getInfoHeight();
if (height > 999)
height = 999;
unsigned int rxFrequency = m_conf.getInfoRXFrequency();
unsigned int txFrequency = m_conf.getInfoTXFrequency();
std::string location = m_conf.getInfoLocation();
std::string description = m_conf.getInfoDescription();
std::string url = m_conf.getInfoURL();
::sprintf((char*)buffer, "%-8.8s%09u%09u%02u%2.2s%8.8s%9.9s%03d%-20.20s%-19.19s%c%-124.124s%-40.40s%-40.40s", m_config + 0U,
rxFrequency, txFrequency, power, m_config + 28U, latitude, longitude, height, location.c_str(),
description.c_str(), m_config[89U], url.c_str(), m_config + 214U, m_config + 254U);
return (unsigned int)::strlen((char*)buffer);
}

View File

@@ -41,6 +41,8 @@ public:
private:
CConf m_conf;
IRepeaterProtocol* m_repeater;
unsigned char* m_config;
unsigned int m_configLen;
CDMRNetwork* m_dmrNetwork1;
std::string m_dmr1Name;
CDMRNetwork* m_dmrNetwork2;
@@ -78,6 +80,8 @@ private:
bool linkXLX(unsigned int number);
void unlinkXLX();
void writeXLXLink(unsigned int srcId, unsigned int dstId, CDMRNetwork* network);
unsigned int getConfig(unsigned char* buffer);
};
#endif

View File

@@ -22,6 +22,18 @@ Enabled=1
Language=en_GB
Directory=./Audio
[Info]
Enabled=0
RXFrequency=435000000
TXFrequency=435000000
Power=1
Latitude=0.0
Longitude=0.0
Height=0
Location=Nowhere
Description=Multi-Mode Repeater
URL=www.google.co.uk
[XLX Network]
Enabled=1
File=XLXHosts.txt