ngscopeclient v0.2.2
Loading...
Searching...
No Matches
OscilloscopeState.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* ngscopeclient *
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 OscilloscopeState_h
36#define OscilloscopeState_h
37
42{
43public:
44
45 OscilloscopeState(std::shared_ptr<Oscilloscope> scope)
46 {
47 size_t n = scope->GetChannelCount();
48 m_channelNumber = n;
49 m_channelInverted = std::make_unique<bool[] >(n);
50 m_channelOffset = std::make_unique<std::vector<float>[] >(n);
51 m_channelRange = std::make_unique<std::vector<float>[] >(n);
52
53 m_channelDigitalThreshold = std::make_unique<std::atomic<float>[] >(n);
54 m_channelAttenuation = std::make_unique<std::atomic<float>[] >(n);
55
56 m_needsUpdate = std::make_unique<std::atomic<bool>[] >(n);
57
58 m_probeName = std::make_unique<std::string[]>(n);
59
60 m_channelCoupling = std::make_unique<int[] >(n);
61 m_couplings = std::make_unique<std::vector<OscilloscopeChannel::CouplingType>[]>(n);
62 m_couplingNames = std::make_unique<std::vector<std::string>[]>(n);
63
64 m_channelBandwidthLimit = std::make_unique<int[] >(n);
65 m_bandwidthLimits = std::make_unique<std::vector<uint32_t>[]>(n);
66 m_bandwidthLimitNames = std::make_unique<std::vector<std::string>[]>(n);
67
68 m_committedOffset = std::make_unique<std::vector<float>[]>(n);
69 m_strOffset = std::make_unique<std::vector<std::string>[]>(n);
70
71 m_committedRange = std::make_unique<std::vector<float>[]>(n);
72 m_strRange = std::make_unique<std::vector<std::string>[]>(n);
73
74 m_committedDigitalThreshold = std::make_unique<float[]>(n);
75 m_strDigitalThreshold = std::make_unique<std::string[]>(n);
76
77 m_committedAttenuation = std::make_unique<float[]>(n);
78 m_strAttenuation = std::make_unique<std::string[]>(n);
79
80 m_adcMode = std::make_unique<int[]>(n);
81
82 Unit volts(Unit::UNIT_VOLTS);
83
84 for(size_t i=0; i<n; i++)
85 {
86 m_channelInverted[i] = false;
87
88 m_channelDigitalThreshold[i] = 0;
89 m_channelAttenuation[i] = 0;
90 m_channelBandwidthLimit[i] = 0;
91 m_channelCoupling[i] = 0;
92 m_channelBandwidthLimit[i] = 0;
93 m_adcMode[i] = 0;
94
95 // Offset and range ar per stream
96 OscilloscopeChannel* chan = dynamic_cast<OscilloscopeChannel*>(scope->GetChannel(i));
97 if(chan)
98 {
99 size_t nstreams = chan->GetStreamCount();
100 for(size_t j=0; j<nstreams; j++)
101 {
102 m_channelOffset[i].push_back(0);
103 m_channelRange[i].push_back(0);
104 m_committedOffset[i].push_back(FLT_MIN);
105 m_committedRange[i].push_back(FLT_MIN);
106 m_strOffset[i].push_back("");
107 m_strRange[i].push_back("");
108 }
109 }
110
111 m_needsUpdate[i] = true;
112
113 m_committedDigitalThreshold[i] = FLT_MIN;
114 m_committedAttenuation[i] = INT_MIN;
115 }
116 }
117
118 void FlushConfigCache()
119 {
120 for(size_t i = 0 ; i < m_channelNumber.load() ; i++)
121 m_needsUpdate[i] = true;
122 }
123
124 std::unique_ptr<bool[]> m_channelInverted;
125 std::unique_ptr<std::vector<float>[]> m_channelOffset;
126 std::unique_ptr<std::vector<float>[]> m_channelRange;
127 std::unique_ptr<std::atomic<float>[]> m_channelDigitalThreshold;
128 std::unique_ptr<std::atomic<float>[]> m_channelAttenuation;
129
130 std::unique_ptr<std::atomic<bool>[]> m_needsUpdate;
131
132 std::atomic<size_t> m_channelNumber;
133
134 //UI state for dialogs etc
135 std::unique_ptr<std::string[]> m_probeName;
136
137 std::unique_ptr<int[]> m_channelBandwidthLimit;
138 std::unique_ptr<std::vector<uint32_t>[]> m_bandwidthLimits;
139 std::unique_ptr<std::vector<std::string>[]> m_bandwidthLimitNames;
140
141 std::unique_ptr<int[]> m_channelCoupling;
142 std::unique_ptr<std::vector<OscilloscopeChannel::CouplingType>[]> m_couplings;
143 std::unique_ptr<std::vector<std::string>[]> m_couplingNames;
144
145 std::unique_ptr<std::vector<float>[]> m_committedOffset;
146 std::unique_ptr<std::vector<std::string>[]> m_strOffset;
147
148 std::unique_ptr<std::vector<float>[]> m_committedRange;
149 std::unique_ptr<std::vector<std::string>[]> m_strRange;
150
151 std::unique_ptr<float[]> m_committedDigitalThreshold;
152 std::unique_ptr<std::string[]> m_strDigitalThreshold;
153
154 std::unique_ptr<float[]> m_committedAttenuation;
155 std::unique_ptr<std::string[]> m_strAttenuation;
156
157 std::unique_ptr<int[]> m_adcMode;
158};
159
160#endif
Definition AcceleratorBuffer.h:204
A single channel on an oscilloscope.
Definition OscilloscopeChannel.h:49
Current status of an Oscilloscope.
Definition OscilloscopeState.h:42
A unit of measurement, plus conversion to pretty-printed output.
Definition Unit.h:59