summaryrefslogtreecommitdiffstats
path: root/servers/gpib_server_lin/src/scope_functions.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-07-16 20:38:04 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-07-16 20:38:04 -0500
commite7ef2071e5f64e1a34201961592750a410060f1f (patch)
tree35bf14da99e4fdad4415cddbcb4a2f15d1c2538a /servers/gpib_server_lin/src/scope_functions.cpp
parenta0d24dbcfc9eb4f6caa6dc96f345183e3851f7af (diff)
downloadulab-e7ef2071e5f64e1a34201961592750a410060f1f.tar.gz
ulab-e7ef2071e5f64e1a34201961592750a410060f1f.zip
Streamline code and fix scope capture
Diffstat (limited to 'servers/gpib_server_lin/src/scope_functions.cpp')
-rw-r--r--servers/gpib_server_lin/src/scope_functions.cpp61
1 files changed, 36 insertions, 25 deletions
diff --git a/servers/gpib_server_lin/src/scope_functions.cpp b/servers/gpib_server_lin/src/scope_functions.cpp
index fb7d9a1..68f2274 100644
--- a/servers/gpib_server_lin/src/scope_functions.cpp
+++ b/servers/gpib_server_lin/src/scope_functions.cpp
@@ -41,6 +41,8 @@ unsigned char scope_raw_screenshot_data[4194304];
double scope_raw_trace_data[65535];
double scope_raw_position_data[65535];
+char scope_segarray[4194304];
+
unsigned long scopeScreenWidth (const char * scopeType) {
if (strcmp("HP54600OS", scopeType) == 0) {
return 512;
@@ -79,7 +81,6 @@ unsigned long scopeScreenSize (const char * scopeType) {
int gpib_read_binblock(int ud, int max_num_bytes, const char * scopeType)
{
- char segarray[4194304];
long array_pointer;
long ai;
@@ -95,7 +96,7 @@ int gpib_read_binblock(int ud, int max_num_bytes, const char * scopeType)
ibtmo(ud, T30s);
ibeos(ud, 0x0);
- ai = gpib_read_array(ud, max_num_bytes, segarray);
+ ai = gpib_read_array(ud, max_num_bytes, scope_segarray);
if (ai == -1) {
return 1;
}
@@ -104,14 +105,14 @@ int gpib_read_binblock(int ud, int max_num_bytes, const char * scopeType)
ai = 0;
for (x=0;x<scopeScreenWidth(scopeType);x++) {
for (y=0;y<scopeScreenHeight(scopeType);y++) {
- if ((x & 0x7) == 0) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (segarray[((x >> 3)+(y*(560/8)))+17] & 0x80) << 0;
- if ((x & 0x7) == 1) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (segarray[((x >> 3)+(y*(560/8)))+17] & 0x40) << 1;
- if ((x & 0x7) == 2) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (segarray[((x >> 3)+(y*(560/8)))+17] & 0x20) << 2;
- if ((x & 0x7) == 3) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (segarray[((x >> 3)+(y*(560/8)))+17] & 0x10) << 3;
- if ((x & 0x7) == 4) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (segarray[((x >> 3)+(y*(560/8)))+17] & 0x08) << 4;
- if ((x & 0x7) == 5) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (segarray[((x >> 3)+(y*(560/8)))+17] & 0x04) << 5;
- if ((x & 0x7) == 6) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (segarray[((x >> 3)+(y*(560/8)))+17] & 0x02) << 6;
- if ((x & 0x7) == 7) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (segarray[((x >> 3)+(y*(560/8)))+17] & 0x01) << 7;
+ if ((x & 0x7) == 0) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (scope_segarray[((x >> 3)+(y*(560/8)))+17] & 0x80) << 0;
+ if ((x & 0x7) == 1) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (scope_segarray[((x >> 3)+(y*(560/8)))+17] & 0x40) << 1;
+ if ((x & 0x7) == 2) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (scope_segarray[((x >> 3)+(y*(560/8)))+17] & 0x20) << 2;
+ if ((x & 0x7) == 3) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (scope_segarray[((x >> 3)+(y*(560/8)))+17] & 0x10) << 3;
+ if ((x & 0x7) == 4) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (scope_segarray[((x >> 3)+(y*(560/8)))+17] & 0x08) << 4;
+ if ((x & 0x7) == 5) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (scope_segarray[((x >> 3)+(y*(560/8)))+17] & 0x04) << 5;
+ if ((x & 0x7) == 6) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (scope_segarray[((x >> 3)+(y*(560/8)))+17] & 0x02) << 6;
+ if ((x & 0x7) == 7) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = (scope_segarray[((x >> 3)+(y*(560/8)))+17] & 0x01) << 7;
if (scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] == 0x0) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = 255;
if (scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] == 0x80) scope_raw_screenshot_data[y+(x*scopeScreenHeight(scopeType))] = 0;
}
@@ -606,8 +607,7 @@ int scope_perform_initial_setup(const char * scopeType, int gpibDevice) {
#define ENABLE_PROFILING
-int scope_get_channel_trace(int desired_channel, const char * scopeType, int gpibDevice) {
- char segarray[4194304];
+long scope_get_channel_trace(int desired_channel, const char * scopeType, int gpibDevice) {
long array_pointer;
long ai;
@@ -657,7 +657,7 @@ printf("[PROFILE] %f s\n\r", ((tp3.tv_nsec+(tp3.tv_sec*1e9))-(tp2.tv_nsec+(tp2.t
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Trying to read %i bytes from GPIB device...\n", 65535);
#endif
- ai = gpib_read_array(gpibDevice, 65535, segarray);
+ ai = gpib_read_array(gpibDevice, 65535, scope_segarray);
if (ai == -1) {
return -1;
}
@@ -669,16 +669,16 @@ printf("[PROFILE] %f s\n\r", ((tp3.tv_nsec+(tp3.tv_sec*1e9))-(tp2.tv_nsec+(tp2.t
clock_gettime(CLOCK_REALTIME, &tp4);
printf("[PROFILE] %f s\n\r", ((tp4.tv_nsec+(tp4.tv_sec*1e9))-(tp3.tv_nsec+(tp3.tv_sec*1e9)))/1e9);
#endif
- TQString preamble(segarray);
+ TQString preamble(scope_segarray);
TQStringList resultPairs = TQStringList::split(";", preamble, FALSE);
// Find/initialize critical data values
- double ymult;
- double yoffset;
- double yposition;
- const char* yunits;
- double xincr;
- double xposition;
- const char* xunits;
+ double ymult = 0;
+ double yoffset = 0;
+ double yposition = 0;
+ char* yunits = NULL;
+ double xincr = 0;
+ double xposition = 0;
+ char* xunits = NULL;
if (resultPairs.count() > 15) {
ymult = resultPairs[13].toDouble();
@@ -690,6 +690,14 @@ printf("[PROFILE] %f s\n\r", ((tp4.tv_nsec+(tp4.tv_sec*1e9))-(tp3.tv_nsec+(tp3.t
xunits = strdup(resultPairs[8]);
}
+ // If the units are desired, comment out these lines...
+ if (yunits) {
+ free(yunits);
+ }
+ if (xunits) {
+ free(xunits);
+ }
+
// Get the curve data now
sprintf(falpha,"CURVE?");
#ifdef ENABLE_EXTRA_DEBUGGING
@@ -703,7 +711,7 @@ printf("[PROFILE] %f s\n\r", ((tp5.tv_nsec+(tp5.tv_sec*1e9))-(tp4.tv_nsec+(tp4.t
#ifdef ENABLE_EXTRA_DEBUGGING
printf("[DEBG] Trying to read %i bytes from GPIB device...\n", 65535*2);
#endif
- ai = gpib_read_array(gpibDevice, 65535*2, segarray);
+ ai = gpib_read_array(gpibDevice, 65535*2, scope_segarray);
if (ai == -1) {
return -1;
}
@@ -718,10 +726,14 @@ printf("[PROFILE] %f s\n\r", ((tp6.tv_nsec+(tp6.tv_sec*1e9))-(tp5.tv_nsec+(tp5.t
// Interpret the results
long pointCount = ai/2;
double horizPos = 0.0;
+ char yheaderlen[2];
+ yheaderlen[0] = scope_segarray[1];
+ yheaderlen[1] = 0;
+ int data_offset = atoi(yheaderlen) + 2;
for (array_pointer=0; array_pointer<pointCount; array_pointer++) {
TQ_INT16 tempvalue;
- tempvalue = segarray[(array_pointer*2)+1]; // LSB
- tempvalue = tempvalue | (segarray[(array_pointer*2)+0] << 8); // MSB
+ tempvalue = scope_segarray[(array_pointer*2)+1+data_offset]; // LSB
+ tempvalue = tempvalue | (scope_segarray[(array_pointer*2)+0+data_offset] << 8); // MSB
scope_raw_trace_data[array_pointer] = tempvalue;
scope_raw_trace_data[array_pointer] = (scope_raw_trace_data[array_pointer] * ymult)-yoffset;
scope_raw_position_data[array_pointer] = horizPos;
@@ -925,7 +937,6 @@ int scope_get_channel_seconds_div(double * retval, int desired_channel, const ch
else {
floatstring[ai]=0;
*retval = ((atof(floatstring)*xincr)/scope_get_number_of_vertical_divisions(scopeType, gpibDevice));
-printf("[RAJA DEBUG 650.0] nr_p: %f, xincr: %E, vert_divs: %d, s/div: %f\n\r", atof(floatstring), xincr, scope_get_number_of_vertical_divisions(scopeType, gpibDevice), *retval); fflush(stdout);
}
#ifdef ENABLE_EXTRA_DEBUGGING