Fix crc and correct default port. it works now[tm]

This commit is contained in:
Stefan `Sec` Zehl 2012-04-04 20:56:52 +02:00
parent 2c03614af8
commit be10004c40
1 changed files with 20 additions and 20 deletions

View File

@ -4,7 +4,8 @@
use strict; use strict;
use POSIX qw(strftime); use POSIX qw(strftime);
use Time::HiRes qw(time); #use Time::HiRes qw(time);
use Digest::CRC qw(crcccitt);
use lib '.'; use lib '.';
use r0ket; use r0ket;
@ -18,10 +19,8 @@ r0ket::set_txmac(pack("H*","0102030201"));
r0ket::set_rxmac(pack("H*","0102030201")); r0ket::set_rxmac(pack("H*","0102030201"));
r0ket::set_channel(81); r0ket::set_channel(81);
r0ket::set_rxlen(16); r0ket::set_rxlen(16);
$r0ket::quiet=1; # Hackety-hack :)
#r0ket::readbeacon();
my $str;
my %bdata; my %bdata;
use Socket; use Socket;
@ -30,8 +29,7 @@ use Sys::Hostname;
my($iaddr,$proto,$port,$paddr); my($iaddr,$proto,$port,$paddr);
$iaddr = gethostbyname(hostname()); $iaddr = gethostbyname(hostname());
$proto = getprotobyname('udp'); $proto = getprotobyname('udp');
#$port = getservbyname('time', 'udp'); $port = "2342";
$port = "7777";
$paddr = sockaddr_in(0, $iaddr); # 0 means let kernel pick $paddr = sockaddr_in(0, $iaddr); # 0 means let kernel pick
socket(SOCKET, PF_INET, SOCK_DGRAM, $proto) || die "socket: $!"; socket(SOCKET, PF_INET, SOCK_DGRAM, $proto) || die "socket: $!";
@ -48,14 +46,14 @@ my $beaconctr=0;
my $lasttime; my $lasttime;
my $crcerr=0; my $crcerr=0;
my $ctr=0; my $ctr=0;
my $fast=0;
my $pkt;
while(1){ while(1){
$str=r0ket::get_packet(); $pkt=r0ket::get_packet();
next if($pkt eq "ack"); # in-band signalling.
$ctr++; $ctr++;
next if($str eq "ack"); # in-band signalling.
my $hdr= my $hdr= pack("CCnnNN",
pack("nCCnnNN",
0xeeee, # icrc16
1, # proto (BEACONLOG_SIGHTING) 1, # proto (BEACONLOG_SIGHTING)
0, # interface (we only have one antenna per "reader") 0, # interface (we only have one antenna per "reader")
1234, # readerid 1234, # readerid
@ -63,14 +61,16 @@ while(1){
$ctr, # sequence $ctr, # sequence
time # timestamp time # timestamp
); );
send (SOCKET, $hdr.$str,0,$hispaddr); my $crc=pack("n",0xffff ^ crcccitt($hdr.$pkt));
my $p=r0ket::nice_beacon($str); send(SOCKET, $crc.$hdr.$pkt,0,$hispaddr);
next if($fast);
my $p=r0ket::nice_beacon($pkt);
if($p->{crc} ne "ok"){ if($p->{crc} ne "ok"){
$crcerr++; $crcerr++;
next; next;
}; };
}; };
print "received $ctr pkts, $crcerr crc errors\n"; print "received $ctr pkts, $crcerr crc errors\n";
r0ket::rest(); r0ket::rest();