]> git.zerfleddert.de Git - rigol/blobdiff - rigold.c
add abstraction for scope-access
[rigol] / rigold.c
index 0be124f1147c877e81321983c9517eedc6530c2e..974a814f348f8d0fdeb9fb2da71eb52c9ba9da18 100644 (file)
--- a/rigold.c
+++ b/rigold.c
@@ -5,9 +5,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <strings.h>
-#include <usb.h>
+#include <unistd.h>
 
-#include "usbtmc.h"
+#include "scope.h"
 #include "commands.h"
 
 static int send_binary(int s, char *buf, int len)
@@ -32,24 +32,26 @@ static int send_text(int s, char *buf)
        return send_binary(s, buf, strlen(buf));
 }
 
-static void serve_index(int s)
+static void serve_index(int s, struct scope *sc)
 {
        send_text(s, "HTTP/1.0 200 OK");
        send_text(s, "Content-type: text/html\n\n");
-       send_text(s, "<html><head><title>Rigol DS1000</title></head><body bgcolor=\"#ffffff\" text=\"#000000\">\n");
+       send_text(s, "<html><head><title>");
+       send_text(s, scope_idn(sc));
+       send_text(s, "</title></head><body bgcolor=\"#ffffff\" text=\"#000000\">\n");
        send_text(s, "<img src=\"/lcd.png\" height=\"234\" width=\"320\">\n");
        send_text(s, "</body></html>\n");
 }
 
-static void serve_lcd(int s, struct usb_dev_handle *sc)
+static void serve_lcd(int s, struct scope *sc)
 {
        char buf[256];
        int imglen;
        unsigned char *png;
 
-       usbtmc_claim(sc);
+       claimscope(sc);
        png = get_lcd(sc, &imglen, 0);
-       usbtmc_release(sc);
+       releasescope(sc);
 
        if (png == NULL)
                return;
@@ -63,7 +65,7 @@ static void serve_lcd(int s, struct usb_dev_handle *sc)
        free(png);
 }
 
-static void parse_request(int s, struct usb_dev_handle *sc)
+static void parse_request(int s, struct scope *sc)
 {
        int ret;
        char buf[1024];
@@ -107,7 +109,7 @@ static void parse_request(int s, struct usb_dev_handle *sc)
        } while(token != NULL);
 
        if (strcmp("/", file) == 0) {
-               serve_index(s);
+               serve_index(s, sc);
        } else if (strcmp("/lcd.png", file) == 0) {
                serve_lcd(s, sc);
        }
@@ -118,11 +120,11 @@ int main(int argc, char **argv)
        int sock, csock;
        int opt;
        socklen_t slen;
-       struct usb_dev_handle *sc;
+       struct scope *sc;
        struct sockaddr_in sin, clientsin;
        unsigned short port = 8088;
 
-       sc = usbtmc_initscope();
+       sc = initscope();
 
        if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
                perror("socket");
@@ -161,6 +163,6 @@ int main(int argc, char **argv)
                close(csock);
        }
 
-       usbtmc_close(sc);
+       closescope(sc);
        return 0;
 }
Impressum, Datenschutz