ngscopeclient v0.2.1
Loading...
Searching...
No Matches
MockOscilloscope.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 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 Unit::UnitType units[7] = {
58 Unit::UNIT_COUNTS, //Unused
59 Unit::UNIT_VOLTS,
60 Unit::UNIT_FS,
61 Unit::UNIT_COUNTS, //"Constant"
62 Unit::UNIT_AMPS,
63 Unit::UNIT_DB,
64 Unit::UNIT_HZ
65 };
66
67 //not copyable or assignable
69 MockOscilloscope& operator=(const MockOscilloscope& rhs) =delete;
70
71 void AddChannel(OscilloscopeChannel* chan)
72 { m_channels.push_back(chan); }
73
74 virtual std::string IDPing() override;
75
76 //Channel configuration
77 virtual bool IsChannelEnabled(size_t i) override;
78 virtual void EnableChannel(size_t i) override;
79 virtual void DisableChannel(size_t i) override;
80 virtual OscilloscopeChannel::CouplingType GetChannelCoupling(size_t i) override;
81 virtual void SetChannelCoupling(size_t i, OscilloscopeChannel::CouplingType type) override;
82 virtual std::vector<OscilloscopeChannel::CouplingType> GetAvailableCouplings(size_t i) override;
83 virtual double GetChannelAttenuation(size_t i) override;
84 virtual void SetChannelAttenuation(size_t i, double atten) override;
85 virtual unsigned int GetChannelBandwidthLimit(size_t i) override;
86 virtual void SetChannelBandwidthLimit(size_t i, unsigned int limit_mhz) override;
87 virtual float GetChannelVoltageRange(size_t i, size_t stream) override;
88 virtual void SetChannelVoltageRange(size_t i, size_t stream, float range) override;
89 virtual OscilloscopeChannel* GetExternalTrigger() override;
90 virtual float GetChannelOffset(size_t i, size_t stream) override;
91 virtual void SetChannelOffset(size_t i, size_t stream, float offset) override;
92
93 //Triggering
94 virtual Oscilloscope::TriggerMode PollTrigger() override;
95 virtual bool AcquireData() override;
96 virtual void Start() override;
97 virtual void StartSingleTrigger() override;
98 virtual void Stop() override;
99 virtual void ForceTrigger() override;
100 virtual bool IsTriggerArmed() override;
101 virtual void PushTrigger() override;
102 virtual void PullTrigger() override;
103
104 virtual std::vector<uint64_t> GetSampleRatesNonInterleaved() override;
105 virtual std::vector<uint64_t> GetSampleRatesInterleaved() override;
106 virtual std::set<InterleaveConflict> GetInterleaveConflicts() override;
107 virtual std::vector<uint64_t> GetSampleDepthsNonInterleaved() override;
108 virtual std::vector<uint64_t> GetSampleDepthsInterleaved() override;
109 virtual uint64_t GetSampleRate() override;
110 virtual uint64_t GetSampleDepth() override;
111 virtual void SetSampleDepth(uint64_t depth) override;
112 virtual void SetSampleRate(uint64_t rate) override;
113 virtual void SetTriggerOffset(int64_t offset) override;
114 virtual int64_t GetTriggerOffset() override;
115 virtual bool IsInterleaving() override;
116 virtual bool SetInterleaving(bool combine) override;
117
118 virtual unsigned int GetInstrumentTypes() const override;
119 virtual uint32_t GetInstrumentTypesForChannel(size_t i) const override;
120
121 //This is intentionally not virtual since it's called by Instrument::m_preloaders
122 //cppcheck-suppress duplInheritedMember
123 void DoPreLoadConfiguration(int version, const YAML::Node& node, IDTable& idmap, ConfigWarningList& warnings);
124
125protected:
126
127 void ArmTrigger();
128
129 OscilloscopeChannel* m_extTrigger;
130
131 std::map<size_t, bool> m_channelsEnabled;
132 std::map<size_t, OscilloscopeChannel::CouplingType> m_channelCoupling;
133 std::map<size_t, double> m_channelAttenuation;
134 std::map<size_t, unsigned int> m_channelBandwidth;
135 std::map<std::pair<size_t, size_t>, float> m_channelVoltageRange;
136 std::map<std::pair<size_t, size_t>, float> m_channelOffset;
137
138 void AutoscaleVertical();
139
140 uint64_t m_sampleRate;
141 uint64_t m_sampleDepth;
142};
143
144#endif
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
std::vector< InstrumentChannel * > m_channels
Set of all channels on this instrument.
Definition Instrument.h:294
Base class for simulated instruments.
Definition MockInstrument.h:44
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:295
virtual void SetChannelVoltageRange(size_t i, size_t stream, float range) override
Sets the range of the current channel configuration.
Definition MockOscilloscope.cpp:268
virtual std::vector< OscilloscopeChannel::CouplingType > GetAvailableCouplings(size_t i) override
Gets the set of legal coupling values for an input channel.
Definition MockOscilloscope.cpp:222
virtual uint64_t GetSampleRate() override
Gets the current sampling rate (in Hz) of this scope.
Definition MockOscilloscope.cpp:323
virtual void SetChannelAttenuation(size_t i, double atten) override
Sets the probe attenuation used for an input channel.
Definition MockOscilloscope.cpp:248
virtual int64_t GetTriggerOffset() override
Gets the trigger offset.
Definition MockOscilloscope.cpp:348
virtual std::vector< uint64_t > GetSampleRatesNonInterleaved() override
Get the legal sampling rates (in Hz) for this scope in all-channels mode.
Definition MockOscilloscope.cpp:288
virtual float GetChannelOffset(size_t i, size_t stream) override
Gets the offset, in volts, for a given channel.
Definition MockOscilloscope.cpp:278
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:81
virtual void DisableChannel(size_t i) override
Turn a channel off, given the index.
Definition MockOscilloscope.cpp:217
virtual bool IsInterleaving() override
Checks if the scope is currently combining channels.
Definition MockOscilloscope.cpp:354
virtual bool AcquireData() override
Pull data from the instrument.
Definition MockOscilloscope.cpp:95
virtual void PushTrigger() override
Pushes changes made to m_trigger to the instrument.
Definition MockOscilloscope.cpp:364
virtual OscilloscopeChannel::CouplingType GetChannelCoupling(size_t i) override
Gets the coupling used for an input channel.
Definition MockOscilloscope.cpp:233
virtual Oscilloscope::TriggerMode PollTrigger() override
Checks the curent trigger status.
Definition MockOscilloscope.cpp:89
virtual void PullTrigger() override
Updates m_trigger with any changes made from the instrument side.
Definition MockOscilloscope.cpp:369
virtual void Stop() override
Stops triggering.
Definition MockOscilloscope.cpp:116
virtual uint64_t GetSampleDepth() override
Gets the current sample depth of this scope.
Definition MockOscilloscope.cpp:328
virtual bool SetInterleaving(bool combine) override
Configures the scope to combine channels.
Definition MockOscilloscope.cpp:359
void AutoscaleVertical()
Calculate min/max of each channel and adjust gain/offset accordingly.
Definition MockOscilloscope.cpp:377
virtual void SetChannelBandwidthLimit(size_t i, unsigned int limit_mhz) override
Sets the bandwidth limit for an input channel.
Definition MockOscilloscope.cpp:258
virtual std::string IDPing() override
Returns the instrument's identification string.
Definition MockOscilloscope.cpp:71
virtual void EnableChannel(size_t i) override
Turn a channel on, given the index.
Definition MockOscilloscope.cpp:212
virtual unsigned int GetChannelBandwidthLimit(size_t i) override
Gets the bandwidth limit for an input channel.
Definition MockOscilloscope.cpp:253
virtual void SetTriggerOffset(int64_t offset) override
Sets the trigger offset.
Definition MockOscilloscope.cpp:343
virtual bool IsTriggerArmed() override
Checks if the trigger is currently armed.
Definition MockOscilloscope.cpp:126
virtual OscilloscopeChannel * GetExternalTrigger() override
Returns the external trigger input channel, if we have one.
Definition MockOscilloscope.cpp:273
virtual bool IsChannelEnabled(size_t i) override
Checks if a channel is enabled in hardware.
Definition MockOscilloscope.cpp:207
virtual float GetChannelVoltageRange(size_t i, size_t stream) override
Gets the range of the current channel configuration.
Definition MockOscilloscope.cpp:263
virtual void SetChannelOffset(size_t i, size_t stream, float offset) override
Sets the offset for a given channel.
Definition MockOscilloscope.cpp:283
virtual void ForceTrigger() override
Forces a single acquisition as soon as possible.
Definition MockOscilloscope.cpp:121
virtual void StartSingleTrigger() override
Arms the trigger for a single acquistion.
Definition MockOscilloscope.cpp:106
virtual std::vector< uint64_t > GetSampleDepthsNonInterleaved() override
Get the legal memory depths for this scope in all-channels mode.
Definition MockOscilloscope.cpp:309
virtual std::vector< uint64_t > GetSampleDepthsInterleaved() override
Get the legal memory depths for this scope in combined-channels mode.
Definition MockOscilloscope.cpp:316
virtual void SetChannelCoupling(size_t i, OscilloscopeChannel::CouplingType type) override
Sets the coupling used for an input channel.
Definition MockOscilloscope.cpp:238
virtual unsigned int GetInstrumentTypes() const override
Returns a bitfield describing the set of instrument types that this instrument supports.
Definition MockOscilloscope.cpp:76
virtual void SetSampleRate(uint64_t rate) override
Sets the sample rate of the scope, in Hz.
Definition MockOscilloscope.cpp:338
virtual void Start() override
Starts the instrument in continuous trigger mode.
Definition MockOscilloscope.cpp:111
virtual void SetSampleDepth(uint64_t depth) override
Sets the sample depth of the scope.
Definition MockOscilloscope.cpp:333
virtual double GetChannelAttenuation(size_t i) override
Gets the probe attenuation for an input channel.
Definition MockOscilloscope.cpp:243
A single channel on an oscilloscope.
Definition OscilloscopeChannel.h:49
Generic representation of an oscilloscope, logic analyzer, or spectrum analyzer.
Definition Oscilloscope.h:51
TriggerMode
Definition Oscilloscope.h:398