Browse Source

Changed Xbeelink configuration

Set the remote address of the xbee via the xbeeconfiguration window and save last address in a txt file. Xbeelink ist still hardcoded to work with series2 xbees
QGC4.4
oberion 14 years ago
parent
commit
17eb2abde6
  1. 2
      qgroundcontrol.pro
  2. 18
      src/comm/XbeeLink.cpp
  3. 4
      src/comm/XbeeLink.h
  4. 6
      src/comm/XbeeLinkInterface.h
  5. 2
      src/ui/CommConfigurationWindow.cc
  6. 64
      src/ui/XbeeConfigurationWindow.cpp
  7. 13
      src/ui/XbeeConfigurationWindow.h

2
qgroundcontrol.pro

@ -539,9 +539,11 @@ TRANSLATIONS += es-MX.ts \ @@ -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

18
src/comm/XbeeLink.cpp

@ -7,7 +7,8 @@ @@ -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() @@ -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() @@ -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() @@ -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)
{

4
src/comm/XbeeLink.h

@ -26,6 +26,8 @@ public: // virtual functions from XbeeLinkInterface @@ -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: @@ -60,6 +62,8 @@ protected:
int m_baudRate;
bool m_connected;
QString m_name;
quint32 m_addrHigh;
quint32 m_addrLow;
private:
bool hardwareConnect();

6
src/comm/XbeeLinkInterface.h

@ -16,6 +16,12 @@ public: @@ -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_

2
src/ui/CommConfigurationWindow.cc

@ -159,6 +159,8 @@ CommConfigurationWindow::CommConfigurationWindow(LinkInterface* link, ProtocolIn @@ -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

64
src/ui/XbeeConfigurationWindow.cpp

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
#include <QDir>
#include <QSettings>
#include <QFileInfoList>
#include <qdatastream.h>
#ifdef _WIN32
#include <QextSerialEnumerator.h>
@ -213,11 +214,23 @@ XbeeConfigurationWindow::XbeeConfigurationWindow(LinkInterface* link, QWidget *p @@ -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 @@ -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 @@ -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) @@ -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<quint32>(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<quint32>(addr);
QFile out("Xbeeconf.txt");
if(out.open(QIODevice::WriteOnly))
{
QDataStream outStr(&out);
outStr << this->highAddr->value();
outStr << this->lowAddr->value();
}
emit addrLowChanged(uaddr);
}

13
src/ui/XbeeConfigurationWindow.h

@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
#include<QtGui\qlayout.h>
#include <LinkInterface.h>
#include"XbeeLinkInterface.h"
#include "../comm/HexSpinBox.h"
class XbeeConfigurationWindow : public QWidget
@ -30,6 +31,10 @@ public slots: @@ -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: @@ -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);
};

Loading…
Cancel
Save