AS4Protocol.h 4.04 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 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
/*=====================================================================
 
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
 
(c) 2009 PIXHAWK PROJECT  <http://pixhawk.ethz.ch>
 
This file is part of the PIXHAWK project
 
    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/>.
 
======================================================================*/
 
/**
 * @file
 *   @brief Brief Description
 *
 *   @author Lorenz Meier <mavteam@student.ethz.ch>
 *
 */

#ifndef AS4PROTOCOL_H_
#define AS4PROTOCOL_H_

#include <QObject>
#include <QMutex>
#include <QString>
#include <QTimer>
#include <QByteArray>
#include <ProtocolInterface.h>
#include <LinkInterface.h>
#include <protocol.h>
/*#include <openJaus.h>

class MyHandler : public EventHandler
{
public:
    ~MyHandler()
    {

    }

    void handleEvent(NodeManagerEvent *e)
    {
        SystemTreeEvent *treeEvent;
        ErrorEvent *errorEvent;
        JausMessageEvent *messageEvent;
        DebugEvent *debugEvent;
        ConfigurationEvent *configEvent;

        switch(e->getType())
        {
                        case NodeManagerEvent::SystemTreeEvent:
            treeEvent = (SystemTreeEvent *)e;
            printf("%s\n", treeEvent->toString().c_str());
            delete e;
            break;

                        case NodeManagerEvent::ErrorEvent:
            errorEvent = (ErrorEvent *)e;
            printf("%s\n", errorEvent->toString().c_str());
            delete e;
            break;

                        case NodeManagerEvent::JausMessageEvent:
            messageEvent = (JausMessageEvent *)e;
            // If you turn this on, the system gets spam-y this is very useful for debug purposes
            if(messageEvent->getJausMessage()->commandCode != JAUS_REPORT_HEARTBEAT_PULSE)
            {
                //printf("%s\n", messageEvent->toString().c_str());
            }
            else
            {
                //printf("%s\n", messageEvent->toString().c_str());
            }
            delete e;
            break;

                        case NodeManagerEvent::DebugEvent:
            debugEvent = (DebugEvent *)e;
            //printf("%s\n", debugEvent->toString().c_str());
            delete e;
            break;

                        case NodeManagerEvent::ConfigurationEvent:
            configEvent = (ConfigurationEvent *)e;
            printf("%s\n", configEvent->toString().c_str());
            delete e;
            break;

                        default:
            delete e;
            break;
        }
    }
};*/

/**
 * SAE AS-4 Nodemanager
 *
 **/
class AS4Protocol : public ProtocolInterface {
    Q_OBJECT

public:
    AS4Protocol();
    ~AS4Protocol();

    void run();
    QString getName();
    int getHeartbeatRate();

public slots:
    void receiveBytes(LinkInterface* link);
    /**
         * @brief Set the rate at which heartbeats are emitted
         *
         * The default rate is 1 Hertz.
         *
         * @param rate heartbeat rate in hertz (times per second)
         */
    void setHeartbeatRate(int rate);

    /**
         * @brief Send an extra heartbeat to all connected units
         *
         * The heartbeat is sent out of order and does not reset the
         * periodic heartbeat emission. It will be just sent in addition.
         */
//    void sendHeartbeat();

protected:
    QTimer* heartbeatTimer;
    int heartbeatRate;
    QMutex receiveMutex;
//    NodeManager* nodeManager;
//    MyHandler* handler;
//    FileLoader* configData;

signals:

};

#endif // AS4PROTOCOL_H_