ngscopeclient v0.3
Loading...
Searching...
No Matches
StreamDescriptor_inlines.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
35#ifndef StreamDescriptor_inlines_h
36#define StreamDescriptor_inlines_h
37
38inline Unit StreamDescriptor::GetXAxisUnits()
39{
40 if(m_channel == nullptr)
41 return Unit(Unit::UNIT_COUNTS);
42 else
43 return m_channel->GetXAxisUnits();
44}
45
46inline Unit StreamDescriptor::GetYAxisUnits()
47{
48 if(m_channel == nullptr)
49 return Unit(Unit::UNIT_VOLTS);
50 else
51 return m_channel->GetYAxisUnits(m_stream);
52}
53
54inline WaveformBase* StreamDescriptor::GetData() const
55{
56 if(m_channel == nullptr)
57 return nullptr;
58 else
59 return m_channel->GetData(m_stream);
60}
61
62inline bool StreamDescriptor::operator==(const StreamDescriptor& rhs) const
63{
64 return (m_channel == rhs.m_channel) && (m_stream == rhs.m_stream);
65}
66
67inline bool StreamDescriptor::operator!=(const StreamDescriptor& rhs) const
68{
69 return (m_channel != rhs.m_channel) || (m_stream != rhs.m_stream);
70}
71
72inline bool StreamDescriptor::operator<(const StreamDescriptor& rhs) const
73{
74 if(m_channel < rhs.m_channel)
75 return true;
76 if( (m_channel == rhs.m_channel) && (m_stream < rhs.m_stream) )
77 return true;
78
79 return false;
80}
81
82inline uint8_t StreamDescriptor::GetFlags() const
83{
84 if(m_channel == nullptr)
85 return 0;
86 else
87 return m_channel->GetStreamFlags(m_stream);
88}
89
90inline float StreamDescriptor::GetVoltageRange()
91{
92 auto schan = dynamic_cast<OscilloscopeChannel*>(m_channel);
93 if(schan == nullptr)
94 return 1;
95 else
96 return schan->GetVoltageRange(m_stream);
97}
98
99inline float StreamDescriptor::GetOffset()
100{
101 auto schan = dynamic_cast<OscilloscopeChannel*>(m_channel);
102 if(schan == nullptr)
103 return 0;
104 else
105 return schan->GetOffset(m_stream);
106}
107
108inline bool StreamDescriptor::IsHighRateOffsetCapable()
109{
110 auto schan = dynamic_cast<OscilloscopeChannel*>(m_channel);
111 if(schan == nullptr)
112 return true;
113 else
114 return schan->IsHighRateOffsetCapable();
115}
116
117inline void StreamDescriptor::SetVoltageRange(float v)
118{
119 auto schan = dynamic_cast<OscilloscopeChannel*>(m_channel);
120 if(schan)
121 schan->SetVoltageRange(v, m_stream);
122}
123
124inline bool StreamDescriptor::IsInverted()
125{
126 auto schan = dynamic_cast<OscilloscopeChannel*>(m_channel);
127 if(schan)
128 return schan->IsInverted(m_stream);
129 return false;
130}
131
132inline void StreamDescriptor::SetOffset(float v)
133{
134 auto schan = dynamic_cast<OscilloscopeChannel*>(m_channel);
135 if(schan)
136 schan->SetOffset(v, m_stream);
137}
138
139inline float StreamDescriptor::GetScalarValue()
140{
141 if(m_channel == nullptr)
142 return 0;
143 else
144 return m_channel->GetScalarValue(m_stream);
145}
146
147inline uint64_t StreamDescriptor::GetDigitalScalarValue()
148{
149 if(m_channel == nullptr)
150 return 0;
151 else
152 return m_channel->GetDigitalScalarValue(m_stream);
153}
154
155inline size_t StreamDescriptor::GetDigitalWidth()
156{
157 if(m_channel == nullptr)
158 return 0;
159 else
160 return m_channel->GetDigitalWidth(m_stream);
161}
162
163inline void StreamDescriptor::AddSink(FlowGraphNode* node)
164{
165 if(m_channel)
166 m_channel->AddSink(m_stream, node);
167}
168
169inline void StreamDescriptor::RemoveSink(FlowGraphNode* node)
170{
171 if(m_channel)
172 m_channel->RemoveSink(m_stream, node);
173}
174
175inline const std::set<FlowGraphNode*>& StreamDescriptor::GetSinks()
176{
177 return m_channel->GetSinks(m_stream);
178}
179
180inline std::string StreamDescriptor::PrettyPrintDigitalScalarHex()
181{
182 auto width = GetDigitalWidth();
183 uint64_t value = GetDigitalScalarValue();
184
185 //Calculate number of hex digits
186 int nibbles = ceil(width / 4.0);
187 if(nibbles < 1)
188 nibbles = 1;
189 if(nibbles > 16)
190 nibbles = 16;
191
192 char format[16];
193 snprintf(format, sizeof(format), "%d'h%%0%d%s", static_cast<int>(width), nibbles, PRIx64);
194
195 //Actually format the value
196 char tmp[32];
197 snprintf(tmp, sizeof(tmp), format, value);
198
199 return std::string(tmp);
200}
201
202
203inline std::string StreamDescriptor::PrettyPrintDigitalScalarBinary()
204{
205 auto width = GetDigitalWidth();
206 uint64_t value = GetDigitalScalarValue();
207
208 std::string ret = std::to_string(width) + "'b";
209 for(int i=width-1; i >= 0; i--)
210 {
211 uint64_t mask = static_cast<uint64_t>(1) << i;
212 if( (value & mask) == mask)
213 ret += "1";
214 else
215 ret += "0";
216 }
217
218 return ret;
219}
220
221inline std::string StreamDescriptor::PrettyPrintDigitalScalarDecimal()
222{
223 auto width = GetDigitalWidth();
224 uint64_t value = GetDigitalScalarValue();
225
226 //Calculate number of decimal digits
227 int digits = ceil(log10(pow(2, width)));
228 if(digits > 16)
229 digits = 16;
230
231 char format[32];
232 snprintf(format, sizeof(format), "%d'd%%0%d%s", static_cast<int>(width), digits, PRIu64);
233
234 //Actually format the value
235 char tmp[32];
236 snprintf(tmp, sizeof(tmp), format, value);
237
238 return std::string(tmp);
239}
240
241#endif
Definition AcceleratorBuffer.h:204
Abstract base class for a node in the signal flow graph.
Definition FlowGraphNode.h:81
uint64_t GetDigitalWidth(size_t stream)
Gets the width of a digital data stream.
Definition InstrumentChannel.h:229
uint64_t GetDigitalScalarValue(size_t stream)
Gets the value of a scalar data stream.
Definition InstrumentChannel.h:221
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
float GetScalarValue(size_t stream)
Gets the value of a scalar data stream.
Definition InstrumentChannel.h:205
virtual Unit GetXAxisUnits()
Returns the X axis unit for this channel.
Definition InstrumentChannel.h:134
uint8_t GetStreamFlags(size_t stream)
Get the flags of a data stream.
Definition InstrumentChannel.h:197
A single channel on an oscilloscope.
Definition OscilloscopeChannel.h:49
Descriptor for a single stream coming off a channel.
Definition StreamDescriptor.h:47
A unit of measurement, plus conversion to pretty-printed output.
Definition Unit.h:59
Base class for all Waveform specializations.
Definition Waveform.h:59