X-Git-Url: http://git.rot13.org/?p=digitaldcpower;a=blobdiff_plain;f=ddcp-script-getval.c;fp=ddcp-script-getval.c;h=3484254f011e0f2b0b146d24bbddabfb6dfa61fc;hp=0000000000000000000000000000000000000000;hb=93791a25a42c0d48fa5a62c41d5907fae5829fee;hpb=1d6d9149f9b438f797a7af85c0454e38a2767a95 diff --git a/ddcp-script-getval.c b/ddcp-script-getval.c new file mode 100644 index 0000000..3484254 --- /dev/null +++ b/ddcp-script-getval.c @@ -0,0 +1,55 @@ +/* vim: set sw=8 ts=8 si et: */ +/* + * Linux software to communicate with the DDCP + * Written by Guido Socher + */ + +#include +#include +#include +#include +#include + +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); +}