From ffc62c792c9a5196cb4ce7a353287dfe20db6524 Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Fri, 9 Oct 2026 14:12:35 +0200 Subject: New upstream version 3.3.0~beta1+dfsg --- JttyDecoder.hpp | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 JttyDecoder.hpp (limited to 'JttyDecoder.hpp') diff --git a/JttyDecoder.hpp b/JttyDecoder.hpp new file mode 100644 index 00000000..f374e463 --- /dev/null +++ b/JttyDecoder.hpp @@ -0,0 +1,116 @@ +#ifndef JTTY_DECODER_HPP +#define JTTY_DECODER_HPP + +#include +#include +#include + +#include +#include + +#include "JttyReceiveTiming.hpp" + +extern "C" { +std::int32_t jtty_rx_create (); +void jtty_rx_destroy (std::int32_t handle); +void jtty_rx_begin (std::int32_t handle, std::int64_t sessionId, + std::int64_t gridOrigin, std::int64_t firstSearch, + std::int32_t samplesPerSymbol); +std::int32_t jtty_rx_process (std::int32_t handle, std::int16_t const * samples, + std::int32_t count, std::int64_t firstSample, + std::int64_t stopSample, std::int32_t maxSteps, + std::int32_t lowFrequency, std::int32_t highFrequency, + float centerFrequency, float tolerance); +std::int64_t jtty_rx_next_required_sample (std::int32_t handle); +std::int64_t jtty_rx_next_search_sample (std::int32_t handle); +std::int32_t jtty_rx_take_updates (std::int32_t handle, std::int32_t capacity, + char * text, std::int64_t * ids, float * frequencies, + double * starts, double * latest, std::int32_t * terminals, + std::int32_t * snrs); +void jtty_rx_end (std::int32_t handle, std::int32_t reason); +} + +namespace Jtty { + +enum class ReceiveTerminal : std::int32_t +{ + Growing = 0, + Complete = 1, + Expired = 2, + ReceptionEnded = 3 +}; + +struct ReceiveUpdate +{ + qint64 messageId {}; + float frequency {}; + QString text; + double startSeconds {}; + double latestSeconds {}; + ReceiveTerminal terminal {ReceiveTerminal::Growing}; + int snr {-10}; +}; + +// Contexts share DSP scratch and must be called from one serialized decoder owner. +class Decoder +{ +public: + Decoder () : handle_ {jtty_rx_create ()} {} + ~Decoder () { if (handle_) jtty_rx_destroy (handle_); } + Decoder (Decoder const&) = delete; + Decoder& operator= (Decoder const&) = delete; + + bool valid () const { return handle_ != 0; } + + void begin (qint64 sessionId, qint64 gridOrigin, qint64 firstSearch, + int samplesPerSymbol = receiveSamplesPerSymbol) + { + jtty_rx_begin (handle_, sessionId, gridOrigin, firstSearch, samplesPerSymbol); + } + + int process (qint16 const * samples, int count, qint64 firstSample, + qint64 stopSample, int maxSteps, int lowFrequency, + int highFrequency, float centerFrequency, float tolerance) + { + return jtty_rx_process (handle_, samples, count, firstSample, stopSample, + maxSteps, lowFrequency, highFrequency, centerFrequency, tolerance); + } + + qint64 nextRequiredSample () const { return jtty_rx_next_required_sample (handle_); } + qint64 nextSearchSample () const { return jtty_rx_next_search_sample (handle_); } + + QVector takeUpdates () + { + constexpr int capacity = 30; + std::array text; + std::array ids; + std::array frequencies; + std::array starts, latest; + std::array terminals; + std::array snrs; + QVector result; + for (;;) { + auto const count = jtty_rx_take_updates (handle_, capacity, text.data (), ids.data (), + frequencies.data (), starts.data (), latest.data (), + terminals.data (), snrs.data ()); + for (int i = 0; i < count; ++i) { + result.push_back ({ids[i], frequencies[i], QString::fromLatin1 (text.data () + i * 80, 80).trimmed (), + starts[i], latest[i], static_cast (terminals[i]), snrs[i]}); + } + if (count < capacity) break; + } + return result; + } + + void end (ReceiveTerminal reason = ReceiveTerminal::ReceptionEnded) + { + jtty_rx_end (handle_, static_cast (reason)); + } + +private: + std::int32_t handle_ {}; +}; + +} + +#endif -- cgit v1.2.3