diff --git a/plugins/channelrx/demodmeshtastic/meshtasticdemod.cpp b/plugins/channelrx/demodmeshtastic/meshtasticdemod.cpp index e54011d6c..52b140f76 100644 --- a/plugins/channelrx/demodmeshtastic/meshtasticdemod.cpp +++ b/plugins/channelrx/demodmeshtastic/meshtasticdemod.cpp @@ -601,6 +601,8 @@ QString MeshtasticDemod::buildMeshtasticJsonPacket( rf["signal_db"] = msg.getSingalDb(); rf["noise_db"] = msg.getNoiseDb(); rf["snr_db"] = msg.getSingalDb() - msg.getNoiseDb(); + // Emit the carrier frequency offset in Hz rounded to two decimal places. + rf["cfoHz"] = std::round(msg.getCfoHz() * 100.0) / 100.0; root["rf"] = rf; // LoRa diff --git a/plugins/channelrx/demodmeshtastic/meshtasticdemoddecoder.cpp b/plugins/channelrx/demodmeshtastic/meshtasticdemoddecoder.cpp index 7b7f858f9..a53c4b93d 100644 --- a/plugins/channelrx/demodmeshtastic/meshtasticdemoddecoder.cpp +++ b/plugins/channelrx/demodmeshtastic/meshtasticdemoddecoder.cpp @@ -362,6 +362,8 @@ bool MeshtasticDemodDecoder::handleMessage(const Message& cmd) outputMsg->setSyncWord(msgSyncWord); outputMsg->setSignalDb(msgSignalDb); outputMsg->setNoiseDb(msgNoiseDb); + // Forward this frame's carrier frequency offset to the decode report. + outputMsg->setCfoHz(msg.getCfoHz()); outputMsg->setMsgTimestamp(msgTimestamp); outputMsg->setPacketSize(getPacketLength()); outputMsg->setNbParityBits(getNbParityBits()); diff --git a/plugins/channelrx/demodmeshtastic/meshtasticdemodmsg.h b/plugins/channelrx/demodmeshtastic/meshtasticdemodmsg.h index 36020fb94..0feba34db 100644 --- a/plugins/channelrx/demodmeshtastic/meshtasticdemodmsg.h +++ b/plugins/channelrx/demodmeshtastic/meshtasticdemodmsg.h @@ -40,6 +40,9 @@ namespace MeshtasticDemodMsg unsigned int getSyncWord() const { return m_syncWord; } float getSingalDb() const { return m_signalDb; } float getNoiseDb() const { return m_noiseDb; } + // Access the carrier frequency offset in Hz carried by this message. + double getCfoHz() const { return m_cfoHz; } + void setCfoHz(double cfoHz) { m_cfoHz = cfoHz; } void pushBackSymbol(unsigned short symbol) { m_symbols.push_back(symbol); @@ -93,6 +96,8 @@ namespace MeshtasticDemodMsg unsigned int m_syncWord; float m_signalDb; float m_noiseDb; + // Initialize the carrier frequency offset in Hz for every new message. + double m_cfoHz = 0.0; MsgDecodeSymbols() : //!< create an empty message Message(), @@ -259,6 +264,9 @@ namespace MeshtasticDemodMsg unsigned int getSyncWord() const { return m_syncWord; } float getSingalDb() const { return m_signalDb; } float getNoiseDb() const { return m_noiseDb; } + // Access the carrier frequency offset in Hz carried by this message. + double getCfoHz() const { return m_cfoHz; } + void setCfoHz(double cfoHz) { m_cfoHz = cfoHz; } const QString& getMsgTimestamp() const { return m_msgTimestamp; } unsigned int getPacketSize() const { return m_packetSize; } unsigned int getNbParityBits() const { return m_nbParityBits; } @@ -338,6 +346,8 @@ namespace MeshtasticDemodMsg unsigned int m_syncWord; float m_signalDb; float m_noiseDb; + // Initialize the carrier frequency offset in Hz for every new message. + double m_cfoHz = 0.0; QString m_msgTimestamp; unsigned int m_packetSize; unsigned int m_nbParityBits; diff --git a/plugins/channelrx/demodmeshtastic/meshtasticdemodsink.cpp b/plugins/channelrx/demodmeshtastic/meshtasticdemodsink.cpp index 8430e8cd1..f2ae65498 100644 --- a/plugins/channelrx/demodmeshtastic/meshtasticdemodsink.cpp +++ b/plugins/channelrx/demodmeshtastic/meshtasticdemodsink.cpp @@ -1019,6 +1019,11 @@ int MeshtasticDemodSink::processLoRaFrameSyncStep() m_loRaCFOInt = static_cast(std::floor((m_loRaDownVal - static_cast(m_nbSymbols)) / 2.0)); } + // Convert the carrier frequency offset (CFO) estimate from FFT bins to Hz. + const double cfoHz = + (static_cast(m_loRaCFOInt) + static_cast(m_loRaCFOFrac)) + * static_cast(m_bandwidth) / static_cast(m_nbSymbols); + // Preserve state-machine net ID bin indices for sync word extraction. // The corrLen-based refinement overwrites m_loRaNetIds but may produce // incorrect results when m_loRaNetIdSamp is not fully populated. @@ -1140,6 +1145,8 @@ int MeshtasticDemodSink::processLoRaFrameSyncStep() m_loRaFrameId++; m_decodeMsg = MeshtasticDemodMsg::MsgDecodeSymbols::create(); m_decodeMsg->setFrameId(m_loRaFrameId); + // Attach the measured carrier frequency offset to this frame. + m_decodeMsg->setCfoHz(cfoHz); { // LoRa sync word is encoded across two net-ID chirps. // First chirp (index 0) carries the high nibble, second (index 1) the low nibble.