Branch: master

260c25eb 2014-04-24 00:11:08 Timothy Pearson
Add GETPERMITTEDSDIVS command to gpib server
M servers/gpib_server_lin/src/gpib_conn.cpp
M servers/gpib_server_lin/src/scope_functions.cpp
M servers/gpib_server_lin/src/scope_functions.h
diff --git a/servers/gpib_server_lin/src/gpib_conn.cpp b/servers/gpib_server_lin/src/gpib_conn.cpp
index c211f84..df5be78 100644
--- a/servers/gpib_server_lin/src/gpib_conn.cpp
+++ b/servers/gpib_server_lin/src/gpib_conn.cpp
@@ -549,6 +549,27 @@
 										writeEndOfFrame();
 									}
 								}
+								else if (m_instrumentCommand == "GETPERMITTEDSDIVS") {		// Want to get permitted seconds/div settings
+									double* permitted_array;
+									int permitted_count;
+									TQ_INT32 value;
+									ds >> value;
+									if (scope_get_permitted_seconds_div_settings(&permitted_count, &permitted_array, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket) == 0) {
+										long i;
+										TQDoubleList permittedValues;
+										for (i=0; i<permitted_count; i++) {
+											permittedValues.append(permitted_array[i]);
+										}
+										free(permitted_array);
+										ds << TQString("ACK");
+										ds << permittedValues;
+										writeEndOfFrame();
+									}
+									else {
+										ds << TQString("NCK");
+										writeEndOfFrame();
+									}
+								}
 								else {
 									printf("[WARNING] Received unknown command %s from host %s\n\r", m_instrumentCommand.ascii(), m_remoteHost.ascii()); fflush(stdout);
 									ds << TQString("NCK");
@@ -1116,20 +1137,20 @@
 			printf("[FAIL] Unable to open serial device %s\n\r", m_serialDevice.ascii()); fflush(stdout);
 			return 1;
 		}
-	
+
 		tcgetattr(m_serialDeviceSocket, &oldtio);	// Save current port settings
 
 		bzero(&newtio, sizeof(newtio));
 		newtio.c_cflag = m_serialBaud | CS8 | CLOCAL | CREAD;
 		newtio.c_iflag = IGNPAR;
 		newtio.c_oflag = 0;
-	
+
 		// Set input mode (non-canonical, no echo,...)
 		newtio.c_lflag = 0;
-	
+
 		newtio.c_cc[VTIME] = 0;	// Inter-character timer unused
 		newtio.c_cc[VMIN]  = 0;	// Blocking read unused
-		
+
 		tcflush(m_serialDeviceSocket, TCIFLUSH);
 		tcsetattr(m_serialDeviceSocket, TCSANOW, &newtio);
 
diff --git a/servers/gpib_server_lin/src/scope_functions.cpp b/servers/gpib_server_lin/src/scope_functions.cpp
index 2cedf45..5b3e34c 100644
--- a/servers/gpib_server_lin/src/scope_functions.cpp
+++ b/servers/gpib_server_lin/src/scope_functions.cpp
@@ -378,7 +378,7 @@
 		#ifdef ENABLE_EXTRA_DEBUGGING
 		printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
 		#endif
-	
+
 		ai = gpib_read_array(gpibDevice, max_num_bytes, floatstring);
 		if (ai == -1) {
 			return 1;
@@ -387,7 +387,7 @@
 			floatstring[ai]=0;
 			*retval = atoi(floatstring);
 		}
-	
+
 		#ifdef ENABLE_EXTRA_DEBUGGING
 		printf("[DEBG] Read %li bytes from GPIB device\n", ai);
 		#endif
@@ -479,7 +479,7 @@
 		#ifdef ENABLE_EXTRA_DEBUGGING
 		printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
 		#endif
-	
+
 		ai = gpib_read_array(gpibDevice, max_num_bytes, floatstring);
 		if (ai == -1) {
 			return 1;
@@ -488,7 +488,7 @@
 			floatstring[ai]=0;
 			*retval = atoi(floatstring);
 		}
-	
+
 		#ifdef ENABLE_EXTRA_DEBUGGING
 		printf("[DEBG] Read %li bytes from GPIB device\n", ai);
 		#endif
@@ -563,7 +563,7 @@
 		#ifdef ENABLE_EXTRA_DEBUGGING
 		printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
 		#endif
-	
+
 		ai = gpib_read_array(gpibDevice, max_num_bytes, floatstring);
 		if (ai == -1) {
 			return 1;
@@ -582,7 +582,7 @@
 				return -1;
 			}
 		}
-	
+
 		#ifdef ENABLE_EXTRA_DEBUGGING
 		printf("[DEBG] Read %li bytes from GPIB device\n", ai);
 		#endif
@@ -658,7 +658,7 @@
 		#ifdef ENABLE_EXTRA_DEBUGGING
 		printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
 		#endif
-	
+
 		ai = gpib_read_array(gpibDevice, max_num_bytes, floatstring);
 		if (ai == -1) {
 			return 1;
@@ -667,7 +667,7 @@
 			floatstring[ai]=0;
 			*retval = atof(floatstring);
 		}
-	
+
 		#ifdef ENABLE_EXTRA_DEBUGGING
 		printf("[DEBG] Read %li bytes from GPIB device\n", ai);
 		#endif
@@ -990,7 +990,7 @@
 		#ifdef ENABLE_EXTRA_DEBUGGING
 		printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
 		#endif
-	
+
 		ai = gpib_read_array(gpibDevice, max_num_bytes, floatstring);
 		if (ai == -1) {
 			return 1;
@@ -999,7 +999,7 @@
 			floatstring[ai]=0;
 			*retval = atof(floatstring);
 		}
-	
+
 		#ifdef ENABLE_EXTRA_DEBUGGING
 		printf("[DEBG] Read %li bytes from GPIB device\n", ai);
 		#endif
@@ -1057,7 +1057,7 @@
 		#ifdef ENABLE_EXTRA_DEBUGGING
 		printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
 		#endif
-	
+
 		ai = gpib_read_array(gpibDevice, max_num_bytes, floatstring);
 		if (ai == -1) {
 			return 1;
@@ -1066,7 +1066,7 @@
 			floatstring[ai]=0;
 			xincr = atof(floatstring);
 		}
-	
+
 		#ifdef ENABLE_EXTRA_DEBUGGING
 		printf("[DEBG] Read %li bytes from GPIB device\n", ai);
 		#endif
@@ -1086,7 +1086,7 @@
 		#ifdef ENABLE_EXTRA_DEBUGGING
 		printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
 		#endif
-	
+
 		ai = gpib_read_array(gpibDevice, max_num_bytes, floatstring);
 		if (ai == -1) {
 			return 1;
@@ -1095,7 +1095,7 @@
 			floatstring[ai]=0;
 			*retval = ((atof(floatstring)*xincr)/scope_get_number_of_vertical_divisions(scopeType, gpibDevice));
 		}
-	
+
 		#ifdef ENABLE_EXTRA_DEBUGGING
 		printf("[DEBG] Read %li bytes from GPIB device\n", ai);
 		#endif
@@ -1151,7 +1151,7 @@
 		#ifdef ENABLE_EXTRA_DEBUGGING
 		printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
 		#endif
-	
+
 		ai = gpib_read_array(gpibDevice, max_num_bytes, floatstring);
 		if (ai == -1) {
 			return 1;
@@ -1160,7 +1160,7 @@
 			floatstring[ai]=0;
 			*retval = atof(floatstring);
 		}
-	
+
 		#ifdef ENABLE_EXTRA_DEBUGGING
 		printf("[DEBG] Read %li bytes from GPIB device\n", ai);
 		#endif
@@ -1200,7 +1200,7 @@
 		#ifdef ENABLE_EXTRA_DEBUGGING
 		printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes);
 		#endif
-	
+
 		ai = gpib_read_array(gpibDevice, max_num_bytes, floatstring);
 		if (ai == -1) {
 			return 1;
@@ -1209,7 +1209,7 @@
 			floatstring[ai]=0;
 			*retval = atof(floatstring);
 		}
-	
+
 		#ifdef ENABLE_EXTRA_DEBUGGING
 		printf("[DEBG] Read %li bytes from GPIB device\n", ai);
 		#endif
@@ -1249,4 +1249,49 @@
 	else {
 		return -1;
 	}
-}
\ No newline at end of file
+}
+
+int scope_get_permitted_seconds_div_settings(int * number_of_values, double ** retarray, const char * scopeType, int gpibDevice) {
+	if (strcmp("HP54600OS", scopeType) == 0) {
+		// FIXME
+		// Not supported (yet)
+		return -1;
+	}
+	else if (strcmp("TDS744AOS", scopeType) == 0) {
+		*number_of_values = 28;
+		double* values = (double*)malloc(sizeof(double)*(*number_of_values));
+		values[0] = 1.25e-8;
+		values[1] = 2.5e-8;
+		values[2] = 5e-8;
+		values[3] = 1e-7;
+		values[4] = 2e-7;
+		values[5] = 5e-7;
+		values[6] = 1e-6;
+		values[7] = 2e-6;
+		values[8] = 5e-6;
+		values[9] = 1e-5;
 ** Diff limit reached (max: 250 lines) **