LinkInterface.h 7.79 KB
Newer Older
pixhawk's avatar
pixhawk committed
1
/*=====================================================================
2

pixhawk's avatar
pixhawk committed
3
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
4

pixhawk's avatar
pixhawk committed
5
(c) 2009 PIXHAWK PROJECT  <http://pixhawk.ethz.ch>
6

pixhawk's avatar
pixhawk committed
7
This file is part of the PIXHAWK project
8 9 10 11 12 13 14 15 16 17 18 19 20 21

PIXHAWK 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.

PIXHAWK 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 PIXHAWK. If not, see <http://www.gnu.org/licenses/>.

pixhawk's avatar
pixhawk committed
22
======================================================================*/
23

pixhawk's avatar
pixhawk committed
24
/**
25 26 27 28 29 30
* @file
*   @brief Brief Description
*
*   @author Lorenz Meier <mavteam@student.ethz.ch>
*
*/
pixhawk's avatar
pixhawk committed
31 32 33 34 35 36 37

#ifndef _LINKINTERFACE_H_
#define _LINKINTERFACE_H_

#include <QThread>

/**
38 39 40 41
* The link interface defines the interface for all links used to communicate
* with the groundstation application.
*
**/
42 43
class LinkInterface : public QThread
{
44
    Q_OBJECT
pixhawk's avatar
pixhawk committed
45
public:
pixhawk's avatar
pixhawk committed
46
    LinkInterface(QObject* parent = 0) : QThread(parent) {}
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
    //virtual ~LinkInterface() = 0;

    /* Connection management */

    /**
     * @brief Get the ID of this link
     *
     * The ID is an unsigned integer, starting at 0
     * @return ID of this link
     **/
    virtual int getId() = 0;

    /**
     * @brief Get the human readable name of this link
     */
    virtual QString getName() = 0;

    /**
     * @brief Determine the connection status
     *
     * @return True if the connection is established, false otherwise
     **/
    virtual bool isConnected() = 0;

    /* Connection characteristics */

    /**
     * @Brief Get the nominal data rate of the interface.
     *
     * The nominal data rate is the theoretical maximum data rate of the
     * interface. For 100Base-T Ethernet this would be 100 Mbit/s (100'000'000
     * Bit/s, NOT 104'857'600 Bit/s).
     *
     * @return The nominal data rate of the interface in bit per second, 0 if unknown
     * @see getLongTermDataRate() For the mean data rate
     * @see getShortTermDataRate() For a the mean data rate of the last seconds
     * @see getCurrentDataRate() For the data rate of the last transferred chunk
     * @see getMaxDataRate() For the maximum data rate
     **/
    virtual qint64 getNominalDataRate() = 0;

    /**
     * @brief Full duplex support of this interface.
     *
     * This method returns true if the interface supports full duplex, which implies
     * the full datarate when sending and receiving data simultaneously.
     *
     * @return True if the interface supports full duplex, false otherwise
     **/
    virtual bool isFullDuplex() = 0;

    /**
     * @brief Get the link quality.
     *
     * The link quality is reported as percent, on a scale from 0 to 100% in 1% increments.
     * If this feature is not supported by the interface, a call to this method return -1.
     *
     * @return The link quality in integer percent or -1 if not supported
     **/
    virtual int getLinkQuality() = 0;

    /**
     * @Brief Get the long term (complete) mean of the data rate
     *
     * The mean of the total data rate. It is calculated as
     * all transferred bits / total link uptime.
     *
     * @return The mean data rate of the interface in bit per second, 0 if unknown
     * @see getNominalDataRate() For the nominal data rate of the interface
     * @see getShortTermDataRate() For a the mean data rate of the last seconds
     * @see getCurrentDataRate() For the data rate of the last transferred chunk
     * @see getMaxDataRate() For the maximum data rate
     **/
    virtual qint64 getTotalUpstream() = 0;

    /**
     * @Brief Get the current data rate
     *
     * The datarate of the last 100 ms
     *
     * @return The mean data rate of the interface in bit per second, 0 if unknown
     * @see getNominalDataRate() For the nominal data rate of the interface
     * @see getLongTermDataRate() For the mean data rate
     * @see getShortTermDataRate() For a the mean data rate of the last seconds
     * @see getMaxDataRate() For the maximum data rate
     **/
    virtual qint64 getCurrentUpstream() = 0;

    /**
     * @Brief Get the maximum data rate
     *
     * The maximum peak data rate.
     *
     * @return The mean data rate of the interface in bit per second, 0 if unknown
     * @see getNominalDataRate() For the nominal data rate of the interface
     * @see getLongTermDataRate() For the mean data rate
     * @see getShortTermDataRate() For a the mean data rate of the last seconds
     * @see getCurrentDataRate() For the data rate of the last transferred chunk
     **/
    virtual qint64 getMaxUpstream() = 0;

    /**
     * @Brief Get the total number of bits sent
     *
     * @return The number of sent bits
     **/
    virtual qint64 getBitsSent() = 0;

    /**
     * @Brief Get the total number of bits received
     *
     * @return The number of received bits
     * @bug Decide if the bits should be counted fromt the instantiation of the interface or if the counter should reset on disconnect.
     **/
    virtual qint64 getBitsReceived() = 0;

    /**
     * @brief Connect this interface logically
     *
     * @return True if connection could be established, false otherwise
     **/
    virtual bool connect() = 0;

    /**
     * @brief Disconnect this interface logically
     *
     * @return True if connection could be terminated, false otherwise
     **/
    virtual bool disconnect() = 0;

    /**
     * @brief Get the current number of bytes in buffer.
     *
     * @return The number of bytes ready to read
     **/
    virtual qint64 bytesAvailable() = 0;
pixhawk's avatar
pixhawk committed
183 184 185

public slots:

186 187 188 189 190 191 192 193 194 195 196
    /**
     * @brief This method allows to write bytes to the interface.
     *
     * If the underlying communication is packet oriented,
     * one write command equals a datagram. In case of serial
     * communication arbitrary byte lengths can be written
     *
     * @param bytes The pointer to the byte array containing the data
     * @param length The length of the data array
     **/
    virtual void writeBytes(const char *bytes, qint64 length) = 0;
pixhawk's avatar
pixhawk committed
197 198

signals:
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230

    /**
     * @brief New data arrived
     *
     * The new data is contained in the QByteArray data. The data is copied for each
     * receiving protocol. For high-speed links like image transmission this might
     * affect performance, for control links it is however desirable to directly
     * forward the link data.
     *
     * @param data the new bytes
     */
    void bytesReceived(LinkInterface* link, QByteArray data);

    /**
     * @brief This signal is emitted instantly when the link is connected
     **/
    void connected();

    /**
     * @brief This signal is emitted instantly when the link is disconnected
     **/
    void disconnected();

    /**
     * @brief This signal is emitted instantly when the link status changes
     **/
    void connected(bool connected);

    /**
     * @brief This signal is emitted if the human readable name of this link changes
     */
    void nameChanged(QString name);
pixhawk's avatar
pixhawk committed
231

232 233 234
    /** @brief Communication error occured */
    void communicationError(const QString& linkname, const QString& error);

pixhawk's avatar
pixhawk committed
235
protected:
236
    static int getNextLinkId() {
237 238 239 240 241 242
        static int nextId = 0;
        return nextId++;
    }

protected slots:

243 244 245 246 247 248 249
    /**
     * @brief Read a number of bytes from the interface.
     *
     * @param bytes The pointer to write the bytes to
     * @param maxLength The maximum length which can be written
     **/
    virtual void readBytes() = 0;
pixhawk's avatar
pixhawk committed
250 251 252 253 254 255 256

};

/* Declare C++ interface as Qt interface */
//Q_DECLARE_INTERFACE(LinkInterface, "org.openground.comm.links.LinkInterface/1.0")

#endif // _LINKINTERFACE_H_