]> git.zerfleddert.de Git - rigol/commitdiff
export data through webinterface
authorMichael Gernoth <michael@gernoth.net>
Sat, 19 Jun 2010 17:16:16 +0000 (19:16 +0200)
committerMichael Gernoth <michael@gernoth.net>
Sat, 19 Jun 2010 17:16:16 +0000 (19:16 +0200)
rigold.c
scope.c
scope.h

index 93a5eb05a78c3c71d1d82fb4720cd616ee08be55..955975a0a1d1ab2539a5bc48202cc4bdb7c2f168 100644 (file)
--- a/rigold.c
+++ b/rigold.c
@@ -196,6 +196,13 @@ static void serve_index(int s, struct scope *sc, char *param)
                sc->status.math.displayed,
                sc->status.fft.displayed);
 
+       send_text(s, "<br>Data: ");
+       send_text(s, "<a href=\"/cgi-bin/data?CHAN1\">Channel 1</a> ");
+       send_text(s, "<a href=\"/cgi-bin/data?CHAN2\">Channel 2</a> ");
+       send_text(s, "<a href=\"/cgi-bin/data?DIG\">Digital</a> ");
+       send_text(s, "<a href=\"/cgi-bin/data?MATH\">Math</a> ");
+       send_text(s, "<a href=\"/cgi-bin/data?FFT\">FFT</a><br>");
+
        send_text(s, "<br>\n");
        send_text(s, "<form method=\"get\" action=\"\">\n");
        send_text(s, "<input type=\"text\" name=\"cmd\" value=\"");
@@ -249,6 +256,28 @@ static void serve_lcd(int s, struct scope *sc)
        free(png);
 }
 
+static void serve_data(int s, struct scope *sc, char *source)
+{
+       char *data;
+       int len;
+       int i;
+
+       send_text(s, "HTTP/1.0 200 OK\n");
+       send_text(s, "Content-type: text/plain\n\n");
+
+       claimscope(sc);
+       data = scope_get_data(sc, source, &len);
+       releasescope(sc);
+
+       if (data != NULL) {
+               for (i = 0; i < (len-1); i++) {
+                       send_text(s, "%d,", data[i]);
+               }
+               send_text(s, "%d", data[len-1]);
+               free(data);
+       }
+}
+
 static void serve_404(int s)
 {
        send_text(s, "HTTP/1.0 404 Not found\n");
@@ -349,6 +378,8 @@ static void parse_request(int s, struct scope *sc)
                serve_index(s, sc, param);
        } else if (strcmp("/cgi-bin/lcd", file) == 0) {
                serve_lcd(s, sc);
+       } else if (strcmp("/cgi-bin/data", file) == 0) {
+               serve_data(s, sc, param);
        } else {
                serve_404(s);
        }
diff --git a/scope.c b/scope.c
index 43439ff9219284b3299e7d903a262cd2f5b4ad63..09c9b8d1c0cd25a08e3f913b623efa185125b299 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -8,6 +8,17 @@
 #include "scope.h"
 #include "usbtmc.h"
 
+#define DATASIZE 10240
+
+#define COPY_SCOPE_STRING(sc, cmd, dst) { \
+                                               char *buf; \
+                                               buf = scope_get_string(sc, cmd, sizeof(dst)); \
+                                               if (buf) { \
+                                                       strcpy(dst, buf); \
+                                                       free(buf); \
+                                               }\
+                                       }
+
 /* Just USB for now... */
 int sendscpi(struct scope* sc, char* cmd, unsigned char *resp, int resplen)
 {
@@ -48,7 +59,7 @@ struct scope* initscope(void)
        }
 
        claimscope(sc);
-       sendscpi(sc, "*IDN?", (unsigned char*)sc->idn, sizeof(sc->idn)); 
+       COPY_SCOPE_STRING(sc, "*IDN?", sc->idn);
        releasescope(sc);
 
        printf("Scope found (%s)\n", sc->idn);
@@ -61,15 +72,6 @@ char *scope_idn(struct scope *sc)
        return sc->idn;
 }
 
-#define COPY_SCOPE_STRING(sc, cmd, dst) { \
-                                               char *buf; \
-                                               buf = scope_get_string(sc, cmd, sizeof(dst)); \
-                                               if (buf) { \
-                                                       strcpy(dst, buf); \
-                                                       free(buf); \
-                                               }\
-                                       }
-
 char *scope_get_string(struct scope *sc, char *cmd, int maxlen)
 {
        unsigned char *buf;
@@ -147,6 +149,22 @@ double scope_get_double(struct scope *sc, char*cmd)
        return ret;
 }
 
+char *scope_get_data(struct scope *sc, char *source, int *len)
+{
+       char *data = NULL;
+       char cmd[128];
+
+       if ((data = malloc(DATASIZE)) == NULL) {
+               perror("malloc");
+               return NULL;
+       }
+
+       snprintf(cmd, sizeof(cmd), ":WAV:DATA? %s", source);
+       *len = sendscpi(sc, cmd, (unsigned char*)data, DATASIZE);
+
+       return data;
+}
+
 void update_scope_measurements(struct scope *sc)
 {
        sc->status.measure.ch1.vpp = scope_get_double(sc, ":MEAS:VPP? CHAN1");
diff --git a/scope.h b/scope.h
index dba5670f3e614bb96baa17159e257c386153b4ea..a74809b3985af1d4d4c9a532ccd85dc8c83a05a2 100644 (file)
--- a/scope.h
+++ b/scope.h
@@ -133,3 +133,4 @@ int scope_get_int(struct scope *sc, char *cmd);
 double scope_get_double(struct scope *sc, char*cmd);
 void update_scope_measurements(struct scope *sc);
 int update_scope_status(struct scope *sc);
+char *scope_get_data(struct scope *sc, char *source, int *len);
Impressum, Datenschutz