From e78ab7bd711f736588ad56112b71c8c6af7ed3cb Mon Sep 17 00:00:00 2001 From: oliverhaag Date: Thu, 26 Aug 2010 00:01:44 +0000 Subject: [PATCH] Samplerate values are calculated now, so every samplerate supported by the hardware is possible --- openhantek/AUTHORS | 1 - openhantek/ChangeLog | 10 ++++++++++ openhantek/mainpage.dox | 4 ++-- openhantek/src/hantek/control.cpp | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------- openhantek/src/hantek/control.h | 8 ++++---- openhantek/src/hantek/device.cpp | 37 ++++++++++++++++++++++--------------- openhantek/src/hantek/device.h | 1 + openhantek/src/hantek/types.cpp | 10 +++++----- openhantek/src/hantek/types.h | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------- 9 files changed, 177 insertions(+), 87 deletions(-) diff --git a/openhantek/AUTHORS b/openhantek/AUTHORS index 306fd93..620ee92 100644 --- a/openhantek/AUTHORS +++ b/openhantek/AUTHORS @@ -1,2 +1 @@ -Oleg Khudyakov Oliver Haag \ No newline at end of file diff --git a/openhantek/ChangeLog b/openhantek/ChangeLog index 64fedd2..1a865d8 100644 --- a/openhantek/ChangeLog +++ b/openhantek/ChangeLog @@ -51,3 +51,13 @@ * Added zoomed scope and markers to exports * Darker default colors for channels in print mode * Added enum values for DSO-5200 bulk commands + +2010-08-24 Oliver Haag +* Documentation of Hantek::Device corrected +* Hantek::Device::bulkReadMulti improved + +2010-08-26 Oliver Haag +* Samplerate values sent to device are calculated now, only limited by hardware +* Added the samplerate formula to the documentation +* Documentation updated with additional information from Oleg +* Removed Oleg from AUTHORS diff --git a/openhantek/mainpage.dox b/openhantek/mainpage.dox index 4dc4f30..20c725d 100644 --- a/openhantek/mainpage.dox +++ b/openhantek/mainpage.dox @@ -20,7 +20,7 @@ After installing these you can build it by running:
 	$ qmake
 	$ make
-	$ make install
+	$ sudo make install
 
\subsection ssec_options Build options @@ -38,7 +38,7 @@ You can set environment variables to set various build options (Done best by pre \section sec_firmware Installation of the firmware \subsection ssec_drivers Gettings the Windows drivers -Before using OpenHantek you have to extract the firmware from the official Windows drivers. You can get them from the Hantek website (English translation). +Before using OpenHantek you have to extract the firmware from the official Windows drivers. You can get them from the Hantek website (English translation). \subsection ssec_dsoextractfw The firmware extraction tool You need the tool dsoextractfw from the sourceforge page too extract the firmware. You have to install libbfd development files and build it by typing:
diff --git a/openhantek/src/hantek/control.cpp b/openhantek/src/hantek/control.cpp
index 0dea9f1..1a3115e 100644
--- a/openhantek/src/hantek/control.cpp
+++ b/openhantek/src/hantek/control.cpp
@@ -42,9 +42,7 @@ namespace Hantek {
 		// Values for the Gain and Timebase enums
 		this->gainSteps             << 0.08 << 0.16 << 0.40 << 0.80 << 1.60 << 4.00
 				<<  8.0 << 16.0 << 40.0;
-		this->samplerateSteps                       <<  1e8 <<  5e7 << 25e6 <<  1e7
-				<<  5e6 << 25e5 <<  1e6 <<  5e5 << 25e4 <<  1e5 <<  5e4 << 25e3 <<  1e4
-				<<  5e3 << 25e2 <<  1e3;
+		this->samplerateChannelMax = 50e6;
 		
 		// Special trigger sources
 		this->specialTriggerSources << tr("EXT") << tr("EXT/10");
@@ -83,10 +81,10 @@ namespace Hantek {
 			this->setOffset(channel, 0.5);
 			this->setTriggerLevel(channel, 0.0);
 		}
-		this->setSamplerate(1e6);
 		this->setBufferSize(BUFFER_SMALL);
+		this->setSamplerate(1e6);
 		this->setTriggerMode(Dso::TRIGGERMODE_NORMAL);
-		this->setTriggerPosition(5e3 / this->samplerateSteps[this->samplerate]);
+		this->setTriggerPosition(5e3 / (this->samplerateMax / this->samplerateDivider));
 		this->setTriggerSlope(Dso::SLOPE_POSITIVE);
 		this->setTriggerSource(false, 0);
 		
@@ -135,7 +133,26 @@ namespace Hantek {
 		for(int control = 0; control < CONTROLINDEX_COUNT; control++)
 			this->controlPending[control] = true;
 		
-		// Get calibration data
+		// Maximum possible samplerate for a single channel
+		switch(this->device->getModel()) {
+			case MODEL_DSO2090:
+			case MODEL_DSO2100:
+				this->samplerateChannelMax = 50e6;
+				break;
+			case MODEL_DSO2150:
+				this->samplerateChannelMax = 75e6;
+				break;
+			case MODEL_DSO2250:
+			case MODEL_DSO5200:
+			case MODEL_DSO5200A:
+				this->samplerateChannelMax = 125e6;
+				break;
+			default:
+				this->samplerateChannelMax = 50e6;
+				break;
+		}
+		
+		// Get channel level data
 		errorCode = this->device->controlRead(CONTROL_VALUE, (unsigned char*) &(this->channelLevels), sizeof(this->channelLevels), (int) VALUE_CHANNELLEVEL);
 		if(errorCode < 0) {
 			this->device->disconnect();
@@ -146,6 +163,8 @@ namespace Hantek {
 		// Adapt offsets
 		for(unsigned int channel = 0; channel < HANTEK_CHANNELS; channel++)
 			this->setOffset(channel, this->offset[channel]);
+		this->setSamplerate(this->samplerateMax / this->samplerateDivider);
+		this->setTriggerPosition(this->triggerPosition);
 		
 		// The control loop is running until the device is disconnected
 		int captureState = CAPTURE_WAITING;
@@ -405,7 +424,7 @@ namespace Hantek {
 			}
 			
 			this->samplesMutex.unlock();
-			emit samplesAvailable(&(this->samples), &(this->samplesSize), this->samplerateSteps[this->samplerate], &(this->samplesMutex));
+			emit samplesAvailable(&(this->samples), &(this->samplesSize), (double) this->samplerateMax / this->samplerateDivider, &(this->samplesMutex));
 		}
 		
 		return 0;
@@ -415,13 +434,13 @@ namespace Hantek {
 	/// \param size The buffer size that should be met (S).
 	/// \return The buffer size that has been set.
 	unsigned long int Control::updateBufferSize(unsigned long int size) {
-		unsigned int sizeId = (size <= BUFFER_SMALL) ? 1 : 2;
+		BufferSizeId sizeId = (size <= BUFFER_SMALL) ? BUFFERID_SMALL : BUFFERID_LARGE;
 		
 		// SetTriggerAndSamplerate bulk command for samplerate
-		((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->setSampleSize(sizeId);
+		((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->setBufferSize(sizeId);
 		this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true;
 		
-		this->bufferSize = (sizeId == 1) ? BUFFER_SMALL : BUFFER_LARGE;
+		this->bufferSize = (sizeId == BUFFERID_SMALL) ? BUFFER_SMALL : BUFFER_LARGE;
 		
 		return this->bufferSize;
 	}
@@ -433,7 +452,7 @@ namespace Hantek {
 		this->updateBufferSize(size);
 		
 		this->setTriggerPosition(this->triggerPosition);
-		this->setSamplerate(this->samplerateSteps[this->samplerate]);
+		this->setSamplerate(this->samplerateMax / this->samplerateDivider);
 		this->setTriggerSlope(this->triggerSlope);
 		
 		return this->bufferSize;
@@ -443,47 +462,59 @@ namespace Hantek {
 	/// \param samplerate The samplerate that should be met (S/s).
 	/// \return The samplerate that has been set.
 	unsigned long int Control::setSamplerate(unsigned long int samplerate) {
-		// Find lowest supported samplerate thats at least as high as the requested
-		int samplerateId;
-		for(samplerateId = SAMPLERATE_COUNT - 1; samplerateId > 0; samplerateId--)
-			if(this->samplerateSteps[samplerateId] >= samplerate)
-				break;
-		// Fastrate is only possible if we're not using both channels
-		if(samplerateId == SAMPLERATE_100MS && ((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->getUsedChannel() == USED_CH1CH2)
-			samplerateId = SAMPLERATE_50MS;
-		
-		// The values that are understood by the oscilloscope
-		/// \todo Check large buffer values, seem to be crap
-		static const unsigned char valueFastSmall[5] = {0, 1, 2, 3, 4};
-		static const unsigned char valueFastLarge[5] = {0, 0, 0, 2, 3};
-		static const unsigned short int valueSlowSmall[13] = {0xfffe, 0xfffc, 0xfff7, 0xffe8, 0xffce, 0xff9c, 0xff07, 0xfe0d, 0xfc19, 0xf63d, 0xec79, 0xd8f1, 0xffed};
-		static const unsigned short int valueSlowLarge[13] = {0xffff, 0x0000, 0xfffc, 0xfff7, 0xffe8, 0xffce, 0xff9d, 0xff07, 0xfe0d, 0xfc19, 0xf63d, 0xec79, 0xffed};
+		if(samplerate == 0)
+			return 0;
 		
 		// SetTriggerAndSamplerate bulk command for samplerate
 		CommandSetTriggerAndSamplerate *commandSetTriggerAndSamplerate = (CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE];
 		
-		// Set SamplerateFast bits for high sampling rates
-		if(samplerateId <= SAMPLERATE_5MS)
-			commandSetTriggerAndSamplerate->setSamplerateFast(this->bufferSize == BUFFER_SMALL ? valueFastSmall[samplerateId - SAMPLERATE_100MS] : valueFastLarge[samplerateId - SAMPLERATE_100MS]);
-		else
-			commandSetTriggerAndSamplerate->setSamplerateFast(4);
+		// Calculate with fast rate first if only one channel is used
+		bool fastRate = false;
+		this->samplerateMax = this->samplerateChannelMax;
+		if(((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->getUsedChannel() != USED_CH1CH2) {
+			fastRate = true;
+			this->samplerateMax *= HANTEK_CHANNELS;
+		}
 		
-		// Set normal Samplerate value for lower sampling rates
-		if(samplerateId >= SAMPLERATE_10MS)
-			commandSetTriggerAndSamplerate->setSamplerate(this->bufferSize == BUFFER_SMALL ? valueSlowSmall[samplerateId - SAMPLERATE_10MS] : valueSlowLarge[samplerateId - SAMPLERATE_10MS]);
-		else
-			commandSetTriggerAndSamplerate->setSamplerate(0x0000);
+		// The maximum sample rate depends on the buffer size
+		switch(commandSetTriggerAndSamplerate->getBufferSize()) {
+			case BUFFERID_ROLL:
+				this->samplerateMax /= 1000;
+				break;
+			case BUFFERID_LARGE:
+				this->samplerateMax /= 2;
+				break;
+			default:
+				break;
+		}
+		
+		// Get divider that would provide the requested rate, can't be zero
+		this->samplerateDivider = qMax(this->samplerateMax / samplerate, (long unsigned int) 1);
 		
+		// Use normal mode if it would meet the rate as exactly as fast rate mode
+		if(fastRate && this->samplerateDivider % HANTEK_CHANNELS == 0) {
+			fastRate = false;
+			this->samplerateMax /= 2;
+			this->samplerateDivider /= HANTEK_CHANNELS;
+		}
+		
+		// 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) this->samplerateDivider - 3) / 2, (long int) 0);
+		unsigned char valueFast = this->samplerateDivider - valueSlow * 2;
+		
+		// Store samplerate fast value
+		commandSetTriggerAndSamplerate->setSamplerateFast(valueFast);
+		// Store samplerate slow value (two's complement)
+		commandSetTriggerAndSamplerate->setSamplerateSlow(valueSlow == 0 ? 0 : 0xffff - valueSlow);
 		// Set fast rate when used
-		commandSetTriggerAndSamplerate->setFastRate(samplerateId == SAMPLERATE_100MS);
+		commandSetTriggerAndSamplerate->setFastRate(fastRate);
 		
 		this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true;
 		
-		this->samplerate = (Samplerate) samplerateId;
-		
 		this->updateBufferSize(this->bufferSize);
 		this->setTriggerSlope(this->triggerSlope);
-		return this->samplerateSteps[samplerateId];
+		return this->samplerateMax / this->samplerateDivider;
 	}	
 	
 	/// \brief Enables/disables filtering of the given channel.
@@ -664,9 +695,12 @@ namespace Hantek {
 			return -1;
 		
 		// SetTriggerAndSamplerate bulk command for trigger position
-		((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->setTriggerSlope((this->bufferSize != BUFFER_SMALL || this->samplerate > SAMPLERATE_10MS || (SAMPLERATE_10MS - this->samplerate) % 2) ? slope : Dso::SLOPE_NEGATIVE - slope);
+		CommandSetTriggerAndSamplerate *commandSetTriggerAndSamplerate = (CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE];
+		
+		commandSetTriggerAndSamplerate->setTriggerSlope((/*this->bufferSize != BUFFER_SMALL ||*/ commandSetTriggerAndSamplerate->getSamplerateFast() % 2 == 0) ? slope : Dso::SLOPE_NEGATIVE - slope);
 		this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true;
 		
+		this->triggerSlope = slope;
 		return 0;
 	}
 	
@@ -677,13 +711,13 @@ namespace Hantek {
 		// Calculate the position value (Varying start point, measured in samples)
 		//unsigned long int positionRange = (this->bufferSize == BUFFER_SMALL) ? 10000 : 32768;
 		unsigned long int positionStart = (this->bufferSize == BUFFER_SMALL) ? 0x77660 : 0x78000;
-		unsigned long int positionValue = position * this->samplerateSteps[this->samplerate] + positionStart;
+		unsigned long int positionValue = position * this->samplerateMax / this->samplerateDivider + positionStart;
 		
 		// SetTriggerAndSamplerate bulk command for trigger position
 		((CommandSetTriggerAndSamplerate *) this->command[COMMAND_SETTRIGGERANDSAMPLERATE])->setTriggerPosition(positionValue);
 		this->commandPending[COMMAND_SETTRIGGERANDSAMPLERATE] = true;
 		
 		this->triggerPosition = position;
-		return (double) (positionValue - positionStart) / this->samplerateSteps[this->samplerate];
+		return (double) (positionValue - positionStart) / this->samplerateMax * this->samplerateDivider;
 	}
 }
diff --git a/openhantek/src/hantek/control.h b/openhantek/src/hantek/control.h
index fe9aa8d..7fe83ae 100644
--- a/openhantek/src/hantek/control.h
+++ b/openhantek/src/hantek/control.h
@@ -81,10 +81,12 @@ namespace Hantek {
 			bool controlPending[CONTROLINDEX_COUNT]; ///< true, when the control command should be executed
 			
 			/// Calibration data for the channel offsets
-			unsigned short channelLevels[HANTEK_CHANNELS][GAIN_COUNT][OFFSET_COUNT];
+			unsigned short int channelLevels[HANTEK_CHANNELS][GAIN_COUNT][OFFSET_COUNT];
 			
 			// Various cached settings
-			Samplerate samplerate; ///< The samplerate id
+			unsigned long int samplerateDivider; ///< The samplerate divider
+			unsigned long int samplerateMax; ///< The maximum sample rate for the current setup
+			unsigned long int samplerateChannelMax; ///< The maximum sample rate for a single channel
 			Gain gain[HANTEK_CHANNELS]; ///< The gain id
 			double offset[HANTEK_CHANNELS]; ///< The current screen offset for each channel
 			double offsetReal[HANTEK_CHANNELS]; ///< The real offset for each channel (Due to quantization)
@@ -103,8 +105,6 @@ namespace Hantek {
 			
 			// Lists for enums
 			QList gainSteps; ///< Voltage steps in V/screenheight
-			QList samplerateSteps; ///< Samplerate steps in S/s
-			QList samplerateValues; ///< Values sent to the oscilloscope
 		
 		public slots:
 			unsigned long int setSamplerate(unsigned long int samplerate);
diff --git a/openhantek/src/hantek/device.cpp b/openhantek/src/hantek/device.cpp
index ffe92f3..006ffb7 100644
--- a/openhantek/src/hantek/device.cpp
+++ b/openhantek/src/hantek/device.cpp
@@ -44,6 +44,7 @@ namespace Hantek {
 				<< 0x5200 << 0x520A;
 		this->modelStrings << "DSO-2090" << "DSO-2100" << "DSO-2150" << "DSO-2250"
 				<< "DSO-5200" << "DSO-5200A";
+		this->model = MODEL_UNKNOWN;
 		
 		this->beginCommandControl = new ControlBeginCommand();
 		
@@ -283,7 +284,7 @@ namespace Hantek {
 	/// \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 0 on success, libusb error code on error.
+	/// \return Number of transferred bytes on success, libusb error code on error.
 	int Device::bulkTransfer(unsigned char endpoint, unsigned char *data, unsigned int length, int attempts) {
 		if(!this->handle)
 			return LIBUSB_ERROR_NO_DEVICE;
@@ -306,7 +307,7 @@ namespace Hantek {
 	/// \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 0 on success, libusb error code on error.
+	/// \return Number of sent bytes on success, libusb error code on error.
 	int Device::bulkWrite(unsigned char *data, unsigned int length, int attempts) {
 		if(!this->handle)
 			return LIBUSB_ERROR_NO_DEVICE;
@@ -333,7 +334,7 @@ namespace Hantek {
 	/// \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 0 on success, libusb error code on error.
+	/// \return Number of received bytes on success, libusb error code on error.
 	int Device::bulkRead(unsigned char *data, unsigned int length, int attempts) {
 		if(!this->handle)
 			return LIBUSB_ERROR_NO_DEVICE;
@@ -359,7 +360,7 @@ namespace Hantek {
 	/// \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 0 on success, libusb error code on error.
+	/// \return Number of sent bytes on success, libusb error code on error.
 	int Device::bulkCommand(Helper::DataArray *command, int attempts) {
 		if(!this->handle)
 			return LIBUSB_ERROR_NO_DEVICE;
@@ -377,7 +378,7 @@ namespace Hantek {
 	/// \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 0 on success, libusb error code on error.
+	/// \return Number of received bytes on success, libusb error code on error.
 	int Device::bulkReadMulti(unsigned char *data, unsigned int length, int attempts) {
 		if(!this->handle)
 			return LIBUSB_ERROR_NO_DEVICE;
@@ -388,24 +389,24 @@ namespace Hantek {
 		if(errorCode < 0)
 			return errorCode;
 		
-		int packetCount = length / this->inPacketLength;
-		
 		errorCode = this->inPacketLength;
-		int packet;
-		for(packet = 0; packet < packetCount && errorCode == this->inPacketLength; packet++) {
+		unsigned int packet, received = 0;
+		for(packet = 0; received < length && errorCode == this->inPacketLength; packet++) {
 #if LIBUSB_VERSION == 0
 			errorCode = LIBUSB_ERROR_TIMEOUT;
 			for(int attempt = 0; (attempt < attempts || attempts == -1) && errorCode == LIBUSB_ERROR_TIMEOUT; attempt++)
-				errorCode = usb_bulk_read(this->handle, HANTEK_EP_IN, (char *) data + packet * this->inPacketLength, this->inPacketLength, HANTEK_TIMEOUT);
+				errorCode = usb_bulk_read(this->handle, HANTEK_EP_IN, (char *) data + packet * this->inPacketLength, qMin(length - received, (unsigned int) this->inPacketLength), HANTEK_TIMEOUT);
 #else
-			errorCode = this->bulkTransfer(HANTEK_EP_IN, data + packet * this->inPacketLength, this->inPacketLength, attempts);
+			errorCode = this->bulkTransfer(HANTEK_EP_IN, data + packet * this->inPacketLength, qMin(length - received, (unsigned int) this->inPacketLength), attempts);
 #endif
+			if(errorCode > 0)
+				received += errorCode;
 		}
 		
 		if(errorCode < 0)
 			return errorCode;
 		else
-			return (packet - 1) * this->inPacketLength + errorCode;
+			return received;
 	}
 	
 	/// \brief Control transfer to the oscilloscope.
@@ -416,7 +417,7 @@ namespace Hantek {
 	/// \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 0 on success, libusb error code on error.
+	/// \return Number of transferred bytes on success, libusb error code on error.
 	int Device::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;
@@ -441,7 +442,7 @@ namespace Hantek {
 	/// \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 0 on success, libusb error code on error.
+	/// \return Number of sent bytes on success, libusb error code on error.
 	int Device::controlWrite(unsigned char request, unsigned char *data, unsigned int length, int value, int index, int attempts) {
 		if(!this->handle)
 			return LIBUSB_ERROR_NO_DEVICE;
@@ -456,7 +457,7 @@ namespace Hantek {
 	/// \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 0 on success, libusb error code on error.
+	/// \return Number of received bytes on success, libusb error code on error.
 	int Device::controlRead(unsigned char request, unsigned char *data, unsigned int length, int value, int index, int attempts) {
 		if(!this->handle)
 			return LIBUSB_ERROR_NO_DEVICE;
@@ -476,4 +477,10 @@ namespace Hantek {
 		
 		return response.getSpeed();
 	}
+	
+	/// \brief Get the oscilloscope model.
+	/// \return The #Model of the connected Hantek DSO.
+	Model Device::getModel() {
+		return this->model;
+	}
 }
diff --git a/openhantek/src/hantek/device.h b/openhantek/src/hantek/device.h
index 2533879..4a70326 100644
--- a/openhantek/src/hantek/device.h
+++ b/openhantek/src/hantek/device.h
@@ -75,6 +75,7 @@ namespace Hantek {
 			int controlRead(unsigned char request, unsigned char *data, unsigned int length, int value = 0, int index = 0, int attempts = HANTEK_ATTEMPTS_DEFAULT);
 			
 			int getConnectionSpeed();
+			Model getModel();
 		
 		protected:
 			// Lists for enums
diff --git a/openhantek/src/hantek/types.cpp b/openhantek/src/hantek/types.cpp
index f2dbac5..8c2e5c8 100644
--- a/openhantek/src/hantek/types.cpp
+++ b/openhantek/src/hantek/types.cpp
@@ -113,12 +113,12 @@ namespace Hantek {
 		this->init();
 		
 		this->setTriggerSource(triggerSource);
-		this->setSampleSize(sampleSize);
+		this->setBufferSize(sampleSize);
 		this->setSamplerateFast(samplerateFast);
 		this->setUsedChannel(usedChannel);
 		this->setFastRate(fastRate);
 		this->setTriggerSlope(triggerSlope);
-		this->setSamplerate(samplerate);
+		this->setSamplerateSlow(samplerate);
 		this->setTriggerPosition(triggerPosition);
 	}
 	
@@ -136,13 +136,13 @@ namespace Hantek {
 	
 	/// \brief Get the sampleSize value in Tsr1Bits.
 	/// \return The sampleSize value.
-	unsigned char CommandSetTriggerAndSamplerate::getSampleSize() {
+	unsigned char CommandSetTriggerAndSamplerate::getBufferSize() {
 		return ((Tsr1Bits *) &(this->array[2]))->sampleSize;
 	}
 	
 	/// \brief Set the sampleSize in Tsr1Bits to the given value.
 	/// \param value The new sampleSize value.
-	void CommandSetTriggerAndSamplerate::setSampleSize(unsigned char value) {
+	void CommandSetTriggerAndSamplerate::setBufferSize(unsigned char value) {
 		((Tsr1Bits *) &(this->array[2]))->sampleSize = value;
 	}
 	
@@ -202,7 +202,7 @@ namespace Hantek {
 	
 	/// \brief Set the Samplerate to the given value.
 	/// \param samplerate The new samplerate value.
-	void CommandSetTriggerAndSamplerate::setSamplerate(unsigned short int samplerate) {
+	void CommandSetTriggerAndSamplerate::setSamplerateSlow(unsigned short int samplerate) {
 		this->array[4] = (unsigned char) samplerate;
 		this->array[5] = (unsigned char) (samplerate >> 8);
 	}
diff --git a/openhantek/src/hantek/types.h b/openhantek/src/hantek/types.h
index 73203eb..d61b9ae 100644
--- a/openhantek/src/hantek/types.h
+++ b/openhantek/src/hantek/types.h
@@ -73,8 +73,12 @@ namespace Hantek {
 		///     0x00
 		///     Tsr1Bits
 		///     Tsr2Bits
-		///     Samplerate[0]
-		///     Samplerate[1]
+		///     SamplerateValue[0]
+		///     SamplerateValue[1]
+		///   
+		/// 
+		/// 
+		///   
 		///     
 		///     
 		///     
@@ -83,6 +87,11 @@ namespace Hantek {
 		///     
 		///   
 		/// 
TriggerPosition[0]TriggerPosition[1]0x000x00
+ /// The samplerate is set relative to the maximum sample rate by a divider that is set in Tsr1Bits.samplerateFast and the 16-bit value in the two SamplerateValue bytes.
+ /// Without using fast rate mode, the samplerate is:
+ /// Samplerate = SamplerateMax / (2comp(SamplerateValue) * 2 + Tsr1Bits.samplerateFast)
+ /// SamplerateMax is 50 MHz for the DSO-2090.
+ /// When using fast rate mode the resulting samplerate is twice as fast, when using the large buffer it is half as fast. When Tsr1Bits.sampleSize is 0 (Roll mode) the sampling rate is divided by 1000. Setting Tsr1Bits.samplerateFast to 0 doesn't work, the result will be the same as Tsr1Bits.samplerateFast = 1. COMMAND_SETTRIGGERANDSAMPLERATE, /// This command forces triggering: @@ -180,7 +189,7 @@ namespace Hantek { /// /// 0x08 /// 0x0f - /// Data + /// Data | 0x01 /// 0x00 /// 0x00 /// 0x00 @@ -197,7 +206,7 @@ namespace Hantek { /// 0x00 /// /// - /// The oscilloscope returns the logical data: + /// The oscilloscope returns the logical data, which is 64 or 512 bytes long: /// /// /// @@ -233,11 +242,11 @@ namespace Hantek { /// /// /// - /// + /// /// /// ///
?0x00Samplerate[0] (?)Samplerate[1] (?)UnknownTsr1.samplerateFast replacement (?)0x00
- COMMAND_DSO5200_0C, + COMMAND_SETSAMPLERATE5200, /// This command seems to set trigger settings for the DSO-5200: /// @@ -324,6 +333,10 @@ namespace Hantek { /// /// /// + /// + ///
Ch2Offset[0]TriggerOffset[1] | 0x20TriggerOffset[0]
+ /// + /// /// /// /// @@ -346,10 +359,18 @@ namespace Hantek { /// /// /// + /// + ///
0x000x000x000x04 ^ (Ch1Gain < 1 V)0x08 ^ (Ch1Gain < 100 mV)0x02 ^ (Ch1Coupling == DC)
+ /// + /// /// /// /// /// + /// + ///
0x20 ^ (Ch2Gain < 1 V)0x40 ^ (Ch2Gain < 100 mV)0x10 ^ (Ch2Coupling == DC)0x01 ^ (Trigger == EXT)
+ /// + /// /// /// /// @@ -368,9 +389,18 @@ namespace Hantek { /// \enum ControlValue hantek/types.h /// \brief All supported values for control commands. enum ControlValue { + /// Value 0x08 is the calibration data for the channels offsets. It holds the offset value for the top and bottom of the scope screen for every gain step on every channel. The data is stored as a three-dimensional array:
+ /// channelLevels[channel][#Gain][#LevelOffset] VALUE_CHANNELLEVEL = 0x08, - VALUE_DEVICEADDRESS = 0x0A, - VALUE_CALIBRATIONDATA = 0x60 + + /// Value 0x0a is the address of the device. It has a length of one byte. + VALUE_DEVICEADDRESS = 0x0a, + + /// Value 0x60 seems to be some calibration data with a length of four bytes. What it is good for is unknown so far. + VALUE_CALIBRATIONDATA = 0x60, + + /// Value 0x70 is an additional data that is used on the DSO-5200, it's six bytes long. + VALUE_UNKNOWN_70 = 0x70 }; ////////////////////////////////////////////////////////////////////////////// @@ -387,8 +417,8 @@ namespace Hantek { /// \enum ConnectionSpeed hantek/types.h /// \brief The speed level of the USB connection. enum ConnectionSpeed { - CONNECTION_FULLSPEED = 0, - CONNECTION_HIGHSPEED = 1 + CONNECTION_FULLSPEED = 0, ///< FullSpeed USB, 64 byte bulk transfers + CONNECTION_HIGHSPEED = 1 ///< HighSpeed USB, 512 byte bulk transfers }; ////////////////////////////////////////////////////////////////////////////// @@ -440,6 +470,15 @@ namespace Hantek { }; ////////////////////////////////////////////////////////////////////////////// + /// \enum BufferSizeId hantek/types.h + /// \brief The size id for CommandSetTriggerAndSamplerate. + enum BufferSizeId { + BUFFERID_ROLL = 0, + BUFFERID_SMALL, + BUFFERID_LARGE + }; + + ////////////////////////////////////////////////////////////////////////////// /// \enum CaptureState hantek/types.h /// \brief The different capture states which the oscilloscope returns. enum CaptureState { @@ -453,10 +492,10 @@ namespace Hantek { /// \enum CommandIndex hantek/types.h /// \brief Can be set by CONTROL_BEGINCOMMAND, maybe it allows multiple commands at the same time? enum CommandIndex { - COMMANDINDEX_0 = 0x03, + COMMANDINDEX_0 = 0x03, ///< Used most of the time COMMANDINDEX_1 = 0x0a, COMMANDINDEX_2 = 0x09, - COMMANDINDEX_3 = 0x01, + COMMANDINDEX_3 = 0x01, ///< Used for #COMMAND_SETTRIGGERANDSAMPLERATE sometimes COMMANDINDEX_4 = 0x02, COMMANDINDEX_5 = 0x08 }; @@ -511,7 +550,7 @@ namespace Hantek { struct Tsr1Bits { unsigned char triggerSource:2; ///< The trigger source, see Hantek::TriggerSource unsigned char sampleSize:3; ///< Buffer size, 0 = Roll, 1 = 10240 S, 2 = 32768 S - unsigned char samplerateFast:3; ///< samplerate id for fast sampling rates + unsigned char samplerateFast:3; ///< samplerate value for fast sampling rates }; ////////////////////////////////////////////////////////////////////////////// @@ -528,7 +567,7 @@ namespace Hantek { struct Tsr2Bits { unsigned char usedChannel:2; ///< Used channels, see Hantek::UsedChannels unsigned char fastRate:1; ///< true, if one channels uses all buffers - unsigned char triggerSlope:1; ///< The trigger slope, see Dso::Slope + unsigned char triggerSlope:1; ///< The trigger slope, see Dso::Slope, inverted when Tsr1Bits.samplerateFast is uneven unsigned char reserved:4; ///< Unused bits }; @@ -567,8 +606,8 @@ namespace Hantek { unsigned char getTriggerSource(); void setTriggerSource(unsigned char value); - unsigned char getSampleSize(); - void setSampleSize(unsigned char value); + unsigned char getBufferSize(); + void setBufferSize(unsigned char value); unsigned char getSamplerateFast(); void setSamplerateFast(unsigned char value); unsigned char getUsedChannel(); @@ -578,7 +617,7 @@ namespace Hantek { unsigned char getTriggerSlope(); void setTriggerSlope(unsigned char slope); unsigned short int getSamplerate(); - void setSamplerate(unsigned short int samplerate); + void setSamplerateSlow(unsigned short int samplerate); unsigned long int getTriggerPosition(); void setTriggerPosition(unsigned long int position); -- libgit2 0.21.4
0x000x000x00