]> rtime.felk.cvut.cz Git - coffee/mt-apps.git/commitdiff
tiny doc and macros
authorJiří Matěják <jiri.matejak@fel.cvut.cz>
Tue, 24 Apr 2018 16:47:41 +0000 (18:47 +0200)
committerJiří Matěják <jiri.matejak@fel.cvut.cz>
Tue, 24 Apr 2018 16:47:41 +0000 (18:47 +0200)
mt_rfid.c
mt_rfid.h

index 75f698f1556ae9457e69c0c7064b6397856c3fdd..d281371918f1d1238ff89eeadbe578fad8894cec 100644 (file)
--- a/mt_rfid.c
+++ b/mt_rfid.c
@@ -3,6 +3,10 @@
  * 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>
@@ -201,15 +205,18 @@ int main(int argc, char **argv)
         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();
index d0a4cc8ed01c249bc91a47c55e57b89f889f464d..5dfe76ef210ac560a8d34984876371ce960c39d2 100644 (file)
--- a/mt_rfid.h
+++ b/mt_rfid.h
@@ -1,38 +1,26 @@
 /**
  * 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