summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/Makefile23
-rw-r--r--client/main.c59
2 files changed, 82 insertions, 0 deletions
diff --git a/client/Makefile b/client/Makefile
new file mode 100644
index 0000000..f2b6ca3
--- /dev/null
+++ b/client/Makefile
@@ -0,0 +1,23 @@
+TARGET = $(shell basename $(CURDIR))
+
+SRCS = $(wildcard *.c)
+OBJS = $(SRCS:.c=.o)
+
+CC = gcc
+
+all: build
+
+build: $(TARGET)
+
+clean:
+ rm -f $(OBJS)
+ rm -f $(TARGET)
+
+run: $(TARGET)
+ $(realpath $(TARGET))
+
+$(TARGET): $(OBJS)
+ $(CC) -o $(TARGET) $(OBJS)
+
+.c.o:
+ $(CC) -c -o $*.o $^
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;
+}