new "display" command to just show the display content
authorMichael Gernoth <michael@gernoth.net>
Sun, 6 Jun 2010 12:54:29 +0000 (14:54 +0200)
committerMichael Gernoth <michael@gernoth.net>
Sun, 6 Jun 2010 12:54:29 +0000 (14:54 +0200)
commands.c
rigol.c

index f5b397352371040eb7e67f8c0c2e2d8a9056ad0f..646d3dec8d6cba04e646f72e12257f37e8f3e425 100644 (file)
@@ -106,17 +106,11 @@ void do_get_buf (struct usb_dev_handle *sc)
        usbtmc_sendscpi (sc, ":TIM:OFFSET 0", NULL, 0);
 }
 
-void do_get_screen(struct usb_dev_handle *sc)
+static unsigned char* get_lcd(struct usb_dev_handle *sc, int *imglen)
 {
        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 = usbtmc_sendscpi(sc, ":KEY:LOCK DISABLE", NULL, 0); 
@@ -128,21 +122,40 @@ void do_get_screen(struct usb_dev_handle *sc)
                printf ("hmm. didnt' get %d bytes, but %d\n\n", sizeof(screen), l); 
        }
 
-       png = lcd2png(screen, &imglen);
+       png = lcd2png(screen, imglen);
+
+       return png;
+}
+
+void do_get_screen(struct usb_dev_handle *sc)
+{
+       time_t lt;
+       char filename[256];
+       unsigned char *png;
+       int imglen;
+       int ret;
+       int fd;
+       pid_t display;
+
+       png = get_lcd(sc, &imglen);
+       if (png == NULL) {
+               perror("get_lcd");
+               return;
+       }
 
        lt = time(NULL);
        strftime(filename, sizeof(filename), "screen_%Y%m%d-%H%M%S.png", localtime(&lt));
        fd=open(filename, O_CREAT|O_WRONLY, 0644);
        if (fd == -1) {
                perror("open");
-               exit(EXIT_FAILURE);
+               return;
        }
 
        while(imglen > 0) {
                ret = write(fd, png, imglen);
                if (ret == -1) {
                        perror("write");
-                       exit(EXIT_FAILURE);
+                       return;
                }
                imglen -= ret;
        }
@@ -165,3 +178,49 @@ void do_get_screen(struct usb_dev_handle *sc)
        }
 }
 
+void do_display_screen(struct usb_dev_handle *sc)
+{
+       unsigned char *png;
+       int imglen;
+       int ret;
+       int pipefd[2];
+       pid_t display;
+
+       png = get_lcd(sc, &imglen);
+       if (png == NULL) {
+               perror("get_lcd");
+               return;
+       }
+
+       if (pipe(pipefd) == -1) {
+               perror("pipe");
+               return;
+       }
+
+       display = fork();
+       switch(display) {
+               case 0:
+                       close(pipefd[1]);
+                       close(STDIN_FILENO);
+                       dup2(pipefd[0], STDIN_FILENO);
+                       execlp("display", "display", "-", NULL);
+                       exit(0);
+                       break;
+               case -1:
+                       perror("fork");
+                       break;
+               default:
+                       close(pipefd[0]);
+                       while(imglen > 0) {
+                               ret = write(pipefd[1], png, imglen);
+                               if (ret == -1) {
+                                       perror("write");
+                                       exit(EXIT_FAILURE);
+                               }
+                               imglen -= ret;
+                       }
+                       close(pipefd[1]);
+                       break;
+       }
+}
+
diff --git a/rigol.c b/rigol.c
index 22a5ceac242f798215b7eaf0003200f5a1c83b68..93b85665c0c3c2fe7f70038d95cc313534c38d0d 100644 (file)
--- a/rigol.c
+++ b/rigol.c
@@ -135,11 +135,15 @@ int main(int argc, char **argv)
                        continue;
                }
                if (strncmp (scpi, "databuf", 7) == 0) {
-                       do_get_buf (sc);
+                       do_get_buf(sc);
                        continue;
                }
                if (strncmp (scpi, "screen", 6) == 0) {
-                       do_get_screen (sc);
+                       do_get_screen(sc);
+                       continue;
+               }
+               if (strncmp (scpi, "display", 7) == 0) {
+                       do_display_screen(sc);
                        continue;
                }
 
Impressum, Datenschutz