43 #endif // HAVE_CONFIG_H
46 #if defined(HAVE_READLINE)
47 # include <readline/readline.h>
48 # include <readline/history.h>
49 #endif //HAVE_READLINE
58 # define msleep(x) do { \
59 struct timespec xsleep; \
60 xsleep.tv_sec = x / 1000; \
61 xsleep.tv_nsec = (x - xsleep.tv_sec * 1000) * 1000 * 1000; \
62 nanosleep(&xsleep, NULL); \
73 #include "libnfc/chips/pn53x.h"
75 #define MAX_FRAME_LEN 264
77 int main(
int argc,
const char *argv[])
80 uint8_t abtRx[MAX_FRAME_LEN];
81 uint8_t abtTx[MAX_FRAME_LEN];
82 size_t szRx =
sizeof(abtRx);
87 if ((input = fopen(argv[1],
"r")) == NULL) {
88 ERR(
"%s",
"Cannot open file.");
95 if (context == NULL) {
96 ERR(
"Unable to init libnfc (malloc)");
104 ERR(
"%s",
"Unable to open NFC device.");
123 const char *prompt =
"> ";
127 #if defined(HAVE_READLINE)
129 cmd = readline(prompt);
137 #endif //HAVE_READLINE
141 printf(
"%s", prompt);
144 ret = fgets(cmd, n, input);
146 ret = fgets(cmd, n, stdin);
148 if (ret == NULL || strlen(cmd) <= 0) {
155 #if defined(HAVE_READLINE)
157 #endif //HAVE_READLINE
166 while (isspace(cmd[offset])) {
169 sscanf(cmd + offset,
"%10d", &ms);
170 printf(
"Pause for %i msecs\n", ms);
178 for (
int i = 0; i < MAX_FRAME_LEN; i++) {
181 while (isspace(cmd[offset])) {
184 size = sscanf(cmd + offset,
"%2x", &byte);
190 if (cmd[offset + 1] == 0) {
201 print_hex(abtTx, szTx);
203 szRx =
sizeof(abtRx);
205 if ((res = pn53x_transceive(pnd, abtTx, szTx, abtRx, szRx, 0)) < 0) {
213 print_hex(abtRx, szRx);