Skip to content

Commit

Permalink
Add thread debugging verbosity
Browse files Browse the repository at this point in the history
Signed-off-by: Martin <Ho-Ro@users.noreply.github.com>
  • Loading branch information
Ho-Ro committed Jun 13, 2023
1 parent f24ec34 commit 47712b4
Show file tree
Hide file tree
Showing 18 changed files with 175 additions and 155 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.bak
.o
.so
*.o
*.so
.*~
*~
*.bak
*.orig
*.new
*.old
Expand Down
5 changes: 5 additions & 0 deletions openhantek/src/docks/HorizontalDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <QDockWidget>
#include <QLabel>
#include <QSignalBlocker>
#include <QThread>

#include <cmath>

Expand Down Expand Up @@ -128,6 +129,8 @@ void HorizontalDock::closeEvent( QCloseEvent *event ) {
double HorizontalDock::setSamplerate( double samplerate ) {
if ( scope->verboseLevel > 2 )
qDebug() << " HDock::setSamplerate()" << samplerate;
if ( scope->verboseLevel > 3 )
qDebug() << " ThreadID:" << QThread::currentThreadId();
samplerateRequest = samplerate;
QSignalBlocker blocker( timebaseSiSpinBox );
timebaseSiSpinBox->setMaximum( scope->horizontal.maxTimebase );
Expand Down Expand Up @@ -227,6 +230,8 @@ void HorizontalDock::samplerateSelected( double samplerate ) {
void HorizontalDock::timebaseSelected( double timebase ) {
if ( scope->verboseLevel > 2 )
qDebug() << " HDock::timebaseSelected()" << timebase;
if ( scope->verboseLevel > 3 )
qDebug() << " ThreadID:" << QThread::currentThreadId();
scope->horizontal.timebase = timebase;
calculateSamplerateSteps( timebase );
emit timebaseChanged( timebase );
Expand Down
3 changes: 3 additions & 0 deletions openhantek/src/docks/SpectrumDock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QDockWidget>
#include <QLabel>
#include <QSignalBlocker>
#include <QThread>

#include <cmath>

Expand Down Expand Up @@ -166,6 +167,8 @@ void SpectrumDock::enableSpectrumDock( bool enabled ) { // disable when using XY
void SpectrumDock::setSamplerate( double samplerate ) {
if ( scope->verboseLevel > 2 )
qDebug() << " SDock::setSamplerate()" << samplerate;
if ( scope->verboseLevel > 3 )
qDebug() << " ThreadID:" << QThread::currentThreadId();
double maxFreqBase = samplerate / DIVS_TIME / 2; // Nyquist frequency
frequencybaseSiSpinBox->setMaximum( maxFreqBase );
if ( frequencybaseSiSpinBox->value() > maxFreqBase )
Expand Down
19 changes: 13 additions & 6 deletions openhantek/src/hantekdso/capturing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@
#include <cmath>


Capturing::Capturing( HantekDsoControl *hdc ) : hdc( hdc ) { hdc->capturing = true; }
CapturingThread::CapturingThread( HantekDsoControl *hdc ) : hdc( hdc ) {
if ( hdc->verboseLevel > 1 ) {
qDebug() << " CapturingThread::CapturingThread()";
if ( hdc->verboseLevel > 2 )
qDebug() << " capturingThread ID: " << currentThreadId();
}
hdc->capturing = true;
}


void Capturing::run() {
void CapturingThread::run() {
forever {
if ( !hdc->capturing || QThread::currentThread()->isInterruptionRequested() ) {
hdc->quitSampling(); // stop the scope
Expand Down Expand Up @@ -41,7 +48,7 @@ static double id2sr( uint8_t timediv ) {
}


void Capturing::xferSamples() {
void CapturingThread::xferSamples() {
QWriteLocker locker( &hdc->raw.lock );
if ( !freeRun )
swap( data, hdc->raw.data );
Expand All @@ -58,7 +65,7 @@ void Capturing::xferSamples() {
}


void Capturing::capture() {
void CapturingThread::capture() {
if ( !hdc->samplingStarted )
return;
int errorCode;
Expand Down Expand Up @@ -165,7 +172,7 @@ void Capturing::capture() {
}


unsigned Capturing::getRealSamples() {
unsigned CapturingThread::getRealSamples() {
int errorCode;
errorCode = hdc->scopeDevice->controlWrite( hdc->getCommand( ControlCode::CONTROL_STARTSAMPLING ) );
if ( errorCode < 0 ) {
Expand All @@ -189,7 +196,7 @@ unsigned Capturing::getRealSamples() {
}


unsigned Capturing::getDemoSamples() {
unsigned CapturingThread::getDemoSamples() {
const uint8_t binaryOffset = 0x80; // ADC format: binary offset
const int8_t V_zero = 0; // ADC = 0V
const int8_t V_plus_1 = 25; // ADC = 1V
Expand Down
4 changes: 2 additions & 2 deletions openhantek/src/hantekdso/capturing.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

#include "hantekdsocontrol.h"

class Capturing : public QThread {
class CapturingThread : public QThread {
Q_OBJECT

public:
Capturing( HantekDsoControl *hdc );
CapturingThread( HantekDsoControl *hdc );
void quitCapturing() { hdc->capturing = false; }

private:
Expand Down
5 changes: 4 additions & 1 deletion openhantek/src/hantekdso/hantekdsocontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ HantekDsoControl::HantekDsoControl( ScopeDevice *device, const DSOModel *model,

if ( verboseLevel > 1 )
qDebug() << " HantekDsoControl::HantekDsoControl()";

qRegisterMetaType< DSOsamples * >();
qRegisterMetaType< QList< double > >();

Expand Down Expand Up @@ -95,6 +94,8 @@ void HantekDsoControl::controlSetSamplerate( uint8_t sampleIndex ) {
uint8_t id = specification->fixedSampleRates[ sampleIndex ].id;
if ( verboseLevel > 2 )
qDebug() << " HDC::controlSetSamplerate()" << sampleIndex << "id:" << id;
if ( verboseLevel > 3 )
qDebug() << " ThreadID:" << QThread::currentThreadId();
modifyCommand< ControlSetSamplerate >( ControlCode::CONTROL_SETSAMPLERATE )->setSamplerate( id, sampleIndex );
if ( sampleIndex != lastIndex ) { // samplerate has changed, start new sampling
restartSampling();
Expand Down Expand Up @@ -134,6 +135,8 @@ Dso::ErrorCode HantekDsoControl::setSamplerate( double samplerate ) {
Dso::ErrorCode HantekDsoControl::setRecordTime( double duration ) {
if ( verboseLevel > 2 )
qDebug() << " HDC::setRecordTime()" << duration;
if ( verboseLevel > 3 )
qDebug() << " ThreadID:" << QThread::currentThreadId();
if ( deviceNotConnected() )
return Dso::ErrorCode::CONNECTION;

Expand Down
4 changes: 2 additions & 2 deletions openhantek/src/hantekdso/hantekdsocontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <QSettings>
#include <QThread>

class Capturing;
class CapturingThread;
class ScopeDevice;

struct Raw {
Expand All @@ -54,7 +54,7 @@ struct Raw {
/// TODO Please anyone, refactor this class into smaller pieces (Separation of Concerns!).
class HantekDsoControl : public QObject {
Q_OBJECT
friend Capturing;
friend CapturingThread;

public:
/**
Expand Down
12 changes: 7 additions & 5 deletions openhantek/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ int main( int argc, char *argv[] ) {
qDebug() << startupTime.elapsed() << "ms:"
<< "use device" << scopeDevice->getModel()->name << "serial number" << scopeDevice->getSerialNumber();

if ( verboseLevel > 2 )
qDebug() << " main thread ID: " << QThread::currentThreadId();

//////// Create DSO control object and move it to a separate thread ////////
if ( verboseLevel )
qDebug() << startupTime.elapsed() << "ms:"
Expand All @@ -383,7 +386,6 @@ int main( int argc, char *argv[] ) {
dsoControl.moveToThread( &dsoControlThread );
QObject::connect( &dsoControlThread, &QThread::started, &dsoControl, &HantekDsoControl::stateMachine );
QObject::connect( &dsoControl, &HantekDsoControl::communicationError, QCoreApplication::instance(), &QCoreApplication::quit );

if ( scopeDevice )
QObject::connect( scopeDevice.get(), &ScopeDevice::deviceDisconnected, QCoreApplication::instance(),
&QCoreApplication::quit );
Expand Down Expand Up @@ -510,8 +512,8 @@ int main( int argc, char *argv[] ) {
dsoControl.enableSamplingUI();
postProcessingThread.start();
dsoControlThread.start();
Capturing capturing( &dsoControl );
capturing.start();
CapturingThread capturingThread( &dsoControl ); // low level capture in separate thread
capturingThread.start();

if ( verboseLevel )
qDebug() << startupTime.elapsed() << "ms:"
Expand All @@ -536,8 +538,8 @@ int main( int argc, char *argv[] ) {
// wait 2 * record time (delay is ms) for dso to finish
unsigned waitForDso = unsigned( 2000 * dsoControl.getSamplesize() / dsoControl.getSamplerate() );
waitForDso = qMax( waitForDso, 10000U ); // wait for at least 10 s
capturing.requestInterruption();
capturing.wait( waitForDso );
capturingThread.requestInterruption();
capturingThread.wait( waitForDso );
if ( verboseLevel < 2 )
std::cerr << "has "; // 2nd part

Expand Down
2 changes: 1 addition & 1 deletion openhantek/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ MainWindow::MainWindow( HantekDsoControl *dsoControl, DsoSettings *settings, Exp
restoreState( dsoSettings->mainWindowState );

// Central oszilloscope widget
dsoWidget = new DsoWidget( &dsoSettings->scope, &dsoSettings->view, spec );
dsoWidget = new DsoWidget( &dsoSettings->scope, &dsoSettings->view, spec, this );
setCentralWidget( dsoWidget );

if ( dsoControl->getDevice()->isRealHW() ) { // enable online calibration and manual command input
Expand Down
30 changes: 15 additions & 15 deletions openhantek/translations/openhantek_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,45 +941,45 @@
<translation type="vanished">Konnte Kanalpegeldaten des Oszilloskops nicht lesen</translation>
</message>
<message>
<location filename="../src/hantekdso/hantekdsocontrol.cpp" line="569"/>
<location filename="../src/hantekdso/hantekdsocontrol.cpp" line="572"/>
<source>Couldn&apos;t get calibration data from oscilloscope&apos;s EEPROM. Use a config file for calibration!</source>
<translation>Konnte Kalibrierdaten des Oszilloskops nicht lesen, benutze eine config-Datei für die Kalibrierung!</translation>
</message>
</context>
<context>
<name>HorizontalDock</name>
<message>
<location filename="../src/docks/HorizontalDock.cpp" line="30"/>
<location filename="../src/docks/HorizontalDock.cpp" line="31"/>
<source>Horizontal</source>
<translation>Horizontal</translation>
</message>
<message>
<location filename="../src/docks/HorizontalDock.cpp" line="36"/>
<location filename="../src/docks/HorizontalDock.cpp" line="37"/>
<source>Samplerate</source>
<translation>Samplerate</translation>
</message>
<message>
<location filename="../src/docks/HorizontalDock.cpp" line="39"/>
<location filename="../src/docks/HorizontalDock.cpp" line="40"/>
<source>Effective samplerate, automatically selected from &apos;Timebase&apos; setting</source>
<translation>Wirksame Abtastrate, automatisch beim Einstellen der &apos;Zeitbasis&apos; ausgewählt</translation>
</message>
<message>
<location filename="../src/docks/HorizontalDock.cpp" line="42"/>
<location filename="../src/docks/HorizontalDock.cpp" line="43"/>
<source>/s</source>
<translation>/s</translation>
</message>
<message>
<location filename="../src/docks/HorizontalDock.cpp" line="46"/>
<location filename="../src/docks/HorizontalDock.cpp" line="47"/>
<source>Timebase</source>
<translation>Zeitbasis</translation>
</message>
<message>
<location filename="../src/docks/HorizontalDock.cpp" line="49"/>
<location filename="../src/docks/HorizontalDock.cpp" line="50"/>
<source>Time per horizontal screen division</source>
<translation>Zeit pro horizontaler Teilung</translation>
</message>
<message>
<location filename="../src/docks/HorizontalDock.cpp" line="66"/>
<location filename="../src/docks/HorizontalDock.cpp" line="67"/>
<source>Select the frequency of the calibration output, scroll for fast change</source>
<translation>Setze die Frequenz des Kalibriersignals, schnelle Auswahl mit dem Mausrad</translation>
</message>
Expand All @@ -988,17 +988,17 @@
<translation type="vanished">Frequenzbasis</translation>
</message>
<message>
<location filename="../src/docks/HorizontalDock.cpp" line="54"/>
<location filename="../src/docks/HorizontalDock.cpp" line="55"/>
<source>Format</source>
<translation>Format</translation>
</message>
<message>
<location filename="../src/docks/HorizontalDock.cpp" line="57"/>
<location filename="../src/docks/HorizontalDock.cpp" line="58"/>
<source>Select signal over time or XY display</source>
<translation>Wähle Signal über Zeit oder XY-Anzeige</translation>
</message>
<message>
<location filename="../src/docks/HorizontalDock.cpp" line="61"/>
<location filename="../src/docks/HorizontalDock.cpp" line="62"/>
<source>Calibration out</source>
<translation>Kalibriersignal</translation>
</message>
Expand Down Expand Up @@ -2543,22 +2543,22 @@
<context>
<name>SpectrumDock</name>
<message>
<location filename="../src/docks/SpectrumDock.cpp" line="28"/>
<location filename="../src/docks/SpectrumDock.cpp" line="29"/>
<source>Spectrum</source>
<translation>Spektrum</translation>
</message>
<message>
<location filename="../src/docks/SpectrumDock.cpp" line="49"/>
<location filename="../src/docks/SpectrumDock.cpp" line="50"/>
<source>Magnitude per vertical screen division</source>
<translation>Magnitude pro vertikaler Teilung</translation>
</message>
<message>
<location filename="../src/docks/SpectrumDock.cpp" line="75"/>
<location filename="../src/docks/SpectrumDock.cpp" line="76"/>
<source>Frequencybase</source>
<translation>Frequenzbasis</translation>
</message>
<message>
<location filename="../src/docks/SpectrumDock.cpp" line="78"/>
<location filename="../src/docks/SpectrumDock.cpp" line="79"/>
<source>Frequency range per horizontal screen division</source>
<translation>Frequenzbereich pro horizontaler Teilung</translation>
</message>
Expand Down
Loading

0 comments on commit 47712b4

Please sign in to comment.