ngscopeclient 0.1-dev+51fbda87c
InstrumentChannel.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 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 std::string GetHwname()
91 { return m_hwname; }
92
94 size_t GetIndex()
95 { return m_index; }
96
99 { return m_instrument; }
100
107 { m_displayname = ""; }
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 { return m_streams[stream].m_yAxisUnit; }
142
149 virtual void SetXAxisUnits(const Unit& rhs)
150 { m_xAxisUnit = rhs; }
151
158 virtual void SetYAxisUnits(const Unit& rhs, size_t stream)
159 { m_streams[stream].m_yAxisUnit = rhs; }
160
163 {
164 if(stream < m_streams.size())
165 return m_streams[stream].m_stype;
166 else
167 return Stream::STREAM_TYPE_UNDEFINED;
168 }
169
172 { return m_streams.size(); }
173
175 std::string GetStreamName(size_t stream)
176 {
177 if(stream < m_streams.size())
178 return m_streams[stream].m_name;
179 else
180 return "";
181 }
182
184 WaveformBase* GetData(size_t stream)
185 {
186 if(stream >= m_streams.size())
187 return nullptr;
188 return m_streams[stream].m_waveform;
189 }
190
192 uint8_t GetStreamFlags(size_t stream)
193 {
194 if(stream >= m_streams.size())
195 return 0;
196 return m_streams[stream].m_flags;
197 }
198
200 float GetScalarValue(size_t stream)
201 {
202 if(stream >= m_streams.size())
203 return 0;
204 return m_streams[stream].m_value;
205 }
206
208 void SetScalarValue(size_t stream, float value)
209 {
210 if(stream >= m_streams.size())
211 return;
212 m_streams[stream].m_value = value;
213 }
214
220 WaveformBase* Detach(size_t stream)
221 {
222 WaveformBase* tmp = m_streams[stream].m_waveform;
223 m_streams[stream].m_waveform = NULL;
224 return tmp;
225 }
226
230 virtual bool ShouldPersistWaveform();
231
236 {
237 VIS_HIDE,
238 VIS_AUTO, //decide based on whether it's enabled etc
239 VIS_SHOW,
240 } m_visibilityMode;
241
246 {
247 DOWNLOAD_UNKNOWN,
252 };
253
261
263 virtual float GetDownloadProgress();
264
266 virtual double GetDownloadStartTime();
267
268protected:
269
270 virtual void ClearStreams();
271 virtual size_t AddStream(Unit yunit, const std::string& name, Stream::StreamType stype, uint8_t flags = 0);
272
275
282 std::string m_hwname;
283
290 std::string m_displayname;
291
295 size_t m_index;
296
301
305 std::vector<Stream> m_streams;
306};
307
308#endif
Declaration of Stream.
Abstract base class for a node in the signal flow graph.
Definition: FlowGraphNode.h:54
A single channel of an instrument.
Definition: InstrumentChannel.h:63
size_t GetIndex()
Gets the (zero based) index of the channel.
Definition: InstrumentChannel.h:94
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
VisibilityMode
Selects how the channel should be displayed in e.g. the ngscopeclient filter graph editor.
Definition: InstrumentChannel.h:236
std::string m_displayname
Display name (user defined, defaults to m_hwname).
Definition: InstrumentChannel.h:290
WaveformBase * Detach(size_t stream)
Detach the capture data from this channel.
Definition: InstrumentChannel.h:220
DownloadState
Enum values to be mapped to GetDownloadState() int result value for specific channel download states.
Definition: InstrumentChannel.h:246
@ DOWNLOAD_WAITING
This channel is waiting to be downloaded (i.e. scope is triggered but previous channels are currently...
Definition: InstrumentChannel.h:249
@ DOWNLOAD_IN_PROGRESS
Download has started.
Definition: InstrumentChannel.h:250
@ DOWNLOAD_NONE
No download is pending (e.g. the scope is in stop mode)
Definition: InstrumentChannel.h:248
@ DOWNLOAD_FINISHED
Download is finished.
Definition: InstrumentChannel.h:251
virtual DownloadState GetDownloadState()
Returns the current download state of this channel.
Definition: InstrumentChannel.cpp:158
virtual float GetDownloadProgress()
returns the current completion of the download (on the range [0, 1]), if not DOWNLOAD_UNKNOWN
Definition: InstrumentChannel.cpp:163
void SetData(WaveformBase *pNew, size_t stream)
Sets the waveform data for a given stream, replacing any previous waveform.
Definition: InstrumentChannel.cpp:139
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:149
WaveformBase * GetData(size_t stream)
Get the contents of a data stream.
Definition: InstrumentChannel.h:184
virtual Unit GetYAxisUnits(size_t stream)
Returns the Y axis unit for a specified stream.
Definition: InstrumentChannel.h:140
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:200
std::string m_hwname
Hardware name of the channel.
Definition: InstrumentChannel.h:282
Unit m_xAxisUnit
Unit of measurement for our horizontal axis (common to all streams)
Definition: InstrumentChannel.h:300
virtual double GetDownloadStartTime()
returns the start time of a download, if we are DOWNLOAD_IN_PROGRESS; undefined, otherwise
Definition: InstrumentChannel.cpp:168
std::string GetStreamName(size_t stream)
Gets the name of a stream (for display in the UI)
Definition: InstrumentChannel.h:175
void SetScalarValue(size_t stream, float value)
Sets the value of a scalar data stream.
Definition: InstrumentChannel.h:208
size_t m_index
Zero based index of the channel within the instrument.
Definition: InstrumentChannel.h:295
Instrument * m_instrument
The instrument we're part of (may be null in the case of filters etc)
Definition: InstrumentChannel.h:274
virtual Unit GetXAxisUnits()
Returns the X axis unit for this channel.
Definition: InstrumentChannel.h:134
std::vector< Stream > m_streams
Configuration data for each of our output streams.
Definition: InstrumentChannel.h:305
size_t GetStreamCount()
Get the number of data streams.
Definition: InstrumentChannel.h:171
Stream::StreamType GetType(size_t stream)
Returns the type of a specified stream.
Definition: InstrumentChannel.h:162
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()
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:192
virtual void SetXAxisUnits(const Unit &rhs)
Changes the X axis unit for this channel.
Definition: InstrumentChannel.h:149
virtual void SetYAxisUnits(const Unit &rhs, size_t stream)
Changes the X axis unit for a specified stream.
Definition: InstrumentChannel.h:158
std::string GetHwname()
Gets the hardware name of the channel (m_hwname)
Definition: InstrumentChannel.h:90
An arbitrary lab instrument. Oscilloscope, LA, PSU, DMM, etc.
Definition: Instrument.h:58
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
Base class for all Waveform specializations.
Definition: Waveform.h:59