2014-03-26 13:21:00 +00:00
|
|
|
#ifndef POLLING_TRANSCEIVER_HPP__
|
|
|
|
|
#define POLLING_TRANSCEIVER_HPP__
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
|
|
#include "TransceiverBase.hpp"
|
|
|
|
|
|
2015-04-26 16:26:54 +00:00
|
|
|
class QTimer;
|
2014-03-26 13:21:00 +00:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Polling Transceiver
|
|
|
|
|
//
|
|
|
|
|
// Helper base class that encapsulates the emulation of continuous
|
|
|
|
|
// update and caching of a transceiver state.
|
|
|
|
|
//
|
|
|
|
|
// Collaborations
|
|
|
|
|
//
|
|
|
|
|
// Implements the TransceiverBase post action interface and provides
|
|
|
|
|
// the abstract poll() operation for sub-classes to implement. The
|
2015-04-26 16:26:54 +00:00
|
|
|
// poll operation is invoked every poll_interval seconds.
|
2014-03-26 13:21:00 +00:00
|
|
|
//
|
|
|
|
|
// Responsibilities
|
|
|
|
|
//
|
|
|
|
|
// Because some rig interfaces don't immediately update after a state
|
|
|
|
|
// change request; this class allows a rig a few polls to stabilise
|
|
|
|
|
// to the requested state before signalling the change. This means
|
|
|
|
|
// that clients don't see intermediate states that are sometimes
|
|
|
|
|
// inaccurate, e.g. changing the split TX frequency on Icom rigs
|
|
|
|
|
// requires a VFO switch and polls while switched will return the
|
|
|
|
|
// wrong current frequency.
|
|
|
|
|
//
|
|
|
|
|
class PollingTransceiver
|
|
|
|
|
: public TransceiverBase
|
|
|
|
|
{
|
2014-04-16 14:59:00 +00:00
|
|
|
Q_OBJECT; // for translation context
|
|
|
|
|
|
2014-03-26 13:21:00 +00:00
|
|
|
protected:
|
2015-04-26 16:26:54 +00:00
|
|
|
explicit PollingTransceiver (int poll_interval); // in seconds
|
2014-03-26 13:21:00 +00:00
|
|
|
|
|
|
|
|
protected:
|
2014-12-06 20:23:29 +00:00
|
|
|
void do_sync (bool force_signal) override final;
|
2014-03-26 13:21:00 +00:00
|
|
|
|
|
|
|
|
// Sub-classes implement this and fetch what they can from the rig
|
|
|
|
|
// in a non-intrusive manner.
|
|
|
|
|
virtual void poll () = 0;
|
|
|
|
|
|
|
|
|
|
void do_post_start () override final;
|
|
|
|
|
void do_post_stop () override final;
|
2014-12-06 20:23:29 +00:00
|
|
|
void do_post_frequency (Frequency, MODE = UNK) override final;
|
|
|
|
|
void do_post_tx_frequency (Frequency, bool rationalize = true) override final;
|
|
|
|
|
void do_post_mode (MODE, bool rationalize = true) override final;
|
2015-01-08 23:51:56 +00:00
|
|
|
void do_post_ptt (bool = true) override final;
|
2014-03-26 13:21:00 +00:00
|
|
|
bool do_pre_update () override final;
|
|
|
|
|
|
|
|
|
|
private:
|
2015-04-26 16:26:54 +00:00
|
|
|
void start_timer ();
|
|
|
|
|
void stop_timer ();
|
|
|
|
|
|
|
|
|
|
Q_SLOT void handle_timeout ();
|
|
|
|
|
|
|
|
|
|
int interval_; // polling interval in milliseconds
|
|
|
|
|
QTimer * poll_timer_;
|
|
|
|
|
|
|
|
|
|
// keep a record of the last state signalled so we can elide
|
|
|
|
|
// duplicate updates
|
|
|
|
|
Transceiver::TransceiverState last_signalled_state_;
|
|
|
|
|
|
|
|
|
|
// keep a record of expected state so we can compare with actual
|
|
|
|
|
// updates to determine when state changes have bubbled through
|
|
|
|
|
Transceiver::TransceiverState next_state_;
|
|
|
|
|
|
|
|
|
|
unsigned retries_; // number of incorrect polls left
|
2014-03-26 13:21:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|