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

Signals

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

Public Member Functions

 HantekDsoControl (ScopeDevice *scopeDevice, const DSOModel *model, unsigned verboseLevel)
 
 ~HantekDsoControl ()
 Cleans up. More...
 
void stateMachine ()
 State machine for the device communication. More...
 
void stopStateMachine ()
 
double getSamplerate () const
 
unsigned getSamplesize () const
 
bool isSampling () const
 
const ScopeDevicegetDevice () const
 Return the associated usb device. More...
 
const DSOModelgetModel () const
 Return the associated scope model. More...
 
Dso::ErrorCode stringCommand (const QString &commandString)
 Sends control commands directly. More...
 
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. More...
 

Static Public Attributes

static const unsigned SAMPLESIZE = 20000
 
static const unsigned SAMPLESIZE_ROLL = 39 * 256
 

Private Member Functions

void setSingleChannel (bool single)
 
bool isSingleChannel () const
 
bool triggerModeNONE ()
 
unsigned getRecordLength () const
 
void setDownsampling (unsigned downsampling)
 
Dso::ErrorCode retrieveChannelLevelData ()
 
unsigned getSampleCount () const
 
unsigned grossSampleCount (unsigned net) const
 adjust for skipping of minimal 2048 leading samples More...
 
unsigned netSampleCount (unsigned gross) const
 calculate backwards to get multiples of 1000 (typical 20000 or 10000) More...
 
void updateInterval ()
 Updates the interval of the periodic thread timer. More...
 
void convertRawDataToSamples ()
 Converts raw oscilloscope data to sample data. More...
 
void restoreTargets ()
 Restore the samplerate/timebase targets after divider updates. More...
 
void updateSamplerateLimits ()
 Update the minimum and maximum supported samplerate. More...
 
unsigned searchTriggerPoint (Dso::Slope dsoSlope, unsigned int startPos=0)
 
Dso::Slope mirrorSlope (Dso::Slope slope)
 
unsigned searchTriggeredPosition ()
 
bool provideTriggeredData ()
 
void controlSetSamplerate (uint8_t sampleIndex)
 
bool deviceNotConnected ()
 USB status, always false for demo device. More...
 
bool triggerChanged ()
 

Static Private Member Functions

static unsigned calculateTriggerPoint (unsigned value)
 Calculates the trigger point from the CommandGetCaptureState data. More...
 

Private Attributes

friend Capturing
 
bool singleChannel = false
 
unsigned verboseLevel = 0
 
ControlCommandcontrol [255] = { nullptr }
 Pointers to control commands. More...
 
ControlCommandfirstControlCommand = nullptr
 
ScopeDevicescopeDevice
 The USB device for the oscilloscope. More...
 
bool sampling = false
 true, if the oscilloscope is taking samples More...
 
const DSOModelmodel
 The attached scope model. More...
 
const Dso::ControlSpecificationspecification
 The specifications of the device. More...
 
Dso::ControlSettings controlsettings
 The current settings of the device. More...
 
const DsoSettingsScopescope = nullptr
 Global scope parameters and configuations. More...
 
unsigned downsamplingNumber = 1
 Number of downsamples to reduce sample rate. More...
 
DSOsamples result
 
unsigned expectedSampleCount = 0
 
bool capturing = false
 
bool samplingStarted = false
 
bool stateMachineRunning = false
 
int acquireInterval = 0
 
int displayInterval = 0
 
unsigned triggeredPositionRaw = 0
 
unsigned activeChannels = 2
 
bool newTriggerParam = false
 
Raw raw
 
std::vector< QString > controlNames
 
unsigned debugLevel = 0
 

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,
unsigned  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 ( )

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.

◆ calculateTriggerPoint()

static unsigned HantekDsoControl::calculateTriggerPoint ( unsigned  value)
staticprivate

Calculates the trigger point from the CommandGetCaptureState data.

Parameters
valueThe data value that contains the trigger point.
Returns
The calculated trigger point for the given data.

◆ 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.

◆ enableSampling

void HantekDsoControl::enableSampling ( bool  enabled)
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

◆ 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 is 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

◆ isSampling()

bool HantekDsoControl::isSampling ( ) const
inline

◆ isSingleChannel()

bool HantekDsoControl::isSingleChannel ( ) const
inlineprivate

◆ mirrorSlope()

Dso::Slope HantekDsoControl::mirrorSlope ( Dso::Slope  slope)
inlineprivate

◆ 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)

◆ provideTriggeredData()

bool HantekDsoControl::provideTriggeredData ( )
private

◆ quitSampling()

void HantekDsoControl::quitSampling ( )

Stops the device.

◆ restartSampling

void HantekDsoControl::restartSampling ( )
slot

Starts a new sampling block.

◆ restoreTargets()

void HantekDsoControl::restoreTargets ( )
private

Restore the samplerate/timebase targets after divider updates.

◆ retrieveChannelLevelData()

Dso::ErrorCode HantekDsoControl::retrieveChannelLevelData ( )
private

◆ samplerateChanged

void HantekDsoControl::samplerateChanged ( double  samplerate)
signal

The samplerate has changed.

◆ 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.

◆ samplingStatusChanged

void HantekDsoControl::samplingStatusChanged ( bool  enabled)
signal

The oscilloscope started/stopped sampling/waiting for trigger.

◆ searchTriggeredPosition()

unsigned HantekDsoControl::searchTriggeredPosition ( )
private

◆ searchTriggerPoint()

unsigned HantekDsoControl::searchTriggerPoint ( Dso::Slope  dsoSlope,
unsigned int  startPos = 0 
)
private

< number of available samples

◆ 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 aquisition 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.

◆ 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:

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

◆ triggerChanged()

bool HantekDsoControl::triggerChanged ( )
inlineprivate

◆ triggerModeNONE()

bool HantekDsoControl::triggerModeNONE ( )
inlineprivate

◆ 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.

Field Documentation

◆ acquireInterval

int HantekDsoControl::acquireInterval = 0
private

◆ activeChannels

unsigned HantekDsoControl::activeChannels = 2
private

◆ Capturing

friend HantekDsoControl::Capturing
private

◆ capturing

bool HantekDsoControl::capturing = false
private

◆ control

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

Pointers to control commands.

◆ controlNames

std::vector< QString > HantekDsoControl::controlNames
private
Initial value:
= { "SETGAIN_CH1", "SETGAIN_CH2", "SETSAMPLERATE", "STARTSAMPLING",
"SETNUMCHANNELS", "SETCOUPLING", "SETCALFREQ" }

◆ 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

◆ model

const DSOModel* HantekDsoControl::model
private

The attached scope model.

◆ newTriggerParam

bool HantekDsoControl::newTriggerParam = false
private

◆ raw

Raw HantekDsoControl::raw
private

◆ result

DSOsamples HantekDsoControl::result
private

◆ SAMPLESIZE

const unsigned HantekDsoControl::SAMPLESIZE = 20000
static

◆ SAMPLESIZE_ROLL

const unsigned HantekDsoControl::SAMPLESIZE_ROLL = 39 * 256
static

◆ sampling

bool HantekDsoControl::sampling = false
private

true, if the oscilloscope is taking samples

◆ samplingStarted

bool HantekDsoControl::samplingStarted = false
private

◆ scope

const DsoSettingsScope* HantekDsoControl::scope = nullptr
private

Global scope parameters and configuations.

◆ 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

◆ triggeredPositionRaw

unsigned HantekDsoControl::triggeredPositionRaw = 0
private

◆ verboseLevel

unsigned HantekDsoControl::verboseLevel = 0
private

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