2016-01-14 18:45:04 +00:00
|
|
|
/*
|
2020-04-09 21:55:20 +00:00
|
|
|
* Copyright (C) 2011-2018,2020 by Jonathan Naylor G4KLX
|
2016-01-14 18:45:04 +00: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.
|
|
|
|
*/
|
|
|
|
|
2018-07-30 17:19:46 +00:00
|
|
|
#include "I2CController.h"
|
2016-01-14 18:45:04 +00:00
|
|
|
#include "DStarDefines.h"
|
|
|
|
#include "DMRDefines.h"
|
|
|
|
#include "YSFDefines.h"
|
2016-09-08 17:38:59 +00:00
|
|
|
#include "P25Defines.h"
|
2018-01-11 19:35:33 +00:00
|
|
|
#include "NXDNDefines.h"
|
2018-06-07 17:46:03 +00:00
|
|
|
#include "POCSAGDefines.h"
|
2016-06-06 16:40:27 +00:00
|
|
|
#include "Thread.h"
|
2016-01-14 18:45:04 +00:00
|
|
|
#include "Modem.h"
|
2018-12-07 09:36:11 +00:00
|
|
|
#include "NullModem.h"
|
2016-01-14 18:45:04 +00:00
|
|
|
#include "Utils.h"
|
|
|
|
#include "Log.h"
|
|
|
|
|
|
|
|
#include <cmath>
|
2016-03-07 20:21:55 +00:00
|
|
|
#include <cstdio>
|
2016-01-14 18:45:04 +00:00
|
|
|
#include <cassert>
|
2016-01-14 23:25:52 +00:00
|
|
|
#include <cstdint>
|
2017-02-20 21:36:35 +00:00
|
|
|
#include <ctime>
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
#if defined(_WIN32) || defined(_WIN64)
|
|
|
|
#include <Windows.h>
|
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const unsigned char MMDVM_FRAME_START = 0xE0U;
|
|
|
|
|
|
|
|
const unsigned char MMDVM_GET_VERSION = 0x00U;
|
|
|
|
const unsigned char MMDVM_GET_STATUS = 0x01U;
|
|
|
|
const unsigned char MMDVM_SET_CONFIG = 0x02U;
|
|
|
|
const unsigned char MMDVM_SET_MODE = 0x03U;
|
2016-02-18 17:37:23 +00:00
|
|
|
const unsigned char MMDVM_SET_FREQ = 0x04U;
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-05-09 20:55:44 +00:00
|
|
|
const unsigned char MMDVM_SEND_CWID = 0x0AU;
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
const unsigned char MMDVM_DSTAR_HEADER = 0x10U;
|
|
|
|
const unsigned char MMDVM_DSTAR_DATA = 0x11U;
|
|
|
|
const unsigned char MMDVM_DSTAR_LOST = 0x12U;
|
|
|
|
const unsigned char MMDVM_DSTAR_EOT = 0x13U;
|
|
|
|
|
|
|
|
const unsigned char MMDVM_DMR_DATA1 = 0x18U;
|
|
|
|
const unsigned char MMDVM_DMR_LOST1 = 0x19U;
|
|
|
|
const unsigned char MMDVM_DMR_DATA2 = 0x1AU;
|
|
|
|
const unsigned char MMDVM_DMR_LOST2 = 0x1BU;
|
|
|
|
const unsigned char MMDVM_DMR_SHORTLC = 0x1CU;
|
|
|
|
const unsigned char MMDVM_DMR_START = 0x1DU;
|
2016-06-17 06:37:49 +00:00
|
|
|
const unsigned char MMDVM_DMR_ABORT = 0x1EU;
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
const unsigned char MMDVM_YSF_DATA = 0x20U;
|
|
|
|
const unsigned char MMDVM_YSF_LOST = 0x21U;
|
|
|
|
|
2016-09-06 18:09:46 +00:00
|
|
|
const unsigned char MMDVM_P25_HDR = 0x30U;
|
|
|
|
const unsigned char MMDVM_P25_LDU = 0x31U;
|
|
|
|
const unsigned char MMDVM_P25_LOST = 0x32U;
|
|
|
|
|
2018-01-11 19:35:33 +00:00
|
|
|
const unsigned char MMDVM_NXDN_DATA = 0x40U;
|
|
|
|
const unsigned char MMDVM_NXDN_LOST = 0x41U;
|
|
|
|
|
2018-06-07 17:46:03 +00:00
|
|
|
const unsigned char MMDVM_POCSAG_DATA = 0x50U;
|
|
|
|
|
2020-06-08 15:33:20 +00:00
|
|
|
const unsigned char MMDVM_AX25_DATA = 0x55U;
|
|
|
|
|
2020-04-09 21:55:20 +00:00
|
|
|
const unsigned char MMDVM_FM_PARAMS1 = 0x60U;
|
|
|
|
const unsigned char MMDVM_FM_PARAMS2 = 0x61U;
|
|
|
|
const unsigned char MMDVM_FM_PARAMS3 = 0x62U;
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
const unsigned char MMDVM_ACK = 0x70U;
|
|
|
|
const unsigned char MMDVM_NAK = 0x7FU;
|
|
|
|
|
2016-10-06 17:38:16 +00:00
|
|
|
const unsigned char MMDVM_SERIAL = 0x80U;
|
|
|
|
|
2018-03-22 07:13:13 +00:00
|
|
|
const unsigned char MMDVM_TRANSPARENT = 0x90U;
|
2018-10-31 15:38:56 +00:00
|
|
|
const unsigned char MMDVM_QSO_INFO = 0x91U;
|
2018-03-22 07:13:13 +00:00
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
const unsigned char MMDVM_DEBUG1 = 0xF1U;
|
|
|
|
const unsigned char MMDVM_DEBUG2 = 0xF2U;
|
|
|
|
const unsigned char MMDVM_DEBUG3 = 0xF3U;
|
|
|
|
const unsigned char MMDVM_DEBUG4 = 0xF4U;
|
|
|
|
const unsigned char MMDVM_DEBUG5 = 0xF5U;
|
|
|
|
|
|
|
|
const unsigned int MAX_RESPONSES = 30U;
|
|
|
|
|
2017-02-20 21:36:35 +00:00
|
|
|
const unsigned int BUFFER_LENGTH = 2000U;
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
CModem::CModem(const std::string& port, bool duplex, bool rxInvert, bool txInvert, bool pttInvert, unsigned int txDelay, unsigned int dmrDelay, bool trace, bool debug) :
|
2016-01-14 18:45:04 +00:00
|
|
|
m_port(port),
|
2017-03-23 20:26:17 +00:00
|
|
|
m_dmrColorCode(0U),
|
|
|
|
m_ysfLoDev(false),
|
2018-05-21 20:32:33 +00:00
|
|
|
m_ysfTXHang(4U),
|
2020-05-06 16:10:23 +00:00
|
|
|
m_p25TXHang(5U),
|
|
|
|
m_nxdnTXHang(5U),
|
2016-06-22 19:42:14 +00:00
|
|
|
m_duplex(duplex),
|
2016-01-14 18:45:04 +00:00
|
|
|
m_rxInvert(rxInvert),
|
|
|
|
m_txInvert(txInvert),
|
|
|
|
m_pttInvert(pttInvert),
|
|
|
|
m_txDelay(txDelay),
|
2016-03-17 18:12:14 +00:00
|
|
|
m_dmrDelay(dmrDelay),
|
2016-08-09 06:08:37 +00:00
|
|
|
m_rxLevel(0U),
|
2016-10-10 16:46:37 +00:00
|
|
|
m_cwIdTXLevel(0U),
|
2016-08-09 06:08:37 +00:00
|
|
|
m_dstarTXLevel(0U),
|
|
|
|
m_dmrTXLevel(0U),
|
|
|
|
m_ysfTXLevel(0U),
|
2016-09-08 17:38:59 +00:00
|
|
|
m_p25TXLevel(0U),
|
2018-01-11 19:35:33 +00:00
|
|
|
m_nxdnTXLevel(0U),
|
2018-06-07 17:46:03 +00:00
|
|
|
m_pocsagTXLevel(0U),
|
2020-04-12 14:10:51 +00:00
|
|
|
m_fmTXLevel(0U),
|
2017-04-14 13:05:30 +00:00
|
|
|
m_trace(trace),
|
2016-01-14 18:45:04 +00:00
|
|
|
m_debug(debug),
|
2016-02-18 17:37:23 +00:00
|
|
|
m_rxFrequency(0U),
|
|
|
|
m_txFrequency(0U),
|
2018-06-12 18:40:49 +00:00
|
|
|
m_pocsagFrequency(0U),
|
2016-01-14 18:45:04 +00:00
|
|
|
m_dstarEnabled(false),
|
|
|
|
m_dmrEnabled(false),
|
|
|
|
m_ysfEnabled(false),
|
2016-09-08 17:38:59 +00:00
|
|
|
m_p25Enabled(false),
|
2018-01-11 19:35:33 +00:00
|
|
|
m_nxdnEnabled(false),
|
2018-06-07 17:46:03 +00:00
|
|
|
m_pocsagEnabled(false),
|
2020-04-12 14:10:51 +00:00
|
|
|
m_fmEnabled(false),
|
2020-06-08 15:33:20 +00:00
|
|
|
m_ax25Enabled(false),
|
2017-10-28 11:37:32 +00:00
|
|
|
m_rxDCOffset(0),
|
2017-08-20 11:07:57 +00:00
|
|
|
m_txDCOffset(0),
|
2018-07-30 17:19:46 +00:00
|
|
|
m_serial(NULL),
|
2016-01-14 18:45:04 +00:00
|
|
|
m_buffer(NULL),
|
2016-03-21 18:16:58 +00:00
|
|
|
m_length(0U),
|
|
|
|
m_offset(0U),
|
2020-06-19 14:09:21 +00:00
|
|
|
m_state(SS_START),
|
|
|
|
m_type(0U),
|
2016-02-15 20:18:30 +00:00
|
|
|
m_rxDStarData(1000U, "Modem RX D-Star"),
|
|
|
|
m_txDStarData(1000U, "Modem TX D-Star"),
|
|
|
|
m_rxDMRData1(1000U, "Modem RX DMR1"),
|
|
|
|
m_rxDMRData2(1000U, "Modem RX DMR2"),
|
|
|
|
m_txDMRData1(1000U, "Modem TX DMR1"),
|
|
|
|
m_txDMRData2(1000U, "Modem TX DMR2"),
|
|
|
|
m_rxYSFData(1000U, "Modem RX YSF"),
|
|
|
|
m_txYSFData(1000U, "Modem TX YSF"),
|
2016-09-08 17:38:59 +00:00
|
|
|
m_rxP25Data(1000U, "Modem RX P25"),
|
|
|
|
m_txP25Data(1000U, "Modem TX P25"),
|
2018-01-11 19:35:33 +00:00
|
|
|
m_rxNXDNData(1000U, "Modem RX NXDN"),
|
|
|
|
m_txNXDNData(1000U, "Modem TX NXDN"),
|
2018-06-07 17:46:03 +00:00
|
|
|
m_txPOCSAGData(1000U, "Modem TX POCSAG"),
|
2020-06-08 15:33:20 +00:00
|
|
|
m_rxAX25Data(1000U, "Modem RX AX.25"),
|
2018-03-22 07:13:13 +00:00
|
|
|
m_rxTransparentData(1000U, "Modem RX Transparent"),
|
|
|
|
m_txTransparentData(1000U, "Modem TX Transparent"),
|
2018-09-13 18:35:12 +00:00
|
|
|
m_sendTransparentDataFrameType(0U),
|
2016-03-29 16:56:30 +00:00
|
|
|
m_statusTimer(1000U, 0U, 250U),
|
2016-04-13 06:51:43 +00:00
|
|
|
m_inactivityTimer(1000U, 2U),
|
2016-03-31 10:42:12 +00:00
|
|
|
m_playoutTimer(1000U, 0U, 10U),
|
2016-01-14 18:45:04 +00:00
|
|
|
m_dstarSpace(0U),
|
|
|
|
m_dmrSpace1(0U),
|
|
|
|
m_dmrSpace2(0U),
|
|
|
|
m_ysfSpace(0U),
|
2016-09-08 17:38:59 +00:00
|
|
|
m_p25Space(0U),
|
2018-01-11 19:35:33 +00:00
|
|
|
m_nxdnSpace(0U),
|
2018-06-07 17:46:03 +00:00
|
|
|
m_pocsagSpace(0U),
|
2016-03-03 18:01:01 +00:00
|
|
|
m_tx(false),
|
2016-11-17 10:48:42 +00:00
|
|
|
m_cd(false),
|
2016-03-21 22:47:58 +00:00
|
|
|
m_lockout(false),
|
2016-09-05 16:40:43 +00:00
|
|
|
m_error(false),
|
2020-04-11 19:42:05 +00:00
|
|
|
m_mode(MODE_IDLE),
|
2020-04-18 13:59:19 +00:00
|
|
|
m_hwType(HWT_UNKNOWN),
|
|
|
|
m_fmCallsign(),
|
|
|
|
m_fmCallsignSpeed(20U),
|
|
|
|
m_fmCallsignFrequency(1000U),
|
|
|
|
m_fmCallsignTime(600U),
|
|
|
|
m_fmCallsignHoldoff(0U),
|
2020-04-22 20:51:43 +00:00
|
|
|
m_fmCallsignHighLevel(35.0F),
|
|
|
|
m_fmCallsignLowLevel(15.0F),
|
2020-04-18 13:59:19 +00:00
|
|
|
m_fmCallsignAtStart(true),
|
|
|
|
m_fmCallsignAtEnd(true),
|
2020-05-04 21:30:16 +00:00
|
|
|
m_fmCallsignAtLatch(true),
|
2020-04-18 13:59:19 +00:00
|
|
|
m_fmRfAck("K"),
|
|
|
|
m_fmAckSpeed(20U),
|
|
|
|
m_fmAckFrequency(1750U),
|
|
|
|
m_fmAckMinTime(4U),
|
|
|
|
m_fmAckDelay(1000U),
|
|
|
|
m_fmAckLevel(80.0F),
|
|
|
|
m_fmTimeout(120U),
|
|
|
|
m_fmTimeoutLevel(80.0F),
|
|
|
|
m_fmCtcssFrequency(88.4F),
|
2020-05-12 12:43:43 +00:00
|
|
|
m_fmCtcssHighThreshold(30U),
|
|
|
|
m_fmCtcssLowThreshold(20U),
|
2020-04-18 13:59:19 +00:00
|
|
|
m_fmCtcssLevel(10.0F),
|
|
|
|
m_fmKerchunkTime(0U),
|
2020-04-25 14:15:56 +00:00
|
|
|
m_fmHangTime(5U),
|
|
|
|
m_fmUseCOS(true),
|
2020-05-06 10:26:54 +00:00
|
|
|
m_fmCOSInvert(false),
|
2020-04-28 13:39:14 +00:00
|
|
|
m_fmRFAudioBoost(1U),
|
2020-04-25 21:43:14 +00:00
|
|
|
m_fmMaxDevLevel(90.0F)
|
2016-01-14 18:45:04 +00:00
|
|
|
{
|
|
|
|
m_buffer = new unsigned char[BUFFER_LENGTH];
|
2020-04-11 19:42:05 +00:00
|
|
|
|
|
|
|
assert(!port.empty());
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CModem::~CModem()
|
|
|
|
{
|
2018-07-30 17:19:46 +00:00
|
|
|
delete m_serial;
|
2016-01-14 18:45:04 +00:00
|
|
|
delete[] m_buffer;
|
|
|
|
}
|
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
void CModem::setSerialParams(const std::string& protocol, unsigned int address)
|
|
|
|
{
|
2018-07-30 17:19:46 +00:00
|
|
|
// Create the serial controller instance according the protocol specified in conf.
|
|
|
|
if (protocol == "i2c")
|
|
|
|
m_serial = new CI2CController(m_port, SERIAL_115200, address, true);
|
2018-07-30 13:58:35 +00:00
|
|
|
else
|
|
|
|
m_serial = new CSerialController(m_port, SERIAL_115200, true);
|
|
|
|
}
|
|
|
|
|
2018-06-12 18:40:49 +00:00
|
|
|
void CModem::setRFParams(unsigned int rxFrequency, int rxOffset, unsigned int txFrequency, int txOffset, int txDCOffset, int rxDCOffset, float rfLevel, unsigned int pocsagFrequency)
|
2016-02-18 17:37:23 +00:00
|
|
|
{
|
2018-06-12 18:40:49 +00:00
|
|
|
m_rxFrequency = rxFrequency + rxOffset;
|
|
|
|
m_txFrequency = txFrequency + txOffset;
|
|
|
|
m_txDCOffset = txDCOffset;
|
|
|
|
m_rxDCOffset = rxDCOffset;
|
|
|
|
m_rfLevel = rfLevel;
|
|
|
|
m_pocsagFrequency = pocsagFrequency + txOffset;
|
2016-02-18 17:37:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-08 15:33:20 +00:00
|
|
|
void CModem::setModeParams(bool dstarEnabled, bool dmrEnabled, bool ysfEnabled, bool p25Enabled, bool nxdnEnabled, bool pocsagEnabled, bool fmEnabled, bool ax25Enabled)
|
2016-01-14 18:45:04 +00:00
|
|
|
{
|
2018-06-07 17:46:03 +00:00
|
|
|
m_dstarEnabled = dstarEnabled;
|
|
|
|
m_dmrEnabled = dmrEnabled;
|
|
|
|
m_ysfEnabled = ysfEnabled;
|
|
|
|
m_p25Enabled = p25Enabled;
|
|
|
|
m_nxdnEnabled = nxdnEnabled;
|
|
|
|
m_pocsagEnabled = pocsagEnabled;
|
2020-04-12 14:10:51 +00:00
|
|
|
m_fmEnabled = fmEnabled;
|
2020-06-08 15:33:20 +00:00
|
|
|
m_ax25Enabled = ax25Enabled;
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 11:59:33 +00:00
|
|
|
void CModem::setLevels(float rxLevel, float cwIdTXLevel, float dstarTXLevel, float dmrTXLevel, float ysfTXLevel, float p25TXLevel, float nxdnTXLevel, float pocsagTXLevel, float fmTXLevel)
|
2016-08-09 06:08:37 +00:00
|
|
|
{
|
2018-06-07 17:46:03 +00:00
|
|
|
m_rxLevel = rxLevel;
|
|
|
|
m_cwIdTXLevel = cwIdTXLevel;
|
|
|
|
m_dstarTXLevel = dstarTXLevel;
|
|
|
|
m_dmrTXLevel = dmrTXLevel;
|
|
|
|
m_ysfTXLevel = ysfTXLevel;
|
|
|
|
m_p25TXLevel = p25TXLevel;
|
|
|
|
m_nxdnTXLevel = nxdnTXLevel;
|
|
|
|
m_pocsagTXLevel = pocsagTXLevel;
|
2020-04-12 14:10:51 +00:00
|
|
|
m_fmTXLevel = fmTXLevel;
|
2016-08-09 06:08:37 +00:00
|
|
|
}
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
void CModem::setDMRParams(unsigned int colorCode)
|
|
|
|
{
|
|
|
|
assert(colorCode < 16U);
|
|
|
|
|
2017-03-23 20:26:17 +00:00
|
|
|
m_dmrColorCode = colorCode;
|
|
|
|
}
|
|
|
|
|
2018-05-21 20:32:33 +00:00
|
|
|
void CModem::setYSFParams(bool loDev, unsigned int txHang)
|
2017-03-23 20:26:17 +00:00
|
|
|
{
|
2018-05-21 20:32:33 +00:00
|
|
|
m_ysfLoDev = loDev;
|
|
|
|
m_ysfTXHang = txHang;
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
2020-05-06 16:10:23 +00:00
|
|
|
void CModem::setP25Params(unsigned int txHang)
|
|
|
|
{
|
|
|
|
m_p25TXHang = txHang;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModem::setNXDNParams(unsigned int txHang)
|
|
|
|
{
|
|
|
|
m_nxdnTXHang = txHang;
|
|
|
|
}
|
|
|
|
|
2018-09-13 18:35:12 +00:00
|
|
|
void CModem::setTransparentDataParams(unsigned int sendFrameType)
|
|
|
|
{
|
|
|
|
m_sendTransparentDataFrameType = sendFrameType;
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
bool CModem::open()
|
|
|
|
{
|
|
|
|
::LogMessage("Opening the MMDVM");
|
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
bool ret = m_serial->open();
|
2018-08-20 03:12:38 +00:00
|
|
|
if (!ret)
|
2016-01-14 18:45:04 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
ret = readVersion();
|
|
|
|
if (!ret) {
|
2018-07-30 13:58:35 +00:00
|
|
|
m_serial->close();
|
2018-07-30 17:19:46 +00:00
|
|
|
delete m_serial;
|
|
|
|
m_serial = NULL;
|
2016-01-14 18:45:04 +00:00
|
|
|
return false;
|
2016-05-14 10:39:56 +00:00
|
|
|
} else {
|
|
|
|
/* Stopping the inactivity timer here when a firmware version has been
|
|
|
|
successfuly read prevents the death spiral of "no reply from modem..." */
|
|
|
|
m_inactivityTimer.stop();
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
2016-02-18 19:29:28 +00:00
|
|
|
ret = setFrequency();
|
2016-01-14 18:45:04 +00:00
|
|
|
if (!ret) {
|
2018-07-30 13:58:35 +00:00
|
|
|
m_serial->close();
|
2018-07-30 17:19:46 +00:00
|
|
|
delete m_serial;
|
|
|
|
m_serial = NULL;
|
2016-01-14 18:45:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-18 19:29:28 +00:00
|
|
|
ret = setConfig();
|
2016-02-18 17:37:23 +00:00
|
|
|
if (!ret) {
|
2018-07-30 13:58:35 +00:00
|
|
|
m_serial->close();
|
2018-07-30 17:19:46 +00:00
|
|
|
delete m_serial;
|
|
|
|
m_serial = NULL;
|
2016-02-18 17:37:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-19 15:11:55 +00:00
|
|
|
if (m_fmEnabled && m_duplex) {
|
2020-04-18 13:59:19 +00:00
|
|
|
ret = setFMCallsignParams();
|
|
|
|
if (!ret) {
|
|
|
|
m_serial->close();
|
|
|
|
delete m_serial;
|
|
|
|
m_serial = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = setFMAckParams();
|
|
|
|
if (!ret) {
|
|
|
|
m_serial->close();
|
|
|
|
delete m_serial;
|
|
|
|
m_serial = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = setFMMiscParams();
|
|
|
|
if (!ret) {
|
|
|
|
m_serial->close();
|
|
|
|
delete m_serial;
|
|
|
|
m_serial = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
m_statusTimer.start();
|
|
|
|
|
2016-03-21 22:47:58 +00:00
|
|
|
m_error = false;
|
2016-03-21 18:16:58 +00:00
|
|
|
m_offset = 0U;
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CModem::clock(unsigned int ms)
|
|
|
|
{
|
2018-07-30 17:19:46 +00:00
|
|
|
assert(m_serial != NULL);
|
|
|
|
|
2016-03-29 16:56:30 +00:00
|
|
|
// Poll the modem status every 250ms
|
2016-01-14 18:45:04 +00:00
|
|
|
m_statusTimer.clock(ms);
|
|
|
|
if (m_statusTimer.hasExpired()) {
|
|
|
|
readStatus();
|
|
|
|
m_statusTimer.start();
|
|
|
|
}
|
|
|
|
|
2016-02-16 17:31:28 +00:00
|
|
|
m_inactivityTimer.clock(ms);
|
|
|
|
if (m_inactivityTimer.hasExpired()) {
|
|
|
|
LogError("No reply from the modem for some time, resetting it");
|
2016-03-21 22:47:58 +00:00
|
|
|
m_error = true;
|
2016-02-16 17:31:28 +00:00
|
|
|
close();
|
2016-06-09 18:51:23 +00:00
|
|
|
|
|
|
|
CThread::sleep(2000U); // 2s
|
|
|
|
while (!open())
|
|
|
|
CThread::sleep(5000U); // 5s
|
2016-02-16 17:31:28 +00:00
|
|
|
}
|
|
|
|
|
2016-03-21 18:16:58 +00:00
|
|
|
RESP_TYPE_MMDVM type = getResponse();
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
if (type == RTM_TIMEOUT) {
|
|
|
|
// Nothing to do
|
|
|
|
} else if (type == RTM_ERROR) {
|
2016-03-16 07:56:27 +00:00
|
|
|
// Nothing to do
|
2016-01-14 18:45:04 +00:00
|
|
|
} else {
|
|
|
|
// type == RTM_OK
|
2020-06-19 14:09:21 +00:00
|
|
|
switch (m_type) {
|
2016-01-14 18:45:04 +00:00
|
|
|
case MMDVM_DSTAR_HEADER: {
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-03-21 18:16:58 +00:00
|
|
|
CUtils::dump(1U, "RX D-Star Header", m_buffer, m_length);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-03-21 18:16:58 +00:00
|
|
|
unsigned char data = m_length - 2U;
|
2016-01-14 18:45:04 +00:00
|
|
|
m_rxDStarData.addData(&data, 1U);
|
|
|
|
|
|
|
|
data = TAG_HEADER;
|
|
|
|
m_rxDStarData.addData(&data, 1U);
|
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_rxDStarData.addData(m_buffer + m_offset, m_length - m_offset);
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMDVM_DSTAR_DATA: {
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-03-21 18:16:58 +00:00
|
|
|
CUtils::dump(1U, "RX D-Star Data", m_buffer, m_length);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-03-21 18:16:58 +00:00
|
|
|
unsigned char data = m_length - 2U;
|
2016-01-14 18:45:04 +00:00
|
|
|
m_rxDStarData.addData(&data, 1U);
|
|
|
|
|
|
|
|
data = TAG_DATA;
|
|
|
|
m_rxDStarData.addData(&data, 1U);
|
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_rxDStarData.addData(m_buffer + m_offset, m_length - m_offset);
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMDVM_DSTAR_LOST: {
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-03-21 18:16:58 +00:00
|
|
|
CUtils::dump(1U, "RX D-Star Lost", m_buffer, m_length);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
unsigned char data = 1U;
|
|
|
|
m_rxDStarData.addData(&data, 1U);
|
|
|
|
|
|
|
|
data = TAG_LOST;
|
|
|
|
m_rxDStarData.addData(&data, 1U);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMDVM_DSTAR_EOT: {
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-03-21 18:16:58 +00:00
|
|
|
CUtils::dump(1U, "RX D-Star EOT", m_buffer, m_length);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
unsigned char data = 1U;
|
|
|
|
m_rxDStarData.addData(&data, 1U);
|
|
|
|
|
|
|
|
data = TAG_EOT;
|
|
|
|
m_rxDStarData.addData(&data, 1U);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMDVM_DMR_DATA1: {
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-03-21 18:16:58 +00:00
|
|
|
CUtils::dump(1U, "RX DMR Data 1", m_buffer, m_length);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-03-21 18:16:58 +00:00
|
|
|
unsigned char data = m_length - 2U;
|
2016-01-14 18:45:04 +00:00
|
|
|
m_rxDMRData1.addData(&data, 1U);
|
|
|
|
|
|
|
|
if (m_buffer[3U] == (DMR_SYNC_DATA | DT_TERMINATOR_WITH_LC))
|
|
|
|
data = TAG_EOT;
|
|
|
|
else
|
|
|
|
data = TAG_DATA;
|
|
|
|
m_rxDMRData1.addData(&data, 1U);
|
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_rxDMRData1.addData(m_buffer + m_offset, m_length - m_offset);
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMDVM_DMR_DATA2: {
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-03-21 18:16:58 +00:00
|
|
|
CUtils::dump(1U, "RX DMR Data 2", m_buffer, m_length);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-03-21 18:16:58 +00:00
|
|
|
unsigned char data = m_length - 2U;
|
2016-01-14 18:45:04 +00:00
|
|
|
m_rxDMRData2.addData(&data, 1U);
|
|
|
|
|
|
|
|
if (m_buffer[3U] == (DMR_SYNC_DATA | DT_TERMINATOR_WITH_LC))
|
|
|
|
data = TAG_EOT;
|
|
|
|
else
|
|
|
|
data = TAG_DATA;
|
|
|
|
m_rxDMRData2.addData(&data, 1U);
|
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_rxDMRData2.addData(m_buffer + m_offset, m_length - m_offset);
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMDVM_DMR_LOST1: {
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-03-21 18:16:58 +00:00
|
|
|
CUtils::dump(1U, "RX DMR Lost 1", m_buffer, m_length);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
unsigned char data = 1U;
|
|
|
|
m_rxDMRData1.addData(&data, 1U);
|
|
|
|
|
|
|
|
data = TAG_LOST;
|
|
|
|
m_rxDMRData1.addData(&data, 1U);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMDVM_DMR_LOST2: {
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-03-21 18:16:58 +00:00
|
|
|
CUtils::dump(1U, "RX DMR Lost 2", m_buffer, m_length);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
unsigned char data = 1U;
|
|
|
|
m_rxDMRData2.addData(&data, 1U);
|
|
|
|
|
|
|
|
data = TAG_LOST;
|
|
|
|
m_rxDMRData2.addData(&data, 1U);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMDVM_YSF_DATA: {
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-03-21 18:16:58 +00:00
|
|
|
CUtils::dump(1U, "RX YSF Data", m_buffer, m_length);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-03-21 18:16:58 +00:00
|
|
|
unsigned char data = m_length - 2U;
|
2016-01-14 18:45:04 +00:00
|
|
|
m_rxYSFData.addData(&data, 1U);
|
|
|
|
|
2016-04-12 20:33:16 +00:00
|
|
|
data = TAG_DATA;
|
2016-01-14 18:45:04 +00:00
|
|
|
m_rxYSFData.addData(&data, 1U);
|
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_rxYSFData.addData(m_buffer + m_offset, m_length - m_offset);
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMDVM_YSF_LOST: {
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-03-21 18:16:58 +00:00
|
|
|
CUtils::dump(1U, "RX YSF Lost", m_buffer, m_length);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
unsigned char data = 1U;
|
|
|
|
m_rxYSFData.addData(&data, 1U);
|
|
|
|
|
|
|
|
data = TAG_LOST;
|
|
|
|
m_rxYSFData.addData(&data, 1U);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-09-08 17:38:59 +00:00
|
|
|
case MMDVM_P25_HDR: {
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-09-08 17:38:59 +00:00
|
|
|
CUtils::dump(1U, "RX P25 Header", m_buffer, m_length);
|
2016-09-06 18:09:46 +00:00
|
|
|
|
2016-09-08 17:38:59 +00:00
|
|
|
unsigned char data = m_length - 2U;
|
|
|
|
m_rxP25Data.addData(&data, 1U);
|
2016-09-06 18:09:46 +00:00
|
|
|
|
2016-09-08 17:38:59 +00:00
|
|
|
data = TAG_HEADER;
|
|
|
|
m_rxP25Data.addData(&data, 1U);
|
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_rxP25Data.addData(m_buffer + m_offset, m_length - m_offset);
|
2016-09-08 17:38:59 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMDVM_P25_LDU: {
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-09-08 17:38:59 +00:00
|
|
|
CUtils::dump(1U, "RX P25 LDU", m_buffer, m_length);
|
|
|
|
|
|
|
|
unsigned char data = m_length - 2U;
|
|
|
|
m_rxP25Data.addData(&data, 1U);
|
|
|
|
|
|
|
|
data = TAG_DATA;
|
|
|
|
m_rxP25Data.addData(&data, 1U);
|
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_rxP25Data.addData(m_buffer + m_offset, m_length - m_offset);
|
2016-09-08 17:38:59 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMDVM_P25_LOST: {
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-09-08 17:38:59 +00:00
|
|
|
CUtils::dump(1U, "RX P25 Lost", m_buffer, m_length);
|
|
|
|
|
|
|
|
unsigned char data = 1U;
|
|
|
|
m_rxP25Data.addData(&data, 1U);
|
|
|
|
|
|
|
|
data = TAG_LOST;
|
|
|
|
m_rxP25Data.addData(&data, 1U);
|
|
|
|
}
|
|
|
|
break;
|
2016-09-06 18:09:46 +00:00
|
|
|
|
2018-01-11 19:35:33 +00:00
|
|
|
case MMDVM_NXDN_DATA: {
|
|
|
|
if (m_trace)
|
|
|
|
CUtils::dump(1U, "RX NXDN Data", m_buffer, m_length);
|
|
|
|
|
|
|
|
unsigned char data = m_length - 2U;
|
|
|
|
m_rxNXDNData.addData(&data, 1U);
|
|
|
|
|
|
|
|
data = TAG_DATA;
|
|
|
|
m_rxNXDNData.addData(&data, 1U);
|
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_rxNXDNData.addData(m_buffer + m_offset, m_length - m_offset);
|
2018-01-11 19:35:33 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMDVM_NXDN_LOST: {
|
|
|
|
if (m_trace)
|
|
|
|
CUtils::dump(1U, "RX NXDN Lost", m_buffer, m_length);
|
|
|
|
|
|
|
|
unsigned char data = 1U;
|
|
|
|
m_rxNXDNData.addData(&data, 1U);
|
|
|
|
|
|
|
|
data = TAG_LOST;
|
|
|
|
m_rxNXDNData.addData(&data, 1U);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-06-08 15:33:20 +00:00
|
|
|
case MMDVM_AX25_DATA: {
|
|
|
|
if (m_trace)
|
|
|
|
CUtils::dump(1U, "RX AX.25 Data", m_buffer, m_length);
|
|
|
|
|
2020-06-09 13:32:05 +00:00
|
|
|
unsigned char data = m_length - 3U;
|
2020-06-08 15:33:20 +00:00
|
|
|
m_rxAX25Data.addData(&data, 1U);
|
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_rxAX25Data.addData(m_buffer + m_offset, m_length - m_offset);
|
2020-06-08 15:33:20 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
case MMDVM_GET_STATUS: {
|
2017-04-14 13:05:30 +00:00
|
|
|
// if (m_trace)
|
2016-03-21 18:16:58 +00:00
|
|
|
// CUtils::dump(1U, "GET_STATUS", m_buffer, m_length);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2018-07-06 05:48:50 +00:00
|
|
|
m_p25Space = 0U;
|
|
|
|
m_nxdnSpace = 0U;
|
|
|
|
m_pocsagSpace = 0U;
|
2018-06-26 17:28:50 +00:00
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_mode = m_buffer[m_offset + 1U];
|
2020-04-11 19:42:05 +00:00
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_tx = (m_buffer[m_offset + 2U] & 0x01U) == 0x01U;
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
bool adcOverflow = (m_buffer[m_offset + 2U] & 0x02U) == 0x02U;
|
2016-01-14 18:45:04 +00:00
|
|
|
if (adcOverflow)
|
2016-01-18 19:37:08 +00:00
|
|
|
LogError("MMDVM ADC levels have overflowed");
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
bool rxOverflow = (m_buffer[m_offset + 2U] & 0x04U) == 0x04U;
|
2016-01-14 19:26:06 +00:00
|
|
|
if (rxOverflow)
|
2016-01-18 19:37:08 +00:00
|
|
|
LogError("MMDVM RX buffer has overflowed");
|
2016-01-14 19:26:06 +00:00
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
bool txOverflow = (m_buffer[m_offset + 2U] & 0x08U) == 0x08U;
|
2016-01-14 19:26:06 +00:00
|
|
|
if (txOverflow)
|
2016-01-18 19:37:08 +00:00
|
|
|
LogError("MMDVM TX buffer has overflowed");
|
2016-01-14 19:26:06 +00:00
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_lockout = (m_buffer[m_offset + 2U] & 0x10U) == 0x10U;
|
2016-03-03 18:01:01 +00:00
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
bool dacOverflow = (m_buffer[m_offset + 2U] & 0x20U) == 0x20U;
|
2016-06-09 18:51:23 +00:00
|
|
|
if (dacOverflow)
|
|
|
|
LogError("MMDVM DAC levels have overflowed");
|
2018-07-19 13:09:00 +00:00
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_cd = (m_buffer[m_offset + 2U] & 0x40U) == 0x40U;
|
2016-06-09 18:51:23 +00:00
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_dstarSpace = m_buffer[m_offset + 3U];
|
|
|
|
m_dmrSpace1 = m_buffer[m_offset + 4U];
|
|
|
|
m_dmrSpace2 = m_buffer[m_offset + 5U];
|
|
|
|
m_ysfSpace = m_buffer[m_offset + 6U];
|
2018-07-06 05:48:50 +00:00
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
if (m_length > (m_offset + 7U))
|
|
|
|
m_p25Space = m_buffer[m_offset + 7U];
|
|
|
|
if (m_length > (m_offset + 8U))
|
|
|
|
m_nxdnSpace = m_buffer[m_offset + 8U];
|
|
|
|
if (m_length > (m_offset + 9U))
|
|
|
|
m_pocsagSpace = m_buffer[m_offset + 9U];
|
2016-02-16 17:31:28 +00:00
|
|
|
|
|
|
|
m_inactivityTimer.start();
|
2020-06-19 14:09:21 +00:00
|
|
|
// LogMessage("status=%02X, tx=%d, space=%u,%u,%u,%u,%u,%u,%u lockout=%d, cd=%d", m_buffer[m_offset + 2U], int(m_tx), m_dstarSpace, m_dmrSpace1, m_dmrSpace2, m_ysfSpace, m_p25Space, m_nxdnSpace, m_pocsagSpace, int(m_lockout), int(m_cd));
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-03-22 07:13:13 +00:00
|
|
|
case MMDVM_TRANSPARENT: {
|
|
|
|
if (m_trace)
|
|
|
|
CUtils::dump(1U, "RX Transparent Data", m_buffer, m_length);
|
|
|
|
|
2018-09-13 18:35:12 +00:00
|
|
|
unsigned char offset = m_sendTransparentDataFrameType;
|
2018-10-31 15:38:56 +00:00
|
|
|
if (offset > 1U) offset = 1U;
|
2020-06-19 14:09:21 +00:00
|
|
|
unsigned char data = m_length - m_offset + offset;
|
2018-03-22 07:13:13 +00:00
|
|
|
m_rxTransparentData.addData(&data, 1U);
|
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_rxTransparentData.addData(m_buffer + m_offset - offset, m_length - m_offset + offset);
|
2018-03-22 07:13:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
// These should not be received, but don't complain if we do
|
|
|
|
case MMDVM_GET_VERSION:
|
|
|
|
case MMDVM_ACK:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MMDVM_NAK:
|
2020-06-19 14:09:21 +00:00
|
|
|
LogWarning("Received a NAK from the MMDVM, command = 0x%02X, reason = %u", m_buffer[m_offset], m_buffer[m_offset + 1U]);
|
2016-01-14 18:45:04 +00:00
|
|
|
break;
|
|
|
|
|
2017-02-13 08:53:33 +00:00
|
|
|
case MMDVM_DEBUG1:
|
|
|
|
case MMDVM_DEBUG2:
|
|
|
|
case MMDVM_DEBUG3:
|
|
|
|
case MMDVM_DEBUG4:
|
|
|
|
case MMDVM_DEBUG5:
|
|
|
|
printDebug();
|
|
|
|
break;
|
|
|
|
|
2018-09-13 18:35:12 +00:00
|
|
|
case MMDVM_SERIAL:
|
|
|
|
//MMDVMHost does not process serial data from the display,
|
|
|
|
// so we send it to the transparent port if sendFrameType==1
|
2018-10-31 15:38:56 +00:00
|
|
|
if (m_sendTransparentDataFrameType > 0U) {
|
2018-09-13 18:35:12 +00:00
|
|
|
if (m_trace)
|
|
|
|
CUtils::dump(1U, "RX Serial Data", m_buffer, m_length);
|
|
|
|
|
|
|
|
unsigned char offset = m_sendTransparentDataFrameType;
|
2018-10-31 15:38:56 +00:00
|
|
|
if (offset > 1U) offset = 1U;
|
2020-06-19 14:09:21 +00:00
|
|
|
unsigned char data = m_length - m_offset + offset;
|
2018-09-13 18:35:12 +00:00
|
|
|
m_rxTransparentData.addData(&data, 1U);
|
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_rxTransparentData.addData(m_buffer + m_offset - offset, m_length - m_offset + offset);
|
2018-09-13 18:35:12 +00:00
|
|
|
break; //only break when sendFrameType>0, else message is unknown
|
|
|
|
}
|
2017-02-13 11:49:25 +00:00
|
|
|
default:
|
2020-06-19 14:09:21 +00:00
|
|
|
LogMessage("Unknown message, type: %02X", m_type);
|
2016-03-21 18:16:58 +00:00
|
|
|
CUtils::dump("Buffer dump", m_buffer, m_length);
|
2016-01-14 18:45:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-31 10:42:12 +00:00
|
|
|
// Only feed data to the modem if the playout timer has expired
|
|
|
|
m_playoutTimer.clock(ms);
|
|
|
|
if (!m_playoutTimer.hasExpired())
|
|
|
|
return;
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
if (m_dstarSpace > 1U && !m_txDStarData.isEmpty()) {
|
2016-02-01 21:44:40 +00:00
|
|
|
unsigned char buffer[4U];
|
|
|
|
m_txDStarData.peek(buffer, 4U);
|
2016-01-18 19:37:08 +00:00
|
|
|
|
2016-02-01 21:44:40 +00:00
|
|
|
if ((buffer[3U] == MMDVM_DSTAR_HEADER && m_dstarSpace > 4U) ||
|
|
|
|
(buffer[3U] == MMDVM_DSTAR_DATA && m_dstarSpace > 1U) ||
|
|
|
|
(buffer[3U] == MMDVM_DSTAR_EOT && m_dstarSpace > 1U)) {
|
2016-01-18 19:37:08 +00:00
|
|
|
unsigned char len = 0U;
|
|
|
|
m_txDStarData.getData(&len, 1U);
|
|
|
|
m_txDStarData.getData(m_buffer, len);
|
|
|
|
|
2016-07-20 06:27:38 +00:00
|
|
|
switch (buffer[3U]) {
|
|
|
|
case MMDVM_DSTAR_HEADER:
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-01-18 19:37:08 +00:00
|
|
|
CUtils::dump(1U, "TX D-Star Header", m_buffer, len);
|
2016-07-20 06:27:38 +00:00
|
|
|
m_dstarSpace -= 4U;
|
|
|
|
break;
|
|
|
|
case MMDVM_DSTAR_DATA:
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-01-18 19:37:08 +00:00
|
|
|
CUtils::dump(1U, "TX D-Star Data", m_buffer, len);
|
2016-07-20 06:27:38 +00:00
|
|
|
m_dstarSpace -= 1U;
|
|
|
|
break;
|
|
|
|
default:
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-01-18 19:37:08 +00:00
|
|
|
CUtils::dump(1U, "TX D-Star EOT", m_buffer, len);
|
2016-07-20 06:27:38 +00:00
|
|
|
m_dstarSpace -= 1U;
|
|
|
|
break;
|
2016-01-18 19:37:08 +00:00
|
|
|
}
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
int ret = m_serial->write(m_buffer, len);
|
2016-01-18 19:37:08 +00:00
|
|
|
if (ret != int(len))
|
|
|
|
LogWarning("Error when writing D-Star data to the MMDVM");
|
2016-03-31 10:42:12 +00:00
|
|
|
|
|
|
|
m_playoutTimer.start();
|
2016-01-18 19:37:08 +00:00
|
|
|
}
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_dmrSpace1 > 1U && !m_txDMRData1.isEmpty()) {
|
|
|
|
unsigned char len = 0U;
|
|
|
|
m_txDMRData1.getData(&len, 1U);
|
|
|
|
m_txDMRData1.getData(m_buffer, len);
|
|
|
|
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-01-14 18:45:04 +00:00
|
|
|
CUtils::dump(1U, "TX DMR Data 1", m_buffer, len);
|
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
int ret = m_serial->write(m_buffer, len);
|
2016-01-14 18:45:04 +00:00
|
|
|
if (ret != int(len))
|
|
|
|
LogWarning("Error when writing DMR data to the MMDVM");
|
|
|
|
|
2016-03-31 10:42:12 +00:00
|
|
|
m_playoutTimer.start();
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
m_dmrSpace1--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_dmrSpace2 > 1U && !m_txDMRData2.isEmpty()) {
|
|
|
|
unsigned char len = 0U;
|
|
|
|
m_txDMRData2.getData(&len, 1U);
|
|
|
|
m_txDMRData2.getData(m_buffer, len);
|
|
|
|
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-01-14 18:45:04 +00:00
|
|
|
CUtils::dump(1U, "TX DMR Data 2", m_buffer, len);
|
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
int ret = m_serial->write(m_buffer, len);
|
2016-01-14 18:45:04 +00:00
|
|
|
if (ret != int(len))
|
|
|
|
LogWarning("Error when writing DMR data to the MMDVM");
|
|
|
|
|
2016-03-31 10:42:12 +00:00
|
|
|
m_playoutTimer.start();
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
m_dmrSpace2--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_ysfSpace > 1U && !m_txYSFData.isEmpty()) {
|
|
|
|
unsigned char len = 0U;
|
|
|
|
m_txYSFData.getData(&len, 1U);
|
|
|
|
m_txYSFData.getData(m_buffer, len);
|
|
|
|
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace)
|
2016-01-14 18:45:04 +00:00
|
|
|
CUtils::dump(1U, "TX YSF Data", m_buffer, len);
|
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
int ret = m_serial->write(m_buffer, len);
|
2016-01-14 18:45:04 +00:00
|
|
|
if (ret != int(len))
|
|
|
|
LogWarning("Error when writing YSF data to the MMDVM");
|
|
|
|
|
2016-03-31 10:42:12 +00:00
|
|
|
m_playoutTimer.start();
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
m_ysfSpace--;
|
|
|
|
}
|
2016-09-08 17:38:59 +00:00
|
|
|
|
|
|
|
if (m_p25Space > 1U && !m_txP25Data.isEmpty()) {
|
|
|
|
unsigned char len = 0U;
|
|
|
|
m_txP25Data.getData(&len, 1U);
|
|
|
|
m_txP25Data.getData(m_buffer, len);
|
|
|
|
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_trace) {
|
2016-09-27 06:56:00 +00:00
|
|
|
if (m_buffer[2U] == MMDVM_P25_HDR)
|
2016-09-08 17:38:59 +00:00
|
|
|
CUtils::dump(1U, "TX P25 HDR", m_buffer, len);
|
|
|
|
else
|
|
|
|
CUtils::dump(1U, "TX P25 LDU", m_buffer, len);
|
|
|
|
}
|
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
int ret = m_serial->write(m_buffer, len);
|
2016-09-08 17:38:59 +00:00
|
|
|
if (ret != int(len))
|
|
|
|
LogWarning("Error when writing P25 data to the MMDVM");
|
|
|
|
|
|
|
|
m_playoutTimer.start();
|
|
|
|
|
|
|
|
m_p25Space--;
|
|
|
|
}
|
2018-01-11 19:35:33 +00:00
|
|
|
|
|
|
|
if (m_nxdnSpace > 1U && !m_txNXDNData.isEmpty()) {
|
|
|
|
unsigned char len = 0U;
|
|
|
|
m_txNXDNData.getData(&len, 1U);
|
|
|
|
m_txNXDNData.getData(m_buffer, len);
|
|
|
|
|
|
|
|
if (m_trace)
|
|
|
|
CUtils::dump(1U, "TX NXDN Data", m_buffer, len);
|
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
int ret = m_serial->write(m_buffer, len);
|
2018-01-11 19:35:33 +00:00
|
|
|
if (ret != int(len))
|
|
|
|
LogWarning("Error when writing NXDN data to the MMDVM");
|
|
|
|
|
|
|
|
m_playoutTimer.start();
|
|
|
|
|
|
|
|
m_nxdnSpace--;
|
|
|
|
}
|
2018-03-22 07:13:13 +00:00
|
|
|
|
2018-06-07 17:46:03 +00:00
|
|
|
if (m_pocsagSpace > 1U && !m_txPOCSAGData.isEmpty()) {
|
|
|
|
unsigned char len = 0U;
|
|
|
|
m_txPOCSAGData.getData(&len, 1U);
|
|
|
|
m_txPOCSAGData.getData(m_buffer, len);
|
|
|
|
|
|
|
|
if (m_trace)
|
|
|
|
CUtils::dump(1U, "TX POCSAG Data", m_buffer, len);
|
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
int ret = m_serial->write(m_buffer, len);
|
2018-06-07 17:46:03 +00:00
|
|
|
if (ret != int(len))
|
|
|
|
LogWarning("Error when writing POCSAG data to the MMDVM");
|
|
|
|
|
|
|
|
m_playoutTimer.start();
|
|
|
|
|
|
|
|
m_pocsagSpace--;
|
|
|
|
}
|
|
|
|
|
2018-03-22 07:13:13 +00:00
|
|
|
if (!m_txTransparentData.isEmpty()) {
|
|
|
|
unsigned char len = 0U;
|
|
|
|
m_txTransparentData.getData(&len, 1U);
|
|
|
|
m_txTransparentData.getData(m_buffer, len);
|
|
|
|
|
|
|
|
if (m_trace)
|
|
|
|
CUtils::dump(1U, "TX Transparent Data", m_buffer, len);
|
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
int ret = m_serial->write(m_buffer, len);
|
2018-03-22 07:13:13 +00:00
|
|
|
if (ret != int(len))
|
|
|
|
LogWarning("Error when writing Transparent data to the MMDVM");
|
|
|
|
}
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModem::close()
|
|
|
|
{
|
2018-07-30 17:19:46 +00:00
|
|
|
assert(m_serial != NULL);
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
::LogMessage("Closing the MMDVM");
|
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
m_serial->close();
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CModem::readDStarData(unsigned char* data)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
|
|
|
|
if (m_rxDStarData.isEmpty())
|
|
|
|
return 0U;
|
|
|
|
|
|
|
|
unsigned char len = 0U;
|
|
|
|
m_rxDStarData.getData(&len, 1U);
|
|
|
|
m_rxDStarData.getData(data, len);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CModem::readDMRData1(unsigned char* data)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
|
|
|
|
if (m_rxDMRData1.isEmpty())
|
|
|
|
return 0U;
|
|
|
|
|
|
|
|
unsigned char len = 0U;
|
|
|
|
m_rxDMRData1.getData(&len, 1U);
|
|
|
|
m_rxDMRData1.getData(data, len);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CModem::readDMRData2(unsigned char* data)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
|
|
|
|
if (m_rxDMRData2.isEmpty())
|
|
|
|
return 0U;
|
|
|
|
|
|
|
|
unsigned char len = 0U;
|
|
|
|
m_rxDMRData2.getData(&len, 1U);
|
|
|
|
m_rxDMRData2.getData(data, len);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CModem::readYSFData(unsigned char* data)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
|
|
|
|
if (m_rxYSFData.isEmpty())
|
|
|
|
return 0U;
|
|
|
|
|
|
|
|
unsigned char len = 0U;
|
|
|
|
m_rxYSFData.getData(&len, 1U);
|
|
|
|
m_rxYSFData.getData(data, len);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2016-09-08 17:38:59 +00:00
|
|
|
unsigned int CModem::readP25Data(unsigned char* data)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
|
|
|
|
if (m_rxP25Data.isEmpty())
|
|
|
|
return 0U;
|
|
|
|
|
|
|
|
unsigned char len = 0U;
|
|
|
|
m_rxP25Data.getData(&len, 1U);
|
|
|
|
m_rxP25Data.getData(data, len);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2018-01-11 19:35:33 +00:00
|
|
|
unsigned int CModem::readNXDNData(unsigned char* data)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
|
|
|
|
if (m_rxNXDNData.isEmpty())
|
|
|
|
return 0U;
|
|
|
|
|
|
|
|
unsigned char len = 0U;
|
|
|
|
m_rxNXDNData.getData(&len, 1U);
|
|
|
|
m_rxNXDNData.getData(data, len);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2020-06-08 15:33:20 +00:00
|
|
|
unsigned int CModem::readAX25Data(unsigned char* data)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
|
|
|
|
if (m_rxAX25Data.isEmpty())
|
|
|
|
return 0U;
|
|
|
|
|
|
|
|
unsigned char len = 0U;
|
|
|
|
m_rxAX25Data.getData(&len, 1U);
|
|
|
|
m_rxAX25Data.getData(data, len);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2018-03-22 07:13:13 +00:00
|
|
|
unsigned int CModem::readTransparentData(unsigned char* data)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
|
|
|
|
if (m_rxTransparentData.isEmpty())
|
|
|
|
return 0U;
|
|
|
|
|
|
|
|
unsigned char len = 0U;
|
|
|
|
m_rxTransparentData.getData(&len, 1U);
|
|
|
|
m_rxTransparentData.getData(data, len);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2016-10-06 17:38:16 +00:00
|
|
|
// To be implemented later if needed
|
|
|
|
unsigned int CModem::readSerial(unsigned char* data, unsigned int length)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
assert(length > 0U);
|
|
|
|
|
|
|
|
return 0U;
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
bool CModem::hasDStarSpace() const
|
|
|
|
{
|
|
|
|
unsigned int space = m_txDStarData.freeSpace() / (DSTAR_FRAME_LENGTH_BYTES + 4U);
|
|
|
|
|
|
|
|
return space > 1U;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CModem::writeDStarData(const unsigned char* data, unsigned int length)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
assert(length > 0U);
|
|
|
|
|
|
|
|
unsigned char buffer[50U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = length + 2U;
|
|
|
|
|
|
|
|
switch (data[0U]) {
|
2016-07-13 06:19:08 +00:00
|
|
|
case TAG_HEADER:
|
|
|
|
buffer[2U] = MMDVM_DSTAR_HEADER;
|
|
|
|
break;
|
|
|
|
case TAG_DATA:
|
|
|
|
buffer[2U] = MMDVM_DSTAR_DATA;
|
|
|
|
break;
|
|
|
|
case TAG_EOT:
|
|
|
|
buffer[2U] = MMDVM_DSTAR_EOT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
CUtils::dump(2U, "Unknown D-Star packet type", data, length);
|
|
|
|
return false;
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
::memcpy(buffer + 3U, data + 1U, length - 1U);
|
|
|
|
|
|
|
|
unsigned char len = length + 2U;
|
|
|
|
m_txDStarData.addData(&len, 1U);
|
|
|
|
m_txDStarData.addData(buffer, len);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CModem::hasDMRSpace1() const
|
|
|
|
{
|
|
|
|
unsigned int space = m_txDMRData1.freeSpace() / (DMR_FRAME_LENGTH_BYTES + 4U);
|
|
|
|
|
|
|
|
return space > 1U;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CModem::hasDMRSpace2() const
|
|
|
|
{
|
|
|
|
unsigned int space = m_txDMRData2.freeSpace() / (DMR_FRAME_LENGTH_BYTES + 4U);
|
|
|
|
|
|
|
|
return space > 1U;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CModem::writeDMRData1(const unsigned char* data, unsigned int length)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
assert(length > 0U);
|
|
|
|
|
|
|
|
if (data[0U] != TAG_DATA && data[0U] != TAG_EOT)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned char buffer[40U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = length + 2U;
|
|
|
|
buffer[2U] = MMDVM_DMR_DATA1;
|
|
|
|
|
|
|
|
::memcpy(buffer + 3U, data + 1U, length - 1U);
|
|
|
|
|
|
|
|
unsigned char len = length + 2U;
|
|
|
|
m_txDMRData1.addData(&len, 1U);
|
|
|
|
m_txDMRData1.addData(buffer, len);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CModem::writeDMRData2(const unsigned char* data, unsigned int length)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
assert(length > 0U);
|
|
|
|
|
|
|
|
if (data[0U] != TAG_DATA && data[0U] != TAG_EOT)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned char buffer[40U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = length + 2U;
|
|
|
|
buffer[2U] = MMDVM_DMR_DATA2;
|
|
|
|
|
|
|
|
::memcpy(buffer + 3U, data + 1U, length - 1U);
|
|
|
|
|
|
|
|
unsigned char len = length + 2U;
|
|
|
|
m_txDMRData2.addData(&len, 1U);
|
|
|
|
m_txDMRData2.addData(buffer, len);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CModem::hasYSFSpace() const
|
|
|
|
{
|
|
|
|
unsigned int space = m_txYSFData.freeSpace() / (YSF_FRAME_LENGTH_BYTES + 4U);
|
|
|
|
|
|
|
|
return space > 1U;
|
|
|
|
}
|
|
|
|
|
2016-09-08 17:38:59 +00:00
|
|
|
bool CModem::writeYSFData(const unsigned char* data, unsigned int length)
|
2016-05-05 16:56:18 +00:00
|
|
|
{
|
2016-09-08 17:38:59 +00:00
|
|
|
assert(data != NULL);
|
|
|
|
assert(length > 0U);
|
2016-05-05 16:56:18 +00:00
|
|
|
|
2016-09-08 17:38:59 +00:00
|
|
|
if (data[0U] != TAG_DATA && data[0U] != TAG_EOT)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned char buffer[130U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = length + 2U;
|
|
|
|
buffer[2U] = MMDVM_YSF_DATA;
|
|
|
|
|
|
|
|
::memcpy(buffer + 3U, data + 1U, length - 1U);
|
|
|
|
|
|
|
|
unsigned char len = length + 2U;
|
|
|
|
m_txYSFData.addData(&len, 1U);
|
|
|
|
m_txYSFData.addData(buffer, len);
|
|
|
|
|
|
|
|
return true;
|
2016-03-03 18:01:01 +00:00
|
|
|
}
|
|
|
|
|
2016-09-08 17:38:59 +00:00
|
|
|
bool CModem::hasP25Space() const
|
2016-03-21 22:47:58 +00:00
|
|
|
{
|
2016-09-08 17:38:59 +00:00
|
|
|
unsigned int space = m_txP25Data.freeSpace() / (P25_LDU_FRAME_LENGTH_BYTES + 4U);
|
|
|
|
|
|
|
|
return space > 1U;
|
2016-03-21 22:47:58 +00:00
|
|
|
}
|
|
|
|
|
2016-09-08 17:38:59 +00:00
|
|
|
bool CModem::writeP25Data(const unsigned char* data, unsigned int length)
|
2016-01-14 18:45:04 +00:00
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
assert(length > 0U);
|
|
|
|
|
2016-09-08 17:38:59 +00:00
|
|
|
if (data[0U] != TAG_HEADER && data[0U] != TAG_DATA && data[0U] != TAG_EOT)
|
2016-01-14 18:45:04 +00:00
|
|
|
return false;
|
|
|
|
|
2016-09-08 17:38:59 +00:00
|
|
|
unsigned char buffer[250U];
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = length + 2U;
|
2016-09-08 17:38:59 +00:00
|
|
|
buffer[2U] = (data[0U] == TAG_HEADER) ? MMDVM_P25_HDR : MMDVM_P25_LDU;
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
::memcpy(buffer + 3U, data + 1U, length - 1U);
|
|
|
|
|
|
|
|
unsigned char len = length + 2U;
|
2016-09-08 17:38:59 +00:00
|
|
|
m_txP25Data.addData(&len, 1U);
|
|
|
|
m_txP25Data.addData(buffer, len);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-01-11 19:35:33 +00:00
|
|
|
bool CModem::hasNXDNSpace() const
|
|
|
|
{
|
|
|
|
unsigned int space = m_txNXDNData.freeSpace() / (NXDN_FRAME_LENGTH_BYTES + 4U);
|
|
|
|
|
|
|
|
return space > 1U;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CModem::writeNXDNData(const unsigned char* data, unsigned int length)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
assert(length > 0U);
|
|
|
|
|
|
|
|
if (data[0U] != TAG_DATA && data[0U] != TAG_EOT)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned char buffer[130U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = length + 2U;
|
|
|
|
buffer[2U] = MMDVM_NXDN_DATA;
|
|
|
|
|
|
|
|
::memcpy(buffer + 3U, data + 1U, length - 1U);
|
|
|
|
|
|
|
|
unsigned char len = length + 2U;
|
|
|
|
m_txNXDNData.addData(&len, 1U);
|
|
|
|
m_txNXDNData.addData(buffer, len);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-07 17:46:03 +00:00
|
|
|
bool CModem::hasPOCSAGSpace() const
|
|
|
|
{
|
|
|
|
unsigned int space = m_txPOCSAGData.freeSpace() / (POCSAG_FRAME_LENGTH_BYTES + 4U);
|
|
|
|
|
|
|
|
return space > 1U;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CModem::writePOCSAGData(const unsigned char* data, unsigned int length)
|
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
assert(length > 0U);
|
|
|
|
|
|
|
|
unsigned char buffer[130U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
2018-06-12 18:14:22 +00:00
|
|
|
buffer[1U] = length + 3U;
|
2018-06-07 17:46:03 +00:00
|
|
|
buffer[2U] = MMDVM_POCSAG_DATA;
|
|
|
|
|
|
|
|
::memcpy(buffer + 3U, data, length);
|
|
|
|
|
2018-10-31 15:38:56 +00:00
|
|
|
unsigned char len = length + 3U;
|
2018-06-07 17:46:03 +00:00
|
|
|
m_txPOCSAGData.addData(&len, 1U);
|
|
|
|
m_txPOCSAGData.addData(buffer, len);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-13 18:35:12 +00:00
|
|
|
bool CModem::writeTransparentData(const unsigned char* data, unsigned int length)
|
2018-03-22 07:13:13 +00:00
|
|
|
{
|
|
|
|
assert(data != NULL);
|
|
|
|
assert(length > 0U);
|
|
|
|
|
|
|
|
unsigned char buffer[250U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = length + 3U;
|
|
|
|
buffer[2U] = MMDVM_TRANSPARENT;
|
|
|
|
|
2018-10-31 15:38:56 +00:00
|
|
|
if (m_sendTransparentDataFrameType > 0U) {
|
2018-08-13 18:39:16 +00:00
|
|
|
::memcpy(buffer + 2U, data, length);
|
|
|
|
length--;
|
|
|
|
buffer[1U]--;
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-08-13 18:39:16 +00:00
|
|
|
//when sendFrameType==1 , only 0x80 and 0x90 (MMDVM_SERIAL and MMDVM_TRANSPARENT) are allowed
|
|
|
|
// and reverted to default (MMDVM_TRANSPARENT) for any other value
|
|
|
|
//when >1, frame type is not checked
|
2018-10-31 15:38:56 +00:00
|
|
|
if (m_sendTransparentDataFrameType == 1U) {
|
|
|
|
if ((buffer[2U] & 0xE0) != 0x80)
|
|
|
|
buffer[2U] = MMDVM_TRANSPARENT;
|
2018-08-13 18:39:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
::memcpy(buffer + 3U, data, length);
|
|
|
|
}
|
2018-03-22 07:13:13 +00:00
|
|
|
|
|
|
|
unsigned char len = length + 3U;
|
|
|
|
m_txTransparentData.addData(&len, 1U);
|
|
|
|
m_txTransparentData.addData(buffer, len);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
bool CModem::writeDStarInfo(const char* my1, const char* my2, const char* your, const char* type, const char* reflector)
|
2018-10-31 15:38:56 +00:00
|
|
|
{
|
|
|
|
assert(m_serial != NULL);
|
|
|
|
assert(my1 != NULL);
|
|
|
|
assert(my2 != NULL);
|
|
|
|
assert(your != NULL);
|
2018-10-31 16:54:57 +00:00
|
|
|
assert(type != NULL);
|
2018-10-31 15:38:56 +00:00
|
|
|
assert(reflector != NULL);
|
|
|
|
|
|
|
|
unsigned char buffer[50U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
2018-10-31 16:54:57 +00:00
|
|
|
buffer[1U] = 33U;
|
2018-10-31 15:38:56 +00:00
|
|
|
buffer[2U] = MMDVM_QSO_INFO;
|
|
|
|
|
|
|
|
buffer[3U] = MODE_DSTAR;
|
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
::memcpy(buffer + 4U, my1, DSTAR_LONG_CALLSIGN_LENGTH);
|
|
|
|
::memcpy(buffer + 12U, my2, DSTAR_SHORT_CALLSIGN_LENGTH);
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
::memcpy(buffer + 16U, your, DSTAR_LONG_CALLSIGN_LENGTH);
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
::memcpy(buffer + 24U, type, 1U);
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
::memcpy(buffer + 25U, reflector, DSTAR_LONG_CALLSIGN_LENGTH);
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
return m_serial->write(buffer, 33U) != 33;
|
2018-10-31 15:38:56 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
bool CModem::writeDMRInfo(unsigned int slotNo, const std::string& src, bool group, const std::string& dest, const char* type)
|
2018-10-31 15:38:56 +00:00
|
|
|
{
|
|
|
|
assert(m_serial != NULL);
|
2018-10-31 16:54:57 +00:00
|
|
|
assert(type != NULL);
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
unsigned char buffer[50U];
|
2018-10-31 15:38:56 +00:00
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
2018-10-31 16:54:57 +00:00
|
|
|
buffer[1U] = 47U;
|
2018-10-31 15:38:56 +00:00
|
|
|
buffer[2U] = MMDVM_QSO_INFO;
|
|
|
|
|
|
|
|
buffer[3U] = MODE_DMR;
|
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
buffer[4U] = slotNo;
|
|
|
|
|
|
|
|
::sprintf((char*)(buffer + 5U), "%20.20s", src.c_str());
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
buffer[25U] = group ? 'G' : 'I';
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
::sprintf((char*)(buffer + 26U), "%20.20s", dest.c_str());
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
::memcpy(buffer + 46U, type, 1U);
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
return m_serial->write(buffer, 47U) != 47;
|
2018-10-31 15:38:56 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
bool CModem::writeYSFInfo(const char* source, const char* dest, const char* type, const char* origin)
|
2018-10-31 15:38:56 +00:00
|
|
|
{
|
|
|
|
assert(m_serial != NULL);
|
2018-10-31 16:54:57 +00:00
|
|
|
assert(source != NULL);
|
2018-10-31 15:38:56 +00:00
|
|
|
assert(dest != NULL);
|
2018-10-31 16:54:57 +00:00
|
|
|
assert(type != NULL);
|
|
|
|
assert(origin != NULL);
|
2018-10-31 15:38:56 +00:00
|
|
|
|
|
|
|
unsigned char buffer[50U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = 35U;
|
|
|
|
buffer[2U] = MMDVM_QSO_INFO;
|
|
|
|
|
|
|
|
buffer[3U] = MODE_YSF;
|
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
::memcpy(buffer + 4U, source, YSF_CALLSIGN_LENGTH);
|
|
|
|
::memcpy(buffer + 14U, dest, YSF_CALLSIGN_LENGTH);
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
::memcpy(buffer + 24U, type, 1U);
|
|
|
|
|
|
|
|
::memcpy(buffer + 25U, origin, YSF_CALLSIGN_LENGTH);
|
2018-10-31 15:38:56 +00:00
|
|
|
|
|
|
|
return m_serial->write(buffer, 35U) != 35;
|
|
|
|
}
|
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
bool CModem::writeP25Info(const char* source, bool group, unsigned int dest, const char* type)
|
2018-10-31 15:38:56 +00:00
|
|
|
{
|
|
|
|
assert(m_serial != NULL);
|
2018-10-31 16:54:57 +00:00
|
|
|
assert(source != NULL);
|
|
|
|
assert(type != NULL);
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
unsigned char buffer[40U];
|
2018-10-31 15:38:56 +00:00
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
2018-10-31 16:54:57 +00:00
|
|
|
buffer[1U] = 31U;
|
2018-10-31 15:38:56 +00:00
|
|
|
buffer[2U] = MMDVM_QSO_INFO;
|
|
|
|
|
|
|
|
buffer[3U] = MODE_DMR;
|
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
::sprintf((char*)(buffer + 4U), "%20.20s", source);
|
|
|
|
|
|
|
|
buffer[24U] = group ? 'G' : 'I';
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
::sprintf((char*)(buffer + 25U), "%05u", dest); // 16-bits
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
::memcpy(buffer + 30U, type, 1U);
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
return m_serial->write(buffer, 31U) != 31;
|
2018-10-31 15:38:56 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
bool CModem::writeNXDNInfo(const char* source, bool group, unsigned int dest, const char* type)
|
2018-10-31 15:38:56 +00:00
|
|
|
{
|
|
|
|
assert(m_serial != NULL);
|
2018-10-31 16:54:57 +00:00
|
|
|
assert(source != NULL);
|
|
|
|
assert(type != NULL);
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
unsigned char buffer[40U];
|
2018-10-31 15:38:56 +00:00
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
2018-10-31 16:54:57 +00:00
|
|
|
buffer[1U] = 31U;
|
2018-10-31 15:38:56 +00:00
|
|
|
buffer[2U] = MMDVM_QSO_INFO;
|
|
|
|
|
|
|
|
buffer[3U] = MODE_NXDN;
|
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
::sprintf((char*)(buffer + 4U), "%20.20s", source);
|
|
|
|
|
|
|
|
buffer[24U] = group ? 'G' : 'I';
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
::sprintf((char*)(buffer + 25U), "%05u", dest); // 16-bits
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
::memcpy(buffer + 30U, type, 1U);
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
return m_serial->write(buffer, 31U) != 31;
|
2018-10-31 15:38:56 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
bool CModem::writePOCSAGInfo(unsigned int ric, const std::string& message)
|
2018-10-31 15:38:56 +00:00
|
|
|
{
|
|
|
|
assert(m_serial != NULL);
|
2018-10-31 16:54:57 +00:00
|
|
|
|
|
|
|
size_t length = message.size();
|
2018-10-31 15:38:56 +00:00
|
|
|
|
|
|
|
unsigned char buffer[250U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
2018-10-31 16:54:57 +00:00
|
|
|
buffer[1U] = length + 11U;
|
2018-10-31 15:38:56 +00:00
|
|
|
buffer[2U] = MMDVM_QSO_INFO;
|
|
|
|
|
|
|
|
buffer[3U] = MODE_POCSAG;
|
|
|
|
|
|
|
|
::sprintf((char*)(buffer + 4U), "%07u", ric); // 21-bits
|
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
::memcpy(buffer + 11U, message.c_str(), length);
|
|
|
|
|
|
|
|
int ret = m_serial->write(buffer, length + 11U);
|
|
|
|
|
|
|
|
return ret != int(length + 11U);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CModem::writeIPInfo(const std::string& address)
|
|
|
|
{
|
|
|
|
assert(m_serial != NULL);
|
|
|
|
|
|
|
|
size_t length = address.size();
|
|
|
|
|
|
|
|
unsigned char buffer[25U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = length + 4U;
|
|
|
|
buffer[2U] = MMDVM_QSO_INFO;
|
|
|
|
|
|
|
|
buffer[3U] = 250U;
|
|
|
|
|
|
|
|
::memcpy(buffer + 4U, address.c_str(), length);
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
int ret = m_serial->write(buffer, length + 4U);
|
2018-10-31 15:38:56 +00:00
|
|
|
|
2018-10-31 16:54:57 +00:00
|
|
|
return ret != int(length + 4U);
|
2018-10-31 15:38:56 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 17:38:16 +00:00
|
|
|
bool CModem::writeSerial(const unsigned char* data, unsigned int length)
|
|
|
|
{
|
2018-07-30 17:19:46 +00:00
|
|
|
assert(m_serial != NULL);
|
2016-10-06 17:38:16 +00:00
|
|
|
assert(data != NULL);
|
|
|
|
assert(length > 0U);
|
|
|
|
|
|
|
|
unsigned char buffer[250U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = length + 3U;
|
|
|
|
buffer[2U] = MMDVM_SERIAL;
|
|
|
|
|
|
|
|
::memcpy(buffer + 3U, data, length);
|
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
int ret = m_serial->write(buffer, length + 3U);
|
2016-10-06 17:38:16 +00:00
|
|
|
|
|
|
|
return ret != int(length + 3U);
|
|
|
|
}
|
|
|
|
|
2016-09-08 17:38:59 +00:00
|
|
|
bool CModem::hasTX() const
|
|
|
|
{
|
|
|
|
return m_tx;
|
|
|
|
}
|
|
|
|
|
2016-11-17 10:48:42 +00:00
|
|
|
bool CModem::hasCD() const
|
|
|
|
{
|
|
|
|
return m_cd;
|
|
|
|
}
|
|
|
|
|
2016-09-08 17:38:59 +00:00
|
|
|
bool CModem::hasLockout() const
|
|
|
|
{
|
|
|
|
return m_lockout;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CModem::hasError() const
|
|
|
|
{
|
|
|
|
return m_error;
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
bool CModem::readVersion()
|
|
|
|
{
|
2018-07-30 17:19:46 +00:00
|
|
|
assert(m_serial != NULL);
|
|
|
|
|
2016-06-09 18:51:23 +00:00
|
|
|
CThread::sleep(2000U); // 2s
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
for (unsigned int i = 0U; i < 6U; i++) {
|
|
|
|
unsigned char buffer[3U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = 3U;
|
|
|
|
buffer[2U] = MMDVM_GET_VERSION;
|
|
|
|
|
2016-02-22 18:12:24 +00:00
|
|
|
// CUtils::dump(1U, "Written", buffer, 3U);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
int ret = m_serial->write(buffer, 3U);
|
2016-01-14 18:45:04 +00:00
|
|
|
if (ret != 3)
|
|
|
|
return false;
|
|
|
|
|
2017-11-15 11:10:12 +00:00
|
|
|
#if defined(__APPLE__)
|
2018-07-30 13:58:35 +00:00
|
|
|
m_serial->setNonblock(true);
|
2017-11-15 11:10:12 +00:00
|
|
|
#endif
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
for (unsigned int count = 0U; count < MAX_RESPONSES; count++) {
|
2016-06-06 16:40:27 +00:00
|
|
|
CThread::sleep(10U);
|
2016-03-21 18:16:58 +00:00
|
|
|
RESP_TYPE_MMDVM resp = getResponse();
|
2016-01-14 18:45:04 +00:00
|
|
|
if (resp == RTM_OK && m_buffer[2U] == MMDVM_GET_VERSION) {
|
2017-12-26 21:10:47 +00:00
|
|
|
if (::memcmp(m_buffer + 4U, "MMDVM ", 6U) == 0)
|
2016-09-05 16:40:43 +00:00
|
|
|
m_hwType = HWT_MMDVM;
|
|
|
|
else if (::memcmp(m_buffer + 4U, "DVMEGA", 6U) == 0)
|
|
|
|
m_hwType = HWT_DVMEGA;
|
2017-11-16 19:39:20 +00:00
|
|
|
else if (::memcmp(m_buffer + 4U, "ZUMspot", 7U) == 0)
|
2017-12-26 21:10:47 +00:00
|
|
|
m_hwType = HWT_MMDVM_ZUMSPOT;
|
|
|
|
else if (::memcmp(m_buffer + 4U, "MMDVM_HS_Hat", 12U) == 0)
|
|
|
|
m_hwType = HWT_MMDVM_HS_HAT;
|
2018-03-05 21:04:01 +00:00
|
|
|
else if (::memcmp(m_buffer + 4U, "MMDVM_HS_Dual_Hat", 17U) == 0)
|
|
|
|
m_hwType = HWT_MMDVM_HS_DUAL_HAT;
|
2018-02-14 15:18:34 +00:00
|
|
|
else if (::memcmp(m_buffer + 4U, "Nano_hotSPOT", 12U) == 0)
|
|
|
|
m_hwType = HWT_NANO_HOTSPOT;
|
2018-05-05 13:42:01 +00:00
|
|
|
else if (::memcmp(m_buffer + 4U, "Nano_DV", 7U) == 0)
|
|
|
|
m_hwType = HWT_NANO_DV;
|
2019-05-30 01:22:53 +00:00
|
|
|
else if (::memcmp(m_buffer + 4U, "D2RG_MMDVM_HS", 13U) == 0)
|
|
|
|
m_hwType = HWT_D2RG_MMDVM_HS;
|
2017-12-26 21:10:47 +00:00
|
|
|
else if (::memcmp(m_buffer + 4U, "MMDVM_HS-", 9U) == 0)
|
2017-11-16 19:57:11 +00:00
|
|
|
m_hwType = HWT_MMDVM_HS;
|
2020-01-08 09:58:41 +00:00
|
|
|
else if (::memcmp(m_buffer + 4U, "OpenGD77_HS", 11U) == 0)
|
|
|
|
m_hwType = HWT_OPENGD77_HS;
|
2016-09-05 16:40:43 +00:00
|
|
|
|
2016-03-21 18:16:58 +00:00
|
|
|
LogInfo("MMDVM protocol version: %u, description: %.*s", m_buffer[3U], m_length - 4U, m_buffer + 4U);
|
2016-01-14 18:45:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-19 07:12:11 +00:00
|
|
|
CThread::sleep(1500U);
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LogError("Unable to read the firmware version after six attempts");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CModem::readStatus()
|
|
|
|
{
|
2018-07-30 17:19:46 +00:00
|
|
|
assert(m_serial != NULL);
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
unsigned char buffer[3U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = 3U;
|
|
|
|
buffer[2U] = MMDVM_GET_STATUS;
|
|
|
|
|
2016-04-14 18:03:51 +00:00
|
|
|
// CUtils::dump(1U, "Written", buffer, 3U);
|
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
return m_serial->write(buffer, 3U) == 3;
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 20:40:55 +00:00
|
|
|
bool CModem::writeConfig()
|
|
|
|
{
|
|
|
|
return setConfig();
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
bool CModem::setConfig()
|
|
|
|
{
|
2018-07-30 17:19:46 +00:00
|
|
|
assert(m_serial != NULL);
|
|
|
|
|
2018-06-07 17:46:03 +00:00
|
|
|
unsigned char buffer[30U];
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
|
2020-05-06 16:10:23 +00:00
|
|
|
buffer[1U] = 24U;
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
buffer[2U] = MMDVM_SET_CONFIG;
|
|
|
|
|
|
|
|
buffer[3U] = 0x00U;
|
|
|
|
if (m_rxInvert)
|
|
|
|
buffer[3U] |= 0x01U;
|
|
|
|
if (m_txInvert)
|
|
|
|
buffer[3U] |= 0x02U;
|
|
|
|
if (m_pttInvert)
|
|
|
|
buffer[3U] |= 0x04U;
|
2017-03-23 20:26:17 +00:00
|
|
|
if (m_ysfLoDev)
|
|
|
|
buffer[3U] |= 0x08U;
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_debug)
|
|
|
|
buffer[3U] |= 0x10U;
|
2016-08-25 16:23:45 +00:00
|
|
|
if (!m_duplex)
|
2016-08-23 06:30:55 +00:00
|
|
|
buffer[3U] |= 0x80U;
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
buffer[4U] = 0x00U;
|
|
|
|
if (m_dstarEnabled)
|
|
|
|
buffer[4U] |= 0x01U;
|
|
|
|
if (m_dmrEnabled)
|
|
|
|
buffer[4U] |= 0x02U;
|
|
|
|
if (m_ysfEnabled)
|
|
|
|
buffer[4U] |= 0x04U;
|
2016-09-08 17:38:59 +00:00
|
|
|
if (m_p25Enabled)
|
|
|
|
buffer[4U] |= 0x08U;
|
2018-01-11 19:35:33 +00:00
|
|
|
if (m_nxdnEnabled)
|
|
|
|
buffer[4U] |= 0x10U;
|
2018-06-07 17:46:03 +00:00
|
|
|
if (m_pocsagEnabled)
|
|
|
|
buffer[4U] |= 0x20U;
|
2020-04-19 15:11:55 +00:00
|
|
|
if (m_fmEnabled && m_duplex)
|
2020-04-12 14:10:51 +00:00
|
|
|
buffer[4U] |= 0x40U;
|
2020-06-08 15:33:20 +00:00
|
|
|
if (m_ax25Enabled)
|
|
|
|
buffer[4U] |= 0x80U;
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
buffer[5U] = m_txDelay / 10U; // In 10ms units
|
|
|
|
|
|
|
|
buffer[6U] = MODE_IDLE;
|
|
|
|
|
2017-06-02 15:34:55 +00:00
|
|
|
buffer[7U] = (unsigned char)(m_rxLevel * 2.55F + 0.5F);
|
2016-10-10 16:46:37 +00:00
|
|
|
|
2017-06-02 15:34:55 +00:00
|
|
|
buffer[8U] = (unsigned char)(m_cwIdTXLevel * 2.55F + 0.5F);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2017-03-23 20:26:17 +00:00
|
|
|
buffer[9U] = m_dmrColorCode;
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-03-17 18:12:14 +00:00
|
|
|
buffer[10U] = m_dmrDelay;
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2017-03-09 07:54:32 +00:00
|
|
|
buffer[11U] = 128U; // Was OscOffset
|
2016-03-17 18:12:14 +00:00
|
|
|
|
2017-06-02 15:34:55 +00:00
|
|
|
buffer[12U] = (unsigned char)(m_dstarTXLevel * 2.55F + 0.5F);
|
|
|
|
buffer[13U] = (unsigned char)(m_dmrTXLevel * 2.55F + 0.5F);
|
|
|
|
buffer[14U] = (unsigned char)(m_ysfTXLevel * 2.55F + 0.5F);
|
|
|
|
buffer[15U] = (unsigned char)(m_p25TXLevel * 2.55F + 0.5F);
|
2016-08-09 06:08:37 +00:00
|
|
|
|
2017-08-20 11:07:57 +00:00
|
|
|
buffer[16U] = (unsigned char)(m_txDCOffset + 128);
|
2017-10-28 11:37:32 +00:00
|
|
|
buffer[17U] = (unsigned char)(m_rxDCOffset + 128);
|
2016-03-21 21:50:45 +00:00
|
|
|
|
2018-01-11 19:35:33 +00:00
|
|
|
buffer[18U] = (unsigned char)(m_nxdnTXLevel * 2.55F + 0.5F);
|
|
|
|
|
2018-05-21 20:32:33 +00:00
|
|
|
buffer[19U] = (unsigned char)m_ysfTXHang;
|
2017-08-20 11:07:57 +00:00
|
|
|
|
2018-06-07 17:46:03 +00:00
|
|
|
buffer[20U] = (unsigned char)(m_pocsagTXLevel * 2.55F + 0.5F);
|
|
|
|
|
2020-04-12 14:10:51 +00:00
|
|
|
buffer[21U] = (unsigned char)(m_fmTXLevel * 2.55F + 0.5F);
|
2018-05-21 20:32:33 +00:00
|
|
|
|
2020-05-06 16:10:23 +00:00
|
|
|
buffer[22U] = (unsigned char)m_p25TXHang;
|
|
|
|
|
|
|
|
buffer[23U] = (unsigned char)m_nxdnTXHang;
|
|
|
|
|
|
|
|
// CUtils::dump(1U, "Written", buffer, 24U);
|
2020-04-12 14:10:51 +00:00
|
|
|
|
2020-05-06 16:10:23 +00:00
|
|
|
int ret = m_serial->write(buffer, 24U);
|
|
|
|
if (ret != 24)
|
2016-01-14 18:45:04 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned int count = 0U;
|
|
|
|
RESP_TYPE_MMDVM resp;
|
|
|
|
do {
|
2016-06-06 16:40:27 +00:00
|
|
|
CThread::sleep(10U);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-06-06 16:40:27 +00:00
|
|
|
resp = getResponse();
|
2016-01-14 18:45:04 +00:00
|
|
|
if (resp == RTM_OK && m_buffer[2U] != MMDVM_ACK && m_buffer[2U] != MMDVM_NAK) {
|
|
|
|
count++;
|
|
|
|
if (count >= MAX_RESPONSES) {
|
|
|
|
LogError("The MMDVM is not responding to the SET_CONFIG command");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (resp == RTM_OK && m_buffer[2U] != MMDVM_ACK && m_buffer[2U] != MMDVM_NAK);
|
|
|
|
|
2016-03-21 18:16:58 +00:00
|
|
|
// CUtils::dump(1U, "Response", m_buffer, m_length);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
|
|
|
if (resp == RTM_OK && m_buffer[2U] == MMDVM_NAK) {
|
|
|
|
LogError("Received a NAK to the SET_CONFIG command from the modem");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-31 10:42:12 +00:00
|
|
|
m_playoutTimer.start();
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-18 17:37:23 +00:00
|
|
|
bool CModem::setFrequency()
|
|
|
|
{
|
2018-07-30 17:19:46 +00:00
|
|
|
assert(m_serial != NULL);
|
|
|
|
|
2018-06-12 18:40:49 +00:00
|
|
|
unsigned char buffer[20U];
|
2018-01-02 02:19:27 +00:00
|
|
|
unsigned char len;
|
2018-12-10 17:22:44 +00:00
|
|
|
unsigned int pocsagFrequency = 433000000U;
|
|
|
|
|
|
|
|
if (m_pocsagEnabled)
|
|
|
|
pocsagFrequency = m_pocsagFrequency;
|
2018-07-19 13:09:00 +00:00
|
|
|
|
2018-01-02 02:19:27 +00:00
|
|
|
if (m_hwType == HWT_DVMEGA)
|
|
|
|
len = 12U;
|
|
|
|
else {
|
|
|
|
buffer[12U] = (unsigned char)(m_rfLevel * 2.55F + 0.5F);
|
2018-06-12 18:40:49 +00:00
|
|
|
|
2018-12-10 17:22:44 +00:00
|
|
|
buffer[13U] = (pocsagFrequency >> 0) & 0xFFU;
|
|
|
|
buffer[14U] = (pocsagFrequency >> 8) & 0xFFU;
|
|
|
|
buffer[15U] = (pocsagFrequency >> 16) & 0xFFU;
|
|
|
|
buffer[16U] = (pocsagFrequency >> 24) & 0xFFU;
|
2018-06-12 18:40:49 +00:00
|
|
|
|
|
|
|
len = 17U;
|
2018-01-02 02:19:27 +00:00
|
|
|
}
|
2016-02-18 17:37:23 +00:00
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
|
2018-01-02 02:19:27 +00:00
|
|
|
buffer[1U] = len;
|
2016-02-18 17:37:23 +00:00
|
|
|
|
|
|
|
buffer[2U] = MMDVM_SET_FREQ;
|
|
|
|
|
|
|
|
buffer[3U] = 0x00U;
|
|
|
|
|
|
|
|
buffer[4U] = (m_rxFrequency >> 0) & 0xFFU;
|
|
|
|
buffer[5U] = (m_rxFrequency >> 8) & 0xFFU;
|
|
|
|
buffer[6U] = (m_rxFrequency >> 16) & 0xFFU;
|
|
|
|
buffer[7U] = (m_rxFrequency >> 24) & 0xFFU;
|
|
|
|
|
|
|
|
buffer[8U] = (m_txFrequency >> 0) & 0xFFU;
|
|
|
|
buffer[9U] = (m_txFrequency >> 8) & 0xFFU;
|
|
|
|
buffer[10U] = (m_txFrequency >> 16) & 0xFFU;
|
|
|
|
buffer[11U] = (m_txFrequency >> 24) & 0xFFU;
|
|
|
|
|
2018-01-02 02:19:27 +00:00
|
|
|
// CUtils::dump(1U, "Written", buffer, len);
|
2016-02-18 17:37:23 +00:00
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
int ret = m_serial->write(buffer, len);
|
2018-01-02 02:19:27 +00:00
|
|
|
if (ret != len)
|
2016-02-18 17:37:23 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned int count = 0U;
|
|
|
|
RESP_TYPE_MMDVM resp;
|
|
|
|
do {
|
2016-06-06 16:40:27 +00:00
|
|
|
CThread::sleep(10U);
|
2016-02-18 17:37:23 +00:00
|
|
|
|
2016-06-06 16:40:27 +00:00
|
|
|
resp = getResponse();
|
2016-02-18 17:37:23 +00:00
|
|
|
if (resp == RTM_OK && m_buffer[2U] != MMDVM_ACK && m_buffer[2U] != MMDVM_NAK) {
|
|
|
|
count++;
|
|
|
|
if (count >= MAX_RESPONSES) {
|
|
|
|
LogError("The MMDVM is not responding to the SET_FREQ command");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (resp == RTM_OK && m_buffer[2U] != MMDVM_ACK && m_buffer[2U] != MMDVM_NAK);
|
|
|
|
|
2016-03-21 18:16:58 +00:00
|
|
|
// CUtils::dump(1U, "Response", m_buffer, m_length);
|
2016-02-18 17:37:23 +00:00
|
|
|
|
|
|
|
if (resp == RTM_OK && m_buffer[2U] == MMDVM_NAK) {
|
|
|
|
LogError("Received a NAK to the SET_FREQ command from the modem");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-21 18:16:58 +00:00
|
|
|
RESP_TYPE_MMDVM CModem::getResponse()
|
2016-01-14 18:45:04 +00:00
|
|
|
{
|
2018-07-30 17:19:46 +00:00
|
|
|
assert(m_serial != NULL);
|
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
if (m_state == SS_START) {
|
2016-03-21 18:16:58 +00:00
|
|
|
// Get the start of the frame or nothing at all
|
2018-07-30 13:58:35 +00:00
|
|
|
int ret = m_serial->read(m_buffer + 0U, 1U);
|
2016-03-16 08:08:28 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
LogError("Error when reading from the modem");
|
|
|
|
return RTM_ERROR;
|
|
|
|
}
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-03-16 08:08:28 +00:00
|
|
|
if (ret == 0)
|
|
|
|
return RTM_TIMEOUT;
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-03-21 18:16:58 +00:00
|
|
|
if (m_buffer[0U] != MMDVM_FRAME_START)
|
|
|
|
return RTM_TIMEOUT;
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_state = SS_LENGTH1;
|
|
|
|
m_length = 1U;
|
2016-03-17 17:54:37 +00:00
|
|
|
}
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
if (m_state == SS_LENGTH1) {
|
|
|
|
// Get the length of the frame, 1/2
|
2018-07-30 13:58:35 +00:00
|
|
|
int ret = m_serial->read(m_buffer + 1U, 1U);
|
2016-03-21 18:16:58 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
LogError("Error when reading from the modem");
|
2020-06-19 14:09:21 +00:00
|
|
|
m_state = SS_START;
|
2016-03-21 18:16:58 +00:00
|
|
|
return RTM_ERROR;
|
|
|
|
}
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2016-03-21 18:16:58 +00:00
|
|
|
if (ret == 0)
|
|
|
|
return RTM_TIMEOUT;
|
2016-03-16 07:56:27 +00:00
|
|
|
|
2016-03-21 18:16:58 +00:00
|
|
|
m_length = m_buffer[1U];
|
|
|
|
m_offset = 2U;
|
2020-06-19 14:09:21 +00:00
|
|
|
|
|
|
|
if (m_length == 0U)
|
|
|
|
m_state = SS_LENGTH2;
|
|
|
|
else
|
|
|
|
m_state = SS_TYPE;
|
2016-03-17 17:54:37 +00:00
|
|
|
}
|
2016-03-16 07:56:27 +00:00
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
if (m_state == SS_LENGTH2) {
|
|
|
|
// Get the length of the frane, 2/2
|
2018-07-30 13:58:35 +00:00
|
|
|
int ret = m_serial->read(m_buffer + 2U, 1U);
|
2016-03-21 18:16:58 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
LogError("Error when reading from the modem");
|
2020-06-19 14:09:21 +00:00
|
|
|
m_state = SS_START;
|
2016-03-21 18:16:58 +00:00
|
|
|
return RTM_ERROR;
|
|
|
|
}
|
2016-03-16 07:56:27 +00:00
|
|
|
|
2016-03-21 18:16:58 +00:00
|
|
|
if (ret == 0)
|
|
|
|
return RTM_TIMEOUT;
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_length = m_buffer[2U] + 255U;
|
2016-03-21 18:16:58 +00:00
|
|
|
m_offset = 3U;
|
2020-06-19 14:09:21 +00:00
|
|
|
m_state = SS_TYPE;
|
2016-03-21 18:16:58 +00:00
|
|
|
}
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
if (m_state == SS_TYPE) {
|
|
|
|
// Get the frame type
|
|
|
|
int ret = m_serial->read(&m_type, 1U);
|
|
|
|
if (ret < 0) {
|
|
|
|
LogError("Error when reading from the modem");
|
|
|
|
m_state = SS_START;
|
|
|
|
return RTM_ERROR;
|
|
|
|
}
|
2017-02-20 21:36:35 +00:00
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
if (ret == 0)
|
|
|
|
return RTM_TIMEOUT;
|
2017-02-20 21:36:35 +00:00
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_buffer[m_offset++] = m_type;
|
|
|
|
|
|
|
|
m_state = SS_DATA;
|
|
|
|
}
|
2017-02-20 21:36:35 +00:00
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
if (m_state == SS_DATA) {
|
2016-03-21 18:16:58 +00:00
|
|
|
while (m_offset < m_length) {
|
2018-07-30 13:58:35 +00:00
|
|
|
int ret = m_serial->read(m_buffer + m_offset, m_length - m_offset);
|
2016-03-21 18:16:58 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
LogError("Error when reading from the modem");
|
2020-06-19 14:09:21 +00:00
|
|
|
m_state = SS_START;
|
2016-03-21 18:16:58 +00:00
|
|
|
return RTM_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
return RTM_TIMEOUT;
|
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
m_offset += ret;
|
|
|
|
}
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
2017-02-12 18:37:00 +00:00
|
|
|
// CUtils::dump(1U, "Received", m_buffer, m_length);
|
|
|
|
|
2020-06-19 14:09:21 +00:00
|
|
|
m_offset = m_length > 255U ? 4U : 3U;
|
|
|
|
m_state = SS_START;
|
|
|
|
|
2017-02-28 08:25:23 +00:00
|
|
|
return RTM_OK;
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
2016-09-05 16:40:43 +00:00
|
|
|
HW_TYPE CModem::getHWType() const
|
|
|
|
{
|
|
|
|
return m_hwType;
|
|
|
|
}
|
|
|
|
|
2020-04-11 19:42:05 +00:00
|
|
|
unsigned char CModem::getMode() const
|
|
|
|
{
|
|
|
|
return m_mode;
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
bool CModem::setMode(unsigned char mode)
|
|
|
|
{
|
2018-07-30 17:19:46 +00:00
|
|
|
assert(m_serial != NULL);
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
unsigned char buffer[4U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = 4U;
|
|
|
|
buffer[2U] = MMDVM_SET_MODE;
|
|
|
|
buffer[3U] = mode;
|
|
|
|
|
2016-02-22 18:12:24 +00:00
|
|
|
// CUtils::dump(1U, "Written", buffer, 4U);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
return m_serial->write(buffer, 4U) == 4;
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
2016-05-09 20:55:44 +00:00
|
|
|
bool CModem::sendCWId(const std::string& callsign)
|
|
|
|
{
|
2018-07-30 17:19:46 +00:00
|
|
|
assert(m_serial != NULL);
|
|
|
|
|
2016-05-09 20:55:44 +00:00
|
|
|
unsigned int length = callsign.length();
|
|
|
|
if (length > 200U)
|
|
|
|
length = 200U;
|
|
|
|
|
|
|
|
unsigned char buffer[205U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = length + 3U;
|
|
|
|
buffer[2U] = MMDVM_SEND_CWID;
|
|
|
|
|
|
|
|
for (unsigned int i = 0U; i < length; i++)
|
|
|
|
buffer[i + 3U] = callsign.at(i);
|
|
|
|
|
|
|
|
// CUtils::dump(1U, "Written", buffer, length + 3U);
|
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
return m_serial->write(buffer, length + 3U) == int(length + 3U);
|
2016-05-09 20:55:44 +00:00
|
|
|
}
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
bool CModem::writeDMRStart(bool tx)
|
|
|
|
{
|
2018-07-30 17:19:46 +00:00
|
|
|
assert(m_serial != NULL);
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
if (tx && m_tx)
|
|
|
|
return true;
|
|
|
|
if (!tx && !m_tx)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
unsigned char buffer[4U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = 4U;
|
|
|
|
buffer[2U] = MMDVM_DMR_START;
|
|
|
|
buffer[3U] = tx ? 0x01U : 0x00U;
|
|
|
|
|
2016-02-22 18:12:24 +00:00
|
|
|
// CUtils::dump(1U, "Written", buffer, 4U);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
return m_serial->write(buffer, 4U) == 4;
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
2016-06-17 06:37:49 +00:00
|
|
|
bool CModem::writeDMRAbort(unsigned int slotNo)
|
|
|
|
{
|
2018-07-30 17:19:46 +00:00
|
|
|
assert(m_serial != NULL);
|
|
|
|
|
2016-06-17 06:37:49 +00:00
|
|
|
if (slotNo == 1U)
|
|
|
|
m_txDMRData1.clear();
|
|
|
|
else
|
|
|
|
m_txDMRData2.clear();
|
|
|
|
|
|
|
|
unsigned char buffer[4U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = 4U;
|
|
|
|
buffer[2U] = MMDVM_DMR_ABORT;
|
|
|
|
buffer[3U] = slotNo;
|
|
|
|
|
|
|
|
// CUtils::dump(1U, "Written", buffer, 4U);
|
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
return m_serial->write(buffer, 4U) == 4;
|
2016-06-17 06:37:49 +00:00
|
|
|
}
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
bool CModem::writeDMRShortLC(const unsigned char* lc)
|
|
|
|
{
|
2018-07-30 17:19:46 +00:00
|
|
|
assert(m_serial != NULL);
|
2016-01-14 18:45:04 +00:00
|
|
|
assert(lc != NULL);
|
|
|
|
|
|
|
|
unsigned char buffer[12U];
|
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = 12U;
|
|
|
|
buffer[2U] = MMDVM_DMR_SHORTLC;
|
|
|
|
buffer[3U] = lc[0U];
|
|
|
|
buffer[4U] = lc[1U];
|
|
|
|
buffer[5U] = lc[2U];
|
|
|
|
buffer[6U] = lc[3U];
|
|
|
|
buffer[7U] = lc[4U];
|
|
|
|
buffer[8U] = lc[5U];
|
|
|
|
buffer[9U] = lc[6U];
|
|
|
|
buffer[10U] = lc[7U];
|
|
|
|
buffer[11U] = lc[8U];
|
|
|
|
|
2016-02-22 18:12:24 +00:00
|
|
|
// CUtils::dump(1U, "Written", buffer, 12U);
|
2016-01-14 18:45:04 +00:00
|
|
|
|
2018-07-30 13:58:35 +00:00
|
|
|
return m_serial->write(buffer, 12U) == 12;
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
|
2020-05-04 21:30:16 +00:00
|
|
|
void CModem::setFMCallsignParams(const std::string& callsign, unsigned int callsignSpeed, unsigned int callsignFrequency, unsigned int callsignTime, unsigned int callsignHoldoff, float callsignHighLevel, float callsignLowLevel, bool callsignAtStart, bool callsignAtEnd, bool callsignAtLatch)
|
2020-04-18 13:59:19 +00:00
|
|
|
{
|
|
|
|
m_fmCallsign = callsign;
|
|
|
|
m_fmCallsignSpeed = callsignSpeed;
|
|
|
|
m_fmCallsignFrequency = callsignFrequency;
|
|
|
|
m_fmCallsignTime = callsignTime;
|
|
|
|
m_fmCallsignHoldoff = callsignHoldoff;
|
2020-04-22 20:51:43 +00:00
|
|
|
m_fmCallsignHighLevel = callsignHighLevel;
|
|
|
|
m_fmCallsignLowLevel = callsignLowLevel;
|
2020-04-18 13:59:19 +00:00
|
|
|
m_fmCallsignAtStart = callsignAtStart;
|
|
|
|
m_fmCallsignAtEnd = callsignAtEnd;
|
2020-05-04 21:30:16 +00:00
|
|
|
m_fmCallsignAtLatch = callsignAtLatch;
|
2020-04-18 13:59:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CModem::setFMAckParams(const std::string& rfAck, unsigned int ackSpeed, unsigned int ackFrequency, unsigned int ackMinTime, unsigned int ackDelay, float ackLevel)
|
|
|
|
{
|
|
|
|
m_fmRfAck = rfAck;
|
|
|
|
m_fmAckSpeed = ackSpeed;
|
|
|
|
m_fmAckFrequency = ackFrequency;
|
|
|
|
m_fmAckMinTime = ackMinTime;
|
|
|
|
m_fmAckDelay = ackDelay;
|
|
|
|
m_fmAckLevel = ackLevel;
|
|
|
|
}
|
|
|
|
|
2020-05-12 12:43:43 +00:00
|
|
|
void CModem::setFMMiscParams(unsigned int timeout, float timeoutLevel, float ctcssFrequency, unsigned int ctcssHighThreshold, unsigned int ctcssLowThreshold, float ctcssLevel, unsigned int kerchunkTime, unsigned int hangTime, bool useCOS, bool cosInvert, unsigned int rfAudioBoost, float maxDevLevel)
|
2020-04-18 13:59:19 +00:00
|
|
|
{
|
|
|
|
m_fmTimeout = timeout;
|
|
|
|
m_fmTimeoutLevel = timeoutLevel;
|
|
|
|
|
2020-05-12 12:43:43 +00:00
|
|
|
m_fmCtcssFrequency = ctcssFrequency;
|
|
|
|
m_fmCtcssHighThreshold = ctcssHighThreshold;
|
|
|
|
m_fmCtcssLowThreshold = ctcssLowThreshold;
|
|
|
|
m_fmCtcssLevel = ctcssLevel;
|
2020-04-18 13:59:19 +00:00
|
|
|
|
|
|
|
m_fmKerchunkTime = kerchunkTime;
|
|
|
|
m_fmHangTime = hangTime;
|
2020-04-25 14:15:56 +00:00
|
|
|
|
|
|
|
m_fmUseCOS = useCOS;
|
2020-05-06 10:26:54 +00:00
|
|
|
m_fmCOSInvert = cosInvert;
|
|
|
|
|
2020-04-28 13:39:14 +00:00
|
|
|
m_fmRFAudioBoost = rfAudioBoost;
|
2020-04-25 21:43:14 +00:00
|
|
|
m_fmMaxDevLevel = maxDevLevel;
|
2020-04-18 13:59:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CModem::setFMCallsignParams()
|
2020-04-09 21:55:20 +00:00
|
|
|
{
|
|
|
|
assert(m_serial != NULL);
|
|
|
|
|
|
|
|
unsigned char buffer[80U];
|
2020-04-22 20:51:43 +00:00
|
|
|
unsigned char len = 10U + m_fmCallsign.size();
|
2020-04-09 21:55:20 +00:00
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = len;
|
|
|
|
buffer[2U] = MMDVM_FM_PARAMS1;
|
|
|
|
|
2020-04-18 13:59:19 +00:00
|
|
|
buffer[3U] = m_fmCallsignSpeed;
|
|
|
|
buffer[4U] = m_fmCallsignFrequency / 10U;
|
|
|
|
buffer[5U] = m_fmCallsignTime;
|
|
|
|
buffer[6U] = m_fmCallsignHoldoff;
|
2020-04-12 15:01:28 +00:00
|
|
|
|
2020-04-22 20:51:43 +00:00
|
|
|
buffer[7U] = (unsigned char)(m_fmCallsignHighLevel * 2.55F + 0.5F);
|
|
|
|
buffer[8U] = (unsigned char)(m_fmCallsignLowLevel * 2.55F + 0.5F);
|
2020-04-09 21:55:20 +00:00
|
|
|
|
2020-04-22 20:51:43 +00:00
|
|
|
buffer[9U] = 0x00U;
|
2020-04-18 13:59:19 +00:00
|
|
|
if (m_fmCallsignAtStart)
|
2020-04-22 20:51:43 +00:00
|
|
|
buffer[9U] |= 0x01U;
|
2020-04-18 13:59:19 +00:00
|
|
|
if (m_fmCallsignAtEnd)
|
2020-04-22 20:51:43 +00:00
|
|
|
buffer[9U] |= 0x02U;
|
2020-05-04 21:30:16 +00:00
|
|
|
if (m_fmCallsignAtLatch)
|
|
|
|
buffer[9U] |= 0x04U;
|
2020-04-09 21:55:20 +00:00
|
|
|
|
2020-04-18 13:59:19 +00:00
|
|
|
for (unsigned int i = 0U; i < m_fmCallsign.size(); i++)
|
2020-04-22 20:51:43 +00:00
|
|
|
buffer[10U + i] = m_fmCallsign.at(i);
|
2020-04-09 21:55:20 +00:00
|
|
|
|
|
|
|
// CUtils::dump(1U, "Written", buffer, len);
|
|
|
|
|
|
|
|
int ret = m_serial->write(buffer, len);
|
|
|
|
if (ret != len)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned int count = 0U;
|
|
|
|
RESP_TYPE_MMDVM resp;
|
|
|
|
do {
|
|
|
|
CThread::sleep(10U);
|
|
|
|
|
|
|
|
resp = getResponse();
|
|
|
|
if (resp == RTM_OK && m_buffer[2U] != MMDVM_ACK && m_buffer[2U] != MMDVM_NAK) {
|
|
|
|
count++;
|
|
|
|
if (count >= MAX_RESPONSES) {
|
|
|
|
LogError("The MMDVM is not responding to the SET_FM_PARAMS1 command");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (resp == RTM_OK && m_buffer[2U] != MMDVM_ACK && m_buffer[2U] != MMDVM_NAK);
|
|
|
|
|
|
|
|
// CUtils::dump(1U, "Response", m_buffer, m_length);
|
|
|
|
|
|
|
|
if (resp == RTM_OK && m_buffer[2U] == MMDVM_NAK) {
|
|
|
|
LogError("Received a NAK to the SET_FM_PARAMS1 command from the modem");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-18 13:59:19 +00:00
|
|
|
bool CModem::setFMAckParams()
|
2020-04-09 21:55:20 +00:00
|
|
|
{
|
|
|
|
assert(m_serial != NULL);
|
|
|
|
|
|
|
|
unsigned char buffer[80U];
|
2020-04-18 13:59:19 +00:00
|
|
|
unsigned char len = 8U + m_fmRfAck.size();
|
2020-04-09 21:55:20 +00:00
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
|
|
|
buffer[1U] = len;
|
|
|
|
buffer[2U] = MMDVM_FM_PARAMS2;
|
|
|
|
|
2020-04-18 13:59:19 +00:00
|
|
|
buffer[3U] = m_fmAckSpeed;
|
|
|
|
buffer[4U] = m_fmAckFrequency / 10U;
|
|
|
|
buffer[5U] = m_fmAckMinTime;
|
|
|
|
buffer[6U] = m_fmAckDelay / 10U;
|
2020-04-12 15:01:28 +00:00
|
|
|
|
2020-04-18 13:59:19 +00:00
|
|
|
buffer[7U] = (unsigned char)(m_fmAckLevel * 2.55F + 0.5F);
|
2020-04-09 21:55:20 +00:00
|
|
|
|
2020-04-18 13:59:19 +00:00
|
|
|
for (unsigned int i = 0U; i < m_fmRfAck.size(); i++)
|
|
|
|
buffer[8U + i] = m_fmRfAck.at(i);
|
2020-04-09 21:55:20 +00:00
|
|
|
|
|
|
|
// CUtils::dump(1U, "Written", buffer, len);
|
|
|
|
|
|
|
|
int ret = m_serial->write(buffer, len);
|
|
|
|
if (ret != len)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned int count = 0U;
|
|
|
|
RESP_TYPE_MMDVM resp;
|
|
|
|
do {
|
|
|
|
CThread::sleep(10U);
|
|
|
|
|
|
|
|
resp = getResponse();
|
|
|
|
if (resp == RTM_OK && m_buffer[2U] != MMDVM_ACK && m_buffer[2U] != MMDVM_NAK) {
|
|
|
|
count++;
|
|
|
|
if (count >= MAX_RESPONSES) {
|
|
|
|
LogError("The MMDVM is not responding to the SET_FM_PARAMS2 command");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (resp == RTM_OK && m_buffer[2U] != MMDVM_ACK && m_buffer[2U] != MMDVM_NAK);
|
|
|
|
|
|
|
|
// CUtils::dump(1U, "Response", m_buffer, m_length);
|
|
|
|
|
|
|
|
if (resp == RTM_OK && m_buffer[2U] == MMDVM_NAK) {
|
|
|
|
LogError("Received a NAK to the SET_FM_PARAMS2 command from the modem");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-18 13:59:19 +00:00
|
|
|
bool CModem::setFMMiscParams()
|
2020-04-09 21:55:20 +00:00
|
|
|
{
|
|
|
|
assert(m_serial != NULL);
|
|
|
|
|
2020-04-11 19:42:05 +00:00
|
|
|
unsigned char buffer[20U];
|
2020-04-09 21:55:20 +00:00
|
|
|
|
|
|
|
buffer[0U] = MMDVM_FRAME_START;
|
2020-05-12 12:43:43 +00:00
|
|
|
buffer[1U] = 15U;
|
2020-04-09 21:55:20 +00:00
|
|
|
buffer[2U] = MMDVM_FM_PARAMS3;
|
|
|
|
|
2020-04-18 13:59:19 +00:00
|
|
|
buffer[3U] = m_fmTimeout / 5U;
|
|
|
|
buffer[4U] = (unsigned char)(m_fmTimeoutLevel * 2.55F + 0.5F);
|
2020-04-09 21:55:20 +00:00
|
|
|
|
2020-04-18 13:59:19 +00:00
|
|
|
buffer[5U] = (unsigned char)m_fmCtcssFrequency;
|
2020-05-12 12:43:43 +00:00
|
|
|
buffer[6U] = m_fmCtcssHighThreshold;
|
|
|
|
buffer[7U] = m_fmCtcssLowThreshold;
|
|
|
|
buffer[8U] = (unsigned char)(m_fmCtcssLevel * 2.55F + 0.5F);
|
2020-04-09 21:55:20 +00:00
|
|
|
|
2020-05-12 12:43:43 +00:00
|
|
|
buffer[9U] = m_fmKerchunkTime;
|
|
|
|
buffer[10U] = m_fmHangTime;
|
2020-04-09 21:55:20 +00:00
|
|
|
|
2020-05-12 12:43:43 +00:00
|
|
|
buffer[11U] = 0x00U;
|
2020-04-25 14:15:56 +00:00
|
|
|
if (m_fmUseCOS)
|
2020-05-12 12:43:43 +00:00
|
|
|
buffer[11U] |= 0x01U;
|
2020-05-06 10:26:54 +00:00
|
|
|
if (m_fmCOSInvert)
|
2020-05-12 12:43:43 +00:00
|
|
|
buffer[11U] |= 0x02U;
|
2020-04-25 14:15:56 +00:00
|
|
|
|
2020-05-12 12:43:43 +00:00
|
|
|
buffer[12U] = m_fmRFAudioBoost;
|
2020-04-25 14:15:56 +00:00
|
|
|
|
2020-05-12 12:43:43 +00:00
|
|
|
buffer[13U] = (unsigned char)(m_fmMaxDevLevel * 2.55F + 0.5F);
|
2020-04-25 21:43:14 +00:00
|
|
|
|
2020-05-12 12:43:43 +00:00
|
|
|
buffer[14U] = (unsigned char)(m_rxLevel * 2.55F + 0.5F);
|
2020-04-09 21:55:20 +00:00
|
|
|
|
2020-05-12 12:43:43 +00:00
|
|
|
// CUtils::dump(1U, "Written", buffer, 15U);
|
2020-04-26 20:50:03 +00:00
|
|
|
|
2020-05-12 12:43:43 +00:00
|
|
|
int ret = m_serial->write(buffer, 15U);
|
|
|
|
if (ret != 15)
|
2020-04-09 21:55:20 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned int count = 0U;
|
|
|
|
RESP_TYPE_MMDVM resp;
|
|
|
|
do {
|
|
|
|
CThread::sleep(10U);
|
|
|
|
|
|
|
|
resp = getResponse();
|
|
|
|
if (resp == RTM_OK && m_buffer[2U] != MMDVM_ACK && m_buffer[2U] != MMDVM_NAK) {
|
|
|
|
count++;
|
|
|
|
if (count >= MAX_RESPONSES) {
|
2020-04-11 19:42:05 +00:00
|
|
|
LogError("The MMDVM is not responding to the SET_FM_PARAMS3 command");
|
2020-04-09 21:55:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (resp == RTM_OK && m_buffer[2U] != MMDVM_ACK && m_buffer[2U] != MMDVM_NAK);
|
|
|
|
|
|
|
|
// CUtils::dump(1U, "Response", m_buffer, m_length);
|
|
|
|
|
|
|
|
if (resp == RTM_OK && m_buffer[2U] == MMDVM_NAK) {
|
2020-04-11 19:42:05 +00:00
|
|
|
LogError("Received a NAK to the SET_FM_PARAMS3 command from the modem");
|
2020-04-09 21:55:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-14 18:45:04 +00:00
|
|
|
void CModem::printDebug()
|
|
|
|
{
|
2017-04-14 13:05:30 +00:00
|
|
|
if (m_buffer[2U] == MMDVM_DEBUG1) {
|
2020-06-19 14:09:21 +00:00
|
|
|
LogMessage("Debug: %.*s", m_length - m_offset - 0U, m_buffer + m_offset);
|
2017-04-14 13:05:30 +00:00
|
|
|
} else if (m_buffer[2U] == MMDVM_DEBUG2) {
|
2016-03-21 18:16:58 +00:00
|
|
|
short val1 = (m_buffer[m_length - 2U] << 8) | m_buffer[m_length - 1U];
|
2020-06-19 14:09:21 +00:00
|
|
|
LogMessage("Debug: %.*s %d", m_length - m_offset - 2U, m_buffer + m_offset, val1);
|
2017-04-14 13:05:30 +00:00
|
|
|
} else if (m_buffer[2U] == MMDVM_DEBUG3) {
|
2016-03-21 18:16:58 +00:00
|
|
|
short val1 = (m_buffer[m_length - 4U] << 8) | m_buffer[m_length - 3U];
|
|
|
|
short val2 = (m_buffer[m_length - 2U] << 8) | m_buffer[m_length - 1U];
|
2020-06-19 14:09:21 +00:00
|
|
|
LogMessage("Debug: %.*s %d %d", m_length - m_offset - 4U, m_buffer + m_offset, val1, val2);
|
2017-04-14 13:05:30 +00:00
|
|
|
} else if (m_buffer[2U] == MMDVM_DEBUG4) {
|
2016-03-21 18:16:58 +00:00
|
|
|
short val1 = (m_buffer[m_length - 6U] << 8) | m_buffer[m_length - 5U];
|
|
|
|
short val2 = (m_buffer[m_length - 4U] << 8) | m_buffer[m_length - 3U];
|
|
|
|
short val3 = (m_buffer[m_length - 2U] << 8) | m_buffer[m_length - 1U];
|
2020-06-19 14:09:21 +00:00
|
|
|
LogMessage("Debug: %.*s %d %d %d", m_length - m_offset - 6U, m_buffer + m_offset, val1, val2, val3);
|
2017-04-14 13:05:30 +00:00
|
|
|
} else if (m_buffer[2U] == MMDVM_DEBUG5) {
|
2016-03-21 18:16:58 +00:00
|
|
|
short val1 = (m_buffer[m_length - 8U] << 8) | m_buffer[m_length - 7U];
|
|
|
|
short val2 = (m_buffer[m_length - 6U] << 8) | m_buffer[m_length - 5U];
|
|
|
|
short val3 = (m_buffer[m_length - 4U] << 8) | m_buffer[m_length - 3U];
|
|
|
|
short val4 = (m_buffer[m_length - 2U] << 8) | m_buffer[m_length - 1U];
|
2020-06-19 14:09:21 +00:00
|
|
|
LogMessage("Debug: %.*s %d %d %d %d", m_length - m_offset - 8U, m_buffer + m_offset, val1, val2, val3, val4);
|
2016-01-14 18:45:04 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-07 09:36:11 +00:00
|
|
|
|
|
|
|
CModem* CModem::createModem(const std::string& port, bool duplex, bool rxInvert, bool txInvert, bool pttInvert, unsigned int txDelay, unsigned int dmrDelay, bool trace, bool debug){
|
|
|
|
if (port == "NullModem")
|
|
|
|
return new CNullModem(port, duplex, rxInvert, txInvert, pttInvert, txDelay, dmrDelay, trace, debug);
|
|
|
|
else
|
|
|
|
return new CModem(port, duplex, rxInvert, txInvert, pttInvert, txDelay, dmrDelay, trace, debug);
|
2020-01-08 09:58:41 +00:00
|
|
|
}
|