Skip to content

Commit

Permalink
Easier device support: Models have even more limited interaction with…
Browse files Browse the repository at this point in the history
… dsocontrol now, only addCommand is called. The commands will be moved to the specification soon as well.
  • Loading branch information
David Graeff committed Jan 8, 2018
1 parent ecbc22e commit dc4cbc9
Show file tree
Hide file tree
Showing 26 changed files with 261 additions and 233 deletions.
1 change: 1 addition & 0 deletions openhantek/src/hantekdso/controlspecification.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,6 @@ struct ControlSpecification {
bool supportsCaptureState = true;
bool supportsOffset = true;
bool supportsCouplingRelays = true;
int fixedUSBinLength = 0;
};
}
30 changes: 12 additions & 18 deletions openhantek/src/hantekdso/hantekdsocontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,11 @@ HantekDsoControl::HantekDsoControl(USBDevice *device)

if (specification.useControlNoBulk) {
device->setEnableBulkTransfer(false);
} else {
// Instantiate the commands needed for all bulk-command-enabled models
addCommand(BulkCode::FORCETRIGGER, new BulkForceTrigger(), false);
addCommand(BulkCode::STARTSAMPLING, new BulkCaptureStart(), false);
addCommand(BulkCode::ENABLETRIGGER, new BulkTriggerEnabled(), false);
addCommand(BulkCode::GETDATA, new BulkGetData(), false);
addCommand(BulkCode::GETCAPTURESTATE, new BulkGetCaptureState(), false);
addCommand(BulkCode::SETGAIN, new BulkSetGain(), false);
}

if (specification.fixedUSBinLength)
device->overwriteInPacketLength(specification.fixedUSBinLength);

// Apply special requirements by the devices model
device->getModel()->applyRequirements(this);

Expand Down Expand Up @@ -135,15 +130,16 @@ unsigned HantekDsoControl::getRecordLength() const {

Dso::ErrorCode HantekDsoControl::retrieveChannelLevelData() {
// Get channel level data
ControlGetLimits c(2);
int errorCode =
device->controlRead((uint8_t)ControlCode::CONTROL_VALUE, (unsigned char *)&(specification.offsetLimit),
sizeof(specification.offsetLimit), (uint8_t)ControlValue::VALUE_OFFSETLIMITS);
device->controlRead(&c);
if (errorCode < 0) {
qWarning() << tr("Couldn't get channel level data from oscilloscope");
emit statusMessage(tr("Couldn't get channel level data from oscilloscope"), 0);
emit communicationError();
return Dso::ErrorCode::CONNECTION;
}
memcpy(specification.offsetLimit,c.offsetLimit,sizeof(specification.offsetLimit));

return Dso::ErrorCode::NONE;
}
Expand Down Expand Up @@ -185,8 +181,7 @@ std::vector<unsigned char> HantekDsoControl::getSamples(unsigned &previousSample
// Request data
errorCode = device->bulkCommand(getCommand(BulkCode::GETDATA), 1);
} else {
const ControlCommand *bulkCommand = getCommand(ControlCode::CONTROL_ACQUIIRE_HARD_DATA);
errorCode = device->controlWrite((uint8_t)bulkCommand->code, bulkCommand->data(), bulkCommand->getSize());
errorCode = device->controlWrite(getCommand(ControlCode::CONTROL_ACQUIIRE_HARD_DATA));
}
if (errorCode < 0) {
qWarning() << "Getting sample data failed: " << libUsbErrorString(errorCode);
Expand Down Expand Up @@ -1040,18 +1035,18 @@ Dso::ErrorCode HantekDsoControl::stringCommand(const QString &commandString) {
return Dso::ErrorCode::UNSUPPORTED;
}

void HantekDsoControl::addCommand(BulkCode code, BulkCommand *newCommand, bool pending) {
void HantekDsoControl::addCommand(BulkCommand *newCommand, bool pending) {
newCommand->pending = pending;
command[(uint8_t)code] = newCommand;
command[(uint8_t)newCommand->code] = newCommand;
newCommand->next = firstBulkCommand;
firstBulkCommand = newCommand;
}

const BulkCommand *HantekDsoControl::getCommand(BulkCode code) const { return command[(uint8_t)code]; }

void HantekDsoControl::addCommand(ControlCode code, ControlCommand *newCommand, bool pending) {
void HantekDsoControl::addCommand(ControlCommand *newCommand, bool pending) {
newCommand->pending = pending;
control[(uint8_t)code] = newCommand;
control[newCommand->code] = newCommand;
newCommand->next = firstControlCommand;
firstControlCommand = newCommand;
}
Expand Down Expand Up @@ -1087,8 +1082,7 @@ void HantekDsoControl::run() {
.arg(QString::number(control[cIndex], 16),
hexDump(this->control[control]->data(), this->control[control]->getSize())));

errorCode =
device->controlWrite((uint8_t)controlCommand->code, controlCommand->data(), controlCommand->getSize());
errorCode = device->controlWrite(controlCommand);
if (errorCode < 0) {
qWarning("Sending control command %2x failed: %s", (uint8_t)controlCommand->code,
libUsbErrorString(errorCode).toLocal8Bit().data());
Expand Down
20 changes: 8 additions & 12 deletions openhantek/src/hantekdso/hantekdsocontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
#include <QTimer>

class USBDevice;
namespace Hantek {
class BulkCommand;
class ControlCommand;
}

/// \brief The DsoControl abstraction layer for %Hantek USB DSOs.
/// TODO Please anyone, refactor this class into smaller pieces (Separation of Concerns!).
Expand Down Expand Up @@ -93,19 +89,19 @@ class HantekDsoControl : public QObject {
/// \return See ::Dso::ErrorCode.
Dso::ErrorCode stringCommand(const QString &commandString);

void addCommand(Hantek::BulkCode code, Hantek::BulkCommand* newCommand, bool pending = true);
void addCommand(BulkCommand* newCommand, bool pending = true);
template<class T> T* modifyCommand(Hantek::BulkCode code) {
command[(uint8_t)code]->pending = true;
return static_cast<T*>(command[(uint8_t)code]);
}
const Hantek::BulkCommand* getCommand(Hantek::BulkCode code) const;
const BulkCommand* getCommand(Hantek::BulkCode code) const;

void addCommand(Hantek::ControlCode code, Hantek::ControlCommand* newCommand, bool pending = true);
void addCommand(ControlCommand* newCommand, bool pending = true);
template<class T> T* modifyCommand(Hantek::ControlCode code) {
control[(uint8_t)code]->pending = true;
return static_cast<T*>(control[(uint8_t)code]);
}
const Hantek::ControlCommand* getCommand(Hantek::ControlCode code) const;
const ControlCommand* getCommand(Hantek::ControlCode code) const;
private:
bool isRollMode() const;
bool isFastRate() const;
Expand Down Expand Up @@ -167,10 +163,10 @@ class HantekDsoControl : public QObject {

private:
/// Pointers to bulk/control commands
Hantek::BulkCommand *command[255] = {0};
Hantek::BulkCommand* firstBulkCommand = nullptr;
Hantek::ControlCommand *control[255] = {0};
Hantek::ControlCommand* firstControlCommand = nullptr;
BulkCommand *command[255] = {0};
BulkCommand* firstBulkCommand = nullptr;
ControlCommand *control[255] = {0};
ControlCommand* firstControlCommand = nullptr;

// Communication with device
USBDevice *device; ///< The USB device for the oscilloscope
Expand Down
13 changes: 10 additions & 3 deletions openhantek/src/hantekdso/models/modelDSO2090.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@ ModelDSO2090::ModelDSO2090() : DSOModel(ID, 0x04b5, 0x2090, 0x04b4, 0x2090, "dso
}

void ModelDSO2090::applyRequirements(HantekDsoControl *dsoControl) const {
dsoControl->addCommand(BulkCode::SETTRIGGERANDSAMPLERATE, new BulkSetTriggerAndSamplerate());
dsoControl->addCommand(ControlCode::CONTROL_SETOFFSET, new ControlSetOffset());
dsoControl->addCommand(ControlCode::CONTROL_SETRELAYS, new ControlSetRelays());
dsoControl->addCommand(new BulkForceTrigger(), false);
dsoControl->addCommand(new BulkCaptureStart(), false);
dsoControl->addCommand(new BulkTriggerEnabled(), false);
dsoControl->addCommand(new BulkGetData(), false);
dsoControl->addCommand(new BulkGetCaptureState(), false);
dsoControl->addCommand(new BulkSetGain(), false);

dsoControl->addCommand(new BulkSetTriggerAndSamplerate(), false);
dsoControl->addCommand(new ControlSetOffset(), false);
dsoControl->addCommand(new ControlSetRelays(), false);
}

ModelDSO2090A::ModelDSO2090A() {
Expand Down
13 changes: 10 additions & 3 deletions openhantek/src/hantekdso/models/modelDSO2150.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ ModelDSO2150::ModelDSO2150() : DSOModel(ID, 0x04b5, 0x2150, 0x04b4, 0x2150, "dso
}

void ModelDSO2150::applyRequirements(HantekDsoControl *dsoControl) const {
dsoControl->addCommand(BulkCode::SETTRIGGERANDSAMPLERATE, new BulkSetTriggerAndSamplerate());
dsoControl->addCommand(ControlCode::CONTROL_SETOFFSET, new ControlSetOffset());
dsoControl->addCommand(ControlCode::CONTROL_SETRELAYS, new ControlSetRelays());
dsoControl->addCommand(new BulkForceTrigger(), false);
dsoControl->addCommand(new BulkCaptureStart(), false);
dsoControl->addCommand(new BulkTriggerEnabled(), false);
dsoControl->addCommand(new BulkGetData(), false);
dsoControl->addCommand(new BulkGetCaptureState(), false);
dsoControl->addCommand(new BulkSetGain(), false);

dsoControl->addCommand(new BulkSetTriggerAndSamplerate(), false);
dsoControl->addCommand(new ControlSetOffset(), false);
dsoControl->addCommand(new ControlSetRelays(), false);
}
21 changes: 14 additions & 7 deletions openhantek/src/hantekdso/models/modelDSO2250.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,19 @@ ModelDSO2250::ModelDSO2250() : DSOModel(ID, 0x04b5, 0x2250, 0x04b4, 0x2250, "dso
}

void ModelDSO2250::applyRequirements(HantekDsoControl *dsoControl) const {
dsoControl->addCommand(new BulkForceTrigger(), false);
dsoControl->addCommand(new BulkCaptureStart(), false);
dsoControl->addCommand(new BulkTriggerEnabled(), false);
dsoControl->addCommand(new BulkGetData(), false);
dsoControl->addCommand(new BulkGetCaptureState(), false);
dsoControl->addCommand(new BulkSetGain(), false);

// Instantiate additional commands for the DSO-2250
dsoControl->addCommand(BulkCode::BSETCHANNELS, new BulkSetChannels2250());
dsoControl->addCommand(BulkCode::CSETTRIGGERORSAMPLERATE, new BulkSetTrigger2250());
dsoControl->addCommand(BulkCode::DSETBUFFER, new BulkSetRecordLength2250());
dsoControl->addCommand(BulkCode::ESETTRIGGERORSAMPLERATE, new BulkSetSamplerate2250());
dsoControl->addCommand(BulkCode::FSETBUFFER, new BulkSetBuffer2250());
dsoControl->addCommand(ControlCode::CONTROL_SETOFFSET, new ControlSetOffset());
dsoControl->addCommand(ControlCode::CONTROL_SETRELAYS, new ControlSetRelays());
dsoControl->addCommand(new BulkSetChannels2250(), false);
dsoControl->addCommand(new BulkSetTrigger2250(), false);
dsoControl->addCommand(new BulkSetRecordLength2250(), false);
dsoControl->addCommand(new BulkSetSamplerate2250(), false);
dsoControl->addCommand(new BulkSetBuffer2250(), false);
dsoControl->addCommand(new ControlSetOffset(), false);
dsoControl->addCommand(new ControlSetRelays(), false);
}
18 changes: 12 additions & 6 deletions openhantek/src/hantekdso/models/modelDSO5200.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ ModelDSO5200::ModelDSO5200() : DSOModel(ID, 0x04b5, 0x5200, 0x04b4, 0x5200, "dso
specification.command.bulk.setSamplerate = BulkCode::CSETTRIGGERORSAMPLERATE;
specification.command.bulk.setTrigger = BulkCode::ESETTRIGGERORSAMPLERATE;
specification.command.bulk.setPretrigger = BulkCode::ESETTRIGGERORSAMPLERATE;
// specification.command.values.voltageLimits = VALUE_ETSCORRECTION;

specification.samplerate.single.base = 100e6;
specification.samplerate.single.max = 125e6;
Expand All @@ -32,12 +31,19 @@ ModelDSO5200::ModelDSO5200() : DSOModel(ID, 0x04b5, 0x5200, 0x04b4, 0x5200, "dso
}

void ModelDSO5200::applyRequirements(HantekDsoControl *dsoControl) const {
dsoControl->addCommand(new BulkForceTrigger(), false);
dsoControl->addCommand(new BulkCaptureStart(), false);
dsoControl->addCommand(new BulkTriggerEnabled(), false);
dsoControl->addCommand(new BulkGetData(), false);
dsoControl->addCommand(new BulkGetCaptureState(), false);
dsoControl->addCommand(new BulkSetGain(), false);

// Instantiate additional commands for the DSO-5200
dsoControl->addCommand(BulkCode::CSETTRIGGERORSAMPLERATE, new BulkSetSamplerate5200());
dsoControl->addCommand(BulkCode::DSETBUFFER, new BulkSetBuffer5200());
dsoControl->addCommand(BulkCode::ESETTRIGGERORSAMPLERATE, new BulkSetTrigger5200());
dsoControl->addCommand(ControlCode::CONTROL_SETOFFSET, new ControlSetOffset());
dsoControl->addCommand(ControlCode::CONTROL_SETRELAYS, new ControlSetRelays());
dsoControl->addCommand(new BulkSetSamplerate5200(), false);
dsoControl->addCommand(new BulkSetBuffer5200(), false);
dsoControl->addCommand(new BulkSetTrigger5200(), false);
dsoControl->addCommand(new ControlSetOffset(), false);
dsoControl->addCommand(new ControlSetRelays(), false);
}

ModelDSO5200A::ModelDSO5200A() {
Expand Down
13 changes: 6 additions & 7 deletions openhantek/src/hantekdso/models/modelDSO6022.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using namespace Hantek;

ModelDSO6022BE::ModelDSO6022BE() : DSOModel(ID, 0x04b5, 0x6022, 0x04b4, 0x6022, "dso6022be", "DSO-6022BE", Dso::ControlSpecification()) {
// 6022BE do not support any bulk commands
// 6022xx do not support any bulk commands
specification.useControlNoBulk = true;
specification.isSoftwareTriggerDevice = true;
specification.isFixedSamplerateDevice = true;
Expand Down Expand Up @@ -35,15 +35,14 @@ ModelDSO6022BE::ModelDSO6022BE() : DSOModel(ID, 0x04b5, 0x6022, 0x04b4, 0x6022,

specification.couplings = {Dso::Coupling::DC};
specification.triggerModes = {Dso::TriggerMode::HARDWARE_SOFTWARE, Dso::TriggerMode::SINGLE};
specification.fixedUSBinLength = 16384;
}

void ModelDSO6022BE::applyRequirements(HantekDsoControl *dsoControl) const {
dsoControl->getDevice()->overwriteInPacketLength(16384);

dsoControl->addCommand(ControlCode::CONTROL_ACQUIIRE_HARD_DATA, new ControlAcquireHardData());
dsoControl->addCommand(ControlCode::CONTROL_SETTIMEDIV, new ControlSetTimeDIV());
dsoControl->addCommand(ControlCode::CONTROL_SETVOLTDIV_CH2, new ControlSetVoltDIV_CH2());
dsoControl->addCommand(ControlCode::CONTROL_SETVOLTDIV_CH1, new ControlSetVoltDIV_CH1());
dsoControl->addCommand(new ControlAcquireHardData());
dsoControl->addCommand(new ControlSetTimeDIV());
dsoControl->addCommand(new ControlSetVoltDIV_CH2());
dsoControl->addCommand(new ControlSetVoltDIV_CH1());
}

ModelDSO6022BL::ModelDSO6022BL() {
Expand Down
Loading

0 comments on commit dc4cbc9

Please sign in to comment.