X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/rigol/blobdiff_plain/610d5b65ca67c740ee40fc044ce502ddf3cba27a..2d17f2ab31a270ebbac95879fef6c7d3176d1960:/rigol.c diff --git a/rigol.c b/rigol.c index 24a4a10..0e9ff9e 100644 --- a/rigol.c +++ b/rigol.c @@ -13,12 +13,18 @@ rmmod uhci_hcd; modprobe uhci_hcd #include #include #include +#include +#include #include #include +#include +#include #include #include +#include "png.h" + //This routine locates a scope by VID/PID and returns an opened handle to it. usb_dev_handle *find_scope() { @@ -293,7 +299,74 @@ void do_get_buf (struct usb_dev_handle *sc) sendscpi (sc, ":TIM:OFFSET 0", NULL, 0); } +void do_get_screen(struct usb_dev_handle *sc) +{ + unsigned char screen[320*234]; + time_t lt; + char filename[256]; + unsigned char *png; + int imglen; + int ret; + int l; + int fd; + 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); + } + png = lcd2png(screen, &imglen); + + lt = time(NULL); + strftime(filename, sizeof(filename), "screen_%Y%m%d-%H%M%S.png", localtime(<)); + fd=open(filename, O_CREAT|O_WRONLY, 0644); + if (fd == -1) { + perror("open"); + exit(EXIT_FAILURE); + } + + while(imglen > 0) { + ret = write(fd, png, imglen); + if (ret == -1) { + perror("write"); + exit(EXIT_FAILURE); + } + imglen -= ret; + } + close(fd); + free(png); + + 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; + } +} + +void child_reaper(int sig) +{ + pid_t child; + + do { + child = waitpid(-1, NULL, WNOHANG); + } while(child > 0); + +} int main(int argc, char **argv) { @@ -301,6 +374,8 @@ int main(int argc, char **argv) char *scpi; unsigned char *buff; int l; + struct sigaction act; + //Init libusb usb_init(); //Locate and open the scope @@ -314,6 +389,19 @@ int main(int argc, char **argv) //Initialize scope initscope(sc); buff = malloc (1024*1024); + if (buff == NULL) { + perror("malloc"); + exit(EXIT_FAILURE); + } + + bzero(&act, sizeof(act)); + act.sa_handler = child_reaper; + act.sa_flags = SA_NOCLDSTOP|SA_RESTART; + if (sigaction(SIGCHLD, &act, NULL) == -1) { + perror("sigaction"); + exit(EXIT_FAILURE); + } + while (1) { scpi = readline ("> "); @@ -330,10 +418,14 @@ int main(int argc, char **argv) do_plot (sc); continue; } - if (strncmp (scpi, "databuf", 4) == 0) { + if (strncmp (scpi, "databuf", 7) == 0) { do_get_buf (sc); continue; } + if (strncmp (scpi, "screen", 6) == 0) { + do_get_screen (sc); + continue; + } l = strlen (scpi); //printf ("got buf(%d): ", l);