OpenHantek
Loading...
Searching...
No Matches
HantekDsoControl Class Reference

The DsoControl abstraction layer for Hantek USB DSOs. TODO Please anyone, refactor this class into smaller pieces (Separation of Concerns!). More...

#include <hantekdsocontrol.h>

Inheritance diagram for HantekDsoControl:

Public Slots

void enableSamplingUI (bool enabled=true)
 If sampling is disabled, no samplesAvailable() signals are send anymore, no samples are fetched from the device and no processing takes place.
Dso::ErrorCode setSamplerate (double samplerate=0.0)
 Sets the samplerate of the oscilloscope.
Dso::ErrorCode setRecordTime (double duration=0.0)
 Sets the time duration of one acquisition by adapting the samplerate.
Dso::ErrorCode setChannelUsed (ChannelID channel, bool used)
 Enables/disables filtering of the given channel.
Dso::ErrorCode setChannelInverted (ChannelID channel, bool inverted)
 Enables/disables inverting of the given channel.
Dso::ErrorCode setProbe (ChannelID channel, double probeAttn)
 Sets the gain for the given channel. Get the actual gain by specification.gainSteps[gainId].
Dso::ErrorCode setGain (ChannelID channel, double gain)
 Sets the probe gain for the given channel.
Dso::ErrorCode setCoupling (ChannelID channel, Dso::Coupling coupling)
 Sets the coupling for the given channel.
Dso::ErrorCode setTriggerMode (Dso::TriggerMode mode)
 Set the trigger mode.
Dso::ErrorCode setTriggerSource (int channel)
 Set the trigger source.
Dso::ErrorCode setTriggerSmooth (int smooth)
 Set the trigger smoothing.
Dso::ErrorCode setTriggerLevel (ChannelID channel, double level)
 Set the trigger level.
Dso::ErrorCode setTriggerSlope (Dso::Slope slope)
 Set the trigger slope.
Dso::ErrorCode setTriggerPosition (double position)
 Set the trigger position.
Dso::ErrorCode setCalFreq (double calfreq=0.0)
 Sets the calibration frequency of the oscilloscope.
void applySettings (DsoSettingsScope *scope)
 Initializes the device with the current settings.
void restartSampling ()
 Starts a new sampling block.
void calibrateOffset (bool enable)
 enable/disable offset calibration

Signals

void showSamplingStatus (bool enabled)
 The oscilloscope started/stopped sampling/waiting for trigger.
void statusMessage (const QString &message, int timeout)
 Status message about the oscilloscope.
void samplesAvailable (const DSOsamples *samples)
 New sample data is available.
void samplerateLimitsChanged (double minimum, double maximum)
 The available samplerate range has changed.
void samplerateSet (int mode, QList< double > sampleSteps)
 The available samplerate for fixed samplerate devices has changed.
void samplerateCalculated (double samplerate, unsigned oversampling)
 The samplerate was newly calculated.
void communicationError () const
void liveCalibrationError () const

Public Member Functions

 HantekDsoControl (ScopeDevice *scopeDevice, const DSOModel *model, int verboseLevel)
 ~HantekDsoControl () override
 Cleans up.
void stateMachine ()
 State machine for the device communication.
void stopStateMachine ()
double getSamplerate () const
unsigned getSamplesize () const
bool isSamplingUI () const
const ScopeDevicegetDevice () const
 Return the associated usb device.
const DSOModelgetModel () const
 Return the associated scope model.
Dso::ErrorCode stringCommand (const QString &commandString)
 Sends control commands directly.
void addCommand (ControlCommand *newCommand, bool pending=true)
template<class T>
T * modifyCommand (Hantek::ControlCode code)
bool hasCommand (Hantek::ControlCode code)
const ControlCommandgetCommand (Hantek::ControlCode code) const
void quitSampling ()
 Stops the device.
void prepareForShutdown ()
 Saves calibration settings e.g. to the scope's EEPROM.

Private Member Functions

void setSingleChannel (bool single)
bool isSingleChannel () const
bool triggerModeNONE ()
unsigned getRecordLength () const
void setDownsampling (unsigned downsampling)
Dso::ErrorCode getCalibrationFromIniFile ()
Dso::ErrorCode getCalibrationFromEEPROM ()
Dso::ErrorCode updateCalibrationValues (bool useEEPROM=false)
Dso::ErrorCode writeCalibrationToEEPROM ()
unsigned getSampleCount () const
unsigned grossSampleCount (unsigned net) const
 adjust for skipping of minimal 2048 leading samples
unsigned netSampleCount (unsigned gross) const
 calculate backwards to get multiples of 1000 (typical 20000 or 10000)
void updateInterval ()
 Updates the interval of the periodic thread timer.
void convertRawDataToSamples ()
 Converts raw oscilloscope data to sample data.
void restoreTargets ()
 Restore the samplerate/timebase targets after divider updates.
void updateSamplerateLimits ()
 Update the minimum and maximum supported samplerate.
void controlSetSamplerate (uint8_t sampleIndex)
bool deviceNotConnected ()
 USB status, always false for demo device.
void requestRefresh (bool active=true)
bool refreshNeeded ()

Private Attributes

friend CapturingThread
std::unique_ptr< MathChannelmathChannel
std::unique_ptr< Triggeringtriggering
bool singleChannel = false
int verboseLevel = 0
bool replaceCalibrationEEPROM = false
ControlCommandcontrol [255] = { nullptr }
 Pointers to control commands.
ControlCommandfirstControlCommand = nullptr
ScopeDevicescopeDevice
 The USB device for the oscilloscope.
bool samplingUI = false
 true, if the oscilloscope is taking samples
const DSOModelmodel
 The attached scope model.
const Dso::ControlSpecificationspecification
 The specifications of the device.
Dso::ControlSettings controlsettings
 The current settings of the device.
const DsoSettingsScopescope = nullptr
 Global scope parameters and configurations.
unsigned downsamplingNumber = 1
 Number of downsamples to reduce sample rate.
DSOsamples result
unsigned expectedSampleCount = 0
bool calibrationHasChanged = false
std::unique_ptr< QSettings > calibrationSettings
double offsetCorrection [HANTEK_GAIN_STEPS][HANTEK_CHANNEL_NUMBER]
double gainCorrection [HANTEK_GAIN_STEPS][HANTEK_CHANNEL_NUMBER]
bool capturing = false
bool samplingStarted = false
bool stateMachineRunning = false
int acquireInterval = 0
int displayInterval = 0
unsigned activeChannels = 2
bool refresh = false
Raw raw
unsigned debugLevel = 0
uint8_t channelOffset [2] = { 0x80, 0x80 }

Detailed Description

The DsoControl abstraction layer for Hantek USB DSOs. TODO Please anyone, refactor this class into smaller pieces (Separation of Concerns!).

Constructor & Destructor Documentation

◆ HantekDsoControl()

HantekDsoControl::HantekDsoControl ( ScopeDevice * scopeDevice,
const DSOModel * model,
int verboseLevel )
explicit

Creates a dsoControl object. The actual event loop / timer is not started. You can optionally create a thread and move the created object to the thread. You need to call updateInterval() to start the timer. This is done implicitly if run() is called.

Parameters
deviceThe usb device. This object does not take ownership.

◆ ~HantekDsoControl()

HantekDsoControl::~HantekDsoControl ( )
override

Cleans up.

Member Function Documentation

◆ addCommand()

void HantekDsoControl::addCommand ( ControlCommand * newCommand,
bool pending = true )

◆ applySettings

void HantekDsoControl::applySettings ( DsoSettingsScope * scope)
slot

Initializes the device with the current settings.

Parameters
scopeThe settings for the oscilloscope.

◆ calibrateOffset

void HantekDsoControl::calibrateOffset ( bool enable)
slot

enable/disable offset calibration

◆ communicationError

void HantekDsoControl::communicationError ( ) const
signal

◆ controlSetSamplerate()

void HantekDsoControl::controlSetSamplerate ( uint8_t sampleIndex)
private

◆ convertRawDataToSamples()

void HantekDsoControl::convertRawDataToSamples ( )
private

Converts raw oscilloscope data to sample data.

◆ deviceNotConnected()

bool HantekDsoControl::deviceNotConnected ( )
private

USB status, always false for demo device.

◆ enableSamplingUI

void HantekDsoControl::enableSamplingUI ( bool enabled = true)
slot

If sampling is disabled, no samplesAvailable() signals are send anymore, no samples are fetched from the device and no processing takes place.

Start sampling process.

Parameters
enabledEnables/Disables sampling

◆ getCalibrationFromEEPROM()

Dso::ErrorCode HantekDsoControl::getCalibrationFromEEPROM ( )
private

◆ getCalibrationFromIniFile()

Dso::ErrorCode HantekDsoControl::getCalibrationFromIniFile ( )
private

◆ getCommand()

const ControlCommand * HantekDsoControl::getCommand ( Hantek::ControlCode code) const
inline

◆ getDevice()

const ScopeDevice * HantekDsoControl::getDevice ( ) const
inline

Return the associated usb device.

◆ getModel()

const DSOModel * HantekDsoControl::getModel ( ) const
inline

Return the associated scope model.

◆ getRecordLength()

unsigned HantekDsoControl::getRecordLength ( ) const
private

◆ getSampleCount()

unsigned HantekDsoControl::getSampleCount ( ) const
inlineprivate

Get the number of samples that are expected returned by the scope. In rolling mode this depends on the usb speed and packet size.

Returns
The total number of samples the scope should return.

◆ getSamplerate()

double HantekDsoControl::getSamplerate ( ) const
inline

◆ getSamplesize()

unsigned HantekDsoControl::getSamplesize ( ) const
inline

◆ grossSampleCount()

unsigned HantekDsoControl::grossSampleCount ( unsigned net) const
inlineprivate

adjust for skipping of minimal 2048 leading samples

◆ hasCommand()

bool HantekDsoControl::hasCommand ( Hantek::ControlCode code)
inline

◆ isSamplingUI()

bool HantekDsoControl::isSamplingUI ( ) const
inline

◆ isSingleChannel()

bool HantekDsoControl::isSingleChannel ( ) const
inlineprivate

◆ liveCalibrationError

void HantekDsoControl::liveCalibrationError ( ) const
signal

◆ modifyCommand()

template<class T>
T * HantekDsoControl::modifyCommand ( Hantek::ControlCode code)
inline

◆ netSampleCount()

unsigned HantekDsoControl::netSampleCount ( unsigned gross) const
inlineprivate

calculate backwards to get multiples of 1000 (typical 20000 or 10000)

◆ prepareForShutdown()

void HantekDsoControl::prepareForShutdown ( )

Saves calibration settings e.g. to the scope's EEPROM.

◆ quitSampling()

void HantekDsoControl::quitSampling ( )

Stops the device.

◆ refreshNeeded()

bool HantekDsoControl::refreshNeeded ( )
inlineprivate

◆ requestRefresh()

void HantekDsoControl::requestRefresh ( bool active = true)
inlineprivate

◆ restartSampling

void HantekDsoControl::restartSampling ( )
slot

Starts a new sampling block.

◆ restoreTargets()

void HantekDsoControl::restoreTargets ( )
private

Restore the samplerate/timebase targets after divider updates.

◆ samplerateCalculated

void HantekDsoControl::samplerateCalculated ( double samplerate,
unsigned oversampling )
signal

The samplerate was newly calculated.

◆ samplerateLimitsChanged

void HantekDsoControl::samplerateLimitsChanged ( double minimum,
double maximum )
signal

The available samplerate range has changed.

◆ samplerateSet

void HantekDsoControl::samplerateSet ( int mode,
QList< double > sampleSteps )
signal

The available samplerate for fixed samplerate devices has changed.

◆ samplesAvailable

void HantekDsoControl::samplesAvailable ( const DSOsamples * samples)
signal

New sample data is available.

◆ setCalFreq

Dso::ErrorCode HantekDsoControl::setCalFreq ( double calfreq = 0.0)
slot

Sets the calibration frequency of the oscilloscope.

Parameters
calfreqThe calibration frequency.
Returns
The tfrequency that has been set, Dso::ErrorCode on error.

◆ setChannelInverted

Dso::ErrorCode HantekDsoControl::setChannelInverted ( ChannelID channel,
bool inverted )
slot

Enables/disables inverting of the given channel.

Parameters
channelThe channel that should be set.
usedtrue if the channel is inverted.
Returns
See Dso::ErrorCode.

◆ setChannelUsed

Dso::ErrorCode HantekDsoControl::setChannelUsed ( ChannelID channel,
bool used )
slot

Enables/disables filtering of the given channel.

Parameters
channelThe channel that should be set.
usedtrue if the channel should be sampled.
Returns
See Dso::ErrorCode.

◆ setCoupling

Dso::ErrorCode HantekDsoControl::setCoupling ( ChannelID channel,
Dso::Coupling coupling )
slot

Sets the coupling for the given channel.

Parameters
channelThe channel that should be set.
couplingThe coupling that should be set.
Returns
error code.

◆ setDownsampling()

void HantekDsoControl::setDownsampling ( unsigned downsampling)
inlineprivate

◆ setGain

Dso::ErrorCode HantekDsoControl::setGain ( ChannelID channel,
double gain )
slot

Sets the probe gain for the given channel.

Parameters
channelThe channel that should be set.
probeAttngain of probe is set.
Returns
error code.

◆ setProbe

Dso::ErrorCode HantekDsoControl::setProbe ( ChannelID channel,
double probeAttn )
slot

Sets the gain for the given channel. Get the actual gain by specification.gainSteps[gainId].

Parameters
channelThe channel that should be set.
gainThe gain that should be met (V/div).
Returns
The gain that has been set, Dso::ErrorCode on error.

◆ setRecordTime

Dso::ErrorCode HantekDsoControl::setRecordTime ( double duration = 0.0)
slot

Sets the time duration of one acquisition by adapting the samplerate.

Parameters
durationThe record time duration that should be met (s), 0.0 to restore current record time.
Returns
The record time duration that has been set, 0.0 on error.

◆ setSamplerate

Dso::ErrorCode HantekDsoControl::setSamplerate ( double samplerate = 0.0)
slot

Sets the samplerate of the oscilloscope.

Parameters
samplerateThe samplerate that should be met (S/s), 0.0 to restore current samplerate.
Returns
The samplerate that has been set, 0.0 on error.

◆ setSingleChannel()

void HantekDsoControl::setSingleChannel ( bool single)
inlineprivate

◆ setTriggerLevel

Dso::ErrorCode HantekDsoControl::setTriggerLevel ( ChannelID channel,
double level )
slot

Set the trigger level.

Parameters
channelThe channel that should be set.
levelThe new trigger level (V).
Returns
See Dso::ErrorCode.

◆ setTriggerMode

Dso::ErrorCode HantekDsoControl::setTriggerMode ( Dso::TriggerMode mode)
slot

Set the trigger mode.

Returns
See Dso::ErrorCode.

◆ setTriggerPosition

Dso::ErrorCode HantekDsoControl::setTriggerPosition ( double position)
slot

Set the trigger position.

Parameters
positionThe new trigger position (in s).
Returns
The trigger position that has been set.

◆ setTriggerSlope

Dso::ErrorCode HantekDsoControl::setTriggerSlope ( Dso::Slope slope)
slot

Set the trigger slope.

Parameters
slopeThe Slope that should cause a trigger.
Returns
See Dso::ErrorCode.

◆ setTriggerSmooth

Dso::ErrorCode HantekDsoControl::setTriggerSmooth ( int smooth)
slot

Set the trigger smoothing.

Parameters
smoothThe filter value.
Returns
See Dso::ErrorCode.

◆ setTriggerSource

Dso::ErrorCode HantekDsoControl::setTriggerSource ( int channel)
slot

Set the trigger source.

Parameters
idThe channel that should be used as trigger.
Returns
See Dso::ErrorCode.

◆ showSamplingStatus

void HantekDsoControl::showSamplingStatus ( bool enabled)
signal

The oscilloscope started/stopped sampling/waiting for trigger.

◆ stateMachine()

void HantekDsoControl::stateMachine ( )

State machine for the device communication.

Call this to start the processing. This method will call itself periodically from there on. Move this class object to an own thread and call run from there.

◆ statusMessage

void HantekDsoControl::statusMessage ( const QString & message,
int timeout )
signal

Status message about the oscilloscope.

◆ stopStateMachine()

void HantekDsoControl::stopStateMachine ( )
inline

◆ stringCommand()

Dso::ErrorCode HantekDsoControl::stringCommand ( const QString & commandString)

Sends control commands directly.

Syntax:

Control command:

cc [hex code] [hex data]
Parameters
commandThe command as string (Has to be parsed).
Returns
See Dso::ErrorCode.

◆ triggerModeNONE()

bool HantekDsoControl::triggerModeNONE ( )
inlineprivate

◆ updateCalibrationValues()

Dso::ErrorCode HantekDsoControl::updateCalibrationValues ( bool useEEPROM = false)
private

◆ updateInterval()

void HantekDsoControl::updateInterval ( )
private

Updates the interval of the periodic thread timer.

◆ updateSamplerateLimits()

void HantekDsoControl::updateSamplerateLimits ( )
private

Update the minimum and maximum supported samplerate.

◆ writeCalibrationToEEPROM()

Dso::ErrorCode HantekDsoControl::writeCalibrationToEEPROM ( )
private

Field Documentation

◆ acquireInterval

int HantekDsoControl::acquireInterval = 0
private

◆ activeChannels

unsigned HantekDsoControl::activeChannels = 2
private

◆ calibrationHasChanged

bool HantekDsoControl::calibrationHasChanged = false
private

◆ calibrationSettings

std::unique_ptr< QSettings > HantekDsoControl::calibrationSettings
private

◆ capturing

bool HantekDsoControl::capturing = false
private

◆ CapturingThread

friend HantekDsoControl::CapturingThread
private

◆ channelOffset

uint8_t HantekDsoControl::channelOffset[2] = { 0x80, 0x80 }
private

◆ control

ControlCommand* HantekDsoControl::control[255] = { nullptr }
private

Pointers to control commands.

◆ controlsettings

Dso::ControlSettings HantekDsoControl::controlsettings
private

The current settings of the device.

◆ debugLevel

unsigned HantekDsoControl::debugLevel = 0
private

◆ displayInterval

int HantekDsoControl::displayInterval = 0
private

◆ downsamplingNumber

unsigned HantekDsoControl::downsamplingNumber = 1
private

Number of downsamples to reduce sample rate.

◆ expectedSampleCount

unsigned HantekDsoControl::expectedSampleCount = 0
private

The expected total number of samples at the last check before sampling started

◆ firstControlCommand

ControlCommand* HantekDsoControl::firstControlCommand = nullptr
private

◆ gainCorrection

double HantekDsoControl::gainCorrection[HANTEK_GAIN_STEPS][HANTEK_CHANNEL_NUMBER]
private

◆ mathChannel

std::unique_ptr< MathChannel > HantekDsoControl::mathChannel
private

◆ model

const DSOModel* HantekDsoControl::model
private

The attached scope model.

◆ offsetCorrection

double HantekDsoControl::offsetCorrection[HANTEK_GAIN_STEPS][HANTEK_CHANNEL_NUMBER]
private

◆ raw

Raw HantekDsoControl::raw
private

◆ refresh

bool HantekDsoControl::refresh = false
private

◆ replaceCalibrationEEPROM

bool HantekDsoControl::replaceCalibrationEEPROM = false
private

◆ result

DSOsamples HantekDsoControl::result
private

◆ samplingStarted

bool HantekDsoControl::samplingStarted = false
private

◆ samplingUI

bool HantekDsoControl::samplingUI = false
private

true, if the oscilloscope is taking samples

◆ scope

const DsoSettingsScope* HantekDsoControl::scope = nullptr
private

Global scope parameters and configurations.

◆ scopeDevice

ScopeDevice* HantekDsoControl::scopeDevice
private

The USB device for the oscilloscope.

◆ singleChannel

bool HantekDsoControl::singleChannel = false
private

◆ specification

const Dso::ControlSpecification* HantekDsoControl::specification
private

The specifications of the device.

◆ stateMachineRunning

bool HantekDsoControl::stateMachineRunning = false
private

◆ triggering

std::unique_ptr< Triggering > HantekDsoControl::triggering
private

◆ verboseLevel

int HantekDsoControl::verboseLevel = 0
private

The documentation for this class was generated from the following files: