diff --git a/Conf.h b/Conf.h index 05e6bc2..3e50b29 100644 --- a/Conf.h +++ b/Conf.h @@ -723,3 +723,4 @@ private: }; #endif + diff --git a/DStarNetwork.cpp b/DStarNetwork.cpp index 27ccc01..165e5fb 100644 --- a/DStarNetwork.cpp +++ b/DStarNetwork.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2014,2016,2019,2020,2021,2023 by Jonathan Naylor G4KLX + * Copyright (C) 2009-2014,2016,2019,2020,2021,2023,2024 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 @@ -166,7 +166,7 @@ bool CDStarNetwork::writePoll(const char* text) buffer[2] = 'R'; buffer[3] = 'P'; - buffer[4] = 0x0A; // Poll with text + buffer[4] = 0x0AU; // Poll with text unsigned int length = ::strlen(text); @@ -228,6 +228,7 @@ void CDStarNetwork::clock(unsigned int ms) case 0x01U: // NETWORK_TEMPTEXT; case 0x04U: // NETWORK_STATUS1..5 + case 0x0AU: // POLL case 0x24U: // NETWORK_DD_DATA return; diff --git a/FMNetwork.cpp b/FMNetwork.cpp index b163959..b10c69b 100644 --- a/FMNetwork.cpp +++ b/FMNetwork.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020,2021,2023 by Jonathan Naylor G4KLX + * Copyright (C) 2020,2021,2023,2024 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 @@ -29,7 +29,6 @@ #include #include #include -#include const unsigned int MMDVM_SAMPLERATE = 8000U; @@ -47,9 +46,11 @@ m_debug(debug), m_enabled(false), m_buffer(2000U, "FM Network"), m_seqNo(0U), +#if defined(HAS_SRC) m_resampler(NULL), +#endif m_error(0), -m_fd(-1) +m_fp(NULL) { assert(!callsign.empty()); assert(gatewayPort > 0U); @@ -69,12 +70,16 @@ m_fd(-1) else m_protocol = FMNP_USRP; +#if defined(HAS_SRC) m_resampler = ::src_new(SRC_SINC_FASTEST, 1, &m_error); +#endif } CFMNetwork::~CFMNetwork() { +#if defined(HAS_SRC) ::src_delete(m_resampler); +#endif } bool CFMNetwork::open() @@ -86,14 +91,25 @@ bool CFMNetwork::open() LogMessage("Opening FM network connection"); - if (!m_squelchFile.empty()) { - m_fd = ::open(m_squelchFile.c_str(), O_WRONLY | O_SYNC); - if (m_fd == -1) { - LogError("Cannot open the squelch file: %s, errno=%d", m_squelchFile.c_str(), errno); - return false; + if (m_protocol == FMNP_RAW) { + if (!m_squelchFile.empty()) { + m_fp = ::fopen(m_squelchFile.c_str(), "wb"); + if (m_fp == NULL) { +#if !defined(_WIN32) && !defined(_WIN64) + LogError("Cannot open the squelch file: %s, errno=%d", m_squelchFile.c_str(), errno); +#else + LogError("Cannot open the squelch file: %s, errno=%lu", m_squelchFile.c_str(), ::GetLastError()); +#endif + return false; + } } } + if ((m_protocol == FMNP_RAW) && (m_sampleRate != MMDVM_SAMPLERATE)) { + LogError("The resampler needed for non-native sample rates has not been included"); + return false; + } + return m_socket.open(m_addr); } @@ -199,6 +215,7 @@ bool CFMNetwork::writeRawData(const float* in, unsigned int nIn) unsigned int length = 0U; +#if defined(HAS_SRC) if (m_sampleRate != MMDVM_SAMPLERATE) { unsigned int nOut = (nIn * m_sampleRate) / MMDVM_SAMPLERATE; @@ -225,13 +242,16 @@ bool CFMNetwork::writeRawData(const float* in, unsigned int nIn) buffer[length++] = (val >> 8) & 0xFFU; } } else { +#endif for (unsigned int i = 0U; i < nIn; i++) { short val = short(in[i] * 32767.0F + 0.5F); // Changing audio format from float to S16LE buffer[length++] = (val >> 0) & 0xFFU; buffer[length++] = (val >> 8) & 0xFFU; } +#if defined(HAS_SRC) } +#endif if (m_debug) CUtils::dump(1U, "FM Network Data Sent", buffer, length); @@ -317,12 +337,18 @@ bool CFMNetwork::writeRawEnd() { m_seqNo = 0U; - if (m_fd != -1) { - size_t n = ::write(m_fd, "Z", 1); + if (m_fp != NULL) { + size_t n = ::fwrite("Z", 1, 1, m_fp); if (n != 1) { +#if !defined(_WIN32) && !defined(_WIN64) LogError("Cannot write to the squelch file: %s, errno=%d", m_squelchFile.c_str(), errno); +#else + LogError("Cannot write to the squelch file: %s, errno=%lu", m_squelchFile.c_str(), ::GetLastError()); +#endif return false; } + + ::fflush(m_fp); } return true; @@ -387,6 +413,7 @@ unsigned int CFMNetwork::readData(float* out, unsigned int nOut) if (bytes == 0U) return 0U; +#if defined(HAS_SRC) if ((m_protocol == FMNP_RAW) && (m_sampleRate != MMDVM_SAMPLERATE)) { unsigned int nIn = (nOut * m_sampleRate) / MMDVM_SAMPLERATE; @@ -419,6 +446,7 @@ unsigned int CFMNetwork::readData(float* out, unsigned int nOut) return false; } } else { +#endif if (bytes < nOut) nOut = bytes; @@ -429,7 +457,9 @@ unsigned int CFMNetwork::readData(float* out, unsigned int nOut) short val = ((buffer[i * 2U + 0U] & 0xFFU) << 0) + ((buffer[i * 2U + 1U] & 0xFFU) << 8); out[i] = float(val) / 65536.0F; } +#if defined(HAS_SRC) } +#endif return nOut; } @@ -443,9 +473,9 @@ void CFMNetwork::close() { m_socket.close(); - if (m_fd != -1) { - ::close(m_fd); - m_fd = -1; + if (m_fp != NULL) { + ::fclose(m_fp); + m_fp = NULL; } LogMessage("Closing FM network connection"); @@ -560,12 +590,18 @@ bool CFMNetwork::writeUSRPStart() bool CFMNetwork::writeRawStart() { - if (m_fd != -1) { - size_t n = ::write(m_fd, "O", 1); + if (m_fp != NULL) { + size_t n = ::fwrite("O", 1, 1, m_fp); if (n != 1) { +#if !defined(_WIN32) && !defined(_WIN64) LogError("Cannot write to the squelch file: %s, errno=%d", m_squelchFile.c_str(), errno); +#else + LogError("Cannot write to the squelch file: %s, errno=%lu", m_squelchFile.c_str(), ::GetLastError()); +#endif return false; } + + ::fflush(m_fp); } return true; diff --git a/FMNetwork.h b/FMNetwork.h index 80ae9ae..e8b264b 100644 --- a/FMNetwork.h +++ b/FMNetwork.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020,2021,2023 by Jonathan Naylor G4KLX + * Copyright (C) 2020,2021,2023,2024 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 @@ -16,7 +16,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifndef FMNetwork_H +#if !defined(FMNetwork_H) #define FMNetwork_H #include "RingBuffer.h" @@ -25,7 +25,9 @@ #if defined(USE_FM) +#if defined(HAS_SRC) #include +#endif #include #include @@ -68,9 +70,11 @@ private: bool m_enabled; CRingBuffer m_buffer; unsigned int m_seqNo; +#if defined(HAS_SRC) SRC_STATE* m_resampler; +#endif int m_error; - int m_fd; + FILE* m_fp; bool writeUSRPStart(); bool writeRawStart(); diff --git a/MMDVMHost.cpp b/MMDVMHost.cpp index 4dd6031..2d445b9 100644 --- a/MMDVMHost.cpp +++ b/MMDVMHost.cpp @@ -81,7 +81,7 @@ static CMMDVMHost* host = NULL; const char* HEADER1 = "This software is for use on amateur radio networks only,"; const char* HEADER2 = "it is to be used for educational purposes only. Its use on"; const char* HEADER3 = "commercial networks is strictly prohibited."; -const char* HEADER4 = "Copyright(C) 2015-2023 by Jonathan Naylor, G4KLX and others"; +const char* HEADER4 = "Copyright(C) 2015-2024 by Jonathan Naylor, G4KLX and others"; int main(int argc, char** argv) { diff --git a/MMDVMHost.vcxproj b/MMDVMHost.vcxproj index 5181fa8..29d0454 100644 --- a/MMDVMHost.vcxproj +++ b/MMDVMHost.vcxproj @@ -93,6 +93,7 @@ Console true kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) @@ -107,6 +108,7 @@ Console true kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) "$(ProjectDir)prebuild.cmd" $(ProjectDir) @@ -131,6 +133,7 @@ true true kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) @@ -149,6 +152,7 @@ true true kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies) + %(AdditionalLibraryDirectories) diff --git a/Makefile b/Makefile index e34f177..6dbcba9 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ # This makefile is for all platforms. +# If you have the resampler library installed, add -DHAS_SRC to the CFLAGS line, and -lsamplerate to the LIBS line. + CC = cc CXX = c++ CFLAGS = -g -O3 -Wall -std=c++0x -pthread -I/usr/local/include diff --git a/UARTController.cpp b/UARTController.cpp index 0d636d8..2400c33 100644 --- a/UARTController.cpp +++ b/UARTController.cpp @@ -295,7 +295,6 @@ bool CUARTController::setRaw() termios.c_cc[VTIME] = 10; #endif -#if !defined(B38400) || (B38400 != 38400) switch (m_speed) { #if defined(B1200) case 1200U: @@ -368,10 +367,6 @@ bool CUARTController::setRaw() ::close(m_fd); return false; } -#else - ::cfsetospeed(&termios, m_speed); - ::cfsetispeed(&termios, m_speed); -#endif if (::tcsetattr(m_fd, TCSANOW, &termios) < 0) { LogError("Cannot set the attributes for %s", m_device.c_str()); diff --git a/UDPSocket.h b/UDPSocket.h index 28e350c..07bf274 100644 --- a/UDPSocket.h +++ b/UDPSocket.h @@ -16,7 +16,7 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifndef UDPSocket_H +#if !defined(UDPSocket_H) #define UDPSocket_H #include @@ -33,6 +33,7 @@ #include #else #include +#include #endif enum IPMATCHTYPE { @@ -69,10 +70,11 @@ private: unsigned short m_localPort; #if defined(_WIN32) || defined(_WIN64) SOCKET m_fd; + int m_af; #else int m_fd; -#endif sa_family_t m_af; +#endif }; #endif diff --git a/Version.h b/Version.h index 85c1d9f..5478441 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20240207"; +const char* VERSION = "20240429"; #endif