diff --git a/openhantek/CMakeLists.txt b/openhantek/CMakeLists.txt index a0d114f2..2c39da36 100644 --- a/openhantek/CMakeLists.txt +++ b/openhantek/CMakeLists.txt @@ -14,7 +14,7 @@ endif() # include directories set(CMAKE_INCLUDE_CURRENT_DIR ON) -include_directories(src/ src/hantekprotocol src/hantekdso src/widgets src/docks src/configdialog) +include_directories(src/ src/hantekdso src/widgets src/docks src/configdialog) # collect sources and other files file(GLOB_RECURSE SRC "src/*.cpp") diff --git a/openhantek/src/analyse/dataanalyzer.h b/openhantek/src/analyse/dataanalyzer.h index 54c22f85..d925a2d3 100644 --- a/openhantek/src/analyse/dataanalyzer.h +++ b/openhantek/src/analyse/dataanalyzer.h @@ -9,7 +9,6 @@ #include #include "dataanalyzerresult.h" -#include "definitions.h" #include "dsosamples.h" #include "utils/printutils.h" #include "enums.h" diff --git a/openhantek/src/analyse/dataanalyzerresult.cpp b/openhantek/src/analyse/dataanalyzerresult.cpp index 7ad213b7..b3408f0d 100644 --- a/openhantek/src/analyse/dataanalyzerresult.cpp +++ b/openhantek/src/analyse/dataanalyzerresult.cpp @@ -9,14 +9,14 @@ DataAnalyzerResult::DataAnalyzerResult(unsigned int channelCount) { analyzedData /// \brief Returns the analyzed data. /// \param channel Channel, whose data should be returned. /// \return Analyzed data as AnalyzedData struct. -const DataChannel *DataAnalyzerResult::data(int channel) const { - if (channel >= (int)this->analyzedData.size()) return 0; +const DataChannel *DataAnalyzerResult::data(unsigned channel) const { + if (channel >= this->analyzedData.size()) return 0; return &this->analyzedData[(size_t)channel]; } -DataChannel *DataAnalyzerResult::modifyData(int channel) { - if (channel >= (int)this->analyzedData.size()) +DataChannel *DataAnalyzerResult::modifyData(unsigned channel) { + if (channel >= this->analyzedData.size()) throw new std::runtime_error("If you modfiy the DataAnalyzerResult, you " "need to set the channels first!"); diff --git a/openhantek/src/analyse/dataanalyzerresult.h b/openhantek/src/analyse/dataanalyzerresult.h index 5266e999..aa6e5a51 100644 --- a/openhantek/src/analyse/dataanalyzerresult.h +++ b/openhantek/src/analyse/dataanalyzerresult.h @@ -25,8 +25,8 @@ struct DataChannel { class DataAnalyzerResult { public: DataAnalyzerResult(unsigned int channelCount); - const DataChannel *data(int channel) const; - DataChannel *modifyData(int channel); + const DataChannel *data(unsigned channel) const; + DataChannel *modifyData(unsigned channel); unsigned int sampleCount() const; unsigned int channelCount() const; diff --git a/openhantek/src/configdialog/DsoConfigAnalysisPage.h b/openhantek/src/configdialog/DsoConfigAnalysisPage.h index 8a9673e9..aa408b51 100644 --- a/openhantek/src/configdialog/DsoConfigAnalysisPage.h +++ b/openhantek/src/configdialog/DsoConfigAnalysisPage.h @@ -2,7 +2,6 @@ #include -#include "definitions.h" #include "settings.h" #include diff --git a/openhantek/src/configdialog/DsoConfigColorsPage.h b/openhantek/src/configdialog/DsoConfigColorsPage.h index b175c65b..21975480 100644 --- a/openhantek/src/configdialog/DsoConfigColorsPage.h +++ b/openhantek/src/configdialog/DsoConfigColorsPage.h @@ -2,7 +2,6 @@ #include -#include "definitions.h" #include "settings.h" #include diff --git a/openhantek/src/configdialog/DsoConfigFilesPage.h b/openhantek/src/configdialog/DsoConfigFilesPage.h index 07f6c614..8bcfd719 100644 --- a/openhantek/src/configdialog/DsoConfigFilesPage.h +++ b/openhantek/src/configdialog/DsoConfigFilesPage.h @@ -2,7 +2,6 @@ #include -#include "definitions.h" #include "settings.h" #include diff --git a/openhantek/src/configdialog/DsoConfigScopePage.h b/openhantek/src/configdialog/DsoConfigScopePage.h index 188669c1..bdeae8c5 100644 --- a/openhantek/src/configdialog/DsoConfigScopePage.h +++ b/openhantek/src/configdialog/DsoConfigScopePage.h @@ -2,7 +2,6 @@ #include -#include "definitions.h" #include "settings.h" #include diff --git a/openhantek/src/docks/HorizontalDock.h b/openhantek/src/docks/HorizontalDock.h index bd0586d9..d9796389 100644 --- a/openhantek/src/docks/HorizontalDock.h +++ b/openhantek/src/docks/HorizontalDock.h @@ -6,7 +6,6 @@ #include #include -#include "definitions.h" #include "settings.h" class QLabel; diff --git a/openhantek/src/docks/SpectrumDock.h b/openhantek/src/docks/SpectrumDock.h index 1c13ea26..d4e72a38 100644 --- a/openhantek/src/docks/SpectrumDock.h +++ b/openhantek/src/docks/SpectrumDock.h @@ -5,7 +5,6 @@ #include #include -#include "definitions.h" #include "settings.h" class QLabel; diff --git a/openhantek/src/docks/TriggerDock.h b/openhantek/src/docks/TriggerDock.h index ce7e9144..19f455aa 100644 --- a/openhantek/src/docks/TriggerDock.h +++ b/openhantek/src/docks/TriggerDock.h @@ -5,7 +5,6 @@ #include #include -#include "definitions.h" #include "settings.h" class QLabel; diff --git a/openhantek/src/docks/VoltageDock.h b/openhantek/src/docks/VoltageDock.h index 4269c588..173341c6 100644 --- a/openhantek/src/docks/VoltageDock.h +++ b/openhantek/src/docks/VoltageDock.h @@ -5,7 +5,6 @@ #include #include -#include "definitions.h" #include "settings.h" class QLabel; diff --git a/openhantek/src/docks/dockwindows.cpp b/openhantek/src/docks/dockwindows.cpp index f80d7cda..b1452af6 100644 --- a/openhantek/src/docks/dockwindows.cpp +++ b/openhantek/src/docks/dockwindows.cpp @@ -10,7 +10,6 @@ #include "analyse/enums.h" #include "hantekdso/enums.h" -#include "definitions.h" #include "dockwindows.h" void SetupDockWidget(QDockWidget *dockWindow, QWidget *dockWidget, QLayout *layout) { diff --git a/openhantek/src/exporter.cpp b/openhantek/src/exporter.cpp index bfec9b64..d675d648 100644 --- a/openhantek/src/exporter.cpp +++ b/openhantek/src/exporter.cpp @@ -18,7 +18,6 @@ #include "exporter.h" #include "analyse/dataanalyzerresult.h" -#include "definitions.h" #include "glgenerator.h" #include "settings.h" #include "utils/dsoStrings.h" diff --git a/openhantek/src/glgenerator.cpp b/openhantek/src/glgenerator.cpp index d9e272cd..ba9ba739 100644 --- a/openhantek/src/glgenerator.cpp +++ b/openhantek/src/glgenerator.cpp @@ -121,9 +121,9 @@ GlGenerator::PrePostStartTriggerSamples GlGenerator::computeSoftwareTriggerTY(co result->data(channel)->voltage.sample.empty()) return PrePostStartTriggerSamples(preTrigSamples, postTrigSamples, swTriggerStart); - double value; + const std::vector& samples = result->data(channel)->voltage.sample; double level = settings->voltage[channel].trigger; - unsigned int sampleCount = result->data(channel)->voltage.sample.size(); + size_t sampleCount = samples.size(); double timeDisplay = settings->horizontal.timebase * 10; double samplesDisplay = timeDisplay * settings->horizontal.samplerate; if (samplesDisplay >= sampleCount) { @@ -137,29 +137,29 @@ GlGenerator::PrePostStartTriggerSamples GlGenerator::computeSoftwareTriggerTY(co "picture. Decrease sample rate")); return PrePostStartTriggerSamples(preTrigSamples, postTrigSamples, swTriggerStart); } - preTrigSamples = (settings->trigger.position * samplesDisplay); - postTrigSamples = sampleCount - (samplesDisplay - preTrigSamples); + preTrigSamples = (unsigned)(settings->trigger.position * samplesDisplay); + postTrigSamples = (unsigned)sampleCount - ((unsigned)samplesDisplay - preTrigSamples); const int threshold = 7; double prev; - bool (*opcmp)(int,int,int); - bool (*smplcmp)(int,int); + bool (*opcmp)(double,double,double); + bool (*smplcmp)(double,double); if (settings->trigger.slope == Dso::SLOPE_POSITIVE) { prev = INT_MAX; - opcmp = [](int value, int level, int prev) { return value > level && prev <= level;}; - smplcmp = [](int sampleK, int value) { return sampleK >= value;}; + opcmp = [](double value, double level, double prev) { return value > level && prev <= level;}; + smplcmp = [](double sampleK, double value) { return sampleK >= value;}; } else { prev = INT_MIN; - opcmp = [](int value, int level, int prev) { return value > level && prev <= level;}; - smplcmp = [](int sampleK, int value) { return sampleK < value;}; + opcmp = [](double value, double level, double prev) { return value < level && prev >= level;}; + smplcmp = [](double sampleK, double value) { return sampleK < value;}; } for (unsigned int i = preTrigSamples; i < postTrigSamples; i++) { - value = result->data(channel)->voltage.sample[i]; + double value = samples[i]; if (opcmp(value, level, prev)) { int rising = 0; for (unsigned int k = i + 1; k < i + 11 && k < sampleCount; k++) { - if (smplcmp(result->data(channel)->voltage.sample[k], value)) { rising++; } + if (smplcmp(samples[k], value)) { rising++; } } if (rising > threshold) { swTriggerStart = i; @@ -170,13 +170,26 @@ GlGenerator::PrePostStartTriggerSamples GlGenerator::computeSoftwareTriggerTY(co } if (swTriggerStart == 0) { timestampDebug(QString("Trigger not asserted. Data ignored")); + preTrigSamples = 0; // preTrigSamples may never be greater than swTriggerStart } return PrePostStartTriggerSamples(preTrigSamples, postTrigSamples, swTriggerStart); } +const SampleValues& GlGenerator::useSamplesOf(int mode, unsigned channel, const DataAnalyzerResult *result) const +{ + static SampleValues emptyDefault; + if (mode == Dso::CHANNELMODE_VOLTAGE) { + if (!settings->voltage[channel].used || !result->data(channel)) return emptyDefault; + return result->data(channel)->voltage; + } else { + if (!settings->spectrum[channel].used || !result->data(channel)) return emptyDefault; + return result->data(channel)->spectrum; + } +} + void GlGenerator::generateGraphs(const DataAnalyzerResult *result) { - int digitalPhosphorDepth = view->digitalPhosphor ? view->digitalPhosphorDepth : 1; + unsigned digitalPhosphorDepth = view->digitalPhosphor ? view->digitalPhosphorDepth : 1; // Handle all digital phosphor related list manipulations for (int mode = Dso::CHANNELMODE_VOLTAGE; mode < Dso::CHANNELMODE_COUNT; ++mode) { @@ -197,105 +210,106 @@ void GlGenerator::generateGraphs(const DataAnalyzerResult *result) { ready = true; - unsigned preTrigSamples; - unsigned postTrigSamples; - unsigned swTriggerStart; + unsigned preTrigSamples=0; + unsigned postTrigSamples=0; + unsigned swTriggerStart=0; switch (settings->horizontal.format) { case Dso::GRAPHFORMAT_TY: std::tie(preTrigSamples, postTrigSamples, swTriggerStart) = computeSoftwareTriggerTY(result); // Add graphs for channels for (int mode = Dso::CHANNELMODE_VOLTAGE; mode < Dso::CHANNELMODE_COUNT; ++mode) { - for (int channel = 0; channel < (int)settings->voltage.size(); ++channel) { + DrawLinesWithHistoryPerChannel& dPerChannel = vaChannel[mode]; + for (unsigned channel = 0; channel < settings->voltage.size(); ++channel) { + DrawLinesWithHistory& withHistory = dPerChannel[channel]; + const SampleValues& samples = useSamplesOf(mode, channel, result); + // Check if this channel is used and available at the data analyzer - if (((mode == Dso::CHANNELMODE_VOLTAGE) ? settings->voltage[channel].used - : settings->spectrum[channel].used) && - result->data(channel) && !result->data(channel)->voltage.sample.empty()) { - // Check if the sample count has changed - size_t sampleCount = (mode == Dso::CHANNELMODE_VOLTAGE) - ? result->data(channel)->voltage.sample.size() - : result->data(channel)->spectrum.sample.size(); - if (mode == Dso::CHANNELMODE_VOLTAGE) sampleCount -= (swTriggerStart - preTrigSamples); - size_t neededSize = sampleCount * 2; + if (samples.sample.empty()) { + // Delete all vector arrays + for (unsigned index = 0; index < digitalPhosphorDepth; ++index) + withHistory[index].clear(); + continue; + } + // Check if the sample count has changed + size_t sampleCount = samples.sample.size(); + if (sampleCount>9000) { + throw new std::runtime_error(""); + } + if (mode == Dso::CHANNELMODE_VOLTAGE) + sampleCount -= (swTriggerStart - preTrigSamples); + size_t neededSize = sampleCount * 2; #if 0 - for(unsigned int index = 0; index < digitalPhosphorDepth; ++index) { - if(vaChannel[mode][channel][index].size() != neededSize) - vaChannel[mode][channel][index].clear(); // Something was changed, drop old traces - } + for(unsigned int index = 0; index < digitalPhosphorDepth; ++index) { + if(vaChannel[mode][channel][index].size() != neededSize) + vaChannel[mode][channel][index].clear(); // Something was changed, drop old traces + } #endif - // Set size directly to avoid reallocations - vaChannel[mode][(size_t)channel].front().resize(neededSize); - - // Iterator to data for direct access - std::vector::iterator glIterator = vaChannel[mode][(size_t)channel].front().begin(); - - // What's the horizontal distance between sampling points? - double horizontalFactor; - if (mode == Dso::CHANNELMODE_VOLTAGE) - horizontalFactor = result->data(channel)->voltage.interval / settings->horizontal.timebase; - else - horizontalFactor = - result->data(channel)->spectrum.interval / settings->horizontal.frequencybase; - - // Fill vector array - if (mode == Dso::CHANNELMODE_VOLTAGE) { - std::vector::const_iterator dataIterator = - result->data(channel)->voltage.sample.begin(); - const double gain = settings->voltage[channel].gain; - const double offset = settings->voltage[channel].offset; - const double invert = settings->voltage[channel].inverted ? -1.0 : 1.0; - - std::advance(dataIterator, swTriggerStart - preTrigSamples); - - for (unsigned int position = 0; position < sampleCount; ++position) { - *(glIterator++) = position * horizontalFactor - DIVS_TIME / 2; - *(glIterator++) = *(dataIterator++) / gain * invert + offset; - } - } else { - std::vector::const_iterator dataIterator = - result->data(channel)->spectrum.sample.begin(); - const double magnitude = settings->spectrum[channel].magnitude; - const double offset = settings->spectrum[channel].offset; - - for (unsigned int position = 0; position < sampleCount; ++position) { - *(glIterator++) = position * horizontalFactor - DIVS_TIME / 2; - *(glIterator++) = *(dataIterator++) / magnitude + offset; - } + // Set size directly to avoid reallocations + withHistory.front().resize(neededSize); + + // Iterator to data for direct access + DrawLines::iterator glIterator = withHistory.front().begin(); + + // What's the horizontal distance between sampling points? + float horizontalFactor; + if (mode == Dso::CHANNELMODE_VOLTAGE) + horizontalFactor = (float)(samples.interval / settings->horizontal.timebase); + else + horizontalFactor = (float)(samples.interval / settings->horizontal.frequencybase); + + // Fill vector array + if (mode == Dso::CHANNELMODE_VOLTAGE) { + std::vector::const_iterator dataIterator = samples.sample.begin(); + const float gain = (float) settings->voltage[channel].gain; + const float offset = (float) settings->voltage[channel].offset; + const float invert = settings->voltage[channel].inverted ? -1.0f : 1.0f; + + std::advance(dataIterator, swTriggerStart - preTrigSamples); + + for (unsigned int position = 0; position < sampleCount; ++position) { + *(glIterator++) = position * horizontalFactor - DIVS_TIME / 2; + *(glIterator++) = (float)*(dataIterator++) / gain * invert + offset; } } else { - // Delete all vector arrays - for (unsigned index = 0; index < (unsigned)digitalPhosphorDepth; ++index) - vaChannel[mode][channel][index].clear(); + std::vector::const_iterator dataIterator = samples.sample.begin(); + const float magnitude = (float)settings->spectrum[channel].magnitude; + const float offset = (float)settings->spectrum[channel].offset; + + for (unsigned int position = 0; position < sampleCount; ++position) { + *(glIterator++) = position * horizontalFactor - DIVS_TIME / 2; + *(glIterator++) = (float)*(dataIterator++) / magnitude + offset; + } } } } break; case Dso::GRAPHFORMAT_XY: - for (int channel = 0; channel < settings->voltage.size(); ++channel) { + for (unsigned channel = 0; channel < settings->voltage.size(); ++channel) { // For even channel numbers check if this channel is used and this and the // following channel are available at the data analyzer if (channel % 2 == 0 && channel + 1 < settings->voltage.size() && settings->voltage[channel].used && result->data(channel) && !result->data(channel)->voltage.sample.empty() && result->data(channel + 1) && !result->data(channel + 1)->voltage.sample.empty()) { // Check if the sample count has changed - const unsigned sampleCount = qMin(result->data(channel)->voltage.sample.size(), + const size_t sampleCount = std::min(result->data(channel)->voltage.sample.size(), result->data(channel + 1)->voltage.sample.size()); - const unsigned neededSize = sampleCount * 2; - for (unsigned index = 0; index < (unsigned)digitalPhosphorDepth; ++index) { - if (vaChannel[Dso::CHANNELMODE_VOLTAGE][(size_t)channel][index].size() != neededSize) - vaChannel[Dso::CHANNELMODE_VOLTAGE][(size_t)channel][index] - .clear(); // Something was changed, drop old traces + const size_t neededSize = sampleCount * 2; + DrawLinesWithHistory& withHistory = vaChannel[Dso::CHANNELMODE_VOLTAGE][(size_t)channel]; + for (unsigned index = 0; index < digitalPhosphorDepth; ++index) { + if (withHistory[index].size() != neededSize) + withHistory[index].clear(); // Something was changed, drop old traces } // Set size directly to avoid reallocations - vaChannel[Dso::CHANNELMODE_VOLTAGE][(size_t)channel].front().resize(neededSize); + DrawLines& drawLines = withHistory.front(); + drawLines.resize(neededSize); // Iterator to data for direct access - std::vector::iterator glIterator = - vaChannel[Dso::CHANNELMODE_VOLTAGE][channel].front().begin(); + std::vector::iterator glIterator = drawLines.begin(); // Fill vector array unsigned int xChannel = channel; @@ -310,8 +324,8 @@ void GlGenerator::generateGraphs(const DataAnalyzerResult *result) { const double yInvert = settings->voltage[yChannel].inverted ? -1.0 : 1.0; for (unsigned int position = 0; position < sampleCount; ++position) { - *(glIterator++) = *(xIterator++) / xGain * xInvert + xOffset; - *(glIterator++) = *(yIterator++) / yGain * yInvert + yOffset; + *(glIterator++) = (GLfloat)( *(xIterator++) / xGain * xInvert + xOffset); + *(glIterator++) = (GLfloat)( *(yIterator++) / yGain * yInvert + yOffset); } } else { // Delete all vector arrays diff --git a/openhantek/src/glgenerator.h b/openhantek/src/glgenerator.h index 994060ef..4dba5c84 100644 --- a/openhantek/src/glgenerator.h +++ b/openhantek/src/glgenerator.h @@ -41,6 +41,8 @@ class GlGenerator : public QObject { DsoSettingsView *view; std::vector vaGrid[3]; bool ready = false; + + const SampleValues &useSamplesOf(int mode, unsigned channel, const DataAnalyzerResult *result) const; signals: void graphsGenerated(); ///< The graphs are ready to be drawn }; diff --git a/openhantek/src/glscope.h b/openhantek/src/glscope.h index 708a0d0b..8e27f246 100644 --- a/openhantek/src/glscope.h +++ b/openhantek/src/glscope.h @@ -13,8 +13,6 @@ using GL_WIDGET_CLASS = QOpenGLWidget; using GL_WIDGET_CLASS = QGLWidget; #endif -#include "definitions.h" - class GlGenerator; class DsoSettings; diff --git a/openhantek/src/hantekdso/controlsettings.cpp b/openhantek/src/hantekdso/controlsettings.cpp index 9815e9e4..b3f0d4a9 100644 --- a/openhantek/src/hantekdso/controlsettings.cpp +++ b/openhantek/src/hantekdso/controlsettings.cpp @@ -1,14 +1,13 @@ #include "controlsettings.h" -#include "definitions.h" namespace Hantek { -ControlSettings::ControlSettings(ControlSamplerateLimits* limits) +ControlSettings::ControlSettings(ControlSamplerateLimits* limits, size_t channelCount) { samplerate.limits = limits; - trigger.level.resize(HANTEK_CHANNELS); - voltage.resize(HANTEK_CHANNELS); - for (unsigned channel = 0; channel < HANTEK_CHANNELS; ++channel) { + trigger.level.resize(channelCount); + voltage.resize(channelCount); + for (unsigned channel = 0; channel < channelCount; ++channel) { trigger.level[channel] = 0.0; voltage[channel].gain = 0; voltage[channel].offset = 0.0; diff --git a/openhantek/src/hantekdso/controlsettings.h b/openhantek/src/hantekdso/controlsettings.h index c35b27eb..af3f7a71 100644 --- a/openhantek/src/hantekdso/controlsettings.h +++ b/openhantek/src/hantekdso/controlsettings.h @@ -52,12 +52,12 @@ struct ControlSettingsVoltage { /// \struct ControlSettings hantek/control.h /// \brief Stores the current settings of the device. struct ControlSettings { - ControlSettings(ControlSamplerateLimits *limits); + ControlSettings(ControlSamplerateLimits *limits, size_t channelCount); ControlSettingsSamplerate samplerate; ///< The samplerate settings std::vector voltage; ///< The amplification settings ControlSettingsTrigger trigger; ///< The trigger settings - unsigned int recordLengthId = 1; ///< The id in the record length array - unsigned short int usedChannels = 0; ///< Number of activated channels + unsigned recordLengthId = 1; ///< The id in the record length array + unsigned usedChannels = 0; ///< Number of activated channels }; } diff --git a/openhantek/src/hantekdso/controlspecification.cpp b/openhantek/src/hantekdso/controlspecification.cpp deleted file mode 100644 index 4bb848f7..00000000 --- a/openhantek/src/hantekdso/controlspecification.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "controlspecification.h" - -namespace Hantek { - -ControlSpecification::ControlSpecification() noexcept { -} - -} diff --git a/openhantek/src/hantekdso/controlspecification.h b/openhantek/src/hantekdso/controlspecification.h index dbe9f39d..f8b6b6c1 100644 --- a/openhantek/src/hantekdso/controlspecification.h +++ b/openhantek/src/hantekdso/controlspecification.h @@ -2,10 +2,10 @@ #pragma once -#include "controlvalue.h" -#include "bulkcode.h" -#include "controlcode.h" -#include "definitions.h" +#include "hantekprotocol/controlvalue.h" +#include "hantekprotocol/bulkcode.h" +#include "hantekprotocol/controlcode.h" +#include "hantekprotocol/definitions.h" #include namespace Hantek { @@ -71,7 +71,6 @@ struct ControlSpecificationSamplerate { /// \struct ControlSpecification hantek/control.h /// \brief Stores the specifications of the currently connected device. struct ControlSpecification { - ControlSpecification() noexcept; // Interface ControlSpecificationCommands command; ///< The commands for this device diff --git a/openhantek/src/hantekdso/hantekdsocontrol.cpp b/openhantek/src/hantekdso/hantekdsocontrol.cpp index cb62991f..7f9811bc 100644 --- a/openhantek/src/hantekdso/hantekdsocontrol.cpp +++ b/openhantek/src/hantekdso/hantekdsocontrol.cpp @@ -12,7 +12,8 @@ #include #include "hantekdsocontrol.h" - +#include "hantekprotocol/bulkStructs.h" +#include "hantekprotocol/controlStructs.h" #include "models/modelDSO6022.h" #include "usb/usbdevice.h" #include "utils/printutils.h" @@ -54,7 +55,7 @@ USBDevice *HantekDsoControl::getDevice() { return device; } const DSOsamples &HantekDsoControl::getLastSamples() { return result; } HantekDsoControl::HantekDsoControl(USBDevice *device) : device(device), - specification(device->getModel()->specification), controlsettings(&(specification.samplerate.single)) { + specification(device->getModel()->specification), controlsettings(&(specification.samplerate.single), HANTEK_CHANNELS) { if (device == nullptr) throw new std::runtime_error("No usb device for HantekDsoControl"); // Transmission-ready control commands @@ -123,7 +124,7 @@ bool HantekDsoControl::isFastRate() const { return controlsettings.samplerate.limits == &specification.samplerate.multi; } -int HantekDsoControl::getRecordLength() const { +unsigned HantekDsoControl::getRecordLength() const { return controlsettings.samplerate.limits->recordLengths[controlsettings.recordLengthId]; } @@ -238,7 +239,7 @@ void HantekDsoControl::convertRawDataToSamples(const std::vector // Resize sample vector result.data[channel].resize(totalSampleCount); - const int gainID = (int)controlsettings.voltage[channel].gain; + const unsigned gainID = controlsettings.voltage[channel].gain; const unsigned short limit = specification.voltageLimit[channel][gainID]; const double offset = controlsettings.voltage[channel].offsetReal; const double gainStep = specification.gainSteps[gainID]; @@ -271,7 +272,7 @@ void HantekDsoControl::convertRawDataToSamples(const std::vector for (unsigned channel = 0; channel < HANTEK_CHANNELS; ++channel) { result.data[channel].resize(totalSampleCount / HANTEK_CHANNELS); - const int gainID = controlsettings.voltage[channel].gain; + const unsigned gainID = controlsettings.voltage[channel].gain; const unsigned short limit = specification.voltageLimit[channel][gainID]; const double offset = controlsettings.voltage[channel].offsetReal; const double gainStep = specification.gainSteps[gainID]; @@ -335,8 +336,7 @@ double HantekDsoControl::getBestSamplerate(double samplerate, bool fastRate, boo limits = &(specification.samplerate.single); // Get downsampling factor that would provide the requested rate - double bestDownsampler = - (double)limits->base / specification.bufferDividers[controlsettings.recordLengthId] / samplerate; + double bestDownsampler = limits->base / specification.bufferDividers[controlsettings.recordLengthId] / samplerate; // Base samplerate sufficient, or is the maximum better? if (bestDownsampler < 1.0 && (samplerate <= limits->max / specification.bufferDividers[controlsettings.recordLengthId] || !maximum)) { @@ -407,6 +407,7 @@ double HantekDsoControl::getBestSamplerate(double samplerate, bool fastRate, boo unsigned HantekDsoControl::getSampleCount() const { if (isRollMode()) { + // TODO handle libusb error return device->getPacketSize(); } else { if (isFastRate()) @@ -716,7 +717,7 @@ Dso::ErrorCode HantekDsoControl::setRecordTime(double duration) { // Better add some margin for our SW trigger unsigned sampleMargin = 2000; unsigned sampleCount = 10240; - int bestId = 0; + unsigned bestId = 0; unsigned sampleId; for (sampleId = 0; sampleId < specification.sampleSteps.size(); ++sampleId) { if (specification.sampleSteps[sampleId] * duration < (sampleCount - sampleMargin)) bestId = sampleId; @@ -746,8 +747,8 @@ Dso::ErrorCode HantekDsoControl::setChannelUsed(unsigned channel, bool used) { // Update settings controlsettings.voltage[channel].used = used; unsigned channelCount = 0; - for (int channelCounter = 0; channelCounter < HANTEK_CHANNELS; ++channelCounter) { - if (controlsettings.voltage[channelCounter].used) ++channelCount; + for (unsigned c = 0; c < HANTEK_CHANNELS; ++c) { + if (controlsettings.voltage[c].used) ++channelCount; } // Calculate the UsedChannels field for the command @@ -974,9 +975,9 @@ Dso::ErrorCode HantekDsoControl::setTriggerLevel(unsigned channel, double level) if (specification.sampleSize > 8) { Offset& offsetLimit = specification.offsetLimit[channel].step[controlsettings.voltage[channel].gain]; // The range is the same as used for the offsets for 10 bit models - minimum = ((unsigned short int)*((unsigned char *)&(offsetLimit.start)) << 8) + + minimum = ((unsigned short)*((unsigned char *)&(offsetLimit.start)) << 8) + *((unsigned char *)&(offsetLimit.start) + 1); - maximum = ((unsigned short int)*((unsigned char *)&(offsetLimit.end)) << 8) + + maximum = ((unsigned short)*((unsigned char *)&(offsetLimit.end)) << 8) + *((unsigned char *)&(offsetLimit.end) + 1); } else { // It's from 0x00 to 0xfd for the 8 bit models @@ -1047,7 +1048,7 @@ Dso::ErrorCode HantekDsoControl::setPretriggerPosition(double position) { if (!device->isConnected()) return Dso::ErrorCode::CONNECTION; // All trigger positions are measured in samples - unsigned positionSamples = position * controlsettings.samplerate.current; + double positionSamples = position * controlsettings.samplerate.current; unsigned recordLength = getRecordLength(); // Fast rate mode uses both channels if (controlsettings.samplerate.limits == &specification.samplerate.multi) positionSamples /= HANTEK_CHANNELS; @@ -1055,7 +1056,7 @@ Dso::ErrorCode HantekDsoControl::setPretriggerPosition(double position) { switch (specification.command.bulk.setPretrigger) { case BULK_SETTRIGGERANDSAMPLERATE: { // Calculate the position value (Start point depending on record length) - unsigned position = isRollMode() ? 0x1 : 0x7ffff - recordLength + positionSamples; + unsigned position = isRollMode() ? 0x1 : 0x7ffff - recordLength + (unsigned)positionSamples; // SetTriggerAndSamplerate bulk command for trigger position static_cast(command[BULK_SETTRIGGERANDSAMPLERATE])->setTriggerPosition(position); @@ -1065,8 +1066,8 @@ Dso::ErrorCode HantekDsoControl::setPretriggerPosition(double position) { } case BULK_FSETBUFFER: { // Calculate the position values (Inverse, maximum is 0x7ffff) - unsigned positionPre = 0x7ffff - recordLength + positionSamples; - unsigned positionPost = 0x7ffff - positionSamples; + unsigned positionPre = 0x7ffff - recordLength + (unsigned)positionSamples; + unsigned positionPost = 0x7ffff - (unsigned)positionSamples; // SetBuffer2250 bulk command for trigger position BulkSetBuffer2250 *commandSetBuffer2250 = static_cast(command[BULK_FSETBUFFER]); @@ -1078,13 +1079,13 @@ Dso::ErrorCode HantekDsoControl::setPretriggerPosition(double position) { } case BULK_ESETTRIGGERORSAMPLERATE: { // Calculate the position values (Inverse, maximum is 0xffff) - unsigned short int positionPre = 0xffff - recordLength + positionSamples; - unsigned short int positionPost = 0xffff - positionSamples; + unsigned positionPre = 0xffff - recordLength + (unsigned)positionSamples; + unsigned positionPost = 0xffff - (unsigned)positionSamples; // SetBuffer5200 bulk command for trigger position BulkSetBuffer5200 *commandSetBuffer5200 = static_cast(command[BULK_DSETBUFFER]); - commandSetBuffer5200->setTriggerPositionPre(positionPre); - commandSetBuffer5200->setTriggerPositionPost(positionPost); + commandSetBuffer5200->setTriggerPositionPre((unsigned short)positionPre); + commandSetBuffer5200->setTriggerPositionPost((unsigned short)positionPost); commandPending[BULK_DSETBUFFER] = true; break; @@ -1297,7 +1298,7 @@ void HantekDsoControl::run() { this->_samplingStarted = false; // Start next capture if necessary by leaving out the break statement - if (!this->sampling) break; + if (!this->sampling) break; else [[fallthrough]]; case CAPTURE_WAITING: // Sampling hasn't started, update the expected sample count @@ -1351,7 +1352,7 @@ void HantekDsoControl::run() { this->_samplingStarted = true; this->cycleCounter = 0; - this->startCycle = controlsettings.trigger.position * 1000 / cycleTime + 1; + this->startCycle = int(controlsettings.trigger.position * 1000.0 / cycleTime + 1.0); this->lastTriggerMode = controlsettings.trigger.mode; break; diff --git a/openhantek/src/hantekdso/hantekdsocontrol.h b/openhantek/src/hantekdso/hantekdsocontrol.h index bb325c9f..4440c08d 100644 --- a/openhantek/src/hantekdso/hantekdsocontrol.h +++ b/openhantek/src/hantekdso/hantekdsocontrol.h @@ -3,8 +3,6 @@ #pragma once #include "errorcodes.h" -#include "bulkStructs.h" -#include "controlStructs.h" #include "dsosamples.h" #include "states.h" #include "controlspecification.h" @@ -88,7 +86,7 @@ class HantekDsoControl : public QObject { private: bool isRollMode() const; bool isFastRate() const; - int getRecordLength() const; + unsigned getRecordLength() const; Dso::ErrorCode retrieveChannelLevelData(); diff --git a/openhantek/src/hantekdso/models/modelDSO2090.cpp b/openhantek/src/hantekdso/models/modelDSO2090.cpp index d07afd17..06ad039f 100644 --- a/openhantek/src/hantekdso/models/modelDSO2090.cpp +++ b/openhantek/src/hantekdso/models/modelDSO2090.cpp @@ -1,4 +1,6 @@ #include "modelDSO2090.h" +#include "hantekprotocol/bulkStructs.h" +#include "hantekdsocontrol.h" using namespace Hantek; diff --git a/openhantek/src/hantekdso/models/modelDSO2090.h b/openhantek/src/hantekdso/models/modelDSO2090.h index fda2ad28..0d153df3 100644 --- a/openhantek/src/hantekdso/models/modelDSO2090.h +++ b/openhantek/src/hantekdso/models/modelDSO2090.h @@ -1,9 +1,8 @@ #pragma once #include "dsomodel.h" -#include "hantekdsocontrol.h" -#include "bulkStructs.h" +class HantekDsoControl; using namespace Hantek; struct ModelDSO2090 : public DSOModel { diff --git a/openhantek/src/hantekdso/models/modelDSO2150.cpp b/openhantek/src/hantekdso/models/modelDSO2150.cpp index 8065d7ef..ed0475e6 100644 --- a/openhantek/src/hantekdso/models/modelDSO2150.cpp +++ b/openhantek/src/hantekdso/models/modelDSO2150.cpp @@ -1,4 +1,6 @@ #include "modelDSO2150.h" +#include "hantekprotocol/bulkStructs.h" +#include "hantekdsocontrol.h" using namespace Hantek; diff --git a/openhantek/src/hantekdso/models/modelDSO2150.h b/openhantek/src/hantekdso/models/modelDSO2150.h index 4aed2bd1..d4ff4c8c 100644 --- a/openhantek/src/hantekdso/models/modelDSO2150.h +++ b/openhantek/src/hantekdso/models/modelDSO2150.h @@ -1,9 +1,8 @@ #pragma once #include "dsomodel.h" -#include "hantekdsocontrol.h" -#include "bulkStructs.h" +class HantekDsoControl; using namespace Hantek; struct ModelDSO2150 : public DSOModel { diff --git a/openhantek/src/hantekdso/models/modelDSO2250.cpp b/openhantek/src/hantekdso/models/modelDSO2250.cpp index 50f6d81a..5efd2442 100644 --- a/openhantek/src/hantekdso/models/modelDSO2250.cpp +++ b/openhantek/src/hantekdso/models/modelDSO2250.cpp @@ -1,4 +1,6 @@ #include "modelDSO2250.h" +#include "hantekprotocol/bulkStructs.h" +#include "hantekdsocontrol.h" using namespace Hantek; diff --git a/openhantek/src/hantekdso/models/modelDSO2250.h b/openhantek/src/hantekdso/models/modelDSO2250.h index b23c65dd..aa81b294 100644 --- a/openhantek/src/hantekdso/models/modelDSO2250.h +++ b/openhantek/src/hantekdso/models/modelDSO2250.h @@ -1,9 +1,8 @@ #pragma once #include "dsomodel.h" -#include "hantekdsocontrol.h" -#include "bulkStructs.h" +class HantekDsoControl; using namespace Hantek; struct ModelDSO2250 : public DSOModel { diff --git a/openhantek/src/hantekdso/models/modelDSO5200.cpp b/openhantek/src/hantekdso/models/modelDSO5200.cpp index 1a00e155..7b52786f 100644 --- a/openhantek/src/hantekdso/models/modelDSO5200.cpp +++ b/openhantek/src/hantekdso/models/modelDSO5200.cpp @@ -1,4 +1,6 @@ #include "modelDSO5200.h" +#include "hantekprotocol/bulkStructs.h" +#include "hantekdsocontrol.h" using namespace Hantek; diff --git a/openhantek/src/hantekdso/models/modelDSO5200.h b/openhantek/src/hantekdso/models/modelDSO5200.h index e50e5c00..3f64c125 100644 --- a/openhantek/src/hantekdso/models/modelDSO5200.h +++ b/openhantek/src/hantekdso/models/modelDSO5200.h @@ -1,9 +1,8 @@ #pragma once #include "dsomodel.h" -#include "hantekdsocontrol.h" -#include "bulkStructs.h" +class HantekDsoControl; using namespace Hantek; struct ModelDSO5200 : public DSOModel { diff --git a/openhantek/src/hantekdso/models/modelDSO6022.cpp b/openhantek/src/hantekdso/models/modelDSO6022.cpp index db2feabb..858e7497 100644 --- a/openhantek/src/hantekdso/models/modelDSO6022.cpp +++ b/openhantek/src/hantekdso/models/modelDSO6022.cpp @@ -1,4 +1,8 @@ #include "modelDSO6022.h" +#include "usb/usbdevice.h" +#include "hantekprotocol/controlStructs.h" +#include "controlindexes.h" +#include "hantekdsocontrol.h" using namespace Hantek; diff --git a/openhantek/src/hantekdso/models/modelDSO6022.h b/openhantek/src/hantekdso/models/modelDSO6022.h index eb977f41..aeea216b 100644 --- a/openhantek/src/hantekdso/models/modelDSO6022.h +++ b/openhantek/src/hantekdso/models/modelDSO6022.h @@ -1,10 +1,8 @@ #pragma once #include "dsomodel.h" -#include "hantekdsocontrol.h" -#include "usb/usbdevice.h" -#include "controlindexes.h" +class HantekDsoControl; using namespace Hantek; struct ModelDSO6022BE : public DSOModel { diff --git a/openhantek/src/hantekprotocol/controlcode.h b/openhantek/src/hantekprotocol/controlcode.h index 423fe7e4..fa269100 100644 --- a/openhantek/src/hantekprotocol/controlcode.h +++ b/openhantek/src/hantekprotocol/controlcode.h @@ -6,7 +6,7 @@ /// \brief All supported control commands. enum ControlCode { /// [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, ::MODEL_DSO5200, - /// ::MODEL_DSO5200A] + /// ::MODEL_DSO5200A, MODEL_DSO6022] ///

/// The 0xa2 control read/write command gives access to a ::ControlValue. ///

@@ -14,7 +14,7 @@ enum ControlCode { CONTROL_VALUE = 0xa2, /// [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, ::MODEL_DSO5200, - /// ::MODEL_DSO5200A] + /// ::MODEL_DSO5200A, MODEL_DSO6022] ///

/// The 0xb2 control read command gets the speed level of the USB /// connection: @@ -132,9 +132,13 @@ enum ControlCode { ///


CONTROL_SETRELAYS = 0xb5, + /// CH1 voltage div setting (6022BE/BL) CONTROL_SETVOLTDIV_CH1 = 0xe0, + /// CH2 voltage div setting (6022BE/BL) CONTROL_SETVOLTDIV_CH2 = 0xe1, + /// Time divisor setting (6022BE/BL) CONTROL_SETTIMEDIV = 0xe2, + /// Request sample data (6022BE/BL) CONTROL_ACQUIIRE_HARD_DATA = 0xe3 }; diff --git a/openhantek/src/scopesettings.h b/openhantek/src/scopesettings.h index 531fce54..3e519b6c 100644 --- a/openhantek/src/scopesettings.h +++ b/openhantek/src/scopesettings.h @@ -1,6 +1,5 @@ #pragma once -#include "definitions.h" #include #include "analyse/enums.h" #include "hantekdso/enums.h" diff --git a/openhantek/src/settings.cpp b/openhantek/src/settings.cpp index 5b79618d..21c8c810 100644 --- a/openhantek/src/settings.cpp +++ b/openhantek/src/settings.cpp @@ -28,7 +28,6 @@ #include "settings.h" -#include "definitions.h" #include "dsowidget.h" /// \brief Set the number of channels. diff --git a/openhantek/src/usb/finddevices.h b/openhantek/src/usb/finddevices.h index 75896dfc..e0799f3d 100644 --- a/openhantek/src/usb/finddevices.h +++ b/openhantek/src/usb/finddevices.h @@ -7,7 +7,6 @@ #include #include -#include "definitions.h" #include "usbdevice.h" struct libusb_context; diff --git a/openhantek/src/usb/usbdevice.cpp b/openhantek/src/usb/usbdevice.cpp index 74c18c58..f1cf9824 100644 --- a/openhantek/src/usb/usbdevice.cpp +++ b/openhantek/src/usb/usbdevice.cpp @@ -7,7 +7,6 @@ #include "usbdevice.h" #include "controlgetspeed.h" -#include "controlcode.h" #include "models.h" #include "utils/printutils.h" @@ -280,7 +279,7 @@ int USBDevice::getConnectionSpeed() { } /// \brief Gets the maximum size of one packet transmitted via bulk transfer. -/// \return The maximum packet size in bytes, -1 on error. +/// \return The maximum packet size in bytes, negative libusb error code on error. int USBDevice::getPacketSize() { const int s = this->getConnectionSpeed(); if (s == CONNECTION_FULLSPEED) @@ -290,8 +289,8 @@ int USBDevice::getPacketSize() { else if (s > CONNECTION_HIGHSPEED) { std::cerr << "Unknown USB speed. Please correct source code in USBDevice::getPacketSize()" << std::endl; throw new std::runtime_error("Unknown USB speed"); - } - return -1; + } else if (s<0) return s; + return 0; } libusb_device *USBDevice::getRawDevice() const { return device; } diff --git a/openhantek/src/usb/usbdevice.h b/openhantek/src/usb/usbdevice.h index f8b742de..6e452cba 100644 --- a/openhantek/src/usb/usbdevice.h +++ b/openhantek/src/usb/usbdevice.h @@ -9,7 +9,6 @@ #include "usbdevicedefinitions.h" #include "controlbegin.h" -#include "definitions.h" #include "utils/dataarray.h" class DSOModel; diff --git a/openhantek/src/utils/dsoStrings.h b/openhantek/src/utils/dsoStrings.h index 2bb42c7c..f69e6041 100644 --- a/openhantek/src/utils/dsoStrings.h +++ b/openhantek/src/utils/dsoStrings.h @@ -4,7 +4,6 @@ #include #include "analyse/enums.h" #include "hantekdso/enums.h" -#include "definitions.h" #define MARKER_COUNT 2 ///< Number of markers diff --git a/openhantek/src/utils/printutils.h b/openhantek/src/utils/printutils.h index ee78d067..20861321 100644 --- a/openhantek/src/utils/printutils.h +++ b/openhantek/src/utils/printutils.h @@ -48,7 +48,7 @@ unsigned int hexParse(const QString dump, unsigned char *data, unsigned int leng /// \brief Print debug information with timestamp. /// \param text Text that will be output via qDebug. #ifdef DEBUG -inline void timestampDebug(QString text) { +inline void timestampDebug(const QString& text) { qDebug("%s: %s", QTime::currentTime().toString("hh:mm:ss.zzz").toLatin1().constData(), text.toLatin1().constData()); } #else diff --git a/openhantek/src/viewconstants.h b/openhantek/src/viewconstants.h index 5b8e24df..973ec744 100644 --- a/openhantek/src/viewconstants.h +++ b/openhantek/src/viewconstants.h @@ -1,5 +1,5 @@ #pragma once -#define DIVS_TIME 10.0 ///< Number of horizontal screen divs -#define DIVS_VOLTAGE 8.0 ///< Number of vertical screen divs +#define DIVS_TIME 10.0f ///< Number of horizontal screen divs +#define DIVS_VOLTAGE 8.0f ///< Number of vertical screen divs #define DIVS_SUB 5 ///< Number of sub-divisions per div diff --git a/openhantek/src/viewsettings.h b/openhantek/src/viewsettings.h index 140bbfda..1a66d144 100644 --- a/openhantek/src/viewsettings.h +++ b/openhantek/src/viewsettings.h @@ -1,6 +1,5 @@ #pragma once -#include "definitions.h" #include #include #include @@ -43,7 +42,7 @@ struct DsoSettingsView { std::vector()}; bool antialiasing = true; ///< Antialiasing for the graphs bool digitalPhosphor = false; ///< true slowly fades out the previous graphs - int digitalPhosphorDepth = 8; ///< Number of channels shown at one time + unsigned digitalPhosphorDepth = 8; ///< Number of channels shown at one time Dso::InterpolationMode interpolation = Dso::INTERPOLATION_LINEAR; ///< Interpolation mode for the graph bool screenColorImages = false; ///< true exports images with screen colors bool zoom = false; ///< true if the magnified scope is enabled