0.6.3 Changes since last version
[digitaldcpower] / ddcp-script-getval.c
diff --git a/ddcp-script-getval.c b/ddcp-script-getval.c
new file mode 100644 (file)
index 0000000..3484254
--- /dev/null
@@ -0,0 +1,55 @@
+/* vim: set sw=8 ts=8 si et: */
+/* 
+ * Linux software to communicate with the DDCP
+ * Written by Guido Socher 
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <termios.h>
+
+int main(int argc, char *argv[])
+{
+        char *device;
+        char c;
+        int c_cnt,state;
+        int fd;
+
+        if (argc != 2){
+                printf("USAGE: ddcp-script-getval /dev/ttyUSB0\n");
+                printf("or     ddcp-script-getval /dev/ttyUSB1\n");
+                exit(0);
+        }
+        device=argv[1];
+
+        /* Set up io port correctly, and open it... */
+        fd = open(device, O_RDWR );
+        if (fd == -1) {
+                fprintf(stderr, "ERROR: open for %s failed.\n",device);
+                exit(1);
+        }
+        write(fd,"\r",1); // send empty line
+        usleep(100000); // commands are polled in the avr and it can take 100ms
+        write(fd,"\r",1); // send empty line
+        usleep(100000); // commands are polled in the avr and it can take 100ms
+        state=0;
+        while ((c_cnt=read(fd,&c,1))){
+                //printf(":0x%x:\n",c); // debug
+                if (c=='#') { // find begining of prompt
+                        state=1;
+                }
+                if (state<1) continue;
+                if (c=='>') {
+                        putc(c,stdout);
+                        state=2;
+                }
+                if (state>1) break;
+                putc(c,stdout);
+        }
+        printf("\n");
+        close(fd);
+        usleep(100000); // commands are polled in the avr and it can take 100ms
+        return(0);
+}