From ae578a283c005fe519225f8f91226ac2c0964047 Mon Sep 17 00:00:00 2001 From: hadaq Date: Thu, 9 Feb 2012 17:36:08 +0000 Subject: [PATCH] update --- libtrbnet_perl/lib/HADES/TrbNet.pm | 39 ++++++++++---------- libtrbnet_perl/test/test.pl | 59 ++++++++++++------------------ 2 files changed, 43 insertions(+), 55 deletions(-) diff --git a/libtrbnet_perl/lib/HADES/TrbNet.pm b/libtrbnet_perl/lib/HADES/TrbNet.pm index 2284b0d..d402de2 100644 --- a/libtrbnet_perl/lib/HADES/TrbNet.pm +++ b/libtrbnet_perl/lib/HADES/TrbNet.pm @@ -45,10 +45,10 @@ sub trb_register_read { my ($trb_address, $register_address) = @_; my @res = trb_register_read_c($trb_address, $register_address); return if (! defined $res[0]); - - my %rh; - %rh = @res; - return \%rh; + + my %hash; + %hash = @res; + return \%hash; } sub trb_register_read_mem { @@ -56,24 +56,23 @@ sub trb_register_read_mem { my @res = trb_register_read_mem_c($trb_address, $register_address, $option, $size); return if (! defined $res[0]); - - my $rh; + + my %hash; my $k = 0; - while ($k < scalar @res) { + my $len_array = scalar @res; + while ($k < $len_array) { my $len = ($res[$k] >> 16) & 0xffff; - my $trb_address = $res[$k] & 0xffff; - my $array = []; + my $trb_address = $res[$k] & 0xffff; + my @array; $k++; - - printf "Addr: 0x%04x, Len: %d\n", $trb_address, $len; - + for (my $i = 0; $i < $len ; $i++, $k++) { - push (@$array, $res[$k]); + push (@array, $res[$k]); } - $rh->{$trb_address} = $array; + $hash{$trb_address} = \@array; } - - return $rh; + + return \%hash; } sub trb_read_uid { @@ -81,17 +80,17 @@ sub trb_read_uid { my @res = trb_read_uid_c($trb_address); return if (! defined $res[0]); - my $rh; + my %hash; for (my $k = 0; $k < scalar @res; $k += 4) { my $uid = ($res[$k] << 32) | $res[$k + 1]; my $endP = $res[$k + 2]; my $sender = $res[$k + 3]; - $rh->{$uid}->{'trb_address'} = $sender; - $rh->{$uid}->{'trb_endpoint'} = $endP; + $hash{$uid}->{'trb_address'} = $sender; + $hash{$uid}->{'trb_endpoint'} = $endP; } - return $rh; + return \%hash; } 1; diff --git a/libtrbnet_perl/test/test.pl b/libtrbnet_perl/test/test.pl index de06482..2c6df71 100755 --- a/libtrbnet_perl/test/test.pl +++ b/libtrbnet_perl/test/test.pl @@ -1,74 +1,63 @@ #!/usr/bin/perl use warnings; -#use strict; +use strict; use Data::Dumper; use HADES::TrbNet; trb_init_ports() or die "Failed trb_init_ports: ", trb_strerror(); -my $res; - +my $ref; +my @array; # Read all UIDs as hash -$res = trb_read_uid(0xfffb) or die "trb_read_uid: ", trb_strerror(); -foreach my $cur_key (sort {$a <=> $b } keys %$res) { +$ref = trb_read_uid(0xfffb) or die "trb_read_uid: ", trb_strerror(); +foreach my $cur_key (sort {$a <=> $b } keys %$ref) { printf "uid: 0x%016x ==> addr: 0x%04x: endpoint: 0x%02x\n", $cur_key, - $res->{$cur_key}->{'trb_address'}, $res->{$cur_key}->{'trb_endpoint'} ; + $ref->{$cur_key}->{'trb_address'}, $ref->{$cur_key}->{'trb_endpoint'} ; } -#print Dumper $res; +#print Dumper $ref; # Read all UIDs as array -my @res2 = trb_read_uid_c(0xfffb) or die "trb_read_uid: ", trb_strerror(); -#print Dumper @res2; -foreach my $cur_key (@res2) { +@array = trb_read_uid_c(0xfffb) or die "trb_read_uid: ", trb_strerror(); +#print Dumper $ref; +foreach my $cur_key (@array) { printf "0x%08x\n", $cur_key; } # Read ADCM's by mem -$res = trb_register_read(0xfffb, 0xa000) +$ref = trb_register_read(0xfffb, 0xa000) or die "Failed trb_register_read: ", trb_strerror(); -foreach my $cur_key (sort {$a <=> $b } keys %$res) { +foreach my $cur_key (sort {$a <=> $b } keys %$ref) { printf "address: 0x%04x ==> value: 0x%08x\n", $cur_key, - $res->{$cur_key}; + $ref->{$cur_key}; } -#print Dumper $res; +#print Dumper $ref; # Read all UIDs as array -my @res3 = trb_register_read_mem_c(0xfffb, 0xa000, 1, 10) or die "trb_register_read_mem_c: ", trb_strerror(); -print Dumper @res3; -foreach my $cur_key (@res3) { +@array = trb_register_read_mem_c(0xfffb, 0xa000, 1, 10) or die "trb_register_read_mem_c: ", trb_strerror(); + +foreach my $cur_key (@array) { printf "0x%08x\n", $cur_key; } # Read read mem test -$res = trb_register_read_mem(0xfffb, 0xa000, 0, 10) or die "trb_register_read_mem: ", trb_strerror(); -#print Dumper %$res; +$ref = trb_register_read_mem(0xfffb, 0xa000, 0, 10) or die "trb_register_read_mem: ", trb_strerror(); +#print Dumper $ref; printf "\n\n\n"; print "Hash content\n"; -foreach my $k (keys %$res) { - printf "0x%04x\n", $k; - printf "Groesse: ",scalar @$res{$k}, "\n"; - foreach my $val (@{$res{$k}}) { - print " $val"; +foreach my $k (keys %$ref) { + printf "key: 0x%04x\n", $k; + print "Groesse: " . scalar @{$ref->{$k}} . "\n"; + foreach my $val (@{$ref->{$k}}) { + printf " 0x%08x\n", $val; } print "\n"; } -# -#foreach my $cur_key (sort {$a <=> $b } keys %$res) { -# printf "0x%04x\n", $cur_key; -# foreach my $val ($res->{$cur_key}) { -# printf Dumper $res->{$cur_key}; -# printf "0x%08x\n", $val; -# } -#} - - - exit; -- 2.43.0