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-02-04 17:17:57 +01:00
|
|
|
#include <QSettings>
|
2011-02-04 18:29:52 +01:00
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFileDialog>
|
2011-02-01 23:58:04 +01:00
|
|
|
#include <stdlib.h>
|
2011-01-26 13:01:09 +01:00
|
|
|
|
|
|
|
#include "pipxtremegadgetwidget.h"
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
#define NO_PORT 0
|
2011-01-31 22:46:42 +01:00
|
|
|
#define SERIAL_PORT 1
|
|
|
|
#define USB_PORT 2
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
// ***************************************************************************************
|
|
|
|
// config packet details
|
|
|
|
|
|
|
|
#define MAX_RETRIES 7
|
|
|
|
#define RETRY_TIME 500 // ms
|
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
#define PIPX_HEADER_MARKER 0x76b38a52
|
2011-02-01 23:58:04 +01:00
|
|
|
|
2011-02-06 11:55:08 +01:00
|
|
|
enum {
|
|
|
|
PIPX_PACKET_TYPE_REQ_DETAILS = 0,
|
|
|
|
PIPX_PACKET_TYPE_DETAILS,
|
|
|
|
PIPX_PACKET_TYPE_REQ_SETTINGS,
|
|
|
|
PIPX_PACKET_TYPE_SETTINGS,
|
|
|
|
PIPX_PACKET_TYPE_REQ_STATE,
|
2011-02-23 10:35:30 +01:00
|
|
|
PIPX_PACKET_TYPE_STATE,
|
|
|
|
PIPX_PACKET_TYPE_SPECTRUM
|
2011-02-06 11:55:08 +01:00
|
|
|
};
|
2011-02-01 23:58:04 +01:00
|
|
|
|
|
|
|
enum {
|
2011-02-06 11:55:08 +01:00
|
|
|
FREQBAND_UNKNOWN = 0,
|
|
|
|
FREQBAND_434MHz,
|
|
|
|
FREQBAND_868MHz,
|
|
|
|
FREQBAND_915MHz
|
2011-02-01 23:58:04 +01:00
|
|
|
};
|
2011-01-31 22:46:42 +01:00
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
enum {
|
2011-02-06 11:55:08 +01:00
|
|
|
LINK_DISCONNECTED = 0,
|
|
|
|
LINK_CONNECTING,
|
|
|
|
LINK_CONNECTED
|
2011-02-03 08:04:46 +01:00
|
|
|
};
|
|
|
|
|
2011-01-31 22:46:42 +01:00
|
|
|
// ***************************************************************************************
|
|
|
|
|
2011-02-05 00:00:48 +01:00
|
|
|
enum {
|
2011-02-06 11:55:08 +01:00
|
|
|
MODE_NORMAL = 0, // normal 2-way packet mode
|
|
|
|
MODE_STREAM_TX, // 1-way continuous tx packet mode
|
|
|
|
MODE_STREAM_RX, // 1-way continuous rx packet mode
|
|
|
|
MODE_PPM_TX, // PPM tx mode
|
|
|
|
MODE_PPM_RX, // PPM rx mode
|
|
|
|
MODE_SCAN_SPECTRUM, // scan the receiver over the whole band
|
|
|
|
MODE_TX_BLANK_CARRIER_TEST, // blank carrier Tx mode (for calibrating the carrier frequency say)
|
|
|
|
MODE_TX_SPECTRUM_TEST // pseudo random Tx data mode (for checking the Tx carrier spectrum)
|
2011-02-05 00:00:48 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// ***************************************************************************************
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
#define Poly32 0x04c11db7 // 32-bit polynomial .. this should produce the same as the STM32 hardware CRC
|
2011-01-31 22:46:42 +01:00
|
|
|
|
|
|
|
uint32_t CRC_Table32[] = {
|
|
|
|
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
|
|
|
|
0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
|
|
|
|
0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
|
|
|
|
0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd,
|
|
|
|
0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5,
|
|
|
|
0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,
|
|
|
|
0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,
|
|
|
|
0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d,
|
|
|
|
0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
|
|
|
|
0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca,
|
|
|
|
0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02,
|
|
|
|
0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
|
|
|
|
0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692,
|
|
|
|
0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a,
|
|
|
|
0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,
|
|
|
|
0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a,
|
|
|
|
0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,
|
|
|
|
0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
|
|
|
|
0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b,
|
|
|
|
0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623,
|
|
|
|
0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,
|
|
|
|
0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,
|
|
|
|
0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b,
|
|
|
|
0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,
|
|
|
|
0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c,
|
|
|
|
0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24,
|
|
|
|
0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
|
|
|
|
0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654,
|
|
|
|
0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c,
|
|
|
|
0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,
|
|
|
|
0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c,
|
|
|
|
0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
|
|
|
|
};
|
2011-01-31 11:16:06 +01:00
|
|
|
|
|
|
|
// ***************************************************************************************
|
|
|
|
|
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),
|
2011-02-01 23:58:04 +01:00
|
|
|
m_ioDevice(NULL),
|
|
|
|
m_stage(PIPX_IDLE)
|
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);
|
|
|
|
|
2011-02-04 16:02:46 +01:00
|
|
|
// qsrand(QDateTime::currentDateTime().toMSecsSinceEpoch()); // only available with Qt 4.7.1 and later
|
|
|
|
qsrand(QDateTime::currentDateTime().toTime_t());
|
2011-02-03 08:04:46 +01:00
|
|
|
|
2011-01-31 22:46:42 +01:00
|
|
|
device_input_buffer.size = 8192;
|
|
|
|
device_input_buffer.used = 0;
|
|
|
|
device_input_buffer.buffer = new quint8 [device_input_buffer.size];
|
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
memset(&pipx_config_details, 0, sizeof(pipx_config_details));
|
|
|
|
memset(&pipx_config_settings, 0, sizeof(pipx_config_settings));
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
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);
|
2011-02-03 14:12:30 +01:00
|
|
|
#if (defined Q_OS_WIN)
|
|
|
|
m_widget->comboBox_SerialBaudrate->addItem("230400", 230400);
|
|
|
|
m_widget->comboBox_SerialBaudrate->addItem("460800", 460800);
|
|
|
|
m_widget->comboBox_SerialBaudrate->addItem("921600", 921600);
|
|
|
|
#endif
|
2011-01-31 11:16:06 +01:00
|
|
|
m_widget->comboBox_SerialBaudrate->setCurrentIndex(m_widget->comboBox_SerialBaudrate->findText("57600"));
|
|
|
|
|
|
|
|
m_widget->comboBox_Mode->clear();
|
2011-02-06 11:55:08 +01:00
|
|
|
m_widget->comboBox_Mode->addItem("Normal", MODE_NORMAL);
|
|
|
|
m_widget->comboBox_Mode->addItem("Continuous Stream Tx", MODE_STREAM_TX);
|
|
|
|
m_widget->comboBox_Mode->addItem("Continuous Stream Rx", MODE_STREAM_RX);
|
|
|
|
m_widget->comboBox_Mode->addItem("PPM Tx", MODE_PPM_TX);
|
|
|
|
m_widget->comboBox_Mode->addItem("PPM Rx", MODE_PPM_RX);
|
|
|
|
m_widget->comboBox_Mode->addItem("Scan Spectrum", MODE_SCAN_SPECTRUM);
|
|
|
|
m_widget->comboBox_Mode->addItem("Test Tx Blank Carrier Frequency", MODE_TX_BLANK_CARRIER_TEST);
|
|
|
|
m_widget->comboBox_Mode->addItem("Test Tx Spectrum", MODE_TX_SPECTRUM_TEST);
|
2011-01-31 11:16:06 +01:00
|
|
|
|
|
|
|
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"));
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
m_widget->comboBox_MaxRFBandwidth->clear();
|
|
|
|
m_widget->comboBox_MaxRFBandwidth->addItem("500", 500);
|
|
|
|
m_widget->comboBox_MaxRFBandwidth->addItem("1000", 1000);
|
|
|
|
m_widget->comboBox_MaxRFBandwidth->addItem("2000", 2000);
|
|
|
|
m_widget->comboBox_MaxRFBandwidth->addItem("4000", 4000);
|
|
|
|
m_widget->comboBox_MaxRFBandwidth->addItem("8000", 8000);
|
|
|
|
m_widget->comboBox_MaxRFBandwidth->addItem("9600", 9600);
|
|
|
|
m_widget->comboBox_MaxRFBandwidth->addItem("16000", 16000);
|
|
|
|
m_widget->comboBox_MaxRFBandwidth->addItem("19200", 19200);
|
|
|
|
m_widget->comboBox_MaxRFBandwidth->addItem("24000", 24000);
|
|
|
|
m_widget->comboBox_MaxRFBandwidth->addItem("32000", 32000);
|
|
|
|
m_widget->comboBox_MaxRFBandwidth->addItem("64000", 64000);
|
|
|
|
m_widget->comboBox_MaxRFBandwidth->addItem("128000", 128000);
|
|
|
|
m_widget->comboBox_MaxRFBandwidth->addItem("192000", 192000);
|
|
|
|
m_widget->comboBox_MaxRFBandwidth->setCurrentIndex(m_widget->comboBox_MaxRFBandwidth->findText("128000"));
|
|
|
|
|
|
|
|
m_widget->comboBox_MaxRFTxPower->clear();
|
|
|
|
m_widget->comboBox_MaxRFTxPower->addItem("1.25mW", 0);
|
|
|
|
m_widget->comboBox_MaxRFTxPower->addItem("1.6mW", 1);
|
|
|
|
m_widget->comboBox_MaxRFTxPower->addItem("3.16mW", 2);
|
|
|
|
m_widget->comboBox_MaxRFTxPower->addItem("6.3mW", 3);
|
|
|
|
m_widget->comboBox_MaxRFTxPower->addItem("12.6mW", 4);
|
|
|
|
m_widget->comboBox_MaxRFTxPower->addItem("25mW", 5);
|
|
|
|
m_widget->comboBox_MaxRFTxPower->addItem("50mW", 6);
|
|
|
|
m_widget->comboBox_MaxRFTxPower->addItem("100mW", 7);
|
|
|
|
m_widget->comboBox_MaxRFTxPower->setCurrentIndex(m_widget->comboBox_MaxRFTxPower->findText("12.6mW"));
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
m_widget->doubleSpinBox_Frequency->setSingleStep(0.00015625);
|
|
|
|
|
|
|
|
m_widget->progressBar_RSSI->setMinimum(-120);
|
2011-02-06 22:21:50 +01:00
|
|
|
m_widget->progressBar_RSSI->setMaximum(0);
|
2011-02-03 15:33:09 +01:00
|
|
|
m_widget->progressBar_RSSI->setValue(m_widget->progressBar_RSSI->minimum());
|
2011-01-31 11:16:06 +01:00
|
|
|
|
2011-02-04 17:17:57 +01:00
|
|
|
m_widget->label_RSSI->setText("RSSI");
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
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-02-01 23:58:04 +01:00
|
|
|
m_widget->pushButton_Save->setEnabled(false);
|
2011-01-31 11:16:06 +01:00
|
|
|
m_widget->pushButton_ScanSpectrum->setEnabled(false);
|
2011-02-04 17:17:57 +01:00
|
|
|
m_widget->pushButton_Import->setEnabled(false);
|
|
|
|
m_widget->pushButton_Export->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-02-01 23:58:04 +01:00
|
|
|
connect(m_widget->pushButton_AESKeyRandom, SIGNAL(clicked()), this, SLOT(randomiseAESKey()));
|
|
|
|
connect(m_widget->pushButton_ScanSpectrum, SIGNAL(clicked()), this, SLOT(scanSpectrum()));
|
|
|
|
connect(m_widget->pushButton_Save, SIGNAL(clicked()), this, SLOT(saveToFlash()));
|
2011-02-02 15:00:33 +01:00
|
|
|
connect(m_widget->lineEdit_AESKey, SIGNAL(textChanged(const QString &)), this, SLOT(textChangedAESKey(const QString &)));
|
2011-02-04 17:17:57 +01:00
|
|
|
connect(m_widget->pushButton_Import, SIGNAL(clicked()), this, SLOT(importSettings()));
|
|
|
|
connect(m_widget->pushButton_Export, SIGNAL(clicked()), this, SLOT(exportSettings()));
|
2011-01-26 13:01:09 +01:00
|
|
|
}
|
|
|
|
|
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-31 22:46:42 +01:00
|
|
|
|
|
|
|
device_input_buffer.mutex.lock();
|
|
|
|
if (device_input_buffer.buffer)
|
|
|
|
{
|
|
|
|
delete [] device_input_buffer.buffer;
|
|
|
|
device_input_buffer.buffer = NULL;
|
|
|
|
device_input_buffer.size = 0;
|
|
|
|
device_input_buffer.used = 0;
|
|
|
|
}
|
|
|
|
device_input_buffer.mutex.unlock();
|
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-02-01 23:58:04 +01:00
|
|
|
uint32_t PipXtremeGadgetWidget::updateCRC32(uint32_t crc, uint8_t b)
|
|
|
|
{
|
|
|
|
return (crc << 8) ^ CRC_Table32[(crc >> 24) ^ b];
|
|
|
|
}
|
|
|
|
|
2011-01-31 22:46:42 +01:00
|
|
|
uint32_t PipXtremeGadgetWidget::updateCRC32Data(uint32_t crc, void *data, int len)
|
|
|
|
{
|
2011-02-01 23:58:04 +01:00
|
|
|
register uint8_t *p = (uint8_t *)data;
|
|
|
|
register uint32_t _crc = crc;
|
2011-01-31 22:46:42 +01:00
|
|
|
for (int i = len; i > 0; i--)
|
|
|
|
_crc = (_crc << 8) ^ CRC_Table32[(_crc >> 24) ^ *p++];
|
|
|
|
return _crc;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate the CRC table
|
|
|
|
void PipXtremeGadgetWidget::makeCRC_Table32()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 256; i++)
|
|
|
|
{
|
|
|
|
uint32_t crc = i;
|
|
|
|
for (int j = 8; j > 0; j--)
|
|
|
|
crc = (crc & 1) ? (crc << 1) ^ Poly32 : crc << 1;
|
|
|
|
CRC_Table32[i] = crc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ***************************************************************************************
|
|
|
|
|
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()
|
|
|
|
{
|
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 22:46:42 +01:00
|
|
|
QStringList list;
|
|
|
|
|
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-02-01 23:58:04 +01:00
|
|
|
m_widget->comboBox_Ports->addItem("com: " + 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++)
|
2011-02-01 23:58:04 +01:00
|
|
|
m_widget->comboBox_Ports->addItem("usb: " + 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-02-01 23:58:04 +01:00
|
|
|
void PipXtremeGadgetWidget::randomiseAESKey()
|
|
|
|
{
|
2011-02-04 16:02:46 +01:00
|
|
|
// uint32_t crc = ((uint32_t)qrand() << 16) ^ qrand() ^ QDateTime::currentDateTime().toMSecsSinceEpoch(); // only available with Qt 4.7.1 and later
|
|
|
|
uint32_t crc = ((uint32_t)qrand() << 16) ^ qrand() ^ QDateTime::currentDateTime().toTime_t();
|
2011-02-01 23:58:04 +01:00
|
|
|
|
|
|
|
QString key = "";
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
2011-02-02 18:20:02 +01:00
|
|
|
for (int i = 0; i < (27 + (qrand() & 0x7f)); i++)
|
2011-02-01 23:58:04 +01:00
|
|
|
crc = updateCRC32(crc, qrand());
|
|
|
|
|
2011-02-02 18:20:02 +01:00
|
|
|
key += QString::number(crc, 16).rightJustified(8, '0');
|
2011-02-01 23:58:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
m_widget->lineEdit_AESKey->setText(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PipXtremeGadgetWidget::scanSpectrum()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void PipXtremeGadgetWidget::saveToFlash()
|
2011-01-26 13:01:09 +01:00
|
|
|
{
|
2011-01-31 22:46:42 +01:00
|
|
|
QMutexLocker locker_dev(&device_mutex);
|
2011-02-01 23:58:04 +01:00
|
|
|
QMutexLocker locker_inbuf(&device_input_buffer.mutex);
|
2011-01-31 22:46:42 +01:00
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
if (!m_ioDevice) return;
|
|
|
|
if (!m_ioDevice->isOpen()) return;
|
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
if (pipx_config_details.serial_number == 0) return; // we first need some details before sending new setings
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
QString s;
|
|
|
|
bool ok;
|
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
t_pipx_config_settings settings;
|
2011-02-01 23:58:04 +01:00
|
|
|
|
2011-02-05 00:00:48 +01:00
|
|
|
settings.mode = m_widget->comboBox_Mode->itemData(m_widget->comboBox_Mode->currentIndex()).toUInt();
|
|
|
|
|
2011-02-02 12:46:11 +01:00
|
|
|
s = m_widget->lineEdit_PairedSerialNumber->text().trimmed().toLower();
|
|
|
|
s.replace(' ', ""); // remove all spaces
|
|
|
|
if (s.startsWith("0x"))
|
|
|
|
{
|
|
|
|
s.remove(0, 2);
|
|
|
|
s = s.trimmed();
|
|
|
|
}
|
2011-02-01 23:58:04 +01:00
|
|
|
settings.destination_id = s.toUInt(&ok, 16);
|
|
|
|
if (s.isEmpty() || !ok)
|
|
|
|
{
|
|
|
|
error("Check your \"Paired Serial Number\" entry!", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
settings.rf_xtal_cap = m_widget->spinBox_FrequencyCalibration->value();
|
2011-01-26 13:01:09 +01:00
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
s = m_widget->doubleSpinBox_Frequency->text().trimmed();
|
2011-02-02 12:46:11 +01:00
|
|
|
s.replace(' ', ""); // remove all spaces
|
2011-02-02 18:53:30 +01:00
|
|
|
settings.frequency_Hz = (uint32_t)(s.toDouble(&ok) * 1e6);
|
2011-02-03 08:04:46 +01:00
|
|
|
if (ok) // round it to the 'frequency step size'
|
|
|
|
settings.frequency_Hz = (uint32_t)(((double)settings.frequency_Hz + pipx_config_details.frequency_step_size / 2) / pipx_config_details.frequency_step_size) * pipx_config_details.frequency_step_size;
|
|
|
|
if (s.isEmpty() || !ok || settings.frequency_Hz < pipx_config_details.min_frequency_Hz || settings.frequency_Hz > pipx_config_details.max_frequency_Hz)
|
2011-02-01 23:58:04 +01:00
|
|
|
{
|
|
|
|
error("Check your \"Frequency\" entry!", 0);
|
|
|
|
return;
|
2011-01-31 11:16:06 +01:00
|
|
|
}
|
2011-02-01 23:58:04 +01:00
|
|
|
|
|
|
|
settings.max_rf_bandwidth = m_widget->comboBox_MaxRFBandwidth->itemData(m_widget->comboBox_MaxRFBandwidth->currentIndex()).toInt();
|
|
|
|
settings.max_tx_power = m_widget->comboBox_MaxRFTxPower->itemData(m_widget->comboBox_MaxRFTxPower->currentIndex()).toInt();
|
|
|
|
settings.serial_baudrate = m_widget->comboBox_SerialPortSpeed->itemData(m_widget->comboBox_SerialPortSpeed->currentIndex()).toInt();
|
|
|
|
settings.aes_enable = m_widget->checkBox_AESEnable->isChecked();
|
2011-02-15 13:57:46 +01:00
|
|
|
settings.rts_time = m_widget->spinBox_RTSTime->value();
|
2011-02-01 23:58:04 +01:00
|
|
|
|
|
|
|
memset(settings.aes_key, 0, sizeof(settings.aes_key));
|
|
|
|
s = m_widget->lineEdit_AESKey->text().trimmed();
|
2011-02-02 12:46:11 +01:00
|
|
|
s.replace(' ', ""); // remove all spaces
|
2011-02-02 15:00:33 +01:00
|
|
|
while (s.length() < 32) s = '0' + s;
|
2011-02-01 23:58:04 +01:00
|
|
|
if (settings.aes_enable && s.length() != 32)
|
|
|
|
{
|
|
|
|
error("Check your \"AES Key\" entry! .. it must be 32 hex characters long", 0);
|
|
|
|
return;
|
|
|
|
}
|
2011-02-02 15:00:33 +01:00
|
|
|
for (int i = 0; i < (int)sizeof(settings.aes_key); i++)
|
2011-02-01 23:58:04 +01:00
|
|
|
{
|
2011-02-02 18:20:02 +01:00
|
|
|
QString s2 = s.left(2);
|
2011-02-01 23:58:04 +01:00
|
|
|
s.remove(0, 2);
|
|
|
|
s = s.trimmed();
|
2011-02-02 18:20:02 +01:00
|
|
|
settings.aes_key[i] = s2.toUInt(&ok, 16);
|
2011-02-01 23:58:04 +01:00
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
error("Check your \"AES Key\" entry! .. it must contain only hex characters (0-9, a-f)", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
// send the new settings to the modem
|
|
|
|
sendSettings(pipx_config_details.serial_number, &settings);
|
2011-02-01 23:58:04 +01:00
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
// retrieve them back
|
|
|
|
m_stage_retries = 0;
|
|
|
|
m_stage = PIPX_REQ_SETTINGS;
|
2011-02-01 23:58:04 +01:00
|
|
|
}
|
|
|
|
|
2011-02-02 15:00:33 +01:00
|
|
|
void PipXtremeGadgetWidget::textChangedAESKey(const QString &text)
|
|
|
|
{
|
|
|
|
QString s = text;
|
|
|
|
s.replace(' ', "");
|
|
|
|
m_widget->label_AESkey->setText("AES Encryption Key (" + QString::number(s.length()) + ")");
|
|
|
|
}
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
// ***************************************************************************************
|
2011-02-03 08:04:46 +01:00
|
|
|
// send various packets
|
2011-02-01 23:58:04 +01:00
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
void PipXtremeGadgetWidget::sendRequestDetails(uint32_t serial_number)
|
2011-02-01 23:58:04 +01:00
|
|
|
{
|
|
|
|
// *****************
|
|
|
|
// create the packet
|
|
|
|
|
|
|
|
t_pipx_config_header header;
|
2011-02-03 08:04:46 +01:00
|
|
|
header.marker = PIPX_HEADER_MARKER;
|
|
|
|
header.serial_number = serial_number;
|
|
|
|
header.type = PIPX_PACKET_TYPE_REQ_DETAILS;
|
|
|
|
header.spare = 0;
|
|
|
|
header.data_size = 0;
|
|
|
|
header.data_crc = 0xffffffff;
|
|
|
|
header.header_crc = 0;
|
|
|
|
header.header_crc = updateCRC32Data(0xffffffff, &header, sizeof(t_pipx_config_header));
|
|
|
|
|
|
|
|
// *****************
|
|
|
|
// send the packet
|
|
|
|
|
|
|
|
// QMutexLocker locker_dev(&device_mutex);
|
|
|
|
if (!m_ioDevice) return;
|
|
|
|
if (!m_ioDevice->isOpen()) return;
|
|
|
|
qint64 bytes_written = m_ioDevice->write((const char*)&header, sizeof(t_pipx_config_header));
|
|
|
|
|
|
|
|
Q_UNUSED(bytes_written)
|
|
|
|
|
|
|
|
// *****************
|
|
|
|
}
|
|
|
|
|
|
|
|
void PipXtremeGadgetWidget::sendRequestSettings(uint32_t serial_number)
|
|
|
|
{
|
|
|
|
if (serial_number == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// *****************
|
|
|
|
// create the packet
|
|
|
|
|
|
|
|
t_pipx_config_header header;
|
|
|
|
header.marker = PIPX_HEADER_MARKER;
|
|
|
|
header.serial_number = serial_number;
|
|
|
|
header.type = PIPX_PACKET_TYPE_REQ_SETTINGS;
|
2011-02-01 23:58:04 +01:00
|
|
|
header.spare = 0;
|
|
|
|
header.data_size = 0;
|
|
|
|
header.data_crc = 0xffffffff;
|
|
|
|
header.header_crc = 0;
|
|
|
|
header.header_crc = updateCRC32Data(0xffffffff, &header, sizeof(t_pipx_config_header));
|
|
|
|
|
|
|
|
// *****************
|
|
|
|
// send the packet
|
|
|
|
|
|
|
|
// QMutexLocker locker_dev(&device_mutex);
|
|
|
|
if (!m_ioDevice) return;
|
|
|
|
if (!m_ioDevice->isOpen()) return;
|
|
|
|
qint64 bytes_written = m_ioDevice->write((const char*)&header, sizeof(t_pipx_config_header));
|
|
|
|
|
2011-02-02 18:20:02 +01:00
|
|
|
// qDebug() << "PipX m_ioDevice->write: " << QString::number(bytes_written) << endl;
|
|
|
|
|
2011-02-02 15:00:33 +01:00
|
|
|
Q_UNUSED(bytes_written)
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
// error("Bytes written", bytes_written); // TEST ONLY
|
|
|
|
|
|
|
|
// *****************
|
|
|
|
}
|
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
void PipXtremeGadgetWidget::sendRequestState(uint32_t serial_number)
|
2011-02-01 23:58:04 +01:00
|
|
|
{
|
2011-02-03 08:04:46 +01:00
|
|
|
if (serial_number == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// *****************
|
|
|
|
// create the packet
|
|
|
|
|
|
|
|
t_pipx_config_header header;
|
|
|
|
header.marker = PIPX_HEADER_MARKER;
|
|
|
|
header.serial_number = serial_number;
|
|
|
|
header.type = PIPX_PACKET_TYPE_REQ_STATE;
|
|
|
|
header.spare = 0;
|
|
|
|
header.data_size = 0;
|
|
|
|
header.data_crc = 0xffffffff;
|
|
|
|
header.header_crc = 0;
|
|
|
|
header.header_crc = updateCRC32Data(0xffffffff, &header, sizeof(t_pipx_config_header));
|
|
|
|
|
|
|
|
// *****************
|
|
|
|
// send the packet
|
|
|
|
|
|
|
|
// QMutexLocker locker_dev(&device_mutex);
|
|
|
|
if (!m_ioDevice) return;
|
|
|
|
if (!m_ioDevice->isOpen()) return;
|
|
|
|
qint64 bytes_written = m_ioDevice->write((const char*)&header, sizeof(t_pipx_config_header));
|
|
|
|
|
|
|
|
// qDebug() << "PipX m_ioDevice->write: " << QString::number(bytes_written) << endl;
|
|
|
|
|
|
|
|
Q_UNUSED(bytes_written)
|
|
|
|
|
|
|
|
// error("Bytes written", bytes_written); // TEST ONLY
|
|
|
|
|
|
|
|
// *****************
|
|
|
|
}
|
|
|
|
|
|
|
|
void PipXtremeGadgetWidget::sendSettings(uint32_t serial_number, t_pipx_config_settings *settings)
|
|
|
|
{
|
|
|
|
if (serial_number == 0)
|
|
|
|
return;
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
if (!settings)
|
|
|
|
return;
|
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
uint8_t buffer[sizeof(t_pipx_config_header) + sizeof(t_pipx_config_settings)];
|
2011-02-01 23:58:04 +01:00
|
|
|
|
|
|
|
t_pipx_config_header *header = (t_pipx_config_header *)buffer;
|
|
|
|
uint8_t *data = (uint8_t *) header + sizeof(t_pipx_config_header);
|
|
|
|
|
|
|
|
// *****************
|
|
|
|
// create the packet
|
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
memcpy(data, settings, sizeof(t_pipx_config_settings));
|
2011-02-01 23:58:04 +01:00
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
header->marker = PIPX_HEADER_MARKER;
|
2011-02-01 23:58:04 +01:00
|
|
|
header->serial_number = serial_number;
|
2011-02-03 08:04:46 +01:00
|
|
|
header->type = PIPX_PACKET_TYPE_SETTINGS;
|
2011-02-01 23:58:04 +01:00
|
|
|
header->spare = 0;
|
2011-02-03 08:04:46 +01:00
|
|
|
header->data_size = sizeof(t_pipx_config_settings);
|
2011-02-01 23:58:04 +01:00
|
|
|
header->data_crc = updateCRC32Data(0xffffffff, data, header->data_size);
|
|
|
|
header->header_crc = 0;
|
|
|
|
header->header_crc = updateCRC32Data(0xffffffff, header, sizeof(t_pipx_config_header));
|
|
|
|
|
|
|
|
// *****************
|
|
|
|
// send the packet
|
|
|
|
|
|
|
|
// QMutexLocker locker_dev(&device_mutex);
|
|
|
|
if (!m_ioDevice) return;
|
|
|
|
if (!m_ioDevice->isOpen()) return;
|
|
|
|
qint64 bytes_written = m_ioDevice->write((const char*)buffer, sizeof(t_pipx_config_header) + header->data_size);
|
|
|
|
|
|
|
|
// error("Bytes written", bytes_written); // TEST ONLY
|
|
|
|
|
2011-02-02 18:20:02 +01:00
|
|
|
Q_UNUSED(bytes_written)
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
// *****************
|
2011-01-26 13:01:09 +01:00
|
|
|
}
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
// ***************************************************************************************
|
|
|
|
// process rx stream data
|
|
|
|
|
|
|
|
void PipXtremeGadgetWidget::processRxStream()
|
2011-01-26 13:01:09 +01:00
|
|
|
{
|
2011-01-31 22:46:42 +01:00
|
|
|
QMutexLocker locker_dev(&device_mutex);
|
|
|
|
QMutexLocker locker_inbuf(&device_input_buffer.mutex);
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
if (!m_ioDevice) return;
|
|
|
|
if (!m_ioDevice->isOpen()) return;
|
2011-01-31 11:16:06 +01:00
|
|
|
|
2011-02-02 18:20:02 +01:00
|
|
|
QTimer::singleShot(100, this, SLOT(processRxStream()));
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
qint64 bytes_available = m_ioDevice->bytesAvailable();
|
|
|
|
if (bytes_available <= 0) return;
|
2011-01-31 11:16:06 +01:00
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
// ensure we have buffer space for the new data
|
|
|
|
if (!device_input_buffer.buffer)
|
|
|
|
{ // allocate a buffer for the data
|
|
|
|
device_input_buffer.size = bytes_available * 2;
|
|
|
|
device_input_buffer.used = 0;
|
|
|
|
device_input_buffer.buffer = new quint8 [device_input_buffer.size];
|
|
|
|
if (!device_input_buffer.buffer) return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((device_input_buffer.used + (bytes_available * 2)) > device_input_buffer.size)
|
|
|
|
{ // need to increase the buffer size
|
2011-01-31 22:46:42 +01:00
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
// create a new larger buffer
|
|
|
|
int new_size = device_input_buffer.used + bytes_available * 2;
|
|
|
|
quint8 *new_buf = new quint8 [new_size];
|
|
|
|
if (!new_buf) return;
|
2011-01-31 22:46:42 +01:00
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
// copy the data from the old buffer into the new buffer
|
|
|
|
memmove(new_buf, device_input_buffer.buffer, device_input_buffer.used);
|
2011-01-31 22:46:42 +01:00
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
// delete the old buffer
|
|
|
|
delete [] device_input_buffer.buffer;
|
2011-01-31 22:46:42 +01:00
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
// keep the new buffer
|
|
|
|
device_input_buffer.buffer = new_buf;
|
|
|
|
device_input_buffer.size = new_size;
|
2011-01-31 22:46:42 +01:00
|
|
|
}
|
2011-02-01 23:58:04 +01:00
|
|
|
}
|
2011-01-31 22:46:42 +01:00
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
// add the new data into the buffer
|
2011-02-02 15:00:33 +01:00
|
|
|
qint64 bytes_read = m_ioDevice->read((char *)(device_input_buffer.buffer + device_input_buffer.used), device_input_buffer.size - device_input_buffer.used);
|
2011-02-01 23:58:04 +01:00
|
|
|
if (bytes_read <= 0) return;
|
2011-02-02 15:00:33 +01:00
|
|
|
device_input_buffer.used += bytes_read;
|
2011-01-26 13:01:09 +01:00
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
processRxBuffer();
|
2011-01-26 13:01:09 +01:00
|
|
|
}
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
void PipXtremeGadgetWidget::processRxBuffer()
|
2011-01-31 22:46:42 +01:00
|
|
|
{ // scan the buffer for a valid packet
|
|
|
|
|
2011-02-02 15:00:33 +01:00
|
|
|
if (!device_input_buffer.buffer || device_input_buffer.used < (int)sizeof(t_pipx_config_header))
|
2011-01-31 22:46:42 +01:00
|
|
|
return; // no data as yet or not yet enough data
|
|
|
|
|
2011-02-02 15:00:33 +01:00
|
|
|
while (device_input_buffer.used >= (int)sizeof(t_pipx_config_header))
|
2011-01-31 22:46:42 +01:00
|
|
|
{
|
|
|
|
uint32_t crc1, crc2;
|
|
|
|
|
|
|
|
t_pipx_config_header *header = (t_pipx_config_header *)device_input_buffer.buffer;
|
|
|
|
uint8_t *data = (uint8_t *)header + sizeof(t_pipx_config_header);
|
|
|
|
|
|
|
|
// check packet marker
|
2011-02-03 08:04:46 +01:00
|
|
|
if (header->marker != PIPX_HEADER_MARKER)
|
2011-01-31 22:46:42 +01:00
|
|
|
{ // marker not yet found
|
|
|
|
// remove a byte
|
|
|
|
int i = 1;
|
|
|
|
if (i < device_input_buffer.used)
|
|
|
|
memmove(device_input_buffer.buffer, device_input_buffer.buffer + i, device_input_buffer.used - i);
|
|
|
|
device_input_buffer.used -= i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check the header CRC
|
|
|
|
crc1 = header->header_crc;
|
|
|
|
header->header_crc = 0;
|
|
|
|
crc2 = updateCRC32Data(0xffffffff, header, sizeof(t_pipx_config_header));
|
|
|
|
header->header_crc = crc1;
|
|
|
|
if (crc2 != crc1)
|
|
|
|
{ // faulty header
|
|
|
|
int i = 1;
|
|
|
|
if (i < device_input_buffer.used)
|
|
|
|
memmove(device_input_buffer.buffer, device_input_buffer.buffer + i, device_input_buffer.used - i);
|
|
|
|
device_input_buffer.used -= i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
// valid error free header found!
|
|
|
|
|
2011-01-31 22:46:42 +01:00
|
|
|
int total_packet_size = sizeof(t_pipx_config_header) + header->data_size;
|
|
|
|
|
|
|
|
if (device_input_buffer.used < total_packet_size)
|
2011-02-01 23:58:04 +01:00
|
|
|
{ // not yet got a full packet
|
|
|
|
break;
|
|
|
|
}
|
2011-01-31 22:46:42 +01:00
|
|
|
|
|
|
|
if (header->data_size > 0)
|
|
|
|
{
|
|
|
|
// check the data crc
|
|
|
|
crc1 = header->data_crc;
|
|
|
|
crc2 = updateCRC32Data(0xffffffff, data, header->data_size);
|
|
|
|
if (crc2 != crc1)
|
|
|
|
{ // faulty data
|
|
|
|
int i = 1;
|
|
|
|
if (i < device_input_buffer.used)
|
|
|
|
memmove(device_input_buffer.buffer, device_input_buffer.buffer + i, device_input_buffer.used - i);
|
|
|
|
device_input_buffer.used -= i;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
processRxPacket(device_input_buffer.buffer, total_packet_size);
|
2011-01-31 22:46:42 +01:00
|
|
|
|
|
|
|
// remove the packet from the buffer
|
|
|
|
if (total_packet_size < device_input_buffer.used)
|
|
|
|
memmove(device_input_buffer.buffer, device_input_buffer.buffer + total_packet_size, device_input_buffer.used - total_packet_size);
|
|
|
|
device_input_buffer.used -= total_packet_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
void PipXtremeGadgetWidget::processRxPacket(quint8 *packet, int packet_size)
|
2011-01-31 11:16:06 +01:00
|
|
|
{
|
2011-01-31 22:46:42 +01:00
|
|
|
if (!packet || packet_size <= 0)
|
2011-01-31 11:16:06 +01:00
|
|
|
return;
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
t_pipx_config_header *header = (t_pipx_config_header *)packet;
|
|
|
|
uint8_t *data = (uint8_t *)header + sizeof(t_pipx_config_header);
|
2011-01-31 22:46:42 +01:00
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
switch (header->type)
|
|
|
|
{
|
2011-02-03 08:04:46 +01:00
|
|
|
case PIPX_PACKET_TYPE_REQ_DETAILS:
|
2011-02-01 23:58:04 +01:00
|
|
|
break;
|
2011-01-31 22:46:42 +01:00
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
case PIPX_PACKET_TYPE_DETAILS:
|
|
|
|
if (m_stage == PIPX_REQ_DETAILS)
|
2011-02-01 23:58:04 +01:00
|
|
|
{
|
2011-02-03 08:04:46 +01:00
|
|
|
m_stage_retries = 0;
|
|
|
|
m_stage = PIPX_REQ_SETTINGS;
|
|
|
|
|
|
|
|
if (packet_size < (int)sizeof(t_pipx_config_header) + (int)sizeof(t_pipx_config_details))
|
2011-02-01 23:58:04 +01:00
|
|
|
break; // packet size is too small - error
|
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
memcpy(&pipx_config_details, data, sizeof(t_pipx_config_details));
|
2011-02-01 23:58:04 +01:00
|
|
|
|
2011-02-23 10:35:30 +01:00
|
|
|
if (pipx_config_details.major_version < 0 || (pipx_config_details.major_version <= 0 && pipx_config_details.minor_version < 6))
|
2011-02-05 00:00:48 +01:00
|
|
|
{
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setIcon(QMessageBox::Critical);
|
2011-02-15 13:57:46 +01:00
|
|
|
msgBox.setText("You need to update your PipX modem firmware to V0.5 or later");
|
2011-02-05 00:00:48 +01:00
|
|
|
msgBox.exec();
|
|
|
|
disconnectPort(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
m_widget->lineEdit_FirmwareVersion->setText(QString::number(pipx_config_details.major_version) + "." + QString::number(pipx_config_details.minor_version));
|
2011-02-01 23:58:04 +01:00
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
m_widget->lineEdit_SerialNumber->setText(QString::number(pipx_config_details.serial_number, 16).toUpper());
|
|
|
|
|
2011-02-06 11:55:08 +01:00
|
|
|
if (pipx_config_details.frequency_band == FREQBAND_434MHz)
|
2011-02-03 08:04:46 +01:00
|
|
|
m_widget->lineEdit_FrequencyBand->setText("434MHz");
|
2011-02-01 23:58:04 +01:00
|
|
|
else
|
2011-02-06 11:55:08 +01:00
|
|
|
if (pipx_config_details.frequency_band == FREQBAND_868MHz)
|
2011-02-03 08:04:46 +01:00
|
|
|
m_widget->lineEdit_FrequencyBand->setText("868MHz");
|
2011-02-01 23:58:04 +01:00
|
|
|
else
|
2011-02-06 11:55:08 +01:00
|
|
|
if (pipx_config_details.frequency_band == FREQBAND_915MHz)
|
2011-02-03 08:04:46 +01:00
|
|
|
m_widget->lineEdit_FrequencyBand->setText("915MHz");
|
2011-02-01 23:58:04 +01:00
|
|
|
else
|
2011-02-03 08:04:46 +01:00
|
|
|
m_widget->lineEdit_FrequencyBand->setText("UNKNOWN [" + QString::number(pipx_config_details.frequency_band) + "]");
|
|
|
|
|
|
|
|
m_widget->lineEdit_MinFrequency->setText(QString::number((double)pipx_config_details.min_frequency_Hz / 1e6, 'f', 6) + "MHz");
|
|
|
|
m_widget->lineEdit_MaxFrequency->setText(QString::number((double)pipx_config_details.max_frequency_Hz / 1e6, 'f', 6) + "MHz");
|
|
|
|
|
|
|
|
m_widget->doubleSpinBox_Frequency->setMinimum((double)pipx_config_details.min_frequency_Hz / 1e6);
|
|
|
|
m_widget->doubleSpinBox_Frequency->setMaximum((double)pipx_config_details.max_frequency_Hz / 1e6);
|
2011-02-06 22:21:50 +01:00
|
|
|
m_widget->doubleSpinBox_Frequency->setSingleStep(((double)pipx_config_details.frequency_step_size * 4) / 1e6);
|
2011-02-03 08:04:46 +01:00
|
|
|
|
|
|
|
m_widget->lineEdit_FrequencyStepSize->setText(QString::number(pipx_config_details.frequency_step_size, 'f', 2) + "Hz");
|
2011-02-01 23:58:04 +01:00
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
m_widget->pushButton_Save->setEnabled(true);
|
|
|
|
m_widget->pushButton_ScanSpectrum->setEnabled(true);
|
2011-02-04 17:17:57 +01:00
|
|
|
m_widget->pushButton_Import->setEnabled(true);
|
|
|
|
m_widget->pushButton_Export->setEnabled(true);
|
2011-02-03 08:04:46 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIPX_PACKET_TYPE_REQ_SETTINGS:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIPX_PACKET_TYPE_SETTINGS:
|
|
|
|
if (m_stage == PIPX_REQ_SETTINGS && pipx_config_details.serial_number != 0)
|
|
|
|
{
|
|
|
|
if (packet_size < (int)sizeof(t_pipx_config_header) + (int)sizeof(t_pipx_config_settings))
|
|
|
|
break; // packet size is too small - error
|
|
|
|
|
|
|
|
m_stage_retries = 0;
|
|
|
|
m_stage = PIPX_REQ_STATE;
|
2011-02-01 23:58:04 +01:00
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
memcpy(&pipx_config_settings, data, sizeof(t_pipx_config_settings));
|
2011-02-01 23:58:04 +01:00
|
|
|
|
2011-02-05 00:00:48 +01:00
|
|
|
m_widget->comboBox_Mode->setCurrentIndex(m_widget->comboBox_Mode->findData(pipx_config_settings.mode));
|
2011-02-03 08:04:46 +01:00
|
|
|
m_widget->lineEdit_PairedSerialNumber->setText(QString::number(pipx_config_settings.destination_id, 16).toUpper());
|
|
|
|
m_widget->spinBox_FrequencyCalibration->setValue(pipx_config_settings.rf_xtal_cap);
|
|
|
|
m_widget->doubleSpinBox_Frequency->setValue((double)pipx_config_settings.frequency_Hz / 1e6);
|
|
|
|
m_widget->comboBox_MaxRFBandwidth->setCurrentIndex(m_widget->comboBox_MaxRFBandwidth->findData(pipx_config_settings.max_rf_bandwidth));
|
|
|
|
m_widget->comboBox_MaxRFTxPower->setCurrentIndex(m_widget->comboBox_MaxRFTxPower->findData(pipx_config_settings.max_tx_power));
|
|
|
|
m_widget->comboBox_SerialPortSpeed->setCurrentIndex(m_widget->comboBox_SerialPortSpeed->findData(pipx_config_settings.serial_baudrate));
|
2011-02-15 13:57:46 +01:00
|
|
|
m_widget->spinBox_RTSTime->setValue(pipx_config_settings.rts_time);
|
2011-02-01 23:58:04 +01:00
|
|
|
|
|
|
|
QString key = "";
|
2011-02-03 08:04:46 +01:00
|
|
|
for (int i = 0; i < (int)sizeof(pipx_config_settings.aes_key); i++)
|
|
|
|
key += QString::number(pipx_config_settings.aes_key[i], 16).rightJustified(2, '0');
|
2011-02-01 23:58:04 +01:00
|
|
|
m_widget->lineEdit_AESKey->setText(key);
|
2011-02-03 08:04:46 +01:00
|
|
|
m_widget->checkBox_AESEnable->setChecked(pipx_config_settings.aes_enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIPX_PACKET_TYPE_REQ_STATE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIPX_PACKET_TYPE_STATE:
|
|
|
|
if (m_stage == PIPX_REQ_STATE && pipx_config_details.serial_number != 0)
|
|
|
|
{
|
|
|
|
if (packet_size < (int)sizeof(t_pipx_config_header) + (int)sizeof(t_pipx_config_state))
|
|
|
|
break; // packet size is too small - error
|
|
|
|
|
|
|
|
m_stage_retries = 0;
|
|
|
|
// m_stage = PIPX_REQ_STATE;
|
|
|
|
|
|
|
|
memcpy(&pipx_config_state, data, sizeof(t_pipx_config_state));
|
|
|
|
|
|
|
|
switch (pipx_config_state.link_state)
|
|
|
|
{
|
2011-02-06 11:55:08 +01:00
|
|
|
case LINK_DISCONNECTED:
|
2011-02-03 08:04:46 +01:00
|
|
|
m_widget->lineEdit_LinkState->setText("Disconnected");
|
|
|
|
break;
|
2011-02-06 11:55:08 +01:00
|
|
|
case LINK_CONNECTING:
|
2011-02-03 08:04:46 +01:00
|
|
|
m_widget->lineEdit_LinkState->setText("Connecting");
|
|
|
|
break;
|
2011-02-06 11:55:08 +01:00
|
|
|
case LINK_CONNECTED:
|
2011-02-03 08:04:46 +01:00
|
|
|
m_widget->lineEdit_LinkState->setText("Connected");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
m_widget->lineEdit_LinkState->setText("Unknown [" + QString::number(pipx_config_state.link_state) + "]");
|
|
|
|
break;
|
|
|
|
}
|
2011-02-03 14:12:30 +01:00
|
|
|
if (pipx_config_state.rssi < m_widget->progressBar_RSSI->minimum())
|
|
|
|
m_widget->progressBar_RSSI->setValue(m_widget->progressBar_RSSI->minimum());
|
|
|
|
else
|
|
|
|
if (pipx_config_state.rssi > m_widget->progressBar_RSSI->maximum())
|
|
|
|
m_widget->progressBar_RSSI->setValue(m_widget->progressBar_RSSI->maximum());
|
|
|
|
else
|
|
|
|
m_widget->progressBar_RSSI->setValue(pipx_config_state.rssi);
|
2011-02-04 17:17:57 +01:00
|
|
|
m_widget->label_RSSI->setText("RSSI " + QString::number(pipx_config_state.rssi) + "dBm");
|
2011-02-03 08:04:46 +01:00
|
|
|
m_widget->lineEdit_RxAFC->setText(QString::number(pipx_config_state.afc) + "Hz");
|
2011-02-03 14:12:30 +01:00
|
|
|
m_widget->lineEdit_Retries->setText(QString::number(pipx_config_state.retries));
|
2011-02-01 23:58:04 +01:00
|
|
|
}
|
2011-01-31 22:46:42 +01:00
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
break;
|
2011-02-03 08:04:46 +01:00
|
|
|
|
2011-02-23 10:35:30 +01:00
|
|
|
case PIPX_PACKET_TYPE_SPECTRUM: // a packet with scanned spectrum data
|
|
|
|
if (pipx_config_details.serial_number != 0)
|
|
|
|
{
|
|
|
|
if (packet_size < (int)sizeof(t_pipx_config_header) + (int)sizeof(t_pipx_config_spectrum))
|
|
|
|
break; // packet size is too small - error
|
|
|
|
|
|
|
|
memcpy(&pipx_config_spectrum, data, sizeof(t_pipx_config_spectrum));
|
|
|
|
int8_t *spec_data = (int8_t *)(data + sizeof(t_pipx_config_spectrum));
|
|
|
|
|
|
|
|
if (pipx_config_spectrum.magnitudes > 0)
|
|
|
|
{
|
|
|
|
m_widget->label_19->setText(QString::number(pipx_config_spectrum.start_frequency) + " " + QString::number(pipx_config_spectrum.frequency_step_size) + " " + QString::number(pipx_config_spectrum.magnitudes));
|
|
|
|
/*
|
|
|
|
QGraphicsScene *spec_scene = m_widget->graphicsView_Spectrum->scene();
|
|
|
|
if (spec_scene)
|
|
|
|
{
|
|
|
|
if (pipx_config_spectrum.start_frequency - pipx_config_details.min_frequency_Hz <= 0)
|
|
|
|
spec_scene->clear();
|
|
|
|
|
|
|
|
int w = 500;
|
|
|
|
int h = 500;
|
|
|
|
|
|
|
|
float xscale = (float)w / (pipx_config_details.max_frequency_Hz - pipx_config_details.min_frequency_Hz);
|
|
|
|
float yscale = h / 128.0f;
|
|
|
|
|
|
|
|
float xs = xscale * (pipx_config_spectrum.start_frequency - pipx_config_details.min_frequency_Hz);
|
|
|
|
|
|
|
|
for (int i = 0; i < pipx_config_spectrum.magnitudes; i++)
|
|
|
|
{
|
|
|
|
int x = -(w / 2) + xs + (xscale * i * pipx_config_spectrum.frequency_step_size);
|
|
|
|
int rssi = (int)spec_data[i] + 128;
|
|
|
|
int y = yscale * rssi;
|
|
|
|
spec_scene->addLine(x, -h / 2, x, (-h / 2) - y, QPen(Qt::green, 1, Qt::SolidLine, Qt::SquareCap));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
default:
|
|
|
|
break;
|
2011-02-01 23:58:04 +01:00
|
|
|
}
|
|
|
|
}
|
2011-01-31 22:46:42 +01:00
|
|
|
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
// ***************************************************************************************
|
2011-01-31 22:46:42 +01:00
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
void PipXtremeGadgetWidget::processStream()
|
|
|
|
{
|
|
|
|
QMutexLocker locker_dev(&device_mutex);
|
|
|
|
QMutexLocker locker_inbuf(&device_input_buffer.mutex);
|
2011-01-31 11:16:06 +01:00
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
if (!m_ioDevice) return;
|
|
|
|
if (!m_ioDevice->isOpen()) return;
|
2011-01-31 11:16:06 +01:00
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
switch (m_stage)
|
|
|
|
{
|
|
|
|
case PIPX_IDLE:
|
2011-02-03 08:04:46 +01:00
|
|
|
QTimer::singleShot(RETRY_TIME, this, SLOT(processStream()));
|
2011-02-01 23:58:04 +01:00
|
|
|
break;
|
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
case PIPX_REQ_DETAILS:
|
2011-02-01 23:58:04 +01:00
|
|
|
if (++m_stage_retries > MAX_RETRIES)
|
|
|
|
{
|
|
|
|
disconnectPort(true, false);
|
|
|
|
break;
|
|
|
|
}
|
2011-02-03 08:04:46 +01:00
|
|
|
sendRequestDetails(0);
|
2011-02-01 23:58:04 +01:00
|
|
|
QTimer::singleShot(RETRY_TIME, this, SLOT(processStream()));
|
|
|
|
break;
|
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
case PIPX_REQ_SETTINGS:
|
2011-02-01 23:58:04 +01:00
|
|
|
if (++m_stage_retries > MAX_RETRIES)
|
|
|
|
{
|
|
|
|
disconnectPort(true, false);
|
|
|
|
break;
|
|
|
|
}
|
2011-02-03 08:04:46 +01:00
|
|
|
sendRequestSettings(pipx_config_details.serial_number);
|
|
|
|
QTimer::singleShot(RETRY_TIME, this, SLOT(processStream()));
|
|
|
|
break;
|
2011-02-01 23:58:04 +01:00
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
case PIPX_REQ_STATE:
|
|
|
|
if (++m_stage_retries > MAX_RETRIES)
|
|
|
|
{
|
|
|
|
disconnectPort(true, false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sendRequestState(pipx_config_details.serial_number);
|
2011-02-01 23:58:04 +01:00
|
|
|
QTimer::singleShot(RETRY_TIME, this, SLOT(processStream()));
|
|
|
|
break;
|
2011-01-31 11:16:06 +01:00
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
default:
|
|
|
|
m_stage_retries = 0;
|
|
|
|
m_stage = PIPX_IDLE;
|
2011-02-03 08:04:46 +01:00
|
|
|
QTimer::singleShot(RETRY_TIME, this, SLOT(processStream()));
|
2011-02-01 23:58:04 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-01-31 22:46:42 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
// ***************************************************************************************
|
2011-01-30 14:28:22 +01:00
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
void PipXtremeGadgetWidget::disconnectPort(bool enable_telemetry, bool lock_stuff)
|
2011-01-30 14:28:22 +01:00
|
|
|
{ // disconnect the comms port
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
if (lock_stuff)
|
|
|
|
{
|
|
|
|
QMutexLocker locker_dev(&device_mutex);
|
|
|
|
QMutexLocker locker_inbuf(&device_input_buffer.mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_stage_retries = 0;
|
|
|
|
m_stage = PIPX_IDLE;
|
2011-01-31 22:46:42 +01:00
|
|
|
|
|
|
|
device_input_buffer.used = 0;
|
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
memset(&pipx_config_details, 0, sizeof(pipx_config_details));
|
|
|
|
memset(&pipx_config_settings, 0, sizeof(pipx_config_settings));
|
2011-01-31 11:16:06 +01:00
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
if (m_ioDevice)
|
|
|
|
{
|
|
|
|
m_ioDevice->close();
|
|
|
|
disconnect(m_ioDevice, 0, 0, 0);
|
|
|
|
delete m_ioDevice;
|
|
|
|
m_ioDevice = NULL;
|
|
|
|
}
|
2011-01-30 14:28:22 +01:00
|
|
|
|
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-02-01 23:58:04 +01:00
|
|
|
m_widget->pushButton_Save->setEnabled(false);
|
2011-02-04 17:17:57 +01:00
|
|
|
m_widget->pushButton_Import->setEnabled(false);
|
|
|
|
m_widget->pushButton_Export->setEnabled(false);
|
2011-02-01 23:58:04 +01:00
|
|
|
|
2011-02-03 08:04:46 +01:00
|
|
|
m_widget->lineEdit_FirmwareVersion->setText("");
|
2011-02-01 23:58:04 +01:00
|
|
|
m_widget->lineEdit_SerialNumber->setText("");
|
|
|
|
m_widget->lineEdit_FrequencyBand->setText("");
|
|
|
|
m_widget->lineEdit_MinFrequency->setText("");
|
|
|
|
m_widget->lineEdit_MaxFrequency->setText("");
|
|
|
|
m_widget->lineEdit_FrequencyStepSize->setText("");
|
2011-02-03 08:04:46 +01:00
|
|
|
m_widget->lineEdit_LinkState->setText("");
|
2011-02-01 23:58:04 +01:00
|
|
|
m_widget->progressBar_RSSI->setValue(m_widget->progressBar_RSSI->minimum());
|
2011-02-04 17:17:57 +01:00
|
|
|
m_widget->label_RSSI->setText("RSSI");
|
2011-02-01 23:58:04 +01:00
|
|
|
m_widget->lineEdit_RxAFC->setText("");
|
2011-02-03 14:12:30 +01:00
|
|
|
m_widget->lineEdit_Retries->setText("");
|
2011-02-01 23:58:04 +01:00
|
|
|
m_widget->lineEdit_PairedSerialNumber->setText("");
|
|
|
|
m_widget->spinBox_FrequencyCalibration->setValue(0);
|
|
|
|
m_widget->doubleSpinBox_Frequency->setValue(0);
|
|
|
|
m_widget->lineEdit_AESKey->setText("");
|
|
|
|
m_widget->checkBox_AESEnable->setChecked(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 22:46:42 +01:00
|
|
|
QMutexLocker locker_dev(&device_mutex);
|
|
|
|
|
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-02-01 23:58:04 +01:00
|
|
|
int type = NO_PORT;
|
|
|
|
if (device_str.toLower().startsWith("com: "))
|
|
|
|
{
|
|
|
|
type = SERIAL_PORT;
|
|
|
|
device_str.remove(0, 5);
|
|
|
|
device_str = device_str.trimmed();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (device_str.toLower().startsWith("usb: "))
|
|
|
|
{
|
|
|
|
type = USB_PORT;
|
|
|
|
device_str.remove(0, 5);
|
|
|
|
device_str = device_str.trimmed();
|
|
|
|
}
|
|
|
|
|
|
|
|
// type = m_widget->comboBox_Ports->itemData(device_idx).toInt();
|
2011-01-30 14:28:22 +01:00
|
|
|
|
|
|
|
// qDebug() << QString::number(type) << ": " << device_str;
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
// Suspend GCS telemety & polling
|
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;
|
2011-02-03 14:12:30 +01:00
|
|
|
#if (defined Q_OS_WIN)
|
|
|
|
case 230400: bdt = BAUD230400; break;
|
|
|
|
case 460800: bdt = BAUD460800; break;
|
|
|
|
case 921600: bdt = BAUD921600; break;
|
|
|
|
#endif
|
2011-01-30 14:28:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
PortSettings settings;
|
|
|
|
settings.BaudRate = bdt;
|
|
|
|
settings.DataBits = DATA_8;
|
|
|
|
settings.Parity = PAR_NONE;
|
|
|
|
settings.StopBits = STOP_1;
|
|
|
|
settings.FlowControl = FLOW_OFF;
|
2011-02-01 23:58:04 +01:00
|
|
|
settings.Timeout_Millisec = 1000;
|
2011-02-02 18:20:02 +01:00
|
|
|
// settings.setQueryMode(QextSerialBase::EventDriven);
|
2011-01-30 14:28:22 +01:00
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
// QextSerialPort *serial_dev = new QextSerialPort(str, settings, QextSerialPort::Polling);
|
2011-02-02 18:20:02 +01:00
|
|
|
// QextSerialPort *serial_dev = new QextSerialPort(str, settings, QextSerialPort::EventDriven);
|
|
|
|
QextSerialPort *serial_dev = new QextSerialPort(str, settings);
|
2011-01-30 14:28:22 +01:00
|
|
|
if (!serial_dev)
|
|
|
|
break;
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
// if (!serial_dev->open(QIODevice::ReadWrite | QIODevice::Unbuffered))
|
|
|
|
if (!serial_dev->open(QIODevice::ReadWrite))
|
2011-01-30 14:28:22 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
// if (!usb_dev->open(QIODevice::ReadWrite | QIODevice::Unbuffered))
|
|
|
|
if (!usb_dev->open(QIODevice::ReadWrite))
|
2011-01-30 14:28:22 +01:00
|
|
|
{
|
|
|
|
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)
|
2011-02-01 23:58:04 +01:00
|
|
|
{ // failed to connect .. restore GCS telemetry and polling
|
2011-01-31 11:16:06 +01:00
|
|
|
enableTelemetry();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // connected OK
|
2011-02-03 08:04:46 +01:00
|
|
|
memset(&pipx_config_details, 0, sizeof(pipx_config_details));
|
|
|
|
memset(&pipx_config_settings, 0, sizeof(pipx_config_settings));
|
|
|
|
|
2011-01-31 11:16:06 +01:00
|
|
|
m_widget->connectButton->setText("Disconnect");
|
|
|
|
m_widget->comboBox_SerialBaudrate->setEnabled(false);
|
|
|
|
m_widget->comboBox_Ports->setEnabled(false);
|
|
|
|
m_widget->refreshPorts->setEnabled(false);
|
2011-02-01 23:58:04 +01:00
|
|
|
|
2011-02-02 15:00:33 +01:00
|
|
|
m_ioDevice->setTextModeEnabled(false);
|
2011-02-02 18:20:02 +01:00
|
|
|
QTimer::singleShot(100, this, SLOT(processRxStream()));
|
|
|
|
// connect(m_ioDevice, SIGNAL(readyRead()), this, SLOT(processRxStream()));
|
2011-01-31 11:16:06 +01:00
|
|
|
|
2011-02-01 23:58:04 +01:00
|
|
|
m_stage_retries = 0;
|
2011-02-03 08:04:46 +01:00
|
|
|
m_stage = PIPX_REQ_DETAILS;
|
|
|
|
QTimer::singleShot(100, this, SLOT(processStream()));
|
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-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
|
|
|
}
|
|
|
|
|
2011-02-04 17:17:57 +01:00
|
|
|
// ***************************************************************************************
|
|
|
|
|
|
|
|
void PipXtremeGadgetWidget::importSettings()
|
|
|
|
{
|
2011-02-04 18:29:52 +01:00
|
|
|
QString filename = "pipx_" + QString::number(pipx_config_details.serial_number, 16).rightJustified(8, '0') + ".ini";
|
|
|
|
|
|
|
|
QFileDialog::Options options;
|
|
|
|
QString selectedFilter;
|
|
|
|
filename = QFileDialog::getOpenFileName(this,
|
|
|
|
tr("Load from PipX settings file"),
|
|
|
|
filename,
|
|
|
|
tr("PipX settings (*.ini)"),
|
|
|
|
&selectedFilter,
|
|
|
|
options
|
|
|
|
).trimmed();
|
|
|
|
if (filename.isEmpty())
|
|
|
|
return;
|
2011-02-04 17:17:57 +01:00
|
|
|
|
2011-02-04 18:29:52 +01:00
|
|
|
if (!QFileInfo(filename).isReadable())
|
|
|
|
{
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setText(tr("Can't read file ") + QFileInfo(filename).absoluteFilePath());
|
|
|
|
msgBox.exec();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSettings settings(filename, QSettings::IniFormat);
|
2011-02-04 17:17:57 +01:00
|
|
|
|
2011-02-04 19:06:01 +01:00
|
|
|
uint32_t serial_number = settings.value("details/serial_number", 0).toUInt();
|
|
|
|
if (serial_number && serial_number != pipx_config_details.serial_number)
|
|
|
|
{
|
|
|
|
// return;
|
|
|
|
}
|
|
|
|
|
2011-02-05 00:00:48 +01:00
|
|
|
pipx_config_settings.mode = settings.value("settings/mode", 0).toUInt();
|
2011-02-04 17:17:57 +01:00
|
|
|
pipx_config_settings.destination_id = settings.value("settings/paired_serial_number", 0).toUInt();
|
|
|
|
pipx_config_settings.rf_xtal_cap = settings.value("settings/frequency_calibration", 0x7f).toUInt();
|
2011-02-04 18:29:52 +01:00
|
|
|
pipx_config_settings.frequency_Hz = settings.value("settings/frequency", (pipx_config_details.min_frequency_Hz + pipx_config_details.max_frequency_Hz) / 2).toUInt();
|
|
|
|
pipx_config_settings.max_rf_bandwidth = settings.value("settings/max_rf_bandwidth", 128000).toUInt();
|
|
|
|
pipx_config_settings.max_tx_power = settings.value("settings/max_tx_power", 4).toUInt();
|
|
|
|
pipx_config_settings.serial_baudrate = settings.value("settings/serial_baudrate", 57600).toUInt();
|
|
|
|
pipx_config_settings.aes_enable = settings.value("settings/aes_enable", false).toBool();
|
|
|
|
for (int i = 0; i < (int)sizeof(pipx_config_settings.aes_key); i++)
|
|
|
|
pipx_config_settings.aes_key[i] = settings.value("settings/aes_key_" + QString::number(i), 0).toUInt();
|
2011-02-15 13:57:46 +01:00
|
|
|
pipx_config_settings.rts_time = settings.value("settings/ready_to_send_time", 10).toUInt();
|
2011-02-04 17:17:57 +01:00
|
|
|
|
2011-02-05 00:00:48 +01:00
|
|
|
m_widget->comboBox_Mode->setCurrentIndex(m_widget->comboBox_Mode->findData(pipx_config_settings.mode));
|
2011-02-04 17:17:57 +01:00
|
|
|
m_widget->lineEdit_PairedSerialNumber->setText(QString::number(pipx_config_settings.destination_id, 16).toUpper());
|
|
|
|
m_widget->spinBox_FrequencyCalibration->setValue(pipx_config_settings.rf_xtal_cap);
|
2011-02-04 18:29:52 +01:00
|
|
|
m_widget->doubleSpinBox_Frequency->setValue((double)pipx_config_settings.frequency_Hz / 1e6);
|
|
|
|
m_widget->comboBox_MaxRFBandwidth->setCurrentIndex(m_widget->comboBox_MaxRFBandwidth->findData(pipx_config_settings.max_rf_bandwidth));
|
|
|
|
m_widget->comboBox_MaxRFTxPower->setCurrentIndex(m_widget->comboBox_MaxRFTxPower->findData(pipx_config_settings.max_tx_power));
|
|
|
|
m_widget->comboBox_SerialPortSpeed->setCurrentIndex(m_widget->comboBox_SerialPortSpeed->findData(pipx_config_settings.serial_baudrate));
|
2011-02-15 13:57:46 +01:00
|
|
|
m_widget->spinBox_RTSTime->setValue(pipx_config_settings.rts_time);
|
2011-02-04 17:17:57 +01:00
|
|
|
|
2011-02-04 18:29:52 +01:00
|
|
|
QString key = "";
|
|
|
|
for (int i = 0; i < (int)sizeof(pipx_config_settings.aes_key); i++)
|
|
|
|
key += QString::number(pipx_config_settings.aes_key[i], 16).rightJustified(2, '0');
|
2011-02-05 00:00:48 +01:00
|
|
|
m_widget->lineEdit_AESKey->setText(key);
|
2011-02-04 18:29:52 +01:00
|
|
|
m_widget->checkBox_AESEnable->setChecked(pipx_config_settings.aes_enable);
|
2011-02-04 17:17:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PipXtremeGadgetWidget::exportSettings()
|
|
|
|
{
|
2011-02-04 18:29:52 +01:00
|
|
|
QString filename = "pipx_" + QString::number(pipx_config_details.serial_number, 16).rightJustified(8, '0') + ".ini";
|
|
|
|
|
|
|
|
filename = QFileDialog::getSaveFileName(this,
|
|
|
|
tr("Save to PipX settings file"),
|
|
|
|
filename,
|
|
|
|
tr("PipX settings (*.ini)")
|
|
|
|
).trimmed();
|
|
|
|
if (filename.isEmpty())
|
|
|
|
return;
|
2011-02-04 19:06:01 +01:00
|
|
|
/*
|
2011-02-04 18:29:52 +01:00
|
|
|
if (QFileInfo(filename).exists())
|
|
|
|
{
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setText(tr("File already exists."));
|
|
|
|
msgBox.setInformativeText(tr("Do you want to overwrite the existing file?"));
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
|
|
|
if (msgBox.exec() == QMessageBox::Ok)
|
|
|
|
QFileInfo(filename).absoluteDir().remove(QFileInfo(filename).fileName());
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
2011-02-04 19:06:01 +01:00
|
|
|
*/ QDir dir = QFileInfo(filename).absoluteDir();
|
2011-02-04 18:29:52 +01:00
|
|
|
if (!dir.exists())
|
|
|
|
{
|
|
|
|
QMessageBox msgBox;
|
2011-02-04 19:06:01 +01:00
|
|
|
msgBox.setText(tr("Can't write file ") + QFileInfo(filename).absoluteFilePath() + " since directory " + dir.absolutePath() + " doesn't exist!");
|
2011-02-04 18:29:52 +01:00
|
|
|
msgBox.exec();
|
|
|
|
return;
|
|
|
|
}
|
2011-02-04 17:17:57 +01:00
|
|
|
|
2011-02-04 18:29:52 +01:00
|
|
|
QSettings settings(filename, QSettings::IniFormat);
|
2011-02-04 19:06:01 +01:00
|
|
|
settings.setValue("details/serial_number", pipx_config_details.serial_number);
|
|
|
|
settings.setValue("details/min_frequency", pipx_config_details.min_frequency_Hz);
|
|
|
|
settings.setValue("details/max_frequency", pipx_config_details.max_frequency_Hz);
|
|
|
|
settings.setValue("details/frequency_band", pipx_config_details.frequency_band);
|
2011-02-05 00:00:48 +01:00
|
|
|
settings.setValue("settings/mode", pipx_config_settings.mode);
|
2011-02-04 17:17:57 +01:00
|
|
|
settings.setValue("settings/paired_serial_number", pipx_config_settings.destination_id);
|
|
|
|
settings.setValue("settings/frequency_calibration", pipx_config_settings.rf_xtal_cap);
|
2011-02-04 18:29:52 +01:00
|
|
|
settings.setValue("settings/frequency", pipx_config_settings.frequency_Hz);
|
|
|
|
settings.setValue("settings/max_rf_bandwidth", pipx_config_settings.max_rf_bandwidth);
|
|
|
|
settings.setValue("settings/max_tx_power", pipx_config_settings.max_tx_power);
|
|
|
|
settings.setValue("settings/serial_baudrate", pipx_config_settings.serial_baudrate);
|
|
|
|
settings.setValue("settings/aes_enable", pipx_config_settings.aes_enable);
|
2011-02-15 13:57:46 +01:00
|
|
|
settings.setValue("settings/ready_to_send_time", pipx_config_settings.rts_time);
|
2011-02-04 18:29:52 +01:00
|
|
|
for (int i = 0; i < (int)sizeof(pipx_config_settings.aes_key); i++)
|
|
|
|
settings.setValue("settings/aes_key_" + QString::number(i), pipx_config_settings.aes_key[i]);
|
2011-02-04 17:17:57 +01:00
|
|
|
}
|
|
|
|
|
2011-01-26 13:01:09 +01:00
|
|
|
// ***************************************************************************************
|
|
|
|
// Shows a message box with an error string.
|
2011-02-01 23:58:04 +01:00
|
|
|
|
2011-01-26 13:01:09 +01:00
|
|
|
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
|
|
|
|
|
|
|
// ***************************************************************************************
|