diff --git a/openhantek/src/hantekdso/controlspecification.h b/openhantek/src/hantekdso/controlspecification.h index a8933d9..859091a 100644 --- a/openhantek/src/hantekdso/controlspecification.h +++ b/openhantek/src/hantekdso/controlspecification.h @@ -94,5 +94,6 @@ struct ControlSpecification { bool supportsCaptureState = true; bool supportsOffset = true; bool supportsCouplingRelays = true; + int fixedUSBinLength = 0; }; } diff --git a/openhantek/src/hantekdso/hantekdsocontrol.cpp b/openhantek/src/hantekdso/hantekdsocontrol.cpp index 6d484b8..d3911c2 100644 --- a/openhantek/src/hantekdso/hantekdsocontrol.cpp +++ b/openhantek/src/hantekdso/hantekdsocontrol.cpp @@ -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); @@ -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; } @@ -185,8 +181,7 @@ std::vector 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); @@ -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; } @@ -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()); diff --git a/openhantek/src/hantekdso/hantekdsocontrol.h b/openhantek/src/hantekdso/hantekdsocontrol.h index 009fdba..8a64980 100644 --- a/openhantek/src/hantekdso/hantekdsocontrol.h +++ b/openhantek/src/hantekdso/hantekdsocontrol.h @@ -24,10 +24,6 @@ #include 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!). @@ -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 T* modifyCommand(Hantek::BulkCode code) { command[(uint8_t)code]->pending = true; return static_cast(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 T* modifyCommand(Hantek::ControlCode code) { control[(uint8_t)code]->pending = true; return static_cast(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; @@ -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 diff --git a/openhantek/src/hantekdso/models/modelDSO2090.cpp b/openhantek/src/hantekdso/models/modelDSO2090.cpp index 07ba3aa..811af36 100644 --- a/openhantek/src/hantekdso/models/modelDSO2090.cpp +++ b/openhantek/src/hantekdso/models/modelDSO2090.cpp @@ -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() { diff --git a/openhantek/src/hantekdso/models/modelDSO2150.cpp b/openhantek/src/hantekdso/models/modelDSO2150.cpp index b56ad5d..1858a81 100644 --- a/openhantek/src/hantekdso/models/modelDSO2150.cpp +++ b/openhantek/src/hantekdso/models/modelDSO2150.cpp @@ -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); } diff --git a/openhantek/src/hantekdso/models/modelDSO2250.cpp b/openhantek/src/hantekdso/models/modelDSO2250.cpp index da407bb..4138396 100644 --- a/openhantek/src/hantekdso/models/modelDSO2250.cpp +++ b/openhantek/src/hantekdso/models/modelDSO2250.cpp @@ -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); } diff --git a/openhantek/src/hantekdso/models/modelDSO5200.cpp b/openhantek/src/hantekdso/models/modelDSO5200.cpp index 1e10287..386c004 100644 --- a/openhantek/src/hantekdso/models/modelDSO5200.cpp +++ b/openhantek/src/hantekdso/models/modelDSO5200.cpp @@ -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; @@ -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() { diff --git a/openhantek/src/hantekdso/models/modelDSO6022.cpp b/openhantek/src/hantekdso/models/modelDSO6022.cpp index 4276e69..da2fe0d 100644 --- a/openhantek/src/hantekdso/models/modelDSO6022.cpp +++ b/openhantek/src/hantekdso/models/modelDSO6022.cpp @@ -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; @@ -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() { diff --git a/openhantek/src/hantekprotocol/bulkStructs.cpp b/openhantek/src/hantekprotocol/bulkStructs.cpp index 3bfe86b..3c9d388 100644 --- a/openhantek/src/hantekprotocol/bulkStructs.cpp +++ b/openhantek/src/hantekprotocol/bulkStructs.cpp @@ -9,13 +9,13 @@ namespace Hantek { ////////////////////////////////////////////////////////////////////////////// // class BulkSetFilter /// \brief Sets the data array to the default values. -BulkSetFilter::BulkSetFilter() : BulkCommand(8) { this->init(); } +BulkSetFilter::BulkSetFilter() : BulkCommand(BulkCode::SETFILTER, 8) { this->init(); } /// \brief Sets the FilterByte to the given value. /// \param channel1 true if channel 1 is filtered. /// \param channel2 true if channel 2 is filtered. /// \param trigger true if trigger is filtered. -BulkSetFilter::BulkSetFilter(bool channel1, bool channel2, bool trigger) : BulkCommand(8) { +BulkSetFilter::BulkSetFilter(bool channel1, bool channel2, bool trigger) : BulkCommand(BulkCode::SETFILTER, 8) { this->init(); this->setChannel(0, channel1); @@ -66,7 +66,7 @@ void BulkSetFilter::init() { ////////////////////////////////////////////////////////////////////////////// // class BulkSetTriggerAndSamplerate /// \brief Sets the data array to the default values. -BulkSetTriggerAndSamplerate::BulkSetTriggerAndSamplerate() : BulkCommand(12) { this->init(); } +BulkSetTriggerAndSamplerate::BulkSetTriggerAndSamplerate() : BulkCommand(BulkCode::SETTRIGGERANDSAMPLERATE, 12) { this->init(); } /// \brief Sets the data bytes to the specified values. /// \param downsampler The Downsampler value. @@ -82,7 +82,7 @@ BulkSetTriggerAndSamplerate::BulkSetTriggerAndSamplerate(uint16_t downsampler, u uint8_t triggerSource, uint8_t recordLength, uint8_t samplerateId, bool downsamplingMode, uint8_t usedChannels, bool fastRate, uint8_t triggerSlope) - : BulkCommand(12) { + : BulkCommand(BulkCode::SETTRIGGERANDSAMPLERATE, 12) { this->init(); this->setTriggerSource(triggerSource); @@ -201,32 +201,32 @@ void BulkSetTriggerAndSamplerate::init() { this->array[0] = (uint8_t) BulkCode:: ////////////////////////////////////////////////////////////////////////////// // class BulkForceTrigger /// \brief Sets the data array to needed values. -BulkForceTrigger::BulkForceTrigger() : BulkCommand(2) { this->array[0] = (uint8_t) BulkCode::FORCETRIGGER; } +BulkForceTrigger::BulkForceTrigger() : BulkCommand(BulkCode::FORCETRIGGER, 2) { this->array[0] = (uint8_t) BulkCode::FORCETRIGGER; } ////////////////////////////////////////////////////////////////////////////// // class BulkCaptureStart /// \brief Sets the data array to needed values. -BulkCaptureStart::BulkCaptureStart() : BulkCommand(2) { this->array[0] = (uint8_t) BulkCode::STARTSAMPLING; } +BulkCaptureStart::BulkCaptureStart() : BulkCommand(BulkCode::STARTSAMPLING, 2) { this->array[0] = (uint8_t) BulkCode::STARTSAMPLING; } ////////////////////////////////////////////////////////////////////////////// // class BulkTriggerEnabled /// \brief Sets the data array to needed values. -BulkTriggerEnabled::BulkTriggerEnabled() : BulkCommand(2) { this->array[0] = (uint8_t) BulkCode::ENABLETRIGGER; } +BulkTriggerEnabled::BulkTriggerEnabled() : BulkCommand(BulkCode::ENABLETRIGGER, 2) { this->array[0] = (uint8_t) BulkCode::ENABLETRIGGER; } ////////////////////////////////////////////////////////////////////////////// // class BulkGetData /// \brief Sets the data array to needed values. -BulkGetData::BulkGetData() : BulkCommand(2) { this->array[0] = (uint8_t) BulkCode::GETDATA; } +BulkGetData::BulkGetData() : BulkCommand(BulkCode::GETDATA, 2) { this->array[0] = (uint8_t) BulkCode::GETDATA; } ////////////////////////////////////////////////////////////////////////////// // class BulkGetCaptureState /// \brief Sets the data array to needed values. -BulkGetCaptureState::BulkGetCaptureState() : BulkCommand(2) { this->array[0] = (uint8_t) BulkCode::GETCAPTURESTATE; } +BulkGetCaptureState::BulkGetCaptureState() : BulkCommand(BulkCode::GETCAPTURESTATE, 2) { this->array[0] = (uint8_t) BulkCode::GETCAPTURESTATE; } ////////////////////////////////////////////////////////////////////////////// // class BulkResponseGetCaptureState /// \brief Initializes the array. -BulkResponseGetCaptureState::BulkResponseGetCaptureState() : BulkCommand(512) {} +BulkResponseGetCaptureState::BulkResponseGetCaptureState() : BulkCommand(BulkCode::GETCAPTURESTATE_RESPONSE, 512) {} /// \brief Gets the capture state. /// \return The CaptureState of the oscilloscope. @@ -241,12 +241,12 @@ unsigned int BulkResponseGetCaptureState::getTriggerPoint() { ////////////////////////////////////////////////////////////////////////////// // class BulkSetGain /// \brief Sets the data array to needed values. -BulkSetGain::BulkSetGain() : BulkCommand(8) { this->init(); } +BulkSetGain::BulkSetGain() : BulkCommand(BulkCode::SETGAIN, 8) { this->init(); } /// \brief Sets the gain to the given values. /// \param channel1 The gain value for channel 1. /// \param channel2 The gain value for channel 2. -BulkSetGain::BulkSetGain(uint8_t channel1, uint8_t channel2) : BulkCommand(8) { +BulkSetGain::BulkSetGain(uint8_t channel1, uint8_t channel2) : BulkCommand(BulkCode::SETGAIN, 8) { this->init(); this->setGain(0, channel1); @@ -281,11 +281,11 @@ void BulkSetGain::init() { this->array[0] = (uint8_t)BulkCode::SETGAIN; } ////////////////////////////////////////////////////////////////////////////// // class BulkSetLogicalData /// \brief Sets the data array to needed values. -BulkSetLogicalData::BulkSetLogicalData() : BulkCommand(8) { this->init(); } +BulkSetLogicalData::BulkSetLogicalData() : BulkCommand(BulkCode::SETLOGICALDATA, 8) { this->init(); } /// \brief Sets the data to the given value. /// \param data The data byte. -BulkSetLogicalData::BulkSetLogicalData(uint8_t data) : BulkCommand(8) { +BulkSetLogicalData::BulkSetLogicalData(uint8_t data) : BulkCommand(BulkCode::SETLOGICALDATA, 8) { this->init(); this->setData(data); @@ -305,16 +305,16 @@ void BulkSetLogicalData::init() { this->array[0] = (uint8_t)BulkCode::SETLOGICAL ////////////////////////////////////////////////////////////////////////////// // class BulkGetLogicalData /// \brief Sets the data array to needed values. -BulkGetLogicalData::BulkGetLogicalData() : BulkCommand(2) { this->array[0] = (uint8_t)BulkCode::GETLOGICALDATA; } +BulkGetLogicalData::BulkGetLogicalData() : BulkCommand(BulkCode::GETLOGICALDATA, 2) { this->array[0] = (uint8_t)BulkCode::GETLOGICALDATA; } ////////////////////////////////////////////////////////////////////////////// // class BulkSetFilter2250 /// \brief Sets the data array to needed values. -BulkSetChannels2250::BulkSetChannels2250() : BulkCommand(4) { this->init(); } +BulkSetChannels2250::BulkSetChannels2250() : BulkCommand(BulkCode::BSETCHANNELS, 4) { this->init(); } /// \brief Sets the used channels. /// \param usedChannels The UsedChannels value. -BulkSetChannels2250::BulkSetChannels2250(uint8_t usedChannels) : BulkCommand(4) { +BulkSetChannels2250::BulkSetChannels2250(uint8_t usedChannels) : BulkCommand(BulkCode::BSETCHANNELS, 4) { this->init(); this->setUsedChannels(usedChannels); @@ -334,12 +334,12 @@ void BulkSetChannels2250::init() { this->array[0] = (uint8_t)BulkCode::BSETCHANN ////////////////////////////////////////////////////////////////////////////// // class BulkSetTrigger2250 /// \brief Sets the data array to needed values. -BulkSetTrigger2250::BulkSetTrigger2250() : BulkCommand(8) { this->init(); } +BulkSetTrigger2250::BulkSetTrigger2250() : BulkCommand(BulkCode::CSETTRIGGERORSAMPLERATE, 8) { this->init(); } /// \brief Sets the used channels. /// \param triggerSource The trigger source id (CTriggerBits). /// \param triggerSlope The triggerSlope value (CTriggerBits). -BulkSetTrigger2250::BulkSetTrigger2250(uint8_t triggerSource, uint8_t triggerSlope) : BulkCommand(8) { +BulkSetTrigger2250::BulkSetTrigger2250(uint8_t triggerSource, uint8_t triggerSlope) : BulkCommand(BulkCode::CSETTRIGGERORSAMPLERATE, 8) { this->init(); this->setTriggerSource(triggerSource); @@ -368,12 +368,12 @@ void BulkSetTrigger2250::init() { this->array[0] = (uint8_t)BulkCode::CSETTRIGGE ////////////////////////////////////////////////////////////////////////////// // class BulkSetSamplerate5200 /// \brief Sets the data array to the default values. -BulkSetSamplerate5200::BulkSetSamplerate5200() : BulkCommand(6) { this->init(); } +BulkSetSamplerate5200::BulkSetSamplerate5200() : BulkCommand(BulkCode::CSETTRIGGERORSAMPLERATE, 6) { this->init(); } /// \brief Sets the data bytes to the specified values. /// \param samplerateSlow The SamplerateSlow value. /// \param samplerateFast The SamplerateFast value. -BulkSetSamplerate5200::BulkSetSamplerate5200(uint16_t samplerateSlow, uint8_t samplerateFast) : BulkCommand(6) { +BulkSetSamplerate5200::BulkSetSamplerate5200(uint16_t samplerateSlow, uint8_t samplerateFast) : BulkCommand(BulkCode::CSETTRIGGERORSAMPLERATE, 6) { this->init(); this->setSamplerateFast(samplerateFast); @@ -407,11 +407,11 @@ void BulkSetSamplerate5200::init() { this->array[0] = (uint8_t)BulkCode::CSETTRI ////////////////////////////////////////////////////////////////////////////// // class BulkSetBuffer2250 /// \brief Sets the data array to the default values. -BulkSetRecordLength2250::BulkSetRecordLength2250() : BulkCommand(4) { this->init(); } +BulkSetRecordLength2250::BulkSetRecordLength2250() : BulkCommand(BulkCode::DSETBUFFER, 4) { this->init(); } /// \brief Sets the data bytes to the specified values. /// \param recordLength The ::RecordLengthId value. -BulkSetRecordLength2250::BulkSetRecordLength2250(uint8_t recordLength) : BulkCommand(4) { +BulkSetRecordLength2250::BulkSetRecordLength2250(uint8_t recordLength) : BulkCommand(BulkCode::DSETBUFFER, 4) { this->init(); this->setRecordLength(recordLength); @@ -431,7 +431,7 @@ void BulkSetRecordLength2250::init() { this->array[0] = (uint8_t)BulkCode::DSETB ////////////////////////////////////////////////////////////////////////////// // class BulkSetBuffer5200 /// \brief Sets the data array to the default values. -BulkSetBuffer5200::BulkSetBuffer5200() : BulkCommand(10) { this->init(); } +BulkSetBuffer5200::BulkSetBuffer5200() : BulkCommand(BulkCode::DSETBUFFER, 10) { this->init(); } /// \brief Sets the data bytes to the specified values. /// \param triggerPositionPre The TriggerPositionPre value. @@ -441,7 +441,7 @@ BulkSetBuffer5200::BulkSetBuffer5200() : BulkCommand(10) { this->init(); } /// \param recordLength The ::RecordLengthId value. BulkSetBuffer5200::BulkSetBuffer5200(uint16_t triggerPositionPre, uint16_t triggerPositionPost, DTriggerPositionUsed usedPre, DTriggerPositionUsed usedPost, uint8_t recordLength) - : BulkCommand(10) { + : BulkCommand(BulkCode::DSETBUFFER, 10) { this->init(); this->setTriggerPositionPre(triggerPositionPre); @@ -511,14 +511,14 @@ void BulkSetBuffer5200::init() { ////////////////////////////////////////////////////////////////////////////// // class BulkSetSamplerate2250 /// \brief Sets the data array to the default values. -BulkSetSamplerate2250::BulkSetSamplerate2250() : BulkCommand(8) { this->init(); } +BulkSetSamplerate2250::BulkSetSamplerate2250() : BulkCommand(BulkCode::ESETTRIGGERORSAMPLERATE, 8) { this->init(); } /// \brief Sets the data bytes to the specified values. /// \param fastRate The fastRate state (ESamplerateBits). /// \param downsampling The downsampling state (ESamplerateBits). /// \param samplerate The Samplerate value. BulkSetSamplerate2250::BulkSetSamplerate2250(bool fastRate, bool downsampling, uint16_t samplerate) - : BulkCommand(8) { + : BulkCommand(BulkCode::ESETTRIGGERORSAMPLERATE, 8) { this->init(); this->setFastRate(fastRate); @@ -563,7 +563,7 @@ void BulkSetSamplerate2250::init() { this->array[0] = (uint8_t)BulkCode::ESETTRI ////////////////////////////////////////////////////////////////////////////// // class BulkSetTrigger5200 /// \brief Sets the data array to the default values. -BulkSetTrigger5200::BulkSetTrigger5200() : BulkCommand(8) { this->init(); } +BulkSetTrigger5200::BulkSetTrigger5200() : BulkCommand(BulkCode::ESETTRIGGERORSAMPLERATE, 8) { this->init(); } /// \brief Sets the data bytes to the specified values. /// \param triggerSource The trigger source id. @@ -573,7 +573,7 @@ BulkSetTrigger5200::BulkSetTrigger5200() : BulkCommand(8) { this->init(); } /// \param triggerPulse The triggerPulse value. BulkSetTrigger5200::BulkSetTrigger5200(uint8_t triggerSource, uint8_t usedChannels, bool fastRate, uint8_t triggerSlope, uint8_t triggerPulse) - : BulkCommand(8) { + : BulkCommand(BulkCode::ESETTRIGGERORSAMPLERATE, 8) { this->init(); this->setTriggerSource(triggerSource); @@ -633,13 +633,13 @@ void BulkSetTrigger5200::init() { /// \class BulkSetBuffer2250 hantek/types.h /// \brief The DSO-2250 BulkCode::FSETBUFFER builder. /// \brief Sets the data array to the default values. -BulkSetBuffer2250::BulkSetBuffer2250() : BulkCommand(10) { this->init(); } +BulkSetBuffer2250::BulkSetBuffer2250() : BulkCommand(BulkCode::FSETBUFFER, 10) { this->init(); } /// \brief Sets the data bytes to the specified values. /// \param triggerPositionPre The TriggerPositionPre value. /// \param triggerPositionPost The TriggerPositionPost value. BulkSetBuffer2250::BulkSetBuffer2250(uint32_t triggerPositionPre, uint32_t triggerPositionPost) - : BulkCommand(12) { + : BulkCommand(BulkCode::FSETBUFFER, 12) { this->init(); this->setTriggerPositionPre(triggerPositionPre); diff --git a/openhantek/src/hantekprotocol/bulkStructs.h b/openhantek/src/hantekprotocol/bulkStructs.h index c430fde..61dd514 100644 --- a/openhantek/src/hantekprotocol/bulkStructs.h +++ b/openhantek/src/hantekprotocol/bulkStructs.h @@ -9,20 +9,10 @@ #include "definitions.h" #include "states.h" -#include "utils/dataarray.h" +#include "usb/bulkcommand.h" namespace Hantek { -class BulkCommand : public DataArray { -protected: - BulkCommand(unsigned size): DataArray(size) {} -public: - bool pending = false; - BulkCommand* next = nullptr; -}; - -////////////////////////////////////////////////////////////////////////////// -/// \class BulkSetFilter hantek/types.h /// \brief The BULK::SETFILTER builder. class BulkSetFilter : public BulkCommand { public: @@ -38,8 +28,6 @@ class BulkSetFilter : public BulkCommand { void init(); }; -////////////////////////////////////////////////////////////////////////////// -/// \class BulkSetTriggerAndSamplerate hantek/types.h /// \brief The BulkCode::SETTRIGGERANDSAMPLERATE builder. class BulkSetTriggerAndSamplerate : public BulkCommand { public: @@ -71,48 +59,36 @@ class BulkSetTriggerAndSamplerate : public BulkCommand { void init(); }; -////////////////////////////////////////////////////////////////////////////// -/// \class BulkForceTrigger hantek/types.h /// \brief The BulkCode::FORCETRIGGER builder. class BulkForceTrigger : public BulkCommand { public: BulkForceTrigger(); }; -////////////////////////////////////////////////////////////////////////////// -/// \class BulkCaptureStart hantek/types.h /// \brief The BULK_CAPTURESTART builder. class BulkCaptureStart : public BulkCommand { public: BulkCaptureStart(); }; -////////////////////////////////////////////////////////////////////////////// -/// \class BulkTriggerEnabled hantek/types.h /// \brief The BULK_TRIGGERENABLED builder. class BulkTriggerEnabled : public BulkCommand { public: BulkTriggerEnabled(); }; -////////////////////////////////////////////////////////////////////////////// -/// \class BulkGetData hantek/types.h /// \brief The BulkCode::GETDATA builder. class BulkGetData : public BulkCommand { public: BulkGetData(); }; -////////////////////////////////////////////////////////////////////////////// -/// \class BulkGetCaptureState hantek/types.h /// \brief The BulkCode::GETCAPTURESTATE builder. class BulkGetCaptureState : public BulkCommand { public: BulkGetCaptureState(); }; -////////////////////////////////////////////////////////////////////////////// -/// \class BulkResponseGetCaptureState hantek/types.h /// \brief The parser for the BulkCode::GETCAPTURESTATE response. class BulkResponseGetCaptureState : public BulkCommand { public: @@ -122,8 +98,6 @@ class BulkResponseGetCaptureState : public BulkCommand { unsigned int getTriggerPoint(); }; -////////////////////////////////////////////////////////////////////////////// -/// \class BulkSetGain hantek/types.h /// \brief The BulkCode::SETGAIN builder. class BulkSetGain : public BulkCommand { public: @@ -137,8 +111,6 @@ class BulkSetGain : public BulkCommand { void init(); }; -////////////////////////////////////////////////////////////////////////////// -/// \class BulkSetLogicalData hantek/types.h /// \brief The BulkCode::SETLOGICALDATA builder. class BulkSetLogicalData : public BulkCommand { public: @@ -152,16 +124,12 @@ class BulkSetLogicalData : public BulkCommand { void init(); }; -////////////////////////////////////////////////////////////////////////////// -/// \class BulkGetLogicalData hantek/types.h /// \brief The BulkCode::GETLOGICALDATA builder. class BulkGetLogicalData : public BulkCommand { public: BulkGetLogicalData(); }; -////////////////////////////////////////////////////////////////////////////// -/// \class BulkSetChannels2250 hantek/types.h /// \brief The DSO-2250 BULK_BSETFILTER builder. class BulkSetChannels2250 : public BulkCommand { public: @@ -175,8 +143,6 @@ class BulkSetChannels2250 : public BulkCommand { void init(); }; -////////////////////////////////////////////////////////////////////////////// -/// \class BulkSetTrigger2250 hantek/types.h /// \brief The DSO-2250 BulkCode::CSETTRIGGERORSAMPLERATE builder. class BulkSetTrigger2250 : public BulkCommand { public: @@ -192,8 +158,6 @@ class BulkSetTrigger2250 : public BulkCommand { void init(); }; -////////////////////////////////////////////////////////////////////////////// -/// \class BulkSetSamplerate5200 hantek/types.h /// \brief The DSO-5200/DSO-5200A BulkCode::CSETTRIGGERORSAMPLERATE builder. class BulkSetSamplerate5200 : public BulkCommand { public: @@ -209,8 +173,6 @@ class BulkSetSamplerate5200 : public BulkCommand { void init(); }; -////////////////////////////////////////////////////////////////////////////// -/// \class BulkSetRecordLength2250 hantek/types.h /// \brief The DSO-2250 BulkCode::DSETBUFFER builder. class BulkSetRecordLength2250 : public BulkCommand { public: @@ -224,8 +186,6 @@ class BulkSetRecordLength2250 : public BulkCommand { void init(); }; -////////////////////////////////////////////////////////////////////////////// -/// \class BulkSetBuffer5200 hantek/types.h /// \brief The DSO-5200/DSO-5200A BulkCode::DSETBUFFER builder. class BulkSetBuffer5200 : public BulkCommand { public: @@ -248,8 +208,6 @@ class BulkSetBuffer5200 : public BulkCommand { void init(); }; -////////////////////////////////////////////////////////////////////////////// -/// \class BulkSetSamplerate2250 hantek/types.h /// \brief The DSO-2250 BulkCode::ESETTRIGGERORSAMPLERATE builder. class BulkSetSamplerate2250 : public BulkCommand { public: @@ -267,8 +225,6 @@ class BulkSetSamplerate2250 : public BulkCommand { void init(); }; -////////////////////////////////////////////////////////////////////////////// -/// \class BulkSetTrigger5200 hantek/types.h /// \brief The DSO-5200/DSO-5200A BulkCode::ESETTRIGGERORSAMPLERATE builder. class BulkSetTrigger5200 : public BulkCommand { public: @@ -291,8 +247,6 @@ class BulkSetTrigger5200 : public BulkCommand { void init(); }; -////////////////////////////////////////////////////////////////////////////// -/// \class BulkSetBuffer2250 hantek/types.h /// \brief The DSO-2250 BulkCode::FSETBUFFER builder. class BulkSetBuffer2250 : public BulkCommand { public: diff --git a/openhantek/src/hantekprotocol/bulkcode.h b/openhantek/src/hantekprotocol/bulkcode.h index 45aafae..8224fba 100644 --- a/openhantek/src/hantekprotocol/bulkcode.h +++ b/openhantek/src/hantekprotocol/bulkcode.h @@ -457,6 +457,8 @@ enum class BulkCode : uint8_t { DSETBUFFER = 0x0d, ESETTRIGGERORSAMPLERATE = 0x0e, FSETBUFFER = 0x0f, + + GETCAPTURESTATE_RESPONSE=0xfe, INVALID=0xff }; diff --git a/openhantek/src/hantekprotocol/controlStructs.cpp b/openhantek/src/hantekprotocol/controlStructs.cpp index eeaf75e..1bdfedc 100644 --- a/openhantek/src/hantekprotocol/controlStructs.cpp +++ b/openhantek/src/hantekprotocol/controlStructs.cpp @@ -3,6 +3,7 @@ #include #include "controlStructs.h" +#include "controlvalue.h" namespace Hantek { @@ -109,4 +110,14 @@ ControlSetTimeDIV::ControlSetTimeDIV() : ControlCommand(ControlCode::CONTROL_SET void ControlSetTimeDIV::setDiv(uint8_t val) { this->array[0] = val; } ControlAcquireHardData::ControlAcquireHardData() : ControlCommand(ControlCode::CONTROL_ACQUIIRE_HARD_DATA,1) { this->array[0] = 0x01; } + +ControlGetLimits::ControlGetLimits(unsigned channels) : ControlCommand(ControlCode::CONTROL_VALUE,1), offsetLimit(new OffsetsPerGainStep[channels]) { + value = (uint8_t)ControlValue::VALUE_OFFSETLIMITS; + array[0] = 0x01; +} + +ControlGetLimits::~ControlGetLimits() +{ + delete [] offsetLimit; +} } diff --git a/openhantek/src/hantekprotocol/controlStructs.h b/openhantek/src/hantekprotocol/controlStructs.h index 8702d9b..6b2403f 100644 --- a/openhantek/src/hantekprotocol/controlStructs.h +++ b/openhantek/src/hantekprotocol/controlStructs.h @@ -2,18 +2,10 @@ #include "definitions.h" #include "usb/usbdevicedefinitions.h" -#include "utils/dataarray.h" +#include "usb/controlcommand.h" #include "controlcode.h" namespace Hantek { -class ControlCommand : public DataArray { -protected: - ControlCommand(ControlCode code, unsigned size): DataArray(size), code(code) {} -public: - bool pending = false; - ControlCode code; - ControlCommand* next = nullptr; -}; struct ControlSetOffset : public ControlCommand { ControlSetOffset(); @@ -102,4 +94,10 @@ struct ControlSetTimeDIV : public ControlCommand { struct ControlAcquireHardData : public ControlCommand { ControlAcquireHardData(); }; + +struct ControlGetLimits : public ControlCommand { + OffsetsPerGainStep* offsetLimit; + ControlGetLimits(unsigned channels); + ~ControlGetLimits(); +}; } diff --git a/openhantek/src/usb/bulkcommand.cpp b/openhantek/src/usb/bulkcommand.cpp new file mode 100644 index 0000000..74023c9 --- /dev/null +++ b/openhantek/src/usb/bulkcommand.cpp @@ -0,0 +1,3 @@ +#include "bulkcommand.h" + +BulkCommand::BulkCommand(Hantek::BulkCode code, unsigned size): DataArray(size), code(code) {} diff --git a/openhantek/src/usb/bulkcommand.h b/openhantek/src/usb/bulkcommand.h new file mode 100644 index 0000000..08ba130 --- /dev/null +++ b/openhantek/src/usb/bulkcommand.h @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#pragma once + +#include +#include "dataarray.h" + +namespace Hantek { +enum class BulkCode : uint8_t; +} + +class BulkCommand : public DataArray { +protected: + BulkCommand(Hantek::BulkCode code, unsigned size); +public: + Hantek::BulkCode code; + bool pending = false; + BulkCommand* next = nullptr; +}; diff --git a/openhantek/src/usb/controlbegin.cpp b/openhantek/src/usb/controlbegin.cpp index 4e2742c..f7e2847 100644 --- a/openhantek/src/usb/controlbegin.cpp +++ b/openhantek/src/usb/controlbegin.cpp @@ -1,6 +1,7 @@ #include "controlbegin.h" +#include "hantekprotocol/controlcode.h" -ControlBeginCommand::ControlBeginCommand(BulkIndex index) : DataArray(10) { +ControlBeginCommand::ControlBeginCommand(BulkIndex index) : ControlCommand(Hantek::ControlCode::CONTROL_BEGINCOMMAND, 10) { array[0] = 0x0f; array[1] = (uint8_t)index; } diff --git a/openhantek/src/usb/controlbegin.h b/openhantek/src/usb/controlbegin.h index fd835f4..c54786c 100644 --- a/openhantek/src/usb/controlbegin.h +++ b/openhantek/src/usb/controlbegin.h @@ -2,13 +2,23 @@ // SPDX-License-Identifier: GPL-2.0+ #pragma once -#include "utils/dataarray.h" +#include "controlcommand.h" #include -#include "usbdevicedefinitions.h" + +/// \enum BulkIndex +/// \brief Can be set by CONTROL_BEGINCOMMAND, maybe it allows multiple commands +/// at the same time? +enum BulkIndex { + COMMANDINDEX_0 = 0x03, ///< Used most of the time + COMMANDINDEX_1 = 0x0a, + COMMANDINDEX_2 = 0x09, + COMMANDINDEX_3 = 0x01, ///< Used for ::BulkCode::SETTRIGGERANDSAMPLERATE sometimes + COMMANDINDEX_4 = 0x02, + COMMANDINDEX_5 = 0x08 +}; /// \class ControlBeginCommand -/// \brief The CONTROL_BEGINCOMMAND builder. -class ControlBeginCommand : public DataArray { +class ControlBeginCommand : public ControlCommand { public: /// \brief Sets the command index to the given value. /// \param index The CommandIndex for the command. diff --git a/openhantek/src/usb/controlcommand.cpp b/openhantek/src/usb/controlcommand.cpp new file mode 100644 index 0000000..56f9a7a --- /dev/null +++ b/openhantek/src/usb/controlcommand.cpp @@ -0,0 +1,3 @@ +#include "controlcommand.h" + +ControlCommand::ControlCommand(Hantek::ControlCode code, unsigned size): DataArray(size), code((uint8_t)code) {} diff --git a/openhantek/src/usb/controlcommand.h b/openhantek/src/usb/controlcommand.h new file mode 100644 index 0000000..55a7fcd --- /dev/null +++ b/openhantek/src/usb/controlcommand.h @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#pragma once + +#include +#include "dataarray.h" + +namespace Hantek { +enum class ControlCode : uint8_t; +} + +class ControlCommand : public DataArray { +protected: + ControlCommand(Hantek::ControlCode code, unsigned size); +public: + bool pending = false; + uint8_t code; + uint8_t value = 0; + ControlCommand* next = nullptr; +}; diff --git a/openhantek/src/usb/controlgetspeed.cpp b/openhantek/src/usb/controlgetspeed.cpp index 3a2a77b..15a636d 100644 --- a/openhantek/src/usb/controlgetspeed.cpp +++ b/openhantek/src/usb/controlgetspeed.cpp @@ -1,6 +1,7 @@ #include "controlgetspeed.h" +#include "hantekprotocol/controlcode.h" -ControlGetSpeed::ControlGetSpeed() : DataArray(10) {} +ControlGetSpeed::ControlGetSpeed() : ControlCommand(Hantek::ControlCode::CONTROL_GETSPEED, 10) {} ConnectionSpeed ControlGetSpeed::getSpeed() { return (ConnectionSpeed)this->array[0]; } diff --git a/openhantek/src/usb/controlgetspeed.h b/openhantek/src/usb/controlgetspeed.h index 9308511..ed7d107 100644 --- a/openhantek/src/usb/controlgetspeed.h +++ b/openhantek/src/usb/controlgetspeed.h @@ -1,14 +1,11 @@ - // SPDX-License-Identifier: GPL-2.0+ #pragma once -#include "utils/dataarray.h" -#include +#include "controlcommand.h" #include "usbdevicedefinitions.h" -/// \class ControlGetSpeed /// \brief The CONTROL_GETSPEED parser. -class ControlGetSpeed : public DataArray { +class ControlGetSpeed : public ControlCommand { public: ControlGetSpeed(); /// \brief Gets the speed of the connection. diff --git a/openhantek/src/utils/dataarray.cpp b/openhantek/src/usb/dataarray.cpp index 466a86d..466a86d 100644 --- a/openhantek/src/utils/dataarray.cpp +++ b/openhantek/src/usb/dataarray.cpp diff --git a/openhantek/src/utils/dataarray.h b/openhantek/src/usb/dataarray.h index 4677594..4677594 100644 --- a/openhantek/src/utils/dataarray.h +++ b/openhantek/src/usb/dataarray.h diff --git a/openhantek/src/usb/usbdevice.cpp b/openhantek/src/usb/usbdevice.cpp index 78cd76c..121c2b5 100644 --- a/openhantek/src/usb/usbdevice.cpp +++ b/openhantek/src/usb/usbdevice.cpp @@ -6,6 +6,8 @@ #include "usbdevice.h" +#include "hantekprotocol/controlStructs.h" +#include "hantekprotocol/bulkStructs.h" #include "controlgetspeed.h" #include "models.h" #include "utils/printutils.h" @@ -139,11 +141,6 @@ int USBDevice::bulkTransfer(unsigned char endpoint, const unsigned char *data, u return transferred; } -/// \brief Bulk write to the oscilloscope. -/// \param data Buffer for the sent/recieved data. -/// \param length The length of the packet. -/// \param attempts The number of attempts, that are done on timeouts. -/// \return Number of sent bytes on success, libusb error code on error. int USBDevice::bulkWrite(const unsigned char *data, unsigned int length, int attempts) { if (!this->handle) return LIBUSB_ERROR_NO_DEVICE; @@ -153,11 +150,6 @@ int USBDevice::bulkWrite(const unsigned char *data, unsigned int length, int att return this->bulkTransfer(HANTEK_EP_OUT, data, length, attempts); } -/// \brief Bulk read from the oscilloscope. -/// \param data Buffer for the sent/recieved data. -/// \param length The length of the packet. -/// \param attempts The number of attempts, that are done on timeouts. -/// \return Number of received bytes on success, libusb error code on error. int USBDevice::bulkRead(unsigned char *data, unsigned int length, int attempts) { if (!this->handle) return LIBUSB_ERROR_NO_DEVICE; @@ -167,29 +159,19 @@ int USBDevice::bulkRead(unsigned char *data, unsigned int length, int attempts) return this->bulkTransfer(HANTEK_EP_IN, data, length, attempts); } -/// \brief Send a bulk command to the oscilloscope. -/// \param command The command, that should be sent. -/// \param attempts The number of attempts, that are done on timeouts. -/// \return Number of sent bytes on success, libusb error code on error. int USBDevice::bulkCommand(const DataArray *command, int attempts) { if (!this->handle) return LIBUSB_ERROR_NO_DEVICE; if (!allowBulkTransfer) return LIBUSB_SUCCESS; // Send BeginCommand control command - int errorCode = this->controlWrite((uint8_t)Hantek::ControlCode::CONTROL_BEGINCOMMAND, beginCommandControl.data(), - beginCommandControl.getSize()); + int errorCode = this->controlWrite(&beginCommandControl); if (errorCode < 0) return errorCode; // Send bulk command return this->bulkWrite(command->data(), command->getSize(), attempts); } -/// \brief Multi packet bulk read from the oscilloscope. -/// \param data Buffer for the sent/recieved data. -/// \param length The length of data contained in the packets. -/// \param attempts The number of attempts, that are done on timeouts. -/// \return Number of received bytes on success, libusb error code on error. int USBDevice::bulkReadMulti(unsigned char *data, unsigned length, int attempts) { if (!this->handle) return LIBUSB_ERROR_NO_DEVICE; @@ -213,15 +195,6 @@ int USBDevice::bulkReadMulti(unsigned char *data, unsigned length, int attempts) return errorCode; } -/// \brief Control transfer to the oscilloscope. -/// \param type The request type, also sets the direction of the transfer. -/// \param request The request field of the packet. -/// \param data Buffer for the sent/recieved data. -/// \param length The length field of the packet. -/// \param value The value field of the packet. -/// \param index The index field of the packet. -/// \param attempts The number of attempts, that are done on timeouts. -/// \return Number of transferred bytes on success, libusb error code on error. int USBDevice::controlTransfer(unsigned char type, unsigned char request, unsigned char *data, unsigned int length, int value, int index, int attempts) { if (!this->handle) return LIBUSB_ERROR_NO_DEVICE; @@ -234,52 +207,29 @@ int USBDevice::controlTransfer(unsigned char type, unsigned char request, unsign return errorCode; } -/// \brief Control write to the oscilloscope. -/// \param request The request field of the packet. -/// \param data Buffer for the sent/recieved data. -/// \param length The length field of the packet. -/// \param value The value field of the packet. -/// \param index The index field of the packet. -/// \param attempts The number of attempts, that are done on timeouts. -/// \return Number of sent bytes on success, libusb error code on error. -int USBDevice::controlWrite(uint8_t request, unsigned char *data, unsigned int length, int value, int index, - int attempts) { +int USBDevice::controlWrite(const ControlCommand* command) { if (!this->handle) return LIBUSB_ERROR_NO_DEVICE; // std::cout << "control" << (int)request << " l:"<controlTransfer(LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT, request, data, length, value, index, - attempts); + return this->controlTransfer(LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT, + (uint8_t)command->code, command->data(), command->getSize(), command->value, 0, HANTEK_ATTEMPTS); } -/// \brief Control read to the oscilloscope. -/// \param request The request field of the packet. -/// \param data Buffer for the sent/recieved data. -/// \param length The length field of the packet. -/// \param value The value field of the packet. -/// \param index The index field of the packet. -/// \param attempts The number of attempts, that are done on timeouts. -/// \return Number of received bytes on success, libusb error code on error. -int USBDevice::controlRead(unsigned char request, unsigned char *data, unsigned int length, int value, int index, - int attempts) { +int USBDevice::controlRead(const ControlCommand *command) { if (!this->handle) return LIBUSB_ERROR_NO_DEVICE; - return this->controlTransfer(LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN, request, data, length, value, index, - attempts); + return this->controlTransfer(LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN, + (uint8_t)command->code, command->data(), command->getSize(), command->value, 0, HANTEK_ATTEMPTS); } -/// \brief Gets the speed of the connection. -/// \return The ::ConnectionSpeed of the USB connection. int USBDevice::getConnectionSpeed() { int errorCode; ControlGetSpeed response; - - errorCode = this->controlRead((uint8_t)Hantek::ControlCode::CONTROL_GETSPEED, response.data(), response.getSize()); + errorCode = this->controlRead(&response); if (errorCode < 0) return errorCode; return response.getSpeed(); } -/// \brief Gets the maximum size of one packet transmitted via bulk transfer. -/// \return The maximum packet size in bytes, negative libusb error code on error. int USBDevice::getPacketSize() { const int s = this->getConnectionSpeed(); if (s == CONNECTION_FULLSPEED) diff --git a/openhantek/src/usb/usbdevice.h b/openhantek/src/usb/usbdevice.h index 97aa4d4..3bb0dfb 100644 --- a/openhantek/src/usb/usbdevice.h +++ b/openhantek/src/usb/usbdevice.h @@ -11,6 +11,7 @@ #include "controlbegin.h" class DSOModel; +class ControlCommand; typedef unsigned long UniqueUSBid; @@ -28,6 +29,10 @@ class USBDevice : public QObject { /// \brief Check if the oscilloscope is connected. /// \return true, if a connection is up. bool isConnected(); + + /** + * @return Return true if this device needs a firmware first + */ bool needsFirmware(); /** @@ -37,8 +42,6 @@ class USBDevice : public QObject { void setFindIteration(unsigned iteration); unsigned getFindIteration() const; - // Various methods to handle USB transfers - /// \brief Bulk transfer to/from the oscilloscope. /// \param endpoint Endpoint number, also sets the direction of the transfer. /// \param data Buffer for the sent/recieved data. @@ -49,20 +52,72 @@ class USBDevice : public QObject { /// error. int bulkTransfer(unsigned char endpoint, const unsigned char *data, unsigned int length, int attempts = HANTEK_ATTEMPTS, unsigned int timeout = HANTEK_TIMEOUT); + + /// \brief Bulk write to the oscilloscope. + /// \param data Buffer for the sent/recieved data. + /// \param length The length of the packet. + /// \param attempts The number of attempts, that are done on timeouts. + /// \return Number of sent bytes on success, libusb error code on error. int bulkWrite(const unsigned char *data, unsigned int length, int attempts = HANTEK_ATTEMPTS); + + /// \brief Bulk read from the oscilloscope. + /// \param data Buffer for the sent/recieved data. + /// \param length The length of the packet. + /// \param attempts The number of attempts, that are done on timeouts. + /// \return Number of received bytes on success, libusb error code on error. int bulkRead(unsigned char *data, unsigned int length, int attempts = HANTEK_ATTEMPTS); + /// \brief Send a bulk command to the oscilloscope. + /// \param command The command, that should be sent. + /// \param attempts The number of attempts, that are done on timeouts. + /// \return Number of sent bytes on success, libusb error code on error. int bulkCommand(const DataArray *command, int attempts = HANTEK_ATTEMPTS); + + /// \brief Multi packet bulk read from the oscilloscope. + /// \param data Buffer for the sent/recieved data. + /// \param length The length of data contained in the packets. + /// \param attempts The number of attempts, that are done on timeouts. + /// \return Number of received bytes on success, libusb error code on error. int bulkReadMulti(unsigned char *data, unsigned length, int attempts = HANTEK_ATTEMPTS_MULTI); + /// \brief Control transfer to the oscilloscope. + /// \param type The request type, also sets the direction of the transfer. + /// \param request The request field of the packet. + /// \param data Buffer for the sent/recieved data. + /// \param length The length field of the packet. + /// \param value The value field of the packet. + /// \param index The index field of the packet. + /// \param attempts The number of attempts, that are done on timeouts. + /// \return Number of transferred bytes on success, libusb error code on error. int controlTransfer(unsigned char type, unsigned char request, unsigned char *data, unsigned int length, int value, int index, int attempts = HANTEK_ATTEMPTS); - int controlWrite(uint8_t request, unsigned char *data, unsigned int length, int value = 0, int index = 0, - int attempts = HANTEK_ATTEMPTS); - int controlRead(unsigned char request, unsigned char *data, unsigned int length, int value = 0, int index = 0, - int attempts = HANTEK_ATTEMPTS); + /// \brief Control write to the oscilloscope. + /// \param request The request field of the packet. + /// \param data Buffer for the sent/recieved data. + /// \param length The length field of the packet. + /// \param value The value field of the packet. + /// \param index The index field of the packet. + /// \param attempts The number of attempts, that are done on timeouts. + /// \return Number of sent bytes on success, libusb error code on error. + int controlWrite(const ControlCommand *command); + + /// \brief Control read to the oscilloscope. + /// \param request The request field of the packet. + /// \param data Buffer for the sent/recieved data. + /// \param length The length field of the packet. + /// \param value The value field of the packet. + /// \param index The index field of the packet. + /// \param attempts The number of attempts, that are done on timeouts. + /// \return Number of received bytes on success, libusb error code on error. + int controlRead(const ControlCommand *command); + + /// \brief Gets the speed of the connection. + /// \return The ::ConnectionSpeed of the USB connection. int getConnectionSpeed(); + + /// \brief Gets the maximum size of one packet transmitted via bulk transfer. + /// \return The maximum packet size in bytes, negative libusb error code on error. int getPacketSize(); /** diff --git a/openhantek/src/usb/usbdevicedefinitions.h b/openhantek/src/usb/usbdevicedefinitions.h index 192c7fc..efa5d1c 100644 --- a/openhantek/src/usb/usbdevicedefinitions.h +++ b/openhantek/src/usb/usbdevicedefinitions.h @@ -15,16 +15,3 @@ enum ConnectionSpeed { CONNECTION_FULLSPEED = 0, ///< FullSpeed USB, 64 byte bulk transfers CONNECTION_HIGHSPEED = 1 ///< HighSpeed USB, 512 byte bulk transfers }; - -/// \enum BulkIndex -/// \brief Can be set by CONTROL_BEGINCOMMAND, maybe it allows multiple commands -/// at the same time? -enum BulkIndex { - COMMANDINDEX_0 = 0x03, ///< Used most of the time - COMMANDINDEX_1 = 0x0a, - COMMANDINDEX_2 = 0x09, - COMMANDINDEX_3 = 0x01, ///< Used for ::BulkCode::SETTRIGGERANDSAMPLERATE sometimes - COMMANDINDEX_4 = 0x02, - COMMANDINDEX_5 = 0x08 -}; -