From 1fee94674ddd2f88209302296f5f30f3c5f2e68b Mon Sep 17 00:00:00 2001 From: hadaq Date: Mon, 22 Oct 2012 00:31:47 +0000 Subject: [PATCH] first version for threshold settings for PADIWA, mt --- thres/run_thresh_on_system.pl | 126 ++++++++++++++++++++++++++++++++++ thres/thresholds_automatic.pl | 12 ++-- 2 files changed, 134 insertions(+), 4 deletions(-) create mode 100755 thres/run_thresh_on_system.pl diff --git a/thres/run_thresh_on_system.pl b/thres/run_thresh_on_system.pl new file mode 100755 index 0000000..35d4b79 --- /dev/null +++ b/thres/run_thresh_on_system.pl @@ -0,0 +1,126 @@ +#!/usr/bin/perl + +use warnings; +use strict; + +use Getopt::Long; +use English; +use Data::Dumper; + +use HADES::TrbNet; + + +my $opt_help; +my @opt_endpoints; +my @opt_chains; +my $opt_offset = 0; +my $opt_verb; + +GetOptions ('h|help' => \$opt_help, + 'e|endpoints=s' => \@opt_endpoints, + 'c|chains=s' => \@opt_chains, + 'o|offset=s' => \$opt_offset, + 'v|verb' => \$opt_verb); + + +my $endpoints = get_ranges(\@opt_endpoints); +my $chains = get_ranges(\@opt_chains); + +if( $opt_help ) { + &help(); + exit(0); +} + + +#print Dumper $endpoints; +#print Dumper $chains; + + +my $command; + +my @pids=(); +my %pids; + +foreach my $endpoint (@$endpoints) { + foreach my $chain (@$chains) { + my $endpoint = sprintf("0x%04x", $endpoint); + $command = "./thresholds_automatic.pl -e $endpoint -o $opt_offset -c $chain"; + #print "command: $command\n"; + my $pid = fork(); + if($pid==0) { #child + my $res = qx($command); + #print $res; + exit; + } + else { + push @pids, $pid; + $pids{$pid} = 1; + } + #print $res; + } +} + +#print Dumper \%pids; + +foreach my $endpoint (@$endpoints) { + foreach my $chain (@$chains) { + my $pid = wait(); + print "pid: $pid returned\n"; + #last if $pid == -1; + delete $pids{$pid}; + #print Dumper \%pids; + } +} + +exit; + + +sub get_ranges { + (my $ra_data) = @_; + + my @array; + foreach my $str (@$ra_data) { + $str=~s/-/\.\./; + $str=~s/\.\.\./\.\./; + my @val = split(/\,/, $str); + #print Dumper \@val; + foreach my $c_val (@val) { + if($c_val =~ /\.\./) { + #print "range: $c_val\n"; + (my $start, my $stop) = $c_val =~ /(\w+)\.\.(\w+)/; + $start = hex($start) if($start=~/0x/); + $stop = hex($stop) if($stop=~/0x/); + #print "start $start, stop $stop\n"; + foreach ($start .. $stop) { + push @array, $_; + } + #print Dumper \@array; + } + else { + $c_val = hex($c_val) if($c_val=~/0x/); + push @array, int($c_val); + } + + } + + } + + return \@array; + +} + + +sub help { + +print <error($s); + $logger_data->error($s); exit(); } -- 2.43.0