1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-19 09:54:15 +01:00

PipX plugin now connects/disconnects from communications port. Have yet to write the comms stream routine/thread and packet protocol.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2627 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
pip 2011-01-30 13:28:22 +00:00 committed by pip
parent 1ae14c5682
commit 89df836c23
4 changed files with 300 additions and 100 deletions

View File

@ -17,7 +17,6 @@ HEADERS += pipxtremegadget.h \
pipxtremegadgetwidget.h \
pipxtremeplugin.h \
delay.h \
devicewidget.h \
SSP/port.h \
SSP/qssp.h \
SSP/qsspt.h \

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>570</width>
<height>381</height>
<height>407</height>
</rect>
</property>
<property name="windowTitle">
@ -15,8 +15,67 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="1">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Serial Baudrate</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QComboBox" name="comboBox_SerialBaudrate">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QComboBox" name="comboBox_Ports">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Set the PC port the modem is connected too</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="connectButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="mouseTracking">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Connect to the modem (when normal telemetry is not used)</string>
</property>
<property name="text">
<string> Connect </string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QToolButton" name="refreshPorts">
<property name="toolTip">
<string>Refresh the list of serial and USB ports available</string>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -29,70 +88,27 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="connectButton">
<property name="enabled">
<bool>true</bool>
<item row="2" column="0">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="mouseTracking">
<bool>true</bool>
</property>
<property name="toolTip">
<string>Tells the mainboard to go down
to bootloader mode.
(Only enabled if telemetry link is established, either
through serial or USB)</string>
</property>
<property name="text">
<string> Connect </string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_Ports">
<property name="minimumSize">
<property name="sizeHint" stdset="0">
<size>
<width>200</width>
<height>0</height>
<width>40</width>
<height>20</height>
</size>
</property>
<property name="toolTip">
<string>When telemetry is not connected, select the communication
method using this combo box.
You can use this to force a communication channel when doing
a &quot;Boot&quot; (button on the left). It is updated automatically when
halting a running board.</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="refreshPorts">
<property name="toolTip">
<string>Refresh the list of serial ports</string>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>8</height>
</size>
</property>
</spacer>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
@ -175,6 +191,9 @@ halting a running board.</string>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Serial number of the remote modem you want to pair with</string>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
@ -431,6 +450,9 @@ halting a running board.</string>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Set the modems serial port speed</string>
</property>
</widget>
</item>
<item row="5" column="3">
@ -441,6 +463,9 @@ halting a running board.</string>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Set the maximum TX output power the modem will use</string>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
@ -457,6 +482,9 @@ halting a running board.</string>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Set the maximum RF datarate/channel bandwidth the modem will use</string>
</property>
</widget>
</item>
<item row="3" column="3">
@ -473,6 +501,9 @@ halting a running board.</string>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Set the modems RF carrier frequency</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
@ -507,6 +538,9 @@ halting a running board.</string>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Calibrate the modems RF carrier frequency</string>
</property>
<property name="accelerated">
<bool>true</bool>
</property>
@ -583,6 +617,9 @@ halting a running board.</string>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Set the modems operating mode</string>
</property>
</widget>
</item>
</layout>
@ -602,7 +639,7 @@ halting a running board.</string>
<item>
<widget class="QLineEdit" name="lineEdit_AESKey">
<property name="toolTip">
<string>The AES encryption key</string>
<string>The AES encryption key - has to be the same key on the remote modem as well)</string>
</property>
<property name="styleSheet">
<string notr="true"/>
@ -633,6 +670,9 @@ halting a running board.</string>
</item>
<item>
<widget class="QCheckBox" name="checkBox_AESEnable">
<property name="toolTip">
<string>Enable/Disable AES encryption</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
@ -644,27 +684,18 @@ halting a running board.</string>
</layout>
</item>
<item>
<spacer name="verticalSpacer_3">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>8</height>
</size>
</property>
</spacer>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QPushButton" name="pushButton_ScanSpectrum">
<property name="toolTip">
<string>Scan whole band</string>
<string>Scan whole band to see where their is interference and/or used channels</string>
</property>
<property name="text">
<string> Scan Spectrum </string>

View File

@ -47,18 +47,33 @@ PipXtremeGadgetWidget::PipXtremeGadgetWidget(QWidget *parent) : QWidget(parent)
m_config->comboBox_Mode->addItem("Tx Carrier Calibrate", 2);
m_config->comboBox_Mode->addItem("Tx Spectrum Test", 3);
m_config->comboBox_SerialBaudrate->clear();
m_config->comboBox_SerialBaudrate->addItem("1200", 1200);
m_config->comboBox_SerialBaudrate->addItem("2400", 2400);
m_config->comboBox_SerialBaudrate->addItem("4800", 4800);
m_config->comboBox_SerialBaudrate->addItem("9600", 9600);
m_config->comboBox_SerialBaudrate->addItem("19200", 19200);
m_config->comboBox_SerialBaudrate->addItem("38400", 38400);
m_config->comboBox_SerialBaudrate->addItem("57600", 57600);
m_config->comboBox_SerialBaudrate->addItem("115200", 115200);
// m_config->comboBox_SerialBaudrate->addItem("230400", 230400);
// m_config->comboBox_SerialBaudrate->addItem("460800", 460800);
// m_config->comboBox_SerialBaudrate->addItem("921600", 921600);
m_config->comboBox_SerialBaudrate->setCurrentIndex(m_config->comboBox_SerialBaudrate->findText("57600"));
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->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->comboBox_SerialPortSpeed->setCurrentIndex(m_config->comboBox_SerialPortSpeed->findText("57600"));
m_config->doubleSpinBox_Frequency->setSingleStep(0.00015625);
@ -93,7 +108,7 @@ PipXtremeGadgetWidget::PipXtremeGadgetWidget(QWidget *parent) : QWidget(parent)
// int opened = rawHidHandle.open(10, 0x20A0, 0x4117, 0xFF9C, 0x0001);
// rawHidPlugin = new RawHIDPlugin();
connect(m_config->connectButton, SIGNAL(clicked()), this, SLOT(goToAPIMode()));
connect(m_config->connectButton, SIGNAL(clicked()), this, SLOT(connectDisconnect()));
getPorts();
@ -109,9 +124,10 @@ PipXtremeGadgetWidget::PipXtremeGadgetWidget(QWidget *parent) : QWidget(parent)
// delay::msleep(600); // just for pips reference
}
// destructor
// destructor .. this never gets called :(
PipXtremeGadgetWidget::~PipXtremeGadgetWidget()
{
disconnect(false);
}
void PipXtremeGadgetWidget::resizeEvent(QResizeEvent *event)
@ -158,7 +174,10 @@ void PipXtremeGadgetWidget::getPorts()
foreach (QextPortInfo port, ports)
list.append(port.friendName);
m_config->comboBox_Ports->addItems(list);
for (int i = 0; i < list.count(); i++)
m_config->comboBox_Ports->addItem(list.at(i), 0);
// m_config->comboBox_Ports->addItems(list);
// ********************************
// Populate the telemetry combo box with usb ports
@ -174,7 +193,10 @@ void PipXtremeGadgetWidget::getPorts()
for (int i = 0; i < opened; i++)
usb_ports.append(rawHidHandle->getserial(i));
m_config->comboBox_Ports->addItems(usb_ports);
for (int i = 0; i < usb_ports.count(); i++)
m_config->comboBox_Ports->addItem(usb_ports.at(i), 1);
// m_config->comboBox_Ports->addItems(usb_ports);
}
delete rawHidHandle;
@ -204,6 +226,8 @@ QString PipXtremeGadgetWidget::getPortDevice(const QString &friendName)
return "";
}
// *************************************************************************
void PipXtremeGadgetWidget::onTelemetryStart()
{
m_config->connectButton->setEnabled(false);
@ -216,6 +240,8 @@ void PipXtremeGadgetWidget::onTelemetryStop()
m_config->comboBox_Ports->setEnabled(true);
}
// *************************************************************************
void PipXtremeGadgetWidget::onTelemetryConnect()
{
}
@ -224,6 +250,8 @@ void PipXtremeGadgetWidget::onTelemetryDisconnect()
{
}
// *************************************************************************
void PipXtremeGadgetWidget::onModemConnect()
{
m_config->connectButton->setText(tr(" Disconnect "));
@ -238,21 +266,37 @@ void PipXtremeGadgetWidget::onModemDisconnect()
m_config->pushButton_ScanSpectrum->setEnabled(false);
}
// *************************************************************************
void PipXtremeGadgetWidget::suspendTelemetry()
{
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
if (!cm) return;
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
if (!cm) return;
// Suspend telemety & polling
cm->disconnectDevice();
cm->suspendPolling();
// Suspend telemety & polling
cm->disconnectDevice();
cm->suspendPolling();
}
void PipXtremeGadgetWidget::restartTelemetryPolling()
{
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
if (!cm) return;
// Restart the polling thread
cm->resumePolling();
}
// *************************************************************************
void PipXtremeGadgetWidget::processOutputStream()
{
if (!m_ioDevice)
return;
if (!m_ioDevice->isOpen())
return;
// if (m_ioDevice->bytesToWrite() < TX_BUFFER_SIZE )
{
// m_ioDevice->write((const char*)txBuffer, dataOffset+length+CHECKSUM_LENGTH);
@ -270,15 +314,139 @@ void PipXtremeGadgetWidget::processInputStream()
}
}
void PipXtremeGadgetWidget::restartTelemetryPolling()
{
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
if (!cm) return;
// *************************************************************************
// Restart the polling thread
cm->resumePolling();
void PipXtremeGadgetWidget::disconnect(bool resume_polling)
{ // disconnect the comms port
if (!m_ioDevice)
return;
m_ioDevice->close();
delete m_ioDevice;
m_ioDevice = NULL;
m_config->connectButton->setText("Connect");
m_config->comboBox_SerialBaudrate->setEnabled(true);
m_config->comboBox_Ports->setEnabled(true);
m_config->refreshPorts->setEnabled(true);
restartTelemetryPolling();
}
void PipXtremeGadgetWidget::connectDisconnect()
{
if (m_ioDevice)
{ // disconnect
disconnect(true);
return;
}
// ****************
// connect
int device_idx = m_config->comboBox_Ports->currentIndex();
if (device_idx < 0)
return;
QString device_str = m_config->comboBox_Ports->currentText().trimmed();
if (device_str.isEmpty())
return;
int type = m_config->comboBox_Ports->itemData(device_idx).toInt();
// qDebug() << QString::number(type) << ": " << device_str;
// Suspend telemety & polling in case it is not done yet
suspendTelemetry();
switch (type)
{
case 0: // serial port
{
QString str = getPortDevice(device_str);
if (str.isEmpty())
break;
int br_idx = m_config->comboBox_SerialBaudrate->currentIndex();
if (br_idx < 0)
break;
int baudrate = m_config->comboBox_SerialBaudrate->itemData(br_idx).toInt();
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;
QextSerialPort *serial_dev = new QextSerialPort(str, settings, QextSerialPort::Polling);
if (!serial_dev)
break;
if (!serial_dev->open(QIODevice::ReadWrite | QIODevice::Unbuffered))
{
delete serial_dev;
break;
}
m_ioDevice = serial_dev;
m_config->connectButton->setText("Disconnect");
m_config->comboBox_SerialBaudrate->setEnabled(false);
m_config->comboBox_Ports->setEnabled(false);
m_config->refreshPorts->setEnabled(false);
return;
}
case 1: // USB port
{
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;
m_config->connectButton->setText("Disconnect");
m_config->comboBox_SerialBaudrate->setEnabled(false);
m_config->comboBox_Ports->setEnabled(false);
m_config->refreshPorts->setEnabled(false);
return;
}
default: // unknown
break;
}
restartTelemetryPolling();
}
// *************************************************************************
// Ask the modem to go into API mode
void PipXtremeGadgetWidget::goToAPIMode(UAVObject* callerObj, bool success)
{

View File

@ -143,7 +143,6 @@ private:
// currently connected QIODevice
QIODevice *m_ioDevice;
QString getPortDevice(const QString &friendName);
void suspendTelemetry();
@ -152,8 +151,11 @@ private:
void processOutputStream();
void processInputStream();
void disconnect(bool resume_polling);
private slots:
void error(QString errorString,int errorNumber);
void connectDisconnect();
void error(QString errorString,int errorNumber);
void goToAPIMode(UAVObject* = NULL, bool = false);
void systemBoot();
void getPorts();