* poll the uFR reader and print JSON formatted card info to stdout.
*/
+// shit to avoid constant repetition
+#define CONCAT_AGAIN(A,B) A ## B
+#define CONCAT(A,B) CONCAT_AGAIN(A,B)
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
return -1;
}
- int fd = tty_open(PORT_NAME, BASYNC_BAUD_RATE);
+ int fd = tty_open(PORT_NAME, CONCAT(B,ASYNC_BAUD_RATE));
if (fd < 0) {
return -2;
}
libev_run(fd);
- close(fd);
- fprintf(stderr, "closed %d\n", fd);
+ if (close(fd) == 0) {
+ fprintf(stderr, "closed %d\n", fd);
+ } else {
+ perror("close");
+ }
UFR_STATUS status;
status = ReaderClose();
/**
* 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
-} mt_rfid_t;
-
-// macros for convenience
+// reader open parameters, see uFR manual
#define READER_TYPE 1 // uFR type (1Mbps)
-#define PORT_INTERFACE 1 // serial
+#define PORT_INTERFACE 1 // serial, auto -> ftdi -> FAIL (some shity drivers missing)
#define PORT_NAME "/dev/ttyUSB0"
-#define ASYNC_SUFFIX 0
-#define ASYNC_BAUD_RATE 1000000
-#define BASYNC_BAUD_RATE B1000000
+// async uid sending parameters
+#define ASYNC_SUFFIX 0 // keep it zero: + separates uids, + terminates strings
+#define ASYNC_BAUD_RATE 1000000 // 1Mbps, otherwise UFR_COMMUNICATION_BREAK
-#define UFR_BEEP
+#define UFR_BEEP // define this to annoy people
// 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_NUM(NAME) printf("\"" #NAME "\": %d", NAME)
#define JSON_NEXT() printf(",\n")
+#define JSON_STR(NAME) printf("\"" #NAME "\": \"%s\"", NAME)
#define JSON_END() printf("\n}\n")
#endif