From 36b10d41001e6cce7d8c6208524a2473adb96335 Mon Sep 17 00:00:00 2001 From: Elliott Liggett Date: Fri, 16 Nov 2018 22:19:44 -0800 Subject: [PATCH] Added AF and RF (RX) gain and ATU basics --- commhandler.cpp | 5 +- rigcommander.cpp | 45 ++++++++++++++- rigcommander.h | 8 +++ wfmain.cpp | 53 ++++++++++++++++- wfmain.h | 21 ++++++- wfmain.ui | 144 ++++++++++++++++++++++++++++++++++++++++++++++- wfview.pro | 5 ++ 7 files changed, 273 insertions(+), 8 deletions(-) diff --git a/commhandler.cpp b/commhandler.cpp index 10de354..6802066 100644 --- a/commhandler.cpp +++ b/commhandler.cpp @@ -77,11 +77,12 @@ void commHandler::sendDataOut(const QByteArray &writeData) { mutex.lock(); - quint64 bytesWritten; + // quint64 bytesWritten; // sned out data //port.send() or whatever - bytesWritten = port->write(writeData); + // bytesWritten = port->write(writeData); + port->write(writeData); //qDebug() << "bytesWritten: " << bytesWritten << " length of byte array: " << writeData.length() << " size of byte array: " << writeData.size(); diff --git a/rigcommander.cpp b/rigcommander.cpp index 1dde624..6d9ab2d 100644 --- a/rigcommander.cpp +++ b/rigcommander.cpp @@ -513,7 +513,7 @@ void rigCommander::parseLevels() qDebug() << "Received a level status readout: "; // printHex(payloadIn, false, true); - char level = (payloadIn[2] * 100) + payloadIn[03]; + unsigned char level = (payloadIn[2] * 100) + payloadIn[03]; qDebug() << "Level is: " << (int)level << " or " << 100.0*level/255.0 << "%"; // Typical RF gain response (rather low setting): @@ -524,15 +524,18 @@ void rigCommander::parseLevels() { case '\x01': // AF level + emit haveAfGain(level); break; case '\x02': // RX RF Gain + emit haveRfGain(level); break; case '\x03': // Squelch level break; case '\x0A': // TX RF level + emit haveTxPower(level); break; } } @@ -543,6 +546,40 @@ void rigCommander::getRfGain() prepDataAndSend(payload); } +void rigCommander::getAfGain() +{ + QByteArray payload("\x14\x01"); + prepDataAndSend(payload); +} + +void rigCommander::setRfGain(unsigned char level) +{ + sendLevelCmd(0x02, level); +} + +void rigCommander::setAfGain(unsigned char level) +{ + sendLevelCmd(0x01, level); +} + +void rigCommander::sendLevelCmd(unsigned char levAddr, unsigned char level) +{ + QByteArray payload("\x14"); + payload.append(levAddr); + // careful here. The value in the units and tens can't exceed 99. + // ie, can't do this: 01 f2 + payload.append((int)level/100); // make sure it works with a zero + // convert the tens: + int tens = (level - 100*((int)level/100))/10; + // convert the units: + int units = level - 100*((int)level/100); + units = units - 10*((int)(units/10)); + // combine and send: + payload.append((tens << 4) | (units) ); // make sure it works with a zero + + prepDataAndSend(payload); +} + void rigCommander::parseRegisters1C() { // PTT lives here @@ -841,6 +878,12 @@ void rigCommander::parseMode() } +void rigCommander::startATU() +{ + QByteArray payload("\x1C\x01\x02"); + prepDataAndSend(payload); +} + QByteArray rigCommander::stripData(const QByteArray &data, unsigned char cutPosition) { QByteArray rtndata; diff --git a/rigcommander.h b/rigcommander.h index a2aafd9..5514690 100644 --- a/rigcommander.h +++ b/rigcommander.h @@ -42,6 +42,10 @@ public slots: void setDataMode(bool dataOn); void getDataMode(); void getRfGain(); + void getAfGain(); + void setRfGain(unsigned char level); + void setAfGain(unsigned char level); + void startATU(); void setCIVAddr(unsigned char civAddr); void handleNewData(const QByteArray &data); void getDebug(); @@ -53,6 +57,9 @@ signals: void haveDataMode(bool dataModeEnabled); void haveBandStackReg(float freq, char mode, bool dataOn); void haveSpectrumBounds(); + void haveRfGain(unsigned char level); + void haveAfGain(unsigned char level); + void haveTxPower(unsigned char level); void dataForComm(const QByteArray &outData); void getMoreDebug(); void finished(); @@ -75,6 +82,7 @@ private: void parseRegisters1C(); void parsePTT(); void parseLevels(); // register 0x14 + void sendLevelCmd(unsigned char levAddr, unsigned char level); void sendDataOut(); void prepDataAndSend(QByteArray data); void debugMe(); diff --git a/wfmain.cpp b/wfmain.cpp index af6a25e..0f735e0 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -80,6 +80,12 @@ wfmain::wfmain(QWidget *parent) : connect(this, SIGNAL(setScopeSpan(char)), rig, SLOT(setScopeSpan(char))); connect(this, SIGNAL(setMode(char)), rig, SLOT(setMode(char))); connect(this, SIGNAL(getRfGain()), rig, SLOT(getRfGain())); + connect(this, SIGNAL(getAfGain()), rig, SLOT(getAfGain())); + connect(this, SIGNAL(setRfGain(unsigned char)), rig, SLOT(setRfGain(unsigned char))); + connect(this, SIGNAL(setAfGain(unsigned char)), rig, SLOT(setAfGain(unsigned char))); + connect(rig, SIGNAL(haveRfGain(unsigned char)), this, SLOT(receiveRfGain(unsigned char))); + connect(rig, SIGNAL(haveAfGain(unsigned char)), this, SLOT(receiveAfGain(unsigned char))); + connect(this, SIGNAL(startATU()), rig, SLOT(startATU())); // Plot user interaction connect(plot, SIGNAL(mouseDoubleClick(QMouseEvent*)), this, SLOT(handlePlotDoubleClick(QMouseEvent*))); @@ -133,7 +139,7 @@ wfmain::wfmain(QWidget *parent) : getInitialRigState(); oldFreqDialVal = ui->freqDial->value(); - + //tracer->visible(); } wfmain::~wfmain() @@ -157,6 +163,9 @@ void wfmain::getInitialRigState() cmdOutQue.append(cmdGetFreq); cmdOutQue.append(cmdGetMode); + cmdOutQue.append(cmdGetRxGain); + cmdOutQue.append(cmdGetAfGain); + cmdOut = cmdNone; delayedCommand->start(); } @@ -300,6 +309,12 @@ void wfmain::runDelayedCommand() case cmdSpecOff: emit spectOutputDisable(); break; + case cmdGetRxGain: + emit getRfGain(); + break; + case cmdGetAfGain: + emit getAfGain(); + break; default: break; } @@ -940,7 +955,7 @@ void wfmain::on_aboutBtn_clicked() QString copyright = QString("Copyright 2017, 2018 Elliott H. Liggett. All rights reserved."); QString ssCredit = QString("Stylesheet qdarkstyle used under MIT license, stored in application directory."); QString contact = QString("email the author: kilocharlie8@gmail.com or W6EL on the air!"); - QString buildInfo = QString("Build XXXX on YYYY-MM-DD at HH:MM by user UUUU"); + QString buildInfo = QString("Build " + QString(GITSHORT) + " on " + QString(__DATE__) + " at " + __TIME__ + " by " + UNAME + "@" + HOST); QString aboutText = copyright + "\n" + ssCredit + "\n"; aboutText.append(contact + "\n" + buildInfo); @@ -977,3 +992,37 @@ void wfmain::on_fRclBtn_clicked() // add delayed command for mode and data mode } + +void wfmain::on_rfGainSlider_valueChanged(int value) +{ + emit setRfGain((unsigned char) value); +} + +void wfmain::on_afGainSlider_valueChanged(int value) +{ + emit setAfGain((unsigned char) value); +} + +void wfmain::receiveRfGain(unsigned char level) +{ + qDebug() << "Setting RF Gain value to " << (int)level; + ui->rfGainSlider->setValue(level); +} + +void wfmain::receiveAfGain(unsigned char level) +{ + qDebug() << "Setting AF Gain value to " << (int)level; + ui->afGainSlider->setValue(level); +} + +void wfmain::on_drawTracerChk_toggled(bool checked) +{ + tracer->setVisible(checked); +} + +void wfmain::on_tuneNowBtn_clicked() +{ + emit startATU(); + showStatusBarText("Starting ATU cycle..."); + +} diff --git a/wfmain.h b/wfmain.h index 8059973..2519b55 100644 --- a/wfmain.h +++ b/wfmain.h @@ -36,7 +36,11 @@ signals: void setPTT(bool pttOn); void getBandStackReg(char band, char regCode); void getRfGain(); + void getAfGain(); void getDebug(); + void setRfGain(unsigned char level); + void setAfGain(unsigned char level); + void startATU(); void spectOutputEnable(); void spectOutputDisable(); void scopeDisplayEnable(); @@ -53,6 +57,9 @@ private slots: void receivePTTstatus(bool pttOn); void receiveDataModeStatus(bool dataOn); void receiveBandStackReg(float freq, char mode, bool dataOn); // freq, mode, (filter,) datamode + void receiveRfGain(unsigned char level); + void receiveAfGain(unsigned char level); + void handlePlotClick(QMouseEvent *); void handlePlotDoubleClick(QMouseEvent *); void handleWFClick(QMouseEvent *); @@ -141,6 +148,18 @@ private slots: void on_aboutQtBtn_clicked(); + void on_fStoBtn_clicked(); + + void on_fRclBtn_clicked(); + + void on_rfGainSlider_valueChanged(int value); + + void on_afGainSlider_valueChanged(int value); + + void on_drawTracerChk_toggled(bool checked); + + void on_tuneNowBtn_clicked(); + private: Ui::wfmain *ui; QCustomPlot *plot; // line plot @@ -184,7 +203,7 @@ private: double freqMhz; double knobFreqMhz; enum cmds {cmdNone, cmdGetFreq, cmdGetMode, cmdGetDataMode, cmdSetDataModeOn, cmdSetDataModeOff, - cmdSpecOn, cmdSpecOff, cmdDispEnable, cmdDispDisable}; + cmdSpecOn, cmdSpecOff, cmdDispEnable, cmdDispDisable, cmdGetRxGain, cmdGetAfGain}; cmds cmdOut; QVector cmdOutQue; int oldFreqDialVal; diff --git a/wfmain.ui b/wfmain.ui index 32b7d59..5539c56 100644 --- a/wfmain.ui +++ b/wfmain.ui @@ -18,7 +18,7 @@ - 1 + 3 @@ -199,6 +199,44 @@ + + + + + 16777215 + 60 + + + + RX RF Gain + + + 255 + + + Qt::Vertical + + + + + + + + 16777215 + 60 + + + + RX AF Gain + + + 255 + + + Qt::Vertical + + + @@ -653,7 +691,7 @@ - + 0 @@ -1004,6 +1042,16 @@ + + + + Tracer + + + true + + + @@ -1099,6 +1147,9 @@ When tuning, set lower digits to zero + + true + @@ -1150,6 +1201,47 @@ + + + + + 0 + 30 + + + + + 60 + 60 + + + + TX Power + + + 255 + + + Qt::Vertical + + + + + + + + 16777215 + 60 + + + + Mic Gain + + + Qt::Vertical + + + @@ -1165,6 +1257,54 @@ + + + + 20 + + + + + Enable ATU + + + + + + + Tune Now + + + + + + + ATU Status: + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + diff --git a/wfview.pro b/wfview.pro index 77e09a5..06d17c0 100644 --- a/wfview.pro +++ b/wfview.pro @@ -20,6 +20,11 @@ QMAKE_CXXFLAGS += -march=native DEFINES += QT_DEPRECATED_WARNINGS DEFINES += QCUSTOMPLOT_COMPILE_LIBRARY +DEFINES += HOST=\\\"`hostname`\\\" UNAME=\\\"`whoami`\\\" + +DEFINES += GITSHORT="\\\"$(shell git -C $$PWD rev-parse --short HEAD)\\\"" + + RESOURCES += qdarkstyle/style.qrc