From be10004c40a68771431e422a1c2e35f00a1dba82 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Wed, 4 Apr 2012 20:56:52 +0200 Subject: [PATCH] Fix crc and correct default port. it works now[tm] --- tools/mesh/beacon-udp.pl | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tools/mesh/beacon-udp.pl b/tools/mesh/beacon-udp.pl index 4b981ef..52a227c 100755 --- a/tools/mesh/beacon-udp.pl +++ b/tools/mesh/beacon-udp.pl @@ -4,7 +4,8 @@ use strict; use POSIX qw(strftime); -use Time::HiRes qw(time); +#use Time::HiRes qw(time); +use Digest::CRC qw(crcccitt); use lib '.'; use r0ket; @@ -18,10 +19,8 @@ r0ket::set_txmac(pack("H*","0102030201")); r0ket::set_rxmac(pack("H*","0102030201")); r0ket::set_channel(81); r0ket::set_rxlen(16); +$r0ket::quiet=1; # Hackety-hack :) -#r0ket::readbeacon(); - -my $str; my %bdata; use Socket; @@ -30,8 +29,7 @@ use Sys::Hostname; my($iaddr,$proto,$port,$paddr); $iaddr = gethostbyname(hostname()); $proto = getprotobyname('udp'); -#$port = getservbyname('time', 'udp'); -$port = "7777"; +$port = "2342"; $paddr = sockaddr_in(0, $iaddr); # 0 means let kernel pick socket(SOCKET, PF_INET, SOCK_DGRAM, $proto) || die "socket: $!"; @@ -48,29 +46,31 @@ my $beaconctr=0; my $lasttime; my $crcerr=0; my $ctr=0; +my $fast=0; +my $pkt; while(1){ - $str=r0ket::get_packet(); + $pkt=r0ket::get_packet(); + next if($pkt eq "ack"); # in-band signalling. $ctr++; - next if($str eq "ack"); # in-band signalling. - my $hdr= - pack("nCCnnNN", - 0xeeee, # icrc16 - 1, # proto (BEACONLOG_SIGHTING) - 0, # interface (we only have one antenna per "reader") - 1234, # readerid - 32, # size - $ctr, # sequence - time # timestamp + 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 ); - 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"){ $crcerr++; next; }; - }; print "received $ctr pkts, $crcerr crc errors\n"; r0ket::rest();