]> rtime.felk.cvut.cz Git - coffee/mt-apps.git/commitdiff
Convert RFID printing to a function
authorMichal Sojka <michal.sojka@cvut.cz>
Wed, 8 Aug 2018 09:31:52 +0000 (11:31 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Wed, 8 Aug 2018 10:08:01 +0000 (12:08 +0200)
... so that we can use it in a simulator.

mt_rfid.c
mt_rfid.h

index 542c60b9672c70260ac6e5636543b513c80fce9d..e987f827c79be7f2d17acf0934550ca70be96c0c 100644 (file)
--- a/mt_rfid.c
+++ b/mt_rfid.c
@@ -86,24 +86,29 @@ static int tty_open(const char *port, int br)
 }
 
 // print complete json
-#define RFID_JSON_PRINT() do { \
-    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();           \
-} while (0)
+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)
 {
-    static char *type = "rfid";
-
     UFR_STATUS status;
     uint8_t card_type;
     uint8_t sak;           //select acknowledge
@@ -122,7 +127,7 @@ static void ufr_read(char *uid, int fd)
         return;
     }
 
-    RFID_JSON_PRINT();
+    rfid_json_print(fd, card_type, sak, uid, size);
 
 #ifdef UFR_BEEP
     ReaderUISignal(0, 1); // no light, one beep
index 10ea402276230e12c43869356c8f3ffc7ee0a3a0..53fa84b7a725bc2fdf6366f46e2ec2e70d91f958 100644 (file)
--- a/mt_rfid.h
+++ b/mt_rfid.h
@@ -2,6 +2,7 @@
 #define MT_RFID_H
 
 #include <ev.h>
+#include <stdint.h>
 
 typedef struct ev_io_ufr {
     ev_io w;           // fd watcher
@@ -39,4 +40,11 @@ void mt_rfid_deinit(mt_rfid_t *self);
 
 #endif /* HAVE_RFID */
 
+void rfid_json_print(int fd,
+                    uint8_t card_type,
+                    uint8_t sak,           //select acknowledge
+                    char *uid,
+                    uint8_t size);
+
+
 #endif