]> jspc29.x-matter.uni-frankfurt.de Git - hadesdaq.git/commitdiff
fixed buffering bug, mt
authorHADES DAQ <hadaq@gsi.de>
Mon, 19 Mar 2018 21:46:15 +0000 (22:46 +0100)
committerHADES DAQ <hadaq@gsi.de>
Mon, 19 Mar 2018 21:46:15 +0000 (22:46 +0100)
nettools/switchport.pl

index e5eceba77b884aa3fe4b529f0032b0cba9a668cb..bfa4a5b1cb1ec4cd2563df4efca03b6be66026c8 100755 (executable)
@@ -2,38 +2,42 @@
 
 #Used to switch off or on a given port of a hub within Trbnet
 
+use IO::Handle;
+stdout->autoflush(1);
+
 $address = $ARGV[0];
 $portnum = $ARGV[1];
 $onoff   = $ARGV[2];
 $chan    = defined($ARGV[3])?$ARGV[3]:"all";
 
 if (!defined($address) || !$address  || !defined($portnum) || $address =~ /help/) {
-       print "Usage: switchport.pl \$hubaddress \$port [on|off] (\$channel)\n";
+  print "Usage: switchport.pl \$hubaddress \$port [on|off] (\$channel)\n";
 }
 
 if($portnum eq "all" && $onoff eq "on") {
-       $port = 0xfffffff;
-       }
+  $port = 0xfffffff;
+}
 else {
-       $port = 1<<$portnum;
-       }
-       
-sub ex{
-       my ($cmd) = @_;
-       my $err = 0;
-       $cmd .= " 2>&1";
-       my @out = qx($cmd);
-       foreach my $s (@out) {
-               print "$s";
-               if($s =~ /ERROR/) {
-                       $err = 1;
-                       }
-               }
-       if ($err) {
-               print "\n=========================================================\nSomething seems to be wrong. Ctrl-C might be a good choice.";
-               getc();
-               }
-       }
+  $port = 1<<$portnum;
+}
+
+sub ex {
+  my ($cmd) = @_;
+  my $err = 0;
+  $cmd .= " 2>&1";
+  my @out = qx($cmd);
+  foreach my $s (@out) {
+    print "$s";
+    if($s =~ /ERROR/) {
+      $err = 1;
+    }
+  }
+  if ($err) {
+    print "\n=========================================================\nSomething seems to be wrong. Ctrl-C might be a good choice.\n\n";
+    #getc();
+    my $temp = <STDIN>;
+  }
+}
 
 
 if($onoff eq "on") {
@@ -41,12 +45,12 @@ if($onoff eq "on") {
   ex("trbcmd setbit $address 0xc0 $port") if ($chan == 0 || $chan eq "all");
   ex("trbcmd setbit $address 0xc1 $port") if ($chan == 1 || $chan eq "all");
   ex("trbcmd setbit $address 0xc3 $port") if ($chan == 3 || $chan eq "all");
-  }
-  
+}
+
 if($onoff eq "off") {
-       print("\t\tDisable port $portnum on hub $address channel $chan...\n");
+  print("\t\tDisable port $portnum on hub $address channel $chan...\n");
   ex("trbcmd clearbit $address 0xc0 $port") if ($chan == 0 || $chan eq "all");
   ex("trbcmd clearbit $address 0xc1 $port") if ($chan == 1 || $chan eq "all");
   ex("trbcmd clearbit $address 0xc3 $port") if ($chan == 3 || $chan eq "all");
-  }
-  
+}
+