diff --git a/devices/xtrx/CMakeLists.txt b/devices/xtrx/CMakeLists.txt
index 189c1b534..14d8d1cb7 100644
--- a/devices/xtrx/CMakeLists.txt
+++ b/devices/xtrx/CMakeLists.txt
@@ -1,11 +1,13 @@
project(xtrxdevice)
set(xtrxdevice_SOURCES
+ devicextrx.cpp
devicextrxparam.cpp
devicextrxshared.cpp
)
set(xtrxdevice_HEADERS
+ devicextrx.h
devicextrxparam.h
devicextrxshared.h
)
diff --git a/devices/xtrx/devicextrx.cpp b/devices/xtrx/devicextrx.cpp
new file mode 100644
index 000000000..02e969681
--- /dev/null
+++ b/devices/xtrx/devicextrx.cpp
@@ -0,0 +1,49 @@
+///////////////////////////////////////////////////////////////////////////////////
+// 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 "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
+};
+
+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];
+}
diff --git a/devices/xtrx/devicextrx.h b/devices/xtrx/devicextrx.h
new file mode 100644
index 000000000..362a08e5d
--- /dev/null
+++ b/devices/xtrx/devicextrx.h
@@ -0,0 +1,37 @@
+///////////////////////////////////////////////////////////////////////////////////
+// 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 . //
+///////////////////////////////////////////////////////////////////////////////////
+
+#ifndef DEVICES_XTRX_DEVICEXTRX_H_
+#define DEVICES_XTRX_DEVICEXTRX_H_
+
+#include
+
+#include "export.h"
+
+class DEVICES_API DeviceXTRX
+{
+public:
+ static void getAutoGains(uint32_t autoGain, uint32_t& lnaGain, uint32_t& tiaGain, uint32_t& pgaGain);
+ static const uint32_t m_nbGains = 74;
+
+private:
+ static const uint32_t m_lnaTbl[m_nbGains];
+ static const uint32_t m_pgaTbl[m_nbGains];
+};
+
+
+
+#endif /* DEVICES_XTRX_DEVICEXTRX_H_ */
diff --git a/plugins/samplesource/xtrxinput/xtrxinput.cpp b/plugins/samplesource/xtrxinput/xtrxinput.cpp
index 18958bfb1..5b276891d 100644
--- a/plugins/samplesource/xtrxinput/xtrxinput.cpp
+++ b/plugins/samplesource/xtrxinput/xtrxinput.cpp
@@ -29,6 +29,7 @@
#include "xtrxinputthread.h"
#include "xtrx/devicextrxparam.h"
#include "xtrx/devicextrxshared.h"
+#include "xtrx/devicextrx.h"
MESSAGE_CLASS_DEFINITION(XTRXInput::MsgConfigureXTRX, Message)
MESSAGE_CLASS_DEFINITION(XTRXInput::MsgGetStreamInfo, Message)
@@ -653,21 +654,15 @@ static double tia_to_db(unsigned idx)
}
}
-void XTRXInput::apply_gain_auto(double gain)
+void XTRXInput::apply_gain_auto(uint32_t gain)
{
- if (xtrx_set_gain(m_deviceShared.m_deviceParams->getDevice(),
- XTRX_CH_AB /*m_deviceShared.m_channel*/,
- XTRX_RX_LNA_GAIN,
- gain,
- NULL) < 0)
- {
- qDebug("XTRXInput::applySettings: xtrx_set_gain(auto) failed");
- }
- else
- {
- //doCalibration = true;
- qDebug() << "XTRXInput::applySettings: Gain (auto) set to " << gain;
- }
+ uint32_t lna, tia, pga;
+
+ DeviceXTRX::getAutoGains(gain, lna, tia, pga);
+
+ apply_gain_lna(lna);
+ apply_gain_tia(tia_to_db(tia));
+ apply_gain_pga(pga);
}
void XTRXInput::apply_gain_lna(double gain)
diff --git a/plugins/samplesource/xtrxinput/xtrxinput.h b/plugins/samplesource/xtrxinput/xtrxinput.h
index 9d713ba4c..3c771fffa 100644
--- a/plugins/samplesource/xtrxinput/xtrxinput.h
+++ b/plugins/samplesource/xtrxinput/xtrxinput.h
@@ -194,7 +194,7 @@ public:
void getLPRange(float& minF, float& maxF, float& stepF) const;
uint32_t getHWLog2Decim() const;
- void apply_gain_auto(double gain);
+ void apply_gain_auto(uint32_t gain);
void apply_gain_lna(double gain);
void apply_gain_tia(double gain);
void apply_gain_pga(double gain);