2012-04-04 17:22:00 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
# vim:set ts=4 sw=4:
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use POSIX qw(strftime);
|
2012-04-04 18:56:52 +00:00
|
|
|
#use Time::HiRes qw(time);
|
|
|
|
use Digest::CRC qw(crcccitt);
|
2012-04-04 17:22:00 +00:00
|
|
|
|
2012-04-05 12:08:54 +00:00
|
|
|
use FindBin;
|
|
|
|
use lib "$FindBin::Bin/lib";
|
|
|
|
|
2012-04-04 17:22:00 +00:00
|
|
|
use r0ket;
|
|
|
|
|
|
|
|
$|=1;
|
|
|
|
|
|
|
|
r0ket::r0ket_init();
|
|
|
|
|
|
|
|
# Default openbeacon settings.
|
|
|
|
r0ket::set_txmac(pack("H*","0102030201"));
|
|
|
|
r0ket::set_rxmac(pack("H*","0102030201"));
|
|
|
|
r0ket::set_channel(81);
|
|
|
|
r0ket::set_rxlen(16);
|
2012-04-04 18:56:52 +00:00
|
|
|
$r0ket::quiet=1; # Hackety-hack :)
|
2012-04-04 17:22:00 +00:00
|
|
|
|
|
|
|
my %bdata;
|
|
|
|
|
|
|
|
use Socket;
|
|
|
|
use Sys::Hostname;
|
|
|
|
|
|
|
|
my($iaddr,$proto,$port,$paddr);
|
|
|
|
$iaddr = gethostbyname(hostname());
|
|
|
|
$proto = getprotobyname('udp');
|
2012-04-04 18:56:52 +00:00
|
|
|
$port = "2342";
|
2012-04-04 17:22:00 +00:00
|
|
|
$paddr = sockaddr_in(0, $iaddr); # 0 means let kernel pick
|
|
|
|
|
|
|
|
socket(SOCKET, PF_INET, SOCK_DGRAM, $proto) || die "socket: $!";
|
|
|
|
bind(SOCKET, $paddr) || die "bind: $!";
|
|
|
|
|
|
|
|
my $host="127.0.0.1";
|
|
|
|
my $hisiaddr = inet_aton($host) || die "unknown host";
|
|
|
|
my $hispaddr = sockaddr_in($port, $hisiaddr);
|
|
|
|
|
|
|
|
###send(SOCKET, 0, 0, $hispaddr);
|
|
|
|
|
|
|
|
|
|
|
|
my $beaconctr=0;
|
|
|
|
my $lasttime;
|
|
|
|
my $crcerr=0;
|
|
|
|
my $ctr=0;
|
2012-04-04 18:56:52 +00:00
|
|
|
my $fast=0;
|
|
|
|
my $pkt;
|
2012-04-04 17:22:00 +00:00
|
|
|
while(1){
|
2012-04-04 18:56:52 +00:00
|
|
|
$pkt=r0ket::get_packet();
|
|
|
|
next if($pkt eq "ack"); # in-band signalling.
|
2012-04-04 17:22:00 +00:00
|
|
|
$ctr++;
|
2012-04-04 18:56:52 +00:00
|
|
|
|
|
|
|
my $hdr= pack("CCnnNN",
|
|
|
|
1, # proto (BEACONLOG_SIGHTING)
|
|
|
|
0, # interface (we only have one antenna per "reader")
|
|
|
|
1234, # readerid
|
|
|
|
32, # size
|
|
|
|
$ctr, # sequence
|
|
|
|
time # timestamp
|
2012-04-04 17:22:00 +00:00
|
|
|
);
|
2012-04-04 18:56:52 +00:00
|
|
|
my $crc=pack("n",0xffff ^ crcccitt($hdr.$pkt));
|
2012-04-04 17:22:00 +00:00
|
|
|
|
2012-04-04 18:56:52 +00:00
|
|
|
send(SOCKET, $crc.$hdr.$pkt,0,$hispaddr);
|
|
|
|
|
|
|
|
next if($fast);
|
|
|
|
my $p=r0ket::nice_beacon($pkt);
|
2012-04-04 17:22:00 +00:00
|
|
|
if($p->{crc} ne "ok"){
|
|
|
|
$crcerr++;
|
|
|
|
next;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
print "received $ctr pkts, $crcerr crc errors\n";
|
|
|
|
r0ket::rest();
|