]> git.zerfleddert.de Git - rigol/blobdiff - rigold.c
display some state-informations on the web
[rigol] / rigold.c
index 6e383b71fb2322555fcf0ff384c95909cdd53cb5..29712e07b09db7230dc510be3032b9554c0d5a80 100644 (file)
--- a/rigold.c
+++ b/rigold.c
@@ -7,6 +7,7 @@
 #include <strings.h>
 #include <unistd.h>
 #include <signal.h>
+#include <stdarg.h>
 
 #include "scope.h"
 #include "commands.h"
@@ -30,19 +31,123 @@ static int send_binary(int s, char *buf, int len)
        return 0;
 }
 
-static int send_text(int s, char *buf)
+static int send_text(int s, char *fmt, ...)
 {
-       return send_binary(s, buf, strlen(buf));
+       va_list argp;
+       char buf[4096];
+       int cnt;
+
+       va_start(argp, fmt);
+       cnt = vsnprintf(buf, sizeof(buf), fmt, argp);
+       va_end(argp);
+
+       if (cnt < 0)
+               return cnt;
+
+       return send_binary(s, buf, cnt);
+}
+
+static int send_command_output(int s, struct scope *sc, char *cmd)
+{
+       unsigned char buf[1024*1024];
+       int res;
+
+       res = sendscpi(sc, cmd, buf, sizeof(buf));
+       send_binary(s, (char*)buf, res);
+
+       return res;
 }
 
-static void serve_index(int s, struct scope *sc)
+static void serve_index(int s, struct scope *sc, char *param)
 {
        send_text(s, "HTTP/1.0 200 OK\n");
        send_text(s, "Content-type: text/html\n\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, "<html><head><title>%s</title></head><body bgcolor=\"#ffffff\" text=\"#000000\">\n", scope_idn(sc));
+       send_text(s, "<img src=\"/cgi-bin/lcd\" height=\"234\" width=\"320\">\n");
+       send_text(s, "<br>\n");
+
+       claimscope(sc);
+       update_scope_status(sc);
+
+       send_text(s, "System: Language: %s, Counter: %d, Beep: %d<br>\n",
+               sc->status.system.lang,
+               sc->status.system.counter_enabled,
+               sc->status.system.beep_enabled);
+       
+       send_text(s, "Keyboard: Key Lock: %d<br>\n",
+               sc->status.keyboard.key_lock);
+
+       send_text(s, "Acquire: Type: %s, Mode: %s, Averages: %d<br>\n",
+               sc->status.acquire.type,
+               sc->status.acquire.mode,
+               sc->status.acquire.averages);
+
+       send_text(s, "Horizontal: Mode: %s, Offset: %lg, Delayed Offset: %lg, Scale: %lg, Format: %s<br>\n",
+               sc->status.timebase.mode,
+               sc->status.timebase.offset,
+               sc->status.timebase.delayed_offset,
+               sc->status.timebase.scale,
+               sc->status.timebase.format);
+
+       send_text(s, "Display: ");
+       send_command_output(s, sc, ":DISP:TYPE?");
+       send_text(s, ", ");
+       send_command_output(s, sc, ":DISP:SCR?");
+       send_text(s, ", Grid: ");
+       send_command_output(s, sc, ":DISP:GRID?");
+       send_text(s, ", Persistence: ");
+       send_command_output(s, sc, ":DISP:PERS?");
+       send_text(s, ", Menu: ");
+       send_command_output(s, sc, ":DISP:MNUS?");
+       send_text(s, ", Brightness: ");
+       send_command_output(s, sc, ":DISP:BRIG?");
+       send_text(s, ", Intensity: ");
+       send_command_output(s, sc, ":DISP:INT?");
+       send_text(s, "<br>\n");
+
+       send_text(s, "Channel 1: ");
+       send_command_output(s, sc, ":CHAN1:DISP?");
+       send_text(s, ", ");
+       send_command_output(s, sc, ":CHAN1:MEMD?");
+       send_text(s, " sample depth, %.10lg samples/s<br>\n", sc->status.acquire.srate_chan1);
+       send_text(s, "Channel 2: ");
+       send_command_output(s, sc, ":CHAN2:DISP?");
+       send_text(s, ", ");
+       send_command_output(s, sc, ":CHAN2:MEMD?");
+       send_text(s, " sample depth, %.10lg samples/s<br>\n", sc->status.acquire.srate_chan2);
+
+       releasescope(sc);
+
+       send_text(s, sc->status.system.lang);
+
+       send_text(s, "<br>\n");
+       send_text(s, "<form method=\"get\" action=\"\">\n");
+       send_text(s, "<input type=\"text\" name=\"cmd\" value=\"");
+       if (param) {
+               if (strncmp(param, "cmd=", 4) == 0)
+                       param += 4;
+
+               send_text(s, param);
+       }
+       send_text(s, "\">\n");
+       send_text(s, "<input type=\"submit\">\n");
+       send_text(s, "</form>\n");
+       send_text(s, "<a href=\"?cmd=:RUN\">RUN</a> ");
+       send_text(s, "<a href=\"?cmd=:STOP\">STOP</a> ");
+       send_text(s, "<a href=\"?cmd=:FORC\">FORCE</a> ");
+       if (param) {
+               claimscope(sc);
+               if (strchr (param, '?')) {
+                       send_text(s, "<pre>< ");
+                       send_text(s, param);
+                       send_text(s, "\n> ");
+                       send_command_output(s, sc, param);
+                       send_text(s, "</pre>\n");
+               } else {
+                       sendscpi(sc, param, NULL, 0);
+               }
+               releasescope(sc);
+       }
        send_text(s, "</body></html>\n");
 }
 
@@ -68,6 +173,16 @@ static void serve_lcd(int s, struct scope *sc)
        free(png);
 }
 
+static void serve_404(int s)
+{
+       send_text(s, "HTTP/1.0 404 Not found\n");
+       send_text(s, "Content-type: text/html\n\n");
+       send_text(s, "<html><head><title>404</title></head>");
+       send_text(s, "<body bgcolor=\"#ffffff\" text=\"#000000\">\n");
+       send_text(s, "<h1>404</h1>");
+       send_text(s, "</body></html>\n");
+}
+
 int is_eor(char *buf)
 {
        int eor = 0;
@@ -97,6 +212,7 @@ static void parse_request(int s, struct scope *sc)
        const char delim[] = " \t\x0d\x0a";
        char *saveptr;
        char *token;
+       char *param = NULL;
 
        alarm(TIMEOUT);
        ret=read(s, buf, sizeof(buf)-1);
@@ -130,10 +246,35 @@ static void parse_request(int s, struct scope *sc)
        }
        alarm(0);
 
+       param = strchr(file, '?');
+       if (param) {
+               *param = 0;
+               param++;
+
+               while ((token = strchr(param, '%')) != NULL) {
+                       char buf[3];
+
+                       if (strlen(token+1) < 2)
+                               break;
+
+                       strncpy(buf, token+1, 3);
+                       buf[2] = 0;
+
+                       *token = (char)strtoul(buf, NULL, 16);
+                       memmove(token+1, token+3, strlen(token)-2);
+
+               }
+               while ((token = strchr(param, '+')) != NULL) {
+                       *token = ' ';
+               }
+       }
+
        if (strcmp("/", file) == 0) {
-               serve_index(s, sc);
-       } else if (strcmp("/lcd.png", file) == 0) {
+               serve_index(s, sc, param);
+       } else if (strcmp("/cgi-bin/lcd", file) == 0) {
                serve_lcd(s, sc);
+       } else {
+               serve_404(s);
        }
 }
 
Impressum, Datenschutz