///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
// //
// This program 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 as version 3 of the License, or //
// //
// This program 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 V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see . //
///////////////////////////////////////////////////////////////////////////////////
#include
#include "xtrx_api.h"
#include "devicextrx.h"
const uint32_t DeviceXTRX::m_lnaTbl[m_nbGains] = {
0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5,
5, 5, 6, 6, 6, 7, 7, 7, 8, 9, 10, 11, 11, 11, 11, 11,
11, 11, 11, 11, 11, 11, 11, 11, 12, 13, 14, 14, 14, 14, 14, 14,
14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
14, 14, 14, 14, 14, 14, 14, 14, 14, 14
};
const uint32_t DeviceXTRX::m_pgaTbl[m_nbGains] = {
0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0,
1, 2, 0, 1, 2, 0, 1, 2, 0, 0, 0, 0, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12, 4, 5, 6, 7, 8,
9, 10, 11, 12, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31
};
DeviceXTRX::DeviceXTRX() :
m_dev(0)
{}
DeviceXTRX::~DeviceXTRX()
{
close();
}
bool DeviceXTRX::open(const char* deviceStr)
{
int res;
qDebug("DeviceXTRX::open: serial: %s", (const char *) deviceStr);
res = xtrx_open(deviceStr, XTRX_O_RESET | 4, &m_dev);
if (res)
{
qCritical() << "DeviceXTRX::open: cannot open device " << deviceStr;
return false;
}
return true;
}
void DeviceXTRX::close()
{
if (m_dev)
{
xtrx_close(m_dev);
m_dev = 0;
}
}
void DeviceXTRX::getAutoGains(uint32_t autoGain, uint32_t& lnaGain, uint32_t& tiaGain, uint32_t& pgaGain)
{
uint32_t value = autoGain + 12 > 73 ? 73 : autoGain + 12;
if (value > 51) {
tiaGain = 2;
} else if (value > 42) {
tiaGain = 1;
} else {
tiaGain = 0;
}
lnaGain = m_lnaTbl[value];
pgaGain = m_pgaTbl[value];
}