From e6b3afbab02e07a4f915e7704f52cab598416a92 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Sun, 15 Apr 2012 23:08:01 +0200 Subject: [PATCH] better commandline handling allow reading of uuid with "c id" --- tools/mesh/rf | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/tools/mesh/rf b/tools/mesh/rf index 0411e67..332ada4 100755 --- a/tools/mesh/rf +++ b/tools/mesh/rf @@ -14,22 +14,26 @@ use r0ket; $|=1; -my $ser; -if($ARGV[0] eq "-d"){ - shift; - $ser=shift; -}; -r0ket::r0ket_init($ser); +### Commandline options +use Getopt::Long; +my $ser = undef; +my $help = 0; +my $writend = 0; +GetOptions ( + "dev=s" => \$ser, + "help" => \$help, + "write" => \$writend, + ); -my @fh; -my $read; +$help=1 if($ARGV[0] =~ /^[h?]/); -if ($ARGV[0] =~ /^-?-?h/ || $#ARGV == -1){ +if ($help){ print STDERR "Mini-Help:\n"; print STDERR "-d (or \$R0KETBRIDGE)\n"; print STDERR "-w write beacon2nick file\n"; print STDERR "\n"; print STDERR "recv: receive (number) pakets\n"; + print STDERR " - r : try to autodetect packet format\n"; print STDERR " - r hex : hexdump packets\n"; print STDERR " - r ascii : asciidump packets\n"; print STDERR " - r beacon : parse as openbeacon\n"; @@ -52,22 +56,23 @@ if ($ARGV[0] =~ /^-?-?h/ || $#ARGV == -1){ print STDERR "- c tx - set txmac\n"; print STDERR "- c len - set rxlength\n"; print STDERR "- c ch - set channel\n"; - print STDERR "- c hex - set any option via hex string\n"; + print STDERR "- c hex - set any of the previous option via hex string\n"; + print STDERR "- c id - read beacon id\n"; print STDERR "\n"; print STDERR "etc...\n"; exit(1); }; -my $writend=0; -if ($ARGV[0] eq "-w"){ - shift; - $writend=1; -}; - END{ r0ket::writebeacon if($writend); }; +r0ket::r0ket_init($ser); +$r0ket::verbose=1; + +my @fh; +my $read; + my $cmd=shift; if($cmd =~ /^r/){ @@ -163,6 +168,10 @@ if($cmd =~ /^r/){ r0ket::set_channel(shift); }elsif ($set =~ /^len/){ r0ket::set_rxlen(shift); + }elsif ($set =~ /^id/){ + r0ket::send_pkt_num("",7); + my $id=r0ket::get_data(7); + print "r0ket id: ",r0ket::hprint($id),"\n"; }else{ die "Unknown config argument $set\n"; };