Skip to content

Commit

Permalink
initial work on 6022be support.
Browse files Browse the repository at this point in the history
currently works only correct voltage interpretation.
triggering and correct frequence docoding is not working.

Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
  • Loading branch information
olerem committed May 26, 2014
1 parent 46cdad5 commit 9a0d274
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 35 deletions.
139 changes: 111 additions & 28 deletions openhantek/src/hantek/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,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 @@ -360,11 +364,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 @@ -488,12 +494,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 @@ -821,6 +839,7 @@ namespace Hantek {
delete this->command[command];
this->commandPending[command] = false;
}
#if 0
// Instantiate the commands needed for all models
this->command[BULK_FORCETRIGGER] = new BulkForceTrigger();
this->command[BULK_STARTSAMPLING] = new BulkCaptureStart();
Expand All @@ -835,6 +854,7 @@ namespace Hantek {
this->specification.command.bulk.setSamplerate = (BulkCode) -1;
this->specification.command.bulk.setTrigger = (BulkCode) -1;
this->specification.command.bulk.setPretrigger = (BulkCode) -1;
#endif
this->specification.command.control.setOffset = CONTROL_SETOFFSET;
this->specification.command.control.setRelays = CONTROL_SETRELAYS;
this->specification.command.values.offsetLimits = VALUE_OFFSETLIMITS;
Expand Down Expand Up @@ -899,6 +919,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 Down Expand Up @@ -983,6 +1022,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 = 125e6;
this->specification.samplerate.single.max = 125e6;
Expand Down Expand Up @@ -1184,7 +1245,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 All @@ -1208,21 +1272,32 @@ namespace Hantek {
for(gainId = 0; gainId < this->specification.gainSteps.count() - 1; ++gainId)
if(this->specification.gainSteps[gainId] >= gain)
break;

// SetGain bulk command for gain
static_cast<BulkSetGain *>(this->command[BULK_SETGAIN])->setGain(channel, this->specification.gainIndex[gainId]);
this->commandPending[BULK_SETGAIN] = true;

// SetRelays control command for gain relays
ControlSetRelays *controlSetRelays = static_cast<ControlSetRelays *>(this->control[CONTROLINDEX_SETRELAYS]);
controlSetRelays->setBelow1V(channel, gainId < 3);
controlSetRelays->setBelow100mV(channel, gainId < 6);
this->controlPending[CONTROLINDEX_SETRELAYS] = true;


// Fixme, shoulb be some kind of protocol check instead of model check.
if (this->device->getModel() == MODEL_DSO6022BE) {
if (channel == 0) {
static_cast<ControlSetVoltDIV_CH1 *>(this->control[CONTROLINDEX_SETVOLTDIV_CH1])->setDiv(this->specification.gainDiv[gainId]);
this->controlPending[CONTROLINDEX_SETVOLTDIV_CH1] = true;
} else if (channel == 1) {
static_cast<ControlSetVoltDIV_CH2 *>(this->control[CONTROLINDEX_SETVOLTDIV_CH2])->setDiv(this->specification.gainDiv[gainId]);
this->controlPending[CONTROLINDEX_SETVOLTDIV_CH2] = true;
} else
qDebug("%s: Unsuported channel: %i\n", __func__, channel);
} else {
// SetGain bulk command for gain
static_cast<BulkSetGain *>(this->command[BULK_SETGAIN])->setGain(channel, this->specification.gainIndex[gainId]);
this->commandPending[BULK_SETGAIN] = true;

// SetRelays control command for gain relays
ControlSetRelays *controlSetRelays = static_cast<ControlSetRelays *>(this->control[CONTROLINDEX_SETRELAYS]);
controlSetRelays->setBelow1V(channel, gainId < 3);
controlSetRelays->setBelow100mV(channel, gainId < 6);
this->controlPending[CONTROLINDEX_SETRELAYS] = true;
}

this->settings.voltage[channel].gain = gainId;

this->setOffset(channel, this->settings.voltage[channel].offset);

//this->setOffset(channel, this->settings.voltage[channel].offset);
return this->specification.gainSteps[gainId];
}

Expand All @@ -1241,12 +1316,16 @@ namespace Hantek {
// The range is given by the calibration data (convert from big endian)
unsigned short int minimum = ((unsigned short int) *((unsigned char *) &(this->specification.offsetLimit[channel][this->settings.voltage[channel].gain][OFFSET_START])) << 8) + *((unsigned char *) &(this->specification.offsetLimit[channel][this->settings.voltage[channel].gain][OFFSET_START]) + 1);
unsigned short int maximum = ((unsigned short int) *((unsigned char *) &(this->specification.offsetLimit[channel][this->settings.voltage[channel].gain][OFFSET_END])) << 8) + *((unsigned char *) &(this->specification.offsetLimit[channel][this->settings.voltage[channel].gain][OFFSET_END]) + 1);


unsigned short int offsetValue = offset * (maximum - minimum) + minimum + 0.5;
double offsetReal = (double) (offsetValue - minimum) / (maximum - minimum);

double offsetReal = 0x80 / this->specification.voltageLimit[channel][this->settings.voltage[channel].gain];
// double offsetReal = (double) (offsetValue - minimum) / (maximum - minimum);

// SetOffset control command for channel offset
static_cast<ControlSetOffset *>(this->control[CONTROLINDEX_SETOFFSET])->setChannel(channel, offsetValue);
this->controlPending[CONTROLINDEX_SETOFFSET] = true;
//static_cast<ControlSetOffset *>(this->control[CONTROLINDEX_SETOFFSET])->setChannel(channel, offsetValue);
//this->controlPending[CONTROLINDEX_SETOFFSET] = true;

this->settings.voltage[channel].offset = offset;
this->settings.voltage[channel].offsetReal = offsetReal;
Expand Down Expand Up @@ -1313,8 +1392,8 @@ namespace Hantek {
// Apply trigger level of the new source
if(special) {
// SetOffset control command for changed trigger level
static_cast<ControlSetOffset *>(this->control[CONTROLINDEX_SETOFFSET])->setTrigger(0x7f);
this->controlPending[CONTROLINDEX_SETOFFSET] = true;
// static_cast<ControlSetOffset *>(this->control[CONTROLINDEX_SETOFFSET])->setTrigger(0x7f);
// this->controlPending[CONTROLINDEX_SETOFFSET] = true;
}
else
this->setTriggerLevel(id, this->settings.trigger.level[id]);
Expand All @@ -1332,6 +1411,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 All @@ -1354,7 +1436,8 @@ namespace Hantek {
unsigned short int levelValue = qBound((long int) minimum, (long int) ((this->settings.voltage[channel].offsetReal + level / this->specification.gainSteps[this->settings.voltage[channel].gain]) * (maximum - minimum) + 0.5) + minimum, (long int) maximum);

// Check if the set channel is the trigger source
if(!this->settings.trigger.special && channel == this->settings.trigger.source) {
if(!this->settings.trigger.special && channel == this->settings.trigger.source &&
this->device->getModel() != MODEL_DSO6022BE) {
// SetOffset control command for trigger level
static_cast<ControlSetOffset *>(this->control[CONTROLINDEX_SETOFFSET])->setTrigger(levelValue);
this->controlPending[CONTROLINDEX_SETOFFSET] = true;
Expand Down
5 changes: 5 additions & 0 deletions openhantek/src/hantek/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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 Expand Up @@ -125,6 +129,7 @@ namespace Hantek {
QList<unsigned short int> voltageLimit[HANTEK_CHANNELS];
/// The index of the selected gain on the hardware
QList<unsigned char> gainIndex;
QList<unsigned char> gainDiv;
/// Calibration data for the channel offsets \todo Should probably be a QList too
unsigned short int offsetLimit[HANTEK_CHANNELS][9][OFFSET_COUNT];
};
Expand Down
19 changes: 13 additions & 6 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 Expand Up @@ -217,7 +220,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 Expand Up @@ -360,9 +366,10 @@ namespace Hantek {
int Device::bulkCommand(Helper::DataArray<unsigned char> *command, int attempts) {
if(!this->handle)
return LIBUSB_ERROR_NO_DEVICE;

return 0;
// Send BeginCommand control command
int errorCode = this->controlWrite(CONTROL_BEGINCOMMAND, this->beginCommandControl->data(), this->beginCommandControl->getSize());
//int errorCode = this->controlWrite(CONTROL_BEGINCOMMAND, this->beginCommandControl->data(), this->beginCommandControl->getSize());
int errorCode = 0;
if(errorCode < 0)
return errorCode;

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;
}
}
Loading

0 comments on commit 9a0d274

Please sign in to comment.