Convert rigState to use shared pointers

half-duplex
Phil Taylor 2023-01-27 19:47:07 +00:00
rodzic 6759625c37
commit edf9f36bf1
6 zmienionych plików z 69 dodań i 35 usunięć

Wyświetl plik

@ -4789,7 +4789,7 @@ void rigCommander::stateUpdated()
{
i.value()._updated = false;
i.value()._valid = true; // Set value to valid as we have requested it (even if we haven't had a response)
qDebug(logRigCtlD()) << "Got new value:" << i.key() << "=" << i.value()._value;
//qDebug(logRigCtlD()) << "Got new value:" << i.key() << "=" << i.value()._value;
switch (i.key()) {
case VFOAFREQ:
if (i.value()._valid) {

Wyświetl plik

@ -10,21 +10,16 @@
#include "rigcommander.h"
#include "rigidentities.h"
#include "wfviewtypes.h"
// 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,
PREAMP, AGC, ATTENUATOR, MODINPUT, AFGAIN, RFGAIN, SQUELCH, RFPOWER, MICGAIN, COMPLEVEL, MONITORLEVEL, BAL, KEYSPD,
VOXGAIN, ANTIVOXGAIN, CWPITCH, NOTCHF, IF, PBTIN, PBTOUT, APF, NR, NB, NBDEPTH, NBWIDTH, RIGINPUT, POWERONOFF, RITVALUE,
FAGCFUNC, NBFUNC, COMPFUNC, VOXFUNC, TONEFUNC, TSQLFUNC, SBKINFUNC, FBKINFUNC, ANFFUNC, NRFUNC, AIPFUNC, APFFUNC, MONFUNC, MNFUNC,RFFUNC,
AROFUNC, MUTEFUNC, VSCFUNC, REVFUNC, SQLFUNC, ABMFUNC, BCFUNC, MBCFUNC, RITFUNC, AFCFUNC, SATMODEFUNC, SCOPEFUNC,
RESUMEFUNC, TBURSTFUNC, TUNERFUNC, LOCKFUNC, SMETER, POWERMETER, SWRMETER, ALCMETER, COMPMETER, VOLTAGEMETER, CURRENTMETER,
};
//* std::static_pointer_cast<unsigned char>(data)
struct value {
quint64 _value=0;
bool _valid = false;
bool _updated = false;
QDateTime _dateUpdated;
std::shared_ptr<void> _value = Q_NULLPTR;
};
class rigstate
@ -38,9 +33,10 @@ public:
QDateTime whenUpdated(stateTypes s) { return map[s]._dateUpdated; }
void set(stateTypes s, quint64 x, bool u) {
if (x != map[s]._value) {
auto d = (std::static_pointer_cast<quint64>(map[s]._value));
if (d == Q_NULLPTR || *d != x) {
_mutex.lock();
map[s]._value = quint64(x);
map[s]._value = std::shared_ptr<quint64>(new quint64(x));
map[s]._valid = true;
map[s]._updated = u;
map[s]._dateUpdated = QDateTime::currentDateTime();
@ -48,9 +44,10 @@ public:
}
}
void set(stateTypes s, qint32 x, bool u) {
if (quint64(x) != map[s]._value) {
auto d = (std::static_pointer_cast<quint32>(map[s]._value));
if (d == Q_NULLPTR || *d != x) {
_mutex.lock();
map[s]._value = quint64(x);
map[s]._value = std::shared_ptr<qint32>(new qint32(x));
map[s]._valid = true;
map[s]._updated = u;
map[s]._dateUpdated = QDateTime::currentDateTime();
@ -58,9 +55,10 @@ public:
}
}
void set(stateTypes s, qint16 x, bool u) {
if (quint64(x) != map[s]._value) {
auto d = (std::static_pointer_cast<qint16>(map[s]._value));
if (d == Q_NULLPTR || *d != x) {
_mutex.lock();
map[s]._value = quint64(x);
map[s]._value = std::shared_ptr<qint16>(new qint16(x));
map[s]._valid = true;
map[s]._updated = u;
map[s]._dateUpdated = QDateTime::currentDateTime();
@ -68,9 +66,10 @@ public:
}
}
void set(stateTypes s, quint16 x, bool u) {
if (quint64(x) != map[s]._value) {
auto d = (std::static_pointer_cast<quint16>(map[s]._value));
if (d == Q_NULLPTR || *d != x) {
_mutex.lock();
map[s]._value = quint64(x);
map[s]._value = std::shared_ptr<quint16>(new quint16(x));
map[s]._valid = true;
map[s]._updated = u;
map[s]._dateUpdated = QDateTime::currentDateTime();
@ -78,9 +77,10 @@ public:
}
}
void set(stateTypes s, quint8 x, bool u) {
if (quint64(x) != map[s]._value) {
auto d = (std::static_pointer_cast<quint8>(map[s]._value));
if (d == Q_NULLPTR || *d != x) {
_mutex.lock();
map[s]._value = quint64(x);
map[s]._value = std::shared_ptr<quint8>(new quint8(x));
map[s]._valid = true;
map[s]._updated = u;
map[s]._dateUpdated = QDateTime::currentDateTime();
@ -88,9 +88,10 @@ public:
}
}
void set(stateTypes s, bool x, bool u) {
if (quint64(x) != map[s]._value) {
auto d = std::static_pointer_cast<bool>(map[s]._value);
if (d == Q_NULLPTR || *d != x) {
_mutex.lock();
map[s]._value = quint64(x);
map[s]._value = std::shared_ptr<bool>(new bool(x));
map[s]._valid = true;
map[s]._updated = u;
map[s]._dateUpdated = QDateTime::currentDateTime();
@ -98,9 +99,10 @@ public:
}
}
void set(stateTypes s, duplexMode x, bool u) {
if (quint64(x) != map[s]._value) {
auto d = (std::static_pointer_cast<duplexMode>(map[s]._value));
if (d == Q_NULLPTR || *d != x) {
_mutex.lock();
map[s]._value = quint64(x);
map[s]._value = std::shared_ptr<duplexMode>(new duplexMode(x));
map[s]._valid = true;
map[s]._updated = u;
map[s]._dateUpdated = QDateTime::currentDateTime();
@ -109,9 +111,10 @@ public:
}
void set(stateTypes s, rigInput x, bool u) {
if (quint64(x) != map[s]._value) {
auto d = (std::static_pointer_cast<rigInput>(map[s]._value));
if (d == Q_NULLPTR || *d != x) {
_mutex.lock();
map[s]._value = quint64(x);
map[s]._value = std::shared_ptr<rigInput>(new rigInput(x));
map[s]._valid = true;
map[s]._updated = u;
map[s]._dateUpdated = QDateTime::currentDateTime();
@ -119,15 +122,28 @@ public:
}
}
bool getBool(stateTypes s) { return map[s]._value != 0; }
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); }
quint64 getInt64(stateTypes s) { return map[s]._value; }
duplexMode getDuplex(stateTypes s) { return duplexMode(map[s]._value); }
rigInput getInput(stateTypes s) { return rigInput(map[s]._value); }
void set(stateTypes s, QString x, bool u) {
auto d = (std::static_pointer_cast<QString>(map[s]._value));
if (d == Q_NULLPTR || *d != x) {
_mutex.lock();
map[s]._value = std::shared_ptr<QString>(new QString(x));
map[s]._valid = true;
map[s]._updated = u;
map[s]._dateUpdated = QDateTime::currentDateTime();
_mutex.unlock();
}
}
bool getBool(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<bool>(map[s]._value); else return false; }
quint8 getChar(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<quint8>(map[s]._value); else return 0; }
qint16 getInt16(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<qint16>(map[s]._value); else return 0;}
quint16 getUInt16(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<quint16>(map[s]._value); else return 0;}
qint32 getInt32(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<qint32>(map[s]._value); else return 0;}
quint32 getUInt32(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<quint32>(map[s]._value); else return 0;}
quint64 getInt64(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<qint64>(map[s]._value); else return 0;}
duplexMode getDuplex(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<duplexMode>(map[s]._value); else return dmSplitOff;}
rigInput getInput(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<rigInput>(map[s]._value); else return inputACC; }
QString getString(stateTypes s) { if (map[s]._value != Q_NULLPTR) return *std::static_pointer_cast<QString>(map[s]._value); else return QString(""); }
QMap<stateTypes, value> map;

Wyświetl plik

@ -2046,7 +2046,9 @@ void wfmain::loadSettings()
udpPrefs.clientName = settings->value("ClientName", udpDefPrefs.clientName).toString();
udpPrefs.halfDuplex = settings->value("HalfDuplex", udpDefPrefs.halfDuplex).toBool();
ui->audioDuplexCombo->blockSignals(true);
ui->audioDuplexCombo->setCurrentIndex((int)udpPrefs.halfDuplex);
ui->audioDuplexCombo->blockSignals(false);
settings->endGroup();
@ -8856,3 +8858,4 @@ void wfmain::on_cwButton_clicked()
cw->raise();
cw->activateWindow();
}

Wyświetl plik

@ -451,6 +451,7 @@ cmd /c copy /y ..\portaudio\msvc\Win32\Debug\portaudio_x86.dll wfview-debug</Com
<QtMoc Include="cwsender.h" />
<ClInclude Include="prefs.h" />
<ClInclude Include="printhex.h" />
<ClInclude Include="rigstate.h" />
<ClInclude Include="sidebandchooser.h" />
<ClInclude Include="wfviewtypes.h" />
<QtMoc Include="usbcontroller.h" />

Wyświetl plik

@ -286,6 +286,9 @@
<ClInclude Include="prefs.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="rigstate.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="debug\moc_predefs.h.cbt">

Wyświetl plik

@ -116,6 +116,17 @@ enum cmds {
cmdSetTime, cmdSetDate, cmdSetUTCOffset
};
// 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,
PREAMP, AGC, ATTENUATOR, MODINPUT, AFGAIN, RFGAIN, SQUELCH, RFPOWER, MICGAIN, COMPLEVEL, MONITORLEVEL, BAL, KEYSPD,
VOXGAIN, ANTIVOXGAIN, CWPITCH, NOTCHF, IF, PBTIN, PBTOUT, APF, NR, NB, NBDEPTH, NBWIDTH, RIGINPUT, POWERONOFF, RITVALUE,
FAGCFUNC, NBFUNC, COMPFUNC, VOXFUNC, TONEFUNC, TSQLFUNC, SBKINFUNC, FBKINFUNC, ANFFUNC, NRFUNC, AIPFUNC, APFFUNC, MONFUNC, MNFUNC, RFFUNC,
AROFUNC, MUTEFUNC, VSCFUNC, REVFUNC, SQLFUNC, ABMFUNC, BCFUNC, MBCFUNC, RITFUNC, AFCFUNC, SATMODEFUNC, SCOPEFUNC,
RESUMEFUNC, TBURSTFUNC, TUNERFUNC, LOCKFUNC, SMETER, POWERMETER, SWRMETER, ALCMETER, COMPMETER, VOLTAGEMETER, CURRENTMETER,
};
struct commandtype {
cmds cmd;
std::shared_ptr<void> data;