SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
devicextrx.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018 Edouard Griffiths, F4EXB //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #include <QDebug>
19 
20 #include "xtrx_api.h"
21 #include "devicextrx.h"
22 
23 const uint32_t DeviceXTRX::m_lnaTbl[m_nbGains] = {
24  0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5,
25  5, 5, 6, 6, 6, 7, 7, 7, 8, 9, 10, 11, 11, 11, 11, 11,
26  11, 11, 11, 11, 11, 11, 11, 11, 12, 13, 14, 14, 14, 14, 14, 14,
27  14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
28  14, 14, 14, 14, 14, 14, 14, 14, 14, 14
29 };
30 
31 const uint32_t DeviceXTRX::m_pgaTbl[m_nbGains] = {
32  0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0,
33  1, 2, 0, 1, 2, 0, 1, 2, 0, 0, 0, 0, 1, 2, 3, 4,
34  5, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12, 4, 5, 6, 7, 8,
35  9, 10, 11, 12, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
36  22, 23, 24, 25, 26, 27, 28, 29, 30, 31
37 };
38 
40  m_dev(0),
41  m_inputRate(0),
42  m_outputRate(0),
43  m_masterRate(0),
44  m_clockGen(0),
45  m_actualInputRate(0),
46  m_actualOutputRate(0)
47 {}
48 
50 {
51  close();
52 }
53 
54 bool DeviceXTRX::open(const char* deviceStr)
55 {
56  int res;
57  qDebug("DeviceXTRX::open: serial: %s", (const char *) deviceStr);
58 
59  res = xtrx_open(deviceStr, XTRX_O_RESET | 4, &m_dev);
60 
61  if (res)
62  {
63  qCritical() << "DeviceXTRX::open: cannot open device " << deviceStr;
64  return false;
65  }
66 
67  return true;
68 }
69 
71 {
72  if (m_dev)
73  {
74  xtrx_close(m_dev);
75  m_dev = 0;
76  }
77 }
78 
79 void DeviceXTRX::getAutoGains(uint32_t autoGain, uint32_t& lnaGain, uint32_t& tiaGain, uint32_t& pgaGain)
80 {
81  uint32_t value = autoGain + 12 > 73 ? 73 : autoGain + 12;
82 
83  if (value > 51) {
84  tiaGain = 2;
85  } else if (value > 42) {
86  tiaGain = 1;
87  } else {
88  tiaGain = 0;
89  }
90 
91  lnaGain = m_lnaTbl[value];
92  pgaGain = m_pgaTbl[value];
93 }
94 
95 double DeviceXTRX::set_samplerate(double rate, double master, bool output)
96 {
97  if (output)
98  {
99  m_outputRate = rate;
100 
101  if (master != 0.0) {
102  m_masterRate = master;
103  }
104  }
105  else
106  {
107  m_inputRate = rate;
108 
109  if (master != 0.0) {
110  m_masterRate = master;
111  }
112  }
113 
114  int res = xtrx_set_samplerate(m_dev,
115  m_masterRate,
116  m_inputRate,
117  m_outputRate,
118  0,
119  &m_clockGen,
122 
123  if (res)
124  {
125  qCritical("DeviceXTRX::set_samplerate: Unable to set %s samplerate, m_masterRate: %f, m_inputRate: %f, m_outputRate: %f, error=%d\n",
126  output ? "output" : "input", m_masterRate, m_inputRate, m_outputRate, res);
127  return 0;
128  }
129  else
130  {
131  qDebug() << "DeviceXTRX::set_samplerate: sample rate set: "
132  << "output: "<< output
133  << "m_masterRate: " << m_masterRate
134  << "m_inputRate: " << m_inputRate
135  << "m_outputRate: " << m_outputRate
136  << "m_clockGen: " << m_clockGen
137  << "m_actualInputRate: " << m_actualInputRate
138  << "m_actualOutputRate: " << m_actualOutputRate;
139  }
140 
141  if (output) {
142  return m_outputRate;
143  }
144 
145  return m_inputRate;
146 }
static const uint32_t m_lnaTbl[m_nbGains]
Definition: devicextrx.h:55
double m_clockGen
Definition: devicextrx.h:51
double set_samplerate(double rate, double master, bool output)
Definition: devicextrx.cpp:95
double m_outputRate
Definition: devicextrx.h:49
unsigned int uint32_t
Definition: rtptypes_win.h:46
double m_actualInputRate
Definition: devicextrx.h:52
static const uint32_t m_pgaTbl[m_nbGains]
Definition: devicextrx.h:56
double m_inputRate
Definition: devicextrx.h:48
void close()
Definition: devicextrx.cpp:70
double m_masterRate
Definition: devicextrx.h:50
struct xtrx_dev * m_dev
device handle
Definition: devicextrx.h:47
static void getAutoGains(uint32_t autoGain, uint32_t &lnaGain, uint32_t &tiaGain, uint32_t &pgaGain)
Definition: devicextrx.cpp:79
bool open(const char *deviceStr)
Definition: devicextrx.cpp:54
double m_actualOutputRate
Definition: devicextrx.h:53