JS8Call-Improved master
Loading...
Searching...
No Matches
JS8.h
Go to the documentation of this file.
1
8
9#ifndef __JS8
10#define __JS8
11
12#include <QObject>
13#include <QSemaphore>
14#include <QThread>
15#include "optional_work.h"
16#include <array>
17#include <chrono>
18#include <functional>
19#include <string>
20#include <variant>
21
22namespace JS8 {
23Q_NAMESPACE
24
25namespace Costas {
33enum class Type { ORIGINAL, MODIFIED };
34
36using Array = std::array<std::array<int, 7>, 3>;
37
43constexpr auto array = [] {
44 constexpr auto COSTAS =
45 std::array{std::array{std::array{4, 2, 5, 6, 1, 3, 0},
46 std::array{4, 2, 5, 6, 1, 3, 0},
47 std::array{4, 2, 5, 6, 1, 3, 0}},
48 std::array{std::array{0, 6, 2, 3, 5, 4, 1},
49 std::array{1, 5, 0, 2, 3, 6, 4},
50 std::array{2, 5, 0, 6, 4, 1, 3}}};
51
52 return [COSTAS](Type type) -> Array const & {
53 return COSTAS[static_cast<std::underlying_type_t<Type>>(type)];
54 };
55}();
56} // namespace Costas
57
65void encode(int type, Costas::Array const &costas, const char *message,
66 int *tones);
67
68namespace Event {
74};
75
77struct SyncStart {
79 int size;
80};
81
88struct SyncState {
89 enum class Type { CANDIDATE, DECODED } type;
90 int mode;
91 float frequency;
92 float dt;
93 union {
95 float decoded;
96 } sync;
97};
98
104struct Decoded {
105 int utc;
106 int snr;
107 float xdt;
108 float frequency;
109 std::string data;
110 int type;
111 float quality;
112 int mode;
113};
114
117 std::size_t decoded;
118};
119
121using Variant =
122 std::variant<DecodeStarted, SyncStart, SyncState, Decoded, DecodeFinished>;
123
125using Emitter = std::function<void(Variant const &)>;
126} // namespace Event
127
135class Worker;
136
145class Decoder : public QObject {
146 Q_OBJECT
147
148 QSemaphore m_semaphore;
149 QThread m_thread;
150 js8::OptionalWorkSignal m_optionalPressure;
151 Worker *m_worker;
152
153 public:
155 Decoder(QObject *parent = nullptr);
156
158 void pendingDecode(bool pending) noexcept;
159 void nextDecodeReady(std::chrono::steady_clock::time_point when) noexcept;
160
161 signals:
162
165
166 public slots:
167
169 void start(QThread::Priority priority);
170
172 void quit();
173
175 void decode();
176};
177} // namespace JS8
178
179#endif
std::function< void(Variant const &)> Emitter
Definition JS8.h:125
std::array< std::array< int, 7 >, 3 > Array
Definition JS8.h:36
Type
Costas array helpers used to map symbols to tones.
Definition JS8.h:33
constexpr auto array
Return the Costas array for the requested Type.
Definition JS8.h:43
std::variant< DecodeStarted, SyncStart, SyncState, Decoded, DecodeFinished > Variant
Definition JS8.h:121
void quit()
Definition JS8.cpp:4107
void pendingDecode(bool pending) noexcept
Definition JS8.cpp:4119
void start(QThread::Priority priority)
Definition JS8.cpp:4103
Decoder(QObject *parent=nullptr)
Definition JS8.cpp:4093
void decodeEvent(Event::Variant const &)
void decode()
Definition JS8.cpp:4114
Definition JS8.cpp:3885
Definition optional_work.h:15
Hardware-independent pressure signal for optional JS8 decode work.
Definition JS8.h:116
std::size_t decoded
Number of decoded frames.
Definition JS8.h:117
Emitted when the decode process starts with the configured submodes.
Definition JS8.h:72
int submodes
Number of submodes active for decoding.
Definition JS8.h:73
Decoded frame payload emitted when a frame is successfully decoded.
Definition JS8.h:104
float xdt
Fine timing offset.
Definition JS8.h:107
float frequency
Frequency estimate in Hz.
Definition JS8.h:108
std::string data
Decoded payload string.
Definition JS8.h:109
int mode
Submode index used for decoding.
Definition JS8.h:112
int snr
Signal-to-noise ratio (dB).
Definition JS8.h:106
int utc
Raw UTC timestamp from decoder.
Definition JS8.h:105
int type
Frame type identifier.
Definition JS8.h:110
float quality
Quality metric.
Definition JS8.h:111
Indicate start of a sync window.
Definition JS8.h:77
int position
Byte/bit position of the sync candidate.
Definition JS8.h:78
int size
Size of the sync window.
Definition JS8.h:79
Sync state update emitted during candidate evaluation.
Definition JS8.h:88
float decoded
Decoded metric when Type::DECODED.
Definition JS8.h:95
float dt
Timing offset (s).
Definition JS8.h:92
int candidate
Candidate index when Type::CANDIDATE.
Definition JS8.h:94
int mode
Submode index.
Definition JS8.h:90
float frequency
Frequency estimate (Hz).
Definition JS8.h:91