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.
preset.h
Go to the documentation of this file.
1 // Copyright (C) 2015-2019 Edouard Griffiths, F4EXB. //
3 // //
4 // Swagger server adapter interface //
5 // //
6 // This program is free software; you can redistribute it and/or modify //
7 // it under the terms of the GNU General Public License as published by //
8 // the Free Software Foundation as version 3 of the License, or //
9 // (at your option) any later version. //
10 // //
11 // This program is distributed in the hope that it will be useful, //
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
14 // GNU General Public License V3 for more details. //
15 // //
16 // You should have received a copy of the GNU General Public License //
17 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
19 #ifndef INCLUDE_PRESET_H
20 #define INCLUDE_PRESET_H
21 
22 #include <QString>
23 #include <QList>
24 #include <QMetaType>
25 
26 #include "export.h"
27 
29 public:
30  struct ChannelConfig {
31  QString m_channelIdURI;
32  QString m_channelId;
33  QByteArray m_config;
34 
35  ChannelConfig(const QString& channelIdURI, const QByteArray& config) :
36  m_channelIdURI(channelIdURI),
37  m_config(config)
38  { }
39  };
40  typedef QList<ChannelConfig> ChannelConfigs;
41 
42  struct DeviceConfig
43  {
44  QString m_deviceId;
45  QString m_deviceSerial;
47  QByteArray m_config;
48 
49  DeviceConfig(const QString& deviceId,
50  const QString& deviceSerial,
51  int deviceSequence,
52  const QByteArray& config) :
53  m_deviceId(deviceId),
54  m_deviceSerial(deviceSerial),
55  m_deviceSequence(deviceSequence),
56  m_config(config)
57  { }
58  };
59  typedef QList<DeviceConfig> DeviceeConfigs;
60 
61  Preset();
62 
63  void resetToDefaults();
64 
65  void setSourcePreset(bool isSourcePreset) { m_sourcePreset = isSourcePreset; }
66  bool isSourcePreset() const { return m_sourcePreset; }
67 
68  QByteArray serialize() const;
69  bool deserialize(const QByteArray& data);
70 
71  void setGroup(const QString& group) { m_group = group; }
72  const QString& getGroup() const { return m_group; }
73  void setDescription(const QString& description) { m_description = description; }
74  const QString& getDescription() const { return m_description; }
75  void setCenterFrequency(const quint64 centerFrequency) { m_centerFrequency = centerFrequency; }
76  quint64 getCenterFrequency() const { return m_centerFrequency; }
77 
78  void setSpectrumConfig(const QByteArray& data) { m_spectrumConfig = data; }
79  const QByteArray& getSpectrumConfig() const { return m_spectrumConfig; }
80 
81  void setLayout(const QByteArray& data) { m_layout = data; }
82  const QByteArray& getLayout() const { return m_layout; }
83 
84  void clearChannels() { m_channelConfigs.clear(); }
85  void addChannel(const QString& channel, const QByteArray& config) { m_channelConfigs.append(ChannelConfig(channel, config)); }
86  int getChannelCount() const { return m_channelConfigs.count(); }
87  const ChannelConfig& getChannelConfig(int index) const { return m_channelConfigs.at(index); }
88 
89  void setDeviceConfig(const QString& deviceId, const QString& deviceSerial, int deviceSequence, const QByteArray& config)
90  {
91  addOrUpdateDeviceConfig(deviceId, deviceSerial, deviceSequence, config);
92  }
93 
94  void addOrUpdateDeviceConfig(const QString& deviceId,
95  const QString& deviceSerial,
96  int deviceSequence,
97  const QByteArray& config);
98 
99  const QByteArray* findBestDeviceConfig(const QString& deviceId,
100  const QString& deviceSerial,
101  int deviceSequence) const;
102 
103  static bool presetCompare(const Preset *p1, Preset *p2)
104  {
105  if (p1->m_group != p2->m_group)
106  {
107  return p1->m_group < p2->m_group;
108  }
109  else
110  {
111  if (p1->m_centerFrequency != p2->m_centerFrequency) {
112  return p1->m_centerFrequency < p2->m_centerFrequency;
113  } else {
114  return p1->m_description < p2->m_description;
115  }
116  }
117  }
118 
119  friend class WebAPIAdapterBase;
120 
121 protected:
123 
124  // group and preset description
125  QString m_group;
126  QString m_description;
128 
129  // general configuration
130  QByteArray m_spectrumConfig;
131 
132  // dc offset and i/q imbalance correction TODO: move it into the source data
135 
136  // channels and configurations
137  ChannelConfigs m_channelConfigs;
138 
139  // devices and configurations
140  DeviceeConfigs m_deviceConfigs;
141 
142  // screen and dock layout
143  QByteArray m_layout;
144 
145 private:
146  const QByteArray* findBestDeviceConfigSoapy(const QString& sourceId, const QString& deviceSerial) const;
147 };
148 
149 Q_DECLARE_METATYPE(const Preset*);
151 
152 #endif // INCLUDE_PRESET_H
void clearChannels()
Definition: preset.h:84
int getChannelCount() const
Definition: preset.h:86
void setCenterFrequency(const quint64 centerFrequency)
Definition: preset.h:75
Q_DECLARE_METATYPE(const Preset *)
DeviceConfig(const QString &deviceId, const QString &deviceSerial, int deviceSequence, const QByteArray &config)
Definition: preset.h:49
QList< ChannelConfig > ChannelConfigs
Definition: preset.h:40
void setLayout(const QByteArray &data)
Definition: preset.h:81
quint64 getCenterFrequency() const
Definition: preset.h:76
quint64 m_centerFrequency
Definition: preset.h:127
const ChannelConfig & getChannelConfig(int index) const
Definition: preset.h:87
void setDeviceConfig(const QString &deviceId, const QString &deviceSerial, int deviceSequence, const QByteArray &config)
Definition: preset.h:89
QString m_channelIdURI
Channel type ID in URI form.
Definition: preset.h:31
bool isSourcePreset() const
Definition: preset.h:66
QByteArray m_spectrumConfig
Definition: preset.h:130
bool m_sourcePreset
Definition: preset.h:122
DeviceeConfigs m_deviceConfigs
Definition: preset.h:140
QByteArray m_config
Definition: preset.h:47
const QByteArray & getLayout() const
Definition: preset.h:82
void addChannel(const QString &channel, const QByteArray &config)
Definition: preset.h:85
void setSpectrumConfig(const QByteArray &data)
Definition: preset.h:78
const QByteArray & getSpectrumConfig() const
Definition: preset.h:79
Definition: preset.h:28
void setDescription(const QString &description)
Definition: preset.h:73
void setGroup(const QString &group)
Definition: preset.h:71
void setSourcePreset(bool isSourcePreset)
Definition: preset.h:65
QString m_group
Definition: preset.h:125
QByteArray m_layout
Definition: preset.h:143
QString m_deviceId
Definition: preset.h:44
QString m_channelId
Channel type ID in short form from object name TODO: use in the future.
Definition: preset.h:32
QList< DeviceConfig > DeviceeConfigs
Definition: preset.h:59
QString m_description
Definition: preset.h:126
QString m_deviceSerial
Definition: preset.h:45
static bool presetCompare(const Preset *p1, Preset *p2)
Definition: preset.h:103
QByteArray m_config
Definition: preset.h:33
#define SDRBASE_API
Definition: export.h:40
const QString & getDescription() const
Definition: preset.h:74
bool m_dcOffsetCorrection
Definition: preset.h:133
const QString & getGroup() const
Definition: preset.h:72
bool m_iqImbalanceCorrection
Definition: preset.h:134
ChannelConfigs m_channelConfigs
Definition: preset.h:137
ChannelConfig(const QString &channelIdURI, const QByteArray &config)
Definition: preset.h:35