Skip to content

Commit

Permalink
Some hantek6022 work integrated into src/hantek/
Browse files Browse the repository at this point in the history
  • Loading branch information
David Gräff committed Mar 3, 2016
1 parent 5074707 commit fc04859
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 14 deletions.
94 changes: 84 additions & 10 deletions openhantek/src/hantek/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ namespace Hantek {
/// \return The current CaptureState of the oscilloscope, libusb error code on error.
int Control::getCaptureState() {
int errorCode;

// Command not supported by this model
if (this->device->getModel() == MODEL_DSO6022BE)
return CAPTURE_READY;

errorCode = this->device->bulkCommand(this->command[BULK_GETCAPTURESTATE], 1);
if(errorCode < 0)
Expand All @@ -249,11 +253,13 @@ namespace Hantek {
/// \return sample count on success, libusb error code on error.
int Control::getSamples(bool process) {
int errorCode;

// Request data
errorCode = this->device->bulkCommand(this->command[BULK_GETDATA], 1);
if(errorCode < 0)
return errorCode;

if (this->device->getModel() != MODEL_DSO6022BE) {
// Request data
errorCode = this->device->bulkCommand(this->command[BULK_GETDATA], 1);
if(errorCode < 0)
return errorCode;
}

// Save raw data to temporary buffer
bool fastRate = false;
Expand Down Expand Up @@ -366,12 +372,24 @@ namespace Hantek {
}
}
else {
bufferPosition += HANTEK_CHANNELS - 1 - channel;
if (this->device->getModel() == MODEL_DSO6022BE)
bufferPosition += channel;
else
bufferPosition += HANTEK_CHANNELS - 1 - channel;

for(unsigned int realPosition = 0; realPosition < sampleCount; ++realPosition, bufferPosition += HANTEK_CHANNELS) {
if(bufferPosition >= totalSampleCount)
bufferPosition %= totalSampleCount;

this->samples[channel][realPosition] = ((double) data[bufferPosition] / this->specification.voltageLimit[channel][this->settings.voltage[channel].gain] - this->settings.voltage[channel].offsetReal) * this->specification.gainSteps[this->settings.voltage[channel].gain];

if (this->device->getModel() == MODEL_DSO6022BE)
this->samples[channel][realPosition] = (((double) data[bufferPosition] - 0x83)
/ this->specification.voltageLimit[channel][this->settings.voltage[channel].gain])
* this->specification.gainSteps[this->settings.voltage[channel].gain];
else
this->samples[channel][realPosition] = ((double) data[bufferPosition]
/ this->specification.voltageLimit[channel][this->settings.voltage[channel].gain]
- this->settings.voltage[channel].offsetReal)
* this->specification.gainSteps[this->settings.voltage[channel].gain];
}
}
}
Expand Down Expand Up @@ -796,6 +814,25 @@ namespace Hantek {
this->commandPending[BULK_ESETTRIGGERORSAMPLERATE] = true;

break;

case MODEL_DSO6022BE:
// 6022BE do not support any bulk commands
this->control[CONTROLINDEX_SETVOLTDIV_CH1] = new ControlSetVoltDIV_CH1();
this->controlCode[CONTROLINDEX_SETVOLTDIV_CH1] = CONTROL_SETVOLTDIV_CH1;
this->controlPending[CONTROLINDEX_SETVOLTDIV_CH1] = true;

this->control[CONTROLINDEX_SETVOLTDIV_CH2] = new ControlSetVoltDIV_CH2();
this->controlCode[CONTROLINDEX_SETVOLTDIV_CH2] = CONTROL_SETVOLTDIV_CH2;
this->controlPending[CONTROLINDEX_SETVOLTDIV_CH2] = true;

this->control[CONTROLINDEX_SETTIMEDIV] = new ControlSetTimeDIV();
this->controlCode[CONTROLINDEX_SETTIMEDIV] = CONTROL_SETTIMEDIV;
this->controlPending[CONTROLINDEX_SETTIMEDIV] = true;

this->control[CONTROLINDEX_ACQUIIRE_HARD_DATA] = new ControlAcquireHardData();
this->controlCode[CONTROLINDEX_ACQUIIRE_HARD_DATA] = CONTROL_ACQUIIRE_HARD_DATA;
this->controlPending[CONTROLINDEX_ACQUIIRE_HARD_DATA] = true;
break;

default:
this->device->disconnect();
Expand All @@ -808,6 +845,12 @@ namespace Hantek {

for(int control = 0; control < CONTROLINDEX_COUNT; ++control)
this->controlPending[control] = true;

// Disable controls not supported by 6022BE
if (this->device->getModel() == MODEL_DSO6022BE) {
this->controlPending[CONTROLINDEX_SETOFFSET] = false;
this->controlPending[CONTROLINDEX_SETRELAYS] = false;
}

// Maximum possible samplerate for a single channel and dividers for record lengths
this->specification.bufferDividers.clear();
Expand Down Expand Up @@ -880,6 +923,28 @@ namespace Hantek {
this->specification.sampleSize = 8;
break;

case MODEL_DSO6022BE:
this->specification.samplerate.single.base = 48e6;
this->specification.samplerate.single.max = 48e6;
this->specification.samplerate.single.maxDownsampler = 1;
this->specification.samplerate.single.recordLengths << UINT_MAX << 10240 << 32768;
this->specification.samplerate.multi.base = 48e6;
this->specification.samplerate.multi.max = 48e6;
this->specification.samplerate.multi.maxDownsampler = 1;
this->specification.samplerate.multi.recordLengths << UINT_MAX << 20480 << 65536;
this->specification.bufferDividers << 1000 << 1 << 1;
this->specification.gainSteps
<< 0.08 << 0.16 << 0.40 << 0.80 << 1.60 << 4.00 << 8.0 << 16.0 << 40.0;
// This data was based on testing and depends on Divider.
for(int channel = 0; channel < HANTEK_CHANNELS; ++channel)
this->specification.voltageLimit[channel]
<< 25 << 51 << 103 << 206 << 412 << 196 << 392 << 784 << 1000;
// Divider. Tested and calculated results are different!
this->specification.gainDiv
<< 10 << 10 << 10 << 10 << 10 << 2 << 2 << 2 << 1;
this->specification.sampleSize = 8;
break;

default:
this->specification.samplerate.single.base = 50e6;
this->specification.samplerate.single.max = 50e6;
Expand All @@ -900,6 +965,9 @@ namespace Hantek {
this->specification.sampleSize = 8;
break;
}
this->settings.recordLengthId = 1;
this->settings.samplerate.limits = &(this->specification.samplerate.single);
this->settings.samplerate.downsampler = 1;
this->previousSampleCount = 0;

// Get channel level data
Expand All @@ -925,7 +993,7 @@ namespace Hantek {
/// \param index The record length index that should be set.
/// \return The record length that has been set, 0 on error.
unsigned int Control::setRecordLength(unsigned int index) {
if(!this->device->isConnected())
if(!this->device->isConnected())
return 0;

if(!this->updateRecordLength(index))
Expand Down Expand Up @@ -1080,7 +1148,10 @@ namespace Hantek {

if(channel >= HANTEK_CHANNELS)
return Dso::ERROR_PARAMETER;


// if (this->device->getModel() == MODEL_DSO6022BE)
// Dso::ERROR_NONE;

// SetRelays control command for coupling relays
static_cast<ControlSetRelays *>(this->control[CONTROLINDEX_SETRELAYS])->setCoupling(channel, coupling != Dso::COUPLING_AC);
this->controlPending[CONTROLINDEX_SETRELAYS] = true;
Expand Down Expand Up @@ -1228,6 +1299,9 @@ namespace Hantek {

if(channel >= HANTEK_CHANNELS)
return Dso::ERROR_PARAMETER;

// if (this->device->getModel() == MODEL_DSO6022BE)
// return Dso::ERROR_NONE;

// Calculate the trigger level value
unsigned short int minimum, maximum;
Expand Down
4 changes: 4 additions & 0 deletions openhantek/src/hantek/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ namespace Hantek {
//CONTROLINDEX_BEGINCOMMAND,
CONTROLINDEX_SETOFFSET,
CONTROLINDEX_SETRELAYS,
CONTROLINDEX_SETVOLTDIV_CH1,
CONTROLINDEX_SETVOLTDIV_CH2,
CONTROLINDEX_SETTIMEDIV,
CONTROLINDEX_ACQUIIRE_HARD_DATA,
CONTROLINDEX_COUNT
};

Expand Down
9 changes: 6 additions & 3 deletions openhantek/src/hantek/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ namespace Hantek {
/// \param parent The parent widget.
Device::Device(QObject *parent) : QObject(parent) {
// Product ids and names for the Model enum
this->modelIds << 0x2090 << 0x2150 << 0x2250 << 0x5200 << 0x520A;
this->modelStrings << "DSO-2090" << "DSO-2150" << "DSO-2250" << "DSO-5200" << "DSO-5200A";
this->modelIds << 0x2090 << 0x2150 << 0x2250 << 0x5200 << 0x520A << 0x6022;
this->modelStrings << "DSO-2090" << "DSO-2150" << "DSO-2250" << "DSO-5200" << "DSO-5200A" << "DSO-6022BE";
this->model = MODEL_UNKNOWN;

this->beginCommandControl = new ControlBeginCommand();
Expand Down Expand Up @@ -136,7 +136,10 @@ namespace Hantek {
this->outPacketLength = endpointDescriptor->wMaxPacketSize;
break;
case HANTEK_EP_IN:
this->inPacketLength = endpointDescriptor->wMaxPacketSize;
if (this->getModel() == MODEL_DSO6022BE)
this->inPacketLength = 16384;
else
this->inPacketLength = endpointDescriptor->wMaxPacketSize;
break;
}
}
Expand Down
44 changes: 44 additions & 0 deletions openhantek/src/hantek/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1030,4 +1030,48 @@ namespace Hantek {
void ControlSetRelays::setTrigger(bool ext) {
this->array[7] = ext ? 0xfe : 0x01;
}

//////////////////////////////////////////////////////////////////////////////
// class ControlSetVoltDIV_CH1
/// \brief Sets the data array to the default values.
ControlSetVoltDIV_CH1::ControlSetVoltDIV_CH1() : Helper::DataArray<uint8_t>(1) {
this->setDiv(5);
}

void ControlSetVoltDIV_CH1::setDiv(uint8_t val) {
this->array[0] = val;
}

//////////////////////////////////////////////////////////////////////////////
// class ControlSetVoltDIV_CH2
/// \brief Sets the data array to the default values.
ControlSetVoltDIV_CH2::ControlSetVoltDIV_CH2() : Helper::DataArray<uint8_t>(1) {
this->setDiv(5);
}

void ControlSetVoltDIV_CH2::setDiv(uint8_t val) {
this->array[0] = val;
}

//////////////////////////////////////////////////////////////////////////////
// class ControlSetTimeDIV
/// \brief Sets the data array to the default values.
ControlSetTimeDIV::ControlSetTimeDIV() : Helper::DataArray<uint8_t>(1) {
this->init();
}

void ControlSetTimeDIV::init() {
this->array[0] = 0x01;
}

//////////////////////////////////////////////////////////////////////////////
// class ControlAcquireHardData
/// \brief Sets the data array to the default values.
ControlAcquireHardData::ControlAcquireHardData() : Helper::DataArray<uint8_t>(1) {
this->init();
}

void ControlAcquireHardData::init() {
this->array[0] = 0x01;
}
}
47 changes: 46 additions & 1 deletion openhantek/src/hantek/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,12 @@ namespace Hantek {
/// The limits are <= instead of < for the 10 bit models, since those support voltages up to 10 V.
/// </p>
/// <p><br /></p>
CONTROL_SETRELAYS = 0xb5
CONTROL_SETRELAYS = 0xb5,

CONTROL_SETVOLTDIV_CH1 = 0xe0,
CONTROL_SETVOLTDIV_CH2 = 0xe1,
CONTROL_SETTIMEDIV = 0xe2,
CONTROL_ACQUIIRE_HARD_DATA = 0xe3
};

//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -648,6 +653,7 @@ namespace Hantek {
MODEL_DSO2250, ///< %Hantek DSO-2250 USB
MODEL_DSO5200, ///< %Hantek DSO-5200 USB
MODEL_DSO5200A, ///< %Hantek DSO-5200A USB
MODEL_DSO6022BE, ///< %Hantek6022BE USB
MODEL_COUNT
};

Expand Down Expand Up @@ -1154,6 +1160,45 @@ namespace Hantek {
bool getTrigger();
void setTrigger(bool ext);
};

//////////////////////////////////////////////////////////////////////////////
/// \class ControlSetVoltDIV_CH1 hantek/types.h
/// \brief The CONTROL_SETVOLTDIV_CH1 builder.
class ControlSetVoltDIV_CH1 : public Helper::DataArray<uint8_t> {
public:
ControlSetVoltDIV_CH1();
void setDiv(uint8_t val);
};

//////////////////////////////////////////////////////////////////////////////
/// \class ControlSetVoltDIV_CH2 hantek/types.h
/// \brief The CONTROL_SETVOLTDIV_CH2 builder.
class ControlSetVoltDIV_CH2 : public Helper::DataArray<uint8_t> {
public:
ControlSetVoltDIV_CH2();
void setDiv(uint8_t val);
};


//////////////////////////////////////////////////////////////////////////////
/// \class ControlSetTimeDIV hantek/types.h
/// \brief The CONTROL_SETTIMEDIV builder.
class ControlSetTimeDIV : public Helper::DataArray<uint8_t> {
public:
ControlSetTimeDIV();
private:
void init();
};

//////////////////////////////////////////////////////////////////////////////
/// \class ControlAcquireHardData hantek/types.h
/// \brief The CONTROL_ACQUIIRE_HARD_DATA builder.
class ControlAcquireHardData : public Helper::DataArray<uint8_t> {
public:
ControlAcquireHardData();
private:
void init();
};
}


Expand Down

0 comments on commit fc04859

Please sign in to comment.