ngscopeclient v0.2.1
Loading...
Searching...
No Matches
InstrumentChannel.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
36#ifndef InstrumentChannel_h
37#define InstrumentChannel_h
38
39#include "Stream.h"
40
41class Instrument;
42
63{
64public:
66 Instrument* inst,
67 const std::string& hwname,
68 const std::string& color = "#808080",
69 Unit xunit = Unit(Unit::UNIT_FS),
70 size_t index = 0);
71
73 Instrument* inst,
74 const std::string& hwname,
75 const std::string& color = "#808080",
76 Unit xunit = Unit(Unit::UNIT_FS),
77 Unit yunit = Unit(Unit::UNIT_VOLTS),
78 Stream::StreamType stype = Stream::STREAM_TYPE_ANALOG,
79 size_t index = 0);
80
81 virtual ~InstrumentChannel();
82
84 std::string m_displaycolor;
85
86 virtual void SetDisplayName(std::string name);
87 virtual std::string GetDisplayName();
88
90 const std::string& GetHwname() const
91 { return m_hwname; }
92
94 size_t GetIndex() const
95 { return m_index; }
96
99 { return m_instrument; }
100
108
110 // Connector types
111
112 enum PhysicalConnector
113 {
114 CONNECTOR_BANANA_DUAL,
115 CONNECTOR_BMA,
116 CONNECTOR_BNC,
117 CONNECTOR_K,
118 CONNECTOR_K_DUAL,
119 CONNECTOR_N,
120 CONNECTOR_SMA
121 };
122
123 virtual PhysicalConnector GetPhysicalConnector();
124
126 // Stream management
127public:
128
129 void SetData(WaveformBase* pNew, size_t stream);
130
135 { return m_xAxisUnit; }
136
140 virtual Unit GetYAxisUnits(size_t stream)
141 {
142 if(stream < m_streams.size())
143 return m_streams[stream].m_yAxisUnit;
144 else
145 return Unit(Unit::UNIT_VOLTS);
146 }
147
154 virtual void SetXAxisUnits(const Unit& rhs)
155 { m_xAxisUnit = rhs; }
156
163 virtual void SetYAxisUnits(const Unit& rhs, size_t stream)
164 { m_streams[stream].m_yAxisUnit = rhs; }
165
168 {
169 if(stream < m_streams.size())
170 return m_streams[stream].m_stype;
171 else
172 return Stream::STREAM_TYPE_UNDEFINED;
173 }
174
177 { return m_streams.size(); }
178
180 std::string GetStreamName(size_t stream)
181 {
182 if(stream < m_streams.size())
183 return m_streams[stream].m_name;
184 else
185 return "";
186 }
187
190 {
191 if(stream >= m_streams.size())
192 return nullptr;
193 return m_streams[stream].m_waveform;
194 }
195
198 {
199 if(stream >= m_streams.size())
200 return 0;
201 return m_streams[stream].m_flags;
202 }
203
205 float GetScalarValue(size_t stream)
206 {
207 if(stream >= m_streams.size())
208 return 0;
209 return m_streams[stream].m_value;
210 }
211
213 void SetScalarValue(size_t stream, float value)
214 {
215 if(stream >= m_streams.size())
216 return;
217 m_streams[stream].m_value = value;
218 }
219
222 {
223 if(stream >= m_streams.size())
224 return 0;
225 return m_streams[stream].m_digitalValue;
226 }
227
230 {
231 if(stream >= m_streams.size())
232 return 0;
233 return m_streams[stream].m_digitalValueWidth;
234 }
235
237 void SetDigitalWidth(size_t stream, uint64_t width)
238 {
239 if(stream >= m_streams.size())
240 return;
241 m_streams[stream].m_digitalValueWidth = width;
242 }
243
246 {
247 if(stream >= m_streams.size())
248 return;
249 m_streams[stream].m_digitalValue = value;
250 }
251
258 {
259 WaveformBase* tmp = m_streams[stream].m_waveform;
260 m_streams[stream].m_waveform = NULL;
261 return tmp;
262 }
263
267 virtual bool ShouldPersistWaveform();
268
273 {
274 VIS_HIDE,
275 VIS_AUTO, //decide based on whether it's enabled etc
276 VIS_SHOW,
277 } m_visibilityMode;
278
290
298
300 virtual float GetDownloadProgress();
301
303 virtual double GetDownloadStartTime();
304
305 virtual void Refresh(vk::raii::CommandBuffer& cmdBuf, std::shared_ptr<QueueHandle> queue) override;
306
307protected:
308
309 virtual void ClearStreams();
310 virtual size_t AddStream(Unit yunit, const std::string& name, Stream::StreamType stype, uint8_t flags = 0);
311
314
321 std::string m_hwname;
322
329 std::string m_displayname;
330
334 size_t m_index;
335
340
344 std::vector<Stream> m_streams;
345};
346
347#endif
Declaration of Stream.
Definition AcceleratorBuffer.h:204
Abstract base class for a node in the signal flow graph.
Definition FlowGraphNode.h:81
A single channel of an instrument.
Definition InstrumentChannel.h:63
virtual std::string GetDisplayName()
Gets the human-readable nickname for this channel, as displayed in the GUI.
Definition InstrumentChannel.cpp:102
std::string m_displaycolor
Display color (HTML hex notation with optional alpha channel: #RRGGBB or ##RRGGBBAA)
Definition InstrumentChannel.h:84
uint64_t GetDigitalWidth(size_t stream)
Gets the width of a digital data stream.
Definition InstrumentChannel.h:229
VisibilityMode
Selects how the channel should be displayed in e.g. the ngscopeclient filter graph editor.
Definition InstrumentChannel.h:273
std::string m_displayname
Display name (user defined, defaults to m_hwname).
Definition InstrumentChannel.h:329
WaveformBase * Detach(size_t stream)
Detach the capture data from this channel.
Definition InstrumentChannel.h:257
DownloadState
Enum values to be mapped to GetDownloadState() int result value for specific channel download states.
Definition InstrumentChannel.h:283
@ DOWNLOAD_WAITING
This channel is waiting to be downloaded (i.e. scope is triggered but previous channels are currently...
Definition InstrumentChannel.h:286
@ DOWNLOAD_IN_PROGRESS
Download has started.
Definition InstrumentChannel.h:287
@ DOWNLOAD_NONE
No download is pending (e.g. the scope is in stop mode)
Definition InstrumentChannel.h:285
@ DOWNLOAD_FINISHED
Download is finished.
Definition InstrumentChannel.h:288
virtual DownloadState GetDownloadState()
Returns the current download state of this channel.
Definition InstrumentChannel.cpp:163
uint64_t GetDigitalScalarValue(size_t stream)
Gets the value of a scalar data stream.
Definition InstrumentChannel.h:221
virtual float GetDownloadProgress()
returns the current completion of the download (on the range [0, 1]), if not DOWNLOAD_UNKNOWN
Definition InstrumentChannel.cpp:168
void SetData(WaveformBase *pNew, size_t stream)
Sets the waveform data for a given stream, replacing any previous waveform.
Definition InstrumentChannel.cpp:144
void ClearCachedDisplayName()
Sets the display name to an empty string, causing a fetch from hardware.
Definition InstrumentChannel.h:106
virtual bool ShouldPersistWaveform()
Determine whether the channel's waveform(s) should be persisted to a session file.
Definition InstrumentChannel.cpp:154
WaveformBase * GetData(size_t stream)
Get the contents of a data stream.
Definition InstrumentChannel.h:189
virtual Unit GetYAxisUnits(size_t stream)
Returns the Y axis unit for a specified stream.
Definition InstrumentChannel.h:140
void SetDigitalWidth(size_t stream, uint64_t width)
Set the width of a digital data stream.
Definition InstrumentChannel.h:237
virtual void SetDisplayName(std::string name)
Sets the human-readable nickname for this channel, as displayed in the GUI.
Definition InstrumentChannel.cpp:94
float GetScalarValue(size_t stream)
Gets the value of a scalar data stream.
Definition InstrumentChannel.h:205
std::string m_hwname
Hardware name of the channel.
Definition InstrumentChannel.h:321
Unit m_xAxisUnit
Unit of measurement for our horizontal axis (common to all streams)
Definition InstrumentChannel.h:339
virtual double GetDownloadStartTime()
returns the start time of a download, if we are DOWNLOAD_IN_PROGRESS; undefined, otherwise
Definition InstrumentChannel.cpp:173
std::string GetStreamName(size_t stream)
Gets the name of a stream (for display in the UI)
Definition InstrumentChannel.h:180
void SetScalarValue(size_t stream, float value)
Sets the value of a scalar data stream.
Definition InstrumentChannel.h:213
size_t m_index
Zero based index of the channel within the instrument.
Definition InstrumentChannel.h:334
Instrument * m_instrument
The instrument we're part of (may be null in the case of filters etc)
Definition InstrumentChannel.h:313
virtual Unit GetXAxisUnits()
Returns the X axis unit for this channel.
Definition InstrumentChannel.h:134
size_t GetIndex() const
Gets the (zero based) index of the channel.
Definition InstrumentChannel.h:94
std::vector< Stream > m_streams
Configuration data for each of our output streams.
Definition InstrumentChannel.h:344
const std::string & GetHwname() const
Gets the hardware name of the channel (m_hwname)
Definition InstrumentChannel.h:90
size_t GetStreamCount()
Get the number of data streams.
Definition InstrumentChannel.h:176
Stream::StreamType GetType(size_t stream)
Returns the type of a specified stream.
Definition InstrumentChannel.h:167
void SetDigitalScalarValue(size_t stream, uint64_t value)
Sets the value of a scalar data stream.
Definition InstrumentChannel.h:245
virtual size_t AddStream(Unit yunit, const std::string &name, Stream::StreamType stype, uint8_t flags=0)
Adds a new data stream to the channel.
Definition InstrumentChannel.cpp:125
virtual void ClearStreams()
Clears out any existing streams.
Definition InstrumentChannel.cpp:113
Instrument * GetInstrument() const
Gets the instrument this channel is part of (if any)
Definition InstrumentChannel.h:98
uint8_t GetStreamFlags(size_t stream)
Get the flags of a data stream.
Definition InstrumentChannel.h:197
virtual void SetXAxisUnits(const Unit &rhs)
Changes the X axis unit for this channel.
Definition InstrumentChannel.h:154
virtual void SetYAxisUnits(const Unit &rhs, size_t stream)
Changes the X axis unit for a specified stream.
Definition InstrumentChannel.h:163
An arbitrary lab instrument. Oscilloscope, LA, PSU, DMM, etc.
Definition Instrument.h:62
StreamType
General data type stored in a stream.
Definition Stream.h:57
A unit of measurement, plus conversion to pretty-printed output.
Definition Unit.h:59
Base class for all Waveform specializations.
Definition Waveform.h:59