From e351d229b4dda6950fe9f447906c9cd00e644679 Mon Sep 17 00:00:00 2001 From: Hades DAQ Date: Wed, 5 Feb 2025 16:46:16 +0100 Subject: [PATCH] update scripts --- scripts/MDC.pm | 2 +- scripts/README.md | 1 + scripts/load_flash_settings.pl | 8 ++++++ scripts/mdc_voltage.pl | 2 +- scripts/pasttrec_set_threshold.pl | 47 +++++++++++++++++++++++++++---- scripts/powercycle_missing.pl | 45 +++++++++++++++++++++++++++++ 6 files changed, 98 insertions(+), 7 deletions(-) create mode 100755 scripts/powercycle_missing.pl diff --git a/scripts/MDC.pm b/scripts/MDC.pm index fdc48c7..9b88e05 100644 --- a/scripts/MDC.pm +++ b/scripts/MDC.pm @@ -50,7 +50,7 @@ sub get_position { $p = (($addr>>8)==0x8e)?0:2; $p += 1 if (($addr>>4)&0xf)>=6; } - elsif($addr > 0xa000 && $addr < 0xbfff) { + elsif($addr >= 0xa000 && $addr < 0xbfff) { $e = $addr & 0x3; $b = ($addr>>4) & 0xf; $s = (($addr>>8)&0xf)%6; diff --git a/scripts/README.md b/scripts/README.md index b0bc30e..db8e42b 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -20,6 +20,7 @@ * `mdc_voltage.pl` set voltages and update voltage database file, switches boards on/off, based on addresses * `mdc_powerboard.pl` send commands to a MDC power board, based on raw device and channel numbers * `check_voltages.pl` reads voltages and suggests changes +* `powercycle_missing.pl` takes the Hmon log and powercyles missing MBOs # Packages * `MDC.pm` Library with common functions, like address lookup diff --git a/scripts/load_flash_settings.pl b/scripts/load_flash_settings.pl index cfa3f37..38e8c76 100755 --- a/scripts/load_flash_settings.pl +++ b/scripts/load_flash_settings.pl @@ -49,17 +49,25 @@ if (defined $board){ elsif (defined $all) { trb_init_ports() or die trb_strerror(); my $boards = trb_read_uid(0xfe90); + my $totalboards = scalar keys %$boards; + my $i = 1; foreach my $uid (keys %$boards) { foreach my $k (keys %{$boards->{$uid}}) { my $addr = $boards->{$uid}{$k}; + print("OEP $i/$totalboards\n"); load_board($addr); + $i++; } } $boards = trb_read_uid(0xfe91); + $totalboards = scalar keys %$boards; + $i = 1; foreach my $uid (keys %$boards) { foreach my $k (keys %{$boards->{$uid}}) { my $addr = $boards->{$uid}{$k}; + print("TDC $i/$totalboards\n"); load_board($addr); + $i++; } } } diff --git a/scripts/mdc_voltage.pl b/scripts/mdc_voltage.pl index 0ccc7f9..c572b96 100755 --- a/scripts/mdc_voltage.pl +++ b/scripts/mdc_voltage.pl @@ -147,7 +147,7 @@ if((defined $on || defined $off) && defined $board) { } } if($on && $off) { - sleep 1; + sleep .2; } if ($on) { foreach my $br (0..15) { diff --git a/scripts/pasttrec_set_threshold.pl b/scripts/pasttrec_set_threshold.pl index 7add8d2..a65c041 100755 --- a/scripts/pasttrec_set_threshold.pl +++ b/scripts/pasttrec_set_threshold.pl @@ -2,17 +2,54 @@ use warnings; use HADES::TrbNet; use Time::HiRes; +use Getopt::Long; + + +my $board; +my $pasttrec; + +Getopt::Long::Configure(qw(gnu_getopt)); +GetOptions( + 'help|h' => \$help, + 'board|b=s' => \$board, + 'pt|p=s' => \$pasttrec, + ); + +if($help) { +print < 0xbbf2) && $board != 0xfe91); + +my $firstpt = $pasttrec // 0; +my $lastpt = $pasttrec // 3; + +die "Pasttrec must be in range 0 to 3" if ($firstpt < 0 || $firstpt > 3); + trb_init_ports() or die trb_strerror(); if($threshold < 0 || $threshold > 127) { - die "not in valid range 0..127\n"; + die "Threshold not in valid range 0..127\n"; } -foreach my $pt (0..3) { - trb_register_write(0xfe91,0xa200+($pt << 4)+3,0x50300+$threshold); +foreach my $pt ($firstpt..$lastpt) { + trb_register_write($board,0xa200+($pt << 4)+3,0x50300+$threshold); } -printf(" Threshold %i set to all available PASTTRECs. \n", $threshold); +printf(" Threshold %i set to PASTTRECs on %04x \n", $threshold,$board); diff --git a/scripts/powercycle_missing.pl b/scripts/powercycle_missing.pl new file mode 100755 index 0000000..05d8685 --- /dev/null +++ b/scripts/powercycle_missing.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl -w +use warnings; +no warnings "portable"; +use FileHandle; +use Getopt::Long; +use Data::Dumper; +use lib '.'; +use Time::HiRes qw(usleep); + + +die "Run on machine with Hmon!" unless -e "/dev/shm/hmon/qalog"; + +my @logfile = qx(tail -n 250 /dev/shm/hmon/qalog); +my %cycledboards; + +foreach my $l (@logfile) { + my @d = split("\t",$l); + if (defined $d[2] && $d[1] eq 'endp' && $d[2] eq 'mdc') { + next if scalar @d < 7; + my @boards = split(' ',$d[7]); +# die "Looks like too many boards missing" unless scalar @boards < 50; + foreach my $b (@boards) { + if ($b =~ /0x8[ef]\w\w/) { + print ("$b"); + print(" skipped\n") and next if $cycledboards{hex($b)}; + system("./mdc_voltage.pl -b $b --on --off"); + usleep(10000); + print("\n"); + $cycledboards{hex($b)}=1; + } + if ($b =~ /0x[ab]\w\w\w/) { + print($b); + $b = 0x8e00 + ((hex($b)>>4)-0xa00); + printf (" -> %04x",$b); + print(" skipped\n") and next if $cycledboards{$b}; + system("./mdc_voltage.pl -b $b --on --off"); + usleep(10000); + print("\n"); + $cycledboards{$b}=1; + } + } + + last; + } +} -- 2.43.0