Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion FMControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down
19 changes: 18 additions & 1 deletion FMNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions FMNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class CFMNetwork {

unsigned int readData(float* out, unsigned int nOut);

bool readEnd();

void reset();

void close();
Expand All @@ -61,6 +63,7 @@ class CFMNetwork {
CRingBuffer<unsigned char> m_buffer;
unsigned int m_seqNo;
CTimer m_timer;
bool m_endOfTransmission;

bool writeStart();
bool writePing();
Expand Down
11 changes: 5 additions & 6 deletions MQTTConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -230,4 +230,3 @@ void CMQTTConnection::onDisconnect(mosquitto* mosq, void* obj, int rc)
CMQTTConnection* p = static_cast<CMQTTConnection*>(obj);
p->m_connected = false;
}

2 changes: 1 addition & 1 deletion Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
#if !defined(VERSION_H)
#define VERSION_H

const char* VERSION = "20260713";
const char* VERSION = "20261028";

#endif