]> rtime.felk.cvut.cz Git - coffee/mt-apps.git/blob - json_helpers.h
mt_server: Use "%s" format string in syslog()
[coffee/mt-apps.git] / json_helpers.h
1 #ifndef JSON_HELPERS_H
2 #define JSON_HELPERS_H
3
4 #include <stdio.h>
5 #include <stdint.h>
6
7 // really simple JSON helpers
8 #define JSON_START()    dprintf(fd,"{")
9 #define JSON_NUM(NAME)  dprintf(fd,"\"" #NAME "\":%d", NAME) //see the int?
10 #define JSON_NEXT()     dprintf(fd,",")
11 #define JSON_STR(NAME)  dprintf(fd,"\"" #NAME "\":\"%s\"", NAME)
12 #define JSON_CHAR(NAME) dprintf(fd,"\"" #NAME "\":\"%c\"", NAME)
13 #define JSON_END()      dprintf(fd,"}\n")
14
15 static inline void
16 keys_json_print(int fd, char key)
17 {
18         static const char *type = "keys";
19
20         JSON_START();
21         JSON_STR(type);
22         JSON_NEXT();
23         JSON_CHAR(key);
24         JSON_END();
25 }
26
27 static inline void
28 rfid_json_print(int fd,
29                 uint8_t card_type,
30                 uint8_t sak,           //select acknowledge
31                 char *uid,
32                 uint8_t size)
33 {
34     static const char *type = "rfid";
35
36     JSON_START();
37     JSON_STR(type);
38     JSON_NEXT();
39     JSON_NUM(card_type);
40     JSON_NEXT();
41     JSON_NUM(sak);
42     JSON_NEXT();
43     JSON_NUM(size);
44     JSON_NEXT();
45     JSON_STR(uid);
46     JSON_END();
47 }
48
49 #endif