ngscopeclient v0.2.1
Loading...
Searching...
No Matches
Instrument.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* libscopehal *
4* *
5* Copyright (c) 2012-2026 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
144 virtual bool IsOffline();
145
147 // Channel enumeration and identification
148
154 virtual uint32_t GetInstrumentTypesForChannel(size_t i) const =0;
155
159 size_t GetChannelCount() const
160 { return m_channels.size(); }
161
171 {
172 if(i >= m_channels.size())
173 return nullptr;
174
175 return m_channels[i];
176 }
177
192 virtual std::string GetChannelDisplayName(size_t i);
193
208 virtual void SetChannelDisplayName(size_t i, std::string name);
209
210 InstrumentChannel* GetChannelByDisplayName(const std::string& name);
211 InstrumentChannel* GetChannelByHwName(const std::string& name);
212
214 // Data capture
215
222 virtual void BackgroundProcessing();
223
229 virtual bool AcquireData() =0;
230
244 virtual void FlushConfigCache();
245
247 // Serialization
248
249public:
250
256 virtual YAML::Node SerializeConfiguration(IDTable& table) const;
257
261 virtual void LoadConfiguration(int version, const YAML::Node& node, IDTable& idmap);
262
270 virtual void PreLoadConfiguration(int version, const YAML::Node& node, IDTable& idmap, ConfigWarningList& warnings);
271
272protected:
273
277 std::list< sigc::slot<void(YAML::Node&, IDTable&)> > m_serializers;
278
282 std::list< sigc::slot<void(int, const YAML::Node&, IDTable&)> > m_loaders;
283
287 std::list< sigc::slot<void(int, const YAML::Node&, IDTable&, ConfigWarningList&)> > m_preloaders;
288
289protected:
290
294 std::vector<InstrumentChannel*> m_channels;
295
296};
297
298#endif
Declaration of ConfigWarningList, ConfigWarningMessage, and WarningList.
Declaration of InstrumentChannel.
Declaration of SerializableObject.
Definition AcceleratorBuffer.h:204
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:49
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:100
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:62
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:200
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:277
InstrumentChannel * GetChannelByDisplayName(const std::string &name)
Gets a channel given the display name.
Definition Instrument.cpp:73
virtual bool AcquireData()=0
Pull data from the instrument.
virtual std::string GetTransportConnectionString()=0
Gets the connection string for our transport.
virtual bool IsOffline()
Checks if the instrument is currently online.
Definition Instrument.cpp:105
virtual void BackgroundProcessing()
Run various background processing typically done by a second thread (e.g. InstrumentThread)
Definition Instrument.cpp:55
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:86
InstrumentChannel * GetChannel(size_t i) const
Gets a given channel on the instrument.
Definition Instrument.h:170
std::vector< InstrumentChannel * > m_channels
Set of all channels on this instrument.
Definition Instrument.h:294
virtual YAML::Node SerializeConfiguration(IDTable &table) const
Serializes this instrument's configuration to a YAML node.
Definition Instrument.cpp:113
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:287
virtual void LoadConfiguration(int version, const YAML::Node &node, IDTable &idmap)
Load instrument and channel configuration from a save file.
Definition Instrument.cpp:194
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:96
size_t GetChannelCount() const
Gets the number of channels (of any type) this instrument has.
Definition Instrument.h:159
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:282
Definition SerializableObject.h:40