diff --git a/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryconfiguration.cpp b/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryconfiguration.cpp index cf7b8acef..b53270a12 100644 --- a/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryconfiguration.cpp +++ b/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryconfiguration.cpp @@ -27,25 +27,18 @@ #include "TCPtelemetryconfiguration.h" #include +#include TCPtelemetryConfiguration::TCPtelemetryConfiguration(QString classId, const QByteArray &state, QObject *parent) : IUAVGadgetConfiguration(classId, parent), m_HostName("127.0.0.1"), m_Port(1000) { - if (state.count() > 0) { - QDataStream stream(state); - int Port; - QString HostName; - stream >> Port; - stream >> HostName; - m_Port = Port; - if (HostName != "") - m_HostName = HostName; - - } + settings = Core::ICore::instance()->settings(); +} +TCPtelemetryConfiguration::~TCPtelemetryConfiguration() +{ } - IUAVGadgetConfiguration *TCPtelemetryConfiguration::clone() { TCPtelemetryConfiguration *m = new TCPtelemetryConfiguration(this->classId()); @@ -56,10 +49,39 @@ IUAVGadgetConfiguration *TCPtelemetryConfiguration::clone() QByteArray TCPtelemetryConfiguration::saveState() const { - QByteArray bytes; + QByteArray bytes; QDataStream stream(&bytes, QIODevice::WriteOnly); stream << m_Port; stream << m_HostName; return bytes; + +} + + +void TCPtelemetryConfiguration::savesettings() const +{ + settings->beginGroup(QLatin1String("TCPtelemetryconnection")); + + settings->beginWriteArray("Current"); + settings->setArrayIndex(0); + settings->setValue(QLatin1String("HostName"), m_HostName); + settings->setValue(QLatin1String("Port"), m_Port); + settings->endArray(); + settings->endGroup(); +} + + +void TCPtelemetryConfiguration::restoresettings() +{ + settings->beginGroup(QLatin1String("TCPtelemetryconnection")); + + settings->beginReadArray("Current"); + settings->setArrayIndex(0); + m_HostName = (settings->value(QLatin1String("HostName"), tr("")).toString()); + m_Port = (settings->value(QLatin1String("Port"), tr("")).toInt()); + settings->endArray(); + settings->endGroup(); + + } diff --git a/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryconfiguration.h b/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryconfiguration.h index 17c97585b..ca90ae399 100644 --- a/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryconfiguration.h +++ b/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryconfiguration.h @@ -30,6 +30,7 @@ #include #include +#include using namespace Core; @@ -41,12 +42,18 @@ Q_PROPERTY(int Port READ Port WRITE setPort) public: explicit TCPtelemetryConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0); + virtual ~TCPtelemetryConfiguration(); QByteArray saveState() const; - IUAVGadgetConfiguration *clone(); + //void savesettings(QSettings* settings) const; + //void restoresettings(QSettings* settings); + void savesettings() const; + void restoresettings(); + IUAVGadgetConfiguration *clone(); QString HostName() const { return m_HostName; } int Port() const { return m_Port; } + public slots: void setHostName(QString HostName) { m_HostName = HostName; } void setPort(int Port) { m_Port = Port; } @@ -54,6 +61,7 @@ public slots: private: QString m_HostName; int m_Port; + QSettings* settings; }; diff --git a/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryoptionspage.cpp b/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryoptionspage.cpp index eca36eeba..d4bc15bc5 100644 --- a/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryoptionspage.cpp +++ b/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryoptionspage.cpp @@ -41,10 +41,14 @@ TCPtelemetryOptionsPage::TCPtelemetryOptionsPage(TCPtelemetryConfiguration *conf IOptionsPage(parent), m_config(config) { -} +} +TCPtelemetryOptionsPage::~TCPtelemetryOptionsPage() +{ +} QWidget *TCPtelemetryOptionsPage::createPage(QWidget *parent) { + m_page = new Ui::TCPtelemetryOptionsPage(); QWidget *w = new QWidget(parent); m_page->setupUi(w); @@ -59,6 +63,12 @@ void TCPtelemetryOptionsPage::apply() { m_config->setPort(m_page->Port->value()); m_config->setHostName(m_page->HostName->text()); + m_config->savesettings(); + + emit availableDevChanged(); + + + } void TCPtelemetryOptionsPage::finish() diff --git a/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryoptionspage.h b/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryoptionspage.h index eb76e5fe4..47cf07538 100644 --- a/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryoptionspage.h +++ b/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryoptionspage.h @@ -29,6 +29,7 @@ #define TCPtelemetryOPTIONSPAGE_H #include "coreplugin/dialogs/ioptionspage.h" +//#include class TCPtelemetryConfiguration; @@ -47,17 +48,26 @@ class TCPtelemetryOptionsPage : public IOptionsPage Q_OBJECT public: explicit TCPtelemetryOptionsPage(TCPtelemetryConfiguration *config, QObject *parent = 0); + virtual ~TCPtelemetryOptionsPage(); + + QString id() const { return QLatin1String("settings"); } + QString trName() const { return tr("settings"); } + QString category() const { return "TCP Connection"; }; + QString trCategory() const { return "TCP Connection"; }; QWidget *createPage(QWidget *parent); void apply(); void finish(); signals: + void availableDevChanged(); public slots: private: TCPtelemetryConfiguration *m_config; Ui::TCPtelemetryOptionsPage *m_page; + //QSettings* settings; + }; #endif // TCPtelemetryOPTIONSPAGE_H diff --git a/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryoptionspage.ui b/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryoptionspage.ui index c7e0e7640..ca97e10a1 100644 --- a/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryoptionspage.ui +++ b/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryoptionspage.ui @@ -6,7 +6,7 @@ 0 0 - 355 + 388 300 @@ -17,27 +17,7 @@ 0 - - - - Host Name/Number - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - + Qt::Horizontal @@ -50,19 +30,33 @@ - - + + + + 1 + + + 999999 + + - - - - + Port + + + + + + + Host Name/Number + + + diff --git a/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryplugin.cpp b/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryplugin.cpp index b725ab54f..a2ddef7a6 100644 --- a/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryplugin.cpp +++ b/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryplugin.cpp @@ -35,25 +35,39 @@ #include #include +#include #include #include TCPtelemetryConnection::TCPtelemetryConnection() -{//no change from serial plugin +{ + tcpSocket = new QTcpSocket(this); - //I'm cheating a little bit here: - //Knowing if the device enumeration really changed is a bit complicated - //so I just signal it whenever we have a device event... + m_config = new TCPtelemetryConfiguration("TCP Connection", NULL, this); + m_config->restoresettings(); + + m_optionspage = new TCPtelemetryOptionsPage(m_config,this); + + //just signal whenever we have a device event... QMainWindow *mw = Core::ICore::instance()->mainWindow(); QObject::connect(mw, SIGNAL(deviceChange()), this, SLOT(onEnumerationChanged())); + QObject::connect(m_optionspage, SIGNAL(availableDevChanged()), + this, SLOT(onEnumerationChanged())); } TCPtelemetryConnection::~TCPtelemetryConnection() -{//no change from serial plugin +{ + /* if (tcpSocket->state()>0){ + tcpSocket->disconnectFromHost (); + }*/ + tcpSocket->close (); + // delete(m_optionspage); + // delete(m_config); + } void TCPtelemetryConnection::onEnumerationChanged() @@ -63,69 +77,43 @@ void TCPtelemetryConnection::onEnumerationChanged() emit availableDevChanged(this); } -/*bool sortPorts(const QextPortInfo &s1,const QextPortInfo &s2) -{ - return s1.portName ports = QextTCPtelemetryEnumerator::getPorts(); - //sort the list by port number (nice idea from PT_Dreamer :)) - qSort(ports.begin(), ports.end(),sortPorts); - foreach( QextPortInfo port, ports ) { - list.append(port.friendName); - }*/ - //for the first attempt just hard code the IP and PORT - list.append((const QString )"Test OpenPilot"); + list.append((const QString )m_config->HostName()); return list; } QIODevice *TCPtelemetryConnection::openDevice(const QString &deviceName) { - - /*QList ports = QextTCPtelemetryEnumerator::getPorts(); - foreach( QextPortInfo port, ports ) { - if(port.friendName == deviceName) - { - //we need to handle port settings here... - PortSettings set; - set.BaudRate = BAUD57600; - set.DataBits = DATA_8; - set.Parity = PAR_NONE; - set.StopBits = STOP_1; - set.FlowControl = FLOW_OFF; - set.Timeout_Millisec = 500; -#ifdef Q_OS_WIN - return new QextTCPtelemetryPort(port.portName, set); -#else - return new QextTCPtelemetryPort(port.physName, set); -#endif - } - }*/ const int Timeout = 5 * 1000; - tcpSocket = new QTcpSocket(this); - - tcpSocket->connectToHost((const QString )"192.168.10.77", 9100); + //if (tcpSocket->state()>0){ + // tcpSocket->close(); + //} + tcpSocket->connectToHost((const QString )m_config->HostName(), m_config->Port()); if (tcpSocket->waitForConnected(Timeout)) { return tcpSocket; } - + QMessageBox msgBox; + msgBox.setText((const QString )tcpSocket->errorString ()); + msgBox.exec(); return NULL; } void TCPtelemetryConnection::closeDevice(const QString &deviceName) -{//no change from serial plugin - - - //nothing to do here +{ + /* if (tcpSocket->state()>0){ + tcpSocket->disconnectFromHost (); + }*/ +//tcpSocket->close(); } @@ -133,7 +121,7 @@ QString TCPtelemetryConnection::connectionName() {//updated from serial plugin - return QString("TCPtelemetry port"); + return QString("TCP telemetry port"); } QString TCPtelemetryConnection::shortName() @@ -166,11 +154,8 @@ bool TCPtelemetryPlugin::initialize(const QStringList &arguments, QString *error Q_UNUSED(arguments); Q_UNUSED(errorString); - //m_optionspage = new TCPtelemetryOptionsPage(NULL,this); - //addAutoReleasedObject(m_optionspage); m_connection = new TCPtelemetryConnection(); - //m_factory = new TCPtelemetryFactory(this); - //addAutoReleasedObject(m_factory); + addAutoReleasedObject(m_connection->Optionspage()); return true; } diff --git a/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryplugin.h b/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryplugin.h index 9d3887448..21e30981c 100644 --- a/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryplugin.h +++ b/ground/src/plugins/TCPtelemetryconnection/TCPtelemetryplugin.h @@ -31,9 +31,12 @@ #include "TCPtelemetry_global.h" #include "TCPtelemetryoptionspage.h" #include "TCPtelemetryconfiguration.h" -#include "TCPtelemetryfactory.h" +//#include "TCPtelemetryfactory.h" #include "coreplugin/iconnection.h" #include +//#include + + class QTcpSocket; class IConnection; @@ -57,10 +60,18 @@ public: virtual QString connectionName(); virtual QString shortName(); + TCPtelemetryConfiguration * Config() const { return m_config; } + TCPtelemetryOptionsPage * Optionspage() const { return m_optionspage; } + + + protected slots: void onEnumerationChanged(); private: QTcpSocket *tcpSocket; + TCPtelemetryConfiguration *m_config; + TCPtelemetryOptionsPage *m_optionspage; + //QSettings* settings; }; @@ -78,9 +89,6 @@ public: virtual void extensionsInitialized(); private: - //TCPtelemetryConfiguration *m_config; - //TCPtelemetryOptionsPage *m_optionspage; - TCPtelemetryFactory *m_factory; TCPtelemetryConnection *m_connection; }; diff --git a/ground/src/plugins/TCPtelemetryconnection/ui_TCPtelemetryoptionspage.h b/ground/src/plugins/TCPtelemetryconnection/ui_TCPtelemetryoptionspage.h index 4d241ce1d..1e0f942c1 100644 --- a/ground/src/plugins/TCPtelemetryconnection/ui_TCPtelemetryoptionspage.h +++ b/ground/src/plugins/TCPtelemetryconnection/ui_TCPtelemetryoptionspage.h @@ -1,7 +1,7 @@ /******************************************************************************** ** Form generated from reading UI file 'TCPtelemetryoptionspage.ui' ** -** Created: Tue 22. Jun 21:46:31 2010 +** Created: Wed 23. Jun 00:36:03 2010 ** by: Qt User Interface Compiler version 4.6.3 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! @@ -28,48 +28,45 @@ class Ui_TCPtelemetryOptionsPage { public: QGridLayout *gridLayout; - QLabel *label_2; - QSpacerItem *verticalSpacer; QSpacerItem *horizontalSpacer; - QLineEdit *HostName; QSpinBox *Port; QLabel *label_3; + QLineEdit *HostName; + QLabel *label_2; void setupUi(QWidget *TCPtelemetryOptionsPage) { if (TCPtelemetryOptionsPage->objectName().isEmpty()) TCPtelemetryOptionsPage->setObjectName(QString::fromUtf8("TCPtelemetryOptionsPage")); - TCPtelemetryOptionsPage->resize(355, 300); + TCPtelemetryOptionsPage->resize(388, 300); gridLayout = new QGridLayout(TCPtelemetryOptionsPage); gridLayout->setContentsMargins(0, 0, 0, 0); gridLayout->setObjectName(QString::fromUtf8("gridLayout")); - label_2 = new QLabel(TCPtelemetryOptionsPage); - label_2->setObjectName(QString::fromUtf8("label_2")); - - gridLayout->addWidget(label_2, 0, 0, 1, 1); - - verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); - - gridLayout->addItem(verticalSpacer, 2, 1, 3, 1); - horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); - gridLayout->addItem(horizontalSpacer, 0, 3, 5, 1); - - HostName = new QLineEdit(TCPtelemetryOptionsPage); - HostName->setObjectName(QString::fromUtf8("HostName")); - - gridLayout->addWidget(HostName, 0, 1, 1, 1); + gridLayout->addItem(horizontalSpacer, 0, 3, 1, 1); Port = new QSpinBox(TCPtelemetryOptionsPage); Port->setObjectName(QString::fromUtf8("Port")); + Port->setMinimum(1); + Port->setMaximum(999999); - gridLayout->addWidget(Port, 1, 1, 1, 1); + gridLayout->addWidget(Port, 4, 2, 1, 1); label_3 = new QLabel(TCPtelemetryOptionsPage); label_3->setObjectName(QString::fromUtf8("label_3")); - gridLayout->addWidget(label_3, 1, 0, 1, 1); + gridLayout->addWidget(label_3, 4, 1, 1, 1); + + HostName = new QLineEdit(TCPtelemetryOptionsPage); + HostName->setObjectName(QString::fromUtf8("HostName")); + + gridLayout->addWidget(HostName, 0, 2, 1, 1); + + label_2 = new QLabel(TCPtelemetryOptionsPage); + label_2->setObjectName(QString::fromUtf8("label_2")); + + gridLayout->addWidget(label_2, 0, 1, 1, 1); retranslateUi(TCPtelemetryOptionsPage); @@ -80,8 +77,8 @@ public: void retranslateUi(QWidget *TCPtelemetryOptionsPage) { TCPtelemetryOptionsPage->setWindowTitle(QApplication::translate("TCPtelemetryOptionsPage", "Form", 0, QApplication::UnicodeUTF8)); - label_2->setText(QApplication::translate("TCPtelemetryOptionsPage", "Host Name/Number", 0, QApplication::UnicodeUTF8)); label_3->setText(QApplication::translate("TCPtelemetryOptionsPage", "Port", 0, QApplication::UnicodeUTF8)); + label_2->setText(QApplication::translate("TCPtelemetryOptionsPage", "Host Name/Number", 0, QApplication::UnicodeUTF8)); } // retranslateUi };