ngscopeclient 0.1-dev+51fbda87c
OscilloscopeChannel.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 OscilloscopeChannel_h
37#define OscilloscopeChannel_h
38
39class Oscilloscope;
40
41#include "InstrumentChannel.h"
42
49{
50public:
51
52 //Some drivers have to be able to call AddStream() for now (this will be refactored out eventually)
53 friend class Oscilloscope;
54 friend class MockOscilloscope;
55
57 Oscilloscope* scope,
58 const std::string& hwname,
59 const std::string& color,
60 Unit xunit = Unit(Unit::UNIT_FS),
61 size_t index = 0);
62
64 Oscilloscope* scope,
65 const std::string& hwname,
66 const std::string& color,
67 Unit xunit = Unit(Unit::UNIT_FS),
68 Unit yunit = Unit(Unit::UNIT_VOLTS),
69 Stream::StreamType stype = Stream::STREAM_TYPE_ANALOG,
70 size_t index = 0);
71 virtual ~OscilloscopeChannel();
72
73 //implemented in Oscilloscope.h
74 Oscilloscope* GetScope();
75
76 size_t GetRefCount()
77 { return m_refcount; }
78
79 virtual void SetDisplayName(std::string name) override;
80 virtual std::string GetDisplayName() override;
81
82 //Hardware configuration
83public:
84 bool IsEnabled();
85
86 //Warning: these functions FORCE the channel to be on or off. May break other code that assumes it's on.
87 void Enable();
88 void Disable();
89
90 //These functions are preferred in GUI or other environments with multiple consumers of waveform data.
91 //The channel is reference counted and only turned off when all consumers have released it.
92 virtual void AddRef();
93 virtual void Release();
94
95 enum CouplingType
96 {
97 COUPLE_DC_1M, //1M ohm, DC coupled
98 COUPLE_AC_1M, //1M ohm, AC coupled
99 COUPLE_DC_50, //50 ohm, DC coupled
100 COUPLE_AC_50, //50 ohm, AC coupled
101 COUPLE_GND, //tie to ground
102 COUPLE_SYNTHETIC //channel is math, digital, or otherwise not a direct voltage measurement
103 };
104
105 virtual CouplingType GetCoupling();
106 virtual void SetCoupling(CouplingType type);
107
108 virtual std::vector<OscilloscopeChannel::CouplingType> GetAvailableCouplings();
109
110 virtual double GetAttenuation();
111 virtual void SetAttenuation(double atten);
112
113 virtual int GetBandwidthLimit();
114 virtual void SetBandwidthLimit(int mhz);
115
116 virtual void SetDeskew(int64_t skew);
117 virtual int64_t GetDeskew();
118
119 bool IsPhysicalChannel()
120 { return (m_instrument != nullptr); }
121
122 virtual float GetVoltageRange(size_t stream);
123 virtual void SetVoltageRange(float range, size_t stream);
124
125 virtual float GetOffset(size_t stream);
126 virtual void SetOffset(float offset, size_t stream);
127
128 void SetDigitalHysteresis(float level);
129 void SetDigitalThreshold(float level);
130
131 void SetCenterFrequency(int64_t freq);
132
133 bool CanAutoZero();
134 void AutoZero();
135 bool CanDegauss();
136 void Degauss();
137 std::string GetProbeName();
138
139 virtual bool CanInvert();
140 virtual void Invert(bool invert);
141 virtual bool IsInverted();
142
143 virtual bool HasInputMux();
144 virtual size_t GetInputMuxSetting();
145 virtual void SetInputMux(size_t select);
146
148
149 virtual DownloadState GetDownloadState() override;
150 virtual float GetDownloadProgress() override;
151 virtual double GetDownloadStartTime() override;
152
153private:
154 // to be accessed by Oscilloscope to update download status
155 DownloadState m_downloadState;
156 float m_downloadProgress;
157 double m_downloadStartTime;
158
159protected:
160 void SharedCtorInit(Unit unit);
161
164};
165
166#endif
Declaration of InstrumentChannel.
A single channel of an instrument.
Definition: InstrumentChannel.h:63
DownloadState
Enum values to be mapped to GetDownloadState() int result value for specific channel download states.
Definition: InstrumentChannel.h:246
Instrument * m_instrument
The instrument we're part of (may be null in the case of filters etc)
Definition: InstrumentChannel.h:274
Fake oscilloscope driver used for offline waveform analysis.
Definition: MockOscilloscope.h:45
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
A single channel on an oscilloscope.
Definition: OscilloscopeChannel.h:49
void SetDefaultDisplayName()
Gives a channel a default display name if there's not one already.
Definition: OscilloscopeChannel.cpp:79
virtual DownloadState GetDownloadState() override
Returns the current download state of this channel.
Definition: OscilloscopeChannel.cpp:351
virtual double GetDownloadStartTime() override
returns the start time of a download, if we are DOWNLOAD_IN_PROGRESS; undefined, otherwise
Definition: OscilloscopeChannel.cpp:361
size_t m_refcount
Number of references (channel is disabled when last ref is released)
Definition: OscilloscopeChannel.h:163
virtual void SetDisplayName(std::string name) override
Sets the human-readable nickname for this channel, as displayed in the GUI.
Definition: OscilloscopeChannel.cpp:246
virtual float GetDownloadProgress() override
returns the current completion of the download (on the range [0, 1]), if not DOWNLOAD_UNKNOWN
Definition: OscilloscopeChannel.cpp:356
virtual std::string GetDisplayName() override
Gets the human-readable nickname for this channel, as displayed in the GUI.
Definition: OscilloscopeChannel.cpp:253
Generic representation of an oscilloscope, logic analyzer, or spectrum analyzer.
Definition: Oscilloscope.h:50
virtual bool IsInverted(size_t i)
Checks if hardware polarity inversion is enabled for a channel.
Definition: Oscilloscope.cpp:854
virtual bool HasInputMux(size_t i)
Checks if a channel has an input multiplexer.
Definition: Oscilloscope.cpp:779
virtual void SetDigitalThreshold(size_t channel, float level)
Gets the threshold for a digital input.
Definition: Oscilloscope.cpp:747
virtual void SetDigitalHysteresis(size_t channel, float level)
Sets the hysteresis for a digital input.
Definition: Oscilloscope.cpp:743
virtual bool CanDegauss(size_t i)
Determines if a channel has a probe connected which supports the "degauss" feature.
Definition: Oscilloscope.cpp:760
virtual void SetInputMux(size_t i, size_t select)
Sets the input mux for a channel.
Definition: Oscilloscope.cpp:795
virtual bool CanAutoZero(size_t i)
Determines if a channel has a probe connected which supports the "auto zero" feature.
Definition: Oscilloscope.cpp:751
virtual size_t GetInputMuxSetting(size_t i)
Gets the setting for a channel's input mux (if it has one)
Definition: Oscilloscope.cpp:784
virtual std::string GetProbeName(size_t i)
Returns the name of the probe connected to the scope, if possible.
Definition: Oscilloscope.cpp:774
virtual void Invert(size_t i, bool invert)
Enables hardware polarity inversion for a channel, if supported.
Definition: Oscilloscope.cpp:850
virtual bool CanInvert(size_t i)
Checks if a channel is capable of hardware polarity inversion.
Definition: Oscilloscope.cpp:845
virtual void AutoZero(size_t i)
Performs an "auto zero" cycle on the attached active probe, if supported by the hardware.
Definition: Oscilloscope.cpp:756
virtual void SetCenterFrequency(size_t channel, int64_t freq)
Sets the center frequency for frequency-domain channels.
Definition: Oscilloscope.cpp:922
virtual void Degauss(size_t i)
Performs an "degauss" cycle on the attached active probe, if supported by the hardware.
Definition: Oscilloscope.cpp:770
StreamType
General data type stored in a stream.
Definition: Stream.h:58
A unit of measurement, plus conversion to pretty-printed output.
Definition: Unit.h:57