-
-void do_plot (struct usb_dev_handle *sc)
-{
- unsigned char ch1[1024], ch2[1024];
- int i, l;
-
- static FILE *gnuplot=NULL;
- FILE *fp;
-
- l = sendscpi(sc, ":WAV:DATA? CHANEL1", ch1, 1024);
-
- if (l != 1024) {
- printf ("hmm. didnt' get 1024 bytes. \n");
- }
-
- l = sendscpi(sc, ":WAV:DATA? CHANNEL2", ch2, 1024);
-
- if (l != 1024) {
- printf ("hmm. didnt' get 1024 bytes. \n");
- }
-
- if (!gnuplot) {
- gnuplot = popen ("gnuplot", "w");
- }
-
- fp = fopen ("temp.dat", "w");
- for (i=0xd4;i<0x32c;i++)
- //for (i=0;i<0x400;i++)
- fprintf (fp, "%d %d\n", 255 - ch1[i], 255 - ch2[i]);
- fclose (fp);
-
- fprintf (gnuplot, "plot 'temp.dat' using 1 with lines, 'temp.dat' using 2 with lines\n");
- fflush (gnuplot);
-}
-
-
-#define ERROR -1e100
-
-double get_float_from_scope (struct usb_dev_handle *sc, char *var)
-{
- unsigned char buf[1024];
- double temp;
- int l;
-
- l = sendscpi(sc, var, buf, 1024);
- if (l > 0) {
- sscanf ((char*)buf, "%lf", &temp);
- return temp;
- }
- return ERROR;
-}
-
-
-void do_get_buf (struct usb_dev_handle *sc)
-{
- FILE *fp;
- int i, j, l, bp;
- char buf[1024];
- unsigned char ch1[1024];
- unsigned char data[512*1024];
- double sampfreq;
-
- sendscpi (sc, ":STOP", NULL, 0);
-
- sampfreq = get_float_from_scope (sc, ":ACQ:SAMP?");
-
- printf ("Got sampling freq: %g\n", sampfreq);
-
- sprintf (buf, ":TIM:SCAL %.15f", 50 / sampfreq);
- printf ("sending scale cmd: %s\n", buf);
- sendscpi (sc, buf, NULL, 0);
-
- sleep (1);
-
- bp=0;
- for (i=-254*1024;i< 254*1024;i += 600) {
- sprintf (buf, ":TIM:OFFSET %.15f", i / sampfreq);
- printf ("Sending offset cmd: %s\n", buf);
- sendscpi (sc, buf, NULL, 0);
-
- l = sendscpi(sc, ":WAV:DATA? CHANEL1", ch1, 1024);
-
- if (l != 1024) {
- printf ("hmm. didnt' get 1024 bytes. \n");
- }
-
- for (j=0;j<600;j++)
- data[bp++] = ch1[j+0xd4];
- }
- printf ("Got %d bytes of data. \n", bp);
-
- fp = fopen ("ch1.dump", "w");
- fwrite (data, bp, 1, fp);
- fclose (fp);
-
- sendscpi (sc, ":TIM:OFFSET 0", NULL, 0);
-}
-
-void do_get_screen(struct usb_dev_handle *sc)
-{
- unsigned char screen[320*234];
- unsigned char screen_conv[320*234*3];
- unsigned char lut[256][3];
- time_t lt;
- char filename[256];
- int i;
- int l;
- FILE *fp;
- pid_t display;
-
- /* Hide "RMT" from screen */
- l = sendscpi(sc, ":KEY:LOCK DISABLE", NULL, 0);
- usleep(20000);
-
- l = sendscpi(sc, ":LCD:DATA?", screen, sizeof(screen));
-
- if (l != sizeof(screen)) {
- printf ("hmm. didnt' get %d bytes, but %d\n\n", sizeof(screen), l);
- }
-
- for(i = 0; i < 256; i++) {
- lut[i][0] = ((i >> 6) * 0x55);
- lut[i][1] = ((((i >> 3) & 7) * 0x49) >> 1);
- lut[i][2] = (((i & 7) * 0x49) >> 1);
- }
-
- for(i = 0; i < sizeof(screen_conv); i += 3) {
- screen_conv[i] = lut[screen[i/3]][0];
- screen_conv[i+1] = lut[screen[i/3]][1];
- screen_conv[i+2] = lut[screen[i/3]][2];
- }
-
- lt = time(NULL);
- strftime(filename, sizeof(filename), "screen_%Y%m%d-%H%M%S.ppm", localtime(<));
-
- fp = fopen (filename, "w");
- fprintf(fp, "P6\n320 234\n255\n");
- fwrite(screen_conv, sizeof(screen_conv), 1, fp);
- fclose (fp);
-
- printf("Waveform saved as %s\n", filename);
-
- display = fork();
- switch(display) {
- case 0:
- execlp("display", "display", filename, NULL);
- exit(0);
- break;
- case -1:
- perror("fork");
- break;
- default:
- break;
- }
-}
-