From e7ef2071e5f64e1a34201961592750a410060f1f Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Mon, 16 Jul 2012 20:38:04 -0500 Subject: [PATCH] Streamline code and fix scope capture --- lib/libtqtrla/src/tqtrla.cpp | 50 ++------------- servers/gpib_server_lin/src/gpib_conn.cpp | 3 +- .../gpib_server_lin/src/scope_functions.cpp | 61 +++++++++++-------- servers/gpib_server_lin/src/scope_functions.h | 2 +- 4 files changed, 43 insertions(+), 73 deletions(-) diff --git a/lib/libtqtrla/src/tqtrla.cpp b/lib/libtqtrla/src/tqtrla.cpp index b3fc1ec..711804e 100644 --- a/lib/libtqtrla/src/tqtrla.cpp +++ b/lib/libtqtrla/src/tqtrla.cpp @@ -326,30 +326,9 @@ TQDataStream &operator<<( TQDataStream &s, const TQFloatArray &data ) { TQ_UINT32 i; TQ_UINT32 count = data.count(); s << count; - - TQIODevice* dev = s.device(); - if (dev) { - // This uses the channel efficiently by writing all the data in one large block - TQBuffer ba; - ba.open(IO_ReadWrite); - TQDataStream ds(&ba); - ds.setPrintableData(s.isPrintableData()); - - for (i=0; iwriteBlock(buffer.data(), buffer.size()); - } - else { - // This uses the channel inefficiently by writing the data in byte-sized chunks - for (i=0; iwriteBlock(buffer.data(), buffer.size()); - } - else { - // This uses the channel inefficiently by writing the data in byte-sized chunks - for (i=0; im_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket); if (traceLength > 0) { - int i; + long i; TQDoubleArray traceData; TQDoubleArray positionData; traceData.resize(traceLength); @@ -300,6 +300,7 @@ void GPIBSocket::commandLoop() { traceData[i] = scope_raw_trace_data[i]; positionData[i] = scope_raw_position_data[i]; } +printf("[RAJA DEBUG 680.0] traceData[10]: %E positionData[10]: %E\n\r", traceData[10], positionData[10]); fflush(stdout); ds << TQString("ACK"); ds << traceData; ds << positionData; 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> 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