Skip to content

Commit

Permalink
Add the optional DMR network options command.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Nov 3, 2016
1 parent 2a5162d commit 34538d8
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ m_dmrNetworkAddress(),
m_dmrNetworkPort(0U),
m_dmrNetworkLocal(0U),
m_dmrNetworkPassword(),
m_dmrNetworkOptions(),
m_dmrNetworkDebug(false),
m_dmrNetworkJitter(300U),
m_dmrNetworkSlot1(true),
Expand Down Expand Up @@ -506,6 +507,8 @@ bool CConf::read()
m_dmrNetworkLocal = (unsigned int)::atoi(value);
else if (::strcmp(key, "Password") == 0)
m_dmrNetworkPassword = value;
else if (::strcmp(key, "Options") == 0)
m_dmrNetworkOptions = value;
else if (::strcmp(key, "Debug") == 0)
m_dmrNetworkDebug = ::atoi(value) == 1;
else if (::strcmp(key, "Jitter") == 0)
Expand Down Expand Up @@ -590,7 +593,6 @@ bool CConf::read()
m_oledBrightness = (unsigned char)::atoi(value);
else if (::strcmp(key, "Brightness") == 0)
m_oledInvert = (unsigned char)::atoi(value);

} else if (section == SECTION_LCDPROC) {
if (::strcmp(key, "Address") == 0)
m_lcdprocAddress = value;
Expand Down Expand Up @@ -1017,6 +1019,11 @@ std::string CConf::getDMRNetworkPassword() const
return m_dmrNetworkPassword;
}

std::string CConf::getDMRNetworkOptions() const
{
return m_dmrNetworkOptions;
}

bool CConf::getDMRNetworkDebug() const
{
return m_dmrNetworkDebug;
Expand Down
2 changes: 2 additions & 0 deletions Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class CConf
unsigned int getDMRNetworkPort() const;
unsigned int getDMRNetworkLocal() const;
std::string getDMRNetworkPassword() const;
std::string getDMRNetworkOptions() const;
bool getDMRNetworkDebug() const;
unsigned int getDMRNetworkJitter() const;
bool getDMRNetworkSlot1() const;
Expand Down Expand Up @@ -288,6 +289,7 @@ class CConf
unsigned int m_dmrNetworkPort;
unsigned int m_dmrNetworkLocal;
std::string m_dmrNetworkPassword;
std::string m_dmrNetworkOptions;
bool m_dmrNetworkDebug;
unsigned int m_dmrNetworkJitter;
bool m_dmrNetworkSlot1;
Expand Down
28 changes: 28 additions & 0 deletions DMRNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ m_buffer(NULL),
m_salt(NULL),
m_streamId(NULL),
m_rxData(1000U, "DMR Network"),
m_options(),
m_callsign(),
m_rxFrequency(0U),
m_txFrequency(0U),
Expand Down Expand Up @@ -97,6 +98,11 @@ CDMRNetwork::~CDMRNetwork()
delete[] m_id;
}

void CDMRNetwork::setOptions(const std::string& options)
{
m_options = options;
}

void CDMRNetwork::setConfig(const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, unsigned int power, unsigned int colorCode, float latitude, float longitude, int height, const std::string& location, const std::string& description, const std::string& url)
{
m_callsign = callsign;
Expand Down Expand Up @@ -362,6 +368,17 @@ void CDMRNetwork::clock(unsigned int ms)
m_retryTimer.start();
break;
case WAITING_AUTHORISATION:
if (m_options.empty()) {
writeConfig();
m_status = WAITING_CONFIG;
} else {
writeOptions();
m_status = WAITING_OPTIONS;
}
m_timeoutTimer.start();
m_retryTimer.start();
break;
case WAITING_OPTIONS:
writeConfig();
m_status = WAITING_CONFIG;
m_timeoutTimer.start();
Expand Down Expand Up @@ -398,6 +415,9 @@ void CDMRNetwork::clock(unsigned int ms)
case WAITING_AUTHORISATION:
writeAuthorisation();
break;
case WAITING_OPTIONS:
writeOptions();
break;
case WAITING_CONFIG:
writeConfig();
break;
Expand Down Expand Up @@ -450,6 +470,14 @@ bool CDMRNetwork::writeAuthorisation()
return write(out, 40U);
}

bool CDMRNetwork::writeOptions()
{
char buffer[300U];
::sprintf(buffer, "RPTO%s", m_options.c_str());

return write((unsigned char*)buffer, (unsigned int)::strlen(buffer));
}

bool CDMRNetwork::writeConfig()
{
const char* software = "MMDVM";
Expand Down
6 changes: 6 additions & 0 deletions DMRNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class CDMRNetwork
CDMRNetwork(const std::string& address, unsigned int port, unsigned int local, unsigned int id, const std::string& password, bool duplex, const char* version, bool debug, bool slot1, bool slot2, bool rssi, HW_TYPE hwType);
~CDMRNetwork();

void setOptions(const std::string& options);

void setConfig(const std::string& callsign, unsigned int rxFrequency, unsigned int txFrequency, unsigned int power, unsigned int colorCode, float latitude, float longitude, int height, const std::string& location, const std::string& description, const std::string& url);

bool open();
Expand Down Expand Up @@ -69,6 +71,7 @@ class CDMRNetwork
WAITING_CONNECT,
WAITING_LOGIN,
WAITING_AUTHORISATION,
WAITING_OPTIONS,
WAITING_CONFIG,
RUNNING
};
Expand All @@ -82,6 +85,8 @@ class CDMRNetwork

CRingBuffer<unsigned char> m_rxData;

std::string m_options;

std::string m_callsign;
unsigned int m_rxFrequency;
unsigned int m_txFrequency;
Expand All @@ -98,6 +103,7 @@ class CDMRNetwork

bool writeLogin();
bool writeAuthorisation();
bool writeOptions();
bool writeConfig();
bool writePing();

Expand Down
1 change: 1 addition & 0 deletions MMDVM.ini
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Port=62031
Jitter=300
# Local=3350
Password=PASSWORD
# Options=
RSSI=0
Slot1=1
Slot2=1
Expand Down
6 changes: 6 additions & 0 deletions MMDVMHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,12 @@ bool CMMDVMHost::createDMRNetwork()

m_dmrNetwork = new CDMRNetwork(address, port, local, id, password, m_duplex, VERSION, debug, slot1, slot2, rssi, hwType);

std::string options = m_conf.getDMRNetworkOptions();
if (!options.empty()) {
LogInfo(" Options: %s", options.c_str());
m_dmrNetwork->setOptions(options);
}

unsigned int rxFrequency = m_conf.getRxFrequency();
unsigned int txFrequency = m_conf.getTxFrequency();
unsigned int power = m_conf.getPower();
Expand Down

0 comments on commit 34538d8

Please sign in to comment.