Skip to content

Commit 85aa946

Browse files
author
David Graeff
committed
Move emitted signals from hantekdsocontrol constructor into startSampling to fix available record length and other missed signals. clang-format everything.
1 parent 2c49e9e commit 85aa946

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+5648
-7098
lines changed

.clang-format

-95
This file was deleted.

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ insert_final_newline = true
1010

1111
# Tab indentation (no size specified)
1212
[*.cpp,*.h]
13-
indent_style = tab
13+
indent_style = space

CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ endif()
3232

3333
# Add auxiliary files to the project, so that these files appear in VisualStudio/QtCreator
3434
add_custom_target(readme SOURCES readme.md)
35-
add_custom_target(format SOURCES ".clang-format"
36-
COMMAND "clang-format" "-style=.clang-format" "-i" "-sort-includes" ${SRC} ${HEADERS})
3735

3836
# Add "cppcheck" command
3937
add_custom_target(cppcheck COMMAND "cppcheck --enable=all -I \"${CMAKE_CURRENT_LIST_DIR}/openhantek/src\" -q ${SRC} --template=\"{file}:{line}: {severity}: {message}\"")

openhantek/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ file(GLOB_RECURSE SRC "src/*.cpp")
1717
file(GLOB_RECURSE HEADERS "src/*.h")
1818
file(GLOB_RECURSE QRC "res/*.qrc")
1919

20+
add_custom_target(format SOURCES ".clang-format"
21+
COMMAND "clang-format" "-style=file" "-i" "-sort-includes" ${SRC} ${HEADERS})
22+
2023
add_subdirectory(translations)
2124
add_subdirectory(res)
2225

openhantek/src/analyse/dataanalyzer.cpp

+101-173
Large diffs are not rendered by default.

openhantek/src/analyse/dataanalyzer.h

+19-19
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
#include <vector>
66

7-
#include <QThread>
87
#include <QMutex>
8+
#include <QThread>
99
#include <memory>
1010

11-
#include "definitions.h"
12-
#include "utils/printutils.h"
1311
#include "dataanalyzerresult.h"
12+
#include "definitions.h"
1413
#include "dsosamples.h"
14+
#include "utils/printutils.h"
1515

1616
struct DsoSettingsScope;
1717

@@ -21,28 +21,28 @@ struct DsoSettingsScope;
2121
/// Calculates the spectrum and various data about the signal and saves the
2222
/// time-/frequencysteps between two values.
2323
class DataAnalyzer : public QObject {
24-
Q_OBJECT
24+
Q_OBJECT
2525

26-
public:
27-
void applySettings(DsoSettingsScope* scope);
28-
void setSourceData(const DSOsamples* data);
26+
public:
27+
void applySettings(DsoSettingsScope *scope);
28+
void setSourceData(const DSOsamples *data);
2929
std::unique_ptr<DataAnalyzerResult> getNextResult();
3030
/**
3131
* Call this if the source data changed.
3232
*/
3333
void samplesAvailable();
34-
private:
34+
35+
private:
3536
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;
37+
static void spectrumAnalysis(DataAnalyzerResult *result, Dso::WindowFunction &lastWindow,
38+
unsigned int lastRecordLength, const DsoSettingsScope *scope);
39+
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;
4545
std::unique_ptr<DataAnalyzerResult> lastResult;
46-
signals:
47-
void analyzed();
46+
signals:
47+
void analyzed();
4848
};
+11-22
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,33 @@
11
#include "dataanalyzerresult.h"
22
#include <stdexcept>
33

4-
DataAnalyzerResult::DataAnalyzerResult(unsigned int channelCount)
5-
{
6-
analyzedData.resize(channelCount);
7-
}
4+
DataAnalyzerResult::DataAnalyzerResult(unsigned int channelCount) { analyzedData.resize(channelCount); }
85

96
/// \brief Returns the analyzed data.
107
/// \param channel Channel, whose data should be returned.
118
/// \return Analyzed data as AnalyzedData struct.
129
const DataChannel *DataAnalyzerResult::data(int channel) const {
13-
if (channel >= (int)this->analyzedData.size())
14-
return 0;
10+
if (channel >= (int)this->analyzedData.size()) return 0;
1511

16-
return &this->analyzedData[(size_t)channel];
12+
return &this->analyzedData[(size_t)channel];
1713
}
1814

1915
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!");
16+
if (channel >= (int)this->analyzedData.size())
17+
throw new std::runtime_error("If you modfiy the DataAnalyzerResult, you "
18+
"need to set the channels first!");
2219

23-
return &this->analyzedData[(size_t)channel];
20+
return &this->analyzedData[(size_t)channel];
2421
}
2522

2623
/// \brief Returns the sample count of the analyzed data.
2724
/// \return The maximum sample count of the last analyzed data.
2825
unsigned int DataAnalyzerResult::sampleCount() const { return this->maxSamples; }
2926

30-
unsigned int DataAnalyzerResult::channelCount() const
31-
{
32-
return analyzedData.size();
33-
}
27+
unsigned int DataAnalyzerResult::channelCount() const { return analyzedData.size(); }
3428

35-
void DataAnalyzerResult::challengeMaxSamples(unsigned int newMaxSamples)
36-
{
37-
if (newMaxSamples > this->maxSamples)
38-
this->maxSamples = newMaxSamples;
29+
void DataAnalyzerResult::challengeMaxSamples(unsigned int newMaxSamples) {
30+
if (newMaxSamples > this->maxSamples) this->maxSamples = newMaxSamples;
3931
}
4032

41-
unsigned int DataAnalyzerResult::getMaxSamples() const
42-
{
43-
return maxSamples;
44-
}
33+
unsigned int DataAnalyzerResult::getMaxSamples() const { return maxSamples; }

openhantek/src/analyse/dataanalyzerresult.h

+15-14
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,38 @@
88
/// \struct SampleValues dataanalyzer.h
99
/// \brief Struct for a array of sample values.
1010
struct SampleValues {
11-
std::vector<double> sample; ///< Vector holding the sampling data
12-
double interval=0.0; ///< The interval between two sample values
11+
std::vector<double> sample; ///< Vector holding the sampling data
12+
double interval = 0.0; ///< The interval between two sample values
1313
};
1414

1515
////////////////////////////////////////////////////////////////////////////////
1616
/// \struct AnalyzedData dataanalyzer.h
1717
/// \brief Struct for the analyzed data.
1818
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
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
2323
};
2424

25-
class DataAnalyzerResult
26-
{
27-
public:
25+
class DataAnalyzerResult {
26+
public:
2827
DataAnalyzerResult(unsigned int channelCount);
2928
const DataChannel *data(int channel) const;
3029
DataChannel *modifyData(int channel);
3130
unsigned int sampleCount() const;
3231
unsigned int channelCount() const;
33-
double *window = nullptr; ///< The array for the dft window factors
32+
double *window = nullptr; ///< The array for the dft window factors
3433

3534
/**
36-
* Applies a new maximum samples value, if the given value is higher than the already stored one
35+
* Applies a new maximum samples value, if the given value is higher than the
36+
* already stored one
3737
* @param newMaxSamples Maximum samples value
3838
*/
3939
void challengeMaxSamples(unsigned int newMaxSamples);
4040
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
41+
42+
private:
43+
std::vector<DataChannel> analyzedData; ///< The analyzed data for each channel
44+
unsigned int maxSamples = 0; ///< The maximum record length of the analyzed data
4445
};

openhantek/src/configdialog/DsoConfigAnalysisPage.cpp

+9-17
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,27 @@
22

33
#include "DsoConfigAnalysisPage.h"
44

5-
DsoConfigAnalysisPage::DsoConfigAnalysisPage(DsoSettings *settings,
6-
QWidget *parent)
5+
DsoConfigAnalysisPage::DsoConfigAnalysisPage(DsoSettings *settings, QWidget *parent)
76
: QWidget(parent), settings(settings) {
87
// Initialize lists for comboboxes
98
QStringList windowFunctionStrings;
10-
windowFunctionStrings << tr("Rectangular") << tr("Hamming") << tr("Hann")
11-
<< tr("Cosine") << tr("Lanczos") << tr("Bartlett")
12-
<< tr("Triangular") << tr("Gauss")
13-
<< tr("Bartlett-Hann") << tr("Blackman")
14-
//<< tr("Kaiser")
15-
<< tr("Nuttall") << tr("Blackman-Harris")
16-
<< tr("Blackman-Nuttall") << tr("Flat top");
9+
windowFunctionStrings << tr("Rectangular") << tr("Hamming") << tr("Hann") << tr("Cosine") << tr("Lanczos")
10+
<< tr("Bartlett") << tr("Triangular") << tr("Gauss") << tr("Bartlett-Hann") << tr("Blackman")
11+
//<< tr("Kaiser")
12+
<< tr("Nuttall") << tr("Blackman-Harris") << tr("Blackman-Nuttall") << tr("Flat top");
1713

1814
// Initialize elements
1915
windowFunctionLabel = new QLabel(tr("Window function"));
2016
windowFunctionComboBox = new QComboBox();
2117
windowFunctionComboBox->addItems(windowFunctionStrings);
22-
windowFunctionComboBox->setCurrentIndex(
23-
settings->scope.spectrumWindow);
18+
windowFunctionComboBox->setCurrentIndex(settings->scope.spectrumWindow);
2419

2520
referenceLevelLabel = new QLabel(tr("Reference level"));
2621
referenceLevelSpinBox = new QDoubleSpinBox();
2722
referenceLevelSpinBox->setDecimals(1);
2823
referenceLevelSpinBox->setMinimum(-40.0);
2924
referenceLevelSpinBox->setMaximum(100.0);
30-
referenceLevelSpinBox->setValue(
31-
settings->scope.spectrumReference);
25+
referenceLevelSpinBox->setValue(settings->scope.spectrumReference);
3226
referenceLevelUnitLabel = new QLabel(tr("dBm"));
3327
referenceLevelLayout = new QHBoxLayout();
3428
referenceLevelLayout->addWidget(referenceLevelSpinBox);
@@ -65,9 +59,7 @@ DsoConfigAnalysisPage::DsoConfigAnalysisPage(DsoSettings *settings,
6559

6660
/// \brief Saves the new settings.
6761
void DsoConfigAnalysisPage::saveSettings() {
68-
settings->scope.spectrumWindow =
69-
(Dso::WindowFunction)windowFunctionComboBox->currentIndex();
70-
settings->scope.spectrumReference =
71-
referenceLevelSpinBox->value();
62+
settings->scope.spectrumWindow = (Dso::WindowFunction)windowFunctionComboBox->currentIndex();
63+
settings->scope.spectrumReference = referenceLevelSpinBox->value();
7264
settings->scope.spectrumLimit = minimumMagnitudeSpinBox->value();
7365
}

0 commit comments

Comments
 (0)