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 (ChannelID channel, bool smooth)
 Set the trigger source. 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 setTriggerOffset (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...
 

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 recordTimeChanged (double duration)
 The record time duration has changed. More...
 
void samplerateChanged (double samplerate)
 The samplerate has changed. More...
 
void communicationError () const
 

Public Member Functions

 HantekDsoControl (USBDevice *device)
 
 ~HantekDsoControl ()
 Cleans up. More...
 
void run ()
 
double getSamplerate () const
 
unsigned getSamplesize () const
 
bool isSampling () const
 
const USBDevicegetDevice () const
 Return the associated usb device. 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
 

Private Member Functions

bool isFastRate () const
 
unsigned getRecordLength () const
 
void setDownsampling (unsigned downsampling)
 
Dso::ErrorCode retrieveChannelLevelData ()
 
unsigned getSampleCount () const
 
void updateInterval ()
 Updates the interval of the periodic thread timer. More...
 
std::vector< unsigned char > getSamples (unsigned &expectedSampleCount) const
 Gets sample data from the oscilloscope. More...
 
void convertRawDataToSamples (const std::vector< unsigned char > &rawData)
 Converts raw oscilloscope data to sample data. More...
 
unsigned updateSamplerate (unsigned downsampler, bool fastRate)
 Sets the samplerate based on the parameters calculated by Control::getBestSamplerate. 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 softwareTrigger ()
 
bool triggering ()
 

Static Private Member Functions

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

Private Attributes

ControlCommandcontrol [255] = { nullptr }
 Pointers to control commands. More...
 
ControlCommandfirstControlCommand = nullptr
 
USBDevicedevice
 The USB device for the oscilloscope. More...
 
bool sampling = false
 true, if the oscilloscope is taking samples More...
 
const Dso::ControlSpecificationspecification
 The specifications of the device. More...
 
Dso::ControlSettings controlsettings
 The current settings of the device. More...
 
unsigned downsamplingNumber = 1
 Number of downsamples to reduce sample rate. More...
 
DSOsamples result
 
unsigned expectedSampleCount = 0
 
bool samplingStarted = false
 
int acquireInterval = 0
 
int displayInterval = 0
 
bool channelSetupChanged = false
 
unsigned triggeredPositionRaw = 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 ( USBDevice device)
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

◆ convertRawDataToSamples()

void HantekDsoControl::convertRawDataToSamples ( const std::vector< unsigned char > &  rawData)
private

Converts raw oscilloscope data to sample data.

◆ 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 USBDevice* HantekDsoControl::getDevice ( ) const
inline

Return the associated usb device.

◆ 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

◆ getSamples()

std::vector< unsigned char > HantekDsoControl::getSamples ( unsigned &  expectedSampleCount) const
private

Gets sample data from the oscilloscope.

◆ getSamplesize()

unsigned HantekDsoControl::getSamplesize ( ) const
inline

◆ hasCommand()

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

◆ isFastRate()

bool HantekDsoControl::isFastRate ( ) const
inlineprivate

◆ isSampling()

bool HantekDsoControl::isSampling ( ) const
inline

◆ mirrorSlope()

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

◆ modifyCommand()

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

◆ recordTimeChanged

void HantekDsoControl::recordTimeChanged ( double  duration)
signal

The record time duration has changed.

◆ restoreTargets()

void HantekDsoControl::restoreTargets ( )
private

Restore the samplerate/timebase targets after divider updates.

◆ retrieveChannelLevelData()

Dso::ErrorCode HantekDsoControl::retrieveChannelLevelData ( )
private

◆ run()

void HantekDsoControl::run ( )

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.

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

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

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

◆ setTriggerOffset

Dso::ErrorCode HantekDsoControl::setTriggerOffset ( 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.

◆ setTriggerSource

Dso::ErrorCode HantekDsoControl::setTriggerSource ( ChannelID  channel,
bool  smooth 
)
slot

Set the trigger source.

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

◆ softwareTrigger()

unsigned HantekDsoControl::softwareTrigger ( )
private

◆ statusMessage

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

Status message about the oscilloscope.

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

◆ triggering()

bool HantekDsoControl::triggering ( )
private

◆ updateInterval()

void HantekDsoControl::updateInterval ( )
private

Updates the interval of the periodic thread timer.

◆ updateSamplerate()

unsigned HantekDsoControl::updateSamplerate ( unsigned  downsampler,
bool  fastRate 
)
private

Sets the samplerate based on the parameters calculated by Control::getBestSamplerate.

Parameters
downsamplerThe downsampling factor.
fastRatetrue, if one channel uses all buffers.
Returns
The downsampling factor that has been set.

◆ updateSamplerateLimits()

void HantekDsoControl::updateSamplerateLimits ( )
private

Update the minimum and maximum supported samplerate.

Field Documentation

◆ acquireInterval

int HantekDsoControl::acquireInterval = 0
private

◆ channelSetupChanged

bool HantekDsoControl::channelSetupChanged = false
private

◆ control

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

Pointers to control commands.

◆ controlsettings

Dso::ControlSettings HantekDsoControl::controlsettings
private

The current settings of the device.

◆ device

USBDevice* HantekDsoControl::device
private

The USB device for the oscilloscope.

◆ 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

◆ result

DSOsamples HantekDsoControl::result
private

◆ sampling

bool HantekDsoControl::sampling = false
private

true, if the oscilloscope is taking samples

◆ samplingStarted

bool HantekDsoControl::samplingStarted = false
private

◆ specification

const Dso::ControlSpecification* HantekDsoControl::specification
private

The specifications of the device.

◆ triggeredPositionRaw

unsigned HantekDsoControl::triggeredPositionRaw = 0
private

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