2011-01-26 13:01:09 +01:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file pipxtremegadgetwidget.cpp
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
|
|
|
* @{
|
|
|
|
* @{
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2011-01-29 08:52:03 +01:00
|
|
|
#include <QDebug>
|
2011-01-31 11:16:06 +01:00
|
|
|
#include <QtOpenGL/QGLWidget>
|
2011-01-26 13:01:09 +01:00
|
|
|
|
|
|
|
#include "pipxtremegadgetwidget.h"
|
|
|
|
|
|
|
|
//#include <aggregation/aggregate.h>
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
#define SERIAL_PORT 1
|
|
|
|
#define USB_PORT 2
|
|
|
|
|
|
|
|
// ***************************************************************************************
|
|
|
|
|
2011-01-26 13:01:09 +01:00
|
|
|
// constructor
|
2011-01-31 11:16:06 +01:00
|
|
|
PipXtremeGadgetWidget::PipXtremeGadgetWidget(QWidget *parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
m_widget(NULL),
|
|
|
|
m_ioDevice(NULL)
|
2011-01-26 13:01:09 +01:00
|
|
|
{
|
2011-01-31 11:16:06 +01:00
|
|
|
m_widget = new Ui_PipXtremeWidget();
|
|
|
|
m_widget->setupUi(this);
|
|
|
|
|
|
|
|
m_widget->comboBox_SerialBaudrate->clear();
|
|
|
|
m_widget->comboBox_SerialBaudrate->addItem("1200", 1200);
|
|
|
|
m_widget->comboBox_SerialBaudrate->addItem("2400", 2400);
|
|
|
|
m_widget->comboBox_SerialBaudrate->addItem("4800", 4800);
|
|
|
|
m_widget->comboBox_SerialBaudrate->addItem("9600", 9600);
|
|
|
|
m_widget->comboBox_SerialBaudrate->addItem("19200", 19200);
|
|
|
|
m_widget->comboBox_SerialBaudrate->addItem("38400", 38400);
|
|
|
|
m_widget->comboBox_SerialBaudrate->addItem("57600", 57600);
|
|
|
|
m_widget->comboBox_SerialBaudrate->addItem("115200", 115200);
|
|
|
|
// m_widget->comboBox_SerialBaudrate->addItem("230400", 230400);
|
|
|
|
// m_widget->comboBox_SerialBaudrate->addItem("460800", 460800);
|
|
|
|
// m_widget->comboBox_SerialBaudrate->addItem("921600", 921600);
|
|
|
|
m_widget->comboBox_SerialBaudrate->setCurrentIndex(m_widget->comboBox_SerialBaudrate->findText("57600"));
|
|
|
|
|
|
|
|
m_widget->comboBox_Mode->clear();
|
|
|
|
m_widget->comboBox_Mode->addItem("Normal", 0);
|
|
|
|
m_widget->comboBox_Mode->addItem("Scan Spectrum", 1);
|
|
|
|
m_widget->comboBox_Mode->addItem("Calibrate Tx Carrier Frequency", 2);
|
|
|
|
m_widget->comboBox_Mode->addItem("Test Tx Spectrum", 3);
|
|
|
|
|
|
|
|
m_widget->comboBox_SerialPortSpeed->clear();
|
|
|
|
for (int i = 0; i < m_widget->comboBox_SerialBaudrate->count(); i++)
|
|
|
|
m_widget->comboBox_SerialPortSpeed->addItem(m_widget->comboBox_SerialBaudrate->itemText(i), m_widget->comboBox_SerialBaudrate->itemData(i));
|
|
|
|
m_widget->comboBox_SerialPortSpeed->setCurrentIndex(m_widget->comboBox_SerialPortSpeed->findText("57600"));
|
|
|
|
|
|
|
|
m_widget->doubleSpinBox_Frequency->setSingleStep(0.00015625);
|
|
|
|
|
|
|
|
m_widget->progressBar_RSSI->setMinimum(-120);
|
|
|
|
m_widget->progressBar_RSSI->setMaximum(-20);
|
|
|
|
m_widget->progressBar_RSSI->setValue(-80);
|
|
|
|
|
|
|
|
m_widget->graphicsView_Spectrum->setScene(new QGraphicsScene(this));
|
|
|
|
m_widget->graphicsView_Spectrum->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
|
|
|
|
// m_widget->graphicsView_Spectrum->setViewport(new QWidget);
|
|
|
|
m_widget->graphicsView_Spectrum->setCacheMode(QGraphicsView::CacheBackground);
|
|
|
|
m_widget->graphicsView_Spectrum->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing);
|
|
|
|
QGraphicsScene *spec_scene = m_widget->graphicsView_Spectrum->scene();
|
2011-01-26 13:01:09 +01:00
|
|
|
if (spec_scene)
|
|
|
|
{
|
2011-01-31 11:16:06 +01:00
|
|
|
spec_scene->setBackgroundBrush(QColor(80, 80, 80));
|
2011-01-26 13:01:09 +01:00
|
|
|
spec_scene->clear();
|
2011-01-31 11:16:06 +01:00
|
|
|
|
2011-01-26 13:01:09 +01:00
|
|
|
// spec_scene->addItem(m_background);
|
|
|
|
// spec_scene->addItem(m_joystickEnd);
|
|
|
|
// spec_scene->setSceneRect(m_background->boundingRect());
|
|
|
|
}
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
m_widget->pushButton_ScanSpectrum->setEnabled(false);
|
2011-01-26 13:01:09 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
QIcon rbi;
|
|
|
|
rbi.addFile(QString(":pipxtreme/images/view-refresh.svg"));
|
|
|
|
m_widget->refreshPorts->setIcon(rbi);
|
2011-01-26 13:01:09 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
// Listen to telemetry connection events
|
|
|
|
ExtensionSystem::PluginManager *pluginManager = ExtensionSystem::PluginManager::instance();
|
|
|
|
if (pluginManager)
|
|
|
|
{
|
|
|
|
TelemetryManager *telemetryManager = pluginManager->getObject<TelemetryManager>();
|
|
|
|
if (telemetryManager)
|
|
|
|
{
|
|
|
|
connect(telemetryManager, SIGNAL(myStart()), this, SLOT(onTelemetryStart()));
|
|
|
|
connect(telemetryManager, SIGNAL(myStop()), this, SLOT(onTelemetryStop()));
|
|
|
|
connect(telemetryManager, SIGNAL(connected()), this, SLOT(onTelemetryConnect()));
|
|
|
|
connect(telemetryManager, SIGNAL(disconnected()), this, SLOT(onTelemetryDisconnect()));
|
|
|
|
}
|
|
|
|
}
|
2011-01-26 13:01:09 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
getPorts();
|
2011-01-26 13:01:09 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
connect(m_widget->connectButton, SIGNAL(clicked()), this, SLOT(connectDisconnect()));
|
|
|
|
connect(m_widget->refreshPorts, SIGNAL(clicked()), this, SLOT(getPorts()));
|
2011-01-26 13:01:09 +01:00
|
|
|
|
|
|
|
// delay::msleep(600); // just for pips reference
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:28:22 +01:00
|
|
|
// destructor .. this never gets called :(
|
2011-01-26 13:01:09 +01:00
|
|
|
PipXtremeGadgetWidget::~PipXtremeGadgetWidget()
|
|
|
|
{
|
2011-01-31 11:16:06 +01:00
|
|
|
disconnectPort(false);
|
2011-01-26 13:01:09 +01:00
|
|
|
}
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
// ***************************************************************************************
|
|
|
|
|
2011-01-26 13:01:09 +01:00
|
|
|
void PipXtremeGadgetWidget::resizeEvent(QResizeEvent *event)
|
|
|
|
{
|
2011-01-31 11:16:06 +01:00
|
|
|
if (m_widget)
|
2011-01-26 13:01:09 +01:00
|
|
|
{
|
2011-01-31 11:16:06 +01:00
|
|
|
if (m_widget->graphicsView_Spectrum)
|
2011-01-26 13:01:09 +01:00
|
|
|
{
|
2011-01-31 11:16:06 +01:00
|
|
|
QGraphicsScene *spec_scene = m_widget->graphicsView_Spectrum->scene();
|
2011-01-26 13:01:09 +01:00
|
|
|
if (spec_scene)
|
|
|
|
{
|
|
|
|
// spec_scene->setSceneRect(QRect(QPoint(0, 0), event->size()));
|
|
|
|
// spec_scene->setBackgroundBrush(Qt::black);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// PipXtremeGadgetWidget::resizeEvent(event);
|
|
|
|
}
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
// ***************************************************************************************
|
|
|
|
|
|
|
|
void PipXtremeGadgetWidget::onComboBoxPorts_currentIndexChanged(int index)
|
2011-01-26 13:01:09 +01:00
|
|
|
{
|
2011-01-31 11:16:06 +01:00
|
|
|
if (index < 0)
|
|
|
|
{
|
|
|
|
m_widget->comboBox_SerialBaudrate->setEnabled(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int type = m_widget->comboBox_Ports->itemData(index).toInt();
|
|
|
|
|
|
|
|
m_widget->comboBox_SerialBaudrate->setEnabled(type == SERIAL_PORT);
|
2011-01-26 13:01:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ***************************************************************************************
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
QString PipXtremeGadgetWidget::getSerialPortDevice(const QString &friendName)
|
|
|
|
{
|
|
|
|
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
|
|
|
|
|
|
|
|
foreach (QextPortInfo port, ports)
|
|
|
|
{
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
if (port.friendName == friendName)
|
|
|
|
return port.portName;
|
|
|
|
#else
|
|
|
|
if (port.friendName == friendName)
|
|
|
|
return port.physName;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool sortSerialPorts(const QextPortInfo &s1, const QextPortInfo &s2)
|
|
|
|
{
|
|
|
|
return (s1.portName < s2.portName);
|
|
|
|
}
|
|
|
|
|
2011-01-26 13:01:09 +01:00
|
|
|
void PipXtremeGadgetWidget::getPorts()
|
|
|
|
{
|
|
|
|
QStringList list;
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
disconnect(m_widget->comboBox_Ports, 0, 0, 0);
|
2011-01-26 13:01:09 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
m_widget->comboBox_Ports->clear();
|
2011-01-26 13:01:09 +01:00
|
|
|
|
|
|
|
// ********************************
|
|
|
|
// Populate the telemetry combo box with serial ports
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
QList<QextPortInfo> serial_ports = QextSerialEnumerator::getPorts();
|
2011-01-26 13:01:09 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
qSort(serial_ports.begin(), serial_ports.end(), sortSerialPorts);
|
2011-01-26 13:01:09 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
foreach (QextPortInfo port, serial_ports)
|
2011-01-26 13:01:09 +01:00
|
|
|
list.append(port.friendName);
|
|
|
|
|
2011-01-30 14:28:22 +01:00
|
|
|
for (int i = 0; i < list.count(); i++)
|
2011-01-31 11:16:06 +01:00
|
|
|
m_widget->comboBox_Ports->addItem(list.at(i), SERIAL_PORT);
|
2011-01-26 13:01:09 +01:00
|
|
|
|
|
|
|
// ********************************
|
|
|
|
// Populate the telemetry combo box with usb ports
|
|
|
|
|
|
|
|
pjrc_rawhid *rawHidHandle = new pjrc_rawhid();
|
|
|
|
if (rawHidHandle)
|
|
|
|
{
|
|
|
|
int opened = rawHidHandle->open(10, 0x20A0, 0x4117, 0xFF9C, 0x0001);
|
|
|
|
if (opened > 0)
|
|
|
|
{
|
|
|
|
QList<QString> usb_ports;
|
|
|
|
|
|
|
|
for (int i = 0; i < opened; i++)
|
|
|
|
usb_ports.append(rawHidHandle->getserial(i));
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
qSort(usb_ports.begin(), usb_ports.end());
|
2011-01-30 14:28:22 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
for (int i = 0; i < usb_ports.count(); i++)
|
|
|
|
m_widget->comboBox_Ports->addItem(usb_ports.at(i), USB_PORT);
|
2011-01-26 13:01:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
delete rawHidHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ********************************
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
connect(m_widget->comboBox_Ports, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboBoxPorts_currentIndexChanged(int)));
|
2011-01-26 13:01:09 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
onComboBoxPorts_currentIndexChanged(m_widget->comboBox_Ports->currentIndex());
|
2011-01-26 13:01:09 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
// ********************************
|
2011-01-26 13:01:09 +01:00
|
|
|
}
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
// ***************************************************************************************
|
2011-01-30 14:28:22 +01:00
|
|
|
|
2011-01-26 13:01:09 +01:00
|
|
|
void PipXtremeGadgetWidget::onTelemetryStart()
|
|
|
|
{
|
2011-01-31 11:16:06 +01:00
|
|
|
setEnabled(false);
|
|
|
|
|
|
|
|
// m_widget->connectButton->setEnabled(false);
|
|
|
|
// m_widget->comboBox_Ports->setEnabled(false);
|
|
|
|
// m_widget->refreshPorts->setEnabled(false);
|
|
|
|
// m_widget->comboBox_SerialBaudrate->setEnabled(false);
|
2011-01-26 13:01:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PipXtremeGadgetWidget::onTelemetryStop()
|
|
|
|
{
|
2011-01-31 11:16:06 +01:00
|
|
|
setEnabled(true);
|
|
|
|
|
|
|
|
// m_widget->connectButton->setEnabled(true);
|
|
|
|
// m_widget->comboBox_Ports->setEnabled(true);
|
|
|
|
// m_widget->refreshPorts->setEnabled(true);
|
|
|
|
// m_widget->comboBox_SerialBaudrate->setEnabled(true);
|
2011-01-26 13:01:09 +01:00
|
|
|
}
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
// ***************************************************************************************
|
2011-01-30 14:28:22 +01:00
|
|
|
|
2011-01-26 13:01:09 +01:00
|
|
|
void PipXtremeGadgetWidget::onTelemetryConnect()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void PipXtremeGadgetWidget::onTelemetryDisconnect()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
// ***************************************************************************************
|
2011-01-26 13:01:09 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
void PipXtremeGadgetWidget::disableTelemetry()
|
|
|
|
{ // Suspend telemetry & polling
|
2011-01-30 14:28:22 +01:00
|
|
|
|
|
|
|
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
|
|
|
if (!cm) return;
|
2011-01-26 13:01:09 +01:00
|
|
|
|
2011-01-30 14:28:22 +01:00
|
|
|
cm->disconnectDevice();
|
|
|
|
cm->suspendPolling();
|
2011-01-26 13:01:09 +01:00
|
|
|
}
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
void PipXtremeGadgetWidget::enableTelemetry()
|
|
|
|
{ // Restart the polling thread
|
|
|
|
|
2011-01-30 14:28:22 +01:00
|
|
|
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
|
|
|
if (!cm) return;
|
|
|
|
|
|
|
|
cm->resumePolling();
|
|
|
|
}
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
// ***************************************************************************************
|
2011-01-30 14:28:22 +01:00
|
|
|
|
2011-01-26 13:01:09 +01:00
|
|
|
void PipXtremeGadgetWidget::processOutputStream()
|
|
|
|
{
|
|
|
|
if (!m_ioDevice)
|
|
|
|
return;
|
|
|
|
|
2011-01-30 14:28:22 +01:00
|
|
|
if (!m_ioDevice->isOpen())
|
|
|
|
return;
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
// if (m_ioDevice->bytesToWrite() < TX_BUFFER_SIZE )
|
|
|
|
{
|
|
|
|
// m_ioDevice->write((const char*)txBuffer, dataOffset+length+CHECKSUM_LENGTH);
|
|
|
|
}
|
2011-01-26 13:01:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PipXtremeGadgetWidget::processInputStream()
|
|
|
|
{
|
2011-01-31 11:16:06 +01:00
|
|
|
while (m_ioDevice)
|
2011-01-26 13:01:09 +01:00
|
|
|
{
|
2011-01-31 11:16:06 +01:00
|
|
|
quint8 buf;
|
|
|
|
|
|
|
|
if (!m_ioDevice->isOpen())
|
|
|
|
break;
|
|
|
|
|
|
|
|
qint64 bytes_available = m_ioDevice->bytesAvailable();
|
|
|
|
if (bytes_available <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
qint64 bytes_read = m_ioDevice->read((char *)&buf, sizeof(buf));
|
|
|
|
if (bytes_read <= 0)
|
|
|
|
break;
|
2011-01-26 13:01:09 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
processInputBytes(&buf, sizeof(buf));
|
2011-01-26 13:01:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
void PipXtremeGadgetWidget::processInputBytes(quint8 *buf, int count)
|
|
|
|
{
|
|
|
|
if (!buf || count <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// ***************************************************************************************
|
2011-01-30 14:28:22 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
void PipXtremeGadgetWidget::disconnectPort(bool enable_telemetry)
|
2011-01-30 14:28:22 +01:00
|
|
|
{ // disconnect the comms port
|
|
|
|
|
|
|
|
if (!m_ioDevice)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_ioDevice->close();
|
2011-01-26 13:01:09 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
disconnect(m_ioDevice, 0, 0, 0);
|
|
|
|
|
2011-01-30 14:28:22 +01:00
|
|
|
delete m_ioDevice;
|
|
|
|
m_ioDevice = NULL;
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
m_widget->connectButton->setText("Connect");
|
|
|
|
m_widget->comboBox_SerialBaudrate->setEnabled(true);
|
|
|
|
m_widget->comboBox_Ports->setEnabled(true);
|
|
|
|
m_widget->refreshPorts->setEnabled(true);
|
|
|
|
m_widget->pushButton_ScanSpectrum->setEnabled(false);
|
2011-01-30 14:28:22 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
if (enable_telemetry)
|
|
|
|
enableTelemetry();
|
2011-01-30 14:28:22 +01:00
|
|
|
}
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
void PipXtremeGadgetWidget::connectPort()
|
|
|
|
{ // connect the comms port
|
2011-01-30 14:28:22 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
disconnectPort(true);
|
2011-01-30 14:28:22 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
int device_idx = m_widget->comboBox_Ports->currentIndex();
|
2011-01-30 14:28:22 +01:00
|
|
|
if (device_idx < 0)
|
|
|
|
return;
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
QString device_str = m_widget->comboBox_Ports->currentText().trimmed();
|
2011-01-30 14:28:22 +01:00
|
|
|
if (device_str.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
int type = m_widget->comboBox_Ports->itemData(device_idx).toInt();
|
2011-01-30 14:28:22 +01:00
|
|
|
|
|
|
|
// qDebug() << QString::number(type) << ": " << device_str;
|
|
|
|
|
|
|
|
// Suspend telemety & polling in case it is not done yet
|
2011-01-31 11:16:06 +01:00
|
|
|
disableTelemetry();
|
2011-01-30 14:28:22 +01:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
2011-01-31 11:16:06 +01:00
|
|
|
case SERIAL_PORT: // serial port
|
2011-01-30 14:28:22 +01:00
|
|
|
{
|
2011-01-31 11:16:06 +01:00
|
|
|
QString str = getSerialPortDevice(device_str);
|
2011-01-30 14:28:22 +01:00
|
|
|
if (str.isEmpty())
|
|
|
|
break;
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
int br_idx = m_widget->comboBox_SerialBaudrate->currentIndex();
|
2011-01-30 14:28:22 +01:00
|
|
|
if (br_idx < 0)
|
|
|
|
break;
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
int baudrate = m_widget->comboBox_SerialBaudrate->itemData(br_idx).toInt();
|
2011-01-30 14:28:22 +01:00
|
|
|
|
|
|
|
BaudRateType bdt = BAUD57600;
|
|
|
|
switch (baudrate)
|
|
|
|
{
|
|
|
|
case 1200: bdt = BAUD1200; break;
|
|
|
|
case 2400: bdt = BAUD2400; break;
|
|
|
|
case 4800: bdt = BAUD4800; break;
|
|
|
|
case 9600: bdt = BAUD9600; break;
|
|
|
|
case 19200: bdt = BAUD19200; break;
|
|
|
|
case 38400: bdt = BAUD38400; break;
|
|
|
|
case 57600: bdt = BAUD57600; break;
|
|
|
|
case 115200: bdt = BAUD115200; break;
|
|
|
|
case 128000: bdt = BAUD128000; break;
|
|
|
|
case 256000: bdt = BAUD256000; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PortSettings settings;
|
|
|
|
settings.BaudRate = bdt;
|
|
|
|
settings.DataBits = DATA_8;
|
|
|
|
settings.Parity = PAR_NONE;
|
|
|
|
settings.StopBits = STOP_1;
|
|
|
|
settings.FlowControl = FLOW_OFF;
|
|
|
|
settings.Timeout_Millisec = 500;
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
// QextSerialPort *serial_dev = new QextSerialPort(str, settings, QextSerialPort::Polling);
|
|
|
|
QextSerialPort *serial_dev = new QextSerialPort(str, settings);
|
2011-01-30 14:28:22 +01:00
|
|
|
if (!serial_dev)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!serial_dev->open(QIODevice::ReadWrite | QIODevice::Unbuffered))
|
|
|
|
{
|
|
|
|
delete serial_dev;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ioDevice = serial_dev;
|
2011-01-31 11:16:06 +01:00
|
|
|
break;
|
2011-01-30 14:28:22 +01:00
|
|
|
}
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
case USB_PORT: // USB port
|
2011-01-30 14:28:22 +01:00
|
|
|
{
|
|
|
|
RawHID *usb_dev = new RawHID(device_str);
|
|
|
|
if (!usb_dev)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!usb_dev->open(QIODevice::ReadWrite | QIODevice::Unbuffered))
|
|
|
|
{
|
|
|
|
delete usb_dev;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ioDevice = usb_dev;
|
2011-01-31 11:16:06 +01:00
|
|
|
break;
|
2011-01-30 14:28:22 +01:00
|
|
|
}
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
default: // unknown port type
|
2011-01-30 14:28:22 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
if (!m_ioDevice)
|
|
|
|
{ // failed to connect
|
|
|
|
enableTelemetry();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // connected OK
|
|
|
|
m_widget->connectButton->setText("Disconnect");
|
|
|
|
m_widget->comboBox_SerialBaudrate->setEnabled(false);
|
|
|
|
m_widget->comboBox_Ports->setEnabled(false);
|
|
|
|
m_widget->refreshPorts->setEnabled(false);
|
|
|
|
m_widget->pushButton_ScanSpectrum->setEnabled(true);
|
|
|
|
|
|
|
|
connect(m_ioDevice, SIGNAL(readyRead()), this, SLOT(processInputStream()));
|
|
|
|
}
|
2011-01-26 13:01:09 +01:00
|
|
|
}
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
// ***************************************************************************************
|
2011-01-26 13:01:09 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
void PipXtremeGadgetWidget::connectDisconnect()
|
2011-01-26 13:01:09 +01:00
|
|
|
{
|
2011-01-31 11:16:06 +01:00
|
|
|
if (m_ioDevice)
|
|
|
|
disconnectPort(true); // disconnect
|
|
|
|
else
|
|
|
|
connectPort(); // connect
|
2011-01-26 13:01:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ***************************************************************************************
|
|
|
|
|
|
|
|
// Shows a message box with an error string.
|
|
|
|
void PipXtremeGadgetWidget::error(QString errorString, int errorNumber)
|
|
|
|
{
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
|
|
|
msgBox.setText(errorString + " [" + QString::number(errorNumber) + "]");
|
|
|
|
msgBox.exec();
|
|
|
|
}
|
2011-01-31 11:16:06 +01:00
|
|
|
|
|
|
|
// ***************************************************************************************
|