]> jspc29.x-matter.uni-frankfurt.de Git - daqtools.git/commitdiff
Get rid of switch/when in get.pl
authorJan Michel <michel@physik.uni-frankfurt.de>
Tue, 5 Nov 2024 13:58:43 +0000 (14:58 +0100)
committerJan Michel <michel@physik.uni-frankfurt.de>
Tue, 5 Nov 2024 13:58:43 +0000 (14:58 +0100)
xml-db/database/Mimosis.xml
xml-db/get.pl

index f996e478b99e56a64aba25dc95087bac40bde63b..9207e566b3ac179e6042f2e014a7528239beef80 100644 (file)
   </group>
 
   
-  <group name="MimosisI2C" address="3e00"  size="6"  purpose="status" mode="rw" continuous="true">
+  <group name="MimosisI2C" address="4e00"  size="6"  purpose="status" mode="rw" continuous="true">
     <register name="MimosisI2C0" address="0000" >
       <description>First I2C register</description>
       <field name="Speed" start="0" bits="6" format="unsigned"  noflag="true" >
index ea7bc3a667d3518be669e932becda1b0c68114bd..5dea63ae926bbb0c99b65db71793275046de5c27 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 use HADES::TrbNet;
 use Storable qw(lock_store retrieve lock_retrieve);
-use feature "switch";
+use feature "switch";
 use Time::HiRes qw( time usleep );
 
 use if (defined $ENV{'QUERY_STRING'}), CGI::Carp => qw(fatalsToBrowser);
@@ -11,7 +11,7 @@ use if (!defined $ENV{'QUERY_STRING'}), Text::TabularDisplay;
 use if (!defined $ENV{'QUERY_STRING'}), Data::Dumper;
 use if (!defined $ENV{'QUERY_STRING'}), Data::TreeDumper;
 use if (!defined $ENV{'QUERY_STRING'}), Getopt::Long;
-no warnings 'experimental::smartmatch';
+no warnings 'experimental::smartmatch';
 
 # use Data::TreeDumper;
 # use Data::Dumper;
@@ -27,7 +27,7 @@ my @RegisterDump;
 my ($file,$entity,$netaddr,@spi_chains,$name, $style, $storefile, $rates, $cache, $isInline, $olddata);
 my $lastboards;
 
-$ENV{'DAQOPSERVER'}="localhost:7" unless (defined $ENV{'DAQOPSERVER'});
+$ENV{'DAQOPSERVER'}="localhost" unless (defined $ENV{'DAQOPSERVER'});
 die "can not connect to trbnet-daemon on $ENV{'DAQOPSERVER'}: ".trb_strerror() unless (defined &trb_init_ports());
 
 
@@ -234,49 +234,61 @@ sub FormatPretty {
     my $t = "";
     $ret = "<$cont ";
     if ($readable) {
-      for ($obj->{format}) {
-        when ("boolean") {
-          if ($obj->{errorflag}) {
-            $ret .= "$cl".($value?"true":"false");
-          } else {
-            $ret .= "$cl".($value?"true":"false");
-          }
-        }
-        when ("float")    { $ret .= sprintf("$cl%.2f",$value);}
-        when ("integer")  { $t    = sprintf("%i",$value);
-                            $t =~ s/(?<=\d)(?=(?:\d\d\d)+\b)/ /g;#&#8198;
-                            $ret .= $cl.$t;
-                          }
-        when ("unsigned") { $t    = sprintf("%u",$value);
-                            $t =~ s/(?<=\d)(?=(?:\d\d\d)+\b)/ /g;#&#8198;
-                            $ret .= $cl.$t;
-                          }
-        when ("signed")   { $t    = sprintf("%i",$value);
-                            $t =~ s/(?<=\d)(?=(?:\d\d\d)+\b)/ /g;#&#8198;
-                            $ret .= $cl.$t;}  #$ret .= sprintf("$cl%d",$value);
-        when ("binary")   { $t    = sprintf("%0".$obj->{bits}."b",$value);
-                            $t =~ s/(?<=\d)(?=(?:\d\d\d\d)+\b)/ /g;#&#8198;
-                            $ret .= $cl.$t;
-                          }
-        when ("bitmask")  { my $tmp = sprintf("%0".$obj->{bits}."b",$value);
-                            $tmp =~ s/(?<=\d)(?=(?:\d\d\d\d)+\b)/ /g;#&#8198;
-                            $tmp =~ s/0/\&#9633\;/g;
-                            $tmp =~ s/1/\&#9632\;/g;
-                            $tmp =~ s/\s/ /g;#&#8198;
-
-                            $ret .= $cl.$tmp;
+      if ($obj->{format} eq "boolean") {
+                          if ($obj->{errorflag}) {
+                            $ret .= "$cl".($value?"true":"false");
+                          } else {
+                            $ret .= "$cl".($value?"true":"false");
                           }
-        when ("time")     {require Date::Format; $ret .= Date::Format::time2str('>%Y-%m-%d %H:%M',$value);}
-        when ("hex")      {$ret .= sprintf($cl."0x%0".(int(($obj->{bits}+3)/4))."x",$value);}
-        when ("enum")     { my $t = sprintf("%x",$value);
-                            if (exists $obj->{enumItems}->{$t}) {
-                              $ret .= $cl.$obj->{enumItems}->{$t}
-                            } else {
-                              $ret .= $cl."0x".$t;
-                            }
+                        }
+      elsif ($obj->{format} eq "float")    {  
+                          $ret .= sprintf("$cl%.2f",$value);
+                        }
+      elsif ($obj->{format} eq "integer")  { 
+                          $t    = sprintf("%i",$value);
+                          $t =~ s/(?<=\d)(?=(?:\d\d\d)+\b)/ /g;#&#8198;
+                          $ret .= $cl.$t;
+                        }
+      elsif ($obj->{format} eq "unsigned") { 
+                          $t    = sprintf("%u",$value);
+                          $t =~ s/(?<=\d)(?=(?:\d\d\d)+\b)/ /g;#&#8198;
+                          $ret .= $cl.$t;
+                        }
+      elsif ($obj->{format} eq "signed")   {  
+                          $t    = sprintf("%i",$value);
+                          $t =~ s/(?<=\d)(?=(?:\d\d\d)+\b)/ /g;#&#8198;
+                          $ret .= $cl.$t;}  #$ret .= sprintf("$cl%d",$value);
+      elsif ($obj->{format} eq "binary")   {  
+                          $t    = sprintf("%0".$obj->{bits}."b",$value);
+                          $t =~ s/(?<=\d)(?=(?:\d\d\d\d)+\b)/ /g;#&#8198;
+                          $ret .= $cl.$t;
+                        }
+      elsif ($obj->{format} eq "bitmask")  { 
+                          my $tmp = sprintf("%0".$obj->{bits}."b",$value);
+                          $tmp =~ s/(?<=\d)(?=(?:\d\d\d\d)+\b)/ /g;#&#8198;
+                          $tmp =~ s/0/\&#9633\;/g;
+                          $tmp =~ s/1/\&#9632\;/g;
+                          $tmp =~ s/\s/ /g;#&#8198;
+
+                          $ret .= $cl.$tmp;
+                        }
+      elsif ($obj->{format} eq "time")     { 
+                          require Date::Format; $ret .= Date::Format::time2str('>%Y-%m-%d %H:%M',$value);
+                        }
+      elsif ($obj->{format} eq "hex")      {       
+                          $ret .= sprintf($cl."0x%0".(int(($obj->{bits}+3)/4))."x",$value);
+                        }
+      elsif ($obj->{format} eq "enum")     {  
+                          my $t = sprintf("%x",$value);
+                          if (exists $obj->{enumItems}->{$t}) {
+                            $ret .= $cl.$obj->{enumItems}->{$t}
+                          } else {
+                            $ret .= $cl."0x".$t;
                           }
-        default           {$ret .= sprintf(">%08x",$value);}
-      }
+                        }
+      else                        {
+                          $ret .= sprintf(">%08x",$value);
+                        }
     } else {
       $ret .= $cl."&nbsp;";
     }
@@ -286,25 +298,23 @@ sub FormatPretty {
     $ret .= sprintf("<span class=\"tooltip\"><b>$name</b> (Bit $range) - raw: 0x%x<br>$cstr</span></div>",$rawvalue);
 
   } else {
-    for ($obj->{format}) {
-      when ("boolean")  {$ret = $value?"true":"false";}
-      when ("float")    {$ret = sprintf("%.2f",$value);}
-      when ("integer")  {$ret = sprintf("%i",$value);}
-      when ("unsigned") {$ret = sprintf("%u",$value);}
-      when ("signed")   {$ret = sprintf("%d",$value);}
-      when ("binary")   {$ret = sprintf("%b",$value);}
-      when ("bitmask")  {$ret = sprintf("%0".$obj->{bits}."b",$value);}
-      when ("time")     {require Date::Format; $ret = Date::Format::time2str('%Y-%m-%d %H:%M',$value);}
-      when ("hex")      {$ret = sprintf("0x%0".int(($obj->{bits}+3)/4)."x",$value);}
-      when ("enum")     { my $t = sprintf("%x",$value);
-                          if (exists $obj->{enumItems}->{$t}) {
-                            $ret = $obj->{enumItems}->{$t}
-                          } else {
-                            $ret = "0x".$t;
-                          }
-                        }
-      default           {$ret = sprintf("0x%08x",$value);}
-    }
+    if ($obj->{format} eq "boolean")  {$ret = $value?"true":"false";}
+      elsif ($obj->{format} eq "float")    {$ret = sprintf("%.2f",$value);}
+      elsif ($obj->{format} eq "integer")  {$ret = sprintf("%i",$value);}
+      elsif ($obj->{format} eq "unsigned") {$ret = sprintf("%u",$value);}
+      elsif ($obj->{format} eq "signed")   {$ret = sprintf("%d",$value);}
+      elsif ($obj->{format} eq "binary")   {$ret = sprintf("%b",$value);}
+      elsif ($obj->{format} eq "bitmask")  {$ret = sprintf("%0".$obj->{bits}."b",$value);}
+      elsif ($obj->{format} eq "time")     {require Date::Format; $ret = Date::Format::time2str('%Y-%m-%d %H:%M',$value);}
+      elsif ($obj->{format} eq "hex")      {$ret = sprintf("0x%0".int(($obj->{bits}+3)/4)."x",$value);}
+      elsif ($obj->{format} eq "enum")     { my $t = sprintf("%x",$value);
+                                            if (exists $obj->{enumItems}->{$t}) {
+                                              $ret = $obj->{enumItems}->{$t}
+                                            } else {
+                                              $ret = "0x".$t;
+                                            }
+                                          }
+    else                                  {$ret = sprintf("0x%08x",$value);}
     $ret .= " ".$obj->{unit} if exists $obj->{unit};
   }
   return $ret;
@@ -360,28 +370,24 @@ sub requestdata {
 
 sub register_read {
   my ($netaddr, $regaddr) = @_;
-  for ($db->{'§EntityType'}) {
-    when ("TrbNetEntity")  {
-      return convert_keys_to_hex(trb_register_read($netaddr, $regaddr));
+  if ($db->{'§EntityType'} eq "TrbNetEntity")  {
+    return convert_keys_to_hex(trb_register_read($netaddr, $regaddr));
     }
-    when ("SpiEntity") {
-      return spi_register_read($netaddr, $regaddr);
+  elsif ($db->{'§EntityType'} eq "SpiEntity") {
+    return spi_register_read($netaddr, $regaddr);
     }
-    default {die "EntityType not recognized";}
-  }
+  else {die "EntityType not recognized";}
 }
 
 sub register_read_mem {
   my ($netaddr, $regaddr, $start, $size) = @_;
-  for ($db->{'§EntityType'}) {
-    when ("TrbNetEntity")  {
-      $o = convert_keys_to_hex(trb_register_read_mem($netaddr, $regaddr, $start, $size));
+  if ($db->{'§EntityType'} eq "TrbNetEntity")  {
+    $o = convert_keys_to_hex(trb_register_read_mem($netaddr, $regaddr, $start, $size));
     }
-    when ("SpiEntity") {
-      die "Reading SpiEntity Memory not implemented yet...";
+  elsif ($db->{'§EntityType'} eq "SpiEntity") {
+    die "Reading SpiEntity Memory not implemented yet...";
     }
-    default {die "EntityType not recognized";}
-  }
+  else {die "EntityType not recognized";}
   #die Dumper($o);
   return $o;
 }