#include "mt_rfid.h"
#include "signal_exit.h"
+#include "json_helpers.h"
// shit to avoid constant repetition
#define CONCAT_AGAIN(A,B) A ## B
perror("fcntl (set)");
return -1;
}
- fprintf(stderr, "set non-blocking\n");
+ fprintf(stderr, "set %d non-blocking\n", fd);
return 0;
}
return -1;
}
- fprintf(stderr, "set rts %d\n", level);
+ fprintf(stderr, "set %d rts %d\n", fd, level);
return 0;
}
return fd;
}
-// really simple JSON helpers
-#define JSON_START() dprintf(fd,"{")
-#define JSON_NUM(NAME) dprintf(fd,"\"" #NAME "\":%d", NAME) //see the int?
-#define JSON_NEXT() dprintf(fd,",")
-#define JSON_STR(NAME) dprintf(fd,"\"" #NAME "\":\"%s\"", NAME)
-#define JSON_END() dprintf(fd,"}\n")
-
// print complete json
-#define 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
return;
}
- JSON_PRINT();
+ rfid_json_print(fd, card_type, sak, uid, size);
#ifdef UFR_BEEP
ReaderUISignal(0, 1); // no light, one beep
fprintf(stderr, "ReaderClose: %s\n", UFR_Status2String(status));
}
-#ifdef IS_MAIN
+#ifndef NO_MAIN
int main(int argc, char **argv)
{
struct ev_loop *loop = EV_DEFAULT;
ev_run(loop, 0);
mt_rfid_deinit(&rfid);
+ ev_loop_destroy(loop);
return 0;
}