From ec2cf3b617a462bda42405acd5c92dff408911b7 Mon Sep 17 00:00:00 2001 From: laforge Date: Sun, 24 Feb 2008 12:42:53 +0000 Subject: add -E parameter to do an endless loop of enumeratiosn. The option has one argument which specifies the delay in milliseconds between the enumeration rounds git-svn-id: https://svn.gnumonks.org/trunk/librfid@2089 e0336214-984f-0b4b-a45f-81c69e1f0ede --- utils/librfid-tool.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) (limited to 'utils') diff --git a/utils/librfid-tool.c b/utils/librfid-tool.c index a336ded..5f8698c 100644 --- a/utils/librfid-tool.c +++ b/utils/librfid-tool.c @@ -456,6 +456,7 @@ static void do_enum(int layer2) if (rh->reader->l2_supported & (1 << layer2)) { l2h = rfid_layer2_init(rh, layer2); + printf("Layer2 init ok\n"); rc = rfid_layer2_open(l2h); } else { printf("error during layer2_open\n"); @@ -488,6 +489,29 @@ static void do_enum(int layer2) } } +static void do_enum_loop(int layer2, unsigned int delay) +{ + while (1) { + do_enum(layer2); + { + unsigned int opt; + unsigned int optlen = sizeof(opt); + + /* turn off RF */ + opt = 1; + rfid_reader_setopt(rh, RFID_OPT_RDR_RF_KILL, &opt, optlen); + + usleep(10 * 1000); + + /* turn on RF */ + opt = 0; + rfid_reader_setopt(rh, RFID_OPT_RDR_RF_KILL, &opt, optlen); + } + usleep(delay * 1000); + printf("--- next run ---\n"); + } +} + #define OPTION_OFFSET 256 static struct option original_opts[] = { @@ -498,6 +522,7 @@ static struct option original_opts[] = { { "scan-loop", 0, 0, 'S' }, { "dump", 0, 0, 'd' }, { "enum", 0, 0, 'e' }, + { "enum-loop", 1, 0, 'E' }, {0, 0, 0, 0} }; @@ -574,6 +599,7 @@ static void help(void) " -l --layer2 {iso14443a,iso14443b,iso15693,icode1}\n" " -d --dump dump rc632 registers\n" " -e --enum enumerate all tag's in field \n" + " -E --enum-loop (ms) enumerate endless\n" " -h --help\n"); } @@ -598,15 +624,27 @@ int main(int argc, char **argv) while (1) { int c, option_index = 0; - c = getopt_long(argc, argv, "hp:l:sSde", opts, &option_index); + c = getopt_long(argc, argv, "hp:l:sSdeE:", opts, &option_index); if (c == -1) break; switch (c) { + case 'E': + i = strtol(optarg, NULL, 10); + + if (reader_init() < 0) + exit(1); + if (layer2<0) + layer2 = RFID_LAYER2_ISO14443A; + + do_enum_loop(layer2, i>1? i : 500); + rfid_reader_close(rh); + exit(0); + break; case 'e': if (reader_init() < 0) exit(1); - if (layer2==0) + if (layer2 < 0) layer2 = RFID_LAYER2_ISO14443A; do_enum(layer2); rfid_reader_close(rh); @@ -647,10 +685,14 @@ int main(int argc, char **argv) exit(2); } break; + default: + printf("unknown cmd: %c\n",c); case 'h': help(); exit(0); break; + case '?': + exit(0); } } -- cgit v1.2.3