From a816818e3f6335e1b5a35be21ca63f13f7a2b142 Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Thu, 7 May 2020 16:17:00 +0100 Subject: [PATCH] Beginnings of external audio for the FM controller. --- FM.h | 4 ++++ SerialPort.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- SerialPort.h | 4 +++- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/FM.h b/FM.h index 9e15c8a..e559293 100644 --- a/FM.h +++ b/FM.h @@ -57,6 +57,10 @@ public: uint8_t setAck(const char* rfAck, uint8_t speed, uint16_t frequency, uint8_t minTime, uint16_t delay, uint8_t level); uint8_t setMisc(uint16_t timeout, uint8_t timeoutLevel, uint8_t ctcssFrequency, uint8_t ctcssThreshold, uint8_t ctcssLevel, uint8_t kerchunkTime, uint8_t hangTime, bool useCOS, bool cosInvert, uint8_t rfAudioBoost, uint8_t maxDev, uint8_t rxLevel); + uint8_t getSpace() const; + + uint8_t writeData(const uint8_t* data, uint8_t length); + private: CFMKeyer m_callsign; CFMKeyer m_rfAck; diff --git a/SerialPort.cpp b/SerialPort.cpp index 711ba6e..f7bde93 100644 --- a/SerialPort.cpp +++ b/SerialPort.cpp @@ -68,6 +68,7 @@ const uint8_t MMDVM_POCSAG_DATA = 0x50U; const uint8_t MMDVM_FM_PARAMS1 = 0x60U; const uint8_t MMDVM_FM_PARAMS2 = 0x61U; const uint8_t MMDVM_FM_PARAMS3 = 0x62U; +const uint8_t MMDVM_FM_DATA = 0x65U; const uint8_t MMDVM_ACK = 0x70U; const uint8_t MMDVM_NAK = 0x7FU; @@ -101,7 +102,7 @@ const uint8_t MMDVM_DEBUG5 = 0xF5U; #define HW_TYPE "MMDVM" #endif -#define DESCRIPTION "20200506 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)" +#define DESCRIPTION "20200507 (D-Star/DMR/System Fusion/P25/NXDN/POCSAG/FM)" #if defined(GITVERSION) #define concat(h, a, b, c) h " " a " " b " GitID #" c "" @@ -156,7 +157,7 @@ void CSerialPort::getStatus() // Send all sorts of interesting internal values reply[0U] = MMDVM_FRAME_START; - reply[1U] = 13U; + reply[1U] = 14U; reply[2U] = MMDVM_GET_STATUS; reply[3U] = 0x00U; @@ -238,7 +239,12 @@ void CSerialPort::getStatus() else reply[12U] = 0U; - writeInt(1U, reply, 13); + if (m_fmEnable) + reply[13U] = fm.getSpace(); + else + reply[13U] = 0U; + + writeInt(1U, reply, 14); } void CSerialPort::getVersion() @@ -876,6 +882,20 @@ void CSerialPort::process() } break; + case MMDVM_FM_DATA: + if (m_fmEnable) { + if (m_modemState == STATE_IDLE || m_modemState == STATE_FM) + err = fm.writeData(m_buffer + 3U, m_len - 3U); + } + if (err == 0U) { + if (m_modemState == STATE_IDLE) + setMode(STATE_FM); + } else { + DEBUG2("Received invalid FM data", err); + sendNAK(err); + } + break; + case MMDVM_TRANSPARENT: case MMDVM_QSO_INFO: // Do nothing on the MMDVM. @@ -1188,6 +1208,29 @@ void CSerialPort::writeNXDNLost() writeInt(1U, reply, 3); } +void CSerialPort::writeFMData(const uint8_t* data, uint8_t length) +{ + if (m_modemState != STATE_FM && m_modemState != STATE_IDLE) + return; + + if (!m_fmEnable) + return; + + uint8_t reply[130U]; + + reply[0U] = MMDVM_FRAME_START; + reply[1U] = 0U; + reply[2U] = MMDVM_FM_DATA; + + uint8_t count = 3U; + for (uint8_t i = 0U; i < length; i++, count++) + reply[count] = data[i]; + + reply[1U] = count; + + writeInt(1U, reply, count); +} + void CSerialPort::writeCalData(const uint8_t* data, uint8_t length) { if (m_modemState != STATE_DSTARCAL) diff --git a/SerialPort.h b/SerialPort.h index cd09bbe..0e69752 100644 --- a/SerialPort.h +++ b/SerialPort.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015,2016,2017,2018 by Jonathan Naylor G4KLX + * Copyright (C) 2015,2016,2017,2018,2020 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 @@ -50,6 +50,8 @@ public: void writeNXDNData(const uint8_t* data, uint8_t length); void writeNXDNLost(); + void writeFMData(const uint8_t* data, uint8_t length); + void writeCalData(const uint8_t* data, uint8_t length); void writeRSSIData(const uint8_t* data, uint8_t length);