phytronFilterIpPortLog.pl: show camonitor data, translate MSTA bits to strings

Wed, 02 Mar 2022 19:06:26 +0100

author
Bernhard.Kuner@bessy.de
date
Wed, 02 Mar 2022 19:06:26 +0100
changeset 2440
2bc737833b37
parent 2439
dd51aae58f05
child 2441
dc3683b9b552

phytronFilterIpPortLog.pl: show camonitor data, translate MSTA bits to strings
Ignore-this: 8987ec85400813fe166d5e44341366cb5bbdd138f8d8ebcd90a1408a70a118eab52a283869d8e429

bin/phytronFilterIpPortLog.pl file | annotate | diff | comparison | revisions
--- a/bin/phytronFilterIpPortLog.pl	Thu Feb 24 15:28:10 2022 +0100
+++ b/bin/phytronFilterIpPortLog.pl	Wed Mar 02 19:06:26 2022 +0100
@@ -14,11 +14,28 @@
 # 0:0C
     use strict;
     use Getopt::Long;
-
     my $usage = "phytronFilterLog.pl [OPTIONS] phytronIpPortLogFile\n\t-h: help\n\t-f: filter e.g. M1.1 for motor 1\n";
     my $filter = ".*";     #default: get all
     my $ignore = "___";
     our($opt_h,$opt_f,$opt_i) = (undef,undef,undef);
+    my @msta = ("Dir=",
+         "DONE",
+         "LS+",
+         "LS_HOME",
+         "nn",
+         "POS",
+         "SLIP_STALL",
+         "HOME",
+         "PRESENT",
+         "PROBLEM",
+         "MOVING",
+         "GAIN_SUPPORT",
+         "COMM_ERR",
+         "LS-",
+         "HOMEDone",
+         "nn"
+         );
+
 
     Getopt::Long::config(qw(no_ignore_case));
     die unless GetOptions("h","f=s","i=s");
@@ -36,17 +53,19 @@
     my $timeWrite;
     my $timeRead;
     my $line;
-    my $lineNr = 0;
+    my $lineNr;
+    my @result;
     while( <IN_FILE> )
     {
         my $matchFilter = undef;
         $line = $_;
         $lineNr++;
-        $timeWrite = $1;
-# check write                    
+        $line = checkCaMonitorData($line,\@result); # return next line, if this is a monitor, same else
         if($line =~ /^.*?\s(.*?)\s.*?\s(\w+)/ && $2 eq 'write') {
+            $timeWrite = $1;
             $line = <IN_FILE>;
             $lineNr++;
+            $line = checkCaMonitorData($line,\@result); # return next line, if this is a monitor, same else
             if($line=~/\d(M.*):../) { # Axis command
                 $command=$1;
             }
@@ -54,44 +73,90 @@
                 $command=$1;
             }
             else {
-                $command = "ILLEGAL COMMAND: '$line'\n";
+                chomp $line;
+                push @result, "$timeWrite\terr\tILLEGAL COMMAND in $lineNr: '$line'\t\n";
             }
             if( not ($command =~/$ignore/) ) {
                 if( $command =~/$filter/) {
-                    print "$lineNr\t$timeWrite\twr\t$command\n";
+                    push @result, "$timeWrite\twr\t$command\n";
                     $matchFilter = 1;
                 }
             }
+            $line = <IN_FILE>;
+            $lineNr++;
+            $line = checkCaMonitorData($line,\@result); # return next line, if this is a monitor, same else
+            if($line =~ /^.*?\s(.*?)\s.*?\s(\w+)/ && $2 eq 'read') {
+                $timeRead = $1;
+                $line = <IN_FILE>;
+                $lineNr++;
+                if($line=~/(.*):../) {
+                    $reply = $1;
+                    $reply = getStatus($reply) if($command=~/M\d+\.\dSE/)
+                }
+                else {
+                    chomp($line);
+                    $reply = "ILLEGAL REPLY: '$line'";
+                }
+                push @result,"$timeRead\trd\t$reply\n" if($matchFilter);
+            }
+            else {
+                chomp($line);
+                push @result, "$timeRead\terr\tMISS READ in $lineNr: '$line'\n";
+            }
+
         }
         else {
             chomp($line);
-            print "$lineNr\t$timeWrite\terr\tWRITE EXPECTED:\t'$line'\n";
+            push @result, "\n$timeWrite\terr\tWRITE EXPECTED in $lineNr:\t'$line'";
         }
         
-# next should be 'read'
+    } # end while
+    close IN_FILE;
+
+#    print $_ foreach (@result);
+    print $_ foreach (sort(@result));
+
+# n2str($value,@bitDescriptions)
+sub n2str
+{   my $value = shift @_;
+    my $rDesc = shift @_;
+    my $hex  = sprintf("%X",$value);
+    my $msg;
+    my $idx=0;
+
+    foreach my $dsc (@$rDesc){
+        my $bit = ($value >> $idx)&0x1;
+        if($dsc=~/=/) {
+            $dsc = $dsc.$bit;
+        }
+        if($dsc=~/!/) {
+            $msg .= " $dsc" if($bit == 0);
+        }
+        else {
+            $msg .= " $dsc" if($bit == 1);
+        }
+        $idx++;
+    }
+    return "0x$hex STAT:$msg";    
+}
+
+# check for camonitor data:
+sub checkCaMonitorData
+{   my ($line,$rResult) = @_;
+    while($line =~ /^(.*?)\.([\w\d]+)\s+\d+-\d+-\d+\s+(.*?)\s+(.*)/) {
+        my $pv=$1;
+        my $field=$2;
+        my $time=$3;
+        my $value=$4;
+        if($field eq "MSTA") {
+            $value = "$value\t".n2str($value,\@msta);
+        }
+        push @$rResult, "$time\t$pv.$field\t$value\n";
         $line = <IN_FILE>;
         $lineNr++;
-        $timeRead = $1;
-        if($line =~ /^.*?\s(.*?)\s.*?\s(\w+)/ && $2 eq 'read') {
-            $line = <IN_FILE>;
-            $lineNr++;
-            if($line=~/(.*):../) {
-                $reply = $1;
-                $reply = getStatus($reply) if($command=~/M\d+\.\dSE/)
-            }
-            else {
-                chomp($line);
-                $reply = "ILLEGAL REPLY: '$line'";
-            }
-            print "$lineNr\t$timeRead\trd\t$reply\n" if($matchFilter);
-        }
-        else {
-            chomp($line);
-            print "$lineNr\t$timeRead\terr\tMISS READ\t'$line'\n";
-        }
     }
-    close IN_FILE;
-
+    return $line;
+}
 sub getStatus 
 {   my ($reply) = @_;
     my $hex  = sprintf("%X",$reply);

mercurial