]> git.zerfleddert.de Git - rigol/commitdiff
display some state-informations on the web
authorMichael Gernoth <michael@gernoth.net>
Thu, 10 Jun 2010 20:40:58 +0000 (22:40 +0200)
committerMichael Gernoth <michael@gernoth.net>
Thu, 10 Jun 2010 20:40:58 +0000 (22:40 +0200)
rigold.c
scope.c
scope.h

index 111c5d6a6da7c03892702c516b6bbbf89059e3fe..29712e07b09db7230dc510be3032b9554c0d5a80 100644 (file)
--- a/rigold.c
+++ b/rigold.c
@@ -7,6 +7,7 @@
 #include <strings.h>
 #include <unistd.h>
 #include <signal.h>
 #include <strings.h>
 #include <unistd.h>
 #include <signal.h>
+#include <stdarg.h>
 
 #include "scope.h"
 #include "commands.h"
 
 #include "scope.h"
 #include "commands.h"
@@ -30,19 +31,95 @@ static int send_binary(int s, char *buf, int len)
        return 0;
 }
 
        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, char *param)
 {
        send_text(s, "HTTP/1.0 200 OK\n");
        send_text(s, "Content-type: text/html\n\n");
 }
 
 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, "<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, "<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=\"");
        send_text(s, "<br>\n");
        send_text(s, "<form method=\"get\" action=\"\">\n");
        send_text(s, "<input type=\"text\" name=\"cmd\" value=\"");
@@ -55,17 +132,16 @@ static void serve_index(int s, struct scope *sc, char *param)
        send_text(s, "\">\n");
        send_text(s, "<input type=\"submit\">\n");
        send_text(s, "</form>\n");
        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) {
        if (param) {
-               unsigned char buf[1024*1024];
-               int res;
-
                claimscope(sc);
                if (strchr (param, '?')) {
                claimscope(sc);
                if (strchr (param, '?')) {
-                       res = sendscpi(sc, param, buf, sizeof(buf));
                        send_text(s, "<pre>< ");
                        send_text(s, param);
                        send_text(s, "\n> ");
                        send_text(s, "<pre>< ");
                        send_text(s, param);
                        send_text(s, "\n> ");
-                       send_binary(s, (char*)buf, res);
+                       send_command_output(s, sc, param);
                        send_text(s, "</pre>\n");
                } else {
                        sendscpi(sc, param, NULL, 0);
                        send_text(s, "</pre>\n");
                } else {
                        sendscpi(sc, param, NULL, 0);
@@ -188,6 +264,9 @@ static void parse_request(int s, struct scope *sc)
                        memmove(token+1, token+3, strlen(token)-2);
 
                }
                        memmove(token+1, token+3, strlen(token)-2);
 
                }
+               while ((token = strchr(param, '+')) != NULL) {
+                       *token = ' ';
+               }
        }
 
        if (strcmp("/", file) == 0) {
        }
 
        if (strcmp("/", file) == 0) {
diff --git a/scope.c b/scope.c
index c316ee527e3f021eb52c6130d958fe6f6b8b85e8..30f175a7de8f9a7ceea01f28b4d0f8b1082f932e 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -2,6 +2,8 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdint.h>
+#include <string.h>
+#include <strings.h>
 
 #include "scope.h"
 #include "usbtmc.h"
 
 #include "scope.h"
 #include "usbtmc.h"
@@ -58,3 +60,119 @@ char *scope_idn(struct scope *sc)
 {
        return sc->idn;
 }
 {
        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;
+       int res;
+
+       buf = malloc(maxlen);
+       if (buf == NULL) {
+               perror("malloc(scope_get_strings)");
+               exit(EXIT_FAILURE);
+       }
+
+       res = sendscpi(sc, cmd, buf, maxlen);
+       if (res < 0) {
+               fprintf(stderr, "Command %s failed with %d\n", cmd, res);
+               free(buf);
+               return NULL;
+       }
+
+       buf[res] = 0;
+
+       return (char*)buf;
+}
+
+int scope_get_truth_value(struct scope *sc, char *cmd)
+{
+       char buf[128];
+       int res;
+
+       bzero(buf, sizeof(buf));
+       res = sendscpi(sc, cmd, (unsigned char*)buf, sizeof(buf)-1);
+       if (res < 0) {
+               fprintf(stderr, "Command %s failed with %d\n", cmd, res);
+               return 0;
+       }
+
+       printf("%s %s\n", cmd, buf);
+
+       if (strcasecmp(buf, "on") == 0) {
+               return 1;
+       } else if (strcasecmp(buf, "enable") == 0) {
+               return 1;
+       }
+
+       return 0;
+}
+
+int scope_get_int(struct scope *sc, char *cmd)
+{
+       char buf[128];
+       int res;
+
+       bzero(buf, sizeof(buf));
+       res = sendscpi(sc, cmd, (unsigned char*)buf, sizeof(buf)-1);
+       if (res < 0) {
+               fprintf(stderr, "Command %s failed with %d\n", cmd, res);
+               return 0;
+       }
+
+       return atoi(buf);
+}
+
+double scope_get_double(struct scope *sc, char*cmd)
+{
+       char buf[128];
+       int res;
+       double ret;
+
+       bzero(buf, sizeof(buf));
+       res = sendscpi(sc, cmd, (unsigned char*)buf, sizeof(buf)-1);
+       if (res < 0) {
+               fprintf(stderr, "Command %s failed with %d\n", cmd, res);
+               return 0.0;
+       }
+
+       ret = strtod(buf, NULL);
+
+       return ret;
+}
+
+int update_scope_status(struct scope *sc)
+{
+       bzero(&(sc->status), sizeof(sc->status));
+
+       COPY_SCOPE_STRING(sc, ":INFO:LANG?", sc->status.system.lang);
+
+       sc->status.system.counter_enabled = scope_get_truth_value(sc, ":COUN:ENAB?");
+       sc->status.system.beep_enabled = scope_get_truth_value(sc, ":BEEP:ENAB?");
+
+       sc->status.keyboard.key_lock = scope_get_truth_value(sc, ":KEY:LOCK?");
+
+       COPY_SCOPE_STRING(sc, ":ACQ:TYPE?", sc->status.acquire.type);
+       COPY_SCOPE_STRING(sc, ":ACQ:MODE?", sc->status.acquire.mode);
+
+       sc->status.acquire.averages = scope_get_int(sc, ":ACQ:AVER?");
+       sc->status.acquire.srate_chan1 = scope_get_double(sc, ":ACQ:SAMP? CHAN1");
+       sc->status.acquire.srate_chan2 = scope_get_double(sc, ":ACQ:SAMP? CHAN2");
+       sc->status.acquire.srate_digital = scope_get_double(sc, ":ACQ:SAMP? DIGITAL");
+
+       COPY_SCOPE_STRING(sc, ":TIM:MODE?", sc->status.timebase.mode);
+       sc->status.timebase.offset = scope_get_double(sc, ":TIM:OFFS?");
+       sc->status.timebase.delayed_offset = scope_get_double(sc, ":TIM:DEL:OFFS?");
+       sc->status.timebase.scale = scope_get_double(sc, ":TIM:SCAL?");
+       COPY_SCOPE_STRING(sc, ":TIM:FORM?", sc->status.timebase.format);
+
+       return 0;
+}
diff --git a/scope.h b/scope.h
index 2f3a61ab3d21c3ff3856f1b4e71033303f469460..cef5e650e4c5125527b410b046ba80d714f13817 100644 (file)
--- a/scope.h
+++ b/scope.h
@@ -8,6 +8,58 @@ struct scope {
                int brokenRigol;
                struct usbtmc_capabilities *cap;
        } usb;
                int brokenRigol;
                struct usbtmc_capabilities *cap;
        } usb;
+       struct {
+               struct {
+                       char lang[32];
+                       int counter_enabled;
+                       int beep_enabled;
+               } system;
+
+               struct {
+                       int key_lock;
+               } keyboard;
+
+               struct {
+                       /* TODO */
+               } measure;
+
+               struct {
+                       char type[32];
+                       char mode[32];
+                       int averages;
+                       double srate_chan1;
+                       double srate_chan2;
+                       double srate_digital;
+               } acquire;
+
+               struct {
+                       /* TODO */
+               } display;
+
+               struct {
+                       /* TODO */
+               } channel;
+
+               struct {
+                       char mode[32];
+                       double offset;
+                       double delayed_offset;
+                       double scale;
+                       char format[32];
+               } timebase;
+
+               struct {
+                       /* TODO */
+               } trigger;
+
+               struct {
+                       /* TODO */
+               } la;
+
+               struct {
+                       /* TODO */
+               } math;
+       } status;
        char idn[128];
 };
 
        char idn[128];
 };
 
@@ -18,3 +70,8 @@ void claimscope(struct scope* sc);
 void releasescope(struct scope* sc);
 void resetscope(struct scope* sc);
 char *scope_idn(struct scope *sc);
 void releasescope(struct scope* sc);
 void resetscope(struct scope* sc);
 char *scope_idn(struct scope *sc);
+char *scope_get_string(struct scope *sc, char *cmd, int maxlen);
+int scope_get_truth_value(struct scope *sc, char *cmd);
+int scope_get_int(struct scope *sc, char *cmd);
+double scope_get_double(struct scope *sc, char*cmd);
+int update_scope_status(struct scope *sc);
Impressum, Datenschutz