SyslinkComponentController.cc 4.57 KB
Newer Older
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
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#include "SyslinkComponentController.h"
#include "QGCApplication.h"
#include "UAS.h"
#include "ParameterManager.h"

#include <QHostAddress>
#include <QtEndian>

QGC_LOGGING_CATEGORY(SyslinkComponentControllerLog, "SyslinkComponentControllerLog")

//-----------------------------------------------------------------------------
SyslinkComponentController::SyslinkComponentController()
{
    _dataRates.append("750Kb/s");
    _dataRates.append("1Mb/s");
    _dataRates.append("2Mb/s");

    Fact* chan = getParameterFact(_vehicle->id(), "SLNK_RADIO_CHAN");
    connect(chan, &Fact::valueChanged, this, &SyslinkComponentController::_channelChanged);
    Fact* rate = getParameterFact(_vehicle->id(), "SLNK_RADIO_RATE");
    connect(rate, &Fact::valueChanged, this, &SyslinkComponentController::_rateChanged);
    Fact* addr1 = getParameterFact(_vehicle->id(), "SLNK_RADIO_ADDR1");
    connect(addr1, &Fact::valueChanged, this, &SyslinkComponentController::_addressChanged);
    Fact* addr2 = getParameterFact(_vehicle->id(), "SLNK_RADIO_ADDR2");
    connect(addr2, &Fact::valueChanged, this, &SyslinkComponentController::_addressChanged);
}

//-----------------------------------------------------------------------------
SyslinkComponentController::~SyslinkComponentController()
{

}

//-----------------------------------------------------------------------------
int
SyslinkComponentController::radioChannel()
{
    return getParameterFact(_vehicle->id(), "SLNK_RADIO_CHAN")->rawValue().toUInt();
}

//-----------------------------------------------------------------------------
void
SyslinkComponentController::setRadioChannel(int num)
{
    Fact* f = getParameterFact(_vehicle->id(), "SLNK_RADIO_CHAN");
    f->setRawValue(QVariant(num));
}

//-----------------------------------------------------------------------------
QString
SyslinkComponentController::radioAddress()
{
    uint32_t val_uh = getParameterFact(_vehicle->id(), "SLNK_RADIO_ADDR1")->rawValue().toUInt();
    uint32_t val_lh = getParameterFact(_vehicle->id(), "SLNK_RADIO_ADDR2")->rawValue().toUInt();
    uint64_t val = (((uint64_t) val_uh) << 32) | ((uint64_t) val_lh);

    return QString().number(val, 16);
}

//-----------------------------------------------------------------------------
void
SyslinkComponentController::setRadioAddress(QString str)
{
    Fact *uh = getParameterFact(_vehicle->id(), "SLNK_RADIO_ADDR1");
    Fact *lh = getParameterFact(_vehicle->id(), "SLNK_RADIO_ADDR2");

    uint64_t val = str.toULongLong(0, 16);

    uint32_t val_uh = val >> 32;
    uint32_t val_lh = val & 0xFFFFFFFF;

    uh->setRawValue(QVariant(val_uh));
    lh->setRawValue(QVariant(val_lh));
}

//-----------------------------------------------------------------------------
int
SyslinkComponentController::radioRate()
{
    return getParameterFact(_vehicle->id(), "SLNK_RADIO_RATE")->rawValue().toInt();
}

//-----------------------------------------------------------------------------
void
SyslinkComponentController::setRadioRate(int idx)
{
    if(idx >= 0 && idx <= 2 && idx != radioRate()) {
        Fact* r = getParameterFact(_vehicle->id(), "SLNK_RADIO_RATE");
        r->setRawValue(idx);
    }
}

//-----------------------------------------------------------------------------
void
SyslinkComponentController::resetDefaults()
{
    Fact* chan = getParameterFact(_vehicle->id(), "SLNK_RADIO_CHAN");
    Fact* rate = getParameterFact(_vehicle->id(), "SLNK_RADIO_RATE");
    Fact* addr1 = getParameterFact(_vehicle->id(), "SLNK_RADIO_ADDR1");
    Fact* addr2 = getParameterFact(_vehicle->id(), "SLNK_RADIO_ADDR2");

    chan->setRawValue(chan->rawDefaultValue());
    rate->setRawValue(rate->rawDefaultValue());
    addr1->setRawValue(addr1->rawDefaultValue());
    addr2->setRawValue(addr2->rawDefaultValue());
}

//-----------------------------------------------------------------------------
void
SyslinkComponentController::_channelChanged(QVariant)
{
    emit radioChannelChanged();
}

//-----------------------------------------------------------------------------
void
SyslinkComponentController::_addressChanged(QVariant)
{
    emit radioAddressChanged();
}

//-----------------------------------------------------------------------------
void
SyslinkComponentController::_rateChanged(QVariant)
{
    emit radioRateChanged();
}