ngscopeclient v0.1-rc1
Instrument.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* libscopehal *
4* *
5* Copyright (c) 2012-2025 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
37#ifndef Instrument_h
38#define Instrument_h
39
40#include "InstrumentChannel.h"
41#include "ConfigWarningList.h"
42#include "SerializableObject.h"
43
60 : public std::enable_shared_from_this<Instrument>
61 , public SerializableObject
62{
63public:
64 virtual ~Instrument();
65
67 // Instrument identification
68
69 /*
70 @brief Types of instrument.
71
72 Note that we can't use RTTI for this because of software options that may or may not be present,
73 and we don't know at object instantiation time.
74
75 For example, some WaveSurfer 3000 devices have the function generator option and others don't.
76 While the WaveSurfer 3000 DMM option is now no-cost, there's no guarantee any given instrument's
77 owner has installed it!
78 */
79 enum InstrumentTypes
80 {
81 //An oscilloscope or logic analyzer
82 INST_OSCILLOSCOPE = 0x01,
83
84 //A multimeter (query to see what measurements it supports)
85 INST_DMM = 0x02,
86
87 //A power supply
88 INST_PSU = 0x04,
89
90 //A function generator
91 INST_FUNCTION = 0x08,
92
93 //An RF signal generator
94 INST_RF_GEN = 0x10,
95
96 //An electronic load
97 INST_LOAD = 0x20,
98
99 //A bit error rate tester
100 INST_BERT = 0x40,
101
102 //A miscellaneous instrument that doesn't fit any other category
103 INST_MISC = 0x80,
104
105 //A switch matrix
106 INST_SWITCH_MATRIX = 0x100
107 };
108
114 virtual unsigned int GetInstrumentTypes() const =0;
115
116 //Device information
117 virtual std::string GetName() const =0;
118 virtual std::string GetVendor() const =0;
119 virtual std::string GetSerial() const =0;
120
126 std::string m_nickname;
127
131 virtual std::string GetTransportConnectionString() =0;
132
136 virtual std::string GetTransportName() =0;
137
139 // Channel enumeration and identification
140
146 virtual uint32_t GetInstrumentTypesForChannel(size_t i) const =0;
147
151 size_t GetChannelCount() const
152 { return m_channels.size(); }
153
163 {
164 if(i >= m_channels.size())
165 return nullptr;
166
167 return m_channels[i];
168 }
169
184 virtual std::string GetChannelDisplayName(size_t i);
185
200 virtual void SetChannelDisplayName(size_t i, std::string name);
201
202 InstrumentChannel* GetChannelByDisplayName(const std::string& name);
203 InstrumentChannel* GetChannelByHwName(const std::string& name);
204
206 // Data capture
207
213 virtual bool AcquireData() =0;
214
228 virtual void FlushConfigCache();
229
231 // Serialization
232
233public:
234
240 virtual YAML::Node SerializeConfiguration(IDTable& table) const;
241
245 virtual void LoadConfiguration(int version, const YAML::Node& node, IDTable& idmap);
246
254 virtual void PreLoadConfiguration(int version, const YAML::Node& node, IDTable& idmap, ConfigWarningList& warnings);
255
256protected:
257
261 std::list< sigc::slot<void(YAML::Node&, IDTable&)> > m_serializers;
262
266 std::list< sigc::slot<void(int, const YAML::Node&, IDTable&)> > m_loaders;
267
271 std::list< sigc::slot<void(int, const YAML::Node&, IDTable&, ConfigWarningList&)> > m_preloaders;
272
273protected:
274
278 std::vector<InstrumentChannel*> m_channels;
279
280};
281
282#endif
Declaration of ConfigWarningList, ConfigWarningMessage, and WarningList.
Declaration of InstrumentChannel.
Declaration of SerializableObject.
All warnings generated by a configuration we're in the process of loading.
Definition: ConfigWarningList.h:90
Bidirectional table mapping integer IDs in scopesession files to object pointers.
Definition: IDTable.h:51
A single channel of an instrument.
Definition: InstrumentChannel.h:63
An arbitrary lab instrument. Oscilloscope, LA, PSU, DMM, etc.
Definition: Instrument.h:62
virtual std::string GetChannelDisplayName(size_t i)
Gets the hardware display name for a channel. This is an arbitrary user-selected string.
Definition: Instrument.cpp:93
virtual unsigned int GetInstrumentTypes() const =0
Returns a bitfield describing the set of instrument types that this instrument supports.
virtual void FlushConfigCache()
Instruments are allowed to cache configuration settings to reduce round trip queries to the device.
Definition: Instrument.cpp:55
virtual void PreLoadConfiguration(int version, const YAML::Node &node, IDTable &idmap, ConfigWarningList &warnings)
Parse a limited subset of instrument configuration but do not apply it.
Definition: Instrument.cpp:188
std::list< sigc::slot< void(YAML::Node &, IDTable &)> > m_serializers
List of methods which need to be called to serialize this node's configuration.
Definition: Instrument.h:261
InstrumentChannel * GetChannelByDisplayName(const std::string &name)
Gets a channel given the display name.
Definition: Instrument.cpp:66
virtual bool AcquireData()=0
Pull data from the instrument.
virtual std::string GetTransportConnectionString()=0
Gets the connection string for our transport.
virtual std::string GetTransportName()=0
Gets the name of our transport.
InstrumentChannel * GetChannelByHwName(const std::string &name)
Gets a channel given the hardware name.
Definition: Instrument.cpp:79
InstrumentChannel * GetChannel(size_t i) const
Gets a given channel on the instrument.
Definition: Instrument.h:162
std::vector< InstrumentChannel * > m_channels
Set of all channels on this instrument.
Definition: Instrument.h:278
virtual YAML::Node SerializeConfiguration(IDTable &table) const
Serializes this instrument's configuration to a YAML node.
Definition: Instrument.cpp:101
virtual uint32_t GetInstrumentTypesForChannel(size_t i) const =0
Returns a bitfield describing the set of instrument types that a given channel supports.
std::string m_nickname
Optional user-selected nickname of the instrument.
Definition: Instrument.h:126
std::list< sigc::slot< void(int, const YAML::Node &, IDTable &, ConfigWarningList &)> > m_preloaders
List of methods which need to be called to pre-load this node's configuration.
Definition: Instrument.h:271
virtual void LoadConfiguration(int version, const YAML::Node &node, IDTable &idmap)
Load instrument and channel configuration from a save file.
Definition: Instrument.cpp:182
virtual void SetChannelDisplayName(size_t i, std::string name)
Sets the hardware display name for a channel. This is an arbitrary user-selected string.
Definition: Instrument.cpp:89
size_t GetChannelCount() const
Gets the number of channels (of any type) this instrument has.
Definition: Instrument.h:151
std::list< sigc::slot< void(int, const YAML::Node &, IDTable &)> > m_loaders
List of methods which need to be called to deserialize this node's configuration.
Definition: Instrument.h:266
Definition: SerializableObject.h:40