mirror of
https://github.com/g4klx/MMDVMHost
synced 2025-12-21 23:45:49 +08:00
Merge branch 'master' into M17_AX25_FM
This commit is contained in:
@@ -22,6 +22,10 @@
|
|||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
const unsigned int BUFFER_LENGTH = 100U;
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
@@ -67,6 +71,9 @@ int CRemoteCommand::send(const std::string& command)
|
|||||||
{
|
{
|
||||||
sockaddr_storage addr;
|
sockaddr_storage addr;
|
||||||
unsigned int addrLen;
|
unsigned int addrLen;
|
||||||
|
char buffer[BUFFER_LENGTH];
|
||||||
|
int retStatus = 0;
|
||||||
|
|
||||||
if (CUDPSocket::lookup("127.0.0.1", m_port, addr, addrLen) != 0) {
|
if (CUDPSocket::lookup("127.0.0.1", m_port, addr, addrLen) != 0) {
|
||||||
LogError("Unable to resolve the address of the host");
|
LogError("Unable to resolve the address of the host");
|
||||||
return 1;
|
return 1;
|
||||||
@@ -86,7 +93,19 @@ int CRemoteCommand::send(const std::string& command)
|
|||||||
|
|
||||||
LogMessage("Command sent: \"%s\" to port: %u", command.c_str(), m_port);
|
LogMessage("Command sent: \"%s\" to port: %u", 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);
|
||||||
|
if (len > 0) {
|
||||||
|
buffer[len] = '\0';
|
||||||
|
LogMessage("%s", buffer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
retStatus = 1;
|
||||||
|
}
|
||||||
|
|
||||||
socket.close();
|
socket.close();
|
||||||
|
|
||||||
return 0;
|
return retStatus;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ REMOTE_COMMAND CRemoteControl::getCommand()
|
|||||||
m_args.clear();
|
m_args.clear();
|
||||||
|
|
||||||
char command[BUFFER_LENGTH];
|
char command[BUFFER_LENGTH];
|
||||||
char buffer[BUFFER_LENGTH];
|
char buffer[BUFFER_LENGTH * 2];
|
||||||
|
std::string replyStr = "OK";
|
||||||
sockaddr_storage address;
|
sockaddr_storage address;
|
||||||
unsigned int addrlen;
|
unsigned int addrlen;
|
||||||
int ret = m_socket.read((unsigned char*)buffer, BUFFER_LENGTH, address, addrlen);
|
int ret = m_socket.read((unsigned char*)buffer, BUFFER_LENGTH, address, addrlen);
|
||||||
@@ -91,6 +92,8 @@ REMOTE_COMMAND CRemoteControl::getCommand()
|
|||||||
m_command = RCD_MODE_NXDN;
|
m_command = RCD_MODE_NXDN;
|
||||||
else if (m_args.at(1U) == "m17")
|
else if (m_args.at(1U) == "m17")
|
||||||
m_command = RCD_MODE_M17;
|
m_command = RCD_MODE_M17;
|
||||||
|
else
|
||||||
|
replyStr = "KO";
|
||||||
} else if (m_args.at(0U) == "enable" && m_args.size() >= ENABLE_ARGS) {
|
} else if (m_args.at(0U) == "enable" && m_args.size() >= ENABLE_ARGS) {
|
||||||
if (m_args.at(1U) == "dstar")
|
if (m_args.at(1U) == "dstar")
|
||||||
m_command = RCD_ENABLE_DSTAR;
|
m_command = RCD_ENABLE_DSTAR;
|
||||||
@@ -108,6 +111,8 @@ REMOTE_COMMAND CRemoteControl::getCommand()
|
|||||||
m_command = RCD_ENABLE_FM;
|
m_command = RCD_ENABLE_FM;
|
||||||
else if (m_args.at(1U) == "ax25")
|
else if (m_args.at(1U) == "ax25")
|
||||||
m_command = RCD_ENABLE_AX25;
|
m_command = RCD_ENABLE_AX25;
|
||||||
|
else
|
||||||
|
replyStr = "KO";
|
||||||
} else if (m_args.at(0U) == "disable" && m_args.size() >= DISABLE_ARGS) {
|
} else if (m_args.at(0U) == "disable" && m_args.size() >= DISABLE_ARGS) {
|
||||||
if (m_args.at(1U) == "dstar")
|
if (m_args.at(1U) == "dstar")
|
||||||
m_command = RCD_DISABLE_DSTAR;
|
m_command = RCD_DISABLE_DSTAR;
|
||||||
@@ -125,6 +130,8 @@ REMOTE_COMMAND CRemoteControl::getCommand()
|
|||||||
m_command = RCD_DISABLE_FM;
|
m_command = RCD_DISABLE_FM;
|
||||||
else if (m_args.at(1U) == "ax25")
|
else if (m_args.at(1U) == "ax25")
|
||||||
m_command = RCD_DISABLE_AX25;
|
m_command = RCD_DISABLE_AX25;
|
||||||
|
else
|
||||||
|
replyStr = "KO";
|
||||||
} else if (m_args.at(0U) == "page" && m_args.size() >= PAGE_ARGS) {
|
} else if (m_args.at(0U) == "page" && m_args.size() >= PAGE_ARGS) {
|
||||||
// Page command is in the form of "page <ric> <message>"
|
// Page command is in the form of "page <ric> <message>"
|
||||||
m_command = RCD_PAGE;
|
m_command = RCD_PAGE;
|
||||||
@@ -135,13 +142,18 @@ REMOTE_COMMAND CRemoteControl::getCommand()
|
|||||||
// Reload command is in the form of "reload"
|
// Reload command is in the form of "reload"
|
||||||
m_command = RCD_RELOAD;
|
m_command = RCD_RELOAD;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
replyStr = "KO";
|
||||||
|
|
||||||
|
::snprintf(buffer, BUFFER_LENGTH * 2, "%s remote command of \"%s\" received", ((m_command == RCD_NONE) ? "Invalid" : "Valid"), command);
|
||||||
if (m_command == RCD_NONE) {
|
if (m_command == RCD_NONE) {
|
||||||
m_args.clear();
|
m_args.clear();
|
||||||
LogWarning("Invalid remote command of \"%s\" received", command);
|
LogWarning(buffer);
|
||||||
} else {
|
} else {
|
||||||
LogMessage("Valid remote command of \"%s\" received", command);
|
LogMessage(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_socket.write((unsigned char*)replyStr.c_str(), replyStr.length(), address, addrlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_command;
|
return m_command;
|
||||||
|
|||||||
Reference in New Issue
Block a user