ngscopeclient 0.1-dev+51fbda87c
DemoOscilloscope.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 DemoOscilloscope_h
38#define DemoOscilloscope_h
39
40#include "TestWaveformSource.h"
41#include <random>
42
53class DemoOscilloscope : public virtual SCPIOscilloscope
54{
55public:
57 virtual ~DemoOscilloscope();
58
59 //not copyable or assignable
60 DemoOscilloscope(const DemoOscilloscope& rhs) =delete;
61 DemoOscilloscope& operator=(const DemoOscilloscope& rhs) =delete;
62
63 virtual std::string IDPing() override;
64
65 virtual std::string GetTransportConnectionString() override;
66 virtual std::string GetTransportName() override;
67 virtual uint32_t GetInstrumentTypesForChannel(size_t i) const override;
68
69 //Channel configuration
70 virtual bool IsChannelEnabled(size_t i) override;
71 virtual void EnableChannel(size_t i) override;
72 virtual void DisableChannel(size_t i) override;
73 virtual OscilloscopeChannel::CouplingType GetChannelCoupling(size_t i) override;
74 virtual void SetChannelCoupling(size_t i, OscilloscopeChannel::CouplingType type) override;
75 virtual std::vector<OscilloscopeChannel::CouplingType> GetAvailableCouplings(size_t i) override;
76 virtual double GetChannelAttenuation(size_t i) override;
77 virtual void SetChannelAttenuation(size_t i, double atten) override;
78 virtual unsigned int GetChannelBandwidthLimit(size_t i) override;
79 virtual void SetChannelBandwidthLimit(size_t i, unsigned int limit_mhz) override;
80 virtual float GetChannelVoltageRange(size_t i, size_t stream) override;
81 virtual void SetChannelVoltageRange(size_t i, size_t stream, float range) override;
82 virtual OscilloscopeChannel* GetExternalTrigger() override;
83 virtual float GetChannelOffset(size_t i, size_t stream) override;
84 virtual void SetChannelOffset(size_t i, size_t stream, float offset) override;
85
86 //Triggering
87 virtual Oscilloscope::TriggerMode PollTrigger() override;
88 virtual bool AcquireData() override;
89 virtual void Start() override;
90 virtual void StartSingleTrigger() override;
91 virtual void Stop() override;
92 virtual void ForceTrigger() override;
93 virtual bool IsTriggerArmed() override;
94 virtual void PushTrigger() override;
95 virtual void PullTrigger() override;
96
97 virtual std::vector<uint64_t> GetSampleRatesNonInterleaved() override;
98 virtual std::vector<uint64_t> GetSampleRatesInterleaved() override;
99 virtual std::set<InterleaveConflict> GetInterleaveConflicts() override;
100 virtual std::vector<uint64_t> GetSampleDepthsNonInterleaved() override;
101 virtual std::vector<uint64_t> GetSampleDepthsInterleaved() override;
102 virtual uint64_t GetSampleRate() override;
103 virtual uint64_t GetSampleDepth() override;
104 virtual void SetSampleDepth(uint64_t depth) override;
105 virtual void SetSampleRate(uint64_t rate) override;
106 virtual void SetTriggerOffset(int64_t offset) override;
107 virtual int64_t GetTriggerOffset() override;
108 virtual bool IsInterleaving() override;
109 virtual bool SetInterleaving(bool combine) override;
110
111 virtual bool IsADCModeConfigurable() override;
112 virtual std::vector<std::string> GetADCModeNames(size_t channel) override;
113 virtual size_t GetADCMode(size_t channel) override;
114 virtual void SetADCMode(size_t channel, size_t mode) override;
115 virtual std::vector<AnalogBank> GetAnalogBanks() override;
116 virtual AnalogBank GetAnalogBank(size_t channel) override;
117
118 virtual unsigned int GetInstrumentTypes() const override;
119 virtual void LoadConfiguration(int version, const YAML::Node& node, IDTable& idmap) override;
120
121protected:
122
125
127 std::map<size_t, bool> m_channelsEnabled;
128
130 std::map<size_t, OscilloscopeChannel::CouplingType> m_channelCoupling;
131
133 std::map<size_t, double> m_channelAttenuation;
134
136 std::map<size_t, unsigned int> m_channelBandwidth;
137
139 std::map<size_t, float> m_channelVoltageRange;
140
142 std::map<size_t, float> m_channelOffset;
143
145 std::map<size_t, size_t> m_channelModes;
146
149 {
152
155
158 };
159
162
165
168
170 uint64_t m_depth;
171
173 uint64_t m_rate;
174
176 std::random_device m_rd;
177
179 std::minstd_rand* m_rng[4];
180
187
189 std::shared_ptr<QueueHandle> m_queue[4];
190
192 std::unique_ptr<vk::raii::CommandPool> m_pool[4];
193
195 std::unique_ptr<vk::raii::CommandBuffer> m_cmdBuf[4];
196
197public:
198 static std::string GetDriverNameInternal();
199
200 OSCILLOSCOPE_INITPROC(DemoOscilloscope)
201};
202
203#endif
204
Declaration of TestWaveformSource.
Simulated oscilloscope for demonstrations and testing.
Definition: DemoOscilloscope.h:54
virtual bool AcquireData() override
Pull data from the instrument.
Definition: DemoOscilloscope.cpp:497
uint64_t m_rate
Sample rate.
Definition: DemoOscilloscope.h:173
ChannelModes
ADC mode selectors (used to select the simulated channel)
Definition: DemoOscilloscope.h:149
@ CHANNEL_MODE_IDEAL
Ideal waveform with no impairments.
Definition: DemoOscilloscope.h:151
@ CHANNEL_MODE_NOISE
5 mV RMS AWGN
Definition: DemoOscilloscope.h:154
@ CHANNEL_MODE_NOISE_LPF
5 mV RMS AWGN + 300mm lossy S-parameter channel
Definition: DemoOscilloscope.h:157
std::map< size_t, unsigned int > m_channelBandwidth
Map of channel ID to bandwidth limit.
Definition: DemoOscilloscope.h:136
virtual void SetSampleRate(uint64_t rate) override
Sets the sample rate of the scope, in Hz.
Definition: DemoOscilloscope.cpp:414
virtual void LoadConfiguration(int version, const YAML::Node &node, IDTable &idmap) override
Load instrument and channel configuration from a save file.
Definition: DemoOscilloscope.cpp:227
static std::string GetDriverNameInternal()
Return the constant driver name "demopsu".
Definition: DemoOscilloscope.cpp:170
virtual std::vector< OscilloscopeChannel::CouplingType > GetAvailableCouplings(size_t i) override
Gets the set of legal coupling values for an input channel.
Definition: DemoOscilloscope.cpp:290
virtual void ForceTrigger() override
Forces a single acquisition as soon as possible.
Definition: DemoOscilloscope.cpp:214
TestWaveformSource * m_source[4]
Signal sources for each channel.
Definition: DemoOscilloscope.h:186
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:180
std::unique_ptr< vk::raii::CommandBuffer > m_cmdBuf[4]
Vulkan command buffer for ISI channel.
Definition: DemoOscilloscope.h:195
virtual void StartSingleTrigger() override
Arms the trigger for a single acquistion.
Definition: DemoOscilloscope.cpp:196
virtual void SetSampleDepth(uint64_t depth) override
Sets the sample depth of the scope.
Definition: DemoOscilloscope.cpp:409
std::map< size_t, size_t > m_channelModes
Map of channel ID to ADC mode.
Definition: DemoOscilloscope.h:145
std::map< size_t, double > m_channelAttenuation
Map of channel ID to probe attenuation.
Definition: DemoOscilloscope.h:133
virtual void SetADCMode(size_t channel, size_t mode) override
Sets the ADC mode for a channel.
Definition: DemoOscilloscope.cpp:468
virtual int64_t GetTriggerOffset() override
Gets the trigger offset.
Definition: DemoOscilloscope.cpp:424
virtual std::vector< AnalogBank > GetAnalogBanks() override
Gets the analog banks for this instrument.
Definition: DemoOscilloscope.cpp:479
virtual void EnableChannel(size_t i) override
Turn a channel on, given the index.
Definition: DemoOscilloscope.cpp:275
DemoOscilloscope(SCPITransport *transport)
Initialize the driver.
Definition: DemoOscilloscope.cpp:52
std::map< size_t, OscilloscopeChannel::CouplingType > m_channelCoupling
Map of channel ID to coupling.
Definition: DemoOscilloscope.h:130
virtual void SetChannelOffset(size_t i, size_t stream, float offset) override
Sets the offset for a given channel.
Definition: DemoOscilloscope.cpp:342
virtual OscilloscopeChannel::CouplingType GetChannelCoupling(size_t i) override
Gets the coupling used for an input channel.
Definition: DemoOscilloscope.cpp:285
virtual float GetChannelVoltageRange(size_t i, size_t stream) override
Gets the range of the current channel configuration.
Definition: DemoOscilloscope.cpp:322
virtual void SetChannelVoltageRange(size_t i, size_t stream, float range) override
Sets the range of the current channel configuration.
Definition: DemoOscilloscope.cpp:327
bool m_triggerOneShot
True if most recent trigger arm was a single-shot trigger.
Definition: DemoOscilloscope.h:164
virtual void SetTriggerOffset(int64_t offset) override
Sets the trigger offset.
Definition: DemoOscilloscope.cpp:419
std::unique_ptr< vk::raii::CommandPool > m_pool[4]
Vulkan command pool for ISI channel.
Definition: DemoOscilloscope.h:192
virtual void PullTrigger() override
Updates m_trigger with any changes made from the instrument side.
Definition: DemoOscilloscope.cpp:445
virtual std::vector< uint64_t > GetSampleRatesNonInterleaved() override
Get the legal sampling rates (in Hz) for this scope in all-channels mode.
Definition: DemoOscilloscope.cpp:347
OscilloscopeChannel * m_extTrigger
External trigger.
Definition: DemoOscilloscope.h:124
virtual bool IsTriggerArmed() override
Checks if the trigger is currently armed.
Definition: DemoOscilloscope.cpp:219
std::random_device m_rd
Random number source for seeding the generators.
Definition: DemoOscilloscope.h:176
virtual std::string IDPing() override
Returns the instrument's identification string.
Definition: DemoOscilloscope.cpp:154
virtual void PushTrigger() override
Pushes changes made to m_trigger to the instrument.
Definition: DemoOscilloscope.cpp:440
virtual std::vector< uint64_t > GetSampleRatesInterleaved() override
Get the legal sampling rates (in Hz) for this scope in combined-channels mode.
Definition: DemoOscilloscope.cpp:365
virtual void SetChannelAttenuation(size_t i, double atten) override
Sets the probe attenuation used for an input channel.
Definition: DemoOscilloscope.cpp:307
virtual uint64_t GetSampleDepth() override
Gets the current sample depth of this scope.
Definition: DemoOscilloscope.cpp:404
virtual float GetChannelOffset(size_t i, size_t stream) override
Gets the offset, in volts, for a given channel.
Definition: DemoOscilloscope.cpp:337
virtual OscilloscopeChannel * GetExternalTrigger() override
Returns the external trigger input channel, if we have one.
Definition: DemoOscilloscope.cpp:332
virtual void SetChannelCoupling(size_t i, OscilloscopeChannel::CouplingType type) override
Sets the coupling used for an input channel.
Definition: DemoOscilloscope.cpp:297
virtual bool IsChannelEnabled(size_t i) override
Checks if a channel is enabled in hardware.
Definition: DemoOscilloscope.cpp:270
virtual size_t GetADCMode(size_t channel) override
Gets the ADC mode for a channel.
Definition: DemoOscilloscope.cpp:462
virtual uint64_t GetSampleRate() override
Gets the current sampling rate (in Hz) of this scope.
Definition: DemoOscilloscope.cpp:399
virtual std::string GetTransportName() override
Gets the name of our transport.
Definition: DemoOscilloscope.cpp:159
virtual double GetChannelAttenuation(size_t i) override
Gets the probe attenuation for an input channel.
Definition: DemoOscilloscope.cpp:302
virtual bool IsInterleaving() override
Checks if the scope is currently combining channels.
Definition: DemoOscilloscope.cpp:430
std::shared_ptr< QueueHandle > m_queue[4]
Vulkan queue for ISI channel.
Definition: DemoOscilloscope.h:189
virtual AnalogBank GetAnalogBank(size_t channel) override
Gets the bank containing a given channel.
Definition: DemoOscilloscope.cpp:487
virtual bool IsADCModeConfigurable() override
Returns true if the ADC is configurable, false if it can only run in one mode.
Definition: DemoOscilloscope.cpp:474
virtual std::vector< uint64_t > GetSampleDepthsInterleaved() override
Get the legal memory depths for this scope in combined-channels mode.
Definition: DemoOscilloscope.cpp:392
virtual unsigned int GetChannelBandwidthLimit(size_t i) override
Gets the bandwidth limit for an input channel.
Definition: DemoOscilloscope.cpp:312
virtual void Start() override
Starts the instrument in continuous trigger mode.
Definition: DemoOscilloscope.cpp:202
virtual bool SetInterleaving(bool combine) override
Configures the scope to combine channels.
Definition: DemoOscilloscope.cpp:435
bool m_triggerArmed
True if trigger is armed.
Definition: DemoOscilloscope.h:161
virtual std::string GetTransportConnectionString() override
Gets the connection string for our transport.
Definition: DemoOscilloscope.cpp:164
virtual void SetChannelBandwidthLimit(size_t i, unsigned int limit_mhz) override
Sets the bandwidth limit for an input channel.
Definition: DemoOscilloscope.cpp:317
virtual void DisableChannel(size_t i) override
Turn a channel off, given the index.
Definition: DemoOscilloscope.cpp:280
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:453
virtual unsigned int GetInstrumentTypes() const override
Returns a bitfield describing the set of instrument types that this instrument supports.
Definition: DemoOscilloscope.cpp:175
std::minstd_rand * m_rng[4]
Random number generators for AWGN synthesis.
Definition: DemoOscilloscope.h:179
std::map< size_t, float > m_channelVoltageRange
Map of channel ID to vertical scale range.
Definition: DemoOscilloscope.h:139
uint64_t m_depth
Memory depth.
Definition: DemoOscilloscope.h:170
float m_sweepFreq
Current frequency within the sweep for channel 2.
Definition: DemoOscilloscope.h:167
std::map< size_t, float > m_channelOffset
Map of channel ID to offset.
Definition: DemoOscilloscope.h:142
std::map< size_t, bool > m_channelsEnabled
Map of channel ID to on/off state.
Definition: DemoOscilloscope.h:127
virtual void Stop() override
Stops triggering.
Definition: DemoOscilloscope.cpp:208
virtual std::vector< uint64_t > GetSampleDepthsNonInterleaved() override
Get the legal memory depths for this scope in all-channels mode.
Definition: DemoOscilloscope.cpp:379
virtual Oscilloscope::TriggerMode PollTrigger() override
Checks the curent trigger status.
Definition: DemoOscilloscope.cpp:188
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:411
An SCPI-based oscilloscope.
Definition: SCPIOscilloscope.h:38
Abstraction of a transport layer for moving SCPI data between endpoints.
Definition: SCPITransport.h:47
Helper class for generating test waveforms.
Definition: TestWaveformSource.h:51