JS8Call-Improved master
Loading...
Searching...
No Matches
PollingTransceiver.h
1#ifndef POLLING_TRANSCEIVER_HPP__
2#define POLLING_TRANSCEIVER_HPP__
3
4#include "TransceiverBase.h"
5
6#include <QObject>
7
8class QTimer;
9
10//
11// Polling Transceiver
12//
13// Helper base class that encapsulates the emulation of continuous
14// update and caching of a transceiver state.
15//
16// Collaborations
17//
18// Implements the TransceiverBase post action interface and provides
19// the abstract poll() operation for sub-classes to implement. The
20// poll operation is invoked every poll_interval seconds.
21//
22// Responsibilities
23//
24// Because some rig interfaces don't immediately update after a state
25// change request; this class allows a rig a few polls to stabilise
26// to the requested state before signalling the change. This means
27// that clients don't see intermediate states that are sometimes
28// inaccurate, e.g. changing the split TX frequency on Icom rigs
29// requires a VFO switch and polls while switched will return the
30// wrong current frequency.
31//
32class PollingTransceiver : public TransceiverBase {
33 Q_OBJECT; // for translation context
34
35 protected:
36 explicit PollingTransceiver(int poll_interval, // in seconds
37 QObject *parent);
38
39 protected:
40 void do_sync(bool force_signal = false,
41 bool no_poll = false) override final;
42
43 // Sub-classes implement this and fetch what they can from the rig
44 // in a non-intrusive manner.
45 virtual void poll() = 0;
46
47 void do_post_start() override final;
48 void do_post_stop() override final;
49 void do_post_frequency(Frequency, MODE) override final;
50 void do_post_tx_frequency(Frequency, MODE) override final;
51 void do_post_mode(MODE) override final;
52 void do_post_ptt(bool = true) override final;
53 bool do_pre_update() override final;
54
55 private:
56 void start_timer();
57 void stop_timer();
58
59 Q_SLOT void handle_timeout();
60
61 int interval_; // polling interval in milliseconds
62 QTimer *poll_timer_;
63
64 // keep a record of the last state signalled so we can elide
65 // duplicate updates
66 Transceiver::TransceiverState last_signalled_state_;
67
68 // keep a record of expected state so we can compare with actual
69 // updates to determine when state changes have bubbled through
71
72 unsigned retries_; // number of incorrect polls left
73};
74
75#endif
Definition Transceiver.h:83