Commit 997a01ec72e12d346296981268020be654fbb5b6

Authored by David Graeff
Committed by David Gräff
1 parent db4f8ba0

Clean up signess. Fix crashes in the software trigger code (glgenerator). Remove…

… headers where they are not used anymore (defines.h for instance)
Showing 43 changed files with 171 additions and 176 deletions
openhantek/CMakeLists.txt
... ... @@ -14,7 +14,7 @@ endif()
14 14  
15 15 # include directories
16 16 set(CMAKE_INCLUDE_CURRENT_DIR ON)
17   -include_directories(src/ src/hantekprotocol src/hantekdso src/widgets src/docks src/configdialog)
  17 +include_directories(src/ src/hantekdso src/widgets src/docks src/configdialog)
18 18  
19 19 # collect sources and other files
20 20 file(GLOB_RECURSE SRC "src/*.cpp")
... ...
openhantek/src/analyse/dataanalyzer.h
... ... @@ -9,7 +9,6 @@
9 9 #include <memory>
10 10  
11 11 #include "dataanalyzerresult.h"
12   -#include "definitions.h"
13 12 #include "dsosamples.h"
14 13 #include "utils/printutils.h"
15 14 #include "enums.h"
... ...
openhantek/src/analyse/dataanalyzerresult.cpp
... ... @@ -9,14 +9,14 @@ DataAnalyzerResult::DataAnalyzerResult(unsigned int channelCount) { analyzedData
9 9 /// \brief Returns the analyzed data.
10 10 /// \param channel Channel, whose data should be returned.
11 11 /// \return Analyzed data as AnalyzedData struct.
12   -const DataChannel *DataAnalyzerResult::data(int channel) const {
13   - if (channel >= (int)this->analyzedData.size()) return 0;
  12 +const DataChannel *DataAnalyzerResult::data(unsigned channel) const {
  13 + if (channel >= this->analyzedData.size()) return 0;
14 14  
15 15 return &this->analyzedData[(size_t)channel];
16 16 }
17 17  
18   -DataChannel *DataAnalyzerResult::modifyData(int channel) {
19   - if (channel >= (int)this->analyzedData.size())
  18 +DataChannel *DataAnalyzerResult::modifyData(unsigned channel) {
  19 + if (channel >= this->analyzedData.size())
20 20 throw new std::runtime_error("If you modfiy the DataAnalyzerResult, you "
21 21 "need to set the channels first!");
22 22  
... ...
openhantek/src/analyse/dataanalyzerresult.h
... ... @@ -25,8 +25,8 @@ struct DataChannel {
25 25 class DataAnalyzerResult {
26 26 public:
27 27 DataAnalyzerResult(unsigned int channelCount);
28   - const DataChannel *data(int channel) const;
29   - DataChannel *modifyData(int channel);
  28 + const DataChannel *data(unsigned channel) const;
  29 + DataChannel *modifyData(unsigned channel);
30 30 unsigned int sampleCount() const;
31 31 unsigned int channelCount() const;
32 32  
... ...
openhantek/src/configdialog/DsoConfigAnalysisPage.h
... ... @@ -2,7 +2,6 @@
2 2  
3 3 #include <QWidget>
4 4  
5   -#include "definitions.h"
6 5 #include "settings.h"
7 6  
8 7 #include <QCheckBox>
... ...
openhantek/src/configdialog/DsoConfigColorsPage.h
... ... @@ -2,7 +2,6 @@
2 2  
3 3 #include <QWidget>
4 4  
5   -#include "definitions.h"
6 5 #include "settings.h"
7 6  
8 7 #include <QCheckBox>
... ...
openhantek/src/configdialog/DsoConfigFilesPage.h
... ... @@ -2,7 +2,6 @@
2 2  
3 3 #include <QWidget>
4 4  
5   -#include "definitions.h"
6 5 #include "settings.h"
7 6  
8 7 #include <QCheckBox>
... ...
openhantek/src/configdialog/DsoConfigScopePage.h
... ... @@ -2,7 +2,6 @@
2 2  
3 3 #include <QWidget>
4 4  
5   -#include "definitions.h"
6 5 #include "settings.h"
7 6  
8 7 #include <QCheckBox>
... ...
openhantek/src/docks/HorizontalDock.h
... ... @@ -6,7 +6,6 @@
6 6 #include <QGridLayout>
7 7  
8 8 #include <vector>
9   -#include "definitions.h"
10 9 #include "settings.h"
11 10  
12 11 class QLabel;
... ...
openhantek/src/docks/SpectrumDock.h
... ... @@ -5,7 +5,6 @@
5 5 #include <QDockWidget>
6 6 #include <QGridLayout>
7 7  
8   -#include "definitions.h"
9 8 #include "settings.h"
10 9  
11 10 class QLabel;
... ...
openhantek/src/docks/TriggerDock.h
... ... @@ -5,7 +5,6 @@
5 5 #include <QDockWidget>
6 6 #include <QGridLayout>
7 7  
8   -#include "definitions.h"
9 8 #include "settings.h"
10 9  
11 10 class QLabel;
... ...
openhantek/src/docks/VoltageDock.h
... ... @@ -5,7 +5,6 @@
5 5 #include <QDockWidget>
6 6 #include <QGridLayout>
7 7  
8   -#include "definitions.h"
9 8 #include "settings.h"
10 9  
11 10 class QLabel;
... ...
openhantek/src/docks/dockwindows.cpp
... ... @@ -10,7 +10,6 @@
10 10  
11 11 #include "analyse/enums.h"
12 12 #include "hantekdso/enums.h"
13   -#include "definitions.h"
14 13 #include "dockwindows.h"
15 14  
16 15 void SetupDockWidget(QDockWidget *dockWindow, QWidget *dockWidget, QLayout *layout) {
... ...
openhantek/src/exporter.cpp
... ... @@ -18,7 +18,6 @@
18 18 #include "exporter.h"
19 19  
20 20 #include "analyse/dataanalyzerresult.h"
21   -#include "definitions.h"
22 21 #include "glgenerator.h"
23 22 #include "settings.h"
24 23 #include "utils/dsoStrings.h"
... ...
openhantek/src/glgenerator.cpp
... ... @@ -121,9 +121,9 @@ GlGenerator::PrePostStartTriggerSamples GlGenerator::computeSoftwareTriggerTY(co
121 121 result->data(channel)->voltage.sample.empty())
122 122 return PrePostStartTriggerSamples(preTrigSamples, postTrigSamples, swTriggerStart);
123 123  
124   - double value;
  124 + const std::vector<double>& samples = result->data(channel)->voltage.sample;
125 125 double level = settings->voltage[channel].trigger;
126   - unsigned int sampleCount = result->data(channel)->voltage.sample.size();
  126 + size_t sampleCount = samples.size();
127 127 double timeDisplay = settings->horizontal.timebase * 10;
128 128 double samplesDisplay = timeDisplay * settings->horizontal.samplerate;
129 129 if (samplesDisplay >= sampleCount) {
... ... @@ -137,29 +137,29 @@ GlGenerator::PrePostStartTriggerSamples GlGenerator::computeSoftwareTriggerTY(co
137 137 "picture. Decrease sample rate"));
138 138 return PrePostStartTriggerSamples(preTrigSamples, postTrigSamples, swTriggerStart);
139 139 }
140   - preTrigSamples = (settings->trigger.position * samplesDisplay);
141   - postTrigSamples = sampleCount - (samplesDisplay - preTrigSamples);
  140 + preTrigSamples = (unsigned)(settings->trigger.position * samplesDisplay);
  141 + postTrigSamples = (unsigned)sampleCount - ((unsigned)samplesDisplay - preTrigSamples);
142 142  
143 143 const int threshold = 7;
144 144 double prev;
145   - bool (*opcmp)(int,int,int);
146   - bool (*smplcmp)(int,int);
  145 + bool (*opcmp)(double,double,double);
  146 + bool (*smplcmp)(double,double);
147 147 if (settings->trigger.slope == Dso::SLOPE_POSITIVE) {
148 148 prev = INT_MAX;
149   - opcmp = [](int value, int level, int prev) { return value > level && prev <= level;};
150   - smplcmp = [](int sampleK, int value) { return sampleK >= value;};
  149 + opcmp = [](double value, double level, double prev) { return value > level && prev <= level;};
  150 + smplcmp = [](double sampleK, double value) { return sampleK >= value;};
151 151 } else {
152 152 prev = INT_MIN;
153   - opcmp = [](int value, int level, int prev) { return value > level && prev <= level;};
154   - smplcmp = [](int sampleK, int value) { return sampleK < value;};
  153 + opcmp = [](double value, double level, double prev) { return value < level && prev >= level;};
  154 + smplcmp = [](double sampleK, double value) { return sampleK < value;};
155 155 }
156 156  
157 157 for (unsigned int i = preTrigSamples; i < postTrigSamples; i++) {
158   - value = result->data(channel)->voltage.sample[i];
  158 + double value = samples[i];
159 159 if (opcmp(value, level, prev)) {
160 160 int rising = 0;
161 161 for (unsigned int k = i + 1; k < i + 11 && k < sampleCount; k++) {
162   - if (smplcmp(result->data(channel)->voltage.sample[k], value)) { rising++; }
  162 + if (smplcmp(samples[k], value)) { rising++; }
163 163 }
164 164 if (rising > threshold) {
165 165 swTriggerStart = i;
... ... @@ -170,13 +170,26 @@ GlGenerator::PrePostStartTriggerSamples GlGenerator::computeSoftwareTriggerTY(co
170 170 }
171 171 if (swTriggerStart == 0) {
172 172 timestampDebug(QString("Trigger not asserted. Data ignored"));
  173 + preTrigSamples = 0; // preTrigSamples may never be greater than swTriggerStart
173 174 }
174 175 return PrePostStartTriggerSamples(preTrigSamples, postTrigSamples, swTriggerStart);
175 176 }
176 177  
  178 +const SampleValues& GlGenerator::useSamplesOf(int mode, unsigned channel, const DataAnalyzerResult *result) const
  179 +{
  180 + static SampleValues emptyDefault;
  181 + if (mode == Dso::CHANNELMODE_VOLTAGE) {
  182 + if (!settings->voltage[channel].used || !result->data(channel)) return emptyDefault;
  183 + return result->data(channel)->voltage;
  184 + } else {
  185 + if (!settings->spectrum[channel].used || !result->data(channel)) return emptyDefault;
  186 + return result->data(channel)->spectrum;
  187 + }
  188 +}
  189 +
177 190 void GlGenerator::generateGraphs(const DataAnalyzerResult *result) {
178 191  
179   - int digitalPhosphorDepth = view->digitalPhosphor ? view->digitalPhosphorDepth : 1;
  192 + unsigned digitalPhosphorDepth = view->digitalPhosphor ? view->digitalPhosphorDepth : 1;
180 193  
181 194 // Handle all digital phosphor related list manipulations
182 195 for (int mode = Dso::CHANNELMODE_VOLTAGE; mode < Dso::CHANNELMODE_COUNT; ++mode) {
... ... @@ -197,105 +210,106 @@ void GlGenerator::generateGraphs(const DataAnalyzerResult *result) {
197 210  
198 211 ready = true;
199 212  
200   - unsigned preTrigSamples;
201   - unsigned postTrigSamples;
202   - unsigned swTriggerStart;
  213 + unsigned preTrigSamples=0;
  214 + unsigned postTrigSamples=0;
  215 + unsigned swTriggerStart=0;
203 216 switch (settings->horizontal.format) {
204 217 case Dso::GRAPHFORMAT_TY:
205 218 std::tie(preTrigSamples, postTrigSamples, swTriggerStart) = computeSoftwareTriggerTY(result);
206 219  
207 220 // Add graphs for channels
208 221 for (int mode = Dso::CHANNELMODE_VOLTAGE; mode < Dso::CHANNELMODE_COUNT; ++mode) {
209   - for (int channel = 0; channel < (int)settings->voltage.size(); ++channel) {
  222 + DrawLinesWithHistoryPerChannel& dPerChannel = vaChannel[mode];
  223 + for (unsigned channel = 0; channel < settings->voltage.size(); ++channel) {
  224 + DrawLinesWithHistory& withHistory = dPerChannel[channel];
  225 + const SampleValues& samples = useSamplesOf(mode, channel, result);
  226 +
210 227 // Check if this channel is used and available at the data analyzer
211   - if (((mode == Dso::CHANNELMODE_VOLTAGE) ? settings->voltage[channel].used
212   - : settings->spectrum[channel].used) &&
213   - result->data(channel) && !result->data(channel)->voltage.sample.empty()) {
214   - // Check if the sample count has changed
215   - size_t sampleCount = (mode == Dso::CHANNELMODE_VOLTAGE)
216   - ? result->data(channel)->voltage.sample.size()
217   - : result->data(channel)->spectrum.sample.size();
218   - if (mode == Dso::CHANNELMODE_VOLTAGE) sampleCount -= (swTriggerStart - preTrigSamples);
219   - size_t neededSize = sampleCount * 2;
  228 + if (samples.sample.empty()) {
  229 + // Delete all vector arrays
  230 + for (unsigned index = 0; index < digitalPhosphorDepth; ++index)
  231 + withHistory[index].clear();
  232 + continue;
  233 + }
  234 + // Check if the sample count has changed
  235 + size_t sampleCount = samples.sample.size();
  236 + if (sampleCount>9000) {
  237 + throw new std::runtime_error("");
  238 + }
  239 + if (mode == Dso::CHANNELMODE_VOLTAGE)
  240 + sampleCount -= (swTriggerStart - preTrigSamples);
  241 + size_t neededSize = sampleCount * 2;
220 242  
221 243 #if 0
222   - for(unsigned int index = 0; index < digitalPhosphorDepth; ++index) {
223   - if(vaChannel[mode][channel][index].size() != neededSize)
224   - vaChannel[mode][channel][index].clear(); // Something was changed, drop old traces
225   - }
  244 + for(unsigned int index = 0; index < digitalPhosphorDepth; ++index) {
  245 + if(vaChannel[mode][channel][index].size() != neededSize)
  246 + vaChannel[mode][channel][index].clear(); // Something was changed, drop old traces
  247 + }
226 248 #endif
227 249  
228   - // Set size directly to avoid reallocations
229   - vaChannel[mode][(size_t)channel].front().resize(neededSize);
230   -
231   - // Iterator to data for direct access
232   - std::vector<GLfloat>::iterator glIterator = vaChannel[mode][(size_t)channel].front().begin();
233   -
234   - // What's the horizontal distance between sampling points?
235   - double horizontalFactor;
236   - if (mode == Dso::CHANNELMODE_VOLTAGE)
237   - horizontalFactor = result->data(channel)->voltage.interval / settings->horizontal.timebase;
238   - else
239   - horizontalFactor =
240   - result->data(channel)->spectrum.interval / settings->horizontal.frequencybase;
241   -
242   - // Fill vector array
243   - if (mode == Dso::CHANNELMODE_VOLTAGE) {
244   - std::vector<double>::const_iterator dataIterator =
245   - result->data(channel)->voltage.sample.begin();
246   - const double gain = settings->voltage[channel].gain;
247   - const double offset = settings->voltage[channel].offset;
248   - const double invert = settings->voltage[channel].inverted ? -1.0 : 1.0;
249   -
250   - std::advance(dataIterator, swTriggerStart - preTrigSamples);
251   -
252   - for (unsigned int position = 0; position < sampleCount; ++position) {
253   - *(glIterator++) = position * horizontalFactor - DIVS_TIME / 2;
254   - *(glIterator++) = *(dataIterator++) / gain * invert + offset;
255   - }
256   - } else {
257   - std::vector<double>::const_iterator dataIterator =
258   - result->data(channel)->spectrum.sample.begin();
259   - const double magnitude = settings->spectrum[channel].magnitude;
260   - const double offset = settings->spectrum[channel].offset;
261   -
262   - for (unsigned int position = 0; position < sampleCount; ++position) {
263   - *(glIterator++) = position * horizontalFactor - DIVS_TIME / 2;
264   - *(glIterator++) = *(dataIterator++) / magnitude + offset;
265   - }
  250 + // Set size directly to avoid reallocations
  251 + withHistory.front().resize(neededSize);
  252 +
  253 + // Iterator to data for direct access
  254 + DrawLines::iterator glIterator = withHistory.front().begin();
  255 +
  256 + // What's the horizontal distance between sampling points?
  257 + float horizontalFactor;
  258 + if (mode == Dso::CHANNELMODE_VOLTAGE)
  259 + horizontalFactor = (float)(samples.interval / settings->horizontal.timebase);
  260 + else
  261 + horizontalFactor = (float)(samples.interval / settings->horizontal.frequencybase);
  262 +
  263 + // Fill vector array
  264 + if (mode == Dso::CHANNELMODE_VOLTAGE) {
  265 + std::vector<double>::const_iterator dataIterator = samples.sample.begin();
  266 + const float gain = (float) settings->voltage[channel].gain;
  267 + const float offset = (float) settings->voltage[channel].offset;
  268 + const float invert = settings->voltage[channel].inverted ? -1.0f : 1.0f;
  269 +
  270 + std::advance(dataIterator, swTriggerStart - preTrigSamples);
  271 +
  272 + for (unsigned int position = 0; position < sampleCount; ++position) {
  273 + *(glIterator++) = position * horizontalFactor - DIVS_TIME / 2;
  274 + *(glIterator++) = (float)*(dataIterator++) / gain * invert + offset;
266 275 }
267 276 } else {
268   - // Delete all vector arrays
269   - for (unsigned index = 0; index < (unsigned)digitalPhosphorDepth; ++index)
270   - vaChannel[mode][channel][index].clear();
  277 + std::vector<double>::const_iterator dataIterator = samples.sample.begin();
  278 + const float magnitude = (float)settings->spectrum[channel].magnitude;
  279 + const float offset = (float)settings->spectrum[channel].offset;
  280 +
  281 + for (unsigned int position = 0; position < sampleCount; ++position) {
  282 + *(glIterator++) = position * horizontalFactor - DIVS_TIME / 2;
  283 + *(glIterator++) = (float)*(dataIterator++) / magnitude + offset;
  284 + }
271 285 }
272 286 }
273 287 }
274 288 break;
275 289  
276 290 case Dso::GRAPHFORMAT_XY:
277   - for (int channel = 0; channel < settings->voltage.size(); ++channel) {
  291 + for (unsigned channel = 0; channel < settings->voltage.size(); ++channel) {
278 292 // For even channel numbers check if this channel is used and this and the
279 293 // following channel are available at the data analyzer
280 294 if (channel % 2 == 0 && channel + 1 < settings->voltage.size() && settings->voltage[channel].used &&
281 295 result->data(channel) && !result->data(channel)->voltage.sample.empty() && result->data(channel + 1) &&
282 296 !result->data(channel + 1)->voltage.sample.empty()) {
283 297 // Check if the sample count has changed
284   - const unsigned sampleCount = qMin(result->data(channel)->voltage.sample.size(),
  298 + const size_t sampleCount = std::min(result->data(channel)->voltage.sample.size(),
285 299 result->data(channel + 1)->voltage.sample.size());
286   - const unsigned neededSize = sampleCount * 2;
287   - for (unsigned index = 0; index < (unsigned)digitalPhosphorDepth; ++index) {
288   - if (vaChannel[Dso::CHANNELMODE_VOLTAGE][(size_t)channel][index].size() != neededSize)
289   - vaChannel[Dso::CHANNELMODE_VOLTAGE][(size_t)channel][index]
290   - .clear(); // Something was changed, drop old traces
  300 + const size_t neededSize = sampleCount * 2;
  301 + DrawLinesWithHistory& withHistory = vaChannel[Dso::CHANNELMODE_VOLTAGE][(size_t)channel];
  302 + for (unsigned index = 0; index < digitalPhosphorDepth; ++index) {
  303 + if (withHistory[index].size() != neededSize)
  304 + withHistory[index].clear(); // Something was changed, drop old traces
291 305 }
292 306  
293 307 // Set size directly to avoid reallocations
294   - vaChannel[Dso::CHANNELMODE_VOLTAGE][(size_t)channel].front().resize(neededSize);
  308 + DrawLines& drawLines = withHistory.front();
  309 + drawLines.resize(neededSize);
295 310  
296 311 // Iterator to data for direct access
297   - std::vector<GLfloat>::iterator glIterator =
298   - vaChannel[Dso::CHANNELMODE_VOLTAGE][channel].front().begin();
  312 + std::vector<GLfloat>::iterator glIterator = drawLines.begin();
299 313  
300 314 // Fill vector array
301 315 unsigned int xChannel = channel;
... ... @@ -310,8 +324,8 @@ void GlGenerator::generateGraphs(const DataAnalyzerResult *result) {
310 324 const double yInvert = settings->voltage[yChannel].inverted ? -1.0 : 1.0;
311 325  
312 326 for (unsigned int position = 0; position < sampleCount; ++position) {
313   - *(glIterator++) = *(xIterator++) / xGain * xInvert + xOffset;
314   - *(glIterator++) = *(yIterator++) / yGain * yInvert + yOffset;
  327 + *(glIterator++) = (GLfloat)( *(xIterator++) / xGain * xInvert + xOffset);
  328 + *(glIterator++) = (GLfloat)( *(yIterator++) / yGain * yInvert + yOffset);
315 329 }
316 330 } else {
317 331 // Delete all vector arrays
... ...
openhantek/src/glgenerator.h
... ... @@ -41,6 +41,8 @@ class GlGenerator : public QObject {
41 41 DsoSettingsView *view;
42 42 std::vector<GLfloat> vaGrid[3];
43 43 bool ready = false;
  44 +
  45 + const SampleValues &useSamplesOf(int mode, unsigned channel, const DataAnalyzerResult *result) const;
44 46 signals:
45 47 void graphsGenerated(); ///< The graphs are ready to be drawn
46 48 };
... ...
openhantek/src/glscope.h
... ... @@ -13,8 +13,6 @@ using GL_WIDGET_CLASS = QOpenGLWidget;
13 13 using GL_WIDGET_CLASS = QGLWidget;
14 14 #endif
15 15  
16   -#include "definitions.h"
17   -
18 16 class GlGenerator;
19 17 class DsoSettings;
20 18  
... ...
openhantek/src/hantekdso/controlsettings.cpp
1 1 #include "controlsettings.h"
2   -#include "definitions.h"
3 2  
4 3 namespace Hantek {
5 4  
6   -ControlSettings::ControlSettings(ControlSamplerateLimits* limits)
  5 +ControlSettings::ControlSettings(ControlSamplerateLimits* limits, size_t channelCount)
7 6 {
8 7 samplerate.limits = limits;
9   - trigger.level.resize(HANTEK_CHANNELS);
10   - voltage.resize(HANTEK_CHANNELS);
11   - for (unsigned channel = 0; channel < HANTEK_CHANNELS; ++channel) {
  8 + trigger.level.resize(channelCount);
  9 + voltage.resize(channelCount);
  10 + for (unsigned channel = 0; channel < channelCount; ++channel) {
12 11 trigger.level[channel] = 0.0;
13 12 voltage[channel].gain = 0;
14 13 voltage[channel].offset = 0.0;
... ...
openhantek/src/hantekdso/controlsettings.h
... ... @@ -52,12 +52,12 @@ struct ControlSettingsVoltage {
52 52 /// \struct ControlSettings hantek/control.h
53 53 /// \brief Stores the current settings of the device.
54 54 struct ControlSettings {
55   - ControlSettings(ControlSamplerateLimits *limits);
  55 + ControlSettings(ControlSamplerateLimits *limits, size_t channelCount);
56 56 ControlSettingsSamplerate samplerate; ///< The samplerate settings
57 57 std::vector<ControlSettingsVoltage> voltage; ///< The amplification settings
58 58 ControlSettingsTrigger trigger; ///< The trigger settings
59   - unsigned int recordLengthId = 1; ///< The id in the record length array
60   - unsigned short int usedChannels = 0; ///< Number of activated channels
  59 + unsigned recordLengthId = 1; ///< The id in the record length array
  60 + unsigned usedChannels = 0; ///< Number of activated channels
61 61 };
62 62  
63 63 }
... ...
openhantek/src/hantekdso/controlspecification.cpp deleted
1   -#include "controlspecification.h"
2   -
3   -namespace Hantek {
4   -
5   -ControlSpecification::ControlSpecification() noexcept {
6   -}
7   -
8   -}
openhantek/src/hantekdso/controlspecification.h
... ... @@ -2,10 +2,10 @@
2 2  
3 3 #pragma once
4 4  
5   -#include "controlvalue.h"
6   -#include "bulkcode.h"
7   -#include "controlcode.h"
8   -#include "definitions.h"
  5 +#include "hantekprotocol/controlvalue.h"
  6 +#include "hantekprotocol/bulkcode.h"
  7 +#include "hantekprotocol/controlcode.h"
  8 +#include "hantekprotocol/definitions.h"
9 9 #include <QList>
10 10  
11 11 namespace Hantek {
... ... @@ -71,7 +71,6 @@ struct ControlSpecificationSamplerate {
71 71 /// \struct ControlSpecification hantek/control.h
72 72 /// \brief Stores the specifications of the currently connected device.
73 73 struct ControlSpecification {
74   - ControlSpecification() noexcept;
75 74 // Interface
76 75 ControlSpecificationCommands command; ///< The commands for this device
77 76  
... ...
openhantek/src/hantekdso/hantekdsocontrol.cpp
... ... @@ -12,7 +12,8 @@
12 12 #include <QTimer>
13 13  
14 14 #include "hantekdsocontrol.h"
15   -
  15 +#include "hantekprotocol/bulkStructs.h"
  16 +#include "hantekprotocol/controlStructs.h"
16 17 #include "models/modelDSO6022.h"
17 18 #include "usb/usbdevice.h"
18 19 #include "utils/printutils.h"
... ... @@ -54,7 +55,7 @@ USBDevice *HantekDsoControl::getDevice() { return device; }
54 55 const DSOsamples &HantekDsoControl::getLastSamples() { return result; }
55 56  
56 57 HantekDsoControl::HantekDsoControl(USBDevice *device) : device(device),
57   - specification(device->getModel()->specification), controlsettings(&(specification.samplerate.single)) {
  58 + specification(device->getModel()->specification), controlsettings(&(specification.samplerate.single), HANTEK_CHANNELS) {
58 59 if (device == nullptr) throw new std::runtime_error("No usb device for HantekDsoControl");
59 60  
60 61 // Transmission-ready control commands
... ... @@ -123,7 +124,7 @@ bool HantekDsoControl::isFastRate() const {
123 124 return controlsettings.samplerate.limits == &specification.samplerate.multi;
124 125 }
125 126  
126   -int HantekDsoControl::getRecordLength() const {
  127 +unsigned HantekDsoControl::getRecordLength() const {
127 128 return controlsettings.samplerate.limits->recordLengths[controlsettings.recordLengthId];
128 129 }
129 130  
... ... @@ -238,7 +239,7 @@ void HantekDsoControl::convertRawDataToSamples(const std::vector&lt;unsigned char&gt;
238 239 // Resize sample vector
239 240 result.data[channel].resize(totalSampleCount);
240 241  
241   - const int gainID = (int)controlsettings.voltage[channel].gain;
  242 + const unsigned gainID = controlsettings.voltage[channel].gain;
242 243 const unsigned short limit = specification.voltageLimit[channel][gainID];
243 244 const double offset = controlsettings.voltage[channel].offsetReal;
244 245 const double gainStep = specification.gainSteps[gainID];
... ... @@ -271,7 +272,7 @@ void HantekDsoControl::convertRawDataToSamples(const std::vector&lt;unsigned char&gt;
271 272 for (unsigned channel = 0; channel < HANTEK_CHANNELS; ++channel) {
272 273 result.data[channel].resize(totalSampleCount / HANTEK_CHANNELS);
273 274  
274   - const int gainID = controlsettings.voltage[channel].gain;
  275 + const unsigned gainID = controlsettings.voltage[channel].gain;
275 276 const unsigned short limit = specification.voltageLimit[channel][gainID];
276 277 const double offset = controlsettings.voltage[channel].offsetReal;
277 278 const double gainStep = specification.gainSteps[gainID];
... ... @@ -335,8 +336,7 @@ double HantekDsoControl::getBestSamplerate(double samplerate, bool fastRate, boo
335 336 limits = &(specification.samplerate.single);
336 337  
337 338 // Get downsampling factor that would provide the requested rate
338   - double bestDownsampler =
339   - (double)limits->base / specification.bufferDividers[controlsettings.recordLengthId] / samplerate;
  339 + double bestDownsampler = limits->base / specification.bufferDividers[controlsettings.recordLengthId] / samplerate;
340 340 // Base samplerate sufficient, or is the maximum better?
341 341 if (bestDownsampler < 1.0 &&
342 342 (samplerate <= limits->max / specification.bufferDividers[controlsettings.recordLengthId] || !maximum)) {
... ... @@ -407,6 +407,7 @@ double HantekDsoControl::getBestSamplerate(double samplerate, bool fastRate, boo
407 407  
408 408 unsigned HantekDsoControl::getSampleCount() const {
409 409 if (isRollMode()) {
  410 + // TODO handle libusb error
410 411 return device->getPacketSize();
411 412 } else {
412 413 if (isFastRate())
... ... @@ -716,7 +717,7 @@ Dso::ErrorCode HantekDsoControl::setRecordTime(double duration) {
716 717 // Better add some margin for our SW trigger
717 718 unsigned sampleMargin = 2000;
718 719 unsigned sampleCount = 10240;
719   - int bestId = 0;
  720 + unsigned bestId = 0;
720 721 unsigned sampleId;
721 722 for (sampleId = 0; sampleId < specification.sampleSteps.size(); ++sampleId) {
722 723 if (specification.sampleSteps[sampleId] * duration < (sampleCount - sampleMargin)) bestId = sampleId;
... ... @@ -746,8 +747,8 @@ Dso::ErrorCode HantekDsoControl::setChannelUsed(unsigned channel, bool used) {
746 747 // Update settings
747 748 controlsettings.voltage[channel].used = used;
748 749 unsigned channelCount = 0;
749   - for (int channelCounter = 0; channelCounter < HANTEK_CHANNELS; ++channelCounter) {
750   - if (controlsettings.voltage[channelCounter].used) ++channelCount;
  750 + for (unsigned c = 0; c < HANTEK_CHANNELS; ++c) {
  751 + if (controlsettings.voltage[c].used) ++channelCount;
751 752 }
752 753  
753 754 // Calculate the UsedChannels field for the command
... ... @@ -974,9 +975,9 @@ Dso::ErrorCode HantekDsoControl::setTriggerLevel(unsigned channel, double level)
974 975 if (specification.sampleSize > 8) {
975 976 Offset& offsetLimit = specification.offsetLimit[channel].step[controlsettings.voltage[channel].gain];
976 977 // The range is the same as used for the offsets for 10 bit models
977   - minimum = ((unsigned short int)*((unsigned char *)&(offsetLimit.start)) << 8) +
  978 + minimum = ((unsigned short)*((unsigned char *)&(offsetLimit.start)) << 8) +
978 979 *((unsigned char *)&(offsetLimit.start) + 1);
979   - maximum = ((unsigned short int)*((unsigned char *)&(offsetLimit.end)) << 8) +
  980 + maximum = ((unsigned short)*((unsigned char *)&(offsetLimit.end)) << 8) +
980 981 *((unsigned char *)&(offsetLimit.end) + 1);
981 982 } else {
982 983 // It's from 0x00 to 0xfd for the 8 bit models
... ... @@ -1047,7 +1048,7 @@ Dso::ErrorCode HantekDsoControl::setPretriggerPosition(double position) {
1047 1048 if (!device->isConnected()) return Dso::ErrorCode::CONNECTION;
1048 1049  
1049 1050 // All trigger positions are measured in samples
1050   - unsigned positionSamples = position * controlsettings.samplerate.current;
  1051 + double positionSamples = position * controlsettings.samplerate.current;
1051 1052 unsigned recordLength = getRecordLength();
1052 1053 // Fast rate mode uses both channels
1053 1054 if (controlsettings.samplerate.limits == &specification.samplerate.multi) positionSamples /= HANTEK_CHANNELS;
... ... @@ -1055,7 +1056,7 @@ Dso::ErrorCode HantekDsoControl::setPretriggerPosition(double position) {
1055 1056 switch (specification.command.bulk.setPretrigger) {
1056 1057 case BULK_SETTRIGGERANDSAMPLERATE: {
1057 1058 // Calculate the position value (Start point depending on record length)
1058   - unsigned position = isRollMode() ? 0x1 : 0x7ffff - recordLength + positionSamples;
  1059 + unsigned position = isRollMode() ? 0x1 : 0x7ffff - recordLength + (unsigned)positionSamples;
1059 1060  
1060 1061 // SetTriggerAndSamplerate bulk command for trigger position
1061 1062 static_cast<BulkSetTriggerAndSamplerate *>(command[BULK_SETTRIGGERANDSAMPLERATE])->setTriggerPosition(position);
... ... @@ -1065,8 +1066,8 @@ Dso::ErrorCode HantekDsoControl::setPretriggerPosition(double position) {
1065 1066 }
1066 1067 case BULK_FSETBUFFER: {
1067 1068 // Calculate the position values (Inverse, maximum is 0x7ffff)
1068   - unsigned positionPre = 0x7ffff - recordLength + positionSamples;
1069   - unsigned positionPost = 0x7ffff - positionSamples;
  1069 + unsigned positionPre = 0x7ffff - recordLength + (unsigned)positionSamples;
  1070 + unsigned positionPost = 0x7ffff - (unsigned)positionSamples;
1070 1071  
1071 1072 // SetBuffer2250 bulk command for trigger position
1072 1073 BulkSetBuffer2250 *commandSetBuffer2250 = static_cast<BulkSetBuffer2250 *>(command[BULK_FSETBUFFER]);
... ... @@ -1078,13 +1079,13 @@ Dso::ErrorCode HantekDsoControl::setPretriggerPosition(double position) {
1078 1079 }
1079 1080 case BULK_ESETTRIGGERORSAMPLERATE: {
1080 1081 // Calculate the position values (Inverse, maximum is 0xffff)
1081   - unsigned short int positionPre = 0xffff - recordLength + positionSamples;
1082   - unsigned short int positionPost = 0xffff - positionSamples;
  1082 + unsigned positionPre = 0xffff - recordLength + (unsigned)positionSamples;
  1083 + unsigned positionPost = 0xffff - (unsigned)positionSamples;
1083 1084  
1084 1085 // SetBuffer5200 bulk command for trigger position
1085 1086 BulkSetBuffer5200 *commandSetBuffer5200 = static_cast<BulkSetBuffer5200 *>(command[BULK_DSETBUFFER]);
1086   - commandSetBuffer5200->setTriggerPositionPre(positionPre);
1087   - commandSetBuffer5200->setTriggerPositionPost(positionPost);
  1087 + commandSetBuffer5200->setTriggerPositionPre((unsigned short)positionPre);
  1088 + commandSetBuffer5200->setTriggerPositionPost((unsigned short)positionPost);
1088 1089 commandPending[BULK_DSETBUFFER] = true;
1089 1090  
1090 1091 break;
... ... @@ -1297,7 +1298,7 @@ void HantekDsoControl::run() {
1297 1298 this->_samplingStarted = false;
1298 1299  
1299 1300 // Start next capture if necessary by leaving out the break statement
1300   - if (!this->sampling) break;
  1301 + if (!this->sampling) break; else [[fallthrough]];
1301 1302  
1302 1303 case CAPTURE_WAITING:
1303 1304 // Sampling hasn't started, update the expected sample count
... ... @@ -1351,7 +1352,7 @@ void HantekDsoControl::run() {
1351 1352  
1352 1353 this->_samplingStarted = true;
1353 1354 this->cycleCounter = 0;
1354   - this->startCycle = controlsettings.trigger.position * 1000 / cycleTime + 1;
  1355 + this->startCycle = int(controlsettings.trigger.position * 1000.0 / cycleTime + 1.0);
1355 1356 this->lastTriggerMode = controlsettings.trigger.mode;
1356 1357 break;
1357 1358  
... ...
openhantek/src/hantekdso/hantekdsocontrol.h
... ... @@ -3,8 +3,6 @@
3 3 #pragma once
4 4  
5 5 #include "errorcodes.h"
6   -#include "bulkStructs.h"
7   -#include "controlStructs.h"
8 6 #include "dsosamples.h"
9 7 #include "states.h"
10 8 #include "controlspecification.h"
... ... @@ -88,7 +86,7 @@ class HantekDsoControl : public QObject {
88 86 private:
89 87 bool isRollMode() const;
90 88 bool isFastRate() const;
91   - int getRecordLength() const;
  89 + unsigned getRecordLength() const;
92 90  
93 91 Dso::ErrorCode retrieveChannelLevelData();
94 92  
... ...
openhantek/src/hantekdso/models/modelDSO2090.cpp
1 1 #include "modelDSO2090.h"
  2 +#include "hantekprotocol/bulkStructs.h"
  3 +#include "hantekdsocontrol.h"
2 4  
3 5 using namespace Hantek;
4 6  
... ...
openhantek/src/hantekdso/models/modelDSO2090.h
1 1 #pragma once
2 2  
3 3 #include "dsomodel.h"
4   -#include "hantekdsocontrol.h"
5   -#include "bulkStructs.h"
6 4  
  5 +class HantekDsoControl;
7 6 using namespace Hantek;
8 7  
9 8 struct ModelDSO2090 : public DSOModel {
... ...
openhantek/src/hantekdso/models/modelDSO2150.cpp
1 1 #include "modelDSO2150.h"
  2 +#include "hantekprotocol/bulkStructs.h"
  3 +#include "hantekdsocontrol.h"
2 4  
3 5 using namespace Hantek;
4 6  
... ...
openhantek/src/hantekdso/models/modelDSO2150.h
1 1 #pragma once
2 2  
3 3 #include "dsomodel.h"
4   -#include "hantekdsocontrol.h"
5   -#include "bulkStructs.h"
6 4  
  5 +class HantekDsoControl;
7 6 using namespace Hantek;
8 7  
9 8 struct ModelDSO2150 : public DSOModel {
... ...
openhantek/src/hantekdso/models/modelDSO2250.cpp
1 1 #include "modelDSO2250.h"
  2 +#include "hantekprotocol/bulkStructs.h"
  3 +#include "hantekdsocontrol.h"
2 4  
3 5 using namespace Hantek;
4 6  
... ...
openhantek/src/hantekdso/models/modelDSO2250.h
1 1 #pragma once
2 2  
3 3 #include "dsomodel.h"
4   -#include "hantekdsocontrol.h"
5   -#include "bulkStructs.h"
6 4  
  5 +class HantekDsoControl;
7 6 using namespace Hantek;
8 7  
9 8 struct ModelDSO2250 : public DSOModel {
... ...
openhantek/src/hantekdso/models/modelDSO5200.cpp
1 1 #include "modelDSO5200.h"
  2 +#include "hantekprotocol/bulkStructs.h"
  3 +#include "hantekdsocontrol.h"
2 4  
3 5 using namespace Hantek;
4 6  
... ...
openhantek/src/hantekdso/models/modelDSO5200.h
1 1 #pragma once
2 2  
3 3 #include "dsomodel.h"
4   -#include "hantekdsocontrol.h"
5   -#include "bulkStructs.h"
6 4  
  5 +class HantekDsoControl;
7 6 using namespace Hantek;
8 7  
9 8 struct ModelDSO5200 : public DSOModel {
... ...
openhantek/src/hantekdso/models/modelDSO6022.cpp
1 1 #include "modelDSO6022.h"
  2 +#include "usb/usbdevice.h"
  3 +#include "hantekprotocol/controlStructs.h"
  4 +#include "controlindexes.h"
  5 +#include "hantekdsocontrol.h"
2 6  
3 7 using namespace Hantek;
4 8  
... ...
openhantek/src/hantekdso/models/modelDSO6022.h
1 1 #pragma once
2 2  
3 3 #include "dsomodel.h"
4   -#include "hantekdsocontrol.h"
5   -#include "usb/usbdevice.h"
6   -#include "controlindexes.h"
7 4  
  5 +class HantekDsoControl;
8 6 using namespace Hantek;
9 7  
10 8 struct ModelDSO6022BE : public DSOModel {
... ...
openhantek/src/hantekprotocol/controlcode.h
... ... @@ -6,7 +6,7 @@
6 6 /// \brief All supported control commands.
7 7 enum ControlCode {
8 8 /// <em>[::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, ::MODEL_DSO5200,
9   - /// ::MODEL_DSO5200A]</em>
  9 + /// ::MODEL_DSO5200A, MODEL_DSO6022]</em>
10 10 /// <p>
11 11 /// The 0xa2 control read/write command gives access to a ::ControlValue.
12 12 /// </p>
... ... @@ -14,7 +14,7 @@ enum ControlCode {
14 14 CONTROL_VALUE = 0xa2,
15 15  
16 16 /// <em>[::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, ::MODEL_DSO5200,
17   - /// ::MODEL_DSO5200A]</em>
  17 + /// ::MODEL_DSO5200A, MODEL_DSO6022]</em>
18 18 /// <p>
19 19 /// The 0xb2 control read command gets the speed level of the USB
20 20 /// connection:
... ... @@ -132,9 +132,13 @@ enum ControlCode {
132 132 /// <p><br /></p>
133 133 CONTROL_SETRELAYS = 0xb5,
134 134  
  135 + /// CH1 voltage div setting (6022BE/BL)
135 136 CONTROL_SETVOLTDIV_CH1 = 0xe0,
  137 + /// CH2 voltage div setting (6022BE/BL)
136 138 CONTROL_SETVOLTDIV_CH2 = 0xe1,
  139 + /// Time divisor setting (6022BE/BL)
137 140 CONTROL_SETTIMEDIV = 0xe2,
  141 + /// Request sample data (6022BE/BL)
138 142 CONTROL_ACQUIIRE_HARD_DATA = 0xe3
139 143 };
140 144  
... ...
openhantek/src/scopesettings.h
1 1 #pragma once
2 2  
3   -#include "definitions.h"
4 3 #include <vector>
5 4 #include "analyse/enums.h"
6 5 #include "hantekdso/enums.h"
... ...
openhantek/src/settings.cpp
... ... @@ -28,7 +28,6 @@
28 28  
29 29 #include "settings.h"
30 30  
31   -#include "definitions.h"
32 31 #include "dsowidget.h"
33 32  
34 33 /// \brief Set the number of channels.
... ...
openhantek/src/usb/finddevices.h
... ... @@ -7,7 +7,6 @@
7 7 #include <map>
8 8 #include <list>
9 9  
10   -#include "definitions.h"
11 10 #include "usbdevice.h"
12 11  
13 12 struct libusb_context;
... ...
openhantek/src/usb/usbdevice.cpp
... ... @@ -7,7 +7,6 @@
7 7 #include "usbdevice.h"
8 8  
9 9 #include "controlgetspeed.h"
10   -#include "controlcode.h"
11 10 #include "models.h"
12 11 #include "utils/printutils.h"
13 12  
... ... @@ -280,7 +279,7 @@ int USBDevice::getConnectionSpeed() {
280 279 }
281 280  
282 281 /// \brief Gets the maximum size of one packet transmitted via bulk transfer.
283   -/// \return The maximum packet size in bytes, -1 on error.
  282 +/// \return The maximum packet size in bytes, negative libusb error code on error.
284 283 int USBDevice::getPacketSize() {
285 284 const int s = this->getConnectionSpeed();
286 285 if (s == CONNECTION_FULLSPEED)
... ... @@ -290,8 +289,8 @@ int USBDevice::getPacketSize() {
290 289 else if (s > CONNECTION_HIGHSPEED) {
291 290 std::cerr << "Unknown USB speed. Please correct source code in USBDevice::getPacketSize()" << std::endl;
292 291 throw new std::runtime_error("Unknown USB speed");
293   - }
294   - return -1;
  292 + } else if (s<0) return s;
  293 + return 0;
295 294 }
296 295  
297 296 libusb_device *USBDevice::getRawDevice() const { return device; }
... ...
openhantek/src/usb/usbdevice.h
... ... @@ -9,7 +9,6 @@
9 9  
10 10 #include "usbdevicedefinitions.h"
11 11 #include "controlbegin.h"
12   -#include "definitions.h"
13 12 #include "utils/dataarray.h"
14 13  
15 14 class DSOModel;
... ...
openhantek/src/utils/dsoStrings.h
... ... @@ -4,7 +4,6 @@
4 4 #include <QString>
5 5 #include "analyse/enums.h"
6 6 #include "hantekdso/enums.h"
7   -#include "definitions.h"
8 7  
9 8 #define MARKER_COUNT 2 ///< Number of markers
10 9  
... ...
openhantek/src/utils/printutils.h
... ... @@ -48,7 +48,7 @@ unsigned int hexParse(const QString dump, unsigned char *data, unsigned int leng
48 48 /// \brief Print debug information with timestamp.
49 49 /// \param text Text that will be output via qDebug.
50 50 #ifdef DEBUG
51   -inline void timestampDebug(QString text) {
  51 +inline void timestampDebug(const QString& text) {
52 52 qDebug("%s: %s", QTime::currentTime().toString("hh:mm:ss.zzz").toLatin1().constData(), text.toLatin1().constData());
53 53 }
54 54 #else
... ...
openhantek/src/viewconstants.h
1 1 #pragma once
2 2  
3   -#define DIVS_TIME 10.0 ///< Number of horizontal screen divs
4   -#define DIVS_VOLTAGE 8.0 ///< Number of vertical screen divs
  3 +#define DIVS_TIME 10.0f ///< Number of horizontal screen divs
  4 +#define DIVS_VOLTAGE 8.0f ///< Number of vertical screen divs
5 5 #define DIVS_SUB 5 ///< Number of sub-divisions per div
... ...
openhantek/src/viewsettings.h
1 1 #pragma once
2 2  
3   -#include "definitions.h"
4 3 #include <QColor>
5 4 #include <QObject>
6 5 #include <QPoint>
... ... @@ -43,7 +42,7 @@ struct DsoSettingsView {
43 42 std::vector<QColor>()};
44 43 bool antialiasing = true; ///< Antialiasing for the graphs
45 44 bool digitalPhosphor = false; ///< true slowly fades out the previous graphs
46   - int digitalPhosphorDepth = 8; ///< Number of channels shown at one time
  45 + unsigned digitalPhosphorDepth = 8; ///< Number of channels shown at one time
47 46 Dso::InterpolationMode interpolation = Dso::INTERPOLATION_LINEAR; ///< Interpolation mode for the graph
48 47 bool screenColorImages = false; ///< true exports images with screen colors
49 48 bool zoom = false; ///< true if the magnified scope is enabled
... ...