From 8b99f51630a222093e95e409f2f50cc9c04d79aa Mon Sep 17 00:00:00 2001 From: Bryan Godbolt Date: Tue, 10 Aug 2010 16:21:35 -0600 Subject: [PATCH] working on opal link --- src/comm/OpalLink.cc | 66 ++++++++++++++++++++++++++++++++++ src/comm/OpalLink.h | 84 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+) diff --git a/src/comm/OpalLink.cc b/src/comm/OpalLink.cc index cec637f4bd..7030be2cb0 100644 --- a/src/comm/OpalLink.cc +++ b/src/comm/OpalLink.cc @@ -2,4 +2,70 @@ OpalLink::OpalLink() { + + // Set unique ID and add link to the list of links + this->id = getNextLinkId(); + this->name = tr("OpalRT link ") + QString::number(getId()); + LinkManager::instance()->add(this); +} + +int OpalLink::getId() +{ + return id; +} + +QString OpalLink::getName() +{ + return name; +} + +void OpalLink::setName(QString name) +{ + this->name = name; + emit nameChanged(this->name); +} + +bool OpalLink::isConnected() { + return connectState; +} + +qint64 OpalLink::getNominalDataRate() +{ + return 0; //unknown +} + +int OpalLink::getLinkQuality() +{ + return -1; //not supported +} + +qint64 OpalLink::getTotalUpstream() +{ + statisticsMutex.lock(); + return bitsSentTotal / ((MG::TIME::getGroundTimeNow() - connectionStartTime) / 1000); + statisticsMutex.unlock(); +} + +qint64 OpalLink::getCurrentUpstream() +{ + return 0; //unknown +} + +qint64 OpalLink::getMaxUpstream() +{ + return 0; //unknown +} + +qint64 OpalLink::getBitsSent() { + return bitsSentTotal; +} + +qint64 OpalLink::getBitsReceived() { + return bitsReceivedTotal; +} + + +bool OpalLink::isFullDuplex() +{ + return false; } diff --git a/src/comm/OpalLink.h b/src/comm/OpalLink.h index f0c81c091b..d3596d6716 100644 --- a/src/comm/OpalLink.h +++ b/src/comm/OpalLink.h @@ -1,10 +1,94 @@ #ifndef OPALLINK_H #define OPALLINK_H +/** + Connection to OpalRT. This class receives MAVLink packets as if it is a true link, but it + interprets the packets internally, and calls the appropriate api functions. + + \author Bryan Godbolt +*/ + +#include + +#include "LinkInterface.h" +#include "LinkManager.h" +#include "MG.h" class OpalLink : public LinkInterface { + Q_OBJECT + /* Connection management */ + + int getId(); + QString getName(); + bool isConnected(); + + /* Connection characteristics */ + + + qint64 getNominalDataRate(); + bool isFullDuplex(); + int getLinkQuality(); + qint64 getTotalUpstream(); + qint64 getCurrentUpstream(); + qint64 getMaxUpstream(); + qint64 getBitsSent(); + qint64 getBitsReceived(); + + + virtual bool connect() = 0; + + + virtual bool disconnect() = 0; + + + virtual qint64 bytesAvailable() = 0; + +public slots: + + + virtual void writeBytes(const char *bytes, qint64 length) = 0; + + + virtual void readBytes(char *bytes, qint64 maxLength) = 0; + +signals: + + void bytesReady(LinkInterface* link); + + + void bytesReceived(LinkInterface* link, QByteArray data); + + + void connected(); + + + void disconnected(); + + + void connected(bool connected); + + + void nameChanged(QString name); + public: OpalLink(); + +protected: + QString name; + int id; + bool connectState; + + quint64 bitsSentTotal; + quint64 bitsSentCurrent; + quint64 bitsSentMax; + quint64 bitsReceivedTotal; + quint64 bitsReceivedCurrent; + quint64 bitsReceivedMax; + quint64 connectionStartTime; + + QMutex statisticsMutex; + + void setName(QString name); }; #endif // OPALLINK_H -- GitLab