2016-01-14 19:45:04 +01:00
|
|
|
/*
|
2021-01-01 14:54:03 +01:00
|
|
|
* Copyright (C) 2015-2021 by Jonathan Naylor G4KLX
|
2016-01-14 19:45:04 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "MMDVMHost.h"
|
2020-12-06 17:12:54 +01:00
|
|
|
#include "DMRDirectNetwork.h"
|
|
|
|
#include "DMRGatewayNetwork.h"
|
2016-12-21 20:58:46 +01:00
|
|
|
#include "RSSIInterpolator.h"
|
2021-02-17 20:35:28 +01:00
|
|
|
#include "NullController.h"
|
2021-02-16 21:05:03 +01:00
|
|
|
#include "UARTController.h"
|
2021-02-17 20:35:28 +01:00
|
|
|
#if defined(__linux__)
|
|
|
|
#include "I2CController.h"
|
|
|
|
#endif
|
2021-02-16 23:34:25 +01:00
|
|
|
#include "UDPController.h"
|
2016-01-14 19:45:04 +01:00
|
|
|
#include "Version.h"
|
|
|
|
#include "StopWatch.h"
|
|
|
|
#include "Defines.h"
|
2016-06-06 18:40:27 +02:00
|
|
|
#include "Thread.h"
|
2016-10-06 19:38:16 +02:00
|
|
|
#include "Log.h"
|
2017-03-10 05:22:33 +01:00
|
|
|
#include "GitVersion.h"
|
2016-01-14 19:45:04 +01:00
|
|
|
|
|
|
|
#include <cstdio>
|
2016-04-04 20:03:38 +02:00
|
|
|
#include <vector>
|
2016-01-14 19:45:04 +01:00
|
|
|
|
2018-07-04 20:00:51 +02:00
|
|
|
#include <cstdlib>
|
2016-01-14 19:45:04 +01:00
|
|
|
|
2016-01-14 20:58:16 +01:00
|
|
|
#if !defined(_WIN32) && !defined(_WIN64)
|
2016-05-05 19:06:05 +02:00
|
|
|
#include <sys/types.h>
|
2016-01-14 19:45:04 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
2016-05-04 00:01:49 +02:00
|
|
|
#include <fcntl.h>
|
2016-05-04 21:06:15 +02:00
|
|
|
#include <pwd.h>
|
2016-05-04 00:01:49 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
2016-05-05 18:56:18 +02:00
|
|
|
const char* DEFAULT_INI_FILE = "MMDVM.ini";
|
2016-05-04 00:01:49 +02:00
|
|
|
#else
|
2016-05-04 22:00:12 +02:00
|
|
|
const char* DEFAULT_INI_FILE = "/etc/MMDVM.ini";
|
2016-01-14 19:45:04 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static bool m_killed = false;
|
2016-05-04 00:01:49 +02:00
|
|
|
static int m_signal = 0;
|
2021-01-01 14:54:03 +01:00
|
|
|
static bool m_reload = false;
|
2016-01-14 19:45:04 +01:00
|
|
|
|
2016-01-14 20:58:16 +01:00
|
|
|
#if !defined(_WIN32) && !defined(_WIN64)
|
2021-01-01 14:54:03 +01:00
|
|
|
static void sigHandler1(int signum)
|
2016-01-14 19:45:04 +01:00
|
|
|
{
|
2017-05-03 15:53:48 +02:00
|
|
|
m_killed = true;
|
|
|
|
m_signal = signum;
|
2016-01-14 19:45:04 +01:00
|
|
|
}
|
2021-01-01 14:54:03 +01:00
|
|
|
|
|
|
|
static void sigHandler2(int signum)
|
|
|
|
{
|
|
|
|
m_reload = true;
|
|
|
|
}
|
2016-01-14 19:45:04 +01:00
|
|
|
#endif
|
|
|
|
|
2022-07-29 23:59:37 +02:00
|
|
|
const char* HEADER1 = "Modified MMDVM Host by Carsten Schmiemann 2022";
|
2022-07-30 00:01:42 +02:00
|
|
|
const char* HEADER2 = "----------------------------------------------";
|
|
|
|
const char* HEADER3 = "DMR Mode only, board will be locked to DMR";
|
|
|
|
const char* HEADER4 = "Original project by gk4lx";
|
2016-01-14 19:45:04 +01:00
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2017-05-03 15:53:48 +02:00
|
|
|
const char* iniFile = DEFAULT_INI_FILE;
|
|
|
|
if (argc > 1) {
|
|
|
|
for (int currentArg = 1; currentArg < argc; ++currentArg) {
|
|
|
|
std::string arg = argv[currentArg];
|
|
|
|
if ((arg == "-v") || (arg == "--version")) {
|
|
|
|
::fprintf(stdout, "MMDVMHost version %s git #%.7s\n", VERSION, gitversion);
|
|
|
|
return 0;
|
|
|
|
} else if (arg.substr(0,1) == "-") {
|
|
|
|
::fprintf(stderr, "Usage: MMDVMHost [-v|--version] [filename]\n");
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
iniFile = argv[currentArg];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-14 19:45:04 +01:00
|
|
|
|
2016-01-14 20:58:16 +01:00
|
|
|
#if !defined(_WIN32) && !defined(_WIN64)
|
2021-01-01 14:54:03 +01:00
|
|
|
::signal(SIGINT, sigHandler1);
|
|
|
|
::signal(SIGTERM, sigHandler1);
|
|
|
|
::signal(SIGHUP, sigHandler1);
|
|
|
|
::signal(SIGUSR1, sigHandler2);
|
2016-01-14 19:45:04 +01:00
|
|
|
#endif
|
|
|
|
|
2017-05-03 15:53:48 +02:00
|
|
|
int ret = 0;
|
2016-01-14 19:45:04 +01:00
|
|
|
|
2017-05-03 15:53:48 +02:00
|
|
|
do {
|
|
|
|
m_signal = 0;
|
2016-01-14 19:45:04 +01:00
|
|
|
|
2017-05-03 15:53:48 +02:00
|
|
|
CMMDVMHost* host = new CMMDVMHost(std::string(iniFile));
|
|
|
|
ret = host->run();
|
2016-05-04 00:01:49 +02:00
|
|
|
|
2017-05-03 15:53:48 +02:00
|
|
|
delete host;
|
2016-05-04 07:35:20 +02:00
|
|
|
|
2017-06-08 11:17:00 +02:00
|
|
|
if (m_signal == 2)
|
2017-06-08 12:44:01 +02:00
|
|
|
::LogInfo("MMDVMHost-%s exited on receipt of SIGINT", VERSION);
|
2017-06-08 11:17:00 +02:00
|
|
|
|
2017-05-03 15:53:48 +02:00
|
|
|
if (m_signal == 15)
|
2017-06-08 12:44:01 +02:00
|
|
|
::LogInfo("MMDVMHost-%s exited on receipt of SIGTERM", VERSION);
|
2016-05-04 07:35:20 +02:00
|
|
|
|
2017-05-03 15:53:48 +02:00
|
|
|
if (m_signal == 1)
|
2017-06-08 11:17:00 +02:00
|
|
|
::LogInfo("MMDVMHost-%s is restarting on receipt of SIGHUP", VERSION);
|
2017-05-03 15:53:48 +02:00
|
|
|
} while (m_signal == 1);
|
2016-05-04 00:01:49 +02:00
|
|
|
|
2017-05-03 15:53:48 +02:00
|
|
|
::LogFinalise();
|
2016-01-14 19:45:04 +01:00
|
|
|
|
2017-05-03 15:53:48 +02:00
|
|
|
return ret;
|
2016-01-14 19:45:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CMMDVMHost::CMMDVMHost(const std::string& confFile) :
|
|
|
|
m_conf(confFile),
|
|
|
|
m_modem(NULL),
|
2019-01-10 10:05:15 +01:00
|
|
|
m_dmr(NULL),
|
2016-01-14 19:45:04 +01:00
|
|
|
m_dmrNetwork(NULL),
|
|
|
|
m_display(NULL),
|
2016-02-02 19:17:36 +01:00
|
|
|
m_mode(MODE_IDLE),
|
2017-09-01 10:25:54 +02:00
|
|
|
m_dstarRFModeHang(10U),
|
|
|
|
m_dmrRFModeHang(10U),
|
|
|
|
m_ysfRFModeHang(10U),
|
|
|
|
m_p25RFModeHang(10U),
|
2018-01-11 20:35:33 +01:00
|
|
|
m_nxdnRFModeHang(10U),
|
2020-12-15 17:21:07 +01:00
|
|
|
m_m17RFModeHang(10U),
|
|
|
|
m_fmRFModeHang(10U),
|
2017-09-01 10:25:54 +02:00
|
|
|
m_dstarNetModeHang(3U),
|
|
|
|
m_dmrNetModeHang(3U),
|
|
|
|
m_ysfNetModeHang(3U),
|
|
|
|
m_p25NetModeHang(3U),
|
2018-01-11 20:35:33 +01:00
|
|
|
m_nxdnNetModeHang(3U),
|
2020-12-15 17:21:07 +01:00
|
|
|
m_m17NetModeHang(3U),
|
2018-06-07 19:46:03 +02:00
|
|
|
m_pocsagNetModeHang(3U),
|
2020-12-15 17:21:07 +01:00
|
|
|
m_fmNetModeHang(3U),
|
2016-02-02 19:17:36 +01:00
|
|
|
m_modeTimer(1000U),
|
2016-05-05 18:56:18 +02:00
|
|
|
m_dmrTXTimer(1000U),
|
2016-05-09 22:55:44 +02:00
|
|
|
m_cwIdTimer(1000U),
|
2016-03-07 20:45:19 +01:00
|
|
|
m_duplex(false),
|
2016-06-22 19:03:56 +02:00
|
|
|
m_timeout(180U),
|
2016-01-14 19:45:04 +01:00
|
|
|
m_dstarEnabled(false),
|
|
|
|
m_dmrEnabled(false),
|
2016-05-09 22:55:44 +02:00
|
|
|
m_ysfEnabled(false),
|
2016-09-08 19:38:59 +02:00
|
|
|
m_p25Enabled(false),
|
2018-01-11 20:35:33 +01:00
|
|
|
m_nxdnEnabled(false),
|
2020-12-15 17:21:07 +01:00
|
|
|
m_m17Enabled(false),
|
2018-06-07 19:46:03 +02:00
|
|
|
m_pocsagEnabled(false),
|
2020-04-09 23:02:47 +02:00
|
|
|
m_fmEnabled(false),
|
2020-12-15 17:21:07 +01:00
|
|
|
m_ax25Enabled(false),
|
2016-10-17 19:01:38 +02:00
|
|
|
m_cwIdTime(0U),
|
2018-01-17 22:21:25 +01:00
|
|
|
m_dmrLookup(NULL),
|
2017-04-10 18:55:53 +02:00
|
|
|
m_callsign(),
|
2017-08-19 17:23:37 +02:00
|
|
|
m_id(0U),
|
2018-10-10 21:05:24 +02:00
|
|
|
m_cwCallsign(),
|
|
|
|
m_lockFileEnabled(false),
|
2018-11-06 13:14:57 +01:00
|
|
|
m_lockFileName(),
|
2019-01-22 15:38:38 +01:00
|
|
|
m_remoteControl(NULL),
|
2022-07-29 19:24:39 +02:00
|
|
|
m_fixedMode(true)
|
2016-01-14 19:45:04 +01:00
|
|
|
{
|
2020-09-20 22:31:32 +02:00
|
|
|
CUDPSocket::startup();
|
2016-01-14 19:45:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CMMDVMHost::~CMMDVMHost()
|
|
|
|
{
|
2020-09-20 22:31:32 +02:00
|
|
|
CUDPSocket::shutdown();
|
2016-01-14 19:45:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int CMMDVMHost::run()
|
|
|
|
{
|
|
|
|
bool ret = m_conf.read();
|
|
|
|
if (!ret) {
|
2016-05-15 00:26:16 +02:00
|
|
|
::fprintf(stderr, "MMDVMHost: cannot read the .ini file\n");
|
2016-01-14 19:45:04 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-05-04 00:01:49 +02:00
|
|
|
#if !defined(_WIN32) && !defined(_WIN64)
|
|
|
|
bool m_daemon = m_conf.getDaemon();
|
|
|
|
if (m_daemon) {
|
|
|
|
// Create new process
|
|
|
|
pid_t pid = ::fork();
|
2016-05-04 21:06:15 +02:00
|
|
|
if (pid == -1) {
|
2018-06-18 19:18:09 +02:00
|
|
|
::fprintf(stderr, "Couldn't fork() , exiting\n");
|
2017-05-03 15:53:48 +02:00
|
|
|
return -1;
|
|
|
|
} else if (pid != 0) {
|
2016-05-04 00:01:49 +02:00
|
|
|
exit(EXIT_SUCCESS);
|
2017-05-03 15:53:48 +02:00
|
|
|
}
|
2016-05-04 00:01:49 +02:00
|
|
|
|
|
|
|
// Create new session and process group
|
2016-05-04 21:06:15 +02:00
|
|
|
if (::setsid() == -1){
|
2018-06-18 19:18:09 +02:00
|
|
|
::fprintf(stderr, "Couldn't setsid(), exiting\n");
|
2017-05-03 15:53:48 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2016-05-04 00:01:49 +02:00
|
|
|
|
|
|
|
// Set the working directory to the root directory
|
2016-05-04 21:06:15 +02:00
|
|
|
if (::chdir("/") == -1){
|
2018-06-18 19:18:09 +02:00
|
|
|
::fprintf(stderr, "Couldn't cd /, exiting\n");
|
2017-05-03 15:53:48 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2016-05-04 00:01:49 +02:00
|
|
|
|
2018-07-03 04:01:19 +02:00
|
|
|
#if !defined(HD44780) && !defined(OLED) && !defined(_OPENWRT)
|
2018-06-18 19:18:09 +02:00
|
|
|
// If we are currently root...
|
2016-05-04 21:06:15 +02:00
|
|
|
if (getuid() == 0) {
|
2016-05-05 19:06:05 +02:00
|
|
|
struct passwd* user = ::getpwnam("mmdvm");
|
|
|
|
if (user == NULL) {
|
2018-06-18 19:18:09 +02:00
|
|
|
::fprintf(stderr, "Could not get the mmdvm user, exiting\n");
|
2016-05-05 19:06:05 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2017-05-03 15:53:48 +02:00
|
|
|
|
2016-05-05 19:06:05 +02:00
|
|
|
uid_t mmdvm_uid = user->pw_uid;
|
2017-05-03 15:53:48 +02:00
|
|
|
gid_t mmdvm_gid = user->pw_gid;
|
|
|
|
|
2018-06-18 19:18:09 +02:00
|
|
|
// Set user and group ID's to mmdvm:mmdvm
|
2017-05-03 15:53:48 +02:00
|
|
|
if (::setgid(mmdvm_gid) != 0) {
|
2018-06-18 19:18:09 +02:00
|
|
|
::fprintf(stderr, "Could not set mmdvm GID, exiting\n");
|
2017-05-03 15:53:48 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (::setuid(mmdvm_uid) != 0) {
|
2018-06-18 19:18:09 +02:00
|
|
|
::fprintf(stderr, "Could not set mmdvm UID, exiting\n");
|
2017-05-03 15:53:48 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-07-19 15:09:00 +02:00
|
|
|
// Double check it worked (AKA Paranoia)
|
2017-05-03 15:53:48 +02:00
|
|
|
if (::setuid(0) != -1){
|
2018-06-18 19:18:09 +02:00
|
|
|
::fprintf(stderr, "It's possible to regain root - something is wrong!, exiting\n");
|
2017-05-03 15:53:48 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2016-05-04 21:06:15 +02:00
|
|
|
}
|
2016-05-04 00:01:49 +02:00
|
|
|
}
|
2017-05-03 23:39:11 +02:00
|
|
|
#else
|
2018-07-03 04:01:19 +02:00
|
|
|
::fprintf(stderr, "Dropping root permissions in daemon mode is disabled.\n");
|
2017-05-03 23:39:11 +02:00
|
|
|
}
|
2016-05-05 10:47:54 +02:00
|
|
|
#endif
|
2016-05-04 00:01:49 +02:00
|
|
|
#endif
|
|
|
|
|
2020-05-09 13:47:26 +02:00
|
|
|
#if !defined(_WIN32) && !defined(_WIN64)
|
2020-10-31 22:35:09 +01:00
|
|
|
ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogFileRotate());
|
2020-05-09 13:47:26 +02:00
|
|
|
#else
|
2020-10-31 22:35:09 +01:00
|
|
|
ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel(), m_conf.getLogFileRotate());
|
2020-05-09 13:47:26 +02:00
|
|
|
#endif
|
2018-06-18 19:18:09 +02:00
|
|
|
if (!ret) {
|
|
|
|
::fprintf(stderr, "MMDVMHost: unable to open the log file\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-07-26 19:43:57 +02:00
|
|
|
#if !defined(_WIN32) && !defined(_WIN64)
|
|
|
|
if (m_daemon) {
|
|
|
|
::close(STDIN_FILENO);
|
|
|
|
::close(STDOUT_FILENO);
|
|
|
|
}
|
|
|
|
#endif
|
2018-06-18 19:18:09 +02:00
|
|
|
|
2016-01-14 19:45:04 +01:00
|
|
|
LogInfo(HEADER1);
|
|
|
|
LogInfo(HEADER2);
|
|
|
|
LogInfo(HEADER3);
|
2016-01-23 18:54:23 +01:00
|
|
|
LogInfo(HEADER4);
|
2016-01-14 19:45:04 +01:00
|
|
|
|
|
|
|
LogMessage("MMDVMHost-%s is starting", VERSION);
|
2017-03-09 21:55:41 +01:00
|
|
|
LogMessage("Built %s %s (GitID #%.7s)", __TIME__, __DATE__, gitversion);
|
2016-01-14 19:45:04 +01:00
|
|
|
|
|
|
|
readParams();
|
|
|
|
|
|
|
|
ret = createModem();
|
|
|
|
if (!ret)
|
|
|
|
return 1;
|
|
|
|
|
2021-05-08 20:34:44 +02:00
|
|
|
if (m_dmrEnabled && !m_modem->hasDMR()) {
|
|
|
|
LogWarning("DMR enabled in the host but not in the modem firmware, disabling");
|
|
|
|
m_dmrEnabled = false;
|
|
|
|
}
|
|
|
|
|
2020-12-15 17:21:07 +01:00
|
|
|
m_display = CDisplay::createDisplay(m_conf, m_modem);
|
2016-01-14 19:45:04 +01:00
|
|
|
|
2016-01-18 22:24:41 +01:00
|
|
|
if (m_dmrEnabled && m_conf.getDMRNetworkEnabled()) {
|
2016-01-14 19:45:04 +01:00
|
|
|
ret = createDMRNetwork();
|
|
|
|
if (!ret)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-03-27 21:40:35 +01:00
|
|
|
sockaddr_storage transparentAddress;
|
|
|
|
unsigned int transparentAddrLen;
|
2018-03-22 08:13:13 +01:00
|
|
|
CUDPSocket* transparentSocket = NULL;
|
|
|
|
|
2018-08-13 20:39:16 +02:00
|
|
|
unsigned int sendFrameType = 0U;
|
2018-03-22 08:13:13 +01:00
|
|
|
if (m_conf.getTransparentEnabled()) {
|
|
|
|
std::string remoteAddress = m_conf.getTransparentRemoteAddress();
|
2021-04-25 07:47:06 +02:00
|
|
|
unsigned short remotePort = m_conf.getTransparentRemotePort();
|
|
|
|
unsigned short localPort = m_conf.getTransparentLocalPort();
|
2018-08-13 20:39:16 +02:00
|
|
|
sendFrameType = m_conf.getTransparentSendFrameType();
|
2018-03-22 08:13:13 +01:00
|
|
|
|
|
|
|
LogInfo("Transparent Data");
|
|
|
|
LogInfo(" Remote Address: %s", remoteAddress.c_str());
|
2021-04-25 07:47:06 +02:00
|
|
|
LogInfo(" Remote Port: %hu", remotePort);
|
|
|
|
LogInfo(" Local Port: %hu", localPort);
|
2018-08-13 20:39:16 +02:00
|
|
|
LogInfo(" Send Frame Type: %u", sendFrameType);
|
2018-03-22 08:13:13 +01:00
|
|
|
|
2020-09-06 13:54:08 +02:00
|
|
|
if (CUDPSocket::lookup(remoteAddress, remotePort, transparentAddress, transparentAddrLen) != 0) {
|
|
|
|
LogError("Unable to resolve the address of the Transparent Data source");
|
|
|
|
return 1;
|
|
|
|
}
|
2018-03-22 08:13:13 +01:00
|
|
|
|
|
|
|
transparentSocket = new CUDPSocket(localPort);
|
2020-09-06 13:54:08 +02:00
|
|
|
ret = transparentSocket->open(transparentAddress);
|
2018-03-22 08:13:13 +01:00
|
|
|
if (!ret) {
|
|
|
|
LogWarning("Could not open the Transparent data socket, disabling");
|
|
|
|
delete transparentSocket;
|
|
|
|
transparentSocket = NULL;
|
2018-09-13 20:35:12 +02:00
|
|
|
sendFrameType=0;
|
2018-03-22 08:13:13 +01:00
|
|
|
}
|
2018-09-13 20:35:12 +02:00
|
|
|
m_modem->setTransparentDataParams(sendFrameType);
|
2018-03-22 08:13:13 +01:00
|
|
|
}
|
|
|
|
|
2018-10-10 21:05:24 +02:00
|
|
|
if (m_conf.getLockFileEnabled()) {
|
2018-10-11 08:50:30 +02:00
|
|
|
m_lockFileEnabled = true;
|
|
|
|
m_lockFileName = m_conf.getLockFileName();
|
|
|
|
|
2018-10-10 21:05:24 +02:00
|
|
|
LogInfo("Lock File Parameters");
|
|
|
|
LogInfo(" Name: %s", m_lockFileName.c_str());
|
2018-10-11 08:50:30 +02:00
|
|
|
|
|
|
|
removeLockFile();
|
2018-10-10 21:05:24 +02:00
|
|
|
}
|
|
|
|
|
2016-05-09 22:55:44 +02:00
|
|
|
if (m_conf.getCWIdEnabled()) {
|
|
|
|
unsigned int time = m_conf.getCWIdTime();
|
2017-04-11 20:26:44 +02:00
|
|
|
m_cwCallsign = m_conf.getCWIdCallsign();
|
2016-05-09 22:55:44 +02:00
|
|
|
|
|
|
|
LogInfo("CW Id Parameters");
|
|
|
|
LogInfo(" Time: %u mins", time);
|
2017-04-11 20:26:44 +02:00
|
|
|
LogInfo(" Callsign: %s", m_cwCallsign.c_str());
|
2016-05-09 22:55:44 +02:00
|
|
|
|
2016-10-17 19:01:38 +02:00
|
|
|
m_cwIdTime = time * 60U;
|
|
|
|
|
|
|
|
m_cwIdTimer.setTimeout(m_cwIdTime / 4U);
|
2016-06-03 16:28:55 +02:00
|
|
|
m_cwIdTimer.start();
|
2016-05-09 22:55:44 +02:00
|
|
|
}
|
|
|
|
|
2017-01-05 20:15:10 +01:00
|
|
|
// For all modes we handle RSSI
|
|
|
|
std::string rssiMappingFile = m_conf.getModemRSSIMappingFile();
|
|
|
|
|
|
|
|
CRSSIInterpolator* rssi = new CRSSIInterpolator;
|
|
|
|
if (!rssiMappingFile.empty()) {
|
|
|
|
LogInfo("RSSI");
|
|
|
|
LogInfo(" Mapping File: %s", rssiMappingFile.c_str());
|
|
|
|
rssi->load(rssiMappingFile);
|
|
|
|
}
|
|
|
|
|
2016-09-13 00:26:05 +02:00
|
|
|
// For DMR and P25 we try to map IDs to callsigns
|
2022-07-29 19:24:39 +02:00
|
|
|
if (m_dmrEnabled) {
|
2016-10-10 20:15:30 +02:00
|
|
|
std::string lookupFile = m_conf.getDMRIdLookupFile();
|
|
|
|
unsigned int reloadTime = m_conf.getDMRIdLookupTime();
|
2016-09-13 00:26:05 +02:00
|
|
|
|
2016-10-10 20:15:30 +02:00
|
|
|
LogInfo("DMR Id Lookups");
|
|
|
|
LogInfo(" File: %s", lookupFile.length() > 0U ? lookupFile.c_str() : "None");
|
|
|
|
if (reloadTime > 0U)
|
|
|
|
LogInfo(" Reload: %u hours", reloadTime);
|
|
|
|
|
2018-01-17 22:21:25 +01:00
|
|
|
m_dmrLookup = new CDMRLookup(lookupFile, reloadTime);
|
|
|
|
m_dmrLookup->read();
|
2016-09-13 00:26:05 +02:00
|
|
|
}
|
|
|
|
|
2016-01-14 19:45:04 +01:00
|
|
|
CStopWatch stopWatch;
|
|
|
|
stopWatch.start();
|
|
|
|
|
2019-11-05 13:44:56 +01:00
|
|
|
DMR_BEACONS dmrBeacons = DMR_BEACONS_OFF;
|
2018-01-16 19:35:29 +01:00
|
|
|
CTimer dmrBeaconIntervalTimer(1000U);
|
|
|
|
CTimer dmrBeaconDurationTimer(1000U);
|
|
|
|
|
2016-01-14 19:45:04 +01:00
|
|
|
if (m_dmrEnabled) {
|
2016-12-21 20:58:46 +01:00
|
|
|
unsigned int id = m_conf.getDMRId();
|
|
|
|
unsigned int colorCode = m_conf.getDMRColorCode();
|
|
|
|
bool selfOnly = m_conf.getDMRSelfOnly();
|
2017-02-27 21:17:55 +01:00
|
|
|
bool embeddedLCOnly = m_conf.getDMREmbeddedLCOnly();
|
|
|
|
bool dumpTAData = m_conf.getDMRDumpTAData();
|
2016-11-10 19:43:54 +01:00
|
|
|
std::vector<unsigned int> prefixes = m_conf.getDMRPrefixes();
|
2016-04-06 19:46:05 +02:00
|
|
|
std::vector<unsigned int> blackList = m_conf.getDMRBlackList();
|
2016-12-21 20:06:29 +01:00
|
|
|
std::vector<unsigned int> whiteList = m_conf.getDMRWhiteList();
|
2017-01-05 20:15:10 +01:00
|
|
|
std::vector<unsigned int> slot1TGWhiteList = m_conf.getDMRSlot1TGWhiteList();
|
|
|
|
std::vector<unsigned int> slot2TGWhiteList = m_conf.getDMRSlot2TGWhiteList();
|
2017-02-27 21:17:55 +01:00
|
|
|
unsigned int callHang = m_conf.getDMRCallHang();
|
2016-12-21 20:58:46 +01:00
|
|
|
unsigned int txHang = m_conf.getDMRTXHang();
|
2018-02-08 21:25:03 +01:00
|
|
|
unsigned int jitter = m_conf.getDMRNetworkJitter();
|
2017-09-01 10:25:54 +02:00
|
|
|
m_dmrRFModeHang = m_conf.getDMRModeHang();
|
2019-11-05 13:44:56 +01:00
|
|
|
dmrBeacons = m_conf.getDMRBeacons();
|
2019-11-17 03:57:58 +01:00
|
|
|
DMR_OVCM_TYPES ovcm = m_conf.getDMROVCM();
|
2016-01-14 19:45:04 +01:00
|
|
|
|
2017-09-01 10:25:54 +02:00
|
|
|
if (txHang > m_dmrRFModeHang)
|
|
|
|
txHang = m_dmrRFModeHang;
|
|
|
|
|
|
|
|
if (m_conf.getDMRNetworkEnabled()) {
|
|
|
|
if (txHang > m_dmrNetModeHang)
|
|
|
|
txHang = m_dmrNetModeHang;
|
|
|
|
}
|
2016-06-22 19:03:56 +02:00
|
|
|
|
|
|
|
if (callHang > txHang)
|
|
|
|
callHang = txHang;
|
|
|
|
|
2017-09-01 10:25:54 +02:00
|
|
|
LogInfo("DMR RF Parameters");
|
2016-01-14 19:45:04 +01:00
|
|
|
LogInfo(" Id: %u", id);
|
|
|
|
LogInfo(" Color Code: %u", colorCode);
|
2016-04-04 18:40:05 +02:00
|
|
|
LogInfo(" Self Only: %s", selfOnly ? "yes" : "no");
|
2017-01-16 13:10:23 +01:00
|
|
|
LogInfo(" Embedded LC Only: %s", embeddedLCOnly ? "yes" : "no");
|
2017-02-27 21:17:55 +01:00
|
|
|
LogInfo(" Dump Talker Alias Data: %s", dumpTAData ? "yes" : "no");
|
2016-04-04 20:03:38 +02:00
|
|
|
LogInfo(" Prefixes: %u", prefixes.size());
|
2018-07-19 15:09:00 +02:00
|
|
|
|
2016-04-06 19:46:05 +02:00
|
|
|
if (blackList.size() > 0U)
|
2016-07-10 22:37:11 +02:00
|
|
|
LogInfo(" Source ID Black List: %u", blackList.size());
|
2016-12-21 20:06:29 +01:00
|
|
|
if (whiteList.size() > 0U)
|
|
|
|
LogInfo(" Source ID White List: %u", whiteList.size());
|
2017-01-05 20:15:10 +01:00
|
|
|
if (slot1TGWhiteList.size() > 0U)
|
|
|
|
LogInfo(" Slot 1 TG White List: %u", slot1TGWhiteList.size());
|
|
|
|
if (slot2TGWhiteList.size() > 0U)
|
|
|
|
LogInfo(" Slot 2 TG White List: %u", slot2TGWhiteList.size());
|
2016-12-21 20:06:29 +01:00
|
|
|
|
2016-06-16 22:40:05 +02:00
|
|
|
LogInfo(" Call Hang: %us", callHang);
|
2016-05-05 18:56:18 +02:00
|
|
|
LogInfo(" TX Hang: %us", txHang);
|
2017-09-01 10:25:54 +02:00
|
|
|
LogInfo(" Mode Hang: %us", m_dmrRFModeHang);
|
2019-11-17 03:57:58 +01:00
|
|
|
if (ovcm == DMR_OVCM_OFF)
|
2019-11-16 16:06:26 +01:00
|
|
|
LogInfo(" OVCM: off");
|
2019-11-17 03:57:58 +01:00
|
|
|
else if (ovcm == DMR_OVCM_RX_ON)
|
|
|
|
LogInfo(" OVCM: on(rx only)");
|
|
|
|
else if (ovcm == DMR_OVCM_TX_ON)
|
|
|
|
LogInfo(" OVCM: on(tx only)");
|
|
|
|
else if (ovcm == DMR_OVCM_ON)
|
2019-11-16 16:06:26 +01:00
|
|
|
LogInfo(" OVCM: on");
|
2021-03-07 18:42:55 +01:00
|
|
|
else if (ovcm == DMR_OVCM_FORCE_OFF)
|
|
|
|
LogInfo(" OVCM: off (forced)");
|
2016-01-14 19:45:04 +01:00
|
|
|
|
2019-11-05 09:42:21 +01:00
|
|
|
switch (dmrBeacons) {
|
|
|
|
case DMR_BEACONS_NETWORK: {
|
|
|
|
unsigned int dmrBeaconDuration = m_conf.getDMRBeaconDuration();
|
2018-01-16 19:35:29 +01:00
|
|
|
|
2019-11-05 09:42:21 +01:00
|
|
|
LogInfo(" DMR Roaming Beacons Type: network");
|
|
|
|
LogInfo(" DMR Roaming Beacons Duration: %us", dmrBeaconDuration);
|
2018-01-16 19:35:29 +01:00
|
|
|
|
2019-11-05 09:42:21 +01:00
|
|
|
dmrBeaconDurationTimer.setTimeout(dmrBeaconDuration);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DMR_BEACONS_TIMED: {
|
|
|
|
unsigned int dmrBeaconInterval = m_conf.getDMRBeaconInterval();
|
|
|
|
unsigned int dmrBeaconDuration = m_conf.getDMRBeaconDuration();
|
|
|
|
|
|
|
|
LogInfo(" DMR Roaming Beacons Type: timed");
|
|
|
|
LogInfo(" DMR Roaming Beacons Interval: %us", dmrBeaconInterval);
|
|
|
|
LogInfo(" DMR Roaming Beacons Duration: %us", dmrBeaconDuration);
|
|
|
|
|
|
|
|
dmrBeaconDurationTimer.setTimeout(dmrBeaconDuration);
|
2018-01-16 19:35:29 +01:00
|
|
|
|
2019-11-05 09:42:21 +01:00
|
|
|
dmrBeaconIntervalTimer.setTimeout(dmrBeaconInterval);
|
|
|
|
dmrBeaconIntervalTimer.start();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LogInfo(" DMR Roaming Beacons Type: off");
|
|
|
|
break;
|
2018-01-15 20:22:01 +01:00
|
|
|
}
|
|
|
|
|
2019-11-16 16:06:26 +01:00
|
|
|
m_dmr = new CDMRControl(id, colorCode, callHang, selfOnly, embeddedLCOnly, dumpTAData, prefixes, blackList, whiteList, slot1TGWhiteList, slot2TGWhiteList, m_timeout, m_modem, m_dmrNetwork, m_display, m_duplex, m_dmrLookup, rssi, jitter, ovcm);
|
2016-05-05 18:56:18 +02:00
|
|
|
|
|
|
|
m_dmrTXTimer.setTimeout(txHang);
|
2016-01-14 19:45:04 +01:00
|
|
|
}
|
|
|
|
|
2019-01-07 12:03:37 +01:00
|
|
|
bool remoteControlEnabled = m_conf.getRemoteControlEnabled();
|
|
|
|
if (remoteControlEnabled) {
|
2020-04-11 06:12:19 +02:00
|
|
|
std::string address = m_conf.getRemoteControlAddress();
|
2021-04-25 07:47:06 +02:00
|
|
|
unsigned short port = m_conf.getRemoteControlPort();
|
2019-01-07 12:03:37 +01:00
|
|
|
|
|
|
|
LogInfo("Remote Control Parameters");
|
2020-04-11 06:12:19 +02:00
|
|
|
LogInfo(" Address: %s", address.c_str());
|
2021-04-25 07:47:06 +02:00
|
|
|
LogInfo(" Port: %hu", port);
|
2019-01-07 12:03:37 +01:00
|
|
|
|
2021-03-22 20:27:08 +01:00
|
|
|
m_remoteControl = new CRemoteControl(this, address, port);
|
2019-01-07 12:03:37 +01:00
|
|
|
|
2019-01-10 10:05:15 +01:00
|
|
|
ret = m_remoteControl->open();
|
2019-01-07 12:03:37 +01:00
|
|
|
if (!ret) {
|
2019-01-10 10:05:15 +01:00
|
|
|
delete m_remoteControl;
|
|
|
|
m_remoteControl = NULL;
|
2019-01-07 12:03:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-30 00:10:10 +02:00
|
|
|
setMode(MODE_DMR);
|
2016-01-14 19:45:04 +01:00
|
|
|
|
2016-05-14 22:31:17 +02:00
|
|
|
LogMessage("MMDVMHost-%s is running", VERSION);
|
2016-05-12 19:04:50 +02:00
|
|
|
|
2016-01-14 19:45:04 +01:00
|
|
|
while (!m_killed) {
|
2020-12-15 17:21:07 +01:00
|
|
|
bool lockout = m_modem->hasLockout();
|
2018-10-10 21:05:24 +02:00
|
|
|
|
2020-12-15 17:21:07 +01:00
|
|
|
if (lockout && m_mode != MODE_LOCKOUT)
|
2016-03-03 22:45:20 +01:00
|
|
|
setMode(MODE_LOCKOUT);
|
2020-12-15 17:21:07 +01:00
|
|
|
else if (!lockout && m_mode == MODE_LOCKOUT)
|
2016-03-03 22:45:20 +01:00
|
|
|
setMode(MODE_IDLE);
|
|
|
|
|
2016-03-21 23:47:58 +01:00
|
|
|
bool error = m_modem->hasError();
|
|
|
|
if (error && m_mode != MODE_ERROR)
|
|
|
|
setMode(MODE_ERROR);
|
|
|
|
else if (!error && m_mode == MODE_ERROR)
|
|
|
|
setMode(MODE_IDLE);
|
|
|
|
|
2020-12-15 17:21:07 +01:00
|
|
|
unsigned char data[500U];
|
2016-01-14 19:45:04 +01:00
|
|
|
unsigned int len;
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
len = m_modem->readDMRData1(data);
|
2019-01-10 10:05:15 +01:00
|
|
|
if (m_dmr != NULL && len > 0U) {
|
2016-02-02 19:17:36 +01:00
|
|
|
if (m_mode == MODE_IDLE) {
|
2016-03-07 20:45:19 +01:00
|
|
|
if (m_duplex) {
|
2019-01-10 10:05:15 +01:00
|
|
|
bool ret = m_dmr->processWakeup(data);
|
2016-05-05 18:56:18 +02:00
|
|
|
if (ret) {
|
2017-09-01 10:25:54 +02:00
|
|
|
m_modeTimer.setTimeout(m_dmrRFModeHang);
|
2016-03-07 20:45:19 +01:00
|
|
|
setMode(MODE_DMR);
|
2018-01-16 19:35:29 +01:00
|
|
|
dmrBeaconDurationTimer.stop();
|
2016-05-05 18:56:18 +02:00
|
|
|
}
|
2016-03-07 20:45:19 +01:00
|
|
|
} else {
|
2017-09-01 10:25:54 +02:00
|
|
|
m_modeTimer.setTimeout(m_dmrRFModeHang);
|
2016-02-02 19:17:36 +01:00
|
|
|
setMode(MODE_DMR);
|
2019-01-10 10:05:15 +01:00
|
|
|
m_dmr->writeModemSlot1(data, len);
|
2018-01-16 19:35:29 +01:00
|
|
|
dmrBeaconDurationTimer.stop();
|
2016-03-07 20:45:19 +01:00
|
|
|
}
|
2016-02-02 19:17:36 +01:00
|
|
|
} else if (m_mode == MODE_DMR) {
|
2016-05-05 18:56:18 +02:00
|
|
|
if (m_duplex && !m_modem->hasTX()) {
|
2019-01-10 10:05:15 +01:00
|
|
|
bool ret = m_dmr->processWakeup(data);
|
2016-05-05 18:56:18 +02:00
|
|
|
if (ret) {
|
|
|
|
m_modem->writeDMRStart(true);
|
|
|
|
m_dmrTXTimer.start();
|
|
|
|
}
|
|
|
|
} else {
|
2019-01-10 10:05:15 +01:00
|
|
|
bool ret = m_dmr->writeModemSlot1(data, len);
|
2017-03-12 20:06:47 +01:00
|
|
|
if (ret) {
|
2018-01-16 19:35:29 +01:00
|
|
|
dmrBeaconDurationTimer.stop();
|
2017-03-12 20:06:47 +01:00
|
|
|
m_modeTimer.start();
|
|
|
|
if (m_duplex)
|
|
|
|
m_dmrTXTimer.start();
|
|
|
|
}
|
2016-05-05 18:56:18 +02:00
|
|
|
}
|
2016-03-07 20:45:19 +01:00
|
|
|
} else if (m_mode != MODE_LOCKOUT) {
|
2016-02-03 10:55:08 +01:00
|
|
|
LogWarning("DMR modem data received when in mode %u", m_mode);
|
2016-01-14 19:45:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
len = m_modem->readDMRData2(data);
|
2019-01-10 10:05:15 +01:00
|
|
|
if (m_dmr != NULL && len > 0U) {
|
2016-02-02 19:17:36 +01:00
|
|
|
if (m_mode == MODE_IDLE) {
|
2016-03-07 20:45:19 +01:00
|
|
|
if (m_duplex) {
|
2019-01-10 10:05:15 +01:00
|
|
|
bool ret = m_dmr->processWakeup(data);
|
2016-05-05 18:56:18 +02:00
|
|
|
if (ret) {
|
2017-09-01 10:25:54 +02:00
|
|
|
m_modeTimer.setTimeout(m_dmrRFModeHang);
|
2016-03-07 20:45:19 +01:00
|
|
|
setMode(MODE_DMR);
|
2018-01-16 19:35:29 +01:00
|
|
|
dmrBeaconDurationTimer.stop();
|
2016-05-05 18:56:18 +02:00
|
|
|
}
|
2016-03-07 20:45:19 +01:00
|
|
|
} else {
|
2017-09-01 10:25:54 +02:00
|
|
|
m_modeTimer.setTimeout(m_dmrRFModeHang);
|
2016-02-02 19:17:36 +01:00
|
|
|
setMode(MODE_DMR);
|
2019-01-10 10:05:15 +01:00
|
|
|
m_dmr->writeModemSlot2(data, len);
|
2018-01-16 19:35:29 +01:00
|
|
|
dmrBeaconDurationTimer.stop();
|
2016-03-07 20:45:19 +01:00
|
|
|
}
|
2016-02-02 19:17:36 +01:00
|
|
|
} else if (m_mode == MODE_DMR) {
|
2016-05-05 18:56:18 +02:00
|
|
|
if (m_duplex && !m_modem->hasTX()) {
|
2019-01-10 10:05:15 +01:00
|
|
|
bool ret = m_dmr->processWakeup(data);
|
2016-05-05 18:56:18 +02:00
|
|
|
if (ret) {
|
|
|
|
m_modem->writeDMRStart(true);
|
|
|
|
m_dmrTXTimer.start();
|
|
|
|
}
|
|
|
|
} else {
|
2019-01-10 10:05:15 +01:00
|
|
|
bool ret = m_dmr->writeModemSlot2(data, len);
|
2017-03-12 20:06:47 +01:00
|
|
|
if (ret) {
|
2018-01-16 19:35:29 +01:00
|
|
|
dmrBeaconDurationTimer.stop();
|
2017-03-12 20:06:47 +01:00
|
|
|
m_modeTimer.start();
|
|
|
|
if (m_duplex)
|
|
|
|
m_dmrTXTimer.start();
|
|
|
|
}
|
2016-05-05 18:56:18 +02:00
|
|
|
}
|
2016-03-07 20:45:19 +01:00
|
|
|
} else if (m_mode != MODE_LOCKOUT) {
|
2016-02-03 10:55:08 +01:00
|
|
|
LogWarning("DMR modem data received when in mode %u", m_mode);
|
2016-01-14 19:45:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 08:13:13 +01:00
|
|
|
len = m_modem->readTransparentData(data);
|
|
|
|
if (transparentSocket != NULL && len > 0U)
|
2020-03-27 21:40:35 +01:00
|
|
|
transparentSocket->write(data, len, transparentAddress, transparentAddrLen);
|
2018-03-22 08:13:13 +01:00
|
|
|
|
2019-01-22 15:38:38 +01:00
|
|
|
if (!m_fixedMode) {
|
|
|
|
if (m_modeTimer.isRunning() && m_modeTimer.hasExpired())
|
|
|
|
setMode(MODE_IDLE);
|
|
|
|
}
|
2016-01-14 19:45:04 +01:00
|
|
|
|
2019-01-10 10:05:15 +01:00
|
|
|
if (m_dmr != NULL) {
|
2016-01-14 19:45:04 +01:00
|
|
|
ret = m_modem->hasDMRSpace1();
|
|
|
|
if (ret) {
|
2019-01-10 10:05:15 +01:00
|
|
|
len = m_dmr->readModemSlot1(data);
|
2016-02-03 10:55:08 +01:00
|
|
|
if (len > 0U) {
|
2016-06-22 19:03:56 +02:00
|
|
|
if (m_mode == MODE_IDLE) {
|
2017-09-01 10:25:54 +02:00
|
|
|
m_modeTimer.setTimeout(m_dmrNetModeHang);
|
2016-02-03 10:55:08 +01:00
|
|
|
setMode(MODE_DMR);
|
2016-06-22 19:03:56 +02:00
|
|
|
}
|
2016-03-07 20:45:19 +01:00
|
|
|
if (m_mode == MODE_DMR) {
|
2016-05-05 18:56:18 +02:00
|
|
|
if (m_duplex) {
|
|
|
|
m_modem->writeDMRStart(true);
|
|
|
|
m_dmrTXTimer.start();
|
|
|
|
}
|
2016-02-03 10:55:08 +01:00
|
|
|
m_modem->writeDMRData1(data, len);
|
2018-01-16 19:35:29 +01:00
|
|
|
dmrBeaconDurationTimer.stop();
|
2016-02-03 10:55:08 +01:00
|
|
|
m_modeTimer.start();
|
2016-03-07 20:45:19 +01:00
|
|
|
} else if (m_mode != MODE_LOCKOUT) {
|
2016-02-03 10:55:08 +01:00
|
|
|
LogWarning("DMR data received when in mode %u", m_mode);
|
|
|
|
}
|
2016-01-14 19:45:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = m_modem->hasDMRSpace2();
|
|
|
|
if (ret) {
|
2019-01-10 10:05:15 +01:00
|
|
|
len = m_dmr->readModemSlot2(data);
|
2016-02-03 10:55:08 +01:00
|
|
|
if (len > 0U) {
|
2016-06-22 19:03:56 +02:00
|
|
|
if (m_mode == MODE_IDLE) {
|
2017-09-01 10:25:54 +02:00
|
|
|
m_modeTimer.setTimeout(m_dmrNetModeHang);
|
2016-02-03 10:55:08 +01:00
|
|
|
setMode(MODE_DMR);
|
2016-06-22 19:03:56 +02:00
|
|
|
}
|
2016-03-07 20:45:19 +01:00
|
|
|
if (m_mode == MODE_DMR) {
|
2016-05-05 18:56:18 +02:00
|
|
|
if (m_duplex) {
|
|
|
|
m_modem->writeDMRStart(true);
|
|
|
|
m_dmrTXTimer.start();
|
|
|
|
}
|
2016-02-03 10:55:08 +01:00
|
|
|
m_modem->writeDMRData2(data, len);
|
2018-01-16 19:35:29 +01:00
|
|
|
dmrBeaconDurationTimer.stop();
|
2016-02-03 10:55:08 +01:00
|
|
|
m_modeTimer.start();
|
2016-03-07 20:45:19 +01:00
|
|
|
} else if (m_mode != MODE_LOCKOUT) {
|
2016-02-03 10:55:08 +01:00
|
|
|
LogWarning("DMR data received when in mode %u", m_mode);
|
|
|
|
}
|
2016-01-14 19:45:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 08:13:13 +01:00
|
|
|
if (transparentSocket != NULL) {
|
2020-03-27 21:40:35 +01:00
|
|
|
sockaddr_storage address;
|
|
|
|
unsigned int addrlen;
|
|
|
|
len = transparentSocket->read(data, 200U, address, addrlen);
|
2018-03-22 08:13:13 +01:00
|
|
|
if (len > 0U)
|
2018-09-13 20:35:12 +02:00
|
|
|
m_modem->writeTransparentData(data, len);
|
2018-03-22 08:13:13 +01:00
|
|
|
}
|
|
|
|
|
2019-01-10 10:05:15 +01:00
|
|
|
remoteControl();
|
2019-01-07 12:03:37 +01:00
|
|
|
|
2016-01-14 19:45:04 +01:00
|
|
|
unsigned int ms = stopWatch.elapsed();
|
2016-02-19 07:21:40 +01:00
|
|
|
stopWatch.start();
|
|
|
|
|
2016-05-09 19:14:27 +02:00
|
|
|
m_display->clock(ms);
|
|
|
|
|
2016-01-14 19:45:04 +01:00
|
|
|
m_modem->clock(ms);
|
2019-01-18 16:57:05 +01:00
|
|
|
|
2019-01-22 15:38:38 +01:00
|
|
|
if (!m_fixedMode)
|
|
|
|
m_modeTimer.clock(ms);
|
2016-02-19 07:21:40 +01:00
|
|
|
|
2021-01-01 14:54:03 +01:00
|
|
|
if (m_reload) {
|
|
|
|
if (m_dmrLookup != NULL)
|
|
|
|
m_dmrLookup->reload();
|
|
|
|
m_reload = false;
|
|
|
|
}
|
|
|
|
|
2019-01-10 10:05:15 +01:00
|
|
|
if (m_dmr != NULL)
|
|
|
|
m_dmr->clock();
|
2022-07-29 18:49:08 +02:00
|
|
|
|
2016-01-26 20:56:10 +01:00
|
|
|
if (m_dmrNetwork != NULL)
|
|
|
|
m_dmrNetwork->clock(ms);
|
2016-01-14 19:45:04 +01:00
|
|
|
|
2016-05-09 22:55:44 +02:00
|
|
|
m_cwIdTimer.clock(ms);
|
|
|
|
if (m_cwIdTimer.isRunning() && m_cwIdTimer.hasExpired()) {
|
2019-01-22 15:38:38 +01:00
|
|
|
if (!m_modem->hasTX()){
|
2016-06-03 16:28:55 +02:00
|
|
|
LogDebug("sending CW ID");
|
2016-09-15 15:17:51 +02:00
|
|
|
m_display->writeCW();
|
2017-04-10 18:55:53 +02:00
|
|
|
m_modem->sendCWId(m_cwCallsign);
|
2016-06-03 16:28:55 +02:00
|
|
|
|
2016-10-17 19:01:38 +02:00
|
|
|
m_cwIdTimer.setTimeout(m_cwIdTime);
|
|
|
|
m_cwIdTimer.start();
|
2016-06-03 16:28:55 +02:00
|
|
|
}
|
2016-05-09 22:55:44 +02:00
|
|
|
}
|
|
|
|
|
2019-11-05 09:42:21 +01:00
|
|
|
switch (dmrBeacons) {
|
|
|
|
case DMR_BEACONS_TIMED:
|
|
|
|
dmrBeaconIntervalTimer.clock(ms);
|
|
|
|
if (dmrBeaconIntervalTimer.isRunning() && dmrBeaconIntervalTimer.hasExpired()) {
|
|
|
|
if ((m_mode == MODE_IDLE || m_mode == MODE_DMR) && !m_modem->hasTX()) {
|
|
|
|
if (!m_fixedMode && m_mode == MODE_IDLE)
|
|
|
|
setMode(MODE_DMR);
|
|
|
|
dmrBeaconIntervalTimer.start();
|
|
|
|
dmrBeaconDurationTimer.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DMR_BEACONS_NETWORK:
|
|
|
|
if (m_dmrNetwork != NULL) {
|
|
|
|
bool beacon = m_dmrNetwork->wantsBeacon();
|
|
|
|
if (beacon) {
|
|
|
|
if ((m_mode == MODE_IDLE || m_mode == MODE_DMR) && !m_modem->hasTX()) {
|
|
|
|
if (!m_fixedMode && m_mode == MODE_IDLE)
|
|
|
|
setMode(MODE_DMR);
|
|
|
|
dmrBeaconDurationTimer.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2018-01-15 20:22:01 +01:00
|
|
|
}
|
|
|
|
|
2018-01-16 19:35:29 +01:00
|
|
|
dmrBeaconDurationTimer.clock(ms);
|
|
|
|
if (dmrBeaconDurationTimer.isRunning() && dmrBeaconDurationTimer.hasExpired()) {
|
2019-01-22 15:38:38 +01:00
|
|
|
if (!m_fixedMode)
|
|
|
|
setMode(MODE_IDLE);
|
2018-01-16 19:35:29 +01:00
|
|
|
dmrBeaconDurationTimer.stop();
|
2016-01-14 20:58:16 +01:00
|
|
|
}
|
|
|
|
|
2016-05-05 18:56:18 +02:00
|
|
|
m_dmrTXTimer.clock(ms);
|
|
|
|
if (m_dmrTXTimer.isRunning() && m_dmrTXTimer.hasExpired()) {
|
|
|
|
m_modem->writeDMRStart(false);
|
|
|
|
m_dmrTXTimer.stop();
|
|
|
|
}
|
|
|
|
|
2016-06-06 18:40:27 +02:00
|
|
|
if (ms < 5U)
|
|
|
|
CThread::sleep(5U);
|
2016-01-14 19:45:04 +01:00
|
|
|
}
|
|
|
|
|
2018-08-15 18:17:42 +02:00
|
|
|
setMode(MODE_QUIT);
|
2016-01-14 19:45:04 +01:00
|
|
|
|
|
|
|
m_modem->close();
|
|
|
|
delete m_modem;
|
|
|
|
|
|
|
|
m_display->close();
|
|
|
|
delete m_display;
|
|
|
|
|
2018-01-17 22:21:25 +01:00
|
|
|
if (m_dmrLookup != NULL)
|
|
|
|
m_dmrLookup->stop();
|
|
|
|
|
2016-01-14 19:45:04 +01:00
|
|
|
if (m_dmrNetwork != NULL) {
|
2021-04-08 19:36:27 +02:00
|
|
|
m_dmrNetwork->close(true);
|
2016-01-14 19:45:04 +01:00
|
|
|
delete m_dmrNetwork;
|
|
|
|
}
|
|
|
|
|
2018-03-22 08:13:13 +01:00
|
|
|
if (transparentSocket != NULL) {
|
|
|
|
transparentSocket->close();
|
|
|
|
delete transparentSocket;
|
|
|
|
}
|
|
|
|
|
2019-01-10 10:05:15 +01:00
|
|
|
if (m_remoteControl != NULL) {
|
|
|
|
m_remoteControl->close();
|
|
|
|
delete m_remoteControl;
|
2019-01-07 12:03:37 +01:00
|
|
|
}
|
|
|
|
|
2019-01-10 10:05:15 +01:00
|
|
|
delete m_dmr;
|
2016-01-14 19:45:04 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CMMDVMHost::createModem()
|
|
|
|
{
|
2021-02-16 23:34:25 +01:00
|
|
|
std::string protocol = m_conf.getModemProtocol();
|
|
|
|
std::string uartPort = m_conf.getModemUARTPort();
|
|
|
|
unsigned int uartSpeed = m_conf.getModemUARTSpeed();
|
|
|
|
std::string i2cPort = m_conf.getModemI2CPort();
|
|
|
|
unsigned int i2cAddress = m_conf.getModemI2CAddress();
|
|
|
|
std::string modemAddress = m_conf.getModemModemAddress();
|
2021-04-25 12:10:35 +02:00
|
|
|
unsigned short modemPort = m_conf.getModemModemPort();
|
|
|
|
std::string localAddress = m_conf.getModemLocalAddress();
|
|
|
|
unsigned short localPort = m_conf.getModemLocalPort();
|
2018-06-12 20:40:49 +02:00
|
|
|
bool rxInvert = m_conf.getModemRXInvert();
|
|
|
|
bool txInvert = m_conf.getModemTXInvert();
|
|
|
|
bool pttInvert = m_conf.getModemPTTInvert();
|
|
|
|
unsigned int txDelay = m_conf.getModemTXDelay();
|
|
|
|
unsigned int dmrDelay = m_conf.getModemDMRDelay();
|
|
|
|
float rxLevel = m_conf.getModemRXLevel();
|
|
|
|
float cwIdTXLevel = m_conf.getModemCWIdTXLevel();
|
|
|
|
float dmrTXLevel = m_conf.getModemDMRTXLevel();
|
|
|
|
bool trace = m_conf.getModemTrace();
|
|
|
|
bool debug = m_conf.getModemDebug();
|
|
|
|
unsigned int colorCode = m_conf.getDMRColorCode();
|
|
|
|
unsigned int rxFrequency = m_conf.getRXFrequency();
|
|
|
|
unsigned int txFrequency = m_conf.getTXFrequency();
|
|
|
|
int rxOffset = m_conf.getModemRXOffset();
|
|
|
|
int txOffset = m_conf.getModemTXOffset();
|
|
|
|
int rxDCOffset = m_conf.getModemRXDCOffset();
|
|
|
|
int txDCOffset = m_conf.getModemTXDCOffset();
|
|
|
|
float rfLevel = m_conf.getModemRFLevel();
|
2020-07-13 17:02:04 +02:00
|
|
|
bool useCOSAsLockout = m_conf.getModemUseCOSAsLockout();
|
2016-01-14 19:45:04 +01:00
|
|
|
|
|
|
|
LogInfo("Modem Parameters");
|
2018-07-19 15:09:00 +02:00
|
|
|
LogInfo(" Protocol: %s", protocol.c_str());
|
2021-02-16 23:34:25 +01:00
|
|
|
|
|
|
|
if (protocol == "uart") {
|
|
|
|
LogInfo(" UART Port: %s", uartPort.c_str());
|
|
|
|
LogInfo(" UART Speed: %u", uartSpeed);
|
|
|
|
} else if (protocol == "udp") {
|
|
|
|
LogInfo(" Modem Address: %s", modemAddress.c_str());
|
2021-04-25 12:10:35 +02:00
|
|
|
LogInfo(" Modem Port: %hu", modemPort);
|
|
|
|
LogInfo(" Local Address: %s", localAddress.c_str());
|
|
|
|
LogInfo(" Local Port: %hu", localPort);
|
2021-02-16 23:34:25 +01:00
|
|
|
}
|
|
|
|
#if defined(__linux__)
|
|
|
|
else if (protocol == "i2c") {
|
|
|
|
LogInfo(" I2C Port: %s", i2cPort.c_str());
|
|
|
|
LogInfo(" I2C Address: %02X", i2cAddress);
|
|
|
|
}
|
2020-12-15 17:21:07 +01:00
|
|
|
#endif
|
2021-02-16 23:34:25 +01:00
|
|
|
|
2016-01-14 19:45:04 +01:00
|
|
|
LogInfo(" RX Invert: %s", rxInvert ? "yes" : "no");
|
|
|
|
LogInfo(" TX Invert: %s", txInvert ? "yes" : "no");
|
|
|
|
LogInfo(" PTT Invert: %s", pttInvert ? "yes" : "no");
|
2016-03-17 19:12:14 +01:00
|
|
|
LogInfo(" TX Delay: %ums", txDelay);
|
2017-06-14 17:44:23 +02:00
|
|
|
LogInfo(" RX Offset: %dHz", rxOffset);
|
|
|
|
LogInfo(" TX Offset: %dHz", txOffset);
|
2017-10-28 13:37:32 +02:00
|
|
|
LogInfo(" RX DC Offset: %d", rxDCOffset);
|
2017-08-20 13:07:57 +02:00
|
|
|
LogInfo(" TX DC Offset: %d", txDCOffset);
|
2017-12-30 16:05:11 +01:00
|
|
|
LogInfo(" RF Level: %.1f%%", rfLevel);
|
2016-03-21 22:50:45 +01:00
|
|
|
LogInfo(" DMR Delay: %u (%.1fms)", dmrDelay, float(dmrDelay) * 0.0416666F);
|
2017-06-02 17:34:55 +02:00
|
|
|
LogInfo(" RX Level: %.1f%%", rxLevel);
|
|
|
|
LogInfo(" CW Id TX Level: %.1f%%", cwIdTXLevel);
|
|
|
|
LogInfo(" DMR TX Level: %.1f%%", dmrTXLevel);
|
2017-06-14 17:44:23 +02:00
|
|
|
LogInfo(" TX Frequency: %uHz (%uHz)", txFrequency, txFrequency + txOffset);
|
2020-07-13 17:02:04 +02:00
|
|
|
LogInfo(" Use COS as Lockout: %s", useCOSAsLockout ? "yes" : "no");
|
2016-01-14 19:45:04 +01:00
|
|
|
|
2021-02-17 22:36:47 +01:00
|
|
|
m_modem = new CModem(m_duplex, rxInvert, txInvert, pttInvert, txDelay, dmrDelay, useCOSAsLockout, trace, debug);
|
2021-02-16 23:34:25 +01:00
|
|
|
|
2021-02-17 22:36:47 +01:00
|
|
|
IModemPort* port = NULL;
|
2021-02-16 23:34:25 +01:00
|
|
|
if (protocol == "uart")
|
2021-02-17 22:36:47 +01:00
|
|
|
port = new CUARTController(uartPort, uartSpeed, true);
|
2021-02-16 23:34:25 +01:00
|
|
|
else if (protocol == "udp")
|
2021-04-25 12:10:35 +02:00
|
|
|
port = new CUDPController(modemAddress, modemPort, localAddress, localPort);
|
2021-02-16 23:34:25 +01:00
|
|
|
#if defined(__linux__)
|
|
|
|
else if (protocol == "i2c")
|
2021-02-17 22:36:47 +01:00
|
|
|
port = new CI2CController(i2cPort, i2cAddress);
|
2021-02-16 23:34:25 +01:00
|
|
|
#endif
|
2021-02-17 20:35:28 +01:00
|
|
|
else if (protocol == "null")
|
2021-02-17 22:36:47 +01:00
|
|
|
port = new CNullController;
|
2021-02-16 23:34:25 +01:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
2021-02-17 22:36:47 +01:00
|
|
|
m_modem->setPort(port);
|
2020-12-15 17:21:07 +01:00
|
|
|
m_modem->setModeParams(m_dstarEnabled, m_dmrEnabled, m_ysfEnabled, m_p25Enabled, m_nxdnEnabled, m_m17Enabled, m_pocsagEnabled, m_fmEnabled, m_ax25Enabled);
|
2022-07-29 18:49:08 +02:00
|
|
|
m_modem->setLevels(rxLevel, cwIdTXLevel, dmrTXLevel);
|
|
|
|
m_modem->setRFParams(rxFrequency, rxOffset, txFrequency, txOffset, txDCOffset, rxDCOffset, rfLevel);
|
2020-04-19 16:36:29 +02:00
|
|
|
m_modem->setDMRParams(colorCode);
|
2020-04-18 15:59:19 +02:00
|
|
|
|
2016-01-14 19:45:04 +01:00
|
|
|
bool ret = m_modem->open();
|
|
|
|
if (!ret) {
|
|
|
|
delete m_modem;
|
|
|
|
m_modem = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CMMDVMHost::createDMRNetwork()
|
|
|
|
{
|
2021-04-25 12:10:35 +02:00
|
|
|
std::string remoteAddress = m_conf.getDMRNetworkRemoteAddress();
|
|
|
|
unsigned short remotePort = m_conf.getDMRNetworkRemotePort();
|
|
|
|
std::string localAddress = m_conf.getDMRNetworkLocalAddress();
|
|
|
|
unsigned short localPort = m_conf.getDMRNetworkLocalPort();
|
2016-01-14 19:45:04 +01:00
|
|
|
unsigned int id = m_conf.getDMRId();
|
|
|
|
std::string password = m_conf.getDMRNetworkPassword();
|
|
|
|
bool debug = m_conf.getDMRNetworkDebug();
|
2016-09-06 20:42:15 +02:00
|
|
|
unsigned int jitter = m_conf.getDMRNetworkJitter();
|
2016-02-15 21:36:05 +01:00
|
|
|
bool slot1 = m_conf.getDMRNetworkSlot1();
|
|
|
|
bool slot2 = m_conf.getDMRNetworkSlot2();
|
2016-09-05 18:40:43 +02:00
|
|
|
HW_TYPE hwType = m_modem->getHWType();
|
2017-09-01 10:25:54 +02:00
|
|
|
m_dmrNetModeHang = m_conf.getDMRNetworkModeHang();
|
2020-12-06 17:12:54 +01:00
|
|
|
std::string options = m_conf.getDMRNetworkOptions();
|
|
|
|
|
|
|
|
std::string type = m_conf.getDMRNetworkType();
|
2016-01-14 19:45:04 +01:00
|
|
|
|
|
|
|
LogInfo("DMR Network Parameters");
|
2020-12-06 17:12:54 +01:00
|
|
|
LogInfo(" Type: %s", type.c_str());
|
2021-04-25 12:10:35 +02:00
|
|
|
LogInfo(" Remote Address: %s", remoteAddress.c_str());
|
|
|
|
LogInfo(" Remote Port: %hu", remotePort);
|
|
|
|
LogInfo(" Local Address: %s", localAddress.c_str());
|
|
|
|
LogInfo(" Local Port: %hu", localPort);
|
2016-09-06 20:42:15 +02:00
|
|
|
LogInfo(" Jitter: %ums", jitter);
|
2016-02-15 21:36:05 +01:00
|
|
|
LogInfo(" Slot 1: %s", slot1 ? "enabled" : "disabled");
|
|
|
|
LogInfo(" Slot 2: %s", slot2 ? "enabled" : "disabled");
|
2017-09-01 10:25:54 +02:00
|
|
|
LogInfo(" Mode Hang: %us", m_dmrNetModeHang);
|
2016-01-14 19:45:04 +01:00
|
|
|
|
2020-12-06 17:12:54 +01:00
|
|
|
if (type == "Direct")
|
2021-04-25 12:10:35 +02:00
|
|
|
m_dmrNetwork = new CDMRDirectNetwork(remoteAddress, remotePort, localAddress, localPort, id, password, m_duplex, VERSION, slot1, slot2, hwType, debug);
|
2020-12-06 17:12:54 +01:00
|
|
|
else
|
2021-04-25 12:10:35 +02:00
|
|
|
m_dmrNetwork = new CDMRGatewayNetwork(remoteAddress, remotePort, localAddress, localPort, id, m_duplex, VERSION, slot1, slot2, hwType, debug);
|
2016-11-03 20:27:52 +01:00
|
|
|
|
2017-08-20 13:07:57 +02:00
|
|
|
unsigned int rxFrequency = m_conf.getRXFrequency();
|
|
|
|
unsigned int txFrequency = m_conf.getTXFrequency();
|
2016-01-14 19:45:04 +01:00
|
|
|
unsigned int power = m_conf.getPower();
|
|
|
|
unsigned int colorCode = m_conf.getDMRColorCode();
|
2020-08-26 10:29:11 +02:00
|
|
|
|
2020-08-26 13:13:34 +02:00
|
|
|
LogInfo("Info Parameters");
|
2016-05-09 22:55:44 +02:00
|
|
|
LogInfo(" Callsign: %s", m_callsign.c_str());
|
2016-01-14 19:45:04 +01:00
|
|
|
LogInfo(" RX Frequency: %uHz", rxFrequency);
|
|
|
|
LogInfo(" TX Frequency: %uHz", txFrequency);
|
|
|
|
LogInfo(" Power: %uW", power);
|
|
|
|
|
2020-12-09 10:41:11 +01:00
|
|
|
if (type == "Direct") {
|
|
|
|
float latitude = m_conf.getLatitude();
|
|
|
|
float longitude = m_conf.getLongitude();
|
|
|
|
int height = m_conf.getHeight();
|
|
|
|
std::string location = m_conf.getLocation();
|
|
|
|
std::string description = m_conf.getDescription();
|
|
|
|
std::string url = m_conf.getURL();
|
|
|
|
|
|
|
|
LogInfo(" Latitude: %fdeg N", latitude);
|
|
|
|
LogInfo(" Longitude: %fdeg E", longitude);
|
|
|
|
LogInfo(" Height: %um", height);
|
|
|
|
LogInfo(" Location: \"%s\"", location.c_str());
|
|
|
|
LogInfo(" Description: \"%s\"", description.c_str());
|
|
|
|
LogInfo(" URL: \"%s\"", url.c_str());
|
|
|
|
|
|
|
|
m_dmrNetwork->setConfig(m_callsign, rxFrequency, txFrequency, power, colorCode, latitude, longitude, height, location, description, url);
|
|
|
|
} else {
|
|
|
|
m_dmrNetwork->setConfig(m_callsign, rxFrequency, txFrequency, power, colorCode, 0.0F, 0.0F, 0, "", "", "");
|
|
|
|
}
|
|
|
|
|
2020-12-06 17:12:54 +01:00
|
|
|
if (!options.empty()) {
|
|
|
|
LogInfo(" Options: %s", options.c_str());
|
|
|
|
|
|
|
|
m_dmrNetwork->setOptions(options);
|
|
|
|
}
|
|
|
|
|
2016-01-14 19:45:04 +01:00
|
|
|
bool ret = m_dmrNetwork->open();
|
|
|
|
if (!ret) {
|
|
|
|
delete m_dmrNetwork;
|
|
|
|
m_dmrNetwork = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-25 19:11:44 +01:00
|
|
|
m_dmrNetwork->enable(true);
|
|
|
|
|
2016-01-14 19:45:04 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMMDVMHost::readParams()
|
|
|
|
{
|
2018-06-07 19:46:03 +02:00
|
|
|
m_dmrEnabled = m_conf.getDMREnabled();
|
|
|
|
m_duplex = m_conf.getDuplex();
|
|
|
|
m_callsign = m_conf.getCallsign();
|
|
|
|
m_id = m_conf.getId();
|
|
|
|
m_timeout = m_conf.getTimeout();
|
2016-06-22 19:03:56 +02:00
|
|
|
|
|
|
|
LogInfo("General Parameters");
|
|
|
|
LogInfo(" Callsign: %s", m_callsign.c_str());
|
2017-08-19 17:23:37 +02:00
|
|
|
LogInfo(" Id: %u", m_id);
|
2016-06-22 19:03:56 +02:00
|
|
|
LogInfo(" Duplex: %s", m_duplex ? "yes" : "no");
|
|
|
|
LogInfo(" Timeout: %us", m_timeout);
|
|
|
|
LogInfo(" DMR: %s", m_dmrEnabled ? "enabled" : "disabled");
|
2016-01-14 19:45:04 +01:00
|
|
|
}
|
|
|
|
|
2016-05-10 19:26:52 +02:00
|
|
|
void CMMDVMHost::setMode(unsigned char mode)
|
2016-02-02 19:17:36 +01:00
|
|
|
{
|
|
|
|
assert(m_modem != NULL);
|
|
|
|
assert(m_display != NULL);
|
|
|
|
|
2022-07-29 18:49:08 +02:00
|
|
|
switch(mode) {
|
2016-02-02 19:17:36 +01:00
|
|
|
case MODE_DMR:
|
2019-01-19 22:28:58 +01:00
|
|
|
if (m_dmrNetwork != NULL)
|
|
|
|
m_dmrNetwork->enable(true);
|
2022-07-29 18:49:08 +02:00
|
|
|
|
2016-03-29 18:59:15 +02:00
|
|
|
m_modem->setMode(MODE_DMR);
|
2016-05-05 18:56:18 +02:00
|
|
|
if (m_duplex) {
|
2016-03-25 21:54:51 +01:00
|
|
|
m_modem->writeDMRStart(true);
|
2016-05-05 18:56:18 +02:00
|
|
|
m_dmrTXTimer.start();
|
|
|
|
}
|
2016-02-02 19:17:36 +01:00
|
|
|
m_mode = MODE_DMR;
|
|
|
|
m_modeTimer.start();
|
2016-10-17 19:01:38 +02:00
|
|
|
m_cwIdTimer.stop();
|
2018-10-11 08:50:30 +02:00
|
|
|
createLockFile("DMR");
|
2016-02-02 19:17:36 +01:00
|
|
|
break;
|
|
|
|
|
2016-03-03 19:01:01 +01:00
|
|
|
case MODE_LOCKOUT:
|
|
|
|
if (m_dmrNetwork != NULL)
|
|
|
|
m_dmrNetwork->enable(false);
|
2019-01-19 18:15:24 +01:00
|
|
|
if (m_dmr != NULL)
|
|
|
|
m_dmr->enable(false);
|
2016-05-05 18:56:18 +02:00
|
|
|
if (m_mode == MODE_DMR && m_duplex && m_modem->hasTX()) {
|
2016-03-03 19:01:01 +01:00
|
|
|
m_modem->writeDMRStart(false);
|
2016-05-05 18:56:18 +02:00
|
|
|
m_dmrTXTimer.stop();
|
|
|
|
}
|
2016-03-29 18:59:15 +02:00
|
|
|
m_modem->setMode(MODE_IDLE);
|
2016-03-03 19:01:01 +01:00
|
|
|
m_display->setLockout();
|
|
|
|
m_mode = MODE_LOCKOUT;
|
|
|
|
m_modeTimer.stop();
|
2016-05-09 22:55:44 +02:00
|
|
|
m_cwIdTimer.stop();
|
2018-10-11 08:50:30 +02:00
|
|
|
removeLockFile();
|
2016-03-03 19:01:01 +01:00
|
|
|
break;
|
|
|
|
|
2016-03-21 23:47:58 +01:00
|
|
|
case MODE_ERROR:
|
2016-05-10 19:26:52 +02:00
|
|
|
LogMessage("Mode set to Error");
|
2016-03-21 23:47:58 +01:00
|
|
|
if (m_dmrNetwork != NULL)
|
|
|
|
m_dmrNetwork->enable(false);
|
2019-01-19 18:15:24 +01:00
|
|
|
if (m_dmr != NULL)
|
|
|
|
m_dmr->enable(false);
|
2016-05-05 18:56:18 +02:00
|
|
|
if (m_mode == MODE_DMR && m_duplex && m_modem->hasTX()) {
|
|
|
|
m_modem->writeDMRStart(false);
|
|
|
|
m_dmrTXTimer.stop();
|
|
|
|
}
|
2016-03-21 23:47:58 +01:00
|
|
|
m_display->setError("MODEM");
|
|
|
|
m_mode = MODE_ERROR;
|
|
|
|
m_modeTimer.stop();
|
2016-05-09 22:55:44 +02:00
|
|
|
m_cwIdTimer.stop();
|
2018-10-11 08:50:30 +02:00
|
|
|
removeLockFile();
|
2016-03-21 23:47:58 +01:00
|
|
|
break;
|
|
|
|
|
2016-02-02 19:17:36 +01:00
|
|
|
default:
|
|
|
|
if (m_dmrNetwork != NULL)
|
|
|
|
m_dmrNetwork->enable(true);
|
2019-01-19 18:15:24 +01:00
|
|
|
if (m_dmr != NULL)
|
2019-01-19 22:28:58 +01:00
|
|
|
m_dmr->enable(true);
|
2016-05-05 18:56:18 +02:00
|
|
|
if (m_mode == MODE_DMR && m_duplex && m_modem->hasTX()) {
|
2016-02-02 19:17:36 +01:00
|
|
|
m_modem->writeDMRStart(false);
|
2016-05-05 18:56:18 +02:00
|
|
|
m_dmrTXTimer.stop();
|
|
|
|
}
|
2016-03-29 18:59:15 +02:00
|
|
|
m_modem->setMode(MODE_IDLE);
|
2017-03-07 14:39:41 +01:00
|
|
|
if (m_mode == MODE_ERROR) {
|
2016-05-12 19:04:50 +02:00
|
|
|
m_modem->sendCWId(m_callsign);
|
2016-10-17 19:01:38 +02:00
|
|
|
m_cwIdTimer.setTimeout(m_cwIdTime);
|
|
|
|
m_cwIdTimer.start();
|
|
|
|
} else {
|
|
|
|
m_cwIdTimer.setTimeout(m_cwIdTime / 4U);
|
2016-05-12 19:04:50 +02:00
|
|
|
m_cwIdTimer.start();
|
|
|
|
}
|
2016-02-02 19:17:36 +01:00
|
|
|
m_display->setIdle();
|
2018-10-11 08:50:30 +02:00
|
|
|
if (mode == MODE_QUIT)
|
2018-08-15 18:17:42 +02:00
|
|
|
m_display->setQuit();
|
2016-02-02 19:17:36 +01:00
|
|
|
m_mode = MODE_IDLE;
|
|
|
|
m_modeTimer.stop();
|
2018-10-10 21:05:24 +02:00
|
|
|
removeLockFile();
|
2016-02-02 19:17:36 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-10-10 21:05:24 +02:00
|
|
|
|
2018-10-11 08:50:30 +02:00
|
|
|
void CMMDVMHost::createLockFile(const char* mode) const
|
2018-10-10 21:05:24 +02:00
|
|
|
{
|
|
|
|
if (m_lockFileEnabled) {
|
2018-10-11 08:50:30 +02:00
|
|
|
FILE* fp = ::fopen(m_lockFileName.c_str(), "wt");
|
|
|
|
if (fp != NULL) {
|
|
|
|
::fprintf(fp, "%s\n", mode);
|
2018-10-10 21:05:24 +02:00
|
|
|
::fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-11 08:50:30 +02:00
|
|
|
void CMMDVMHost::removeLockFile() const
|
2018-10-10 21:05:24 +02:00
|
|
|
{
|
2018-10-11 08:50:30 +02:00
|
|
|
if (m_lockFileEnabled)
|
|
|
|
::remove(m_lockFileName.c_str());
|
2018-10-10 21:05:24 +02:00
|
|
|
}
|
2018-10-11 08:50:30 +02:00
|
|
|
|
2019-01-10 10:05:15 +01:00
|
|
|
void CMMDVMHost::remoteControl()
|
|
|
|
{
|
2019-01-11 14:02:33 +01:00
|
|
|
if (m_remoteControl == NULL)
|
2019-01-10 10:05:15 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
REMOTE_COMMAND command = m_remoteControl->getCommand();
|
2019-01-22 15:56:15 +01:00
|
|
|
switch (command) {
|
2019-01-10 10:05:15 +01:00
|
|
|
case RCD_MODE_IDLE:
|
2019-01-22 15:38:38 +01:00
|
|
|
m_fixedMode = false;
|
|
|
|
setMode(MODE_IDLE);
|
2019-01-10 10:05:15 +01:00
|
|
|
break;
|
|
|
|
case RCD_MODE_LOCKOUT:
|
2019-01-22 15:38:38 +01:00
|
|
|
m_fixedMode = false;
|
|
|
|
setMode(MODE_LOCKOUT);
|
2019-01-10 10:05:15 +01:00
|
|
|
break;
|
|
|
|
case RCD_MODE_DMR:
|
2019-01-22 15:56:15 +01:00
|
|
|
if (m_dmr != NULL)
|
2019-01-22 15:38:38 +01:00
|
|
|
processModeCommand(MODE_DMR, m_dmrRFModeHang);
|
2019-01-10 10:05:15 +01:00
|
|
|
break;
|
2020-05-02 22:40:55 +02:00
|
|
|
case RCD_ENABLE_DMR:
|
2020-12-15 17:21:07 +01:00
|
|
|
if (m_dmr != NULL && !m_dmrEnabled)
|
2020-05-02 22:40:55 +02:00
|
|
|
processEnableCommand(m_dmrEnabled, true);
|
2021-01-01 15:45:08 +01:00
|
|
|
if (m_dmrNetwork != NULL)
|
|
|
|
m_dmrNetwork->enable(true);
|
2020-05-02 22:40:55 +02:00
|
|
|
break;
|
|
|
|
case RCD_DISABLE_DMR:
|
2020-12-15 17:21:07 +01:00
|
|
|
if (m_dmr != NULL && m_dmrEnabled)
|
2020-05-02 22:40:55 +02:00
|
|
|
processEnableCommand(m_dmrEnabled, false);
|
2021-01-01 15:45:08 +01:00
|
|
|
if (m_dmrNetwork != NULL)
|
|
|
|
m_dmrNetwork->enable(false);
|
2020-05-02 22:40:55 +02:00
|
|
|
break;
|
2020-05-05 20:24:29 +02:00
|
|
|
case RCD_CW:
|
2020-05-05 20:30:56 +02:00
|
|
|
setMode(MODE_IDLE); // Force the modem to go idle so that we can send the CW text.
|
2020-12-15 17:21:07 +01:00
|
|
|
if (!m_modem->hasTX()) {
|
|
|
|
std::string cwtext;
|
|
|
|
for (unsigned int i = 0U; i < m_remoteControl->getArgCount(); i++) {
|
|
|
|
if (i > 0U)
|
|
|
|
cwtext += " ";
|
|
|
|
cwtext += m_remoteControl->getArgString(i);
|
|
|
|
}
|
|
|
|
m_display->writeCW();
|
|
|
|
m_modem->sendCWId(cwtext);
|
|
|
|
}
|
|
|
|
break;
|
2021-01-01 14:54:03 +01:00
|
|
|
case RCD_RELOAD:
|
|
|
|
m_reload = true;
|
|
|
|
break;
|
2019-01-10 10:05:15 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-01-22 15:38:38 +01:00
|
|
|
|
|
|
|
void CMMDVMHost::processModeCommand(unsigned char mode, unsigned int timeout)
|
|
|
|
{
|
|
|
|
m_fixedMode = false;
|
|
|
|
m_modeTimer.setTimeout(timeout);
|
|
|
|
|
|
|
|
if (m_remoteControl->getArgCount() > 0U) {
|
|
|
|
if (m_remoteControl->getArgString(0U) == "fixed") {
|
|
|
|
m_fixedMode = true;
|
|
|
|
} else {
|
|
|
|
unsigned int t = m_remoteControl->getArgUInt(0U);
|
|
|
|
if (t > 0U)
|
|
|
|
m_modeTimer.setTimeout(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setMode(mode);
|
|
|
|
}
|
2020-05-02 22:40:55 +02:00
|
|
|
|
|
|
|
void CMMDVMHost::processEnableCommand(bool& mode, bool enabled)
|
|
|
|
{
|
|
|
|
LogDebug("Setting mode current=%s new=%s",mode ? "true" : "false",enabled ? "true" : "false");
|
2020-12-15 17:21:07 +01:00
|
|
|
|
|
|
|
mode = enabled;
|
|
|
|
|
|
|
|
m_modem->setModeParams(m_dstarEnabled, m_dmrEnabled, m_ysfEnabled, m_p25Enabled, m_nxdnEnabled, m_m17Enabled, m_pocsagEnabled, m_fmEnabled, m_ax25Enabled);
|
2020-05-02 22:40:55 +02:00
|
|
|
if (!m_modem->writeConfig())
|
|
|
|
LogError("Cannot write Config to MMDVM");
|
|
|
|
}
|
2021-03-22 20:27:08 +01:00
|
|
|
|
|
|
|
void CMMDVMHost::buildNetworkStatusString(std::string &str)
|
|
|
|
{
|
|
|
|
str = "";
|
|
|
|
str += std::string(" dmr:") + (((m_dmrNetwork == NULL) || (m_dmrEnabled == false)) ? "n/a" : (m_dmrNetwork->isConnected() ? "conn" : "disc"));
|
|
|
|
str += std::string(" fm:") + (m_fmEnabled ? "conn" : "n/a");
|
|
|
|
}
|
2022-01-21 11:51:41 +01:00
|
|
|
|
|
|
|
void CMMDVMHost::buildNetworkHostsString(std::string &str)
|
|
|
|
{
|
|
|
|
str = "";
|
|
|
|
|
|
|
|
str += std::string(" dmr:\"") + ((m_dmrEnabled && (m_dmrNetwork != NULL)) ? m_conf.getDMRNetworkRemoteAddress() : "NONE") + "\"";
|
|
|
|
}
|