LinkInterface.h 5.81 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
    virtual ~LinkInterface() { emit this->deleteLink(this); }
48 49 50 51 52 53 54 55 56

    /* Connection management */

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

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

64 65
    virtual void requestReset() = 0;

66 67 68 69 70
    /**
     * @brief Determine the connection status
     *
     * @return True if the connection is established, false otherwise
     **/
71
    virtual bool isConnected() const = 0;
72 73 74 75

    /* Connection characteristics */

    /**
76
     * @Brief Get the maximum connection speed for this interface.
77 78 79 80 81 82 83
     *
     * 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
     **/
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
    virtual qint64 getConnectionSpeed() const = 0;

    /**
     * @Brief Get the current incoming data rate.
     *
     * This should be over a short timespan, something like 100ms. A precise value isn't necessary,
     * and this can be filtered, but should be a reasonable estimate of current data rate.
     *
     * @return The data rate of the interface in bits per second, 0 if unknown
     **/
    virtual qint64 getCurrentInDataRate() const = 0;

    /**
     * @Brief Get the current outgoing data rate.
     *
     * This should be over a short timespan, something like 100ms. A precise value isn't necessary,
     * and this can be filtered, but should be a reasonable estimate of current data rate.
     *
     * @return The data rate of the interface in bits per second, 0 if unknown
     **/
    virtual qint64 getCurrentOutDataRate() const = 0;
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125

    /**
     * @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
126 127 128

public slots:

129 130 131 132 133 134 135 136 137 138 139
    /**
     * @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
140 141

signals:
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

    /**
     * @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
174

175 176 177
    /** @brief Communication error occured */
    void communicationError(const QString& linkname, const QString& error);

178 179
    void communicationUpdate(const QString& linkname, const QString& text);

180 181 182
	/** @brief destroying element */
	void deleteLink(LinkInterface* const link);

pixhawk's avatar
pixhawk committed
183
protected:
184
    static int getNextLinkId() {
185
        static int nextId = 1;
186 187 188 189 190
        return nextId++;
    }

protected slots:

191 192 193 194 195 196 197
    /**
     * @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
198 199 200 201 202 203 204

};

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

#endif // _LINKINTERFACE_H_