AS4Protocol.cc 3.69 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4
/*=====================================================================
 
PIXHAWK Micro Air Vehicle Flying Robotics Toolkit
 
pixhawk's avatar
pixhawk committed
5
(c) 2009, 2010 PIXHAWK PROJECT  <http://pixhawk.ethz.ch>
pixhawk's avatar
pixhawk committed
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
 
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>
 *
 */

#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>


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);
/*
    // 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");
        }
        */

}

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

void AS4Protocol::run()
{
}


/**
 * @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
    static const int maxlen = 4096 * 100;
    static char buffer[maxlen];

    qint64 bytesToRead = link->bytesAvailable();

    // Get all data at once, let link read the bytes in the buffer array
    link->readBytes(buffer, maxlen);
//
//    /*
//    // 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;
//

    for (int position = 0; position < bytesToRead; position++)
    {
    }
//    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;
}