You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
184 lines
4.7 KiB
184 lines
4.7 KiB
/*===================================================================== |
|
|
|
QGroundControl Open Source Ground Control Station |
|
|
|
(c) 2009 - 2011 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org> |
|
|
|
This file is part of the QGROUNDCONTROL project |
|
|
|
QGROUNDCONTROL 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. |
|
|
|
QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
======================================================================*/ |
|
|
|
/** |
|
* @file |
|
* @brief Brief Description |
|
* |
|
* @author Lorenz Meier <mavteam@student.ethz.ch> |
|
* |
|
*/ |
|
|
|
#ifndef SERIALLINK_H |
|
#define SERIALLINK_H |
|
|
|
#include <QObject> |
|
#include <QThread> |
|
#include <QMutex> |
|
#include <QString> |
|
#include "qserialport.h" |
|
#include <configuration.h> |
|
#include "SerialLinkInterface.h" |
|
#ifdef _WIN32 |
|
#include "windows.h" |
|
#endif |
|
|
|
|
|
/** |
|
* @brief The SerialLink class provides cross-platform access to serial links. |
|
* It takes care of the link management and provides a common API to higher |
|
* level communication layers. It is implemented as a wrapper class for a thread |
|
* that handles the serial communication. All methods have therefore to be thread- |
|
* safe. |
|
* |
|
*/ |
|
class SerialLink : public SerialLinkInterface |
|
{ |
|
Q_OBJECT |
|
//Q_INTERFACES(SerialLinkInterface:LinkInterface) |
|
|
|
public: |
|
SerialLink(QString portname = "", |
|
int baudrate=57600, |
|
bool flow=false, |
|
bool parity=false, |
|
int dataBits=8, |
|
int stopBits=1); |
|
~SerialLink(); |
|
|
|
static const int poll_interval = SERIAL_POLL_INTERVAL; ///< Polling interval, defined in configuration.h |
|
|
|
/** @brief Get a list of the currently available ports */ |
|
QVector<QString>* getCurrentPorts(); |
|
|
|
bool isConnected() const; |
|
qint64 bytesAvailable(); |
|
|
|
/** |
|
* @brief The port handle |
|
*/ |
|
QString getPortName() const; |
|
/** |
|
* @brief The human readable port name |
|
*/ |
|
QString getName() const; |
|
int getBaudRate() const; |
|
int getDataBits() const; |
|
int getStopBits() const; |
|
|
|
// ENUM values |
|
int getBaudRateType() const; |
|
int getFlowType() const; |
|
int getParityType() const; |
|
int getDataBitsType() const; |
|
int getStopBitsType() const; |
|
|
|
/* Extensive statistics for scientific purposes */ |
|
qint64 getNominalDataRate() const; |
|
qint64 getTotalUpstream(); |
|
qint64 getCurrentUpstream(); |
|
qint64 getMaxUpstream(); |
|
qint64 getTotalDownstream(); |
|
qint64 getCurrentDownstream(); |
|
qint64 getMaxDownstream(); |
|
qint64 getBitsSent() const; |
|
qint64 getBitsReceived() const; |
|
|
|
void loadSettings(); |
|
void writeSettings(); |
|
|
|
void run(); |
|
|
|
int getLinkQuality() const; |
|
bool isFullDuplex() const; |
|
int getId() const; |
|
|
|
public slots: |
|
bool setPortName(QString portName); |
|
bool setBaudRate(int rate); |
|
bool setDataBits(int dataBits); |
|
bool setStopBits(int stopBits); |
|
|
|
// Set string rate |
|
bool setBaudRateString(const QString& rate); |
|
|
|
// Set ENUM values |
|
bool setBaudRateType(int rateIndex); |
|
bool setFlowType(int flow); |
|
bool setParityType(int parity); |
|
bool setDataBitsType(int dataBits); |
|
bool setStopBitsType(int stopBits); |
|
|
|
void readBytes(); |
|
/** |
|
* @brief Write a number of bytes to the interface. |
|
* |
|
* @param data Pointer to the data byte array |
|
* @param size The size of the bytes array |
|
**/ |
|
void writeBytes(const char* data, qint64 length); |
|
bool connect(); |
|
bool disconnect(); |
|
|
|
protected slots: |
|
void checkForBytes(); |
|
|
|
protected: |
|
quint64 bytesRead; |
|
TNX::QSerialPort * port; |
|
TNX::QPortSettings portSettings; |
|
#ifdef _WIN32 |
|
HANDLE winPort; |
|
DCB winPortSettings; |
|
#endif |
|
QString porthandle; |
|
QString name; |
|
int timeout; |
|
int id; |
|
|
|
quint64 bitsSentTotal; |
|
quint64 bitsSentShortTerm; |
|
quint64 bitsSentCurrent; |
|
quint64 bitsSentMax; |
|
quint64 bitsReceivedTotal; |
|
quint64 bitsReceivedShortTerm; |
|
quint64 bitsReceivedCurrent; |
|
quint64 bitsReceivedMax; |
|
quint64 connectionStartTime; |
|
QMutex statisticsMutex; |
|
QMutex dataMutex; |
|
QVector<QString>* ports; |
|
|
|
private: |
|
volatile bool m_stopp; |
|
QMutex m_stoppMutex; |
|
|
|
void setName(QString name); |
|
bool hardwareConnect(); |
|
|
|
signals: |
|
void aboutToCloseFlag(); |
|
|
|
}; |
|
|
|
#endif // SERIALLINK_H
|
|
|