mirror of
https://github.com/g4klx/DMRGateway
synced 2025-12-22 22:45:36 +08:00
Implement remote command support.
- Defaut port is 7643 (totally arbitrary)
- Using RemoteCommandDMRG, each network can be enabled or disabled (net1 .. net5, xlx):
~ $ RemoteCommandDMRG 7643 disable net2
M: 2021-03-20 11:48:40.494 Command sent: "disable net2" to port: 7643
M: 2021-03-20 11:48:40.545 OK
- Using RemoteCommandDMRG, a connection status can be retrieved:
~ $ RemoteCommandDMRG 7643 status
M: 2021-03-20 11:49:13.513 Command sent: "status" to port: 7643
M: 2021-03-20 11:49:13.563 xlx:conn net1:conn net2:n/a net3:n/a net4:conn net5:n/a
A returned string is expected from the socket connection, this is why I did not reuse the MMDVMHost's RemoteCommand (unless MMDVMHost RemoteControl is modified as well).
The exit value can be used in scripting (also 1 if we didn't get any reply).
This commit is contained in:
@@ -40,6 +40,7 @@ m_name(name),
|
||||
m_location(location),
|
||||
m_debug(debug),
|
||||
m_socket(local),
|
||||
m_enabled(false),
|
||||
m_status(WAITING_CONNECT),
|
||||
m_retryTimer(1000U, 10U),
|
||||
m_timeoutTimer(1000U, 60U),
|
||||
@@ -108,6 +109,14 @@ bool CDMRNetwork::open()
|
||||
return true;
|
||||
}
|
||||
|
||||
void CDMRNetwork::enable(bool enabled)
|
||||
{
|
||||
if (!enabled && m_enabled)
|
||||
m_rxData.clear();
|
||||
|
||||
m_enabled = enabled;
|
||||
}
|
||||
|
||||
bool CDMRNetwork::read(CDMRData& data)
|
||||
{
|
||||
if (m_status != RUNNING)
|
||||
@@ -345,9 +354,11 @@ void CDMRNetwork::clock(unsigned int ms)
|
||||
if (m_debug)
|
||||
CUtils::dump(1U, "Network Received", m_buffer, length);
|
||||
|
||||
unsigned char len = length;
|
||||
m_rxData.addData(&len, 1U);
|
||||
m_rxData.addData(m_buffer, len);
|
||||
if (m_enabled) {
|
||||
unsigned char len = length;
|
||||
m_rxData.addData(&len, 1U);
|
||||
m_rxData.addData(m_buffer, len);
|
||||
}
|
||||
} else if (::memcmp(m_buffer, "MSTNAK", 6U) == 0) {
|
||||
if (m_status == RUNNING) {
|
||||
LogWarning("%s, Login to the master has failed, retrying login ...", m_name.c_str());
|
||||
|
||||
Reference in New Issue
Block a user