AS4Protocol.cc 3.87 KB
Newer Older
pixhawk's avatar
pixhawk committed
1
/*=====================================================================
lm's avatar
lm committed
2 3 4 5 6 7 8 9

QGroundControl Open Source Ground Control Station

(c) 2009, 2010 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
pixhawk's avatar
pixhawk committed
10 11 12
    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.
lm's avatar
lm committed
13 14

    QGROUNDCONTROL is distributed in the hope that it will be useful,
pixhawk's avatar
pixhawk committed
15 16 17
    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.
lm's avatar
lm committed
18

pixhawk's avatar
pixhawk committed
19
    You should have received a copy of the GNU General Public License
lm's avatar
lm committed
20 21
    along with QGROUNDCONTROL. 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
/**
 * @file
 *   @brief Brief Description
 *
 *   @author Lorenz Meier <mavteam@student.ethz.ch>
 *
 */

#include <QDebug>
#include <QTime>

#include <MG.h>
#include <AS4Protocol.h>
#include <UASInterface.h>
#include <UASManager.h>
#include <UASInterface.h>
#include <UAS.h>
#include <configuration.h>
#include <LinkManager.h>
#include <inttypes.h>
#include <iostream>

46 47
#include "QGC.h"

pixhawk's avatar
pixhawk committed
48 49 50 51 52 53 54 55 56

AS4Protocol::AS4Protocol()
{

    // Start heartbeat timer, emitting a heartbeat at the configured rate
    heartbeatRate = 1; ///< SAE AS-4 has a fixed heartbeat rate of 1 hz.
//    heartbeatTimer = new QTimer(this);
//    connect(heartbeatTimer, SIGNAL(timeout()), this, SLOT());
//    heartbeatTimer->start(1000/heartbeatRate);
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
    /*
        // Start the node manager
        configData = new FileLoader("nodeManager.conf");
        handler = new MyHandler();

            try
            {
                    nodeManager = new NodeManager(configData, handler);
                    qDebug() << "SAE AS-4 NODE MANAGER constructed";
            }
            catch(char *exceptionString)
            {
                    printf("%s", exceptionString);
                    printf("Terminating Program...\n");
            }
            catch(...)
            {
                    printf("Node Manager Construction Failed. Terminating Program...\n");
            }
            */
pixhawk's avatar
pixhawk committed
77 78 79 80 81 82 83 84 85 86 87 88

}

AS4Protocol::~AS4Protocol()
{
//        delete nodeManager;
//        delete handler;
//        delete configData;
}

void AS4Protocol::run()
{
89
    forever {
90 91
        QGC::SLEEP::msleep(5000);
    }
pixhawk's avatar
pixhawk committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
}


/**
 * @brief Receive bytes from a communication interface.
 *
 * The bytes copied by calling the LinkInterface::readBytes() method.
 *
 * @param link The interface to read from
 * @see LinkInterface
 **/
void AS4Protocol::receiveBytes(LinkInterface* link)
{
//    receiveMutex.lock();
    // Prepare buffer
107 108
    //static const int maxlen = 4096 * 100;
    //static char buffer[maxlen];
pixhawk's avatar
pixhawk committed
109 110 111 112

    qint64 bytesToRead = link->bytesAvailable();

    // Get all data at once, let link read the bytes in the buffer array
113
    //link->readBytes(buffer, maxlen);
pixhawk's avatar
pixhawk committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127
//
//    /*
//    // Debug output
//    std::cerr << "receive buffer: ";
//    for (int i = 0; i < bytesToRead; i++)
//    {
//            std::cerr << std::hex << static_cast<unsigned char>(buffer[i]);
//    }
//    std::cerr << std::dec << " length: " << bytesToRead;
//    */
//
//    qDebug() << __FILE__ << __LINE__ << ": buffer size:" << maxlen << "bytes:" << bytesToRead;
//

128
    for (int position = 0; position < bytesToRead; position++) {
pixhawk's avatar
pixhawk committed
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
    }
//    receiveMutex.unlock();

}


/**
 * @brief Get the human-readable name of this protocol.
 *
 * @return The name of this protocol
 **/
QString AS4Protocol::getName()
{
    return QString(tr("SAE AS-4"));
}

void AS4Protocol::setHeartbeatRate(int rate)
{
    heartbeatRate = rate;
    heartbeatTimer->setInterval(1000/heartbeatRate);
}

int AS4Protocol::getHeartbeatRate()
{
    return heartbeatRate;
}