]>
git.zerfleddert.de Git - rigol/blob - rigold.c
4d4d0b337e3374c1fcfa2450dca46e952d81bc34
2 #include <sys/socket.h>
13 static int send_binary(int s
, char *buf
, int len
)
18 ret
= write(s
, buf
, len
);
30 static int send_text(int s
, char *buf
)
32 return send_binary(s
, buf
, strlen(buf
));
35 static void serve_index(int s
)
37 send_text(s
, "HTTP/1.0 200 OK");
38 send_text(s
, "Content-type: text/html\n\n");
39 send_text(s
, "<html><head><title>Rigol DS1000</title></head><body bgcolor=\"#ffffff\" text=\"#000000\">\n");
40 send_text(s
, "<img src=\"/lcd.png\" height=\"234\" width=\"320\">\n");
41 send_text(s
, "</body></html>\n");
44 static void serve_lcd(int s
, struct usb_dev_handle
*sc
)
51 png
= get_lcd(sc
, &imglen
, 0);
58 send_text(s
, "HTTP/1.0 200 OK");
59 send_text(s
, "Content-type: image/png\n");
60 snprintf(buf
, sizeof(buf
), "Content-length: %u\n\n", imglen
);
62 send_binary(s
, (char*)png
, imglen
);
66 static void parse_request(int s
, struct usb_dev_handle
*sc
)
71 const char delim
[] = " \t\x0d\x0a";
72 const char crlf
[] = "\x0d\x0a";
76 ret
=read(s
, buf
, sizeof(buf
)-1);
83 token
= strtok_r(buf
, delim
, &saveptr
);
84 /* TODO: Only GET... */
85 token
= strtok_r(NULL
, delim
, &saveptr
);
86 bzero(&file
, sizeof(file
));
87 strncpy(file
, token
, sizeof(file
)-1);
90 token
= strtok_r(NULL
, crlf
, &saveptr
);
94 ret
=read(s
, buf
, sizeof(buf
)-1);
100 token
= strtok_r(buf
, crlf
, &saveptr
);
103 } while(token
!= NULL
);
105 if (strcmp("/", file
) == 0) {
107 } else if (strcmp("/lcd.png", file
) == 0) {
112 int main(int argc
, char **argv
)
117 struct usb_dev_handle
*sc
;
118 struct sockaddr_in sin
, clientsin
;
119 unsigned short port
= 8888;
121 sc
= usbtmc_initscope();
123 if ((sock
= socket(AF_INET
, SOCK_STREAM
, 0)) == -1) {
132 bzero(&sin
, sizeof(sin
));
133 sin
.sin_addr
.s_addr
=htonl(INADDR_ANY
);
134 sin
.sin_family
=AF_INET
;
135 sin
.sin_port
=htons(port
);
138 setsockopt(sock
, SOL_SOCKET
, SO_REUSEADDR
, &opt
,sizeof(opt
));
140 if (bind(sock
, (struct sockaddr
*)&sin
, sizeof(sin
)) == -1) {
146 printf("Listening on Port %u\n", port
);
149 bzero(&clientsin
, sizeof(clientsin
));
150 slen
= sizeof(clientsin
);
151 if ((csock
= accept(sock
, (struct sockaddr
*)&clientsin
, &slen
)) == -1) {
155 parse_request(csock
, sc
);