From 436e4b13b5bb6cab0f5a741fe3916b5ad20f68b1 Mon Sep 17 00:00:00 2001 From: Roberto Date: Thu, 29 Oct 2026 19:57:08 +0100 Subject: [PATCH 1/2] MMDVMHost: use async MQTT connection to prevent blocking Changed mosquitto_connect to mosquitto_connect_async in MQTTConnection.cpp. This prevents the host from freezing at startup if the MQTT broker is unreachable, allowing libmosquitto to handle reconnections in the background. --- MQTTConnection.cpp | 11 +++++------ Version.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/MQTTConnection.cpp b/MQTTConnection.cpp index d3edbdf0..493a1c5f 100644 --- a/MQTTConnection.cpp +++ b/MQTTConnection.cpp @@ -80,12 +80,12 @@ bool CMQTTConnection::open() ::mosquitto_message_callback_set(m_mosq, onMessage); ::mosquitto_disconnect_callback_set(m_mosq, onDisconnect); - int rc = ::mosquitto_connect(m_mosq, m_host.c_str(), m_port, m_keepalive); + // Use asynchronous connection to prevent the host from blocking if the broker is down + int rc = ::mosquitto_connect_async(m_mosq, m_host.c_str(), m_port, m_keepalive); if (rc != MOSQ_ERR_SUCCESS) { - ::mosquitto_destroy(m_mosq); - m_mosq = nullptr; - ::fprintf(stderr, "MQTT Error connecting: %s\n", ::mosquitto_strerror(rc)); - return false; + // Do not destroy m_mosq and do not return false. + // Mosquitto will try to reconnect in the background. Just warn the user. + ::fprintf(stderr, "MQTT Warning: Unable to connect immediately (will keep trying): %s\n", ::mosquitto_strerror(rc)); } rc = ::mosquitto_loop_start(m_mosq); @@ -230,4 +230,3 @@ void CMQTTConnection::onDisconnect(mosquitto* mosq, void* obj, int rc) CMQTTConnection* p = static_cast(obj); p->m_connected = false; } - diff --git a/Version.h b/Version.h index d5813152..cf92b353 100644 --- a/Version.h +++ b/Version.h @@ -19,6 +19,6 @@ #if !defined(VERSION_H) #define VERSION_H -const char* VERSION = "20260713"; +const char* VERSION = "20261028"; #endif From dc791dcd51da44a1ea94816d1e4bc8e4ea3e7a89 Mon Sep 17 00:00:00 2001 From: "Luciano C. P." Date: Sat, 31 Oct 2026 07:55:51 -0400 Subject: [PATCH 2/2] Reset FM IIR filter states on end of transmission --- FMControl.cpp | 15 ++++++++++++++- FMNetwork.cpp | 19 ++++++++++++++++++- FMNetwork.h | 3 +++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/FMControl.cpp b/FMControl.cpp index 056b76c1..e3bb8d72 100644 --- a/FMControl.cpp +++ b/FMControl.cpp @@ -124,8 +124,16 @@ bool CFMControl::writeModem(const unsigned char* data, unsigned int length) if (m_network == nullptr) return true; - if (data[0U] == TAG_EOT) + if (data[0U] == TAG_EOT) { + // Reset the RX filter states at the end of each transmission so that + // leftover IIR state cannot bleed into the next conversation. + m_deEmphasis->reset(); + m_filterStage1->reset(); + m_filterStage2->reset(); + m_filterStage3->reset(); + return m_network->writeEnd(); + } if (data[0U] != TAG_DATA) return false; @@ -185,6 +193,11 @@ unsigned int CFMControl::readModem(unsigned char* data, unsigned int space) if (m_network == nullptr) return 0U; + // A network end-of-transmission was received, reset the TX pre-emphasis + // filter so that the next conversation starts with clean filter state. + if (m_network->readEnd()) + m_preEmphasis->reset(); + if (space > 240U) // 160 samples 12-bit space = 240U; // 160 samples 12-bit diff --git a/FMNetwork.cpp b/FMNetwork.cpp index d8b4ab80..4c364b90 100644 --- a/FMNetwork.cpp +++ b/FMNetwork.cpp @@ -42,7 +42,8 @@ m_debug(debug), m_enabled(false), m_buffer(2000U, "FM Network"), m_seqNo(0U), -m_timer(1000U, 5U) +m_timer(1000U, 5U), +m_endOfTransmission(false) { assert(!callsign.empty()); assert(gatewayPort > 0U); @@ -215,6 +216,11 @@ void CFMNetwork::clock(unsigned int ms) if (m_debug) CUtils::dump(1U, "FM Network Data Received", buffer, length); + if (::memcmp(buffer, "FME", 3U) == 0) { + m_endOfTransmission = true; + return; + } + if (::memcmp(buffer, "FMD", 3U) != 0) return; @@ -244,9 +250,20 @@ unsigned int CFMNetwork::readData(float* out, unsigned int nOut) return nOut; } +bool CFMNetwork::readEnd() +{ + if (m_endOfTransmission) { + m_endOfTransmission = false; + return true; + } + + return false; +} + void CFMNetwork::reset() { m_buffer.clear(); + m_endOfTransmission = false; } void CFMNetwork::close() diff --git a/FMNetwork.h b/FMNetwork.h index 98c0dad2..776372ec 100644 --- a/FMNetwork.h +++ b/FMNetwork.h @@ -45,6 +45,8 @@ class CFMNetwork { unsigned int readData(float* out, unsigned int nOut); + bool readEnd(); + void reset(); void close(); @@ -61,6 +63,7 @@ class CFMNetwork { CRingBuffer m_buffer; unsigned int m_seqNo; CTimer m_timer; + bool m_endOfTransmission; bool writeStart(); bool writePing();