Skip to content

Commit

Permalink
Add RemoteCommand 'status' command.
Browse files Browse the repository at this point in the history
As DMRGateway, it reports connection status.

Command sent: "status" to port: 7642
dstar:n/a dmr:conn ysf:n/a p25:n/a nxdn:n/a fm:n/a

RemoveCommand has been slighlty modified, as using Log on a read-only filesystem simply forbids the strings to be displayed.
Another solution would be to set LogInitialisse's filePath to "/tmp/" for *nix systems.
  • Loading branch information
f1rmb committed Mar 22, 2021
1 parent 0088b0b commit 27b7d3f
Show file tree
Hide file tree
Showing 21 changed files with 90 additions and 9 deletions.
5 changes: 5 additions & 0 deletions DMRDirectNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ bool CDMRDirectNetwork::writeTalkerAlias(unsigned int id, unsigned char type, co
return write(buffer, 15U);
}

bool CDMRDirectNetwork::isConnected() const
{
return (m_status == RUNNING);
}

void CDMRDirectNetwork::close()
{
LogMessage("Closing DMR Network");
Expand Down
2 changes: 2 additions & 0 deletions DMRDirectNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class CDMRDirectNetwork : public IDMRNetwork

virtual void clock(unsigned int ms);

virtual bool isConnected() const;

virtual void close();

private:
Expand Down
5 changes: 5 additions & 0 deletions DMRGatewayNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ bool CDMRGatewayNetwork::writeTalkerAlias(unsigned int id, unsigned char type, c
return write(buffer, 15U);
}

bool CDMRGatewayNetwork::isConnected() const
{
return (m_enabled && (m_addrLen != 0));
}

void CDMRGatewayNetwork::close()
{
LogMessage("DMR, Closing DMR Network");
Expand Down
2 changes: 2 additions & 0 deletions DMRGatewayNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class CDMRGatewayNetwork : public IDMRNetwork

virtual void clock(unsigned int ms);

virtual bool isConnected() const;

virtual void close();

private:
Expand Down
2 changes: 2 additions & 0 deletions DMRNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class IDMRNetwork

virtual void clock(unsigned int ms) = 0;

virtual bool isConnected() const = 0;

virtual void close() = 0;

private:
Expand Down
5 changes: 5 additions & 0 deletions DStarNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ void CDStarNetwork::reset()
m_inId = 0U;
}

bool CDStarNetwork::isConnected() const
{
return (m_enabled && (m_addrLen != 0));
}

void CDStarNetwork::close()
{
m_socket.close();
Expand Down
2 changes: 2 additions & 0 deletions DStarNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class CDStarNetwork {

void reset();

bool isConnected() const;

void close();

void clock(unsigned int ms);
Expand Down
13 changes: 12 additions & 1 deletion MMDVMHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ int CMMDVMHost::run()
LogInfo(" Address: %s", address.c_str());
LogInfo(" Port: %u", port);

m_remoteControl = new CRemoteControl(address, port);
m_remoteControl = new CRemoteControl(this, address, port);

ret = m_remoteControl->open();
if (!ret) {
Expand Down Expand Up @@ -2140,3 +2140,14 @@ void CMMDVMHost::processEnableCommand(bool& mode, bool enabled)
if (!m_modem->writeConfig())
LogError("Cannot write Config to MMDVM");
}

void CMMDVMHost::buildNetworkStatusString(std::string &str)
{
str = "";
str += std::string("dstar:") + (((m_dstarNetwork == NULL) || (m_dstarEnabled == false)) ? "n/a" : (m_dstarNetwork->isConnected() ? "conn" : "disc"));
str += std::string(" dmr:") + (((m_dmrNetwork == NULL) || (m_dmrEnabled == false)) ? "n/a" : (m_dmrNetwork->isConnected() ? "conn" : "disc"));
str += std::string(" ysf:") + (((m_ysfNetwork == NULL) || (m_ysfEnabled == false)) ? "n/a" : (m_ysfNetwork->isConnected() ? "conn" : "disc"));
str += std::string(" p25:") + (((m_p25Network == NULL) || (m_p25Enabled == false)) ? "n/a" : (m_p25Network->isConnected() ? "conn" : "disc"));
str += std::string(" nxdn:") + (((m_nxdnNetwork == NULL) || (m_nxdnEnabled == false)) ? "n/a" : (m_nxdnNetwork->isConnected() ? "conn" : "disc"));
str += std::string(" fm:") + (m_fmEnabled ? "conn" : "n/a");
}
2 changes: 2 additions & 0 deletions MMDVMHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class CMMDVMHost

int run();

void buildNetworkStatusString(std::string &str);

private:
CConf m_conf;
CModem* m_modem;
Expand Down
5 changes: 5 additions & 0 deletions NXDNIcomNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ void CNXDNIcomNetwork::reset()
{
}

bool CNXDNIcomNetwork::isConnected() const
{
return (m_enabled && (m_addrLen != 0));
}

void CNXDNIcomNetwork::close()
{
m_socket.close();
Expand Down
2 changes: 2 additions & 0 deletions NXDNIcomNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class CNXDNIcomNetwork : public INXDNNetwork {

virtual void reset();

virtual bool isConnected() const;

virtual void close();

virtual void clock(unsigned int ms);
Expand Down
5 changes: 5 additions & 0 deletions NXDNKenwoodNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,11 @@ void CNXDNKenwoodNetwork::reset()
m_seen4 = false;
}

bool CNXDNKenwoodNetwork::isConnected() const
{
return (m_enabled && (m_rtcpAddrLen != 0U) && (m_rtpAddrLen != 0U));
}

void CNXDNKenwoodNetwork::close()
{
m_rtcpSocket.close();
Expand Down
2 changes: 2 additions & 0 deletions NXDNKenwoodNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class CNXDNKenwoodNetwork : public INXDNNetwork {

virtual void reset();

virtual bool isConnected() const;

virtual void close();

virtual void clock(unsigned int ms);
Expand Down
2 changes: 2 additions & 0 deletions NXDNNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class INXDNNetwork {

virtual void reset() = 0;

virtual bool isConnected() const = 0;

virtual void close() = 0;

virtual void clock(unsigned int ms) = 0;
Expand Down
5 changes: 5 additions & 0 deletions P25Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,11 @@ unsigned int CP25Network::read(unsigned char* data, unsigned int length)
return c;
}

bool CP25Network::isConnected() const
{
return (m_enabled && (m_addrLen != 0));
}

void CP25Network::close()
{
m_socket.close();
Expand Down
2 changes: 2 additions & 0 deletions P25Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class CP25Network {

unsigned int read(unsigned char* data, unsigned int length);

bool isConnected() const;

void close();

void clock(unsigned int ms);
Expand Down
8 changes: 4 additions & 4 deletions RemoteCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int CRemoteCommand::send(const std::string& command)
int retStatus = 0;

if (CUDPSocket::lookup("127.0.0.1", m_port, addr, addrLen) != 0) {
LogError("Unable to resolve the address of the host");
::fprintf(stderr, "Unable to resolve the address of the host\n");
return 1;
}

Expand All @@ -91,14 +91,14 @@ int CRemoteCommand::send(const std::string& command)
return 1;
}

LogMessage("Command sent: \"%s\" to port: %u", command.c_str(), m_port);
::fprintf(stdout, "Command sent: \"%s\" to port: %u\n", command.c_str(), m_port);

std::this_thread::sleep_for(std::chrono::milliseconds(50));

int len = socket.read((unsigned char*)&buffer[0], BUFFER_LENGTH, addr, addrLen);
int len = socket.read((unsigned char*)buffer, BUFFER_LENGTH, addr, addrLen);
if (len > 0) {
buffer[len] = '\0';
LogMessage("%s", buffer);
::fprintf(stdout, "%s\n", buffer);
}
else
{
Expand Down
15 changes: 13 additions & 2 deletions RemoteControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

#include "RemoteControl.h"
#include "MMDVMHost.h"
#include "Log.h"

#include <cstdio>
Expand All @@ -32,7 +33,8 @@ const unsigned int CW_ARGS = 2U;

const unsigned int BUFFER_LENGTH = 100U;

CRemoteControl::CRemoteControl(const std::string address, unsigned int port) :
CRemoteControl::CRemoteControl(CMMDVMHost *host, const std::string address, unsigned int port) :
m_host(host),
m_socket(address, port),
m_command(RCD_NONE),
m_args()
Expand Down Expand Up @@ -131,7 +133,16 @@ REMOTE_COMMAND CRemoteControl::getCommand()
} else if (m_args.at(0U) == "reload") {
// Reload command is in the form of "reload"
m_command = RCD_RELOAD;
}
} else if (m_args.at(0U) == "status") {
if (m_host != NULL) {
m_host->buildNetworkStatusString(replyStr);
}
else {
replyStr = "KO";
}

m_command = RCD_CONNECTION_STATUS;
}
else
replyStr = "KO";

Expand Down
8 changes: 6 additions & 2 deletions RemoteControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <vector>
#include <string>

class CMMDVMHost;

enum REMOTE_COMMAND {
RCD_NONE,
RCD_MODE_IDLE,
Expand All @@ -48,12 +50,13 @@ enum REMOTE_COMMAND {
RCD_DISABLE_FM,
RCD_PAGE,
RCD_CW,
RCD_RELOAD
RCD_RELOAD,
RCD_CONNECTION_STATUS
};

class CRemoteControl {
public:
CRemoteControl(const std::string address, unsigned int port);
CRemoteControl(class CMMDVMHost *host, const std::string address, unsigned int port);
~CRemoteControl();

bool open();
Expand All @@ -69,6 +72,7 @@ class CRemoteControl {
void close();

private:
CMMDVMHost* m_host;
CUDPSocket m_socket;
REMOTE_COMMAND m_command;
std::vector<std::string> m_args;
Expand Down
5 changes: 5 additions & 0 deletions YSFNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ void CYSFNetwork::reset()
::memset(m_tag, ' ', YSF_CALLSIGN_LENGTH);
}

bool CYSFNetwork::isConnected() const
{
return (m_enabled && (m_addrLen != 0));
}

void CYSFNetwork::close()
{
m_socket.close();
Expand Down
2 changes: 2 additions & 0 deletions YSFNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class CYSFNetwork {

void reset();

bool isConnected() const;

void close();

void clock(unsigned int ms);
Expand Down

0 comments on commit 27b7d3f

Please sign in to comment.