use strict;
use Parallel::ForkManager;
use Net::Ping;
+use Getopt::Long;
use Data::Dumper;
-my @trbs = (78, 84, 101, 102);
+my $power;
+my $reboot;
+my $help;
-my $map = {
- 1 => { trb => 84, sys => "TDC 00"},
- 2 => { trb => 101, sys => "TDC 01"},
- 3 => { trb => 78, sys => "TDC 02"},
- 4 => { trb => 102, sys => "TDC 03"},
- 0 => { trb => 61, sys => "CTS"},
-};
+my $result = GetOptions (
+ "h|help" => \$help,
+ "p|powercycle" => \$power,
+ "r|reboot" => \$reboot
+ );
+my @trbs = (142,134,"009",130,128,131,129,158,144,139,138,164,166,137,163,153,136,162);
+
+my $map = { };
+
+my $i = 0;
+foreach my $cur_trb (@trbs) {
+ $map->{$i} = { trb => $cur_trb, addr => "0xdead", sys => "no assigned system" };
+ $i++;
+}
+#print Dumper $map;
+
+#my $map = {
+# 0 => { trb => 84, addr => "0xc001", sys => "CTS"},
+# 1 => { trb => 61, addr => "0x8610", sys => "TOF"},
+# 2 => { trb => 113, addr => "0x8113", sys => "TOF"},
+# 3 => { trb => 158, addr => "0x8158", sys => "TOF"},
+#};
+
my $MAX_PROCESSES=50;
my $pm = Parallel::ForkManager->new($MAX_PROCESSES);
+my $maximal_reboot_counter = 4;
+my $number_of_reboots_done = 0;
+
+my $rh_unsuccessful = {};
+
+$pm->run_on_finish(
+ sub { my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $data_structure_reference) = @_;
+ #print "** $ident just got out of the pool ".
+ # "with PID $pid and exit code: $exit_code\n";
+ #print Dumper ($pid, $exit_code, $ident, $exit_signal, $core_dump, $data_structure_reference);
+ if ($exit_code == 0 && defined $data_structure_reference) {
+ $rh_unsuccessful->{$ident} = $$data_structure_reference;
+ }
+ }
+ );
#my $p = Net::Ping->new();
-#print Dumper keys %$map;
-#exit;
-foreach my $ct (keys %$map) {
+my $first_iteration = 1;
+
+#print Dumper keys %$rh_unsuccessful;
+
+while ( (($first_iteration == 1) || keys %$rh_unsuccessful) &&
+ ($number_of_reboots_done < $maximal_reboot_counter) ) {
+ #print Dumper $rh_unsuccessful;
+ #print Dumper keys %$rh_unsuccessful;
+
+ $rh_unsuccessful = {};
+ $first_iteration = 0;
+ foreach my $ct (keys %$map) {
+ my $success = 0;
#my $num = sprintf "%3.3d", $ct;
my $trbnum= $map->{$ct}->{trb};
my $num = sprintf "%3.3d", $trbnum;
- my $host= "trb" . $num;
+ my $host= "trb3sc" . $num;
+ #my $host= "trb" . $num ."b";
my $system = $map->{$ct}->{sys};
#print "192.168.0.$ct $host.gsi.de $host\n";
#my $r = $p->ping($host,1);
- my $c= "ping -W1 -c1 $host";
+ my $c= "ping -W1 -i0.2 -c4 $host";
- my $pid = $pm->start and next;
+ # my $sysnum = sprintf "0x80%.2x", $ct;
+ my $sysnum = $map->{$ct}->{addr};
+ #$sysnum = "0x7999" if $ct == -1;
+ my $pid = $pm->start("$sysnum") and next;
#my $p = Net::Ping->new("udp", 1);
#my $r = $p->ping("192.168.0.56");
#print "result: $r\n";
my $r = qx($c);
- my $sysnum = sprintf "0x80%.2x", $ct;
- $sysnum = "0x7999" if $ct == -1;
#printf "$sysnum, system: %-8s, trb: $host ", $system;
printf "$sysnum $host %-8s ", $system;
if (grep /64 bytes/, $r) {
- print "is alive.\n";
+ print "is alive.\n";
+ $success = $trbnum;
+ } else {
+ print "is not alive.\n";
+ }
+
+ my $str = "jhhj";
+ $pm->finish($success, \$host); # Terminates the child process
+ }
+
+ $pm->wait_all_children;
+
+ #$rh_unsuccessful = { "0x8007"=>"hh", "0x8001"=>"jjhj"} ;
+
+ if ($reboot && ($number_of_reboots_done < $maximal_reboot_counter) && keys %$rh_unsuccessful) {
+ #print Dumper $rh_unsuccessful;
+ print "have to reboot FPGAs, first make a reset and reassign the addresses.\n";
+ my $cmd = 'trbcmd reset; sleep 2; ~/trbsoft/daqtools/merge_serial_address.pl $DAQ_TOOLS_PATH/base/serials_trb3.db $USER_DIR/db/addresses_trb3.db';
+ qx($cmd);
+ sleep 3;
+ # test trbnet:
+ my $error_str = "ERROR: read_uid failed: Termination Status Error";
+ $cmd = "trbcmd i 0xffff 2>&1";
+ my $r = qx($cmd);
+ if ($r=~/$error_str/) {
+ print "could not access trbnet, so have to reboot all FPGAs.\n";
+ $rh_unsuccessful = { "0xffff"=>"all"} ;
+ }
+
+ my $ctsnum = $map->{0}->{addr};
+ if ($rh_unsuccessful->{ $ctsnum } || (scalar keys %$rh_unsuccessful) > 5) {
+ print "many TRBs (or CTS: ". $ctsnum . ") are not alive, so let us make a reload of all FPGAs.\n";
+ $rh_unsuccessful = { "0xffff"=>"all"} ;
}
- else {
- print "is not alive.\n";
- }
- $pm->finish; # Terminates the child process
+ foreach my $cur (keys %$rh_unsuccessful) {
+ my $host = $rh_unsuccessful->{$cur};
+ #my $cmd = "trbcmd reload " . $cur;
+ $cmd = "trbcmd reload $cur";
+ print "rebooting: $cur\n";
+ #print "$cmd\n";
+ qx($cmd);
+ #print "number of reboots done: $number_of_reboots_done\n";
+ }
+ print "wait 9 seconds\n";
+ sleep 9;
+ $number_of_reboots_done++;
+ }
+
+
+
}
-$pm->wait_all_children;
+exit 1 if(scalar keys %$rh_unsuccessful > 0);
+
#$p->close();
+
+
+
+
+
+
+
+
+
+
+
my $writecfgflash;
my $verifycfgflash;
my $verify;
+my $fastcheck = 0;
my $dumpuserflash;
my $writeuserflash;
my $rr;
"writecfgflash" => \$writecfgflash,
"verifycfgflash" => \$verifycfgflash,
"verifypage" => \$verify,
+ "fastcheck=i" => \$fastcheck,
"dumpuserflash:s" => \$dumpuserflash,
"writeuserflash:s" => \$writeuserflash,
"eraseuserflash" => \$eraseuserflash,
if ($execute eq "verifycfgflash" | defined $verifycfgflash) {
checkcfgflash();
- printf("Verify with file: %s \n", $filename);
+ printf("Verify %x with file: %s \n", $endpoint, $filename);
if (!defined($filename)) {$filename=$verifycfgflash;}
if (!defined $filename) {
die "for the command verifycfgflash an option or --filename is missing.\n";
my $p = 0;
my $ok = 1;
+ # while (my $s = <INF> && ($fastcheck eq 0 || $p < $fastcheck)) {
while (my $s = <INF>) {
my @t = split(' ',$s);
foreach my $e (sort keys %$b) {
if (($b->{$e} & 0xff) ne (hex($t[$i+1]) & 0xff)) {
printf("\nByte %i differs in page %x: flash: %02x file: %02x\n", $i, $p, $b->{$e}&0xff, hex($t[$i+1]) & 0xff);
- $ok = 0;
+ $ok = 0; exit 1;
}
}
}
# }
$p++;
+ if ($fastcheck > 0 && $p > $fastcheck) {
+ last;
+ }
+
}
if ($ok eq 0) {
printf("\nVerification failed!!!\n");
+ exit 1;
} else {
printf("\nVerification OK\n");
}