/* * Remote Laboratory Instrumentation Server * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * (c) 2009 Timothy Pearson * Raptor Engineering * http://www.raptorengineeringinc.com */ #include #include #include #include #include #include #include #include #include "parameters.h" #include "gpib_functions.h" #include "gpib/ib.h" #include #include #define SCOPE_TRACE_MAX_POINTS 131072 extern char falpha[1024]; unsigned char scope_raw_screenshot_data[4194304]; double scope_raw_trace_data[SCOPE_TRACE_MAX_POINTS]; double scope_raw_position_data[SCOPE_TRACE_MAX_POINTS]; char scope_segarray[4194304]; unsigned long scopeScreenWidth (const char * scopeType) { if (strcmp("HP54600OS", scopeType) == 0) { return 512; } else if ((strcmp("TDS744AOS", scopeType) == 0) || (strcmp("TDS744COS", scopeType) == 0)) { return 640; } else { return 1; } } unsigned long scopeScreenHeight (const char * scopeType) { if (strcmp("HP54600OS", scopeType) == 0) { return 280; } else if ((strcmp("TDS744AOS", scopeType) == 0) || (strcmp("TDS744COS", scopeType) == 0)) { return 480; } else { return 1; } } unsigned long scopeScreenSize (const char * scopeType) { if (strcmp("HP54600OS", scopeType) == 0) { return scopeScreenWidth(scopeType)*scopeScreenHeight(scopeType)*3; } else if ((strcmp("TDS744AOS", scopeType) == 0) || (strcmp("TDS744COS", scopeType) == 0)) { return scopeScreenWidth(scopeType)*scopeScreenHeight(scopeType)*3; } else { return 1; } } int gpib_read_binblock(int ud, int max_num_bytes, const char * scopeType) { long array_pointer; long ai; int x; int y; array_pointer = 0; #ifdef ENABLE_EXTRA_DEBUGGING printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes); #endif ibtmo(ud, T30s); ibeos(ud, 0x0); ai = gpib_read_array(ud, max_num_bytes, scope_segarray); if (ai == -1) { return 1; } else { if (strcmp("HP54600OS", scopeType) == 0) { 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))] = (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; } } } else { return 2; } } ibtmo(ud, T10s); #ifdef ENABLE_EXTRA_DEBUGGING printf("[DEBG] Read %li bytes from GPIB device\n", array_pointer); #endif return 0; } int scope_get_screenshot_stage2(const char * scopeType, int gpibDevice) { long bytestosend; int k; int m; if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0) || (strcmp("TDS744COS", scopeType) == 0)) { printf("[INFO] Getting scope screenshot [Stage 2]\n\r"); if (strcmp("HP54600OS", scopeType) == 0) { if (gpib_read_binblock(gpibDevice, 19768, scopeType) == 0) { return 0; } else { return 1; } } else if ((strcmp("TDS744AOS", scopeType) == 0) || (strcmp("TDS744COS", scopeType) == 0)) { gpib_read_binary(gpibDevice, scopeScreenSize(scopeType)); int bpp; TQImage bmp; bmp.load("/tmp/current_scope_screenshot.bmp"); if (bmp.isNull()) { printf("[WARN] Unable to load screenshot bitmap\n\r"); return 1; } bpp = bmp.depth(); #ifdef ENABLE_EXTRA_DEBUGGING printf("[DEBG] Found BPP of %d\n\r", bpp); #endif bytestosend = 0; for (m=0;m 15) { ymult = resultPairs[13].toDouble(); yoffset = resultPairs[14].toDouble()*ymult; yposition = resultPairs[15].toDouble()*ymult; yunits = strdup(resultPairs[12]); xincr = resultPairs[9].toDouble(); xposition = resultPairs[10].toDouble(); xunits = strdup(resultPairs[8]); } } else if (strcmp("TDS744COS", scopeType) == 0) { if (resultPairs.count() > 15) { ymult = resultPairs[13].toDouble(); yoffset = resultPairs[14].toDouble()*ymult; yposition = resultPairs[15].toDouble()*ymult; yunits = strdup(resultPairs[12]); xincr = resultPairs[9].toDouble(); xposition = resultPairs[10].toDouble(); xunits = strdup(resultPairs[8]); } } #ifdef ENABLE_EXTRA_TRACE_DEBUGGING printf("[DEBG] Decoded preamble: xincr: %f ymult: %f\n", xincr, ymult); #endif // 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 printf("[DEBG] Writing: %s\n\r", falpha); #endif if (gpib_write(gpibDevice, falpha) == 0) { #ifdef ENABLE_PROFILING clock_gettime(CLOCK_REALTIME, &tp5); printf("[PROFILE] %f s\n\r", ((tp5.tv_nsec+(tp5.tv_sec*1e9))-(tp4.tv_nsec+(tp4.tv_sec*1e9)))/1e9); #endif #ifdef ENABLE_EXTRA_DEBUGGING printf("[DEBG] Trying to read %i bytes from GPIB device...\n", (SCOPE_TRACE_MAX_POINTS-1)*2); #endif ai = gpib_read_array(gpibDevice, (SCOPE_TRACE_MAX_POINTS-1)*2, scope_segarray); if (ai == -1) { return -1; } else { #ifdef ENABLE_PROFILING clock_gettime(CLOCK_REALTIME, &tp6); printf("[PROFILE] %f s\n\r", ((tp6.tv_nsec+(tp6.tv_sec*1e9))-(tp5.tv_nsec+(tp5.tv_sec*1e9)))/1e9); #endif #ifdef ENABLE_EXTRA_DEBUGGING printf("[DEBG] Read %li bytes from GPIB device\n", ai); #endif // Interpret the results long pointCount = ai/2; double horizPos = 0.0; char yheaderlen[2]; #ifdef ENABLE_EXTRA_TRACE_DEBUGGING printf("[DEBG] Point count: %d\n", pointCount); #endif yheaderlen[0] = scope_segarray[1]; yheaderlen[1] = 0; int data_offset = atoi(yheaderlen) + 2; for (array_pointer=0; array_pointer