44 #endif // HAVE_CONFIG_H
47 #if defined(HAVE_READLINE)
48 # include <readline/readline.h>
49 # include <readline/history.h>
50 #endif //HAVE_READLINE
59 # define msleep(x) do { \
60 struct timespec xsleep; \
61 xsleep.tv_sec = x / 1000; \
62 xsleep.tv_nsec = (x - xsleep.tv_sec * 1000) * 1000 * 1000; \
63 nanosleep(&xsleep, NULL); \
74 #include "libnfc/chips/pn53x.h"
76 #define MAX_FRAME_LEN 264
78 int main(
int argc,
const char *argv[])
81 uint8_t abtRx[MAX_FRAME_LEN];
82 uint8_t abtTx[MAX_FRAME_LEN];
83 size_t szRx =
sizeof(abtRx);
88 if ((input = fopen(argv[1],
"r")) == NULL) {
89 ERR(
"%s",
"Cannot open file.");
96 if (context == NULL) {
97 ERR(
"Unable to init libnfc (malloc)");
105 ERR(
"%s",
"Unable to open NFC device.");
124 const char *prompt =
"> ";
128 #if defined(HAVE_READLINE)
130 cmd = readline(prompt);
138 #endif //HAVE_READLINE
142 printf(
"%s", prompt);
145 ret = fgets(cmd, n, input);
147 ret = fgets(cmd, n, stdin);
149 if (ret == NULL || strlen(cmd) <= 0) {
156 #if defined(HAVE_READLINE)
158 #endif //HAVE_READLINE
167 while (isspace(cmd[offset])) {
170 sscanf(cmd + offset,
"%10d", &ms);
171 printf(
"Pause for %i msecs\n", ms);
179 for (
int i = 0; i < MAX_FRAME_LEN; i++) {
182 while (isspace(cmd[offset])) {
185 size = sscanf(cmd + offset,
"%2x", &byte);
191 if (cmd[offset + 1] == 0) {
202 print_hex(abtTx, szTx);
204 szRx =
sizeof(abtRx);
206 if ((res = pn53x_transceive(pnd, abtTx, szTx, abtRx, szRx, 0)) < 0) {
214 print_hex(abtRx, szRx);