Added pseudo-terminal capability. TODO: Make sure wfview will parse 0xE0

data.
merge-requests/1/merge
Elliott Liggett 2019-01-09 22:44:48 -08:00
rodzic 815f8965f0
commit f30d300fe6
4 zmienionych plików z 215 dodań i 213 usunięć

Wyświetl plik

@ -24,8 +24,10 @@ commHandler::commHandler()
//port->setReadBufferSize(1024); // manually. 256 never saw any return from the radio. why...
//qDebug() << "Serial buffer size: " << port->readBufferSize();
initializePt();
connect(port, SIGNAL(readyRead()), this, SLOT(receiveDataIn()));
connect(pseudoterm, SIGNAL(readyRead()), this, SLOT(receiveDataInPt()));
}
commHandler::commHandler(QString portName)
@ -51,9 +53,61 @@ commHandler::commHandler(QString portName)
//qDebug() << "Serial buffer size: " << port->readBufferSize();
initializePt();
connect(port, SIGNAL(readyRead()), this, SLOT(receiveDataIn()));
connect(pseudoterm, SIGNAL(readyRead()), this, SLOT(receiveDataInPt()));
}
void commHandler::initializePt()
{
qDebug() << "init pt";
pseudoterm = new QSerialPort();
setupPtComm();
openPtPort();
}
void commHandler::setupPtComm()
{
qDebug() << "Setting up pt";
pseudoterm->setPortName("/dev/ptmx");
// pseudoterm->setBaudRate(baudrate);
// pseudoterm->setStopBits(QSerialPort::OneStop);
}
void commHandler::openPtPort()
{
qDebug() << "opening pt port";
bool success;
char ptname[128];
success = pseudoterm->open(QIODevice::ReadWrite);
if(success)
{
qDebug() << "Opened pt device, attempting to grant pt status";
ptfd = pseudoterm->handle();
qDebug() << "ptfd: " << ptfd;
if(grantpt(ptfd))
{
qDebug() << "Failed to grantpt";
return;
}
if(unlockpt(ptfd))
{
qDebug() << "Failed to unlock pt";
return;
}
// we're good!
qDebug() << "Opened pseudoterminal.";
qDebug() << "Slave name: " << ptsname(ptfd);
ptsname_r(ptfd, ptname, 128);
ptDevSlave = QString::fromLocal8Bit(ptname);
} else {
ptfd = 0;
qDebug() << "Could not open pseudo-terminal.";
}
}
commHandler::~commHandler()
{
@ -89,6 +143,34 @@ void commHandler::sendDataOut(const QByteArray &writeData)
mutex.unlock();
}
void commHandler::sendDataOutPt(const QByteArray &writeData)
{
ptMutex.lock();
// quint64 bytesWritten;
// sned out data
//port.send() or whatever
// bytesWritten = port->write(writeData);
//printHex(writeData, false, true);
pseudoterm->write(writeData);
//qDebug() << "bytesWritten: " << bytesWritten << " length of byte array: " << writeData.length() << " size of byte array: " << writeData.size();
ptMutex.unlock();
}
void commHandler::receiveDataInPt()
{
// We received data from the pseudo-term.
// qDebug() << "Sending data from pseudo-terminal to radio";
// Send this data to the radio:
QByteArray ptdata = pseudoterm->readAll();
// should check the data and rollback
// for now though...
sendDataOut(ptdata);
}
void commHandler::receiveDataIn()
{
// connected to comm port data signal
@ -106,6 +188,17 @@ void commHandler::receiveDataIn()
// good!
port->commitTransaction();
emit haveDataFromPort(inPortData);
if( (inPortData[2] == 0x00) || (inPortData[2] == 0xE0) || (inPortData[3] == 0xE0) )
{
// send to the pseudo port as well
// index 2 is dest, 0xE1 is wfview, 0xE0 is assumed to be the other device.
// Maybe change to "Not 0xE1"
// 0xE1 = wfview
// 0xE0 = pseudo-term host
// 0x00 = broadcast to all
//qDebug() << "Sending data from radio to pseudo-terminal";
sendDataOutPt(inPortData);
}
if(rolledBack)
{

Wyświetl plik

@ -21,13 +21,14 @@ public:
~commHandler();
private slots:
void receiveDataIn();
void receiveDataIn(); // from physical port
void receiveDataInPt(); // from pseudo-term
void receiveDataFromUserToRig(const QByteArray &data);
void debugThis();
signals:
void haveTextMessage(QString message); // status, debug
void sendDataOutToPort(const QByteArray &writeData);
void haveTextMessage(QString message); // status, debug only
void sendDataOutToPort(const QByteArray &writeData); // not used
void haveDataFromPort(QByteArray data); // emit this when we have data, connect to rigcommander
private:
@ -35,7 +36,12 @@ private:
void openPort();
void closePort();
void sendDataOut(const QByteArray &writeData);
void initializePt(); // like ch constructor
void setupPtComm();
void openPtPort();
void sendDataOut(const QByteArray &writeData); // out to radio
void sendDataOutPt(const QByteArray &writeData); // out to pseudo-terminal
void debugMe();
void hexPrint();
@ -54,6 +60,13 @@ private:
unsigned char stopbits;
bool rolledBack;
QSerialPort *pseudoterm;
int ptfd; // pseudo-terminal file desc.
mutable QMutex ptMutex;
bool havePt;
QString ptDevSlave;
bool isConnected; // port opened
mutable QMutex mutex;

Wyświetl plik

@ -608,11 +608,7 @@ void wfmain::runDelayedCommand()
}
cmdOut = cmdNone; // yep. Hope this wasn't called twice in a row rapidly.
// Note: Commands that need a specific order should use this queue.
// Commands that do not need a speific order should probably just
// go through the signal-slot queue mechanism... which should be more clearly defined.
// Prototype vector queue:
// Note: All command should use this queue. There is no need to use the above system.
if(!cmdOutQue.isEmpty())
{
@ -678,7 +674,6 @@ void wfmain::runDelayedCommand()
// every command insertion to include a ->start.... probably worth doing.
delayedCommand->start();
}
}
void wfmain::receiveFreq(double freqMhz)
@ -700,8 +695,13 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e
{
if((startFreq != oldLowerFreq) || (endFreq != oldUpperFreq))
{
// If the frequency changed and we were drawing peaks, now is the time to clearn them
if(drawPeaks)
{
// TODO: create non-button function to do this
// This will break if the button is ever moved or renamed.
on_clearPeakBtn_clicked();
}
}
oldLowerFreq = startFreq;
@ -712,13 +712,7 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e
//qDebug() << "Spectrum data received at UI! Length: " << specLen;
if(specLen != 475)
{
// qDebug () << "Unusual spectrum: length: " << specLen;
if(specLen > 475)
{
specLen = 475;
} else {
// as-is
}
//qDebug () << "Unusual spectrum: length: " << specLen;
return; // safe. Using these unusual length things is a problem.
}
@ -727,7 +721,6 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e
for(int i=0; i < spectWidth; i++)
{
x[i] = (i * (endFreq-startFreq)/spectWidth) + startFreq;
}
for(int i=0; i<specLen; i++)
@ -803,7 +796,6 @@ void wfmain::handlePlotDoubleClick(QMouseEvent *me)
cmdOut = cmdGetFreq;
delayedCommand->start();
showStatusBarText(QString("Going to %1 MHz").arg(x));
}
void wfmain::handleWFDoubleClick(QMouseEvent *me)
@ -818,7 +810,6 @@ void wfmain::handleWFDoubleClick(QMouseEvent *me)
cmdOut = cmdGetFreq;
delayedCommand->start();
showStatusBarText(QString("Going to %1 MHz").arg(x));
}
void wfmain::handlePlotClick(QMouseEvent *me)
@ -839,38 +830,6 @@ void wfmain::on_startBtn_clicked()
emit spectOutputEnable();
}
//void wfmain::on_getFreqBtn_clicked()
//{
// emit getFrequency();
//}
//void wfmain::on_getModeBtn_clicked()
//{
// emit getMode();
//}
//void wfmain::on_debugBtn_clicked()
//{
// // Temporary place to try code
// // emit getDebug();
// // emit getBandStackReg(0x11,1); // 20M, latest
// // emit getRfGain();
//// for(int a=0; a<100; a++)
//// {
//// cmdOutQue.append(cmdGetRxGain);
//// cmdOutQue.append(cmdGetSql);
//// }
//// delayedCommand->start();
// // emit getRigID();
// //mem.dumpMemory();
// saveSettings();
//}
void wfmain::on_stopBtn_clicked()
{
emit spectOutputDisable();
@ -892,7 +851,9 @@ void wfmain::receiveMode(QString mode)
// return;
} else if((index >= 0) && (index < 9))
{
ui->modeSelectCombo->blockSignals(true);
ui->modeSelectCombo->setCurrentIndex(index);
ui->modeSelectCombo->blockSignals(false);
currentModeIndex = index;
}
// Note: we need to know if the DATA mode is active to reach mode-D
@ -911,28 +872,19 @@ void wfmain::receiveDataModeStatus(bool dataEnabled)
// LSB
ui->modeSelectCombo->setCurrentIndex(8);
//ui->modeLabel->setText( "LSB-D" );
} else if (currentModeIndex == 1)
{
// USB
ui->modeSelectCombo->setCurrentIndex(9);
//ui->modeLabel->setText( "USB-D" );
}
// TODO: be more intelligent here to avoid -D-D-D.
// include the text above.
// ui->modeLabel->setText( ui->modeLabel->text() + "-D" );
// Remove if works.
}
} else {
// update to _not_ have the -D
ui->modeSelectCombo->setCurrentIndex(currentModeIndex);
// No need to update status label?
}
}
void wfmain::on_clearPeakBtn_clicked()
{
spectrumPeaks = QByteArray( (int)spectWidth, '\x01' );
@ -951,10 +903,8 @@ void wfmain::on_drawPeakChk_clicked(bool checked)
}
prefs.drawPeaks = checked;
}
void wfmain::on_fullScreenChk_clicked(bool checked)
{
if(checked)
@ -1072,8 +1022,6 @@ void wfmain::on_fCEbtn_clicked()
freqTextSelected = false;
}
void wfmain::on_scopeCenterModeChk_clicked(bool checked)
{
emit setScopeCenterMode(checked);
@ -1097,13 +1045,6 @@ void wfmain::on_scopeEdgeCombo_currentIndexChanged(int index)
emit setScopeEdge((char)index+1);
}
//void wfmain::on_modeSelectCombo_currentIndexChanged(int index)
//{
// do nothing. The change may be from receiving a mode status update or the user. Can't tell which is which here.
//}
void wfmain::on_modeSelectCombo_activated(int index)
{
// Reference:

235
wfmain.ui
Wyświetl plik

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>630</width>
<width>703</width>
<height>582</height>
</rect>
</property>
@ -75,6 +75,27 @@
<item>
<widget class="QComboBox" name="scopeEdgeCombo"/>
</item>
<item>
<widget class="QPushButton" name="clearPeakBtn">
<property name="text">
<string>Clear Peaks</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="startBtn">
<property name="text">
<string>Start WF</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="stopBtn">
<property name="text">
<string>Stop WF</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
@ -187,42 +208,82 @@
</widget>
</item>
<item>
<widget class="QSlider" name="rfGainSlider">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>60</height>
</size>
<layout class="QVBoxLayout" name="verticalLayout_8">
<property name="rightMargin">
<number>0</number>
</property>
<property name="toolTip">
<string>RX RF Gain</string>
</property>
<property name="maximum">
<number>255</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<item>
<widget class="QSlider" name="rfGainSlider">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>60</height>
</size>
</property>
<property name="toolTip">
<string>RX RF Gain</string>
</property>
<property name="maximum">
<number>255</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_10">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>15</height>
</size>
</property>
<property name="text">
<string>RF</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QSlider" name="afGainSlider">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>60</height>
</size>
<layout class="QVBoxLayout" name="verticalLayout_9">
<property name="rightMargin">
<number>0</number>
</property>
<property name="toolTip">
<string>RX AF Gain</string>
</property>
<property name="maximum">
<number>255</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<item>
<widget class="QSlider" name="afGainSlider">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>60</height>
</size>
</property>
<property name="toolTip">
<string>RX AF Gain</string>
</property>
<property name="maximum">
<number>255</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_11">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>15</height>
</size>
</property>
<property name="text">
<string>AF</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_3">
@ -239,57 +300,6 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="startBtn">
<property name="text">
<string>Start WF</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="stopBtn">
<property name="text">
<string>Stop WF</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="clearPeakBtn">
<property name="text">
<string>Clear Peaks</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="bandTab">
@ -1173,47 +1183,6 @@
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="txPowerSlider">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="toolTip">
<string>TX Power</string>
</property>
<property name="maximum">
<number>255</number>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="micGainSlider">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>60</height>
</size>
</property>
<property name="toolTip">
<string>Mic Gain</string>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveSettingsBtn">
<property name="text">
@ -1269,20 +1238,6 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>ATU Status:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="tuneStatusLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="tuneSpacer">
<property name="orientation">
@ -1322,7 +1277,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>630</width>
<width>703</width>
<height>20</height>
</rect>
</property>