From: Michal Sojka Date: Wed, 8 Aug 2018 13:34:29 +0000 (+0200) Subject: Compile our version of libwebsockets if not found in the system X-Git-Url: https://rtime.felk.cvut.cz/gitweb/coffee/mt-apps.git/commitdiff_plain/0f47abacad5361d1b2f74524d0bad2d18bddae03?hp=c26dd60fbf150e7cf95a4e9cea4b1bc5c7c6cb2c Compile our version of libwebsockets if not found in the system This is mainly for simulator purpuses. --- diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..56c12ef --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libwebsockets"] + path = libwebsockets + url = https://github.com/warmcat/libwebsockets.git diff --git a/Makefile b/Makefile index 3706856..7207748 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,5 @@ OUTPUT_DIR = build -CFLAGS = -Ilibwebsockets/include -Llibwebsockets/lib can_compile = $(shell if echo '$(1)' | $(CC) $(CFLAGS) -c -xc - -o /dev/null >/dev/null 2>&1; then echo yes; fi) HAVE_RFID := $(call can_compile,\#include ) @@ -39,7 +38,23 @@ all: mtserver mtkeys mtaio clean: rm -rf $(OUTPUT_DIR) +# Check LWS version and compile our own if not found +ifeq ($(shell pkg-config libwebsockets = 2.2.1 || echo no),no) +libwebsockets/CMakeLists.txt: + git submodupe update --init libwebsockets + +libwebsockets/CMakeCache.txt: libwebsockets/CMakeLists.txt + cd libwebsockets && cmake -DLWS_WITH_LIBEV=ON -DLWS_WITH_SHARED=OFF . + +libwebsockets/lib/libwebsockets.a: libwebsockets/CMakeCache.txt + cd libwebsockets && cmake --build . + +mt_server.c: libwebsockets/lib/libwebsockets.a + +CFLAGS += -Ilibwebsockets/include -Llibwebsockets/lib -g -lz $(shell pkg-config --libs openssl) +endif + .SECONDEXPANSION: -mt%: $$($$@_SRCS) +mtserver mtkeys mtaio mtrfid: $$($$@_SRCS) mkdir -p $(OUTPUT_DIR) $(CC) $(CFLAGS) $($@_DEFS) -o $(OUTPUT_DIR)/$@ $^ $($@_LIBS) diff --git a/libwebsockets b/libwebsockets new file mode 160000 index 0000000..6f13ccf --- /dev/null +++ b/libwebsockets @@ -0,0 +1 @@ +Subproject commit 6f13ccf7c376b66cd7254aecb51ac162a58e274f diff --git a/mt_sim.c b/mt_sim.c new file mode 100644 index 0000000..081a11e --- /dev/null +++ b/mt_sim.c @@ -0,0 +1,58 @@ +#include +#include + +#include "mt_sim.h" +#include "json_helpers.h" + +static ev_io w; +static int pipefd; +static struct termios saved_term; + +static void stdin_cb(EV_P_ ev_io *w, int revents) +{ + char ch; + + read(w->fd, &ch, sizeof(ch)); + + char uid[15]; + + switch (ch) { + case 'A' ... 'F': + keys_json_print(pipefd, ch); + break; + case 'a' ... 'f': + keys_json_print(pipefd, ch + 'A' - 'a'); + break; + case '0' ... '9': + strcpy(uid, "?ABC0123456789"); + uid[0] = ch; + rfid_json_print(pipefd, 42, 32, uid, (strlen(uid)+1)/2); + break; + } +} + +int mt_sim_init(struct ev_loop *loop, int fd) +{ + pipefd = fd; + + if (!isatty(STDIN_FILENO)) { + fprintf(stderr, "stdin is not a terminal\n"); + return -1; + } + + struct termios term; + tcgetattr(STDIN_FILENO, &term); + saved_term = term; + term.c_lflag &= ~ICANON; + tcsetattr(STDIN_FILENO, TCSADRAIN, &term); + + ev_io_init(&w, stdin_cb, STDIN_FILENO, EV_READ); + ev_io_start(loop, &w); + + return 0; +} + +void mt_sim_deinit(void) +{ + tcsetattr(STDIN_FILENO, TCSADRAIN, &saved_term); +} diff --git a/mt_sim.h b/mt_sim.h new file mode 100644 index 0000000..24df511 --- /dev/null +++ b/mt_sim.h @@ -0,0 +1,9 @@ +#ifndef MT_SIM_H +#define MT_SIM_H + +#include + +int mt_sim_init(struct ev_loop *loop, int fd); +void mt_sim_deinit(void); + +#endif