ngscopeclient 0.1-dev+51fbda87c
MockOscilloscope.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
37#ifndef MockOscilloscope_h
38#define MockOscilloscope_h
39
45{
46public:
48 const std::string& name,
49 const std::string& vendor,
50 const std::string& serial,
51 const std::string& transport,
52 const std::string& driver,
53 const std::string& args
54 );
55 virtual ~MockOscilloscope();
56
57 virtual bool IsOffline() override;
58
59 Unit::UnitType units[7] = {
60 Unit::UNIT_COUNTS, //Unused
61 Unit::UNIT_VOLTS,
62 Unit::UNIT_FS,
63 Unit::UNIT_COUNTS, //"Constant"
64 Unit::UNIT_AMPS,
65 Unit::UNIT_DB,
66 Unit::UNIT_HZ
67 };
68
69 //not copyable or assignable
70 MockOscilloscope(const MockOscilloscope& rhs) =delete;
71 MockOscilloscope& operator=(const MockOscilloscope& rhs) =delete;
72
73 void AddChannel(OscilloscopeChannel* chan)
74 { m_channels.push_back(chan); }
75
76 virtual std::string IDPing() override;
77
78 virtual std::string GetTransportConnectionString() override;
79 virtual std::string GetTransportName() override;
80
81 virtual std::string GetName() const override;
82 virtual std::string GetVendor() const override;
83 virtual std::string GetSerial() const override;
84
85 //Channel configuration
86 virtual bool IsChannelEnabled(size_t i) override;
87 virtual void EnableChannel(size_t i) override;
88 virtual void DisableChannel(size_t i) override;
89 virtual OscilloscopeChannel::CouplingType GetChannelCoupling(size_t i) override;
90 virtual void SetChannelCoupling(size_t i, OscilloscopeChannel::CouplingType type) override;
91 virtual std::vector<OscilloscopeChannel::CouplingType> GetAvailableCouplings(size_t i) override;
92 virtual double GetChannelAttenuation(size_t i) override;
93 virtual void SetChannelAttenuation(size_t i, double atten) override;
94 virtual unsigned int GetChannelBandwidthLimit(size_t i) override;
95 virtual void SetChannelBandwidthLimit(size_t i, unsigned int limit_mhz) override;
96 virtual float GetChannelVoltageRange(size_t i, size_t stream) override;
97 virtual void SetChannelVoltageRange(size_t i, size_t stream, float range) override;
98 virtual OscilloscopeChannel* GetExternalTrigger() override;
99 virtual float GetChannelOffset(size_t i, size_t stream) override;
100 virtual void SetChannelOffset(size_t i, size_t stream, float offset) override;
101
102 //Triggering
103 virtual Oscilloscope::TriggerMode PollTrigger() override;
104 virtual bool AcquireData() override;
105 virtual void Start() override;
106 virtual void StartSingleTrigger() override;
107 virtual void Stop() override;
108 virtual void ForceTrigger() override;
109 virtual bool IsTriggerArmed() override;
110 virtual void PushTrigger() override;
111 virtual void PullTrigger() override;
112
113 virtual std::vector<uint64_t> GetSampleRatesNonInterleaved() override;
114 virtual std::vector<uint64_t> GetSampleRatesInterleaved() override;
115 virtual std::set<InterleaveConflict> GetInterleaveConflicts() override;
116 virtual std::vector<uint64_t> GetSampleDepthsNonInterleaved() override;
117 virtual std::vector<uint64_t> GetSampleDepthsInterleaved() override;
118 virtual uint64_t GetSampleRate() override;
119 virtual uint64_t GetSampleDepth() override;
120 virtual void SetSampleDepth(uint64_t depth) override;
121 virtual void SetSampleRate(uint64_t rate) override;
122 virtual void SetTriggerOffset(int64_t offset) override;
123 virtual int64_t GetTriggerOffset() override;
124 virtual bool IsInterleaving() override;
125 virtual bool SetInterleaving(bool combine) override;
126
127 virtual unsigned int GetInstrumentTypes() const override;
128 virtual uint32_t GetInstrumentTypesForChannel(size_t i) const override;
129 void DoLoadConfiguration(int version, const YAML::Node& node, IDTable& idmap);
130 void DoSerializeConfiguration(YAML::Node& node, IDTable& table);
131
132protected:
133
134 void ArmTrigger();
135
136 //standard *IDN? fields
137 std::string m_name;
138 std::string m_vendor;
139 std::string m_serial;
140 std::string m_fwVersion;
141
142 OscilloscopeChannel* m_extTrigger;
143
144 std::map<size_t, bool> m_channelsEnabled;
145 std::map<size_t, OscilloscopeChannel::CouplingType> m_channelCoupling;
146 std::map<size_t, double> m_channelAttenuation;
147 std::map<size_t, unsigned int> m_channelBandwidth;
148 std::map<std::pair<size_t, size_t>, float> m_channelVoltageRange;
149 std::map<std::pair<size_t, size_t>, float> m_channelOffset;
150
151 void AutoscaleVertical();
152
153 //Simulated transport information
154 std::string m_transport;
155 std::string m_driver;
156 std::string m_args;
157
158 uint64_t m_sampleRate;
159 uint64_t m_sampleDepth;
160
161public:
162
163 virtual std::string GetDriverName()
164 { return m_driver; }
165};
166
167#endif
Bidirectional table mapping integer IDs in scopesession files to object pointers.
Definition: IDTable.h:49
std::vector< InstrumentChannel * > m_channels
Set of all channels on this instrument.
Definition: Instrument.h:259
Fake oscilloscope driver used for offline waveform analysis.
Definition: MockOscilloscope.h:45
virtual std::vector< uint64_t > GetSampleRatesInterleaved() override
Get the legal sampling rates (in Hz) for this scope in combined-channels mode.
Definition: MockOscilloscope.cpp:328
virtual void SetChannelVoltageRange(size_t i, size_t stream, float range) override
Sets the range of the current channel configuration.
Definition: MockOscilloscope.cpp:301
virtual std::vector< OscilloscopeChannel::CouplingType > GetAvailableCouplings(size_t i) override
Gets the set of legal coupling values for an input channel.
Definition: MockOscilloscope.cpp:255
virtual uint64_t GetSampleRate() override
Gets the current sampling rate (in Hz) of this scope.
Definition: MockOscilloscope.cpp:356
virtual void SetChannelAttenuation(size_t i, double atten) override
Sets the probe attenuation used for an input channel.
Definition: MockOscilloscope.cpp:281
virtual int64_t GetTriggerOffset() override
Gets the trigger offset.
Definition: MockOscilloscope.cpp:381
virtual std::vector< uint64_t > GetSampleRatesNonInterleaved() override
Get the legal sampling rates (in Hz) for this scope in all-channels mode.
Definition: MockOscilloscope.cpp:321
virtual float GetChannelOffset(size_t i, size_t stream) override
Gets the offset, in volts, for a given channel.
Definition: MockOscilloscope.cpp:311
virtual uint32_t GetInstrumentTypesForChannel(size_t i) const override
Returns a bitfield describing the set of instrument types that a given channel supports.
Definition: MockOscilloscope.cpp:100
virtual void DisableChannel(size_t i) override
Turn a channel off, given the index.
Definition: MockOscilloscope.cpp:250
virtual bool IsInterleaving() override
Checks if the scope is currently combining channels.
Definition: MockOscilloscope.cpp:387
virtual bool AcquireData() override
Pull data from the instrument.
Definition: MockOscilloscope.cpp:129
virtual void PushTrigger() override
Pushes changes made to m_trigger to the instrument.
Definition: MockOscilloscope.cpp:397
virtual OscilloscopeChannel::CouplingType GetChannelCoupling(size_t i) override
Gets the coupling used for an input channel.
Definition: MockOscilloscope.cpp:266
virtual Oscilloscope::TriggerMode PollTrigger() override
Checks the curent trigger status.
Definition: MockOscilloscope.cpp:123
virtual void PullTrigger() override
Updates m_trigger with any changes made from the instrument side.
Definition: MockOscilloscope.cpp:402
virtual void Stop() override
Stops triggering.
Definition: MockOscilloscope.cpp:150
virtual uint64_t GetSampleDepth() override
Gets the current sample depth of this scope.
Definition: MockOscilloscope.cpp:361
virtual bool SetInterleaving(bool combine) override
Configures the scope to combine channels.
Definition: MockOscilloscope.cpp:392
void AutoscaleVertical()
Calculate min/max of each channel and adjust gain/offset accordingly.
Definition: MockOscilloscope.cpp:410
virtual void SetChannelBandwidthLimit(size_t i, unsigned int limit_mhz) override
Sets the bandwidth limit for an input channel.
Definition: MockOscilloscope.cpp:291
virtual std::string IDPing() override
Returns the instrument's identification string.
Definition: MockOscilloscope.cpp:80
virtual void EnableChannel(size_t i) override
Turn a channel on, given the index.
Definition: MockOscilloscope.cpp:245
virtual unsigned int GetChannelBandwidthLimit(size_t i) override
Gets the bandwidth limit for an input channel.
Definition: MockOscilloscope.cpp:286
virtual std::string GetTransportConnectionString() override
Gets the connection string for our transport.
Definition: MockOscilloscope.cpp:90
virtual void SetTriggerOffset(int64_t offset) override
Sets the trigger offset.
Definition: MockOscilloscope.cpp:376
virtual bool IsOffline() override
Checks if the instrument is currently online.
Definition: MockOscilloscope.cpp:75
virtual bool IsTriggerArmed() override
Checks if the trigger is currently armed.
Definition: MockOscilloscope.cpp:160
virtual OscilloscopeChannel * GetExternalTrigger() override
Returns the external trigger input channel, if we have one.
Definition: MockOscilloscope.cpp:306
virtual bool IsChannelEnabled(size_t i) override
Checks if a channel is enabled in hardware.
Definition: MockOscilloscope.cpp:240
virtual float GetChannelVoltageRange(size_t i, size_t stream) override
Gets the range of the current channel configuration.
Definition: MockOscilloscope.cpp:296
virtual void SetChannelOffset(size_t i, size_t stream, float offset) override
Sets the offset for a given channel.
Definition: MockOscilloscope.cpp:316
virtual void ForceTrigger() override
Forces a single acquisition as soon as possible.
Definition: MockOscilloscope.cpp:155
virtual void StartSingleTrigger() override
Arms the trigger for a single acquistion.
Definition: MockOscilloscope.cpp:140
virtual std::vector< uint64_t > GetSampleDepthsNonInterleaved() override
Get the legal memory depths for this scope in all-channels mode.
Definition: MockOscilloscope.cpp:342
virtual std::vector< uint64_t > GetSampleDepthsInterleaved() override
Get the legal memory depths for this scope in combined-channels mode.
Definition: MockOscilloscope.cpp:349
virtual void SetChannelCoupling(size_t i, OscilloscopeChannel::CouplingType type) override
Sets the coupling used for an input channel.
Definition: MockOscilloscope.cpp:271
virtual unsigned int GetInstrumentTypes() const override
Returns a bitfield describing the set of instrument types that this instrument supports.
Definition: MockOscilloscope.cpp:95
virtual std::string GetTransportName() override
Gets the name of our transport.
Definition: MockOscilloscope.cpp:85
virtual void SetSampleRate(uint64_t rate) override
Sets the sample rate of the scope, in Hz.
Definition: MockOscilloscope.cpp:371
virtual void Start() override
Starts the instrument in continuous trigger mode.
Definition: MockOscilloscope.cpp:145
virtual void SetSampleDepth(uint64_t depth) override
Sets the sample depth of the scope.
Definition: MockOscilloscope.cpp:366
virtual double GetChannelAttenuation(size_t i) override
Gets the probe attenuation for an input channel.
Definition: MockOscilloscope.cpp:276
A single channel on an oscilloscope.
Definition: OscilloscopeChannel.h:49
Generic representation of an oscilloscope, logic analyzer, or spectrum analyzer.
Definition: Oscilloscope.h:50
TriggerMode
Definition: Oscilloscope.h:411