Skip to content

Commit 812e83f

Browse files
author
David Graeff
committed
Finish refactoring of data flow from USBDevice->HantekDSOControl->DataAnalyser->DSOWidget->GLGenerator. Less thread locks, no deadlocks by design
1 parent 7611820 commit 812e83f

20 files changed

+2084
-2353
lines changed

openhantek/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ set(CMAKE_AUTORCC ON)
1010

1111
# include directories
1212
set(CMAKE_INCLUDE_CURRENT_DIR ON)
13-
include_directories(src/ src/dso src/hantek)
13+
include_directories(src/ src/hantek src/analyse src/widgets src/docks src/configdialog)
1414

1515
# collect sources and other files
1616
file(GLOB_RECURSE SRC "src/*.cpp")

openhantek/src/analyse/dataanalyzer.cpp

+426
Large diffs are not rendered by default.

openhantek/src/analyse/dataanalyzer.h

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
3+
#pragma once
4+
5+
#include <vector>
6+
7+
#include <QThread>
8+
#include <QMutex>
9+
#include <memory>
10+
11+
#include "definitions.h"
12+
#include "utils/printutils.h"
13+
#include "dataanalyzerresult.h"
14+
#include "dsosamples.h"
15+
16+
struct DsoSettingsScope;
17+
18+
////////////////////////////////////////////////////////////////////////////////
19+
/// \class DataAnalyzer dataanalyzer.h
20+
/// \brief Analyzes the data from the dso.
21+
/// Calculates the spectrum and various data about the signal and saves the
22+
/// time-/frequencysteps between two values.
23+
class DataAnalyzer : public QObject {
24+
Q_OBJECT
25+
26+
public:
27+
void applySettings(DsoSettingsScope* scope);
28+
void setSourceData(const DSOsamples* data);
29+
std::unique_ptr<DataAnalyzerResult> getNextResult();
30+
/**
31+
* Call this if the source data changed.
32+
*/
33+
void samplesAvailable();
34+
private:
35+
static std::unique_ptr<DataAnalyzerResult> convertData(const DSOsamples *data, const DsoSettingsScope *scope);
36+
static void spectrumAnalysis(DataAnalyzerResult* result,
37+
Dso::WindowFunction &lastWindow,
38+
unsigned int lastRecordLength,
39+
const DsoSettingsScope* scope);
40+
private:
41+
DsoSettingsScope* scope;
42+
unsigned int lastRecordLength=0; ///< The record length of the previously analyzed data
43+
Dso::WindowFunction lastWindow=(Dso::WindowFunction)-1; ///< The previously used dft window function
44+
const DSOsamples *sourceData=nullptr;
45+
std::unique_ptr<DataAnalyzerResult> lastResult;
46+
signals:
47+
void analyzed();
48+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "dataanalyzerresult.h"
2+
#include <stdexcept>
3+
4+
DataAnalyzerResult::DataAnalyzerResult(unsigned int channelCount)
5+
{
6+
analyzedData.resize(channelCount);
7+
}
8+
9+
/// \brief Returns the analyzed data.
10+
/// \param channel Channel, whose data should be returned.
11+
/// \return Analyzed data as AnalyzedData struct.
12+
const DataChannel *DataAnalyzerResult::data(int channel) const {
13+
if (channel >= (int)this->analyzedData.size())
14+
return 0;
15+
16+
return &this->analyzedData[(size_t)channel];
17+
}
18+
19+
DataChannel *DataAnalyzerResult::modifyData(int channel) {
20+
if (channel >= (int)this->analyzedData.size())
21+
throw new std::runtime_error("If you modfiy the DataAnalyzerResult, you need to set the channels first!");
22+
23+
return &this->analyzedData[(size_t)channel];
24+
}
25+
26+
/// \brief Returns the sample count of the analyzed data.
27+
/// \return The maximum sample count of the last analyzed data.
28+
unsigned int DataAnalyzerResult::sampleCount() const { return this->maxSamples; }
29+
30+
unsigned int DataAnalyzerResult::channelCount() const
31+
{
32+
return analyzedData.size();
33+
}
34+
35+
void DataAnalyzerResult::challengeMaxSamples(unsigned int newMaxSamples)
36+
{
37+
if (newMaxSamples > this->maxSamples)
38+
this->maxSamples = newMaxSamples;
39+
}
40+
41+
unsigned int DataAnalyzerResult::getMaxSamples() const
42+
{
43+
return maxSamples;
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
3+
#pragma once
4+
5+
#include <vector>
6+
7+
////////////////////////////////////////////////////////////////////////////////
8+
/// \struct SampleValues dataanalyzer.h
9+
/// \brief Struct for a array of sample values.
10+
struct SampleValues {
11+
std::vector<double> sample; ///< Vector holding the sampling data
12+
double interval=0.0; ///< The interval between two sample values
13+
};
14+
15+
////////////////////////////////////////////////////////////////////////////////
16+
/// \struct AnalyzedData dataanalyzer.h
17+
/// \brief Struct for the analyzed data.
18+
struct DataChannel {
19+
SampleValues voltage; ///< The time-domain voltage levels (V)
20+
SampleValues spectrum; ///< The frequency-domain power levels (dB)
21+
double amplitude = 0.0; ///< The amplitude of the signal
22+
double frequency = 0.0; ///< The frequency of the signal
23+
};
24+
25+
class DataAnalyzerResult
26+
{
27+
public:
28+
DataAnalyzerResult(unsigned int channelCount);
29+
const DataChannel *data(int channel) const;
30+
DataChannel *modifyData(int channel);
31+
unsigned int sampleCount() const;
32+
unsigned int channelCount() const;
33+
double *window = nullptr; ///< The array for the dft window factors
34+
35+
/**
36+
* Applies a new maximum samples value, if the given value is higher than the already stored one
37+
* @param newMaxSamples Maximum samples value
38+
*/
39+
void challengeMaxSamples(unsigned int newMaxSamples);
40+
unsigned int getMaxSamples() const;
41+
private:
42+
std::vector<DataChannel> analyzedData; ///< The analyzed data for each channel
43+
unsigned int maxSamples = 0; ///< The maximum record length of the analyzed data
44+
};

0 commit comments

Comments
 (0)