]> rtime.felk.cvut.cz Git - coffee/mt-apps.git/blobdiff - json_helpers.h
mt_server: Use "%s" format string in syslog()
[coffee/mt-apps.git] / json_helpers.h
index f064f36b7c0bbddbd6f5408557de19253681358f..629d13faad499418395f1c52f027588a6a3b8f26 100644 (file)
@@ -1,6 +1,9 @@
 #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?
@@ -9,4 +12,38 @@
 #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