SyslinkComponentController.cc 4.86 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
/****************************************************************************
 *
 *   (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()
{
Don Gagne's avatar
Don Gagne committed
23 24 25
    _dataRates.append(QStringLiteral("750Kb/s"));
    _dataRates.append(QStringLiteral("1Mb/s"));
    _dataRates.append(QStringLiteral("2Mb/s"));
26

Don Gagne's avatar
Don Gagne committed
27
    Fact* chan = getParameterFact(_vehicle->id(), QStringLiteral("SLNK_RADIO_CHAN"));
28
    connect(chan, &Fact::valueChanged, this, &SyslinkComponentController::_channelChanged);
Don Gagne's avatar
Don Gagne committed
29
    Fact* rate = getParameterFact(_vehicle->id(), QStringLiteral("SLNK_RADIO_RATE"));
30
    connect(rate, &Fact::valueChanged, this, &SyslinkComponentController::_rateChanged);
Don Gagne's avatar
Don Gagne committed
31
    Fact* addr1 = getParameterFact(_vehicle->id(), QStringLiteral("SLNK_RADIO_ADDR1"));
32
    connect(addr1, &Fact::valueChanged, this, &SyslinkComponentController::_addressChanged);
Don Gagne's avatar
Don Gagne committed
33
    Fact* addr2 = getParameterFact(_vehicle->id(), QStringLiteral("SLNK_RADIO_ADDR2"));
34 35 36 37 38 39 40 41 42 43 44 45 46
    connect(addr2, &Fact::valueChanged, this, &SyslinkComponentController::_addressChanged);
}

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

}

//-----------------------------------------------------------------------------
int
SyslinkComponentController::radioChannel()
{
Don Gagne's avatar
Don Gagne committed
47
    return getParameterFact(_vehicle->id(), QStringLiteral("SLNK_RADIO_CHAN"))->rawValue().toUInt();
48 49 50 51 52 53
}

//-----------------------------------------------------------------------------
void
SyslinkComponentController::setRadioChannel(int num)
{
Don Gagne's avatar
Don Gagne committed
54
    Fact* f = getParameterFact(_vehicle->id(), QStringLiteral("SLNK_RADIO_CHAN"));
55 56 57 58 59 60 61
    f->setRawValue(QVariant(num));
}

//-----------------------------------------------------------------------------
QString
SyslinkComponentController::radioAddress()
{
Don Gagne's avatar
Don Gagne committed
62 63
    uint32_t val_uh = getParameterFact(_vehicle->id(), QStringLiteral("SLNK_RADIO_ADDR1"))->rawValue().toUInt();
    uint32_t val_lh = getParameterFact(_vehicle->id(), QStringLiteral("SLNK_RADIO_ADDR2"))->rawValue().toUInt();
64 65 66 67 68 69 70 71 72
    uint64_t val = (((uint64_t) val_uh) << 32) | ((uint64_t) val_lh);

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

//-----------------------------------------------------------------------------
void
SyslinkComponentController::setRadioAddress(QString str)
{
Don Gagne's avatar
Don Gagne committed
73 74
    Fact *uh = getParameterFact(_vehicle->id(), QStringLiteral("SLNK_RADIO_ADDR1"));
    Fact *lh = getParameterFact(_vehicle->id(), QStringLiteral("SLNK_RADIO_ADDR2"));
75 76 77 78 79 80 81 82 83 84 85 86 87 88

    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()
{
Don Gagne's avatar
Don Gagne committed
89
    return getParameterFact(_vehicle->id(), QStringLiteral("SLNK_RADIO_RATE"))->rawValue().toInt();
90 91 92 93 94 95 96
}

//-----------------------------------------------------------------------------
void
SyslinkComponentController::setRadioRate(int idx)
{
    if(idx >= 0 && idx <= 2 && idx != radioRate()) {
Don Gagne's avatar
Don Gagne committed
97
        Fact* r = getParameterFact(_vehicle->id(), QStringLiteral("SLNK_RADIO_RATE"));
98 99 100 101 102 103 104 105
        r->setRawValue(idx);
    }
}

//-----------------------------------------------------------------------------
void
SyslinkComponentController::resetDefaults()
{
Don Gagne's avatar
Don Gagne committed
106 107 108 109
    Fact* chan = getParameterFact(_vehicle->id(), QStringLiteral("SLNK_RADIO_CHAN"));
    Fact* rate = getParameterFact(_vehicle->id(), QStringLiteral("SLNK_RADIO_RATE"));
    Fact* addr1 = getParameterFact(_vehicle->id(), QStringLiteral("SLNK_RADIO_ADDR1"));
    Fact* addr2 = getParameterFact(_vehicle->id(), QStringLiteral("SLNK_RADIO_ADDR2"));
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

    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();
}