summaryrefslogtreecommitdiff
path: root/client/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'client/main.c')
-rw-r--r--client/main.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/client/main.c b/client/main.c
new file mode 100644
index 0000000..8ea731b
--- /dev/null
+++ b/client/main.c
@@ -0,0 +1,59 @@
+#include <arpa/inet.h>
+#include <fcntl.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+#define PORT 2319
+
+int main(int argc, char **argv) {
+ int ret;
+ char c, last;
+ ssize_t in;
+
+ int fd;
+ int sfd;
+
+ char buf[256];
+
+ struct sockaddr_in addr;
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(PORT);
+ addr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
+
+ sfd = socket(AF_INET, SOCK_DGRAM, 0);
+ if(sfd < 0) {
+ perror("Failed to open socket");
+ exit(EXIT_FAILURE);
+ }
+
+ ret = bind(sfd, (struct sockaddr*) &addr, sizeof(addr));
+ if(ret < 0) {
+ perror("Failed to bind socket");
+ exit(EXIT_FAILURE);
+ }
+
+ for(;;) {
+ in = read(sfd, buf, sizeof(buf) - 1);
+ if(in < 0) {
+ perror("Failed to read from serial port");
+ exit(EXIT_FAILURE);
+ }
+ buf[in] = 0;
+
+ ret = sscanf(buf, "%c->%c\n", &last, &c);
+ if(ret < 2)
+ continue;
+
+ if(last == 'L' && c == 'H')
+ system("/home/jake/.bin/scripts/reed open");
+
+ if(last == 'H' && c == 'L')
+ system("/home/jake/.bin/scripts/reed close");
+ }
+
+ return 0;
+}