]> rtime.felk.cvut.cz Git - coffee/mt-apps.git/blobdiff - mt_rfid.h
mt_server: Use "%s" format string in syslog()
[coffee/mt-apps.git] / mt_rfid.h
index d0a4cc8ed01c249bc91a47c55e57b89f889f464d..01acb9b7bcb2586e917b6a2a22de2b3a9be71fb4 100644 (file)
--- a/mt_rfid.h
+++ b/mt_rfid.h
@@ -1,38 +1,39 @@
-/**
- * mt_rfid.h
- * Start your own mt-rfid pthread.
- */
-
 #ifndef MT_RFID_H
 #define MT_RFID_H
 
-// setup structure
-// it might tempt you to run multiple instances with one reader, don't.
-// running each instance with its own reader (port name) should fine.
-typedef struct {
-    unsigned reader_type;    // 0: auto, 1: 1Mbps, 2,3: slooow
-    char *port_name;         // "COM9", "/dev/ttyUSB0", "" for auto selection
-    unsigned port_interface; // 0: auto, 1: serial, 2: ftdi
-    unsigned beep;           // beep when a card is beeing read
-    unsigned run;            // polling condition
+#include <ev.h>
+#include <stdint.h>
+
+typedef struct ev_io_ufr {
+    ev_io w;           // fd watcher
+    char uid_data[24]; // store uid here (uid is 10 bytes max)
+    char *uid;         // current position in uid_data
+    int fd;            // PORT_NAME file descriptor
+} ev_io_ufr;
+
+typedef struct mt_rfid_t {
+    ev_io_ufr w; // reader watcher
+    int fd;      // print JSON output here
 } mt_rfid_t;
 
-// macros for convenience
-#define READER_TYPE    1 // uFR type (1Mbps)
-#define PORT_INTERFACE 1 // serial
-#define PORT_NAME "/dev/ttyUSB0"
+// reader open parameters, see uFR manual
+#define UFR_READER_TYPE     1       // uFR type (1Mbps)
+#define UFR_PORT_INTERFACE  1       // serial; auto->ftdi->FAIL
+#define UFR_PORT_NAME       "/dev/ttyUSB0" // reader device
+#define UFR_ASYNC_BAUD_RATE 1000000 // 1Mbps, otherwise UFR_COMMUNICATION_BREAK
+
+#define UFR_BEEP // define this to annoy people
+
+// connect to the reader, add self to loop and make it write to fd
+// return 0 on success, negative number otherwise
+int mt_rfid_init(mt_rfid_t *self, struct ev_loop *loop, int fd);
 
-#define ASYNC_SUFFIX 0
-#define ASYNC_BAUD_RATE 1000000
-#define BASYNC_BAUD_RATE B1000000
+// disconnect from reader
+void mt_rfid_deinit(mt_rfid_t *self);
 
-#define UFR_BEEP
+#else
 
-// really simple JSON helpers
-#define JSON_NUM(NAME) printf("\"" #NAME "\": %d", NAME)
-#define JSON_STR(NAME) printf("\"" #NAME "\": \"%s\"", NAME)
-#define JSON_START() printf("{\n")
-#define JSON_NEXT() printf(",\n")
-#define JSON_END() printf("\n}\n")
+#define mt_rfid_init(self, loop, fd) 0
+#define mt_rfid_deinit(self) 0
 
 #endif