tweak voltage divider for my config
[digitaldcpower] / ddcp-script-getval.c
1 /* vim: set sw=8 ts=8 si et: */
2 /* 
3  * Linux software to communicate with the DDCP
4  * Written by Guido Socher 
5  */
6
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <unistd.h>
10 #include <fcntl.h>
11 #include <termios.h>
12
13 int main(int argc, char *argv[])
14 {
15         char *device;
16         char c;
17         int c_cnt,state;
18         int fd;
19
20         if (argc != 2){
21                 printf("USAGE: ddcp-script-getval com-port-device\n");
22                 printf("Example, linux: ddcp-script-getval /dev/ttyUSB0\n");
23                 printf("Example, mac: ddcp-script-getval /dev/tty.usbserial-*\n");
24                 exit(0);
25         }
26         device=argv[1];
27
28         /* Set up io port correctly, and open it... */
29         fd = open(device, O_RDWR );
30         if (fd == -1) {
31                 fprintf(stderr, "ERROR: open for %s failed.\n",device);
32                 exit(1);
33         }
34         write(fd,"\r",1); // send empty line
35         usleep(100000); // commands are polled in the avr and it can take 100ms
36         write(fd,"\r",1); // send empty line
37         usleep(100000); // commands are polled in the avr and it can take 100ms
38         state=0;
39         while ((c_cnt=read(fd,&c,1))){
40                 //printf(":0x%x:\n",c); // debug
41                 if (c=='#') { // find begining of prompt
42                         state=1;
43                 }
44                 if (state<1) continue;
45                 if (c=='>') {
46                         fputc(c,stdout);
47                         state=2;
48                 }
49                 if (state>1) break;
50                 putc(c,stdout);
51         }
52         close(fd);
53         printf("\n");
54         usleep(100000); // commands are polled in the avr and it can take 100ms
55         return(0);
56 }