ngscopeclient 0.1-dev+51fbda87c
Instrument.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* libscopehal *
4* *
5* Copyright (c) 2012-2024 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
36#ifndef Instrument_h
37#define Instrument_h
38
39#include "InstrumentChannel.h"
40#include "ConfigWarningList.h"
41
42
57 : public std::enable_shared_from_this<Instrument>
58{
59public:
60 virtual ~Instrument();
61
63 // Instrument identification
64
65 /*
66 @brief Types of instrument.
67
68 Note that we can't use RTTI for this because of software options that may or may not be present,
69 and we don't know at object instantiation time.
70
71 For example, some WaveSurfer 3000 devices have the function generator option and others don't.
72 While the WaveSurfer 3000 DMM option is now no-cost, there's no guarantee any given instrument's
73 owner has installed it!
74 */
75 enum InstrumentTypes
76 {
77 //An oscilloscope or logic analyzer
78 INST_OSCILLOSCOPE = 0x01,
79
80 //A multimeter (query to see what measurements it supports)
81 INST_DMM = 0x02,
82
83 //A power supply
84 INST_PSU = 0x04,
85
86 //A function generator
87 INST_FUNCTION = 0x08,
88
89 //An RF signal generator
90 INST_RF_GEN = 0x10,
91
92 //An electronic load
93 INST_LOAD = 0x20,
94
95 //A bit error rate tester
96 INST_BERT = 0x40,
97
98 //A miscellaneous instrument that doesn't fit any other category
99 INST_MISC = 0x80,
100
101 //A switch matrix
102 INST_SWITCH_MATRIX = 0x100
103 };
104
110 virtual unsigned int GetInstrumentTypes() const =0;
111
112 //Device information
113 virtual std::string GetName() const =0;
114 virtual std::string GetVendor() const =0;
115 virtual std::string GetSerial() const =0;
116
122 std::string m_nickname;
123
127 virtual std::string GetTransportConnectionString() =0;
128
132 virtual std::string GetTransportName() =0;
133
135 // Channel enumeration and identification
136
142 virtual uint32_t GetInstrumentTypesForChannel(size_t i) const =0;
143
147 size_t GetChannelCount() const
148 { return m_channels.size(); }
149
159 {
160 if(i >= m_channels.size())
161 return nullptr;
162
163 return m_channels[i];
164 }
165
180 virtual std::string GetChannelDisplayName(size_t i);
181
196 virtual void SetChannelDisplayName(size_t i, std::string name);
197
198 InstrumentChannel* GetChannelByDisplayName(const std::string& name);
199 InstrumentChannel* GetChannelByHwName(const std::string& name);
200
202 // Data capture
203
209 virtual bool AcquireData() =0;
210
212 // Serialization
213
214public:
215
221 virtual YAML::Node SerializeConfiguration(IDTable& table) const;
222
226 virtual void LoadConfiguration(int version, const YAML::Node& node, IDTable& idmap);
227
235 virtual void PreLoadConfiguration(int version, const YAML::Node& node, IDTable& idmap, ConfigWarningList& warnings);
236
237protected:
238
242 std::list< sigc::slot<void(YAML::Node&, IDTable&)> > m_serializers;
243
247 std::list< sigc::slot<void(int, const YAML::Node&, IDTable&)> > m_loaders;
248
252 std::list< sigc::slot<void(int, const YAML::Node&, IDTable&, ConfigWarningList&)> > m_preloaders;
253
254protected:
255
259 std::vector<InstrumentChannel*> m_channels;
260
261};
262
263#endif
Declaration of ConfigWarningList, ConfigWarningMessage, and WarningList.
Declaration of InstrumentChannel.
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:58
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:78
virtual unsigned int GetInstrumentTypes() const =0
Returns a bitfield describing the set of instrument types that this instrument supports.
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:173
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:242
InstrumentChannel * GetChannelByDisplayName(const std::string &name)
Gets a channel given the display name.
Definition: Instrument.cpp:51
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:64
InstrumentChannel * GetChannel(size_t i) const
Gets a given channel on the instrument.
Definition: Instrument.h:158
std::vector< InstrumentChannel * > m_channels
Set of all channels on this instrument.
Definition: Instrument.h:259
virtual YAML::Node SerializeConfiguration(IDTable &table) const
Serializes this instrument's configuration to a YAML node.
Definition: Instrument.cpp:86
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:122
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:252
virtual void LoadConfiguration(int version, const YAML::Node &node, IDTable &idmap)
Load instrument and channel configuration from a save file.
Definition: Instrument.cpp:167
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:74
size_t GetChannelCount() const
Gets the number of channels (of any type) this instrument has.
Definition: Instrument.h:147
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:247