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.
fileinputsettings.cpp
Go to the documentation of this file.
1 // Copyright (C) 2017-2019 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 "util/simpleserializer.h"
19 
20 #include "fileinputsettings.h"
21 
22 const unsigned int FileInputSettings::m_accelerationMaxScale = 2;
23 
25 {
27 }
28 
30 {
31  m_centerFrequency = 435000000;
32  m_sampleRate = 48000;
33  m_fileName = "./test.sdriq";
35  m_loop = true;
36  m_useReverseAPI = false;
37  m_reverseAPIAddress = "127.0.0.1";
38  m_reverseAPIPort = 8888;
40 }
41 
42 QByteArray FileInputSettings::serialize() const
43 {
44  SimpleSerializer s(1);
45  s.writeString(1, m_fileName);
47  s.writeBool(3, m_loop);
52 
53  return s.final();
54 }
55 
56 bool FileInputSettings::deserialize(const QByteArray& data)
57 {
58  SimpleDeserializer d(data);
59 
60  if(!d.isValid()) {
62  return false;
63  }
64 
65  if (d.getVersion() == 1)
66  {
67  uint32_t uintval;
68 
69  d.readString(1, &m_fileName, "./test.sdriq");
70  d.readU32(2, &m_accelerationFactor, 1);
71  d.readBool(3, &m_loop, true);
72  d.readBool(4, &m_useReverseAPI, false);
73  d.readString(5, &m_reverseAPIAddress, "127.0.0.1");
74  d.readU32(6, &uintval, 0);
75 
76  if ((uintval > 1023) && (uintval < 65535)) {
77  m_reverseAPIPort = uintval;
78  } else {
79  m_reverseAPIPort = 8888;
80  }
81 
82  d.readU32(7, &uintval, 0);
83  m_reverseAPIDeviceIndex = uintval > 99 ? 99 : uintval;
84 
85  return true;
86  }
87  else
88  {
90  return false;
91  }
92 }
93 
94 int FileInputSettings::getAccelerationIndex(int accelerationValue)
95 {
96  if (accelerationValue <= 1) {
97  return 0;
98  }
99 
100  int v = accelerationValue;
101  int j = 0;
102 
103  for (int i = 0; i <= accelerationValue; i++)
104  {
105  if (v < 20)
106  {
107  if (v < 2) {
108  j = 0;
109  } else if (v < 5) {
110  j = 1;
111  } else if (v < 10) {
112  j = 2;
113  } else {
114  j = 3;
115  }
116 
117  return 3*i + j;
118  }
119 
120  v /= 10;
121  }
122 
123  return 3*m_accelerationMaxScale + 3;
124 }
125 
126 int FileInputSettings::getAccelerationValue(int accelerationIndex)
127 {
128  if (accelerationIndex <= 0) {
129  return 1;
130  }
131 
132  unsigned int v = accelerationIndex - 1;
133  int m = pow(10.0, v/3 > m_accelerationMaxScale ? m_accelerationMaxScale : v/3);
134  int x = 1;
135 
136  if (v % 3 == 0) {
137  x = 2;
138  } else if (v % 3 == 1) {
139  x = 5;
140  } else if (v % 3 == 2) {
141  x = 10;
142  }
143 
144  return x * m;
145 }
146 
147 
148 
149 
150 
uint16_t m_reverseAPIDeviceIndex
bool deserialize(const QByteArray &data)
bool readU32(quint32 id, quint32 *result, quint32 def=0) const
bool readString(quint32 id, QString *result, const QString &def=QString::null) const
bool readBool(quint32 id, bool *result, bool def=false) const
bool isValid() const
unsigned int uint32_t
Definition: rtptypes_win.h:46
QByteArray serialize() const
int32_t i
Definition: decimators.h:244
static int getAccelerationIndex(int averaging)
static int getAccelerationValue(int averagingIndex)
quint32 getVersion() const
void writeU32(quint32 id, quint32 value)
void writeBool(quint32 id, bool value)
static const unsigned int m_accelerationMaxScale
Max power of 10 multiplier to 2,5,10 base ex: 2 -> 2,5,10,20,50,100,200,500,1000. ...
void writeString(quint32 id, const QString &value)
const QByteArray & final()