mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-15 07:29:15 +01:00
Added USB port detection
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2594 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
99eb1a89f9
commit
549e92f9c0
@ -49,7 +49,7 @@ through serial or USB)</string>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="telemetryLink">
|
||||
<widget class="QComboBox" name="comboBox_Ports">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
|
@ -1,303 +1,375 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
#include "pipxtremegadgetwidget.h"
|
||||
|
||||
// constructor
|
||||
PipXtremeGadgetWidget::PipXtremeGadgetWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
m_config = new Ui_PipXtremeWidget();
|
||||
m_config->setupUi(this);
|
||||
|
||||
m_ioDev = NULL;
|
||||
|
||||
currentStep = IAP_STATE_READY;
|
||||
rescueStep = RESCUE_STEP0;
|
||||
resetOnly = false;
|
||||
|
||||
m_config->comboBox_Mode->clear();
|
||||
m_config->comboBox_Mode->addItem("Normal", 0);
|
||||
m_config->comboBox_Mode->addItem("Scan Spectrum", 1);
|
||||
m_config->comboBox_Mode->addItem("Tx Carrier Calibrate", 2);
|
||||
m_config->comboBox_Mode->addItem("Tx Spectrum Test", 3);
|
||||
|
||||
m_config->comboBox_SerialPortSpeed->clear();
|
||||
m_config->comboBox_SerialPortSpeed->addItem("1200", 1200);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("2400", 2400);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("4800", 4800);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("9600", 9600);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("19200", 19200);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("38400", 38400);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("57600", 57600);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("115200", 115200);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("230400", 230400);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("460800", 460800);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("921600", 921600);
|
||||
|
||||
m_config->doubleSpinBox_Frequency->setSingleStep(0.00015625);
|
||||
|
||||
m_config->graphicsView_Spectrum->setScene(new QGraphicsScene(this));
|
||||
QGraphicsScene *spec_scene = m_config->graphicsView_Spectrum->scene();
|
||||
if (spec_scene)
|
||||
{
|
||||
spec_scene->setBackgroundBrush(Qt::black);
|
||||
spec_scene->clear();
|
||||
// spec_scene->addItem(m_background);
|
||||
// spec_scene->addItem(m_joystickEnd);
|
||||
// spec_scene->setSceneRect(m_background->boundingRect());
|
||||
}
|
||||
|
||||
m_config->pushButton_ScanSpectrum->setEnabled(false);
|
||||
|
||||
// Listen to autopilot connection events
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
TelemetryManager *telMngr = pm->getObject<TelemetryManager>();
|
||||
connect(telMngr, SIGNAL(connected()), this, SLOT(onTelemetryConnect()));
|
||||
connect(telMngr, SIGNAL(disconnected()), this, SLOT(onTelemetryDisconnect()));
|
||||
|
||||
// Note: remove listening to the connection manager, it overlaps with
|
||||
// listening to the telemetry manager, we should only listen to one, not both.
|
||||
|
||||
// Also listen to disconnect actions from the user:
|
||||
// Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
||||
// connect(cm, SIGNAL(deviceDisconnected()), this, SLOT(onModemDisconnect()));
|
||||
|
||||
connect(m_config->connectButton, SIGNAL(clicked()), this, SLOT(goToAPIMode()));
|
||||
|
||||
getPorts();
|
||||
|
||||
QIcon rbi;
|
||||
rbi.addFile(QString(":pipxtreme/images/view-refresh.svg"));
|
||||
m_config->refreshPorts->setIcon(rbi);
|
||||
|
||||
connect(m_config->refreshPorts, SIGNAL(clicked()), this, SLOT(getPorts()));
|
||||
|
||||
// delay::msleep(600); // just for pips reference
|
||||
}
|
||||
|
||||
// destructor
|
||||
PipXtremeGadgetWidget::~PipXtremeGadgetWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void PipXtremeGadgetWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
if (m_config)
|
||||
{
|
||||
if (m_config->graphicsView_Spectrum)
|
||||
{
|
||||
QGraphicsScene *spec_scene = m_config->graphicsView_Spectrum->scene();
|
||||
if (spec_scene)
|
||||
{
|
||||
// spec_scene->setSceneRect(QRect(QPoint(0, 0), event->size()));
|
||||
// spec_scene->setBackgroundBrush(Qt::black);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PipXtremeGadgetWidget::resizeEvent(event);
|
||||
}
|
||||
|
||||
bool sortPorts(const QextPortInfo &s1,const QextPortInfo &s2)
|
||||
{
|
||||
return (s1.portName < s2.portName);
|
||||
}
|
||||
|
||||
void PipXtremeGadgetWidget::getPorts()
|
||||
{
|
||||
QStringList list;
|
||||
|
||||
// m_config->refreshPorts->setEnabled(false);
|
||||
// m_config->telemetryLink->setEnabled(false);
|
||||
|
||||
// ********************************
|
||||
// Populate the telemetry combo box
|
||||
|
||||
// get usb port list
|
||||
|
||||
// get serial port list
|
||||
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
|
||||
qSort(ports.begin(), ports.end(), sortPorts); // sort the list by port number (nice idea from PT_Dreamer :))
|
||||
foreach (QextPortInfo port, ports)
|
||||
list.append(port.friendName);
|
||||
|
||||
m_config->telemetryLink->clear();
|
||||
m_config->telemetryLink->addItems(list);
|
||||
|
||||
// ********************************
|
||||
|
||||
// m_config->refreshPorts->setEnabled(true);
|
||||
// m_config->telemetryLink->setEnabled(true);
|
||||
}
|
||||
|
||||
QString PipXtremeGadgetWidget::getPortDevice(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 "";
|
||||
}
|
||||
|
||||
void PipXtremeGadgetWidget::onTelemetryConnect()
|
||||
{
|
||||
m_config->connectButton->setEnabled(false);
|
||||
m_config->telemetryLink->setEnabled(false);
|
||||
}
|
||||
|
||||
void PipXtremeGadgetWidget::onTelemetryDisconnect()
|
||||
{
|
||||
m_config->connectButton->setEnabled(true);
|
||||
m_config->telemetryLink->setEnabled(true);
|
||||
}
|
||||
|
||||
void PipXtremeGadgetWidget::onModemConnect()
|
||||
{
|
||||
m_config->connectButton->setText(tr(" Disconnect "));
|
||||
m_config->telemetryLink->setEnabled(false);
|
||||
m_config->pushButton_ScanSpectrum->setEnabled(true);
|
||||
}
|
||||
|
||||
void PipXtremeGadgetWidget::onModemDisconnect()
|
||||
{
|
||||
m_config->connectButton->setText(tr(" Connect "));
|
||||
m_config->telemetryLink->setEnabled(true);
|
||||
m_config->pushButton_ScanSpectrum->setEnabled(false);
|
||||
}
|
||||
|
||||
// Ask the modem to go into API mode
|
||||
void PipXtremeGadgetWidget::goToAPIMode(UAVObject* callerObj, bool success)
|
||||
{
|
||||
Q_UNUSED(callerObj);
|
||||
/*
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
UAVObject *fwIAP = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("FirmwareIAPObj")));
|
||||
|
||||
switch (currentStep)
|
||||
{
|
||||
case IAP_STATE_READY:
|
||||
getPorts(); // Useful in case a new serial port appeared since the initial list,
|
||||
// otherwise we won't find it when we stop the board.
|
||||
|
||||
// The board is running, send the 1st IAP Reset order:
|
||||
fwIAP->getField("Command")->setValue("1122");
|
||||
connect(fwIAP,SIGNAL(transactionCompleted(UAVObject*,bool)),this,SLOT(goToAPIMode(UAVObject*, bool)));
|
||||
currentStep = IAP_STATE_STEP_1;
|
||||
fwIAP->updated();
|
||||
|
||||
break;
|
||||
|
||||
case IAP_STATE_STEP_1:
|
||||
if (!success)
|
||||
{
|
||||
currentStep = IAP_STATE_READY;
|
||||
disconnect(fwIAP, SIGNAL(transactionCompleted(UAVObject*,bool)),this,SLOT(goToAPIMode(UAVObject*, bool)));
|
||||
break;
|
||||
}
|
||||
|
||||
delay::msleep(600);
|
||||
|
||||
fwIAP->getField("Command")->setValue("2233");
|
||||
currentStep = IAP_STATE_READY;
|
||||
fwIAP->updated();
|
||||
|
||||
break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// Tell the modem to reset
|
||||
void PipXtremeGadgetWidget::systemReset()
|
||||
{
|
||||
resetOnly = true;
|
||||
/*
|
||||
if (dfu)
|
||||
{
|
||||
delete dfu;
|
||||
dfu = NULL;
|
||||
}
|
||||
*/
|
||||
goToAPIMode();
|
||||
}
|
||||
|
||||
// Tells the system to boot (from Bootloader state)
|
||||
void PipXtremeGadgetWidget::systemBoot()
|
||||
{
|
||||
/*
|
||||
// Suspend telemety & polling in case it is not done yet
|
||||
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
||||
cm->disconnectDevice();
|
||||
cm->suspendPolling();
|
||||
|
||||
QString devName = m_config->telemetryLink->currentText();
|
||||
repaint();
|
||||
|
||||
if (!dfu)
|
||||
{
|
||||
if (devName == "USB")
|
||||
dfu = new DFUObject(DFU_DEBUG, false, QString());
|
||||
else
|
||||
dfu = new DFUObject(DFU_DEBUG,true,getPortDevice(devName));
|
||||
}
|
||||
dfu->AbortOperation();
|
||||
if (!dfu->enterDFU(0))
|
||||
{
|
||||
delete dfu;
|
||||
dfu = NULL;
|
||||
|
||||
return;
|
||||
}
|
||||
dfu->JumpToApp();
|
||||
// Restart the polling thread
|
||||
cm->resumePolling();
|
||||
|
||||
m_config->telemetryLink->setEnabled(true);
|
||||
if (currentStep == IAP_STATE_BOOTLOADER )
|
||||
{
|
||||
}
|
||||
currentStep = IAP_STATE_READY;
|
||||
delete dfu; // Frees up the USB/Serial port too
|
||||
dfu = NULL;
|
||||
*/
|
||||
}
|
||||
|
||||
// Shows a message box with an error string.
|
||||
void PipXtremeGadgetWidget::error(QString errorString, int errorNumber)
|
||||
{
|
||||
Q_UNUSED(errorNumber);
|
||||
QMessageBox msgBox;
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setText(errorString + " [" + QString::number(errorNumber) + "]");
|
||||
msgBox.exec();
|
||||
}
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
#include <qDebug>
|
||||
|
||||
#include "pipxtremegadgetwidget.h"
|
||||
|
||||
//#include <aggregation/aggregate.h>
|
||||
|
||||
// constructor
|
||||
PipXtremeGadgetWidget::PipXtremeGadgetWidget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
m_config = new Ui_PipXtremeWidget();
|
||||
m_config->setupUi(this);
|
||||
|
||||
m_ioDevice = NULL;
|
||||
|
||||
currentStep = IAP_STATE_READY;
|
||||
rescueStep = RESCUE_STEP0;
|
||||
resetOnly = false;
|
||||
|
||||
m_config->comboBox_Mode->clear();
|
||||
m_config->comboBox_Mode->addItem("Normal", 0);
|
||||
m_config->comboBox_Mode->addItem("Scan Spectrum", 1);
|
||||
m_config->comboBox_Mode->addItem("Tx Carrier Calibrate", 2);
|
||||
m_config->comboBox_Mode->addItem("Tx Spectrum Test", 3);
|
||||
|
||||
m_config->comboBox_SerialPortSpeed->clear();
|
||||
m_config->comboBox_SerialPortSpeed->addItem("1200", 1200);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("2400", 2400);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("4800", 4800);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("9600", 9600);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("19200", 19200);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("38400", 38400);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("57600", 57600);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("115200", 115200);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("230400", 230400);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("460800", 460800);
|
||||
m_config->comboBox_SerialPortSpeed->addItem("921600", 921600);
|
||||
|
||||
m_config->doubleSpinBox_Frequency->setSingleStep(0.00015625);
|
||||
|
||||
m_config->graphicsView_Spectrum->setScene(new QGraphicsScene(this));
|
||||
QGraphicsScene *spec_scene = m_config->graphicsView_Spectrum->scene();
|
||||
if (spec_scene)
|
||||
{
|
||||
spec_scene->setBackgroundBrush(Qt::black);
|
||||
spec_scene->clear();
|
||||
// spec_scene->addItem(m_background);
|
||||
// spec_scene->addItem(m_joystickEnd);
|
||||
// spec_scene->setSceneRect(m_background->boundingRect());
|
||||
}
|
||||
|
||||
m_config->pushButton_ScanSpectrum->setEnabled(false);
|
||||
|
||||
// Listen to autopilot connection events
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
TelemetryManager *telMngr = pm->getObject<TelemetryManager>();
|
||||
connect(telMngr, SIGNAL(myStart()), this, SLOT(onTelemetryStart()));
|
||||
connect(telMngr, SIGNAL(myStop()), this, SLOT(onTelemetryStop()));
|
||||
connect(telMngr, SIGNAL(connected()), this, SLOT(onTelemetryConnect()));
|
||||
connect(telMngr, SIGNAL(disconnected()), this, SLOT(onTelemetryDisconnect()));
|
||||
|
||||
// Note: remove listening to the connection manager, it overlaps with
|
||||
// listening to the telemetry manager, we should only listen to one, not both.
|
||||
|
||||
// Also listen to disconnect actions from the user:
|
||||
// Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
||||
// connect(cm, SIGNAL(deviceDisconnected()), this, SLOT(onModemDisconnect()));
|
||||
|
||||
// int opened = rawHidHandle.open(10, 0x20A0, 0x4117, 0xFF9C, 0x0001);
|
||||
// rawHidPlugin = new RawHIDPlugin();
|
||||
|
||||
connect(m_config->connectButton, SIGNAL(clicked()), this, SLOT(goToAPIMode()));
|
||||
|
||||
getPorts();
|
||||
|
||||
QIcon rbi;
|
||||
rbi.addFile(QString(":pipxtreme/images/view-refresh.svg"));
|
||||
m_config->refreshPorts->setIcon(rbi);
|
||||
|
||||
connect(m_config->refreshPorts, SIGNAL(clicked()), this, SLOT(getPorts()));
|
||||
|
||||
if (m_ioDevice)
|
||||
connect(m_ioDevice, SIGNAL(readyRead()), this, SLOT(processInputStream()));
|
||||
|
||||
// delay::msleep(600); // just for pips reference
|
||||
}
|
||||
|
||||
// destructor
|
||||
PipXtremeGadgetWidget::~PipXtremeGadgetWidget()
|
||||
{
|
||||
}
|
||||
|
||||
void PipXtremeGadgetWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
if (m_config)
|
||||
{
|
||||
if (m_config->graphicsView_Spectrum)
|
||||
{
|
||||
QGraphicsScene *spec_scene = m_config->graphicsView_Spectrum->scene();
|
||||
if (spec_scene)
|
||||
{
|
||||
// spec_scene->setSceneRect(QRect(QPoint(0, 0), event->size()));
|
||||
// spec_scene->setBackgroundBrush(Qt::black);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// PipXtremeGadgetWidget::resizeEvent(event);
|
||||
}
|
||||
|
||||
bool sortSerialPorts(const QextPortInfo &s1, const QextPortInfo &s2)
|
||||
{
|
||||
return (s1.portName < s2.portName);
|
||||
}
|
||||
|
||||
// ***************************************************************************************
|
||||
|
||||
void PipXtremeGadgetWidget::getPorts()
|
||||
{
|
||||
QStringList list;
|
||||
|
||||
// m_config->refreshPorts->setEnabled(false);
|
||||
// m_config->comboBox_Ports->setEnabled(false);
|
||||
|
||||
m_config->comboBox_Ports->clear();
|
||||
|
||||
// ********************************
|
||||
// Populate the telemetry combo box with serial ports
|
||||
|
||||
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
|
||||
|
||||
qSort(ports.begin(), ports.end(), sortSerialPorts);
|
||||
|
||||
foreach (QextPortInfo port, ports)
|
||||
list.append(port.friendName);
|
||||
|
||||
m_config->comboBox_Ports->addItems(list);
|
||||
|
||||
// ********************************
|
||||
// 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));
|
||||
|
||||
m_config->comboBox_Ports->addItems(usb_ports);
|
||||
}
|
||||
|
||||
delete rawHidHandle;
|
||||
}
|
||||
|
||||
// ********************************
|
||||
|
||||
// m_config->refreshPorts->setEnabled(true);
|
||||
// m_config->comboBox_Ports->setEnabled(true);
|
||||
}
|
||||
|
||||
QString PipXtremeGadgetWidget::getPortDevice(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 "";
|
||||
}
|
||||
|
||||
void PipXtremeGadgetWidget::onTelemetryStart()
|
||||
{
|
||||
m_config->connectButton->setEnabled(false);
|
||||
m_config->comboBox_Ports->setEnabled(false);
|
||||
}
|
||||
|
||||
void PipXtremeGadgetWidget::onTelemetryStop()
|
||||
{
|
||||
m_config->connectButton->setEnabled(true);
|
||||
m_config->comboBox_Ports->setEnabled(true);
|
||||
}
|
||||
|
||||
void PipXtremeGadgetWidget::onTelemetryConnect()
|
||||
{
|
||||
}
|
||||
|
||||
void PipXtremeGadgetWidget::onTelemetryDisconnect()
|
||||
{
|
||||
}
|
||||
|
||||
void PipXtremeGadgetWidget::onModemConnect()
|
||||
{
|
||||
m_config->connectButton->setText(tr(" Disconnect "));
|
||||
m_config->comboBox_Ports->setEnabled(false);
|
||||
m_config->pushButton_ScanSpectrum->setEnabled(true);
|
||||
}
|
||||
|
||||
void PipXtremeGadgetWidget::onModemDisconnect()
|
||||
{
|
||||
m_config->connectButton->setText(tr(" Connect "));
|
||||
m_config->comboBox_Ports->setEnabled(true);
|
||||
m_config->pushButton_ScanSpectrum->setEnabled(false);
|
||||
}
|
||||
|
||||
void PipXtremeGadgetWidget::suspendTelemetry()
|
||||
{
|
||||
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
||||
if (!cm) return;
|
||||
|
||||
// Suspend telemety & polling
|
||||
cm->disconnectDevice();
|
||||
cm->suspendPolling();
|
||||
}
|
||||
|
||||
void PipXtremeGadgetWidget::processOutputStream()
|
||||
{
|
||||
if (!m_ioDevice)
|
||||
return;
|
||||
|
||||
// if (m_ioDevice->bytesToWrite() < TX_BUFFER_SIZE )
|
||||
{
|
||||
// m_ioDevice->write((const char*)txBuffer, dataOffset+length+CHECKSUM_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
void PipXtremeGadgetWidget::processInputStream()
|
||||
{
|
||||
while (m_ioDevice && m_ioDevice->bytesAvailable() > 0)
|
||||
{
|
||||
quint8 tmp;
|
||||
m_ioDevice->read((char*)&tmp, 1);
|
||||
|
||||
// processInputByte(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
void PipXtremeGadgetWidget::restartTelemetryPolling()
|
||||
{
|
||||
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
||||
if (!cm) return;
|
||||
|
||||
// Restart the polling thread
|
||||
cm->resumePolling();
|
||||
}
|
||||
|
||||
// Ask the modem to go into API mode
|
||||
void PipXtremeGadgetWidget::goToAPIMode(UAVObject* callerObj, bool success)
|
||||
{
|
||||
Q_UNUSED(callerObj);
|
||||
/*
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
UAVObject *fwIAP = dynamic_cast<UAVDataObject*>(objManager->getObject(QString("FirmwareIAPObj")));
|
||||
|
||||
switch (currentStep)
|
||||
{
|
||||
case IAP_STATE_READY:
|
||||
getPorts(); // Useful in case a new serial port appeared since the initial list,
|
||||
// otherwise we won't find it when we stop the board.
|
||||
|
||||
// The board is running, send the 1st IAP Reset order:
|
||||
fwIAP->getField("Command")->setValue("1122");
|
||||
connect(fwIAP,SIGNAL(transactionCompleted(UAVObject*,bool)),this,SLOT(goToAPIMode(UAVObject*, bool)));
|
||||
currentStep = IAP_STATE_STEP_1;
|
||||
fwIAP->updated();
|
||||
|
||||
break;
|
||||
|
||||
case IAP_STATE_STEP_1:
|
||||
if (!success)
|
||||
{
|
||||
currentStep = IAP_STATE_READY;
|
||||
disconnect(fwIAP, SIGNAL(transactionCompleted(UAVObject*,bool)),this,SLOT(goToAPIMode(UAVObject*, bool)));
|
||||
break;
|
||||
}
|
||||
|
||||
delay::msleep(600);
|
||||
|
||||
fwIAP->getField("Command")->setValue("2233");
|
||||
currentStep = IAP_STATE_READY;
|
||||
fwIAP->updated();
|
||||
|
||||
break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// Tells the system to boot (from Bootloader state)
|
||||
void PipXtremeGadgetWidget::systemBoot()
|
||||
{
|
||||
/*
|
||||
// Suspend telemety & polling in case it is not done yet
|
||||
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
||||
cm->disconnectDevice();
|
||||
cm->suspendPolling();
|
||||
|
||||
QString devName = m_config->comboBox_Ports->currentText();
|
||||
repaint();
|
||||
|
||||
if (!dfu)
|
||||
{
|
||||
if (devName == "USB")
|
||||
dfu = new DFUObject(DFU_DEBUG, false, QString());
|
||||
else
|
||||
dfu = new DFUObject(DFU_DEBUG,true,getPortDevice(devName));
|
||||
}
|
||||
dfu->AbortOperation();
|
||||
if (!dfu->enterDFU(0))
|
||||
{
|
||||
delete dfu;
|
||||
dfu = NULL;
|
||||
|
||||
return;
|
||||
}
|
||||
dfu->JumpToApp();
|
||||
// Restart the polling thread
|
||||
cm->resumePolling();
|
||||
|
||||
m_config->comboBox_Ports->setEnabled(true);
|
||||
if (currentStep == IAP_STATE_BOOTLOADER )
|
||||
{
|
||||
}
|
||||
currentStep = IAP_STATE_READY;
|
||||
delete dfu; // Frees up the USB/Serial port too
|
||||
dfu = NULL;
|
||||
*/
|
||||
}
|
||||
|
||||
// ***************************************************************************************
|
||||
|
||||
// Shows a message box with an error string.
|
||||
void PipXtremeGadgetWidget::error(QString errorString, int errorNumber)
|
||||
{
|
||||
Q_UNUSED(errorNumber);
|
||||
QMessageBox msgBox;
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.setText(errorString + " [" + QString::number(errorNumber) + "]");
|
||||
msgBox.exec();
|
||||
}
|
||||
|
@ -1,106 +1,162 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pipxtremegadgetwidget.h
|
||||
* @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
|
||||
*/
|
||||
|
||||
#ifndef PIPXTREMEGADGETWIDGET_H
|
||||
#define PIPXTREMEGADGETWIDGET_H
|
||||
|
||||
#include "ui_pipxtreme.h"
|
||||
#include "delay.h"
|
||||
|
||||
#include <qextserialport.h>
|
||||
#include <qextserialenumerator.h>
|
||||
|
||||
#include "uavtalk/telemetrymanager.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
#include "uavobjects/uavobject.h"
|
||||
#include "rawhid/rawhidplugin.h"
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QThread>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
#include <QtCore/QVector>
|
||||
#include <QtCore/QIODevice>
|
||||
#include <QtCore/QLinkedList>
|
||||
/*
|
||||
class IConnection;
|
||||
|
||||
struct devListItem
|
||||
{
|
||||
IConnection *connection;
|
||||
QString devName;
|
||||
QString displayedName;
|
||||
};
|
||||
*/
|
||||
class PipXtremeGadgetWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PipXtremeGadgetWidget(QWidget *parent = 0);
|
||||
~PipXtremeGadgetWidget();
|
||||
|
||||
typedef enum { IAP_STATE_READY, IAP_STATE_STEP_1} IAPStep;
|
||||
typedef enum { RESCUE_STEP0, RESCUE_STEP1, RESCUE_STEP2, RESCUE_STEP3, RESCUE_POWER1, RESCUE_POWER2, RESCUE_DETECT } RescueStep;
|
||||
|
||||
public slots:
|
||||
void onTelemetryConnect();
|
||||
void onTelemetryDisconnect();
|
||||
void onModemConnect();
|
||||
void onModemDisconnect();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
|
||||
private:
|
||||
Ui_PipXtremeWidget *m_config;
|
||||
|
||||
IAPStep currentStep;
|
||||
RescueStep rescueStep;
|
||||
bool resetOnly;
|
||||
|
||||
// QLinkedList<devListItem> m_devList;
|
||||
// QList<IConnection*> m_connectionsList;
|
||||
|
||||
// currently connected connection plugin
|
||||
// devListItem m_connectionDevice;
|
||||
|
||||
// currently connected QIODevice
|
||||
QIODevice *m_ioDev;
|
||||
|
||||
QString getPortDevice(const QString &friendName);
|
||||
|
||||
private slots:
|
||||
void error(QString errorString,int errorNumber);
|
||||
void goToAPIMode(UAVObject* = NULL, bool = false);
|
||||
void systemReset();
|
||||
void systemBoot();
|
||||
void getPorts();
|
||||
};
|
||||
|
||||
#endif
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file pipxtremegadgetwidget.h
|
||||
* @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
|
||||
*/
|
||||
|
||||
#ifndef PIPXTREMEGADGETWIDGET_H
|
||||
#define PIPXTREMEGADGETWIDGET_H
|
||||
|
||||
#include "ui_pipxtreme.h"
|
||||
#include "delay.h"
|
||||
|
||||
#include <qextserialport.h>
|
||||
#include <qextserialenumerator.h>
|
||||
|
||||
#include "uavtalk/telemetrymanager.h"
|
||||
#include "extensionsystem/pluginmanager.h"
|
||||
#include "uavobjects/uavobjectmanager.h"
|
||||
#include "uavobjects/uavobject.h"
|
||||
|
||||
#include "rawhid/rawhidplugin.h"
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QThread>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
#include <QtCore/QVector>
|
||||
#include <QtCore/QIODevice>
|
||||
#include <QtCore/QLinkedList>
|
||||
|
||||
// *************************
|
||||
// pipx config comms packets
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t marker;
|
||||
uint32_t serial_number;
|
||||
uint8_t type;
|
||||
uint8_t spare;
|
||||
uint16_t data_size;
|
||||
uint32_t crc;
|
||||
uint8_t data[0];
|
||||
} t_pipx_header;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t mode;
|
||||
uint8_t state;
|
||||
} t_pipx_data_mode_state;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t serial_baudrate; // serial uart baudrate
|
||||
|
||||
uint32_t destination_id;
|
||||
|
||||
uint32_t min_frequency_Hz;
|
||||
uint32_t max_frequency_Hz;
|
||||
uint32_t frequency_Hz;
|
||||
|
||||
uint32_t max_rf_bandwidth;
|
||||
|
||||
uint8_t max_tx_power;
|
||||
|
||||
uint8_t frequency_band;
|
||||
|
||||
uint8_t rf_xtal_cap;
|
||||
|
||||
bool aes_enable;
|
||||
uint8_t aes_key[16];
|
||||
|
||||
uint16_t frequency_step_size;
|
||||
} t_pipx_data_settings;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t start_frequency;
|
||||
uint16_t frequency_step_size;
|
||||
uint16_t magnitudes;
|
||||
int8_t magnitude[0];
|
||||
} t_pipx_data_spectrum;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
// *************************
|
||||
|
||||
class PipXtremeGadgetWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PipXtremeGadgetWidget(QWidget *parent = 0);
|
||||
~PipXtremeGadgetWidget();
|
||||
|
||||
typedef enum { IAP_STATE_READY, IAP_STATE_STEP_1} IAPStep;
|
||||
typedef enum { RESCUE_STEP0, RESCUE_STEP1, RESCUE_STEP2, RESCUE_STEP3, RESCUE_POWER1, RESCUE_POWER2, RESCUE_DETECT } RescueStep;
|
||||
|
||||
public slots:
|
||||
void onTelemetryStart();
|
||||
void onTelemetryStop();
|
||||
void onTelemetryConnect();
|
||||
void onTelemetryDisconnect();
|
||||
|
||||
void onModemConnect();
|
||||
void onModemDisconnect();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
|
||||
private:
|
||||
Ui_PipXtremeWidget *m_config;
|
||||
|
||||
IAPStep currentStep;
|
||||
RescueStep rescueStep;
|
||||
bool resetOnly;
|
||||
|
||||
pjrc_rawhid rawHidHandle;
|
||||
// RawHIDPlugin *rawHidPlugin;
|
||||
|
||||
// currently connected QIODevice
|
||||
QIODevice *m_ioDevice;
|
||||
|
||||
|
||||
QString getPortDevice(const QString &friendName);
|
||||
|
||||
void suspendTelemetry();
|
||||
void restartTelemetryPolling();
|
||||
|
||||
void processOutputStream();
|
||||
void processInputStream();
|
||||
|
||||
private slots:
|
||||
void error(QString errorString,int errorNumber);
|
||||
void goToAPIMode(UAVObject* = NULL, bool = false);
|
||||
void systemBoot();
|
||||
void getPorts();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user