2018-12-28 19:20:48 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2017 Sergey Kostanbaev, Fairwaves Inc. //
|
|
|
|
// //
|
|
|
|
// 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 <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-12-29 18:44:37 -05:00
|
|
|
#include <QDebug>
|
|
|
|
|
2018-12-28 19:20:48 -05:00
|
|
|
#include "devicextrxshared.h"
|
2018-12-30 19:43:24 -05:00
|
|
|
#include "devicextrx.h"
|
2018-12-28 19:20:48 -05:00
|
|
|
|
|
|
|
MESSAGE_CLASS_DEFINITION(DeviceXTRXShared::MsgReportBuddyChange, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(DeviceXTRXShared::MsgReportClockSourceChange, Message)
|
|
|
|
MESSAGE_CLASS_DEFINITION(DeviceXTRXShared::MsgReportDeviceInfo, Message)
|
|
|
|
|
|
|
|
const float DeviceXTRXShared::m_sampleFifoLengthInSeconds = 0.25;
|
|
|
|
const int DeviceXTRXShared::m_sampleFifoMinSize = 48000; // 192kS/s knee
|
|
|
|
|
2018-12-30 19:43:24 -05:00
|
|
|
DeviceXTRXShared::DeviceXTRXShared() :
|
|
|
|
m_dev(0),
|
|
|
|
m_channel(-1),
|
|
|
|
m_source(0),
|
|
|
|
m_sink(0),
|
|
|
|
m_inputRate(0),
|
|
|
|
m_outputRate(0),
|
|
|
|
m_masterRate(0)
|
|
|
|
{}
|
2018-12-28 19:20:48 -05:00
|
|
|
|
2018-12-30 19:43:24 -05:00
|
|
|
DeviceXTRXShared::~DeviceXTRXShared()
|
|
|
|
{}
|
2018-12-28 19:20:48 -05:00
|
|
|
|
2018-12-30 19:43:24 -05:00
|
|
|
double DeviceXTRXShared::set_samplerate(double rate, double master, bool output)
|
2018-12-28 19:20:48 -05:00
|
|
|
{
|
|
|
|
if (output)
|
|
|
|
{
|
|
|
|
m_outputRate = rate;
|
|
|
|
|
|
|
|
if (master != 0.0) {
|
|
|
|
m_masterRate = master;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_inputRate = rate;
|
|
|
|
|
|
|
|
if (master != 0.0) {
|
|
|
|
m_masterRate = master;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-29 18:44:37 -05:00
|
|
|
double actualcgen;
|
|
|
|
double actualrx;
|
|
|
|
double actualtx;
|
|
|
|
|
2018-12-30 19:43:24 -05:00
|
|
|
int res = xtrx_set_samplerate(m_dev->getDevice(),
|
2018-12-28 19:20:48 -05:00
|
|
|
m_masterRate,
|
|
|
|
m_inputRate,
|
|
|
|
m_outputRate,
|
|
|
|
0,
|
2018-12-29 18:44:37 -05:00
|
|
|
&actualcgen,
|
|
|
|
&actualrx,
|
|
|
|
&actualtx);
|
2018-12-28 19:20:48 -05:00
|
|
|
|
2018-12-29 18:44:37 -05:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
qCritical("DeviceXTRXShared::set_samplerate: Unable to set %s samplerate, m_masterRate: %f, m_inputRate: %f, m_outputRate: %f, error=%d\n",
|
|
|
|
output ? "output" : "input", m_masterRate, m_inputRate, m_outputRate, res);
|
2018-12-28 19:20:48 -05:00
|
|
|
return 0;
|
|
|
|
}
|
2018-12-29 18:44:37 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug() << "DeviceXTRXShared::set_samplerate: sample rate set: "
|
|
|
|
<< "output: "<< output
|
|
|
|
<< "m_masterRate: " << m_masterRate
|
|
|
|
<< "m_inputRate: " << m_inputRate
|
|
|
|
<< "m_outputRate: " << m_outputRate
|
|
|
|
<< "actualcgen: " << actualcgen
|
|
|
|
<< "actualrx: " << actualrx
|
|
|
|
<< "actualtx: " << actualtx;
|
|
|
|
}
|
2018-12-28 19:20:48 -05:00
|
|
|
|
|
|
|
if (output) {
|
|
|
|
return m_outputRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_inputRate;
|
|
|
|
}
|
|
|
|
|
2018-12-29 05:07:14 -05:00
|
|
|
double DeviceXTRXShared::get_board_temperature()
|
2018-12-28 19:20:48 -05:00
|
|
|
{
|
|
|
|
uint64_t val = 0;
|
|
|
|
|
2018-12-30 19:43:24 -05:00
|
|
|
int res = xtrx_val_get(m_dev->getDevice(), XTRX_TRX, XTRX_CH_AB, XTRX_BOARD_TEMP, &val);
|
2018-12-28 19:20:48 -05:00
|
|
|
|
|
|
|
if (res) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
2018-12-29 05:07:14 -05:00
|
|
|
|
|
|
|
bool DeviceXTRXShared::get_gps_status()
|
|
|
|
{
|
|
|
|
uint64_t val = 0;
|
|
|
|
|
2018-12-30 19:43:24 -05:00
|
|
|
int res = xtrx_val_get(m_dev->getDevice(), XTRX_TRX, XTRX_CH_AB, XTRX_WAIT_1PPS, &val);
|
2018-12-29 05:07:14 -05:00
|
|
|
|
|
|
|
if (res) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return val != 0;
|
|
|
|
}
|