better commandline handling

allow reading of uuid with "c id"
This commit is contained in:
Stefan `Sec` Zehl 2012-04-15 23:08:01 +02:00
parent 4f859c82a0
commit e6b3afbab0
1 changed files with 25 additions and 16 deletions

View File

@ -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 <devicename> (or \$R0KETBRIDGE)\n";
print STDERR "-w write beacon2nick file\n";
print STDERR "\n";
print STDERR "recv<num>: 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 <opt>hex - set any option via hex string\n";
print STDERR "- c <opt>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";
};