diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index fb5e8a9d12dc6335f31edfbedb64e1e5a214445a..f0e5c1dab695e8e794a1c33dee16d76f9698fa5b 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -539,9 +539,11 @@ TRANSLATIONS += es-MX.ts \ win32-msvc2008|win32-msvc2010|linux{ HEADERS += src/comm/XbeeLinkInterface.h \ src/comm/XbeeLink.h \ + src/comm/HexSpinBox.h \ src/ui/XbeeConfigurationWindow.h \ src/comm/CallConv.h SOURCES += src/comm/XbeeLink.cpp \ + src/comm/HexSpinBox.cpp \ src/ui/XbeeConfigurationWindow.cpp DEFINES += XBEELINK INCLUDEPATH += thirdParty/libxbee diff --git a/src/comm/XbeeLink.cpp b/src/comm/XbeeLink.cpp index 0ddb0d86d640028a309d5b6af2364baeae13c9fc..78c102ef8d4323bcb9056ef2f038923d66395b55 100644 --- a/src/comm/XbeeLink.cpp +++ b/src/comm/XbeeLink.cpp @@ -7,7 +7,8 @@ #include "XbeeLink.h" XbeeLink::XbeeLink(QString portName, int baudRate) : - m_xbeeCon(NULL), m_portName(NULL), m_portNameLength(0), m_baudRate(baudRate), m_connected(false), m_id(-1) + m_xbeeCon(NULL), m_portName(NULL), m_portNameLength(0), m_baudRate(baudRate), m_connected(false), m_id(-1), + m_addrHigh(0), m_addrLow(0) { /* setup the xbee */ @@ -160,6 +161,7 @@ qint64 XbeeLink::getBitsReceived() bool XbeeLink::hardwareConnect() { + emit tryConnectBegin(true); if(this->isConnected()) { this->disconnect(); @@ -172,9 +174,11 @@ bool XbeeLink::hardwareConnect() { /* oh no... it failed */ qDebug() <<"xbee_setup() failed...\n"; + emit tryConnectEnd(true); return false; } this->m_xbeeCon = xbee_newcon('A',xbee2_data,0x13A200,0x403D0935); + emit tryConnectEnd(true); this->m_connected = true; emit connected(); emit connected(true); @@ -256,6 +260,18 @@ void XbeeLink::run() } } +bool XbeeLink::setRemoteAddressHigh(quint32 high) +{ + this->m_addrHigh = high; + return true; +} + +bool XbeeLink::setRemoteAddressLow(quint32 low) +{ + this->m_addrLow = low; + return true; +} + /* void CALLTYPE XbeeLink::portCallback(xbee_con *xbeeCon, xbee_pkt *XbeePkt) { diff --git a/src/comm/XbeeLink.h b/src/comm/XbeeLink.h index befd8a63c1be45452be95360b24ac7124cd7d1e1..e07e95f8c52b9ae886371b931ea451a0276d03d6 100644 --- a/src/comm/XbeeLink.h +++ b/src/comm/XbeeLink.h @@ -26,6 +26,8 @@ public: // virtual functions from XbeeLinkInterface public slots: // virtual functions from XbeeLinkInterface bool setPortName(QString portName); bool setBaudRate(int rate); + bool setRemoteAddressHigh(quint32 high); + bool setRemoteAddressLow(quint32 low); public: // virtual functions from LinkInterface int getId(); @@ -60,6 +62,8 @@ protected: int m_baudRate; bool m_connected; QString m_name; + quint32 m_addrHigh; + quint32 m_addrLow; private: bool hardwareConnect(); diff --git a/src/comm/XbeeLinkInterface.h b/src/comm/XbeeLinkInterface.h index 96bd0c001969429ba7324228bbd99083637c47b7..37fd9249912d205c1cda44b24418165df1d007fc 100644 --- a/src/comm/XbeeLinkInterface.h +++ b/src/comm/XbeeLinkInterface.h @@ -16,6 +16,12 @@ public: public slots: virtual bool setPortName(QString portName) = 0; virtual bool setBaudRate(int rate) = 0; + virtual bool setRemoteAddressHigh(quint32 high) = 0; + virtual bool setRemoteAddressLow(quint32 low) = 0; + +signals: + void tryConnectBegin(bool toTrue); + void tryConnectEnd(bool toTrue); }; #endif // XBEELINKINTERFACE_H_ diff --git a/src/ui/CommConfigurationWindow.cc b/src/ui/CommConfigurationWindow.cc index 7ee3880667c9f0e60ffca7867e5fba970e91a439..0e02aa04db05e5c30e174a32f32c00cfc6dd9882 100644 --- a/src/ui/CommConfigurationWindow.cc +++ b/src/ui/CommConfigurationWindow.cc @@ -159,6 +159,8 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn ui.linkScrollArea->setWidget(conf); ui.linkGroupBox->setTitle(tr("Xbee Link")); ui.linkType->setCurrentIndex(4); + connect(xbee,SIGNAL(tryConnectBegin(bool)),ui.actionConnect,SLOT(setDisabled(bool))); + connect(xbee,SIGNAL(tryConnectEnd(bool)),ui.actionConnect,SLOT(setEnabled(bool))); } #endif // XBEELINK if (serial == 0 && udp == 0 && sim == 0 diff --git a/src/ui/XbeeConfigurationWindow.cpp b/src/ui/XbeeConfigurationWindow.cpp index bf8111d3e42d0235f7773547cf9383175eac7ac0..54c3b45c4e301002e3fc70ea81b7de0efd0629b5 100644 --- a/src/ui/XbeeConfigurationWindow.cpp +++ b/src/ui/XbeeConfigurationWindow.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #ifdef _WIN32 #include @@ -213,11 +214,23 @@ XbeeConfigurationWindow::XbeeConfigurationWindow(LinkInterface* link, QWidget *p portBox = new QComboBox; portBox->setEditable(true); portLabel->setBuddy(portBox); + highAddrLabel = new QLabel; + highAddrLabel->setText(tr("Remote hex Address &High")); + highAddr = new HexSpinBox(this); + highAddrLabel->setBuddy(highAddr); + lowAddrLabel = new QLabel; + lowAddrLabel->setText(tr("Remote hex Address &Low")); + lowAddr = new HexSpinBox(this); + lowAddrLabel->setBuddy(lowAddr); actionLayout = new QGridLayout; actionLayout->addWidget(baudLabel,1,1); actionLayout->addWidget(baudBox,1,2); actionLayout->addWidget(portLabel,2,1); actionLayout->addWidget(portBox,2,2); + actionLayout->addWidget(highAddrLabel,3,1); + actionLayout->addWidget(highAddr,3,2); + actionLayout->addWidget(lowAddrLabel,4,1); + actionLayout->addWidget(lowAddr,4,2); tmpLayout = new QVBoxLayout; tmpLayout->addStretch(); tmpLayout->addLayout(actionLayout); @@ -231,6 +244,10 @@ XbeeConfigurationWindow::XbeeConfigurationWindow(LinkInterface* link, QWidget *p connect(portBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(setPortName(QString))); connect(portBox,SIGNAL(editTextChanged(QString)),this,SLOT(setPortName(QString))); connect(baudBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(setBaudRateString(QString))); + connect(highAddr,SIGNAL(valueChanged(int)),this,SLOT(addrChangedHigh(int))); + connect(lowAddr,SIGNAL(valueChanged(int)),this,SLOT(addrChangedLow(int))); + connect(this,SIGNAL(addrHighChanged(quint32)),xbeeLink,SLOT(setRemoteAddressHigh(quint32))); + connect(this,SIGNAL(addrLowChanged(quint32)),xbeeLink,SLOT(setRemoteAddressLow(quint32))); baudBox->addItem("1200",1200); baudBox->addItem("2400",2400); @@ -240,6 +257,27 @@ XbeeConfigurationWindow::XbeeConfigurationWindow(LinkInterface* link, QWidget *p baudBox->addItem("38400",38400); baudBox->addItem("57600",57600); baudBox->setCurrentIndex(6); + + // try to open xbeeConf file for last remote address + QFile in("Xbeeconf.txt"); + if(in.open(QIODevice::ReadOnly)) + { + QDataStream inStr(&in); + int tmpaddrHigh; + int tmpaddrLow; + inStr >> tmpaddrHigh; + inStr >> tmpaddrLow; + highAddr->setValue(tmpaddrHigh); + lowAddr->setValue(tmpaddrLow); + } + else + { + highAddr->setValue(0x13A200); + lowAddr->setValue(0x40DDDDDD); + } + + + this->setupPortList(); portCheckTimer = new QTimer(this); @@ -382,4 +420,30 @@ void XbeeConfigurationWindow::setBaudRateString(QString baud) { int rate = baud.toInt(); this->link->setBaudRate(rate); +} + +void XbeeConfigurationWindow::addrChangedHigh(int addr) +{ + quint32 uaddr = static_cast(addr); + QFile out("Xbeeconf.txt"); + if(out.open(QIODevice::WriteOnly)) + { + QDataStream outStr(&out); + outStr << this->highAddr->value(); + outStr << this->lowAddr->value(); + } + emit addrHighChanged(uaddr); +} + +void XbeeConfigurationWindow::addrChangedLow(int addr) +{ + quint32 uaddr = static_cast(addr); + QFile out("Xbeeconf.txt"); + if(out.open(QIODevice::WriteOnly)) + { + QDataStream outStr(&out); + outStr << this->highAddr->value(); + outStr << this->lowAddr->value(); + } + emit addrLowChanged(uaddr); } \ No newline at end of file diff --git a/src/ui/XbeeConfigurationWindow.h b/src/ui/XbeeConfigurationWindow.h index 8c9ef5d923377d9bbc5d927832524605f6d8057b..549414f215dcd7e17910c7d4068829157baf4257 100644 --- a/src/ui/XbeeConfigurationWindow.h +++ b/src/ui/XbeeConfigurationWindow.h @@ -12,6 +12,7 @@ #include #include #include"XbeeLinkInterface.h" +#include "../comm/HexSpinBox.h" class XbeeConfigurationWindow : public QWidget @@ -30,6 +31,10 @@ public slots: void setBaudRateString(QString baud); void setupPortList(); +private slots: + void addrChangedHigh(int addr); + void addrChangedLow(int addr); + protected: void showEvent(QShowEvent* event); void hideEvent(QHideEvent* event); @@ -46,6 +51,14 @@ private: XbeeLinkInterface* link; QAction* action; QTimer* portCheckTimer; + HexSpinBox* highAddr; + HexSpinBox* lowAddr; + QLabel* highAddrLabel; + QLabel* lowAddrLabel; + +signals: + void addrHighChanged(quint32 addrHigh); + void addrLowChanged(quint32 addrLow); };