ifeq ($(HAVE_RFID),yes)
mtaio_SRCS += mt_rfid.c
mtaio_LIBS += -luFCoder-armhf
+else
+mtaio_SRCS += mt_sim.c
+mtaio_DEFS += -DSIM=1
endif
all: mtserver mtkeys mtaio
#ifndef JSON_HELPERS_H
#define JSON_HELPERS_H
+#include <stdio.h>
+#include <stdint.h>
+
// really simple JSON helpers
#define JSON_START() dprintf(fd,"{")
#define JSON_NUM(NAME) dprintf(fd,"\"" #NAME "\":%d", NAME) //see the int?
#define JSON_CHAR(NAME) dprintf(fd,"\"" #NAME "\":\"%c\"", NAME)
#define JSON_END() dprintf(fd,"}\n")
+static inline void
+keys_json_print(int fd, char key)
+{
+ static const char *type = "keys";
+
+ JSON_START();
+ JSON_STR(type);
+ JSON_NEXT();
+ JSON_CHAR(key);
+ JSON_END();
+}
+
+static inline void
+rfid_json_print(int fd,
+ uint8_t card_type,
+ uint8_t sak, //select acknowledge
+ char *uid,
+ uint8_t size)
+{
+ static const char *type = "rfid";
+
+ JSON_START();
+ JSON_STR(type);
+ JSON_NEXT();
+ JSON_NUM(card_type);
+ JSON_NEXT();
+ JSON_NUM(sak);
+ JSON_NEXT();
+ JSON_NUM(size);
+ JSON_NEXT();
+ JSON_STR(uid);
+ JSON_END();
+}
+
#endif
#include "mt_server.h"
#include "signal_exit.h"
#include "mt_blank.h"
+#include "mt_sim.h"
int main(int argc, char **argv)
{
set_signal_exit(loop);
+#if !defined(SIM)
if (mt_rfid_init(&rfid, loop, pipefd[1]) != 0) {
return -1;
}
return -1;
}
- if (mt_server_init(&server, loop, pipefd[0]) != 0) {
- return -2;
- }
-
if (mt_blank_init(loop) != 0) {
return -3;
}
+#else
+ if (mt_sim_init(loop, pipefd[1]) != 0) {
+ return -1;
+ }
+#endif
+
+ if (mt_server_init(&server, loop, pipefd[0]) != 0) {
+ return -2;
+ }
ev_run(loop, 0);
mt_server_deinit(&server);
+#if !defined(SIM)
mt_keys_deinit(&keys);
mt_rfid_deinit(&rfid);
+#else
+ mt_sim_deinit();
+#endif
ev_loop_destroy(loop);
return 0;
#include "signal_exit.h"
#include "json_helpers.h"
-void keys_json_print(int fd, char key)
-{
- static const char *type = "keys";
-
- JSON_START();
- JSON_STR(type);
- JSON_NEXT();
- JSON_CHAR(key);
- JSON_END();
-}
-
static void keys_cb(EV_P_ ev_io *w_, int revents)
{
ev_io_keys *w = (ev_io_keys *)w_;
void mt_keys_deinit(mt_keys_t *self);
-void keys_json_print(int fd, char key);
-
#endif
return fd;
}
-// print complete json
-void rfid_json_print(int fd,
- uint8_t card_type,
- uint8_t sak, //select acknowledge
- char *uid,
- uint8_t size)
-{
- static const char *type = "rfid";
-
- JSON_START();
- JSON_STR(type);
- JSON_NEXT();
- JSON_NUM(card_type);
- JSON_NEXT();
- JSON_NUM(sak);
- JSON_NEXT();
- JSON_NUM(size);
- JSON_NEXT();
- JSON_STR(uid);
- JSON_END();
-}
-
static void ufr_read(char *uid, int fd)
{
UFR_STATUS status;
#define MT_PROTOCOL_RX_BUFFER_SIZE 128
#define INPUT_LINE_LENGTH MT_PROTOCOL_RX_BUFFER_SIZE
+#if defined(SIM)
+#define HTTP_PORT 8080 // listen here
+#define HTTP_ORIGIN "html" // where the html files are
+#else
#define HTTP_PORT 80 // listen here
-#define HTTP_MOUNTPOINT "/" // mountpoint URL
#define HTTP_ORIGIN "/usr/share/mtserver" // where the html files are
+#endif
+#define HTTP_MOUNTPOINT "/" // mountpoint URL
#define HTTP_DEFAULT "index.html" // default filename
#define JSON_EMPTY "{\"type\":\"empty\"}" // default message