diff --git a/docs/adddevice.md b/docs/adddevice.md index f35dd1d..284a06c 100644 --- a/docs/adddevice.md +++ b/docs/adddevice.md @@ -53,12 +53,12 @@ The actual commands that are send, need to be defined as well, for instance: ``` c++ specification.command.control.setOffset = CONTROL_SETOFFSET; specification.command.control.setRelays = CONTROL_SETRELAYS; - specification.command.bulk.setGain = BULK_SETGAIN; - specification.command.bulk.setRecordLength = BULK_SETTRIGGERANDSAMPLERATE; - specification.command.bulk.setChannels = BULK_SETTRIGGERANDSAMPLERATE; - specification.command.bulk.setSamplerate = BULK_SETTRIGGERANDSAMPLERATE; - specification.command.bulk.setTrigger = BULK_SETTRIGGERANDSAMPLERATE; - specification.command.bulk.setPretrigger = BULK_SETTRIGGERANDSAMPLERATE; + specification.command.bulk.setGain = BulkCode::SETGAIN; + specification.command.bulk.setRecordLength = BulkCode::SETTRIGGERANDSAMPLERATE; + specification.command.bulk.setChannels = BulkCode::SETTRIGGERANDSAMPLERATE; + specification.command.bulk.setSamplerate = BulkCode::SETTRIGGERANDSAMPLERATE; + specification.command.bulk.setTrigger = BulkCode::SETTRIGGERANDSAMPLERATE; + specification.command.bulk.setPretrigger = BulkCode::SETTRIGGERANDSAMPLERATE; ``` diff --git a/openhantek/src/docks/TriggerDock.cpp b/openhantek/src/docks/TriggerDock.cpp index 25a02aa..2d3d3bb 100644 --- a/openhantek/src/docks/TriggerDock.cpp +++ b/openhantek/src/docks/TriggerDock.cpp @@ -23,14 +23,15 @@ /// \param specialTriggers The names of the special trigger sources. /// \param parent The parent widget. /// \param flags Flags for the window manager. -TriggerDock::TriggerDock(DsoSettings *settings, const QStringList *specialTriggers, QWidget *parent, +TriggerDock::TriggerDock(DsoSettings *settings, const std::vector &specialTriggers, QWidget *parent, Qt::WindowFlags flags) : QDockWidget(tr("Trigger"), parent, flags), settings(settings) { // Initialize lists for comboboxes for (unsigned int channel = 0; channel < settings->scope.physicalChannels; ++channel) this->sourceStandardStrings << tr("CH%1").arg(channel + 1); - this->sourceSpecialStrings << *specialTriggers; + for(const std::string& name: specialTriggers) + this->sourceSpecialStrings.append(QString::fromStdString(name)); // Initialize elements this->modeLabel = new QLabel(tr("Mode")); diff --git a/openhantek/src/docks/TriggerDock.h b/openhantek/src/docks/TriggerDock.h index 19f455a..451f022 100644 --- a/openhantek/src/docks/TriggerDock.h +++ b/openhantek/src/docks/TriggerDock.h @@ -19,7 +19,7 @@ class TriggerDock : public QDockWidget { Q_OBJECT public: - TriggerDock(DsoSettings *settings, const QStringList *specialTriggers, QWidget *parent, Qt::WindowFlags flags = 0); + TriggerDock(DsoSettings *settings, const std::vector& specialTriggers, QWidget *parent, Qt::WindowFlags flags = 0); int setMode(Dso::TriggerMode mode); int setSource(bool special, unsigned int id); diff --git a/openhantek/src/hantekdso/controlindexes.h b/openhantek/src/hantekdso/controlindexes.h index 4550865..6f0d2a7 100644 --- a/openhantek/src/hantekdso/controlindexes.h +++ b/openhantek/src/hantekdso/controlindexes.h @@ -8,15 +8,12 @@ namespace Hantek { /// \enum ControlIndex /// \brief The array indices for the waiting control commands. enum ControlIndex { - // CONTROLINDEX_VALUE, - // CONTROLINDEX_GETSPEED, - // CONTROLINDEX_BEGINCOMMAND, CONTROLINDEX_SETOFFSET, CONTROLINDEX_SETRELAYS, CONTROLINDEX_SETVOLTDIV_CH1, CONTROLINDEX_SETVOLTDIV_CH2, - CONTROLINDEX_SETTIMEDIV, - CONTROLINDEX_ACQUIIRE_HARD_DATA, + CONTROLINDEX_SETTIMEDIV, ///< For 6022BL/BE + CONTROLINDEX_ACQUIIRE_HARD_DATA, ///< For 6022BL/BE CONTROLINDEX_COUNT }; diff --git a/openhantek/src/hantekdso/controlsettings.h b/openhantek/src/hantekdso/controlsettings.h index af3f7a7..a03ef04 100644 --- a/openhantek/src/hantekdso/controlsettings.h +++ b/openhantek/src/hantekdso/controlsettings.h @@ -58,6 +58,8 @@ struct ControlSettings { ControlSettingsTrigger trigger; ///< The trigger settings unsigned recordLengthId = 1; ///< The id in the record length array unsigned usedChannels = 0; ///< Number of activated channels + // Software trigger, margin + const unsigned swtriggerSampleMargin = 2000; }; } diff --git a/openhantek/src/hantekdso/controlspecification.h b/openhantek/src/hantekdso/controlspecification.h index f8b6b6c..b646994 100644 --- a/openhantek/src/hantekdso/controlspecification.h +++ b/openhantek/src/hantekdso/controlspecification.h @@ -10,6 +10,9 @@ namespace Hantek { +typedef unsigned RecordLengthID; +typedef unsigned ChannelID; + ////////////////////////////////////////////////////////////////////////////// /// \struct ControlSpecificationCommandsBulk hantek/control.h /// \brief Stores the bulk command codes used for this device. @@ -29,7 +32,7 @@ struct ControlSpecificationCommandsBulk { struct ControlSpecificationCommandsControl { ControlCode setOffset = (ControlCode)-1; ///< Command for setting offset calibration data ControlCode setRelays = (ControlCode)-1; ///< Command for setting gain relays (Usually in - /// combination with BULK_SETGAIN) + /// combination with BulkCode::SETGAIN) }; ////////////////////////////////////////////////////////////////////////////// @@ -67,6 +70,23 @@ struct ControlSpecificationSamplerate { ControlSamplerateLimits multi = {100e6, 100e6, 0, std::vector()}; ///< The limits for multi channel mode }; +struct ControlSpecificationGainLevel { + /// The index of the selected gain on the hardware + unsigned char gainIndex; + /// Available voltage steps in V/screenheight + double gainSteps; +}; + +struct FixedSampleRate { + unsigned char id; + double samplerate; +}; + +struct SpecialTriggerChannel { + std::string name; + int hardwareID; +}; + ////////////////////////////////////////////////////////////////////////////// /// \struct ControlSpecification hantek/control.h /// \brief Stores the specifications of the currently connected device. @@ -76,22 +96,24 @@ struct ControlSpecification { // Limits ControlSpecificationSamplerate samplerate; ///< The samplerate specifications - std::vector bufferDividers; ///< Samplerate dividers for record lengths - std::vector gainSteps; ///< Available voltage steps in V/screenheight + std::vector bufferDividers; ///< Samplerate dividers for record lengths unsigned char sampleSize; ///< Number of bits per sample // Calibration /// The sample values at the top of the screen std::vector voltageLimit[HANTEK_CHANNELS]; - /// The index of the selected gain on the hardware - std::vector gainIndex; - std::vector gainDiv; - std::vector sampleSteps; ///< Available samplerate steps in s - std::vector sampleDiv; - /// Calibration data for the channel offsets OffsetsPerGainStep offsetLimit[HANTEK_CHANNELS]; + /// Gain levels + std::vector gain; + + /// For devices that support only fixed sample rates (isFixedSamplerateDevice=true) + std::vector fixedSampleRates; + + std::vector specialTriggerChannels; + + bool isFixedSamplerateDevice = false; bool isSoftwareTriggerDevice = false; bool useControlNoBulk = false; bool supportsCaptureState = true; diff --git a/openhantek/src/hantekdso/hantekdsocontrol.cpp b/openhantek/src/hantekdso/hantekdsocontrol.cpp index 7f9811b..0c706ee 100644 --- a/openhantek/src/hantekdso/hantekdsocontrol.cpp +++ b/openhantek/src/hantekdso/hantekdsocontrol.cpp @@ -32,10 +32,10 @@ void HantekDsoControl::startSampling() { if (!isRollMode()) emit recordTimeChanged((double)getRecordLength() / controlsettings.samplerate.current); emit samplerateChanged(controlsettings.samplerate.current); - if (specification.isSoftwareTriggerDevice) { + if (specification.isFixedSamplerateDevice) { // Convert to GUI presentable values (1e5 -> 1.0, 48e6 -> 480.0 etc) QList sampleSteps; - for (double v : specification.sampleSteps) { sampleSteps << v / 1e5; } + for (auto& v : specification.fixedSampleRates) { sampleSteps << v.samplerate / 1e5; } emit samplerateSet(1, sampleSteps); } @@ -48,7 +48,14 @@ void HantekDsoControl::stopSampling() { emit samplingStopped(); } -const QStringList *HantekDsoControl::getSpecialTriggerSources() { return &(specialTriggerSources); } +const std::vector HantekDsoControl::getSpecialTriggerSources() +{ + std::vector sources; + for (auto& v: specification.specialTriggerChannels) { + sources.push_back(v.name); + } + return sources; +} USBDevice *HantekDsoControl::getDevice() { return device; } @@ -65,12 +72,12 @@ HantekDsoControl::HantekDsoControl(USBDevice *device) : device(device), this->controlCode[CONTROLINDEX_SETRELAYS] = CONTROL_SETRELAYS; // Instantiate the commands needed for all models - command[BULK_FORCETRIGGER] = new BulkForceTrigger(); - command[BULK_STARTSAMPLING] = new BulkCaptureStart(); - command[BULK_ENABLETRIGGER] = new BulkTriggerEnabled(); - command[BULK_GETDATA] = new BulkGetData(); - command[BULK_GETCAPTURESTATE] = new BulkGetCaptureState(); - command[BULK_SETGAIN] = new BulkSetGain(); + command[(uint8_t)BulkCode::FORCETRIGGER] = new BulkForceTrigger(); + command[(uint8_t)BulkCode::STARTSAMPLING] = new BulkCaptureStart(); + command[(uint8_t)BulkCode::ENABLETRIGGER] = new BulkTriggerEnabled(); + command[(uint8_t)BulkCode::GETDATA] = new BulkGetData(); + command[(uint8_t)BulkCode::GETCAPTURESTATE] = new BulkGetCaptureState(); + command[(uint8_t)BulkCode::SETGAIN] = new BulkSetGain(); if (specification.useControlNoBulk) device->setEnableBulkTransfer(false); @@ -82,7 +89,7 @@ HantekDsoControl::HantekDsoControl(USBDevice *device) : device(device), } HantekDsoControl::~HantekDsoControl() { - for (int cIndex = 0; cIndex < BULK_COUNT; ++cIndex) { delete command[cIndex]; } + for (int cIndex = 0; cIndex < (uint8_t)BulkCode::COUNT; ++cIndex) { delete command[cIndex]; } for (int cIndex = 0; cIndex < CONTROLINDEX_COUNT; ++cIndex) { delete control[cIndex]; } } @@ -157,7 +164,7 @@ std::pair HantekDsoControl::getCaptureState() const { if (!specification.supportsCaptureState) return std::make_pair(CAPTURE_READY, 0); - errorCode = device->bulkCommand(command[BULK_GETCAPTURESTATE], 1); + errorCode = device->bulkCommand(command[(uint8_t)BulkCode::GETCAPTURESTATE], 1); if (errorCode < 0) { qWarning() << "Getting capture state failed: " << libUsbErrorString(errorCode); return std::make_pair(CAPTURE_ERROR, 0); @@ -176,7 +183,7 @@ std::pair HantekDsoControl::getCaptureState() const { std::vector HantekDsoControl::getSamples(unsigned &previousSampleCount) const { if (!specification.useControlNoBulk) { // Request data - int errorCode = device->bulkCommand(command[BULK_GETDATA], 1); + int errorCode = device->bulkCommand(command[(uint8_t)BulkCode::GETDATA], 1); if (errorCode < 0) { qWarning() << "Getting sample data failed: " << libUsbErrorString(errorCode); emit communicationError(); @@ -242,7 +249,7 @@ void HantekDsoControl::convertRawDataToSamples(const std::vector const unsigned gainID = controlsettings.voltage[channel].gain; const unsigned short limit = specification.voltageLimit[channel][gainID]; const double offset = controlsettings.voltage[channel].offsetReal; - const double gainStep = specification.gainSteps[gainID]; + const double gainStep = specification.gain[gainID].gainSteps; // Convert data from the oscilloscope and write it into the sample buffer unsigned bufferPosition = controlsettings.trigger.point * 2; @@ -275,7 +282,7 @@ void HantekDsoControl::convertRawDataToSamples(const std::vector const unsigned gainID = controlsettings.voltage[channel].gain; const unsigned short limit = specification.voltageLimit[channel][gainID]; const double offset = controlsettings.voltage[channel].offsetReal; - const double gainStep = specification.gainSteps[gainID]; + const double gainStep = specification.gain[gainID].gainSteps; // Convert data from the oscilloscope and write it into the sample buffer unsigned bufferPosition = controlsettings.trigger.point * 2; @@ -344,7 +351,7 @@ double HantekDsoControl::getBestSamplerate(double samplerate, bool fastRate, boo bestSamplerate = limits->max / specification.bufferDividers[controlsettings.recordLengthId]; } else { switch (specification.command.bulk.setSamplerate) { - case BULK_SETTRIGGERANDSAMPLERATE: + case BulkCode::SETTRIGGERANDSAMPLERATE: // DSO-2090 supports the downsampling factors 1, 2, 4 and 5 using // valueFast or all even values above using valueSlow if ((maximum && bestDownsampler <= 5.0) || (!maximum && bestDownsampler < 6.0)) { @@ -372,7 +379,7 @@ double HantekDsoControl::getBestSamplerate(double samplerate, bool fastRate, boo } break; - case BULK_CSETTRIGGERORSAMPLERATE: + case BulkCode::CSETTRIGGERORSAMPLERATE: // DSO-5200 may not supports all downsampling factors, requires testing if (maximum) { bestDownsampler = ceil(bestDownsampler); // Round up to next integer value @@ -381,7 +388,7 @@ double HantekDsoControl::getBestSamplerate(double samplerate, bool fastRate, boo } break; - case BULK_ESETTRIGGERORSAMPLERATE: + case BulkCode::ESETTRIGGERORSAMPLERATE: // DSO-2250 doesn't have a fast value, so it supports all downsampling // factors if (maximum) { @@ -421,30 +428,30 @@ unsigned HantekDsoControl::updateRecordLength(unsigned index) { if (index >= (unsigned)controlsettings.samplerate.limits->recordLengths.size()) return 0; switch (specification.command.bulk.setRecordLength) { - case BULK_SETTRIGGERANDSAMPLERATE: + case BulkCode::SETTRIGGERANDSAMPLERATE: // SetTriggerAndSamplerate bulk command for record length - static_cast(command[BULK_SETTRIGGERANDSAMPLERATE])->setRecordLength(index); - commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; + static_cast(command[(uint8_t)BulkCode::SETTRIGGERANDSAMPLERATE])->setRecordLength(index); + commandPending[(uint8_t)BulkCode::SETTRIGGERANDSAMPLERATE] = true; break; - case BULK_DSETBUFFER: - if (specification.command.bulk.setPretrigger == BULK_FSETBUFFER) { + case BulkCode::DSETBUFFER: + if (specification.command.bulk.setPretrigger == BulkCode::FSETBUFFER) { // Pointers to needed commands BulkSetRecordLength2250 *commandSetRecordLength2250 = - static_cast(command[BULK_DSETBUFFER]); + static_cast(command[(uint8_t)BulkCode::DSETBUFFER]); commandSetRecordLength2250->setRecordLength(index); } else { // SetBuffer5200 bulk command for record length - BulkSetBuffer5200 *commandSetBuffer5200 = static_cast(command[BULK_DSETBUFFER]); + BulkSetBuffer5200 *commandSetBuffer5200 = static_cast(command[(uint8_t)BulkCode::DSETBUFFER]); commandSetBuffer5200->setUsedPre(DTriggerPositionUsed::DTRIGGERPOSITION_ON); commandSetBuffer5200->setUsedPost(DTriggerPositionUsed::DTRIGGERPOSITION_ON); commandSetBuffer5200->setRecordLength(index); } - commandPending[BULK_DSETBUFFER] = true; + commandPending[(uint8_t)BulkCode::DSETBUFFER] = true; break; @@ -475,7 +482,7 @@ unsigned HantekDsoControl::updateSamplerate(unsigned downsampler, bool fastRate) // Set the calculated samplerate switch (specification.command.bulk.setSamplerate) { - case BULK_SETTRIGGERANDSAMPLERATE: { + case BulkCode::SETTRIGGERANDSAMPLERATE: { short int downsamplerValue = 0; unsigned char samplerateId = 0; bool downsampling = false; @@ -501,7 +508,7 @@ unsigned HantekDsoControl::updateSamplerate(unsigned downsampler, bool fastRate) // Pointers to needed commands BulkSetTriggerAndSamplerate *commandSetTriggerAndSamplerate = - static_cast(command[BULK_SETTRIGGERANDSAMPLERATE]); + static_cast(command[(uint8_t)BulkCode::SETTRIGGERANDSAMPLERATE]); // Store if samplerate ID or downsampling factor is used commandSetTriggerAndSamplerate->setDownsamplingMode(downsampling); @@ -512,11 +519,11 @@ unsigned HantekDsoControl::updateSamplerate(unsigned downsampler, bool fastRate) // Set fast rate when used commandSetTriggerAndSamplerate->setFastRate(false /*fastRate*/); - commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; + commandPending[(uint8_t)BulkCode::SETTRIGGERANDSAMPLERATE] = true; break; } - case BULK_CSETTRIGGERORSAMPLERATE: { + case BulkCode::CSETTRIGGERORSAMPLERATE: { // Split the resulting divider into the values understood by the device // The fast value is kept at 4 (or 3) for slow sample rates long int valueSlow = qMax(((long int)downsampler - 3) / 2, (long int)0); @@ -524,9 +531,9 @@ unsigned HantekDsoControl::updateSamplerate(unsigned downsampler, bool fastRate) // Pointers to needed commands BulkSetSamplerate5200 *commandSetSamplerate5200 = - static_cast(command[BULK_CSETTRIGGERORSAMPLERATE]); + static_cast(command[(uint8_t)BulkCode::CSETTRIGGERORSAMPLERATE]); BulkSetTrigger5200 *commandSetTrigger5200 = - static_cast(command[BULK_ESETTRIGGERORSAMPLERATE]); + static_cast(command[(uint8_t)BulkCode::ESETTRIGGERORSAMPLERATE]); // Store samplerate fast value commandSetSamplerate5200->setSamplerateFast(4 - valueFast); @@ -535,15 +542,15 @@ unsigned HantekDsoControl::updateSamplerate(unsigned downsampler, bool fastRate) // Set fast rate when used commandSetTrigger5200->setFastRate(fastRate); - commandPending[BULK_CSETTRIGGERORSAMPLERATE] = true; - commandPending[BULK_ESETTRIGGERORSAMPLERATE] = true; + commandPending[(uint8_t)BulkCode::CSETTRIGGERORSAMPLERATE] = true; + commandPending[(uint8_t)BulkCode::ESETTRIGGERORSAMPLERATE] = true; break; } - case BULK_ESETTRIGGERORSAMPLERATE: { + case BulkCode::ESETTRIGGERORSAMPLERATE: { // Pointers to needed commands BulkSetSamplerate2250 *commandSetSamplerate2250 = - static_cast(command[BULK_ESETTRIGGERORSAMPLERATE]); + static_cast(command[(uint8_t)BulkCode::ESETTRIGGERORSAMPLERATE]); bool downsampling = downsampler >= 1; // Store downsampler state value @@ -553,7 +560,7 @@ unsigned HantekDsoControl::updateSamplerate(unsigned downsampler, bool fastRate) // Set fast rate when used commandSetSamplerate2250->setFastRate(fastRate); - commandPending[BULK_ESETTRIGGERORSAMPLERATE] = true; + commandPending[(uint8_t)BulkCode::ESETTRIGGERORSAMPLERATE] = true; break; } @@ -655,19 +662,17 @@ Dso::ErrorCode HantekDsoControl::setSamplerate(double samplerate) { } } else { unsigned sampleId; - for (sampleId = 0; sampleId < specification.sampleSteps.size() - 1; ++sampleId) - if (specification.sampleSteps[sampleId] == samplerate) break; + for (sampleId = 0; sampleId < specification.fixedSampleRates.size() - 1; ++sampleId) + if (specification.fixedSampleRates[sampleId].samplerate == samplerate) break; this->controlCode[CONTROLINDEX_SETTIMEDIV] = CONTROL_SETTIMEDIV; static_cast(this->control[CONTROLINDEX_SETTIMEDIV]) - ->setDiv(specification.sampleDiv[sampleId]); + ->setDiv(specification.fixedSampleRates[sampleId].id); this->controlPending[CONTROLINDEX_SETTIMEDIV] = true; controlsettings.samplerate.current = samplerate; - // Provide margin for SW trigger - unsigned sampleMargin = 2000; // Check for Roll mode if (!isRollMode()) - emit recordTimeChanged((double)(getRecordLength() - sampleMargin) / controlsettings.samplerate.current); + emit recordTimeChanged((double)(getRecordLength() - controlsettings.swtriggerSampleMargin) / controlsettings.samplerate.current); emit samplerateChanged(controlsettings.samplerate.current); return Dso::ErrorCode::NONE; @@ -688,7 +693,7 @@ Dso::ErrorCode HantekDsoControl::setRecordTime(double duration) { controlsettings.samplerate.target.samplerateSet = false; } - if (!specification.isSoftwareTriggerDevice) { + if (!specification.isFixedSamplerateDevice) { // Calculate the maximum samplerate that would still provide the requested // duration double maxSamplerate = @@ -714,21 +719,18 @@ Dso::ErrorCode HantekDsoControl::setRecordTime(double duration) { // supported // Find highest samplerate using less than 10240 samples to obtain our // duration. - // Better add some margin for our SW trigger - unsigned sampleMargin = 2000; unsigned sampleCount = 10240; - unsigned bestId = 0; unsigned sampleId; - for (sampleId = 0; sampleId < specification.sampleSteps.size(); ++sampleId) { - if (specification.sampleSteps[sampleId] * duration < (sampleCount - sampleMargin)) bestId = sampleId; + for (sampleId = 0; sampleId < specification.fixedSampleRates.size(); ++sampleId) { + if (specification.fixedSampleRates[sampleId].samplerate * duration < + (sampleCount - controlsettings.swtriggerSampleMargin))break; } - sampleId = bestId; // Usable sample value this->controlCode[CONTROLINDEX_SETTIMEDIV] = CONTROL_SETTIMEDIV; static_cast(this->control[CONTROLINDEX_SETTIMEDIV]) - ->setDiv(specification.sampleDiv[sampleId]); + ->setDiv(specification.fixedSampleRates[sampleId].id); this->controlPending[CONTROLINDEX_SETTIMEDIV] = true; - controlsettings.samplerate.current = specification.sampleSteps[sampleId]; + controlsettings.samplerate.current = specification.fixedSampleRates[sampleId].samplerate; emit samplerateChanged(controlsettings.samplerate.current); return Dso::ErrorCode::NONE; @@ -759,7 +761,7 @@ Dso::ErrorCode HantekDsoControl::setChannelUsed(unsigned channel, bool used) { usedChannels = UsedChannels::USED_CH1CH2; } else { // DSO-2250 uses a different value for channel 2 - if (specification.command.bulk.setChannels == BULK_BSETCHANNELS) + if (specification.command.bulk.setChannels == BulkCode::BSETCHANNELS) usedChannels = UsedChannels::BUSED_CH2; else usedChannels = UsedChannels::USED_CH2; @@ -767,24 +769,24 @@ Dso::ErrorCode HantekDsoControl::setChannelUsed(unsigned channel, bool used) { } switch (specification.command.bulk.setChannels) { - case BULK_SETTRIGGERANDSAMPLERATE: { + case BulkCode::SETTRIGGERANDSAMPLERATE: { // SetTriggerAndSamplerate bulk command for trigger source - static_cast(command[BULK_SETTRIGGERANDSAMPLERATE]) + static_cast(command[(uint8_t)BulkCode::SETTRIGGERANDSAMPLERATE]) ->setUsedChannels((uint8_t)usedChannels); - commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; + commandPending[(uint8_t)BulkCode::SETTRIGGERANDSAMPLERATE] = true; break; } - case BULK_BSETCHANNELS: { + case BulkCode::BSETCHANNELS: { // SetChannels2250 bulk command for active channels - static_cast(command[BULK_BSETCHANNELS])->setUsedChannels((uint8_t)usedChannels); - commandPending[BULK_BSETCHANNELS] = true; + static_cast(command[(uint8_t)BulkCode::BSETCHANNELS])->setUsedChannels((uint8_t)usedChannels); + commandPending[(uint8_t)BulkCode::BSETCHANNELS] = true; break; } - case BULK_ESETTRIGGERORSAMPLERATE: { + case BulkCode::ESETTRIGGERORSAMPLERATE: { // SetTrigger5200s bulk command for trigger source - static_cast(command[BULK_ESETTRIGGERORSAMPLERATE])->setUsedChannels((uint8_t)usedChannels); - commandPending[BULK_ESETTRIGGERORSAMPLERATE] = true; + static_cast(command[(uint8_t)BulkCode::ESETTRIGGERORSAMPLERATE])->setUsedChannels((uint8_t)usedChannels); + commandPending[(uint8_t)BulkCode::ESETTRIGGERORSAMPLERATE] = true; break; } default: @@ -830,34 +832,34 @@ Dso::ErrorCode HantekDsoControl::setGain(unsigned channel, double gain) { if (channel >= HANTEK_CHANNELS) return Dso::ErrorCode::PARAMETER; // Find lowest gain voltage thats at least as high as the requested - unsigned gainId; - for (gainId = 0; gainId < specification.gainSteps.size() - 1; ++gainId) - if (specification.gainSteps[gainId] >= gain) break; + unsigned gainID; + for (gainID = 0; gainID < specification.gain.size() - 1; ++gainID) + if (specification.gain[gainID].gainSteps >= gain) break; if (specification.useControlNoBulk) { if (channel == 0) { static_cast(this->control[CONTROLINDEX_SETVOLTDIV_CH1]) - ->setDiv(specification.gainDiv[gainId]); + ->setDiv(specification.gain[gainID].gainIndex); this->controlPending[CONTROLINDEX_SETVOLTDIV_CH1] = true; } else if (channel == 1) { static_cast(this->control[CONTROLINDEX_SETVOLTDIV_CH2]) - ->setDiv(specification.gainDiv[gainId]); + ->setDiv(specification.gain[gainID].gainIndex); this->controlPending[CONTROLINDEX_SETVOLTDIV_CH2] = true; } else qDebug("%s: Unsuported channel: %i\n", __func__, channel); } else { // SetGain bulk command for gain - static_cast(command[BULK_SETGAIN])->setGain(channel, specification.gainIndex[gainId]); - commandPending[BULK_SETGAIN] = true; + static_cast(command[(uint8_t)BulkCode::SETGAIN])->setGain(channel, specification.gain[gainID].gainIndex); + commandPending[(uint8_t)BulkCode::SETGAIN] = true; // SetRelays control command for gain relays ControlSetRelays *controlSetRelays = static_cast(this->control[CONTROLINDEX_SETRELAYS]); - controlSetRelays->setBelow1V(channel, gainId < 3); - controlSetRelays->setBelow100mV(channel, gainId < 6); + controlSetRelays->setBelow1V(channel, gainID < 3); + controlSetRelays->setBelow100mV(channel, gainID < 6); this->controlPending[CONTROLINDEX_SETRELAYS] = true; } - controlsettings.voltage[channel].gain = gainId; + controlsettings.voltage[channel].gain = gainID; this->setOffset(channel, controlsettings.voltage[channel].offset); @@ -913,30 +915,36 @@ Dso::ErrorCode HantekDsoControl::setTriggerMode(Dso::TriggerMode mode) { /// \return See ::Dso::ErrorCode. Dso::ErrorCode HantekDsoControl::setTriggerSource(bool special, unsigned id) { if (!device->isConnected()) return Dso::ErrorCode::CONNECTION; + if (specification.isSoftwareTriggerDevice) return Dso::ErrorCode::UNSUPPORTED; - if ((!special && id >= HANTEK_CHANNELS) || (special && id >= HANTEK_SPECIAL_CHANNELS)) + if (!special && id >= HANTEK_CHANNELS) return Dso::ErrorCode::PARAMETER; + if (special && id >= specification.specialTriggerChannels.size()) + return Dso::ErrorCode::PARAMETER; + + int hardwareID = special ? specification.specialTriggerChannels[id].hardwareID:(int)id; + switch (specification.command.bulk.setTrigger) { - case BULK_SETTRIGGERANDSAMPLERATE: + case BulkCode::SETTRIGGERANDSAMPLERATE: // SetTriggerAndSamplerate bulk command for trigger source - static_cast(command[BULK_SETTRIGGERANDSAMPLERATE]) - ->setTriggerSource(special ? 3 + id : 1 - id); - commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; + static_cast(command[(uint8_t)BulkCode::SETTRIGGERANDSAMPLERATE]) + ->setTriggerSource(1 - hardwareID); + commandPending[(uint8_t)BulkCode::SETTRIGGERANDSAMPLERATE] = true; break; - case BULK_CSETTRIGGERORSAMPLERATE: + case BulkCode::CSETTRIGGERORSAMPLERATE: // SetTrigger2250 bulk command for trigger source - static_cast(command[BULK_CSETTRIGGERORSAMPLERATE]) - ->setTriggerSource(special ? 0 : 2 + id); - commandPending[BULK_CSETTRIGGERORSAMPLERATE] = true; + static_cast(command[(uint8_t)BulkCode::CSETTRIGGERORSAMPLERATE]) + ->setTriggerSource(2 + hardwareID); + commandPending[(uint8_t)BulkCode::CSETTRIGGERORSAMPLERATE] = true; break; - case BULK_ESETTRIGGERORSAMPLERATE: + case BulkCode::ESETTRIGGERORSAMPLERATE: // SetTrigger5200 bulk command for trigger source - static_cast(command[BULK_ESETTRIGGERORSAMPLERATE]) - ->setTriggerSource(special ? 3 + id : 1 - id); - commandPending[BULK_ESETTRIGGERORSAMPLERATE] = true; + static_cast(command[(uint8_t)BulkCode::ESETTRIGGERORSAMPLERATE]) + ->setTriggerSource(1 - hardwareID); + commandPending[(uint8_t)BulkCode::ESETTRIGGERORSAMPLERATE] = true; break; default: @@ -986,8 +994,9 @@ Dso::ErrorCode HantekDsoControl::setTriggerLevel(unsigned channel, double level) } // Never get out of the limits + const unsigned gainID = controlsettings.voltage[channel].gain; const double offsetReal = controlsettings.voltage[channel].offsetReal; - const double gainStep = specification.gainSteps[controlsettings.voltage[channel].gain]; + const double gainStep = specification.gain[gainID].gainSteps; unsigned short levelValue = qBound( minimum, (unsigned short)(((offsetReal + level / gainStep) * (maximum - minimum) + 0.5) + minimum), maximum); @@ -1013,22 +1022,22 @@ Dso::ErrorCode HantekDsoControl::setTriggerSlope(Dso::Slope slope) { if (slope >= Dso::SLOPE_COUNT) return Dso::ErrorCode::PARAMETER; switch (specification.command.bulk.setTrigger) { - case BULK_SETTRIGGERANDSAMPLERATE: { + case BulkCode::SETTRIGGERANDSAMPLERATE: { // SetTriggerAndSamplerate bulk command for trigger slope - static_cast(command[BULK_SETTRIGGERANDSAMPLERATE])->setTriggerSlope(slope); - commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; + static_cast(command[(uint8_t)BulkCode::SETTRIGGERANDSAMPLERATE])->setTriggerSlope(slope); + commandPending[(uint8_t)BulkCode::SETTRIGGERANDSAMPLERATE] = true; break; } - case BULK_CSETTRIGGERORSAMPLERATE: { + case BulkCode::CSETTRIGGERORSAMPLERATE: { // SetTrigger2250 bulk command for trigger slope - static_cast(command[BULK_CSETTRIGGERORSAMPLERATE])->setTriggerSlope(slope); - commandPending[BULK_CSETTRIGGERORSAMPLERATE] = true; + static_cast(command[(uint8_t)BulkCode::CSETTRIGGERORSAMPLERATE])->setTriggerSlope(slope); + commandPending[(uint8_t)BulkCode::CSETTRIGGERORSAMPLERATE] = true; break; } - case BULK_ESETTRIGGERORSAMPLERATE: { + case BulkCode::ESETTRIGGERORSAMPLERATE: { // SetTrigger5200 bulk command for trigger slope - static_cast(command[BULK_ESETTRIGGERORSAMPLERATE])->setTriggerSlope(slope); - commandPending[BULK_ESETTRIGGERORSAMPLERATE] = true; + static_cast(command[(uint8_t)BulkCode::ESETTRIGGERORSAMPLERATE])->setTriggerSlope(slope); + commandPending[(uint8_t)BulkCode::ESETTRIGGERORSAMPLERATE] = true; break; } default: @@ -1039,7 +1048,7 @@ Dso::ErrorCode HantekDsoControl::setTriggerSlope(Dso::Slope slope) { return Dso::ErrorCode::NONE; } -void HantekDsoControl::forceTrigger() { commandPending[BULK_FORCETRIGGER] = true; } +void HantekDsoControl::forceTrigger() { commandPending[(uint8_t)BulkCode::FORCETRIGGER] = true; } /// \brief Set the trigger position. /// \param position The new trigger position (in s). @@ -1054,39 +1063,39 @@ Dso::ErrorCode HantekDsoControl::setPretriggerPosition(double position) { if (controlsettings.samplerate.limits == &specification.samplerate.multi) positionSamples /= HANTEK_CHANNELS; switch (specification.command.bulk.setPretrigger) { - case BULK_SETTRIGGERANDSAMPLERATE: { + case BulkCode::SETTRIGGERANDSAMPLERATE: { // Calculate the position value (Start point depending on record length) unsigned position = isRollMode() ? 0x1 : 0x7ffff - recordLength + (unsigned)positionSamples; // SetTriggerAndSamplerate bulk command for trigger position - static_cast(command[BULK_SETTRIGGERANDSAMPLERATE])->setTriggerPosition(position); - commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; + static_cast(command[(uint8_t)BulkCode::SETTRIGGERANDSAMPLERATE])->setTriggerPosition(position); + commandPending[(uint8_t)BulkCode::SETTRIGGERANDSAMPLERATE] = true; break; } - case BULK_FSETBUFFER: { + case BulkCode::FSETBUFFER: { // Calculate the position values (Inverse, maximum is 0x7ffff) unsigned positionPre = 0x7ffff - recordLength + (unsigned)positionSamples; unsigned positionPost = 0x7ffff - (unsigned)positionSamples; // SetBuffer2250 bulk command for trigger position - BulkSetBuffer2250 *commandSetBuffer2250 = static_cast(command[BULK_FSETBUFFER]); + BulkSetBuffer2250 *commandSetBuffer2250 = static_cast(command[(uint8_t)BulkCode::FSETBUFFER]); commandSetBuffer2250->setTriggerPositionPre(positionPre); commandSetBuffer2250->setTriggerPositionPost(positionPost); - commandPending[BULK_FSETBUFFER] = true; + commandPending[(uint8_t)BulkCode::FSETBUFFER] = true; break; } - case BULK_ESETTRIGGERORSAMPLERATE: { + case BulkCode::ESETTRIGGERORSAMPLERATE: { // Calculate the position values (Inverse, maximum is 0xffff) unsigned positionPre = 0xffff - recordLength + (unsigned)positionSamples; unsigned positionPost = 0xffff - (unsigned)positionSamples; // SetBuffer5200 bulk command for trigger position - BulkSetBuffer5200 *commandSetBuffer5200 = static_cast(command[BULK_DSETBUFFER]); + BulkSetBuffer5200 *commandSetBuffer5200 = static_cast(command[(uint8_t)BulkCode::DSETBUFFER]); commandSetBuffer5200->setTriggerPositionPre((unsigned short)positionPre); commandSetBuffer5200->setTriggerPositionPost((unsigned short)positionPost); - commandPending[BULK_DSETBUFFER] = true; + commandPending[(uint8_t)BulkCode::DSETBUFFER] = true; break; } @@ -1115,7 +1124,7 @@ Dso::ErrorCode HantekDsoControl::stringCommand(const QString &commandString) { // Read command code (First byte) hexParse(commandParts[2], &commandCode, 1); - if (commandCode > BULK_COUNT) return Dso::ErrorCode::UNSUPPORTED; + if (commandCode > (uint8_t)BulkCode::COUNT) return Dso::ErrorCode::UNSUPPORTED; // Update bulk command and mark as pending hexParse(data, command[commandCode]->data(), command[commandCode]->getSize()); @@ -1146,7 +1155,7 @@ void HantekDsoControl::run() { int errorCode = 0; // Send all pending bulk commands - for (int cIndex = 0; cIndex < BULK_COUNT; ++cIndex) { + for (int cIndex = 0; cIndex < (uint8_t)BulkCode::COUNT; ++cIndex) { if (!commandPending[cIndex]) continue; timestampDebug( @@ -1200,7 +1209,7 @@ void HantekDsoControl::run() { // Sampling hasn't started, update the expected sample count this->previousSampleCount = this->getSampleCount(); - errorCode = device->bulkCommand(command[BULK_STARTSAMPLING]); + errorCode = device->bulkCommand(command[(uint8_t)BulkCode::STARTSAMPLING]); if (errorCode < 0) { if (errorCode == LIBUSB_ERROR_NO_DEVICE) { emit communicationError(); @@ -1216,7 +1225,7 @@ void HantekDsoControl::run() { break; case RollState::ENABLETRIGGER: - errorCode = device->bulkCommand(command[BULK_ENABLETRIGGER]); + errorCode = device->bulkCommand(command[(uint8_t)BulkCode::ENABLETRIGGER]); if (errorCode < 0) { if (errorCode == LIBUSB_ERROR_NO_DEVICE) { emit communicationError(); @@ -1230,7 +1239,7 @@ void HantekDsoControl::run() { break; case RollState::FORCETRIGGER: - errorCode = device->bulkCommand(command[BULK_FORCETRIGGER]); + errorCode = device->bulkCommand(command[(uint8_t)BulkCode::FORCETRIGGER]); if (errorCode < 0) { if (errorCode == LIBUSB_ERROR_NO_DEVICE) { emit communicationError(); @@ -1310,7 +1319,7 @@ void HantekDsoControl::run() { if (this->cycleCounter == this->startCycle && !isRollMode()) { // Buffer refilled completely since start of sampling, enable the // trigger now - errorCode = device->bulkCommand(command[BULK_ENABLETRIGGER]); + errorCode = device->bulkCommand(command[(uint8_t)BulkCode::ENABLETRIGGER]); if (errorCode < 0) { if (errorCode == LIBUSB_ERROR_NO_DEVICE) { emit communicationError(); @@ -1323,7 +1332,7 @@ void HantekDsoControl::run() { } else if (this->cycleCounter >= 8 + this->startCycle && controlsettings.trigger.mode == Dso::TRIGGERMODE_AUTO) { // Force triggering - errorCode = device->bulkCommand(command[BULK_FORCETRIGGER]); + errorCode = device->bulkCommand(command[(uint8_t)BulkCode::FORCETRIGGER]); if (errorCode < 0) { if (errorCode == LIBUSB_ERROR_NO_DEVICE) { emit communicationError(); @@ -1339,7 +1348,7 @@ void HantekDsoControl::run() { } // Start capturing - errorCode = device->bulkCommand(command[BULK_STARTSAMPLING]); + errorCode = device->bulkCommand(command[(uint8_t)BulkCode::STARTSAMPLING]); if (errorCode < 0) { if (errorCode == LIBUSB_ERROR_NO_DEVICE) { emit communicationError(); diff --git a/openhantek/src/hantekdso/hantekdsocontrol.h b/openhantek/src/hantekdso/hantekdsocontrol.h index 4440c08..eb20caf 100644 --- a/openhantek/src/hantekdso/hantekdsocontrol.h +++ b/openhantek/src/hantekdso/hantekdsocontrol.h @@ -8,7 +8,6 @@ #include "controlspecification.h" #include "controlsettings.h" #include "controlindexes.h" -#include "utils/dataarray.h" #include "utils/printutils.h" #include @@ -19,6 +18,10 @@ #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!). @@ -62,7 +65,7 @@ class HantekDsoControl : public QObject { double getMaxSamplerate(); /// \brief Get a list of the names of the special trigger sources. - const QStringList *getSpecialTriggerSources(); + const std::vector getSpecialTriggerSources(); /// Return the associated usb device. USBDevice *getDevice(); @@ -144,11 +147,11 @@ class HantekDsoControl : public QObject { public: // TODO redo command queues /// Pointers to bulk commands, ready to be transmitted - DataArray *command[Hantek::BULK_COUNT] = {0}; + Hantek::BulkCommand *command[(uint8_t)Hantek::BulkCode::COUNT] = {0}; /// true, when the command should be executed - bool commandPending[Hantek::BULK_COUNT] = {false}; + bool commandPending[(uint8_t)Hantek::BulkCode::COUNT] = {false}; ///< Pointers to control commands - DataArray *control[Hantek::CONTROLINDEX_COUNT] = {0}; + Hantek::ControlCommand *control[Hantek::CONTROLINDEX_COUNT] = {0}; ///< Request codes for control commands unsigned char controlCode[Hantek::CONTROLINDEX_COUNT]; ///< true, when the control command should be executed @@ -158,8 +161,6 @@ class HantekDsoControl : public QObject { USBDevice *device; ///< The USB device for the oscilloscope bool sampling = false; ///< true, if the oscilloscope is taking samples - QStringList specialTriggerSources = {tr("EXT"), tr("EXT/10")}; ///< Names of the special trigger sources - // Device setup Hantek::ControlSpecification specification; ///< The specifications of the device Hantek::ControlSettings controlsettings; ///< The current settings of the device diff --git a/openhantek/src/hantekdso/models/modelDSO2090.cpp b/openhantek/src/hantekdso/models/modelDSO2090.cpp index 06ad039..219bc03 100644 --- a/openhantek/src/hantekdso/models/modelDSO2090.cpp +++ b/openhantek/src/hantekdso/models/modelDSO2090.cpp @@ -7,12 +7,12 @@ using namespace Hantek; ModelDSO2090::ModelDSO2090() : DSOModel(ID, 0x04b5, 0x2090, 0x04b4, 0x2090, "dso2090x86", "DSO-2090", Hantek::ControlSpecification()) { specification.command.control.setOffset = CONTROL_SETOFFSET; specification.command.control.setRelays = CONTROL_SETRELAYS; - specification.command.bulk.setGain = BULK_SETGAIN; - specification.command.bulk.setRecordLength = BULK_SETTRIGGERANDSAMPLERATE; - specification.command.bulk.setChannels = BULK_SETTRIGGERANDSAMPLERATE; - specification.command.bulk.setSamplerate = BULK_SETTRIGGERANDSAMPLERATE; - specification.command.bulk.setTrigger = BULK_SETTRIGGERANDSAMPLERATE; - specification.command.bulk.setPretrigger = BULK_SETTRIGGERANDSAMPLERATE; + specification.command.bulk.setGain = BulkCode::SETGAIN; + specification.command.bulk.setRecordLength = BulkCode::SETTRIGGERANDSAMPLERATE; + specification.command.bulk.setChannels = BulkCode::SETTRIGGERANDSAMPLERATE; + specification.command.bulk.setSamplerate = BulkCode::SETTRIGGERANDSAMPLERATE; + specification.command.bulk.setTrigger = BulkCode::SETTRIGGERANDSAMPLERATE; + specification.command.bulk.setPretrigger = BulkCode::SETTRIGGERANDSAMPLERATE; specification.samplerate.single.base = 50e6; specification.samplerate.single.max = 50e6; @@ -23,16 +23,17 @@ ModelDSO2090::ModelDSO2090() : DSOModel(ID, 0x04b5, 0x2090, 0x04b4, 0x2090, "dso specification.samplerate.multi.maxDownsampler = 131072; specification.samplerate.multi.recordLengths = {UINT_MAX, 20480, 65536}; specification.bufferDividers = { 1000 , 1 , 1 }; - specification.gainSteps = { 0.08 , 0.16 , 0.40 , 0.80 , 1.60 , 4.00 , 8.0 , 16.0 , 40.0 }; specification.voltageLimit[0] = { 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 }; specification.voltageLimit[1] = { 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 }; - specification.gainIndex = { 0 , 1 , 2 , 0 , 1 , 2 , 0 , 1 , 2 }; + specification.gain = { {0,0.08} , {1,0.16} , {2,0.40} , {0,0.80} , + {1,1.60} , {2,4.00} , {0,8.00} , {1,16.00} , {2,40.00} }; specification.sampleSize = 8; + specification.specialTriggerChannels = {{"EXT", -2}, {"EXT/10", -3}}; } void ModelDSO2090::applyRequirements(HantekDsoControl *dsoControl) const { - dsoControl->command[BULK_SETTRIGGERANDSAMPLERATE] = new BulkSetTriggerAndSamplerate(); - dsoControl->commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; + dsoControl->command[(uint8_t)BulkCode::SETTRIGGERANDSAMPLERATE] = new BulkSetTriggerAndSamplerate(); + dsoControl->commandPending[(uint8_t)BulkCode::SETTRIGGERANDSAMPLERATE] = true; dsoControl->controlPending[CONTROLINDEX_SETOFFSET] = true; dsoControl->controlPending[CONTROLINDEX_SETRELAYS] = true; diff --git a/openhantek/src/hantekdso/models/modelDSO2150.cpp b/openhantek/src/hantekdso/models/modelDSO2150.cpp index ed0475e..a60baa6 100644 --- a/openhantek/src/hantekdso/models/modelDSO2150.cpp +++ b/openhantek/src/hantekdso/models/modelDSO2150.cpp @@ -7,12 +7,12 @@ using namespace Hantek; ModelDSO2150::ModelDSO2150() : DSOModel(ID, 0x04b5, 0x2150, 0x04b4, 0x2150, "dso2150x86", "DSO-2150", Hantek::ControlSpecification()) { specification.command.control.setOffset = CONTROL_SETOFFSET; specification.command.control.setRelays = CONTROL_SETRELAYS; - specification.command.bulk.setGain = BULK_SETGAIN; - specification.command.bulk.setRecordLength = BULK_SETTRIGGERANDSAMPLERATE; - specification.command.bulk.setChannels = BULK_SETTRIGGERANDSAMPLERATE; - specification.command.bulk.setSamplerate = BULK_SETTRIGGERANDSAMPLERATE; - specification.command.bulk.setTrigger = BULK_SETTRIGGERANDSAMPLERATE; - specification.command.bulk.setPretrigger = BULK_SETTRIGGERANDSAMPLERATE; + specification.command.bulk.setGain = BulkCode::SETGAIN; + specification.command.bulk.setRecordLength = BulkCode::SETTRIGGERANDSAMPLERATE; + specification.command.bulk.setChannels = BulkCode::SETTRIGGERANDSAMPLERATE; + specification.command.bulk.setSamplerate = BulkCode::SETTRIGGERANDSAMPLERATE; + specification.command.bulk.setTrigger = BulkCode::SETTRIGGERANDSAMPLERATE; + specification.command.bulk.setPretrigger = BulkCode::SETTRIGGERANDSAMPLERATE; specification.samplerate.single.base = 50e6; specification.samplerate.single.max = 75e6; @@ -23,16 +23,17 @@ ModelDSO2150::ModelDSO2150() : DSOModel(ID, 0x04b5, 0x2150, 0x04b4, 0x2150, "dso specification.samplerate.multi.maxDownsampler = 131072; specification.samplerate.multi.recordLengths = {UINT_MAX, 20480, 65536}; specification.bufferDividers = { 1000 , 1 , 1 }; - specification.gainSteps = { 0.08 , 0.16 , 0.40 , 0.80 , 1.60 , 4.00 , 8.0 , 16.0 , 40.0 }; specification.voltageLimit[0] = { 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 }; specification.voltageLimit[1] = { 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 }; - specification.gainIndex = { 0 , 1 , 2 , 0 , 1 , 2 , 0 , 1 , 2 }; + specification.gain = { {0,0.08} , {1,0.16} , {2,0.40} , {0,0.80} , + {1,1.60} , {2,4.00} , {0,8.00} , {1,16.00} , {2,40.00} }; specification.sampleSize = 8; + specification.specialTriggerChannels = {{"EXT", -2}, {"EXT/10", -3}}; } void ModelDSO2150::applyRequirements(HantekDsoControl *dsoControl) const { - dsoControl->command[BULK_SETTRIGGERANDSAMPLERATE] = new BulkSetTriggerAndSamplerate(); - dsoControl->commandPending[BULK_SETTRIGGERANDSAMPLERATE] = true; + dsoControl->command[(uint8_t)BulkCode::SETTRIGGERANDSAMPLERATE] = new BulkSetTriggerAndSamplerate(); + dsoControl->commandPending[(uint8_t)BulkCode::SETTRIGGERANDSAMPLERATE] = true; dsoControl->controlPending[CONTROLINDEX_SETOFFSET] = true; dsoControl->controlPending[CONTROLINDEX_SETRELAYS] = true; } diff --git a/openhantek/src/hantekdso/models/modelDSO2250.cpp b/openhantek/src/hantekdso/models/modelDSO2250.cpp index 5efd244..ee8ef53 100644 --- a/openhantek/src/hantekdso/models/modelDSO2250.cpp +++ b/openhantek/src/hantekdso/models/modelDSO2250.cpp @@ -7,12 +7,12 @@ using namespace Hantek; ModelDSO2250::ModelDSO2250() : DSOModel(ID, 0x04b5, 0x2250, 0x04b4, 0x2250, "dso2250x86", "DSO-2250", Hantek::ControlSpecification()) { specification.command.control.setOffset = CONTROL_SETOFFSET; specification.command.control.setRelays = CONTROL_SETRELAYS; - specification.command.bulk.setGain = BULK_SETGAIN; - specification.command.bulk.setRecordLength = BULK_DSETBUFFER; - specification.command.bulk.setChannels = BULK_BSETCHANNELS; - specification.command.bulk.setSamplerate = BULK_ESETTRIGGERORSAMPLERATE; - specification.command.bulk.setTrigger = BULK_CSETTRIGGERORSAMPLERATE; - specification.command.bulk.setPretrigger = BULK_FSETBUFFER; + specification.command.bulk.setGain = BulkCode::SETGAIN; + specification.command.bulk.setRecordLength = BulkCode::DSETBUFFER; + specification.command.bulk.setChannels = BulkCode::BSETCHANNELS; + specification.command.bulk.setSamplerate = BulkCode::ESETTRIGGERORSAMPLERATE; + specification.command.bulk.setTrigger = BulkCode::CSETTRIGGERORSAMPLERATE; + specification.command.bulk.setPretrigger = BulkCode::FSETBUFFER; specification.samplerate.single.base = 100e6; specification.samplerate.single.max = 100e6; @@ -23,25 +23,26 @@ ModelDSO2250::ModelDSO2250() : DSOModel(ID, 0x04b5, 0x2250, 0x04b4, 0x2250, "dso specification.samplerate.multi.maxDownsampler = 65536; specification.samplerate.multi.recordLengths = {UINT_MAX, 20480, 1048576}; specification.bufferDividers = { 1000 , 1 , 1 }; - specification.gainSteps = { 0.08 , 0.16 , 0.40 , 0.80 , 1.60 , 4.00 , 8.0 , 16.0 , 40.0 }; specification.voltageLimit[0] = { 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 }; specification.voltageLimit[1] = { 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 }; - specification.gainIndex = { 0 , 2 , 3 , 0 , 2 , 3 , 0 , 2 , 3 }; + specification.gain = { {0,0.08} , {2,0.16} , {3,0.40} , {0,0.80} , + {2,1.60} , {3,4.00} , {0,8.00} , {2,16.00} , {3,40.00} }; specification.sampleSize = 8; + specification.specialTriggerChannels = {{"EXT", -2}}; } void ModelDSO2250::applyRequirements(HantekDsoControl *dsoControl) const { // Instantiate additional commands for the DSO-2250 - dsoControl->command[BULK_BSETCHANNELS] = new BulkSetChannels2250(); - dsoControl->command[BULK_CSETTRIGGERORSAMPLERATE] = new BulkSetTrigger2250(); - dsoControl->command[BULK_DSETBUFFER] = new BulkSetRecordLength2250(); - dsoControl->command[BULK_ESETTRIGGERORSAMPLERATE] = new BulkSetSamplerate2250(); - dsoControl->command[BULK_FSETBUFFER] = new BulkSetBuffer2250(); - dsoControl->commandPending[BULK_BSETCHANNELS] = true; - dsoControl->commandPending[BULK_CSETTRIGGERORSAMPLERATE] = true; - dsoControl->commandPending[BULK_DSETBUFFER] = true; - dsoControl->commandPending[BULK_ESETTRIGGERORSAMPLERATE] = true; - dsoControl->commandPending[BULK_FSETBUFFER] = true; + dsoControl->command[(uint8_t)BulkCode::BSETCHANNELS] = new BulkSetChannels2250(); + dsoControl->command[(uint8_t)BulkCode::CSETTRIGGERORSAMPLERATE] = new BulkSetTrigger2250(); + dsoControl->command[(uint8_t)BulkCode::DSETBUFFER] = new BulkSetRecordLength2250(); + dsoControl->command[(uint8_t)BulkCode::ESETTRIGGERORSAMPLERATE] = new BulkSetSamplerate2250(); + dsoControl->command[(uint8_t)BulkCode::FSETBUFFER] = new BulkSetBuffer2250(); + dsoControl->commandPending[(uint8_t)BulkCode::BSETCHANNELS] = true; + dsoControl->commandPending[(uint8_t)BulkCode::CSETTRIGGERORSAMPLERATE] = true; + dsoControl->commandPending[(uint8_t)BulkCode::DSETBUFFER] = true; + dsoControl->commandPending[(uint8_t)BulkCode::ESETTRIGGERORSAMPLERATE] = true; + dsoControl->commandPending[(uint8_t)BulkCode::FSETBUFFER] = true; dsoControl->controlPending[CONTROLINDEX_SETOFFSET] = true; dsoControl->controlPending[CONTROLINDEX_SETRELAYS] = true; diff --git a/openhantek/src/hantekdso/models/modelDSO5200.cpp b/openhantek/src/hantekdso/models/modelDSO5200.cpp index 7b52786..6f31197 100644 --- a/openhantek/src/hantekdso/models/modelDSO5200.cpp +++ b/openhantek/src/hantekdso/models/modelDSO5200.cpp @@ -7,12 +7,12 @@ using namespace Hantek; ModelDSO5200::ModelDSO5200() : DSOModel(ID, 0x04b5, 0x5200, 0x04b4, 0x5200, "dso5200x86", "DSO-5200", Hantek::ControlSpecification()) { specification.command.control.setOffset = CONTROL_SETOFFSET; specification.command.control.setRelays = CONTROL_SETRELAYS; - specification.command.bulk.setGain = BULK_SETGAIN; - specification.command.bulk.setRecordLength = BULK_DSETBUFFER; - specification.command.bulk.setChannels = BULK_ESETTRIGGERORSAMPLERATE; - specification.command.bulk.setSamplerate = BULK_CSETTRIGGERORSAMPLERATE; - specification.command.bulk.setTrigger = BULK_ESETTRIGGERORSAMPLERATE; - specification.command.bulk.setPretrigger = BULK_ESETTRIGGERORSAMPLERATE; + specification.command.bulk.setGain = BulkCode::SETGAIN; + specification.command.bulk.setRecordLength = BulkCode::DSETBUFFER; + specification.command.bulk.setChannels = BulkCode::ESETTRIGGERORSAMPLERATE; + 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; @@ -24,22 +24,23 @@ ModelDSO5200::ModelDSO5200() : DSOModel(ID, 0x04b5, 0x5200, 0x04b4, 0x5200, "dso specification.samplerate.multi.maxDownsampler = 131072; specification.samplerate.multi.recordLengths = {UINT_MAX, 20480, 28672}; specification.bufferDividers = { 1000 , 1 , 1 }; - specification.gainSteps = { 0.16 , 0.40 , 0.80 , 1.60 , 4.00 , 8.0 , 16.0 , 40.0 , 80.0 }; /// \todo Use calibration data to get the DSO-5200(A) sample ranges specification.voltageLimit[0] = { 368 , 454 , 908 , 368 , 454 , 908 , 368 , 454 , 908 }; specification.voltageLimit[1] = { 368 , 454 , 908 , 368 , 454 , 908 , 368 , 454 , 908 }; - specification.gainIndex = { 1 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 }; + specification.gain = { {1,0.16} , {0,0.40} , {0,0.80} , {1,1.60} , + {0,4.00} , {0,8.00} , {1,16.0} , {0,40.0} , {0,80.0} }; specification.sampleSize = 10; + specification.specialTriggerChannels = {{"EXT", -2}, {"EXT/10", -3}}; // 3, 4 } void ModelDSO5200::applyRequirements(HantekDsoControl *dsoControl) const { // Instantiate additional commands for the DSO-5200 - dsoControl->command[BULK_CSETTRIGGERORSAMPLERATE] = new BulkSetSamplerate5200(); - dsoControl->command[BULK_DSETBUFFER] = new BulkSetBuffer5200(); - dsoControl->command[BULK_ESETTRIGGERORSAMPLERATE] = new BulkSetTrigger5200(); - dsoControl->commandPending[BULK_CSETTRIGGERORSAMPLERATE] = true; - dsoControl->commandPending[BULK_DSETBUFFER] = true; - dsoControl->commandPending[BULK_ESETTRIGGERORSAMPLERATE] = true; + dsoControl->command[(uint8_t)BulkCode::CSETTRIGGERORSAMPLERATE] = new BulkSetSamplerate5200(); + dsoControl->command[(uint8_t)BulkCode::DSETBUFFER] = new BulkSetBuffer5200(); + dsoControl->command[(uint8_t)BulkCode::ESETTRIGGERORSAMPLERATE] = new BulkSetTrigger5200(); + dsoControl->commandPending[(uint8_t)BulkCode::CSETTRIGGERORSAMPLERATE] = true; + dsoControl->commandPending[(uint8_t)BulkCode::DSETBUFFER] = true; + dsoControl->commandPending[(uint8_t)BulkCode::ESETTRIGGERORSAMPLERATE] = true; dsoControl->controlPending[CONTROLINDEX_SETOFFSET] = true; dsoControl->controlPending[CONTROLINDEX_SETRELAYS] = true; diff --git a/openhantek/src/hantekdso/models/modelDSO6022.cpp b/openhantek/src/hantekdso/models/modelDSO6022.cpp index 858e749..02ef84e 100644 --- a/openhantek/src/hantekdso/models/modelDSO6022.cpp +++ b/openhantek/src/hantekdso/models/modelDSO6022.cpp @@ -10,6 +10,7 @@ ModelDSO6022BE::ModelDSO6022BE() : DSOModel(ID, 0x04b5, 0x6022, 0x04b4, 0x6022, // 6022BE do not support any bulk commands specification.useControlNoBulk = true; specification.isSoftwareTriggerDevice = true; + specification.isFixedSamplerateDevice = true; specification.supportsCaptureState = false; specification.supportsOffset = false; specification.supportsCouplingRelays = false; @@ -23,14 +24,14 @@ ModelDSO6022BE::ModelDSO6022BE() : DSOModel(ID, 0x04b5, 0x6022, 0x04b4, 0x6022, specification.samplerate.multi.maxDownsampler = 10; specification.samplerate.multi.recordLengths = {UINT_MAX, 20480}; specification.bufferDividers = { 1000 , 1 , 1 }; - 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. specification.voltageLimit[0] = { 25 , 51 , 103 , 206 , 412 , 196 , 392 , 784 , 1000 }; specification.voltageLimit[1] = { 25 , 51 , 103 , 206 , 412 , 196 , 392 , 784 , 1000 }; // Divider. Tested and calculated results are different! - specification.gainDiv = { 10 , 10 , 10 , 10 , 10 , 2 , 2 , 2 , 1 }; - specification.sampleSteps = { 1e5 , 2e5 , 5e5 , 1e6 , 2e6 , 4e6 , 8e6 , 16e6 , 24e6 , 48e6 }; - specification.sampleDiv = { 10 , 20 , 50 , 1 , 2 , 4 , 8 , 16 , 24 , 48 }; + specification.gain = { {10,0.08} , {10,0.16} , {10,0.40} , {10,0.80} , + {10,1.60} , {2,4.00} , {2,8.00} , {2,16.00} , {1,40.00} }; + specification.fixedSampleRates = { {10,1e5} , {20,2e5} , {50,5e5} , {1,1e6} , {2,2e6} , {4,4e6} , {8,8e6} , + {16,16e6} , {24,24e6} , {48,48e6} }; specification.sampleSize = 8; } diff --git a/openhantek/src/hantekprotocol/bulkStructs.cpp b/openhantek/src/hantekprotocol/bulkStructs.cpp index 8bf7672..b2a77bc 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() : DataArray(8) { this->init(); } +BulkSetFilter::BulkSetFilter() : BulkCommand(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) : DataArray(8) { +BulkSetFilter::BulkSetFilter(bool channel1, bool channel2, bool trigger) : BulkCommand(8) { this->init(); this->setChannel(0, channel1); @@ -59,14 +59,14 @@ void BulkSetFilter::setTrigger(bool filtered) { /// \brief Initialize the array to the needed values. void BulkSetFilter::init() { - this->array[0] = BULK_SETFILTER; + this->array[0] =(uint8_t) BulkCode::SETFILTER; this->array[1] = 0x0f; } ////////////////////////////////////////////////////////////////////////////// // class BulkSetTriggerAndSamplerate /// \brief Sets the data array to the default values. -BulkSetTriggerAndSamplerate::BulkSetTriggerAndSamplerate() : DataArray(12) { this->init(); } +BulkSetTriggerAndSamplerate::BulkSetTriggerAndSamplerate() : BulkCommand(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) - : DataArray(12) { + : BulkCommand(12) { this->init(); this->setTriggerSource(triggerSource); @@ -196,37 +196,37 @@ void BulkSetTriggerAndSamplerate::setTriggerPosition(uint32_t position) { } /// \brief Initialize the array to the needed values. -void BulkSetTriggerAndSamplerate::init() { this->array[0] = BULK_SETTRIGGERANDSAMPLERATE; } +void BulkSetTriggerAndSamplerate::init() { this->array[0] = (uint8_t) BulkCode::SETTRIGGERANDSAMPLERATE; } ////////////////////////////////////////////////////////////////////////////// // class BulkForceTrigger /// \brief Sets the data array to needed values. -BulkForceTrigger::BulkForceTrigger() : DataArray(2) { this->array[0] = BULK_FORCETRIGGER; } +BulkForceTrigger::BulkForceTrigger() : BulkCommand(2) { this->array[0] = (uint8_t) BulkCode::FORCETRIGGER; } ////////////////////////////////////////////////////////////////////////////// // class BulkCaptureStart /// \brief Sets the data array to needed values. -BulkCaptureStart::BulkCaptureStart() : DataArray(2) { this->array[0] = BULK_STARTSAMPLING; } +BulkCaptureStart::BulkCaptureStart() : BulkCommand(2) { this->array[0] = (uint8_t) BulkCode::STARTSAMPLING; } ////////////////////////////////////////////////////////////////////////////// // class BulkTriggerEnabled /// \brief Sets the data array to needed values. -BulkTriggerEnabled::BulkTriggerEnabled() : DataArray(2) { this->array[0] = BULK_ENABLETRIGGER; } +BulkTriggerEnabled::BulkTriggerEnabled() : BulkCommand(2) { this->array[0] = (uint8_t) BulkCode::ENABLETRIGGER; } ////////////////////////////////////////////////////////////////////////////// // class BulkGetData /// \brief Sets the data array to needed values. -BulkGetData::BulkGetData() : DataArray(2) { this->array[0] = BULK_GETDATA; } +BulkGetData::BulkGetData() : BulkCommand(2) { this->array[0] = (uint8_t) BulkCode::GETDATA; } ////////////////////////////////////////////////////////////////////////////// // class BulkGetCaptureState /// \brief Sets the data array to needed values. -BulkGetCaptureState::BulkGetCaptureState() : DataArray(2) { this->array[0] = BULK_GETCAPTURESTATE; } +BulkGetCaptureState::BulkGetCaptureState() : BulkCommand(2) { this->array[0] = (uint8_t) BulkCode::GETCAPTURESTATE; } ////////////////////////////////////////////////////////////////////////////// // class BulkResponseGetCaptureState /// \brief Initializes the array. -BulkResponseGetCaptureState::BulkResponseGetCaptureState() : DataArray(512) {} +BulkResponseGetCaptureState::BulkResponseGetCaptureState() : BulkCommand(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() : DataArray(8) { this->init(); } +BulkSetGain::BulkSetGain() : BulkCommand(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) : DataArray(8) { +BulkSetGain::BulkSetGain(uint8_t channel1, uint8_t channel2) : BulkCommand(8) { this->init(); this->setGain(0, channel1); @@ -276,16 +276,16 @@ void BulkSetGain::setGain(unsigned int channel, uint8_t value) { } /// \brief Initialize the array to the needed values. -void BulkSetGain::init() { this->array[0] = BULK_SETGAIN; } +void BulkSetGain::init() { this->array[0] = (uint8_t)BulkCode::SETGAIN; } ////////////////////////////////////////////////////////////////////////////// // class BulkSetLogicalData /// \brief Sets the data array to needed values. -BulkSetLogicalData::BulkSetLogicalData() : DataArray(8) { this->init(); } +BulkSetLogicalData::BulkSetLogicalData() : BulkCommand(8) { this->init(); } /// \brief Sets the data to the given value. /// \param data The data byte. -BulkSetLogicalData::BulkSetLogicalData(uint8_t data) : DataArray(8) { +BulkSetLogicalData::BulkSetLogicalData(uint8_t data) : BulkCommand(8) { this->init(); this->setData(data); @@ -300,21 +300,21 @@ uint8_t BulkSetLogicalData::getData() { return this->array[2]; } void BulkSetLogicalData::setData(uint8_t data) { this->array[2] = data; } /// \brief Initialize the array to the needed values. -void BulkSetLogicalData::init() { this->array[0] = BULK_SETLOGICALDATA; } +void BulkSetLogicalData::init() { this->array[0] = (uint8_t)BulkCode::SETLOGICALDATA; } ////////////////////////////////////////////////////////////////////////////// // class BulkGetLogicalData /// \brief Sets the data array to needed values. -BulkGetLogicalData::BulkGetLogicalData() : DataArray(2) { this->array[0] = BULK_GETLOGICALDATA; } +BulkGetLogicalData::BulkGetLogicalData() : BulkCommand(2) { this->array[0] = (uint8_t)BulkCode::GETLOGICALDATA; } ////////////////////////////////////////////////////////////////////////////// // class BulkSetFilter2250 /// \brief Sets the data array to needed values. -BulkSetChannels2250::BulkSetChannels2250() : DataArray(4) { this->init(); } +BulkSetChannels2250::BulkSetChannels2250() : BulkCommand(4) { this->init(); } /// \brief Sets the used channels. /// \param usedChannels The UsedChannels value. -BulkSetChannels2250::BulkSetChannels2250(uint8_t usedChannels) : DataArray(4) { +BulkSetChannels2250::BulkSetChannels2250(uint8_t usedChannels) : BulkCommand(4) { this->init(); this->setUsedChannels(usedChannels); @@ -329,17 +329,17 @@ uint8_t BulkSetChannels2250::getUsedChannels() { return this->array[2]; } void BulkSetChannels2250::setUsedChannels(uint8_t value) { this->array[2] = value; } /// \brief Initialize the array to the needed values. -void BulkSetChannels2250::init() { this->array[0] = BULK_BSETCHANNELS; } +void BulkSetChannels2250::init() { this->array[0] = (uint8_t)BulkCode::BSETCHANNELS; } ////////////////////////////////////////////////////////////////////////////// // class BulkSetTrigger2250 /// \brief Sets the data array to needed values. -BulkSetTrigger2250::BulkSetTrigger2250() : DataArray(8) { this->init(); } +BulkSetTrigger2250::BulkSetTrigger2250() : BulkCommand(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) : DataArray(8) { +BulkSetTrigger2250::BulkSetTrigger2250(uint8_t triggerSource, uint8_t triggerSlope) : BulkCommand(8) { this->init(); this->setTriggerSource(triggerSource); @@ -363,17 +363,17 @@ uint8_t BulkSetTrigger2250::getTriggerSlope() { return ((CTriggerBits *)&(this-> void BulkSetTrigger2250::setTriggerSlope(uint8_t slope) { ((CTriggerBits *)&(this->array[2]))->triggerSlope = slope; } /// \brief Initialize the array to the needed values. -void BulkSetTrigger2250::init() { this->array[0] = BULK_CSETTRIGGERORSAMPLERATE; } +void BulkSetTrigger2250::init() { this->array[0] = (uint8_t)BulkCode::CSETTRIGGERORSAMPLERATE; } ////////////////////////////////////////////////////////////////////////////// // class BulkSetSamplerate5200 /// \brief Sets the data array to the default values. -BulkSetSamplerate5200::BulkSetSamplerate5200() : DataArray(6) { this->init(); } +BulkSetSamplerate5200::BulkSetSamplerate5200() : BulkCommand(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) : DataArray(6) { +BulkSetSamplerate5200::BulkSetSamplerate5200(uint16_t samplerateSlow, uint8_t samplerateFast) : BulkCommand(6) { this->init(); this->setSamplerateFast(samplerateFast); @@ -402,16 +402,16 @@ void BulkSetSamplerate5200::setSamplerateSlow(uint16_t samplerate) { } /// \brief Initialize the array to the needed values. -void BulkSetSamplerate5200::init() { this->array[0] = BULK_CSETTRIGGERORSAMPLERATE; } +void BulkSetSamplerate5200::init() { this->array[0] = (uint8_t)BulkCode::CSETTRIGGERORSAMPLERATE; } ////////////////////////////////////////////////////////////////////////////// // class BulkSetBuffer2250 /// \brief Sets the data array to the default values. -BulkSetRecordLength2250::BulkSetRecordLength2250() : DataArray(4) { this->init(); } +BulkSetRecordLength2250::BulkSetRecordLength2250() : BulkCommand(4) { this->init(); } /// \brief Sets the data bytes to the specified values. /// \param recordLength The ::RecordLengthId value. -BulkSetRecordLength2250::BulkSetRecordLength2250(uint8_t recordLength) : DataArray(4) { +BulkSetRecordLength2250::BulkSetRecordLength2250(uint8_t recordLength) : BulkCommand(4) { this->init(); this->setRecordLength(recordLength); @@ -426,12 +426,12 @@ uint8_t BulkSetRecordLength2250::getRecordLength() { return this->array[2]; } void BulkSetRecordLength2250::setRecordLength(uint8_t value) { this->array[2] = value; } /// \brief Initialize the array to the needed values. -void BulkSetRecordLength2250::init() { this->array[0] = BULK_DSETBUFFER; } +void BulkSetRecordLength2250::init() { this->array[0] = (uint8_t)BulkCode::DSETBUFFER; } ////////////////////////////////////////////////////////////////////////////// // class BulkSetBuffer5200 /// \brief Sets the data array to the default values. -BulkSetBuffer5200::BulkSetBuffer5200() : DataArray(10) { this->init(); } +BulkSetBuffer5200::BulkSetBuffer5200() : BulkCommand(10) { this->init(); } /// \brief Sets the data bytes to the specified values. /// \param triggerPositionPre The TriggerPositionPre value. @@ -441,7 +441,7 @@ BulkSetBuffer5200::BulkSetBuffer5200() : DataArray(10) { this->init(); /// \param recordLength The ::RecordLengthId value. BulkSetBuffer5200::BulkSetBuffer5200(uint16_t triggerPositionPre, uint16_t triggerPositionPost, DTriggerPositionUsed usedPre, DTriggerPositionUsed usedPost, uint8_t recordLength) - : DataArray(10) { + : BulkCommand(10) { this->init(); this->setTriggerPositionPre(triggerPositionPre); @@ -503,7 +503,7 @@ void BulkSetBuffer5200::setRecordLength(uint8_t value) { ((DBufferBits *)&(this- /// \brief Initialize the array to the needed values. void BulkSetBuffer5200::init() { - this->array[0] = BULK_DSETBUFFER; + this->array[0] = (uint8_t)BulkCode::DSETBUFFER; this->array[5] = 0xff; this->array[9] = 0xff; } @@ -511,14 +511,14 @@ void BulkSetBuffer5200::init() { ////////////////////////////////////////////////////////////////////////////// // class BulkSetSamplerate2250 /// \brief Sets the data array to the default values. -BulkSetSamplerate2250::BulkSetSamplerate2250() : DataArray(8) { this->init(); } +BulkSetSamplerate2250::BulkSetSamplerate2250() : BulkCommand(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) - : DataArray(8) { + : BulkCommand(8) { this->init(); this->setFastRate(fastRate); @@ -558,12 +558,12 @@ void BulkSetSamplerate2250::setSamplerate(uint16_t samplerate) { } /// \brief Initialize the array to the needed values. -void BulkSetSamplerate2250::init() { this->array[0] = BULK_ESETTRIGGERORSAMPLERATE; } +void BulkSetSamplerate2250::init() { this->array[0] = (uint8_t)BulkCode::ESETTRIGGERORSAMPLERATE; } ////////////////////////////////////////////////////////////////////////////// // class BulkSetTrigger5200 /// \brief Sets the data array to the default values. -BulkSetTrigger5200::BulkSetTrigger5200() : DataArray(8) { this->init(); } +BulkSetTrigger5200::BulkSetTrigger5200() : BulkCommand(8) { this->init(); } /// \brief Sets the data bytes to the specified values. /// \param triggerSource The trigger source id. @@ -573,7 +573,7 @@ BulkSetTrigger5200::BulkSetTrigger5200() : DataArray(8) { this->init(); /// \param triggerPulse The triggerPulse value. BulkSetTrigger5200::BulkSetTrigger5200(uint8_t triggerSource, uint8_t usedChannels, bool fastRate, uint8_t triggerSlope, uint8_t triggerPulse) - : DataArray(8) { + : BulkCommand(8) { this->init(); this->setTriggerSource(triggerSource); @@ -625,21 +625,21 @@ void BulkSetTrigger5200::setTriggerPulse(bool pulse) { ((ETsrBits *)&(this->arra /// \brief Initialize the array to the needed values. void BulkSetTrigger5200::init() { - this->array[0] = BULK_ESETTRIGGERORSAMPLERATE; + this->array[0] = (uint8_t)BulkCode::ESETTRIGGERORSAMPLERATE; this->array[4] = 0x02; } ////////////////////////////////////////////////////////////////////////////// /// \class BulkSetBuffer2250 hantek/types.h -/// \brief The DSO-2250 BULK_FSETBUFFER builder. +/// \brief The DSO-2250 BulkCode::FSETBUFFER builder. /// \brief Sets the data array to the default values. -BulkSetBuffer2250::BulkSetBuffer2250() : DataArray(10) { this->init(); } +BulkSetBuffer2250::BulkSetBuffer2250() : BulkCommand(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) - : DataArray(12) { + : BulkCommand(12) { this->init(); this->setTriggerPositionPre(triggerPositionPre); @@ -675,5 +675,5 @@ void BulkSetBuffer2250::setTriggerPositionPre(uint32_t position) { } /// \brief Initialize the array to the needed values. -void BulkSetBuffer2250::init() { this->array[0] = BULK_FSETBUFFER; } +void BulkSetBuffer2250::init() { this->array[0] = (uint8_t)BulkCode::FSETBUFFER; } } diff --git a/openhantek/src/hantekprotocol/bulkStructs.h b/openhantek/src/hantekprotocol/bulkStructs.h index 3402934..65276a6 100644 --- a/openhantek/src/hantekprotocol/bulkStructs.h +++ b/openhantek/src/hantekprotocol/bulkStructs.h @@ -13,10 +13,15 @@ namespace Hantek { +class BulkCommand : public DataArray { +protected: + BulkCommand(unsigned size): DataArray(size) {} +}; + ////////////////////////////////////////////////////////////////////////////// /// \class BulkSetFilter hantek/types.h -/// \brief The BULK_SETFILTER builder. -class BulkSetFilter : public DataArray { +/// \brief The BULK::SETFILTER builder. +class BulkSetFilter : public BulkCommand { public: BulkSetFilter(); BulkSetFilter(bool channel1, bool channel2, bool trigger); @@ -32,8 +37,8 @@ class BulkSetFilter : public DataArray { ////////////////////////////////////////////////////////////////////////////// /// \class BulkSetTriggerAndSamplerate hantek/types.h -/// \brief The BULK_SETTRIGGERANDSAMPLERATE builder. -class BulkSetTriggerAndSamplerate : public DataArray { +/// \brief The BulkCode::SETTRIGGERANDSAMPLERATE builder. +class BulkSetTriggerAndSamplerate : public BulkCommand { public: BulkSetTriggerAndSamplerate(); BulkSetTriggerAndSamplerate(uint16_t downsampler, uint32_t triggerPosition, uint8_t triggerSource = 0, @@ -65,8 +70,8 @@ class BulkSetTriggerAndSamplerate : public DataArray { ////////////////////////////////////////////////////////////////////////////// /// \class BulkForceTrigger hantek/types.h -/// \brief The BULK_FORCETRIGGER builder. -class BulkForceTrigger : public DataArray { +/// \brief The BulkCode::FORCETRIGGER builder. +class BulkForceTrigger : public BulkCommand { public: BulkForceTrigger(); }; @@ -74,7 +79,7 @@ class BulkForceTrigger : public DataArray { ////////////////////////////////////////////////////////////////////////////// /// \class BulkCaptureStart hantek/types.h /// \brief The BULK_CAPTURESTART builder. -class BulkCaptureStart : public DataArray { +class BulkCaptureStart : public BulkCommand { public: BulkCaptureStart(); }; @@ -82,31 +87,31 @@ class BulkCaptureStart : public DataArray { ////////////////////////////////////////////////////////////////////////////// /// \class BulkTriggerEnabled hantek/types.h /// \brief The BULK_TRIGGERENABLED builder. -class BulkTriggerEnabled : public DataArray { +class BulkTriggerEnabled : public BulkCommand { public: BulkTriggerEnabled(); }; ////////////////////////////////////////////////////////////////////////////// /// \class BulkGetData hantek/types.h -/// \brief The BULK_GETDATA builder. -class BulkGetData : public DataArray { +/// \brief The BulkCode::GETDATA builder. +class BulkGetData : public BulkCommand { public: BulkGetData(); }; ////////////////////////////////////////////////////////////////////////////// /// \class BulkGetCaptureState hantek/types.h -/// \brief The BULK_GETCAPTURESTATE builder. -class BulkGetCaptureState : public DataArray { +/// \brief The BulkCode::GETCAPTURESTATE builder. +class BulkGetCaptureState : public BulkCommand { public: BulkGetCaptureState(); }; ////////////////////////////////////////////////////////////////////////////// /// \class BulkResponseGetCaptureState hantek/types.h -/// \brief The parser for the BULK_GETCAPTURESTATE response. -class BulkResponseGetCaptureState : public DataArray { +/// \brief The parser for the BulkCode::GETCAPTURESTATE response. +class BulkResponseGetCaptureState : public BulkCommand { public: BulkResponseGetCaptureState(); @@ -116,8 +121,8 @@ class BulkResponseGetCaptureState : public DataArray { ////////////////////////////////////////////////////////////////////////////// /// \class BulkSetGain hantek/types.h -/// \brief The BULK_SETGAIN builder. -class BulkSetGain : public DataArray { +/// \brief The BulkCode::SETGAIN builder. +class BulkSetGain : public BulkCommand { public: BulkSetGain(); BulkSetGain(uint8_t channel1, uint8_t channel2); @@ -131,8 +136,8 @@ class BulkSetGain : public DataArray { ////////////////////////////////////////////////////////////////////////////// /// \class BulkSetLogicalData hantek/types.h -/// \brief The BULK_SETLOGICALDATA builder. -class BulkSetLogicalData : public DataArray { +/// \brief The BulkCode::SETLOGICALDATA builder. +class BulkSetLogicalData : public BulkCommand { public: BulkSetLogicalData(); BulkSetLogicalData(uint8_t data); @@ -146,8 +151,8 @@ class BulkSetLogicalData : public DataArray { ////////////////////////////////////////////////////////////////////////////// /// \class BulkGetLogicalData hantek/types.h -/// \brief The BULK_GETLOGICALDATA builder. -class BulkGetLogicalData : public DataArray { +/// \brief The BulkCode::GETLOGICALDATA builder. +class BulkGetLogicalData : public BulkCommand { public: BulkGetLogicalData(); }; @@ -155,7 +160,7 @@ class BulkGetLogicalData : public DataArray { ////////////////////////////////////////////////////////////////////////////// /// \class BulkSetChannels2250 hantek/types.h /// \brief The DSO-2250 BULK_BSETFILTER builder. -class BulkSetChannels2250 : public DataArray { +class BulkSetChannels2250 : public BulkCommand { public: BulkSetChannels2250(); BulkSetChannels2250(uint8_t usedChannels); @@ -169,8 +174,8 @@ class BulkSetChannels2250 : public DataArray { ////////////////////////////////////////////////////////////////////////////// /// \class BulkSetTrigger2250 hantek/types.h -/// \brief The DSO-2250 BULK_CSETTRIGGERORSAMPLERATE builder. -class BulkSetTrigger2250 : public DataArray { +/// \brief The DSO-2250 BulkCode::CSETTRIGGERORSAMPLERATE builder. +class BulkSetTrigger2250 : public BulkCommand { public: BulkSetTrigger2250(); BulkSetTrigger2250(uint8_t triggerSource, uint8_t triggerSlope); @@ -186,8 +191,8 @@ class BulkSetTrigger2250 : public DataArray { ////////////////////////////////////////////////////////////////////////////// /// \class BulkSetSamplerate5200 hantek/types.h -/// \brief The DSO-5200/DSO-5200A BULK_CSETTRIGGERORSAMPLERATE builder. -class BulkSetSamplerate5200 : public DataArray { +/// \brief The DSO-5200/DSO-5200A BulkCode::CSETTRIGGERORSAMPLERATE builder. +class BulkSetSamplerate5200 : public BulkCommand { public: BulkSetSamplerate5200(); BulkSetSamplerate5200(uint16_t samplerateSlow, uint8_t samplerateFast); @@ -203,8 +208,8 @@ class BulkSetSamplerate5200 : public DataArray { ////////////////////////////////////////////////////////////////////////////// /// \class BulkSetRecordLength2250 hantek/types.h -/// \brief The DSO-2250 BULK_DSETBUFFER builder. -class BulkSetRecordLength2250 : public DataArray { +/// \brief The DSO-2250 BulkCode::DSETBUFFER builder. +class BulkSetRecordLength2250 : public BulkCommand { public: BulkSetRecordLength2250(); BulkSetRecordLength2250(uint8_t recordLength); @@ -218,8 +223,8 @@ class BulkSetRecordLength2250 : public DataArray { ////////////////////////////////////////////////////////////////////////////// /// \class BulkSetBuffer5200 hantek/types.h -/// \brief The DSO-5200/DSO-5200A BULK_DSETBUFFER builder. -class BulkSetBuffer5200 : public DataArray { +/// \brief The DSO-5200/DSO-5200A BulkCode::DSETBUFFER builder. +class BulkSetBuffer5200 : public BulkCommand { public: BulkSetBuffer5200(); BulkSetBuffer5200(uint16_t triggerPositionPre, uint16_t triggerPositionPost, DTriggerPositionUsed usedPre = DTriggerPositionUsed::DTRIGGERPOSITION_OFF, @@ -242,8 +247,8 @@ class BulkSetBuffer5200 : public DataArray { ////////////////////////////////////////////////////////////////////////////// /// \class BulkSetSamplerate2250 hantek/types.h -/// \brief The DSO-2250 BULK_ESETTRIGGERORSAMPLERATE builder. -class BulkSetSamplerate2250 : public DataArray { +/// \brief The DSO-2250 BulkCode::ESETTRIGGERORSAMPLERATE builder. +class BulkSetSamplerate2250 : public BulkCommand { public: BulkSetSamplerate2250(); BulkSetSamplerate2250(bool fastRate, bool downsampling = false, uint16_t samplerate = 0); @@ -261,8 +266,8 @@ class BulkSetSamplerate2250 : public DataArray { ////////////////////////////////////////////////////////////////////////////// /// \class BulkSetTrigger5200 hantek/types.h -/// \brief The DSO-5200/DSO-5200A BULK_ESETTRIGGERORSAMPLERATE builder. -class BulkSetTrigger5200 : public DataArray { +/// \brief The DSO-5200/DSO-5200A BulkCode::ESETTRIGGERORSAMPLERATE builder. +class BulkSetTrigger5200 : public BulkCommand { public: BulkSetTrigger5200(); BulkSetTrigger5200(uint8_t triggerSource, uint8_t usedChannels, bool fastRate = false, uint8_t triggerSlope = 0, @@ -285,8 +290,8 @@ class BulkSetTrigger5200 : public DataArray { ////////////////////////////////////////////////////////////////////////////// /// \class BulkSetBuffer2250 hantek/types.h -/// \brief The DSO-2250 BULK_FSETBUFFER builder. -class BulkSetBuffer2250 : public DataArray { +/// \brief The DSO-2250 BulkCode::FSETBUFFER builder. +class BulkSetBuffer2250 : public BulkCommand { public: BulkSetBuffer2250(); BulkSetBuffer2250(uint32_t triggerPositionPre, uint32_t triggerPositionPost); diff --git a/openhantek/src/hantekprotocol/bulkcode.h b/openhantek/src/hantekprotocol/bulkcode.h index d356718..3afb047 100644 --- a/openhantek/src/hantekprotocol/bulkcode.h +++ b/openhantek/src/hantekprotocol/bulkcode.h @@ -1,5 +1,7 @@ #pragma once +#include + namespace Hantek { ////////////////////////////////////////////////////////////////////////////// @@ -7,7 +9,7 @@ namespace Hantek { /// \brief All supported bulk commands. /// Indicies given in square brackets specify byte numbers in little endian /// format. -enum BulkCode { +enum class BulkCode : uint8_t { /// BulkSetFilter [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO5200, /// ::MODEL_DSO5200A] ///

@@ -29,7 +31,7 @@ enum BulkCode { /// This command is used by the official %Hantek software, but doesn't seem /// to be used by the device. ///


- BULK_SETFILTER, + SETFILTER, /// BulkSetTriggerAndSamplerate [::MODEL_DSO2090, ::MODEL_DSO2150] ///

@@ -86,7 +88,7 @@ enum BulkCode { /// using the large buffer. ///

///


- BULK_SETTRIGGERANDSAMPLERATE, + SETTRIGGERANDSAMPLERATE, /// BulkForceTrigger [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, /// ::MODEL_DSO5200, ::MODEL_DSO5200A] @@ -100,7 +102,7 @@ enum BulkCode { /// ///

///


- BULK_FORCETRIGGER, + FORCETRIGGER, /// BulkCaptureStart [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, /// ::MODEL_DSO5200, ::MODEL_DSO5200A] @@ -114,7 +116,7 @@ enum BulkCode { /// ///

///


- BULK_STARTSAMPLING, + STARTSAMPLING, /// BulkTriggerEnabled [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, /// ::MODEL_DSO5200, ::MODEL_DSO5200A] @@ -128,7 +130,7 @@ enum BulkCode { /// ///

///


- BULK_ENABLETRIGGER, + ENABLETRIGGER, /// BulkGetData [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, /// ::MODEL_DSO5200, ::MODEL_DSO5200A] @@ -179,7 +181,7 @@ enum BulkCode { /// ///

///


- BULK_GETDATA, + GETDATA, /// BulkGetCaptureState [::MODEL_DSO2090, ::MODEL_DSO2150, /// ::MODEL_DSO2250, ::MODEL_DSO5200, ::MODEL_DSO5200A] @@ -208,7 +210,7 @@ enum BulkCode { /// ///

///


- BULK_GETCAPTURESTATE, + GETCAPTURESTATE, /// BulkSetGain [::MODEL_DSO2090, ::MODEL_DSO2150, ::MODEL_DSO2250, /// ::MODEL_DSO5200, ::MODEL_DSO5200A] @@ -229,7 +231,7 @@ enum BulkCode { /// It is usually used in combination with ::CONTROL_SETRELAYS. ///

///


- BULK_SETGAIN, + SETGAIN, /// BulkSetLogicalData [] ///

@@ -249,7 +251,7 @@ enum BulkCode { /// ///

///


- BULK_SETLOGICALDATA, + SETLOGICALDATA, /// BulkGetLogicalData [] ///

@@ -273,7 +275,7 @@ enum BulkCode { /// ///

///


- BULK_GETLOGICALDATA, + GETLOGICALDATA, /// [] ///

@@ -286,7 +288,7 @@ enum BulkCode { /// ///

///


- BULK_AUNKNOWN, + AUNKNOWN, /// BulkSetChannels2250 [::MODEL_DSO2250] ///

@@ -301,7 +303,7 @@ enum BulkCode { /// ///

///


- BULK_BSETCHANNELS, + BSETCHANNELS, /// BulkSetTrigger2250 [::MODEL_DSO2250] ///

@@ -348,7 +350,7 @@ enum BulkCode { /// SamplerateSlow = 0 and SamplerateFast = 4. ///

///


- BULK_CSETTRIGGERORSAMPLERATE, + CSETTRIGGERORSAMPLERATE, /// BulkSetRecordLength2250 [::MODEL_DSO2250] ///

@@ -394,7 +396,7 @@ enum BulkCode { /// TriggerPositionPost value is maximal for 0 % and minimal for 100%. ///

///


- BULK_DSETBUFFER, + DSETBUFFER, /// BulkSetSamplerate2250 [::MODEL_DSO2250] ///

@@ -440,7 +442,7 @@ enum BulkCode { /// ///

///


- BULK_ESETTRIGGERORSAMPLERATE, + ESETTRIGGERORSAMPLERATE, /// BulkSetBuffer2250 [::MODEL_DSO2250] ///

@@ -475,9 +477,9 @@ enum BulkCode { /// TriggerPositionPost value is maximal for 0 % and minimal for 100%. ///

///


- BULK_FSETBUFFER, + FSETBUFFER, - BULK_COUNT + COUNT }; } diff --git a/openhantek/src/hantekprotocol/controlStructs.cpp b/openhantek/src/hantekprotocol/controlStructs.cpp index 31fa105..c5fdf13 100644 --- a/openhantek/src/hantekprotocol/controlStructs.cpp +++ b/openhantek/src/hantekprotocol/controlStructs.cpp @@ -6,9 +6,9 @@ namespace Hantek { -ControlSetOffset::ControlSetOffset() : DataArray(17) {} +ControlSetOffset::ControlSetOffset() : ControlCommand(17) {} -ControlSetOffset::ControlSetOffset(uint16_t channel1, uint16_t channel2, uint16_t trigger) : DataArray(17) { +ControlSetOffset::ControlSetOffset(uint16_t channel1, uint16_t channel2, uint16_t trigger) : ControlCommand(17) { this->setChannel(0, channel1); this->setChannel(1, channel2); this->setTrigger(trigger); @@ -40,7 +40,7 @@ void ControlSetOffset::setTrigger(uint16_t level) { ControlSetRelays::ControlSetRelays(bool ch1Below1V, bool ch1Below100mV, bool ch1CouplingDC, bool ch2Below1V, bool ch2Below100mV, bool ch2CouplingDC, bool triggerExt) - : DataArray(17) { + : ControlCommand(17) { this->setBelow1V(0, ch1Below1V); this->setBelow100mV(0, ch1Below100mV); this->setCoupling(0, ch1CouplingDC); @@ -96,17 +96,17 @@ bool ControlSetRelays::getTrigger() { return (this->array[7] & 0x01) == 0x00; } void ControlSetRelays::setTrigger(bool ext) { this->array[7] = ext ? 0xfe : 0x01; } -ControlSetVoltDIV_CH1::ControlSetVoltDIV_CH1() : DataArray(1) { this->setDiv(5); } +ControlSetVoltDIV_CH1::ControlSetVoltDIV_CH1() : ControlCommand(1) { this->setDiv(5); } void ControlSetVoltDIV_CH1::setDiv(uint8_t val) { this->array[0] = val; } -ControlSetVoltDIV_CH2::ControlSetVoltDIV_CH2() : DataArray(1) { this->setDiv(5); } +ControlSetVoltDIV_CH2::ControlSetVoltDIV_CH2() : ControlCommand(1) { this->setDiv(5); } void ControlSetVoltDIV_CH2::setDiv(uint8_t val) { this->array[0] = val; } -ControlSetTimeDIV::ControlSetTimeDIV() : DataArray(1) { this->setDiv(1); } +ControlSetTimeDIV::ControlSetTimeDIV() : ControlCommand(1) { this->setDiv(1); } void ControlSetTimeDIV::setDiv(uint8_t val) { this->array[0] = val; } -ControlAcquireHardData::ControlAcquireHardData() : DataArray(1) { this->array[0] = 0x01; } +ControlAcquireHardData::ControlAcquireHardData() : ControlCommand(1) { this->array[0] = 0x01; } } diff --git a/openhantek/src/hantekprotocol/controlStructs.h b/openhantek/src/hantekprotocol/controlStructs.h index 61559b0..3ebe515 100644 --- a/openhantek/src/hantekprotocol/controlStructs.h +++ b/openhantek/src/hantekprotocol/controlStructs.h @@ -5,7 +5,12 @@ #include "utils/dataarray.h" namespace Hantek { -struct ControlSetOffset : public DataArray { +class ControlCommand : public DataArray { +protected: + ControlCommand(unsigned size): DataArray(size) {} +}; + +struct ControlSetOffset : public ControlCommand { ControlSetOffset(); /// \brief Sets the offsets to the given values. /// \param channel1 The offset for channel 1. @@ -29,7 +34,7 @@ struct ControlSetOffset : public DataArray { void setTrigger(uint16_t level); }; -struct ControlSetRelays : public DataArray { +struct ControlSetRelays : public ControlCommand { /// \brief Sets all relay states. /// \param ch1Below1V Sets the state of the Channel 1 below 1 V relay. /// \param ch1Below100mV Sets the state of the Channel 1 below 100 mV relay. @@ -74,22 +79,22 @@ struct ControlSetRelays : public DataArray { void setTrigger(bool ext); }; -struct ControlSetVoltDIV_CH1 : public DataArray { +struct ControlSetVoltDIV_CH1 : public ControlCommand { ControlSetVoltDIV_CH1(); void setDiv(uint8_t val); }; -struct ControlSetVoltDIV_CH2 : public DataArray { +struct ControlSetVoltDIV_CH2 : public ControlCommand { ControlSetVoltDIV_CH2(); void setDiv(uint8_t val); }; -struct ControlSetTimeDIV : public DataArray { +struct ControlSetTimeDIV : public ControlCommand { ControlSetTimeDIV(); void setDiv(uint8_t val); }; -struct ControlAcquireHardData : public DataArray { +struct ControlAcquireHardData : public ControlCommand { ControlAcquireHardData(); }; } diff --git a/openhantek/src/hantekprotocol/definitions.h b/openhantek/src/hantekprotocol/definitions.h index 640d5f4..55e630b 100644 --- a/openhantek/src/hantekprotocol/definitions.h +++ b/openhantek/src/hantekprotocol/definitions.h @@ -8,7 +8,6 @@ #define HANTEK_GAIN_STEPS 9 #define HANTEK_CHANNELS 2 ///< Number of physical channels -#define HANTEK_SPECIAL_CHANNELS 2 ///< Number of special channels namespace Hantek { /// \enum UsedChannels @@ -68,7 +67,7 @@ struct OffsetsPerGainStep { }; /// \struct FilterBits -/// \brief The bits for BULK_SETFILTER. +/// \brief The bits for BULK::SETFILTER. struct FilterBits { uint8_t channel1 : 1; ///< Set to true when channel 1 isn't used uint8_t channel2 : 1; ///< Set to true when channel 2 isn't used @@ -78,7 +77,7 @@ struct FilterBits { /// \struct GainBits -/// \brief The gain bits for BULK_SETGAIN. +/// \brief The gain bits for BulkCode::SETGAIN. struct GainBits { uint8_t channel1 : 2; ///< Gain for CH1, 0 = 1e* V, 1 = 2e*, 2 = 5e* uint8_t channel2 : 2; ///< Gain for CH1, 0 = 1e* V, 1 = 2e*, 2 = 5e* diff --git a/openhantek/src/usb/usbdevice.cpp b/openhantek/src/usb/usbdevice.cpp index f1cf982..f0d8a61 100644 --- a/openhantek/src/usb/usbdevice.cpp +++ b/openhantek/src/usb/usbdevice.cpp @@ -123,14 +123,14 @@ unsigned USBDevice::getFindIteration() const return findIteration; } -int USBDevice::bulkTransfer(unsigned char endpoint, unsigned char *data, unsigned int length, int attempts, +int USBDevice::bulkTransfer(unsigned char endpoint, const unsigned char *data, unsigned int length, int attempts, unsigned int timeout) { if (!this->handle) return LIBUSB_ERROR_NO_DEVICE; int errorCode = LIBUSB_ERROR_TIMEOUT; - int transferred; + int transferred = 0; for (int attempt = 0; (attempt < attempts || attempts == -1) && errorCode == LIBUSB_ERROR_TIMEOUT; ++attempt) - errorCode = libusb_bulk_transfer(this->handle, endpoint, data, length, &transferred, timeout); + errorCode = libusb_bulk_transfer(this->handle, endpoint, (unsigned char*) data, (int)length, &transferred, timeout); if (errorCode == LIBUSB_ERROR_NO_DEVICE) disconnectFromDevice(); if (errorCode < 0) @@ -144,7 +144,7 @@ int USBDevice::bulkTransfer(unsigned char endpoint, unsigned char *data, unsigne /// \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(unsigned char *data, unsigned int length, int attempts) { +int USBDevice::bulkWrite(const unsigned char *data, unsigned int length, int attempts) { if (!this->handle) return LIBUSB_ERROR_NO_DEVICE; int errorCode = this->getConnectionSpeed(); @@ -171,7 +171,7 @@ int USBDevice::bulkRead(unsigned char *data, unsigned int length, int attempts) /// \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(DataArray *command, int attempts) { +int USBDevice::bulkCommand(const DataArray *command, int attempts) { if (!this->handle) return LIBUSB_ERROR_NO_DEVICE; if (!allowBulkTransfer) return LIBUSB_SUCCESS; diff --git a/openhantek/src/usb/usbdevice.h b/openhantek/src/usb/usbdevice.h index 6e452cb..b4c73b7 100644 --- a/openhantek/src/usb/usbdevice.h +++ b/openhantek/src/usb/usbdevice.h @@ -9,7 +9,6 @@ #include "usbdevicedefinitions.h" #include "controlbegin.h" -#include "utils/dataarray.h" class DSOModel; @@ -48,12 +47,12 @@ class USBDevice : public QObject { /// \param timeout The timeout in ms. /// \return Number of transferred bytes on success, libusb error code on /// error. - int bulkTransfer(unsigned char endpoint, unsigned char *data, unsigned int length, int attempts = HANTEK_ATTEMPTS, + int bulkTransfer(unsigned char endpoint, const unsigned char *data, unsigned int length, int attempts = HANTEK_ATTEMPTS, unsigned int timeout = HANTEK_TIMEOUT); - int bulkWrite(unsigned char *data, unsigned int length, int attempts = HANTEK_ATTEMPTS); + int bulkWrite(const unsigned char *data, unsigned int length, int attempts = HANTEK_ATTEMPTS); int bulkRead(unsigned char *data, unsigned int length, int attempts = HANTEK_ATTEMPTS); - int bulkCommand(DataArray *command, int attempts = HANTEK_ATTEMPTS); + int bulkCommand(const DataArray *command, int attempts = HANTEK_ATTEMPTS); int bulkReadMulti(unsigned char *data, unsigned length, int attempts = HANTEK_ATTEMPTS_MULTI); int controlTransfer(unsigned char type, unsigned char request, unsigned char *data, unsigned int length, int value, diff --git a/openhantek/src/usb/usbdevicedefinitions.h b/openhantek/src/usb/usbdevicedefinitions.h index de53b2e..192c7fc 100644 --- a/openhantek/src/usb/usbdevicedefinitions.h +++ b/openhantek/src/usb/usbdevicedefinitions.h @@ -23,7 +23,7 @@ enum BulkIndex { COMMANDINDEX_0 = 0x03, ///< Used most of the time COMMANDINDEX_1 = 0x0a, COMMANDINDEX_2 = 0x09, - COMMANDINDEX_3 = 0x01, ///< Used for ::BULK_SETTRIGGERANDSAMPLERATE sometimes + COMMANDINDEX_3 = 0x01, ///< Used for ::BulkCode::SETTRIGGERANDSAMPLERATE sometimes COMMANDINDEX_4 = 0x02, COMMANDINDEX_5 = 0x08 }; diff --git a/openhantek/src/utils/dataarray.h b/openhantek/src/utils/dataarray.h index 3684770..4677594 100644 --- a/openhantek/src/utils/dataarray.h +++ b/openhantek/src/utils/dataarray.h @@ -8,7 +8,7 @@ template class DataArray { DataArray(unsigned int size); ~DataArray(); - T *data(); + T *data() const; T operator[](unsigned int index); unsigned int getSize() const; @@ -31,7 +31,7 @@ template DataArray::~DataArray() { delete[] this->array; } /// \brief Returns a pointer to the array data. /// \return The internal data array. -template T *DataArray::data() { return this->array; } +template T *DataArray::data() const { return this->array; } /// \brief Returns array element when using square brackets. /// \return The array element.