ngscopeclient v0.2.1
Loading...
Searching...
No Matches
DemoOscilloscope.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 DemoOscilloscope_h
38#define DemoOscilloscope_h
39
40#include "TestWaveformSource.h"
42#include <random>
43
54class DemoOscilloscope : public virtual SCPIOscilloscope
55{
56public:
58 virtual ~DemoOscilloscope();
59
60 //not copyable or assignable
62 DemoOscilloscope& operator=(const DemoOscilloscope& rhs) =delete;
63
64 virtual std::string IDPing() override;
65
66 virtual std::string GetTransportConnectionString() override;
67 virtual std::string GetTransportName() override;
68 virtual uint32_t GetInstrumentTypesForChannel(size_t i) const override;
69
70 //Channel configuration
71 virtual bool IsChannelEnabled(size_t i) override;
72 virtual void EnableChannel(size_t i) override;
73 virtual void DisableChannel(size_t i) override;
74 virtual OscilloscopeChannel::CouplingType GetChannelCoupling(size_t i) override;
75 virtual void SetChannelCoupling(size_t i, OscilloscopeChannel::CouplingType type) override;
76 virtual std::vector<OscilloscopeChannel::CouplingType> GetAvailableCouplings(size_t i) override;
77 virtual double GetChannelAttenuation(size_t i) override;
78 virtual void SetChannelAttenuation(size_t i, double atten) override;
79 virtual unsigned int GetChannelBandwidthLimit(size_t i) override;
80 virtual void SetChannelBandwidthLimit(size_t i, unsigned int limit_mhz) override;
81 virtual float GetChannelVoltageRange(size_t i, size_t stream) override;
82 virtual void SetChannelVoltageRange(size_t i, size_t stream, float range) override;
83 virtual OscilloscopeChannel* GetExternalTrigger() override;
84 virtual float GetChannelOffset(size_t i, size_t stream) override;
85 virtual void SetChannelOffset(size_t i, size_t stream, float offset) override;
86 virtual bool IsHighRateOffsetCapable(size_t i) override;
87
88 //Triggering
89 virtual Oscilloscope::TriggerMode PollTrigger() override;
90 virtual bool AcquireData() override;
91 virtual void Start() override;
92 virtual void StartSingleTrigger() override;
93 virtual void Stop() override;
94 virtual void ForceTrigger() override;
95 virtual bool IsTriggerArmed() override;
96 virtual void PushTrigger() override;
97 virtual void PullTrigger() override;
98
99 virtual std::vector<uint64_t> GetSampleRatesNonInterleaved() override;
100 virtual std::vector<uint64_t> GetSampleRatesInterleaved() override;
101 virtual std::set<InterleaveConflict> GetInterleaveConflicts() override;
102 virtual std::vector<uint64_t> GetSampleDepthsNonInterleaved() override;
103 virtual std::vector<uint64_t> GetSampleDepthsInterleaved() override;
104 virtual uint64_t GetSampleRate() override;
105 virtual uint64_t GetSampleDepth() override;
106 virtual void SetSampleDepth(uint64_t depth) override;
107 virtual void SetSampleRate(uint64_t rate) override;
108 virtual void SetTriggerOffset(int64_t offset) override;
109 virtual int64_t GetTriggerOffset() override;
110 virtual bool IsInterleaving() override;
111 virtual bool SetInterleaving(bool combine) override;
112 virtual bool CanInterleave() override;
113
114 virtual bool IsADCModeConfigurable() override;
115 virtual bool IsADCModePerChannel() override;
116 virtual std::vector<std::string> GetADCModeNames(size_t channel) override;
117 virtual size_t GetADCMode(size_t channel) override;
118 virtual void SetADCMode(size_t channel, size_t mode) override;
119 virtual std::vector<AnalogBank> GetAnalogBanks() override;
120 virtual AnalogBank GetAnalogBank(size_t channel) override;
121
122 virtual unsigned int GetInstrumentTypes() const override;
123 virtual void LoadConfiguration(int version, const YAML::Node& node, IDTable& idmap) override;
124
125 virtual std::vector<DigitalBank> GetDigitalBanks() override;
126
127
128protected:
129
132
134 std::map<size_t, bool> m_channelsEnabled;
135
137 std::map<size_t, OscilloscopeChannel::CouplingType> m_channelCoupling;
138
140 std::map<size_t, double> m_channelAttenuation;
141
143 std::map<size_t, unsigned int> m_channelBandwidth;
144
146 std::map<size_t, float> m_channelVoltageRange;
147
149 std::map<size_t, float> m_channelOffset;
150
152 std::map<size_t, size_t> m_channelModes;
153
155 std::vector<OscilloscopeChannel*> m_digitalChannels;
156
169
172
175
178
180 std::random_device m_rd;
181
183 std::minstd_rand* m_rng[4];
184
189
190 TestDigitalWaveformSource* m_digitalSource;
191
192public:
193 static std::string GetDriverNameInternal();
194
195 //This is intentionally not virtual since it's a static method used by enumeration
196 //cppcheck-suppress duplInheritedMember
197 static std::vector<SCPIInstrumentModel> GetDriverSupportedModels()
198 {
199 return
200 {
201 {"Demo Oscilloscope", {{ SCPITransportType::TRANSPORT_NULL, "" }}}
202 };
203 }
204 OSCILLOSCOPE_INITPROC(DemoOscilloscope)
205};
206
207#endif
208
Declaration of TestDigitalWaveformSource.
Declaration of TestWaveformSource.
Definition AcceleratorBuffer.h:204
Simulated oscilloscope for demonstrations and testing.
Definition DemoOscilloscope.h:55
virtual bool AcquireData() override
Pull data from the instrument.
Definition DemoOscilloscope.cpp:537
uint64_t m_rate
Sample rate.
Definition DemoOscilloscope.h:177
std::vector< OscilloscopeChannel * > m_digitalChannels
Digital channels.
Definition DemoOscilloscope.h:155
ChannelModes
ADC mode selectors (used to select the simulated channel)
Definition DemoOscilloscope.h:159
@ CHANNEL_MODE_IDEAL
Ideal waveform with no impairments.
Definition DemoOscilloscope.h:161
@ CHANNEL_MODE_NOISE
5 mV RMS AWGN
Definition DemoOscilloscope.h:164
@ CHANNEL_MODE_NOISE_LPF
5 mV RMS AWGN + 300mm lossy S-parameter channel
Definition DemoOscilloscope.h:167
std::map< size_t, unsigned int > m_channelBandwidth
Map of channel ID to bandwidth limit.
Definition DemoOscilloscope.h:143
virtual void SetSampleRate(uint64_t rate) override
Sets the sample rate of the scope, in Hz.
Definition DemoOscilloscope.cpp:444
virtual void LoadConfiguration(int version, const YAML::Node &node, IDTable &idmap) override
Load instrument and channel configuration from a save file.
Definition DemoOscilloscope.cpp:251
static std::string GetDriverNameInternal()
Return the constant driver name "demopsu".
Definition DemoOscilloscope.cpp:194
virtual std::vector< OscilloscopeChannel::CouplingType > GetAvailableCouplings(size_t i) override
Gets the set of legal coupling values for an input channel.
Definition DemoOscilloscope.cpp:314
virtual void ForceTrigger() override
Forces a single acquisition as soon as possible.
Definition DemoOscilloscope.cpp:238
TestWaveformSource * m_source[4]
Signal sources for each channel.
Definition DemoOscilloscope.h:188
virtual uint32_t GetInstrumentTypesForChannel(size_t i) const override
Returns a bitfield describing the set of instrument types that a given channel supports.
Definition DemoOscilloscope.cpp:204
virtual void StartSingleTrigger() override
Arms the trigger for a single acquistion.
Definition DemoOscilloscope.cpp:220
virtual void SetSampleDepth(uint64_t depth) override
Sets the sample depth of the scope.
Definition DemoOscilloscope.cpp:439
std::map< size_t, size_t > m_channelModes
Map of channel ID to ADC mode.
Definition DemoOscilloscope.h:152
std::map< size_t, double > m_channelAttenuation
Map of channel ID to probe attenuation.
Definition DemoOscilloscope.h:140
virtual void SetADCMode(size_t channel, size_t mode) override
Sets the ADC mode for a channel.
Definition DemoOscilloscope.cpp:503
virtual int64_t GetTriggerOffset() override
Gets the trigger offset.
Definition DemoOscilloscope.cpp:454
virtual std::vector< AnalogBank > GetAnalogBanks() override
Gets the analog banks for this instrument.
Definition DemoOscilloscope.cpp:519
virtual void EnableChannel(size_t i) override
Turn a channel on, given the index.
Definition DemoOscilloscope.cpp:299
std::map< size_t, OscilloscopeChannel::CouplingType > m_channelCoupling
Map of channel ID to coupling.
Definition DemoOscilloscope.h:137
virtual void SetChannelOffset(size_t i, size_t stream, float offset) override
Sets the offset for a given channel.
Definition DemoOscilloscope.cpp:371
virtual OscilloscopeChannel::CouplingType GetChannelCoupling(size_t i) override
Gets the coupling used for an input channel.
Definition DemoOscilloscope.cpp:309
virtual float GetChannelVoltageRange(size_t i, size_t stream) override
Gets the range of the current channel configuration.
Definition DemoOscilloscope.cpp:346
virtual void SetChannelVoltageRange(size_t i, size_t stream, float range) override
Sets the range of the current channel configuration.
Definition DemoOscilloscope.cpp:351
virtual void SetTriggerOffset(int64_t offset) override
Sets the trigger offset.
Definition DemoOscilloscope.cpp:449
virtual bool IsADCModePerChannel() override
Returns true if the ADC is a per-channel setting, false if global for the entire instrument.
Definition DemoOscilloscope.cpp:514
virtual void PullTrigger() override
Updates m_trigger with any changes made from the instrument side.
Definition DemoOscilloscope.cpp:480
virtual std::vector< uint64_t > GetSampleRatesNonInterleaved() override
Get the legal sampling rates (in Hz) for this scope in all-channels mode.
Definition DemoOscilloscope.cpp:376
virtual bool IsHighRateOffsetCapable(size_t i) override
Checks if the channel supports high rate offset changes, or if the GUI should rate-limit.
Definition DemoOscilloscope.cpp:356
OscilloscopeChannel * m_extTrigger
External trigger.
Definition DemoOscilloscope.h:131
virtual bool IsTriggerArmed() override
Checks if the trigger is currently armed.
Definition DemoOscilloscope.cpp:243
std::random_device m_rd
Random number source for seeding the generators.
Definition DemoOscilloscope.h:180
virtual std::string IDPing() override
Returns the instrument's identification string.
Definition DemoOscilloscope.cpp:178
virtual void PushTrigger() override
Pushes changes made to m_trigger to the instrument.
Definition DemoOscilloscope.cpp:475
virtual std::vector< uint64_t > GetSampleRatesInterleaved() override
Get the legal sampling rates (in Hz) for this scope in combined-channels mode.
Definition DemoOscilloscope.cpp:394
virtual void SetChannelAttenuation(size_t i, double atten) override
Sets the probe attenuation used for an input channel.
Definition DemoOscilloscope.cpp:331
virtual uint64_t GetSampleDepth() override
Gets the current sample depth of this scope.
Definition DemoOscilloscope.cpp:434
virtual float GetChannelOffset(size_t i, size_t stream) override
Gets the offset, in volts, for a given channel.
Definition DemoOscilloscope.cpp:366
virtual OscilloscopeChannel * GetExternalTrigger() override
Returns the external trigger input channel, if we have one.
Definition DemoOscilloscope.cpp:361
virtual void SetChannelCoupling(size_t i, OscilloscopeChannel::CouplingType type) override
Sets the coupling used for an input channel.
Definition DemoOscilloscope.cpp:321
virtual bool IsChannelEnabled(size_t i) override
Checks if a channel is enabled in hardware.
Definition DemoOscilloscope.cpp:294
virtual size_t GetADCMode(size_t channel) override
Gets the ADC mode for a channel.
Definition DemoOscilloscope.cpp:497
virtual uint64_t GetSampleRate() override
Gets the current sampling rate (in Hz) of this scope.
Definition DemoOscilloscope.cpp:429
virtual std::string GetTransportName() override
Gets the name of our transport.
Definition DemoOscilloscope.cpp:183
virtual double GetChannelAttenuation(size_t i) override
Gets the probe attenuation for an input channel.
Definition DemoOscilloscope.cpp:326
virtual bool IsInterleaving() override
Checks if the scope is currently combining channels.
Definition DemoOscilloscope.cpp:465
virtual AnalogBank GetAnalogBank(size_t channel) override
Gets the bank containing a given channel.
Definition DemoOscilloscope.cpp:527
virtual bool IsADCModeConfigurable() override
Returns true if the ADC is configurable, false if it can only run in one mode.
Definition DemoOscilloscope.cpp:509
virtual std::vector< DigitalBank > GetDigitalBanks() override
Gets the digital channel banks for this instrument.
Definition DemoOscilloscope.cpp:145
virtual std::vector< uint64_t > GetSampleDepthsInterleaved() override
Get the legal memory depths for this scope in combined-channels mode.
Definition DemoOscilloscope.cpp:422
virtual unsigned int GetChannelBandwidthLimit(size_t i) override
Gets the bandwidth limit for an input channel.
Definition DemoOscilloscope.cpp:336
virtual void Start() override
Starts the instrument in continuous trigger mode.
Definition DemoOscilloscope.cpp:226
virtual bool SetInterleaving(bool combine) override
Configures the scope to combine channels.
Definition DemoOscilloscope.cpp:470
virtual std::string GetTransportConnectionString() override
Gets the connection string for our transport.
Definition DemoOscilloscope.cpp:188
virtual void SetChannelBandwidthLimit(size_t i, unsigned int limit_mhz) override
Sets the bandwidth limit for an input channel.
Definition DemoOscilloscope.cpp:341
virtual bool CanInterleave() override
Returns true if we have no interleave conflicts, false if we have conflicts.
Definition DemoOscilloscope.cpp:460
virtual void DisableChannel(size_t i) override
Turn a channel off, given the index.
Definition DemoOscilloscope.cpp:304
virtual std::vector< std::string > GetADCModeNames(size_t channel) override
Gets the names of the ADC modes for the bank a given channel is located in.
Definition DemoOscilloscope.cpp:488
virtual unsigned int GetInstrumentTypes() const override
Returns a bitfield describing the set of instrument types that this instrument supports.
Definition DemoOscilloscope.cpp:199
std::minstd_rand * m_rng[4]
Random number generators for AWGN synthesis.
Definition DemoOscilloscope.h:183
std::map< size_t, float > m_channelVoltageRange
Map of channel ID to vertical scale range.
Definition DemoOscilloscope.h:146
uint64_t m_depth
Memory depth.
Definition DemoOscilloscope.h:174
float m_sweepFreq
Current frequency within the sweep for channel 2.
Definition DemoOscilloscope.h:171
std::map< size_t, float > m_channelOffset
Map of channel ID to offset.
Definition DemoOscilloscope.h:149
std::map< size_t, bool > m_channelsEnabled
Map of channel ID to on/off state.
Definition DemoOscilloscope.h:134
virtual void Stop() override
Stops triggering.
Definition DemoOscilloscope.cpp:232
virtual std::vector< uint64_t > GetSampleDepthsNonInterleaved() override
Get the legal memory depths for this scope in all-channels mode.
Definition DemoOscilloscope.cpp:408
virtual Oscilloscope::TriggerMode PollTrigger() override
Checks the curent trigger status.
Definition DemoOscilloscope.cpp:212
Bidirectional table mapping integer IDs in scopesession files to object pointers.
Definition IDTable.h:49
A single channel on an oscilloscope.
Definition OscilloscopeChannel.h:49
TriggerMode
Definition Oscilloscope.h:398
An SCPI-based oscilloscope.
Definition SCPIOscilloscope.h:38
Abstraction of a transport layer for moving SCPI data between endpoints.
Definition SCPITransport.h:53
Helper class for generating test digital waveforms.
Definition TestDigitalWaveformSource.h:48
Helper class for generating test waveforms.
Definition TestWaveformSource.h:85