wfview/rigstate.h

140 wiersze
4.8 KiB
C
Czysty Zwykły widok Historia

2021-12-01 10:01:05 +00:00
#ifndef RIGSTATEH
#define RIGSTATEH
2021-11-23 00:39:10 +00:00
#include <QObject>
#include <QMutex>
2021-12-01 10:01:05 +00:00
#include <QDateTime>
#include <QVariant>
#include <QMap>
#include <QCache>
2021-11-23 00:39:10 +00:00
#include "rigcommander.h"
#include "rigidentities.h"
2021-11-23 00:39:10 +00:00
// Meters at the end as they are ALWAYS updated from the rig!
enum stateTypes { VFOAFREQ, VFOBFREQ, CURRENTVFO, PTT, MODE, FILTER, PASSBAND, DUPLEX, DATAMODE, ANTENNA, RXANTENNA, CTCSS, TSQL, DTCS, CSQL,
2022-11-26 19:01:16 +00:00
PREAMP, AGC, ATTENUATOR, MODINPUT, AFGAIN, RFGAIN, SQUELCH, RFPOWER, MICGAIN, COMPLEVEL, MONITORLEVEL, BAL, KEYSPD,
2022-10-31 12:03:04 +00:00
VOXGAIN, ANTIVOXGAIN, CWPITCH, NOTCHF, IF, PBTIN, PBTOUT, APF, NR, NB, NBDEPTH, NBWIDTH, RIGINPUT, POWERONOFF, RITVALUE,
2021-11-23 00:39:10 +00:00
FAGCFUNC, NBFUNC, COMPFUNC, VOXFUNC, TONEFUNC, TSQLFUNC, SBKINFUNC, FBKINFUNC, ANFFUNC, NRFUNC, AIPFUNC, APFFUNC, MONFUNC, MNFUNC,RFFUNC,
2022-10-31 12:03:04 +00:00
AROFUNC, MUTEFUNC, VSCFUNC, REVFUNC, SQLFUNC, ABMFUNC, BCFUNC, MBCFUNC, RITFUNC, AFCFUNC, SATMODEFUNC, SCOPEFUNC,
2022-10-31 12:15:56 +00:00
RESUMEFUNC, TBURSTFUNC, TUNERFUNC, LOCKFUNC, SMETER, POWERMETER, SWRMETER, ALCMETER, COMPMETER, VOLTAGEMETER, CURRENTMETER,
2021-12-01 10:01:05 +00:00
};
2021-11-23 00:39:10 +00:00
2021-12-01 10:01:05 +00:00
struct value {
quint64 _value=0;
bool _valid = false;
bool _updated = false;
QDateTime _dateUpdated;
};
2021-11-23 00:39:10 +00:00
class rigstate
{
public:
2021-12-01 10:01:05 +00:00
void invalidate(stateTypes s) { map[s]._valid = false; }
bool isValid(stateTypes s) { return map[s]._valid; }
bool isUpdated(stateTypes s) { return map[s]._updated; }
QDateTime whenUpdated(stateTypes s) { return map[s]._dateUpdated; }
void set(stateTypes s, quint64 x, bool u) {
if (x != map[s]._value) {
_mutex.lock();
2022-10-31 12:03:04 +00:00
map[s]._value = quint64(x);
2021-12-01 10:01:05 +00:00
map[s]._valid = true;
map[s]._updated = u;
map[s]._dateUpdated = QDateTime::currentDateTime();
_mutex.unlock();
}
}
void set(stateTypes s, qint32 x, bool u) {
2022-10-31 12:03:04 +00:00
if (quint64(x) != map[s]._value) {
2021-12-01 10:01:05 +00:00
_mutex.lock();
2022-10-31 12:03:04 +00:00
map[s]._value = quint64(x);
map[s]._valid = true;
map[s]._updated = u;
map[s]._dateUpdated = QDateTime::currentDateTime();
_mutex.unlock();
}
}
void set(stateTypes s, qint16 x, bool u) {
if (quint64(x) != map[s]._value) {
_mutex.lock();
map[s]._value = quint64(x);
2021-12-01 10:01:05 +00:00
map[s]._valid = true;
map[s]._updated = u;
map[s]._dateUpdated = QDateTime::currentDateTime();
_mutex.unlock();
}
}
void set(stateTypes s, quint16 x, bool u) {
2022-10-31 12:03:04 +00:00
if (quint64(x) != map[s]._value) {
2021-12-01 10:01:05 +00:00
_mutex.lock();
2022-10-31 12:03:04 +00:00
map[s]._value = quint64(x);
2021-12-01 10:01:05 +00:00
map[s]._valid = true;
map[s]._updated = u;
map[s]._dateUpdated = QDateTime::currentDateTime();
_mutex.unlock();
}
}
void set(stateTypes s, quint8 x, bool u) {
2022-10-31 12:03:04 +00:00
if (quint64(x) != map[s]._value) {
2021-12-01 10:01:05 +00:00
_mutex.lock();
2022-10-31 12:03:04 +00:00
map[s]._value = quint64(x);
2021-12-01 10:01:05 +00:00
map[s]._valid = true;
map[s]._updated = u;
map[s]._dateUpdated = QDateTime::currentDateTime();
_mutex.unlock();
}
}
void set(stateTypes s, bool x, bool u) {
2022-10-31 12:03:04 +00:00
if (quint64(x) != map[s]._value) {
2021-12-01 10:01:05 +00:00
_mutex.lock();
2022-10-31 12:03:04 +00:00
map[s]._value = quint64(x);
2021-12-01 10:01:05 +00:00
map[s]._valid = true;
map[s]._updated = u;
map[s]._dateUpdated = QDateTime::currentDateTime();
_mutex.unlock();
}
}
void set(stateTypes s, duplexMode x, bool u) {
2022-10-31 12:03:04 +00:00
if (quint64(x) != map[s]._value) {
2021-12-01 10:01:05 +00:00
_mutex.lock();
2022-10-31 12:03:04 +00:00
map[s]._value = quint64(x);
2021-12-01 10:01:05 +00:00
map[s]._valid = true;
map[s]._updated = u;
map[s]._dateUpdated = QDateTime::currentDateTime();
_mutex.unlock();
}
}
void set(stateTypes s, rigInput x, bool u) {
2022-10-31 12:03:04 +00:00
if (quint64(x) != map[s]._value) {
_mutex.lock();
2022-10-31 12:03:04 +00:00
map[s]._value = quint64(x);
map[s]._valid = true;
map[s]._updated = u;
map[s]._dateUpdated = QDateTime::currentDateTime();
_mutex.unlock();
}
}
2021-12-01 10:01:05 +00:00
bool getBool(stateTypes s) { return map[s]._value != 0; }
2022-10-31 12:03:04 +00:00
quint8 getChar(stateTypes s) { return quint8(map[s]._value); }
qint16 getInt16(stateTypes s) { return qint16(map[s]._value); }
quint16 getUInt16(stateTypes s) { return quint16(map[s]._value); }
qint32 getInt32(stateTypes s) { return qint32(map[s]._value); }
quint32 getUInt32(stateTypes s) { return quint32(map[s]._value); }
2021-12-01 10:01:05 +00:00
quint64 getInt64(stateTypes s) { return map[s]._value; }
2022-10-31 12:03:04 +00:00
duplexMode getDuplex(stateTypes s) { return duplexMode(map[s]._value); }
rigInput getInput(stateTypes s) { return rigInput(map[s]._value); }
2021-12-01 10:01:05 +00:00
QMap<stateTypes, value> map;
2021-11-23 00:39:10 +00:00
private:
2021-12-01 10:01:05 +00:00
//std::map<stateTypes, std::unique_ptr<valueBase> > values;
2021-11-23 00:39:10 +00:00
QMutex _mutex;
};
#endif