2016-01-14 18:45:04 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
#include "Log.h"
|
|
|
|
#include "Version.h"
|
|
|
|
#include "StopWatch.h"
|
|
|
|
#include "Defines.h"
|
2016-01-27 20:01:50 +00:00
|
|
|
#include "DStarControl.h"
|
2016-01-14 18:45:04 +00:00
|
|
|
#include "DMRControl.h"
|
|
|
|
#include "TFTSerial.h"
|
|
|
|
#include "NullDisplay.h"
|
2016-02-16 07:27:13 +00:00
|
|
|
#include "YSFControl.h"
|
2016-04-06 18:53:25 +00:00
|
|
|
#include "Nextion.h"
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-03-15 07:53:38 +00:00
|
|
|
#if defined(HD44780)
|
2016-03-14 22:58:09 +00:00
|
|
|
#include "HD44780.h"
|
|
|
|
#endif
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
#include <cstdio>
|
2016-04-04 18:03:38 +00:00
|
|
|
#include <vector>
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-01-14 19:58:16 +00:00
|
|
|
#if !defined(_WIN32) && !defined(_WIN64)
|
2016-01-14 18:45:04 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static bool m_killed = false;
|
|
|
|
|
2016-01-14 19:58:16 +00:00
|
|
|
#if !defined(_WIN32) && !defined(_WIN64)
|
2016-01-14 18:45:04 +00:00
|
|
|
static void sigHandler(int)
|
|
|
|
{
|
|
|
|
m_killed = true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-01-23 17:54:23 +00:00
|
|
|
const char* HEADER1 = "This software is for use on amateur radio networks only,";
|
|
|
|
const char* HEADER2 = "it is to be used for educational purposes only. Its use on";
|
|
|
|
const char* HEADER3 = "commercial networks is strictly prohibited.";
|
|
|
|
const char* HEADER4 = "Copyright(C) 2015, 2016 by Jonathan Naylor, G4KLX";
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
if (argc == 1) {
|
|
|
|
::fprintf(stderr, "Usage: MMDVMHost <conf file>\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-01-14 19:58:16 +00:00
|
|
|
#if !defined(_WIN32) && !defined(_WIN64)
|
2016-01-14 18:45:04 +00:00
|
|
|
::signal(SIGUSR1, sigHandler);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CMMDVMHost* host = new CMMDVMHost(std::string(argv[1]));
|
|
|
|
int ret2 = host->run();
|
|
|
|
|
|
|
|
delete host;
|
|
|
|
|
|
|
|
::LogFinalise();
|
|
|
|
|
|
|
|
return ret2;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMMDVMHost::CMMDVMHost(const std::string& confFile) :
|
|
|
|
m_conf(confFile),
|
|
|
|
m_modem(NULL),
|
2016-01-25 21:00:19 +00:00
|
|
|
m_dstarNetwork(NULL),
|
2016-01-14 18:45:04 +00:00
|
|
|
m_dmrNetwork(NULL),
|
|
|
|
m_display(NULL),
|
2016-02-02 18:17:36 +00:00
|
|
|
m_mode(MODE_IDLE),
|
|
|
|
m_modeTimer(1000U),
|
2016-03-07 19:45:19 +00:00
|
|
|
m_duplex(false),
|
2016-01-14 18:45:04 +00:00
|
|
|
m_dstarEnabled(false),
|
|
|
|
m_dmrEnabled(false),
|
|
|
|
m_ysfEnabled(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CMMDVMHost::~CMMDVMHost()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int CMMDVMHost::run()
|
|
|
|
{
|
|
|
|
bool ret = m_conf.read();
|
|
|
|
if (!ret) {
|
|
|
|
::fprintf(stderr, "MMDVMHost: cannot read the .ini file\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-03-07 18:42:05 +00:00
|
|
|
ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel());
|
2016-01-14 18:45:04 +00:00
|
|
|
if (!ret) {
|
|
|
|
::fprintf(stderr, "MMDVMHost: unable to open the log file\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
LogInfo(HEADER1);
|
|
|
|
LogInfo(HEADER2);
|
|
|
|
LogInfo(HEADER3);
|
2016-01-23 17:54:23 +00:00
|
|
|
LogInfo(HEADER4);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
LogMessage("MMDVMHost-%s is starting", VERSION);
|
|
|
|
|
|
|
|
readParams();
|
|
|
|
|
|
|
|
ret = createModem();
|
|
|
|
if (!ret)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
createDisplay();
|
|
|
|
|
2016-01-25 21:00:19 +00:00
|
|
|
if (m_dstarEnabled && m_conf.getDStarNetworkEnabled()) {
|
|
|
|
ret = createDStarNetwork();
|
|
|
|
if (!ret)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-01-18 21:24:41 +00:00
|
|
|
if (m_dmrEnabled && m_conf.getDMRNetworkEnabled()) {
|
2016-01-14 18:45:04 +00:00
|
|
|
ret = createDMRNetwork();
|
|
|
|
if (!ret)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-01-14 19:58:16 +00:00
|
|
|
CTimer dmrBeaconTimer(1000U, 4U);
|
|
|
|
bool dmrBeaconsEnabled = m_dmrEnabled && m_conf.getDMRBeacons();
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
CStopWatch stopWatch;
|
|
|
|
stopWatch.start();
|
|
|
|
|
2016-01-27 20:01:50 +00:00
|
|
|
CDStarControl* dstar = NULL;
|
|
|
|
if (m_dstarEnabled) {
|
|
|
|
std::string callsign = m_conf.getCallsign();
|
2016-04-06 17:46:05 +00:00
|
|
|
std::string module = m_conf.getDStarModule();
|
|
|
|
bool selfOnly = m_conf.getDStarSelfOnly();
|
2016-01-27 20:01:50 +00:00
|
|
|
unsigned int timeout = m_conf.getTimeout();
|
2016-04-06 17:46:05 +00:00
|
|
|
std::vector<std::string> blackList = m_conf.getDStarBlackList();
|
2016-01-27 20:01:50 +00:00
|
|
|
|
|
|
|
LogInfo("D-Star Parameters");
|
|
|
|
LogInfo(" Callsign: %s", callsign.c_str());
|
|
|
|
LogInfo(" Module: %s", module.c_str());
|
2016-04-04 16:40:05 +00:00
|
|
|
LogInfo(" Self Only: %s", selfOnly ? "yes" : "no");
|
2016-04-06 17:46:05 +00:00
|
|
|
if (blackList.size() > 0U)
|
|
|
|
LogInfo(" Black List: %u", blackList.size());
|
2016-01-27 20:01:50 +00:00
|
|
|
LogInfo(" Timeout: %us", timeout);
|
|
|
|
|
2016-04-06 17:46:05 +00:00
|
|
|
dstar = new CDStarControl(callsign, module, selfOnly, blackList, m_dstarNetwork, m_display, timeout, m_duplex);
|
2016-01-27 20:01:50 +00:00
|
|
|
}
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
CDMRControl* dmr = NULL;
|
|
|
|
if (m_dmrEnabled) {
|
|
|
|
unsigned int id = m_conf.getDMRId();
|
|
|
|
unsigned int colorCode = m_conf.getDMRColorCode();
|
2016-04-04 16:40:05 +00:00
|
|
|
bool selfOnly = m_conf.getDMRSelfOnly();
|
2016-04-04 18:03:38 +00:00
|
|
|
std::vector<unsigned int> prefixes = m_conf.getDMRPrefixes();
|
2016-04-06 17:46:05 +00:00
|
|
|
std::vector<unsigned int> blackList = m_conf.getDMRBlackList();
|
2016-01-14 18:45:04 +00:00
|
|
|
unsigned int timeout = m_conf.getTimeout();
|
2016-04-12 17:26:13 +00:00
|
|
|
std::string lookupFile = m_conf.getDMRLookupFile();
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
LogInfo("DMR Parameters");
|
|
|
|
LogInfo(" Id: %u", id);
|
|
|
|
LogInfo(" Color Code: %u", colorCode);
|
2016-04-04 16:40:05 +00:00
|
|
|
LogInfo(" Self Only: %s", selfOnly ? "yes" : "no");
|
2016-04-04 18:03:38 +00:00
|
|
|
LogInfo(" Prefixes: %u", prefixes.size());
|
2016-04-06 17:46:05 +00:00
|
|
|
if (blackList.size() > 0U)
|
|
|
|
LogInfo(" Black List: %u", blackList.size());
|
2016-01-14 18:45:04 +00:00
|
|
|
LogInfo(" Timeout: %us", timeout);
|
2016-04-12 17:26:13 +00:00
|
|
|
LogInfo(" Lookup File: %s", lookupFile.length() > 0U ? lookupFile.c_str() : "None");
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-04-12 17:26:13 +00:00
|
|
|
dmr = new CDMRControl(id, colorCode, selfOnly, prefixes, blackList, timeout, m_modem, m_dmrNetwork, m_display, m_duplex, lookupFile);
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
2016-02-16 07:27:13 +00:00
|
|
|
CYSFControl* ysf = NULL;
|
|
|
|
if (m_ysfEnabled) {
|
|
|
|
std::string callsign = m_conf.getCallsign();
|
|
|
|
unsigned int timeout = m_conf.getTimeout();
|
2016-02-22 21:13:48 +00:00
|
|
|
bool parrot = m_conf.getFusionParrotEnabled();
|
2016-02-16 07:27:13 +00:00
|
|
|
|
|
|
|
LogInfo("System Fusion Parameters");
|
|
|
|
LogInfo(" Callsign: %s", callsign.c_str());
|
|
|
|
LogInfo(" Timeout: %us", timeout);
|
2016-02-22 21:13:48 +00:00
|
|
|
LogInfo(" Parrot: %s", parrot ? "enabled" : "disabled");
|
2016-02-16 07:27:13 +00:00
|
|
|
|
2016-03-07 19:45:19 +00:00
|
|
|
ysf = new CYSFControl(callsign, m_display, timeout, m_duplex, parrot);
|
2016-02-16 07:27:13 +00:00
|
|
|
}
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-02-02 18:17:36 +00:00
|
|
|
m_modeTimer.setTimeout(m_conf.getModeHang());
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-02-02 18:17:36 +00:00
|
|
|
setMode(MODE_IDLE);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
while (!m_killed) {
|
2016-03-03 21:45:20 +00:00
|
|
|
bool lockout = m_modem->hasLockout();
|
|
|
|
if (lockout && m_mode != MODE_LOCKOUT)
|
|
|
|
setMode(MODE_LOCKOUT);
|
|
|
|
else if (!lockout && m_mode == MODE_LOCKOUT)
|
|
|
|
setMode(MODE_IDLE);
|
|
|
|
|
2016-03-21 22:47:58 +00: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);
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
unsigned char data[200U];
|
|
|
|
unsigned int len;
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
len = m_modem->readDStarData(data);
|
|
|
|
if (dstar != NULL && len > 0U) {
|
2016-02-02 18:17:36 +00:00
|
|
|
if (m_mode == MODE_IDLE) {
|
|
|
|
bool ret = dstar->writeModem(data);
|
|
|
|
if (ret)
|
|
|
|
setMode(MODE_DSTAR);
|
|
|
|
} else if (m_mode == MODE_DSTAR) {
|
2016-02-02 08:00:04 +00:00
|
|
|
dstar->writeModem(data);
|
2016-02-02 18:17:36 +00:00
|
|
|
m_modeTimer.start();
|
2016-03-07 19:45:19 +00:00
|
|
|
} else if (m_mode != MODE_LOCKOUT) {
|
2016-02-03 09:55:08 +00:00
|
|
|
LogWarning("D-Star modem data received when in mode %u", m_mode);
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
len = m_modem->readDMRData1(data);
|
|
|
|
if (dmr != NULL && len > 0U) {
|
2016-02-02 18:17:36 +00:00
|
|
|
if (m_mode == MODE_IDLE) {
|
2016-03-07 19:45:19 +00:00
|
|
|
if (m_duplex) {
|
|
|
|
bool ret = dmr->processWakeup(data);
|
|
|
|
if (ret)
|
|
|
|
setMode(MODE_DMR);
|
|
|
|
} else {
|
2016-02-02 18:17:36 +00:00
|
|
|
setMode(MODE_DMR);
|
2016-03-07 19:45:19 +00:00
|
|
|
dmr->writeModemSlot1(data);
|
|
|
|
dmrBeaconTimer.stop();
|
|
|
|
}
|
2016-02-02 18:17:36 +00:00
|
|
|
} else if (m_mode == MODE_DMR) {
|
2016-01-14 18:45:04 +00:00
|
|
|
dmr->writeModemSlot1(data);
|
2016-01-14 19:58:16 +00:00
|
|
|
dmrBeaconTimer.stop();
|
2016-02-02 18:17:36 +00:00
|
|
|
m_modeTimer.start();
|
2016-03-07 19:45:19 +00:00
|
|
|
} else if (m_mode != MODE_LOCKOUT) {
|
2016-02-03 09:55:08 +00:00
|
|
|
LogWarning("DMR modem data received when in mode %u", m_mode);
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
len = m_modem->readDMRData2(data);
|
|
|
|
if (dmr != NULL && len > 0U) {
|
2016-02-02 18:17:36 +00:00
|
|
|
if (m_mode == MODE_IDLE) {
|
2016-03-07 19:45:19 +00:00
|
|
|
if (m_duplex) {
|
|
|
|
bool ret = dmr->processWakeup(data);
|
|
|
|
if (ret)
|
|
|
|
setMode(MODE_DMR);
|
|
|
|
} else {
|
2016-02-02 18:17:36 +00:00
|
|
|
setMode(MODE_DMR);
|
2016-03-07 19:45:19 +00:00
|
|
|
dmr->writeModemSlot2(data);
|
|
|
|
dmrBeaconTimer.stop();
|
|
|
|
}
|
2016-02-02 18:17:36 +00:00
|
|
|
} else if (m_mode == MODE_DMR) {
|
2016-01-14 18:45:04 +00:00
|
|
|
dmr->writeModemSlot2(data);
|
2016-01-14 19:58:16 +00:00
|
|
|
dmrBeaconTimer.stop();
|
2016-02-02 18:17:36 +00:00
|
|
|
m_modeTimer.start();
|
2016-03-07 19:45:19 +00:00
|
|
|
} else if (m_mode != MODE_LOCKOUT) {
|
2016-02-03 09:55:08 +00:00
|
|
|
LogWarning("DMR modem data received when in mode %u", m_mode);
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
len = m_modem->readYSFData(data);
|
|
|
|
if (ysf != NULL && len > 0U) {
|
2016-02-02 18:17:36 +00:00
|
|
|
if (m_mode == MODE_IDLE) {
|
2016-02-16 07:27:13 +00:00
|
|
|
bool ret = ysf->writeModem(data);
|
2016-02-02 18:17:36 +00:00
|
|
|
if (ret)
|
|
|
|
setMode(MODE_YSF);
|
|
|
|
} else if (m_mode == MODE_YSF) {
|
2016-02-16 07:27:13 +00:00
|
|
|
ysf->writeModem(data);
|
2016-02-02 18:17:36 +00:00
|
|
|
m_modeTimer.start();
|
2016-03-07 19:45:19 +00:00
|
|
|
} else if (m_mode != MODE_LOCKOUT) {
|
2016-02-03 09:55:08 +00:00
|
|
|
LogWarning("System Fusion modem data received when in mode %u", m_mode);
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-02 18:17:36 +00:00
|
|
|
if (m_modeTimer.isRunning() && m_modeTimer.hasExpired())
|
|
|
|
setMode(MODE_IDLE);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
if (dstar != NULL) {
|
2016-01-25 19:59:37 +00:00
|
|
|
ret = m_modem->hasDStarSpace();
|
2016-01-14 18:45:04 +00:00
|
|
|
if (ret) {
|
2016-01-27 20:01:50 +00:00
|
|
|
len = dstar->readModem(data);
|
2016-02-03 09:55:08 +00:00
|
|
|
if (len > 0U) {
|
2016-03-07 19:45:19 +00:00
|
|
|
if (m_mode == MODE_IDLE)
|
2016-02-03 09:55:08 +00:00
|
|
|
setMode(MODE_DSTAR);
|
2016-03-07 19:45:19 +00:00
|
|
|
if (m_mode == MODE_DSTAR) {
|
2016-02-03 09:55:08 +00:00
|
|
|
m_modem->writeDStarData(data, len);
|
|
|
|
m_modeTimer.start();
|
2016-03-07 19:45:19 +00:00
|
|
|
} else if (m_mode != MODE_LOCKOUT) {
|
2016-02-03 09:55:08 +00:00
|
|
|
LogWarning("D-Star data received when in mode %u", m_mode);
|
|
|
|
}
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dmr != NULL) {
|
|
|
|
ret = m_modem->hasDMRSpace1();
|
|
|
|
if (ret) {
|
|
|
|
len = dmr->readModemSlot1(data);
|
2016-02-03 09:55:08 +00:00
|
|
|
if (len > 0U) {
|
2016-03-07 19:45:19 +00:00
|
|
|
if (m_mode == MODE_IDLE)
|
2016-02-03 09:55:08 +00:00
|
|
|
setMode(MODE_DMR);
|
2016-03-07 19:45:19 +00:00
|
|
|
if (m_mode == MODE_DMR) {
|
2016-02-03 09:55:08 +00:00
|
|
|
m_modem->writeDMRData1(data, len);
|
|
|
|
dmrBeaconTimer.stop();
|
|
|
|
m_modeTimer.start();
|
2016-03-07 19:45:19 +00:00
|
|
|
} else if (m_mode != MODE_LOCKOUT) {
|
2016-02-03 09:55:08 +00:00
|
|
|
LogWarning("DMR data received when in mode %u", m_mode);
|
|
|
|
}
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = m_modem->hasDMRSpace2();
|
|
|
|
if (ret) {
|
|
|
|
len = dmr->readModemSlot2(data);
|
2016-02-03 09:55:08 +00:00
|
|
|
if (len > 0U) {
|
2016-03-07 19:45:19 +00:00
|
|
|
if (m_mode == MODE_IDLE)
|
2016-02-03 09:55:08 +00:00
|
|
|
setMode(MODE_DMR);
|
2016-03-07 19:45:19 +00:00
|
|
|
if (m_mode == MODE_DMR) {
|
2016-02-03 09:55:08 +00:00
|
|
|
m_modem->writeDMRData2(data, len);
|
|
|
|
dmrBeaconTimer.stop();
|
|
|
|
m_modeTimer.start();
|
2016-03-07 19:45:19 +00:00
|
|
|
} else if (m_mode != MODE_LOCKOUT) {
|
2016-02-03 09:55:08 +00:00
|
|
|
LogWarning("DMR data received when in mode %u", m_mode);
|
|
|
|
}
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ysf != NULL) {
|
2016-01-25 19:59:37 +00:00
|
|
|
ret = m_modem->hasYSFSpace();
|
2016-01-14 18:45:04 +00:00
|
|
|
if (ret) {
|
2016-02-16 07:27:13 +00:00
|
|
|
len = ysf->readModem(data);
|
2016-02-03 09:55:08 +00:00
|
|
|
if (len > 0U) {
|
2016-03-07 19:45:19 +00:00
|
|
|
if (m_mode == MODE_IDLE)
|
2016-02-03 09:55:08 +00:00
|
|
|
setMode(MODE_YSF);
|
2016-03-07 19:45:19 +00:00
|
|
|
if (m_mode == MODE_YSF) {
|
2016-02-03 09:55:08 +00:00
|
|
|
m_modem->writeYSFData(data, len);
|
|
|
|
m_modeTimer.start();
|
2016-03-07 19:45:19 +00:00
|
|
|
} else if (m_mode != MODE_LOCKOUT) {
|
2016-02-03 09:55:08 +00:00
|
|
|
LogWarning("System Fusion data received when in mode %u", m_mode);
|
|
|
|
}
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-14 19:58:16 +00:00
|
|
|
if (m_dmrNetwork != NULL) {
|
|
|
|
bool run = m_dmrNetwork->wantsBeacon();
|
2016-02-02 18:17:36 +00:00
|
|
|
if (dmrBeaconsEnabled && run && m_mode == MODE_IDLE) {
|
2016-02-04 18:11:29 +00:00
|
|
|
setMode(MODE_DMR, false);
|
2016-01-14 19:58:16 +00:00
|
|
|
dmrBeaconTimer.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
unsigned int ms = stopWatch.elapsed();
|
2016-02-19 06:21:40 +00:00
|
|
|
stopWatch.start();
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
m_modem->clock(ms);
|
2016-02-02 18:17:36 +00:00
|
|
|
m_modeTimer.clock(ms);
|
2016-02-19 06:21:40 +00:00
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
if (dstar != NULL)
|
2016-03-14 20:55:15 +00:00
|
|
|
dstar->clock();
|
2016-01-14 18:45:04 +00:00
|
|
|
if (dmr != NULL)
|
2016-03-14 20:55:15 +00:00
|
|
|
dmr->clock();
|
2016-01-14 18:45:04 +00:00
|
|
|
if (ysf != NULL)
|
2016-03-14 20:55:15 +00:00
|
|
|
ysf->clock();
|
2016-02-19 06:21:40 +00:00
|
|
|
|
2016-01-26 19:56:10 +00:00
|
|
|
if (m_dstarNetwork != NULL)
|
|
|
|
m_dstarNetwork->clock(ms);
|
|
|
|
if (m_dmrNetwork != NULL)
|
|
|
|
m_dmrNetwork->clock(ms);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-01-14 19:58:16 +00:00
|
|
|
dmrBeaconTimer.clock(ms);
|
|
|
|
if (dmrBeaconTimer.isRunning() && dmrBeaconTimer.hasExpired()) {
|
2016-02-04 18:11:29 +00:00
|
|
|
setMode(MODE_IDLE, false);
|
2016-01-14 19:58:16 +00:00
|
|
|
dmrBeaconTimer.stop();
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
if (ms < 5U) {
|
2016-01-14 19:58:16 +00:00
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
2016-01-14 18:45:04 +00:00
|
|
|
::Sleep(5UL); // 5ms
|
|
|
|
#else
|
|
|
|
::usleep(5000); // 5ms
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LogMessage("MMDVMHost is exiting on receipt of SIGHUP1");
|
|
|
|
|
2016-02-02 18:17:36 +00:00
|
|
|
setMode(MODE_IDLE);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
m_modem->close();
|
|
|
|
delete m_modem;
|
|
|
|
|
|
|
|
m_display->close();
|
|
|
|
delete m_display;
|
|
|
|
|
2016-01-25 21:00:19 +00:00
|
|
|
if (m_dstarNetwork != NULL) {
|
|
|
|
m_dstarNetwork->close();
|
|
|
|
delete m_dstarNetwork;
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
if (m_dmrNetwork != NULL) {
|
|
|
|
m_dmrNetwork->close();
|
|
|
|
delete m_dmrNetwork;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete dstar;
|
|
|
|
delete dmr;
|
|
|
|
delete ysf;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CMMDVMHost::createModem()
|
|
|
|
{
|
2016-02-18 17:37:23 +00:00
|
|
|
std::string port = m_conf.getModemPort();
|
|
|
|
bool rxInvert = m_conf.getModemRXInvert();
|
|
|
|
bool txInvert = m_conf.getModemTXInvert();
|
|
|
|
bool pttInvert = m_conf.getModemPTTInvert();
|
|
|
|
unsigned int txDelay = m_conf.getModemTXDelay();
|
2016-03-17 18:12:14 +00:00
|
|
|
unsigned int dmrDelay = m_conf.getModemDMRDelay();
|
|
|
|
unsigned int rxLevel = m_conf.getModemRXLevel();
|
2016-02-18 17:37:23 +00:00
|
|
|
unsigned int txLevel = m_conf.getModemTXLevel();
|
|
|
|
bool debug = m_conf.getModemDebug();
|
|
|
|
unsigned int colorCode = m_conf.getDMRColorCode();
|
|
|
|
unsigned int rxFrequency = m_conf.getRxFrequency();
|
|
|
|
unsigned int txFrequency = m_conf.getTxFrequency();
|
2016-03-21 21:50:45 +00:00
|
|
|
int oscOffset = m_conf.getModemOscOffset();
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
LogInfo("Modem Parameters");
|
|
|
|
LogInfo(" Port: %s", port.c_str());
|
|
|
|
LogInfo(" RX Invert: %s", rxInvert ? "yes" : "no");
|
|
|
|
LogInfo(" TX Invert: %s", txInvert ? "yes" : "no");
|
|
|
|
LogInfo(" PTT Invert: %s", pttInvert ? "yes" : "no");
|
2016-03-17 18:12:14 +00:00
|
|
|
LogInfo(" TX Delay: %ums", txDelay);
|
2016-03-21 21:50:45 +00:00
|
|
|
LogInfo(" DMR Delay: %u (%.1fms)", dmrDelay, float(dmrDelay) * 0.0416666F);
|
2016-03-17 18:12:14 +00:00
|
|
|
LogInfo(" RX Level: %u%%", rxLevel);
|
|
|
|
LogInfo(" TX Level: %u%%", txLevel);
|
2016-02-18 17:37:23 +00:00
|
|
|
LogInfo(" RX Frequency: %uHz", rxFrequency);
|
|
|
|
LogInfo(" TX Frequency: %uHz", txFrequency);
|
2016-03-21 21:50:45 +00:00
|
|
|
LogInfo(" Osc. Offset: %dppm", oscOffset);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-03-21 21:50:45 +00:00
|
|
|
m_modem = new CModem(port, rxInvert, txInvert, pttInvert, txDelay, rxLevel, txLevel, dmrDelay, oscOffset, debug);
|
2016-01-14 18:45:04 +00:00
|
|
|
m_modem->setModeParams(m_dstarEnabled, m_dmrEnabled, m_ysfEnabled);
|
2016-02-18 17:37:23 +00:00
|
|
|
m_modem->setRFParams(rxFrequency, txFrequency);
|
2016-01-14 18:45:04 +00:00
|
|
|
m_modem->setDMRParams(colorCode);
|
|
|
|
|
|
|
|
bool ret = m_modem->open();
|
|
|
|
if (!ret) {
|
|
|
|
delete m_modem;
|
|
|
|
m_modem = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-25 21:00:19 +00:00
|
|
|
bool CMMDVMHost::createDStarNetwork()
|
|
|
|
{
|
|
|
|
std::string gatewayAddress = m_conf.getDStarGatewayAddress();
|
|
|
|
unsigned int gatewayPort = m_conf.getDStarGatewayPort();
|
|
|
|
unsigned int localPort = m_conf.getDStarLocalPort();
|
|
|
|
bool debug = m_conf.getDStarNetworkDebug();
|
|
|
|
|
|
|
|
LogInfo("D-Star Network Parameters");
|
|
|
|
LogInfo(" Gateway Address: %s", gatewayAddress.c_str());
|
|
|
|
LogInfo(" Gateway Port: %u", gatewayPort);
|
|
|
|
LogInfo(" Local Port: %u", localPort);
|
|
|
|
|
2016-03-08 17:26:51 +00:00
|
|
|
m_dstarNetwork = new CDStarNetwork(gatewayAddress, gatewayPort, localPort, m_duplex, VERSION, debug);
|
2016-01-25 21:00:19 +00:00
|
|
|
|
|
|
|
bool ret = m_dstarNetwork->open();
|
|
|
|
if (!ret) {
|
|
|
|
delete m_dstarNetwork;
|
|
|
|
m_dstarNetwork = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_dstarNetwork->enable(true);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
bool CMMDVMHost::createDMRNetwork()
|
|
|
|
{
|
|
|
|
std::string address = m_conf.getDMRNetworkAddress();
|
|
|
|
unsigned int port = m_conf.getDMRNetworkPort();
|
2016-04-03 18:11:45 +00:00
|
|
|
unsigned int local = m_conf.getDMRNetworkLocal();
|
2016-01-14 18:45:04 +00:00
|
|
|
unsigned int id = m_conf.getDMRId();
|
|
|
|
std::string password = m_conf.getDMRNetworkPassword();
|
|
|
|
bool debug = m_conf.getDMRNetworkDebug();
|
2016-02-15 20:36:05 +00:00
|
|
|
bool slot1 = m_conf.getDMRNetworkSlot1();
|
|
|
|
bool slot2 = m_conf.getDMRNetworkSlot2();
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
LogInfo("DMR Network Parameters");
|
|
|
|
LogInfo(" Address: %s", address.c_str());
|
|
|
|
LogInfo(" Port: %u", port);
|
2016-04-03 18:11:45 +00:00
|
|
|
if (local > 0U)
|
|
|
|
LogInfo(" Local: %u", local);
|
|
|
|
else
|
|
|
|
LogInfo(" Local: random");
|
2016-02-15 20:36:05 +00:00
|
|
|
LogInfo(" Slot 1: %s", slot1 ? "enabled" : "disabled");
|
|
|
|
LogInfo(" Slot 2: %s", slot2 ? "enabled" : "disabled");
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-04-03 18:11:45 +00:00
|
|
|
m_dmrNetwork = new CDMRIPSC(address, port, local, id, password, m_duplex, VERSION, debug, slot1, slot2);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
std::string callsign = m_conf.getCallsign();
|
|
|
|
unsigned int rxFrequency = m_conf.getRxFrequency();
|
|
|
|
unsigned int txFrequency = m_conf.getTxFrequency();
|
|
|
|
unsigned int power = m_conf.getPower();
|
|
|
|
unsigned int colorCode = m_conf.getDMRColorCode();
|
|
|
|
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("Info Parameters");
|
|
|
|
LogInfo(" Callsign: %s", callsign.c_str());
|
|
|
|
LogInfo(" RX Frequency: %uHz", rxFrequency);
|
|
|
|
LogInfo(" TX Frequency: %uHz", txFrequency);
|
|
|
|
LogInfo(" Power: %uW", power);
|
|
|
|
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(callsign, rxFrequency, txFrequency, power, colorCode, latitude, longitude, height, location, description, url);
|
|
|
|
|
|
|
|
bool ret = m_dmrNetwork->open();
|
|
|
|
if (!ret) {
|
|
|
|
delete m_dmrNetwork;
|
|
|
|
m_dmrNetwork = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-25 18:11:44 +00:00
|
|
|
m_dmrNetwork->enable(true);
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMMDVMHost::readParams()
|
|
|
|
{
|
|
|
|
m_dstarEnabled = m_conf.getDStarEnabled();
|
|
|
|
m_dmrEnabled = m_conf.getDMREnabled();
|
|
|
|
m_ysfEnabled = m_conf.getFusionEnabled();
|
2016-03-07 19:45:19 +00:00
|
|
|
m_duplex = m_conf.getDuplex();
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMMDVMHost::createDisplay()
|
|
|
|
{
|
2016-04-11 09:55:20 +00:00
|
|
|
std::string type = m_conf.getDisplay();
|
2016-04-08 11:47:05 +00:00
|
|
|
std::string callsign = m_conf.getCallsign();
|
|
|
|
unsigned int dmrid = m_conf.getDMRId();
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
LogInfo("Display Parameters");
|
|
|
|
LogInfo(" Type: %s", type.c_str());
|
|
|
|
|
|
|
|
if (type == "TFT Serial") {
|
2016-04-06 18:53:25 +00:00
|
|
|
std::string port = m_conf.getTFTSerialPort();
|
2016-02-16 18:30:12 +00:00
|
|
|
unsigned int brightness = m_conf.getTFTSerialBrightness();
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
LogInfo(" Port: %s", port.c_str());
|
2016-03-01 06:32:02 +00:00
|
|
|
LogInfo(" Brightness: %u", brightness);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-04-21 10:09:54 +00:00
|
|
|
m_display = new CTFTSerial(callsign, dmrid, port, brightness);
|
2016-04-06 18:53:25 +00:00
|
|
|
} else if (type == "Nextion") {
|
|
|
|
std::string port = m_conf.getNextionPort();
|
|
|
|
unsigned int brightness = m_conf.getNextionBrightness();
|
|
|
|
|
|
|
|
LogInfo(" Port: %s", port.c_str());
|
|
|
|
LogInfo(" Brightness: %u", brightness);
|
|
|
|
|
2016-04-20 19:23:51 +00:00
|
|
|
m_display = new CNextion(callsign, dmrid, port, brightness);
|
2016-03-15 07:53:38 +00:00
|
|
|
#if defined(HD44780)
|
2016-03-14 22:58:09 +00:00
|
|
|
} else if (type == "HD44780") {
|
|
|
|
unsigned int rows = m_conf.getHD44780Rows();
|
|
|
|
unsigned int columns = m_conf.getHD44780Columns();
|
2016-04-06 16:43:20 +00:00
|
|
|
std::vector<unsigned int> pins = m_conf.getHD44780Pins();
|
2016-03-14 22:58:09 +00:00
|
|
|
|
2016-04-06 16:43:20 +00:00
|
|
|
if (pins.size() == 6U) {
|
|
|
|
LogInfo(" Rows: %u", rows);
|
|
|
|
LogInfo(" Columns: %u", columns);
|
|
|
|
LogInfo(" Pins: %u,%u,%u,%u,%u,%u", pins.at(0U), pins.at(1U), pins.at(2U), pins.at(3U), pins.at(4U), pins.at(5U));
|
2016-03-14 22:58:09 +00:00
|
|
|
|
2016-04-21 10:03:55 +00:00
|
|
|
m_display = new CHD44780(rows, columns, callsign, dmrid, pins);
|
2016-04-06 16:43:20 +00:00
|
|
|
}
|
2016-03-14 22:58:09 +00:00
|
|
|
#endif
|
2016-01-14 18:45:04 +00:00
|
|
|
} else {
|
|
|
|
m_display = new CNullDisplay;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ret = m_display->open();
|
|
|
|
if (!ret) {
|
|
|
|
delete m_display;
|
|
|
|
m_display = new CNullDisplay;
|
|
|
|
}
|
|
|
|
}
|
2016-02-02 18:17:36 +00:00
|
|
|
|
2016-02-04 18:11:29 +00:00
|
|
|
void CMMDVMHost::setMode(unsigned char mode, bool logging)
|
2016-02-02 18:17:36 +00:00
|
|
|
{
|
|
|
|
assert(m_modem != NULL);
|
|
|
|
assert(m_display != NULL);
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case MODE_DSTAR:
|
2016-02-04 18:11:29 +00:00
|
|
|
if (logging)
|
|
|
|
LogMessage("Mode set to D-Star");
|
2016-02-02 18:17:36 +00:00
|
|
|
if (m_dmrNetwork != NULL)
|
|
|
|
m_dmrNetwork->enable(false);
|
|
|
|
m_modem->setMode(MODE_DSTAR);
|
|
|
|
m_mode = MODE_DSTAR;
|
|
|
|
m_modeTimer.start();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MODE_DMR:
|
2016-02-04 18:11:29 +00:00
|
|
|
if (logging)
|
|
|
|
LogMessage("Mode set to DMR");
|
2016-02-02 18:17:36 +00:00
|
|
|
if (m_dstarNetwork != NULL)
|
|
|
|
m_dstarNetwork->enable(false);
|
2016-03-29 16:59:15 +00:00
|
|
|
m_modem->setMode(MODE_DMR);
|
2016-03-25 20:54:51 +00:00
|
|
|
if (m_duplex)
|
|
|
|
m_modem->writeDMRStart(true);
|
2016-02-02 18:17:36 +00:00
|
|
|
m_mode = MODE_DMR;
|
|
|
|
m_modeTimer.start();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MODE_YSF:
|
2016-02-04 18:11:29 +00:00
|
|
|
if (logging)
|
|
|
|
LogMessage("Mode set to System Fusion");
|
2016-02-02 18:17:36 +00:00
|
|
|
if (m_dstarNetwork != NULL)
|
|
|
|
m_dstarNetwork->enable(false);
|
|
|
|
if (m_dmrNetwork != NULL)
|
|
|
|
m_dmrNetwork->enable(false);
|
|
|
|
m_modem->setMode(MODE_YSF);
|
|
|
|
m_mode = MODE_YSF;
|
|
|
|
m_modeTimer.start();
|
|
|
|
break;
|
|
|
|
|
2016-03-03 18:01:01 +00:00
|
|
|
case MODE_LOCKOUT:
|
|
|
|
if (logging)
|
|
|
|
LogMessage("Mode set to Lockout");
|
|
|
|
if (m_dstarNetwork != NULL)
|
|
|
|
m_dstarNetwork->enable(false);
|
|
|
|
if (m_dmrNetwork != NULL)
|
|
|
|
m_dmrNetwork->enable(false);
|
2016-03-25 20:54:51 +00:00
|
|
|
if (m_mode == MODE_DMR && m_duplex)
|
2016-03-03 18:01:01 +00:00
|
|
|
m_modem->writeDMRStart(false);
|
2016-03-29 16:59:15 +00:00
|
|
|
m_modem->setMode(MODE_IDLE);
|
2016-03-03 18:01:01 +00:00
|
|
|
m_display->setLockout();
|
|
|
|
m_mode = MODE_LOCKOUT;
|
|
|
|
m_modeTimer.stop();
|
|
|
|
break;
|
|
|
|
|
2016-03-21 22:47:58 +00:00
|
|
|
case MODE_ERROR:
|
|
|
|
if (logging)
|
|
|
|
LogMessage("Mode set to Error");
|
|
|
|
if (m_dstarNetwork != NULL)
|
|
|
|
m_dstarNetwork->enable(false);
|
|
|
|
if (m_dmrNetwork != NULL)
|
|
|
|
m_dmrNetwork->enable(false);
|
|
|
|
m_display->setError("MODEM");
|
|
|
|
m_mode = MODE_ERROR;
|
|
|
|
m_modeTimer.stop();
|
|
|
|
break;
|
|
|
|
|
2016-02-02 18:17:36 +00:00
|
|
|
default:
|
2016-02-04 18:11:29 +00:00
|
|
|
if (logging)
|
|
|
|
LogMessage("Mode set to Idle");
|
2016-02-02 18:17:36 +00:00
|
|
|
if (m_dstarNetwork != NULL)
|
|
|
|
m_dstarNetwork->enable(true);
|
|
|
|
if (m_dmrNetwork != NULL)
|
|
|
|
m_dmrNetwork->enable(true);
|
2016-03-25 20:54:51 +00:00
|
|
|
if (m_mode == MODE_DMR && m_duplex)
|
2016-02-02 18:17:36 +00:00
|
|
|
m_modem->writeDMRStart(false);
|
2016-03-29 16:59:15 +00:00
|
|
|
m_modem->setMode(MODE_IDLE);
|
2016-02-02 18:17:36 +00:00
|
|
|
m_display->setIdle();
|
|
|
|
m_mode = MODE_IDLE;
|
|
|
|
m_modeTimer.stop();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|