summaryrefslogtreecommitdiff
path: root/LiveAudioTestController.hpp
blob: 3f329ef380012d4434db3d0af62ed9bbc20f7094 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// -*- Mode: C++ -*-
#ifndef LIVE_AUDIO_TEST_CONTROLLER_HPP__
#define LIVE_AUDIO_TEST_CONTROLLER_HPP__

#include <QObject>
#include <QSet>
#include <QString>
#include <QStringList>
#include <QTimer>
#include <QTextBlock>
#include <QElapsedTimer>
#include <QByteArray>
#include <QVector>
#include <vector>

class FixtureAudioInput;
class MainWindow;
class QTextEdit;

class LiveAudioTestController final
  : public QObject
{
  Q_OBJECT

public:
  enum class Mode
  {
    Ft8,
    Jtty
  };

  LiveAudioTestController (MainWindow * window, FixtureAudioInput * fixture,
                           QString expectedPath, Mode mode = Mode::Ft8,
                           QObject * parent = nullptr);

  void begin ();
  bool succeeded () const {return m_succeeded;}

private:
  enum class DecoderStage
  {
    None,
    EarlyStandard,
    Multithreaded
  };

  static QSet<QString> readExpectedMessages (QString const& path, QString * error);
  static QStringList readExpectedJttyMessages (QString const& path, QString * error);
  static QString messageFromDecoderLine (QByteArray const& line);
  void prepareWhenReady ();
  void prepareFt8WhenReady ();
  void prepareJttyWhenReady ();
  void maybeFinish ();
  void maybeFinishFt8 ();
  void maybeFinishJtty ();
  void observeJttyDisplay ();
  void pollJttyDisplay ();
  void checkJttyReviewAndStatus ();
  void completeJttyTest ();
  void fail (QString const& reason);
  void checkForUnexpectedModal ();
  void exerciseSubmittedFt8Rollover ();

  MainWindow * m_window;
  FixtureAudioInput * m_fixture;
  QString m_expectedPath;
  Mode m_mode;
  QSet<QString> m_expected;
  QStringList m_expectedJtty;
  QString m_expectedJttyPrefix;
  QSet<QString> m_observed;
  QSet<QString> m_displayed;
  QSet<QString> m_earlyObserved;
  QSet<QString> m_multithreadedObserved;
  QSet<QString> m_earlyRaw;
  QSet<QString> m_multithreadedRaw;
  QString m_initializationError;
  QTimer m_timeout;
  QTimer m_prepareTimer;
  QTimer m_modalTimer;
  QTimer m_jttyPollTimer;
  QTimer m_jttyStageTimer;
  QTextEdit * m_jttyAllDecodes {nullptr};
  QTextEdit * m_jttyQsoFrequency {nullptr};
  qint64 m_emittedFrames {0};
  qint64 m_captureStartMs {0};
  QTextBlock m_jttyAllPrefixBlock, m_jttyQsoPrefixBlock;
  enum class JttyCheckStage { Live, Review, Stopped, Wav, Drain, TimedMode };
  JttyCheckStage m_jttyCheckStage {JttyCheckStage::Live};
  QElapsedTimer m_jttyCheckElapsed;
  QString m_jttyAllBeforeReview, m_jttyQsoBeforeReview;
  QVector<QTextBlock> m_jttyAllLiveBlocks, m_jttyQsoLiveBlocks;
  QString m_jttyLogPath, m_jttySaveDirectory;
  qint64 m_jttyInitialLogSize = 0;
  QByteArray m_jttyLogBeforeReview;
  QSet<QString> m_jttyInitialRecordings;
  int m_completedCycles {0};
  quint64 m_submittedGeneration {0};
  quint64 m_submittedCycle {0};
  quint64 m_rolloverEpoch {0};
  quint64 m_preRolloverEpoch {0};
  int m_rolloverAcceptedEnd {0};
  int m_rolloverAcceptedBlocks {0};
  int m_rolloverRejectedBlocks {0};
  int m_submittedCompletions {0};
  std::vector<short> m_rolloverSamples;
  bool m_rolloverVerified {false};
  DecoderStage m_decoderStage {DecoderStage::None};
  bool m_sawEarlyStandardDecode {false};
  bool m_sawConfiguredMultithreadedDecode {false};
  bool m_completedMultithreadedDecode {false};
  bool m_fixtureFinished {false};
  bool m_armed {false};
  bool m_jttyAllSawPrefix {false};
  bool m_jttyQsoSawPrefix {false};
  QSet<QString> m_jttyAllFinals;
  QSet<QString> m_jttyQsoFinals;
  bool m_finished {false};
  bool m_succeeded {false};
};

#endif