Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  <20032004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  <20032004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019 
<== Date ==> <== Thread ==>

Subject: Re: Maximum (Minimum) Vaue of a Set of Readback PVs
From: kuner <kuner@mail.bessy.de>
To: tech-talk <tech-talk@aps.anl.gov>
Date: Tue, 24 Jun 2003 21:19:15 +0200
Sorry, that was indeed the outpur of the script. If I've improoved my mail skills yet, the script should be attached now

--
-------------------------------------------------------------------
-- Bernhard.Kuner@bessy.de ----------- Bessy Gmbh -----------------
-- +49 30 6392 4981 ------------------ Albert Einstein Strasse 15 -
-------------------------------------- 12489 Berlin ---------------


eval 'exec perl -S $0 ${1+"$@"}'  # -*- Mode: perl -*-
	if $running_under_some_shell;
use strict;
#
# $Log$

# CreateSt.pl
#
# A little helper to create a snl program that watches a set of PV's and sets a 
# bo record to 1 if at least one of the watched PVS is 1 and set's it to 0 if all
# PV's are 0. Needed to create a summ signal for many error conditions.
#
# For every state set with the functionality described above define a list of 
# Variables to be monitored. Declare all of this lists in %allSig the rest is done
# by the script. It is made shure that PV's that are needed in multiple lists are
# declared and monitored only once.
#
# The subroutine 'stateSet' defines what to do in the state set. It can be modified
# easily.

##################################################
###########   define dependencies here  ##########
##################################################

### define a list for every state set.
my $applicationName='PPTMOD';
my @misc = qw(PPTMOD:CabDoorSw PPTMOD:EarthSw PPTMOD:EmergSw 
		PPTMOD:eoLineMax PPTMOD:GndRod
);
my @cooling = qw(PPTMOD:BodyWaFlSw PPTMOD:CavyWaFlSw PPTMOD:CircWaFlSw 
		PPTMOD:CollWaFlSw PPTMOD:LoadWaFlSw PPTMOD:MagnetTempSw 
		PPTMOD:MagnWaFlSw PPTMOD:TankTempSw PPTMOD:TankWaFlSw
);

### Create one state set for every list
my %allSig = ("misc" => \@misc,
              "cooling" => \@cooling,
  );

##################################################
##########   from now on: DON'T EDIT   ##########
##################################################

  print "**** Creating: state machine for $applicationName application ****\n";

# Create a hash with all signals once
  my %allSignals;
  my $nrOfSignals=0;
  foreach my $s (keys(%allSig))
  { 
    my $rSig = $allSig{$s};
    my %Sig;
    foreach my $sig (@$rSig)
    { my $idx = $allSignals{$sig};
      next if( defined $idx );
      $idx = $nrOfSignals;
      $nrOfSignals++;
      $allSignals{$sig}=$idx;
    }
  }

#  print "All signals and indices, $nrOfSignals\n";
#  my $idx=0;
#  my %revSig = reverse %allSignals;
#  foreach my $pv (sort keys %allSignals){ printf ("%30s = %2d    %2d = %s\n",$pv,$allSignals{$pv},$idx,$revSig{$idx}); $idx++;}

  open (ST, ">$applicationName.st") or die "Can't open file: $applicationName.st: $!";

# Create header of .st file declare and monitor all PV's
  print ST   "program $applicationName\n".
	     "\n".
	     "int stt[$nrOfSignals];\n";

# Define one record for each state set for the output of the calculation done in the state set
  print "\tcreate: $applicationName.st ($nrOfSignals signals). Need epics bo-records:\n";
  foreach my $s (keys(%allSig) )
  { print ST "int $s"."On;\n"; # nameOfTheListOn
    print "\t- $s"."On,\n";
  }
  print ST "\n";
  foreach my $s (keys %allSig )
  { print ST "assign $s"."On \tto \"$applicationName:$s"."On\";\n";
  }
  print ST   "\n/*sorted in alphabetical order of signals*/\n";
  my $idx=0;
  foreach my $sig (sort keys %allSignals)
  { print ST "assign stt[$allSignals{$sig}] to \t\"$sig\";\n";
    #print  "$sig assign stt[$idx] to \t\"$revSig{$sig}\";\n";
    $idx++;
  }
  print ST   "\n".  
	     "monitor stt;\n".
	     "\n";
# now all PVs are declared so create a state set for every list  
  foreach my$sig (keys %allSig)
  { stateSet($sig, $allSig{$sig});
  }
  # Close output file
  close ST or die "Can't close output file: $applicationName"."psOff.st $!\n";

# Create this state set for one list
sub stateSet
{ my($name,$rPVs) = @_;		# name of the state set and PV's related to it
  my $nRows = scalar(@$rPVs);	# number of PV's
# init state
  print ST   "ss $name"."States\n".
             "{\n".
             "  state st_$name"."Init\n".
             "  { when()\n".
             "    { $name"."On=1;\n".
             "      pvPut($name"."On);\n".
             "    } state st_$name"."On\n".
             "  } \n".
             "\n".
             "  state st_$name"."Off\n".
             "  { when(stt[$allSignals{$rPVs->[0]}]";
# the 'one is on' state
  for( $idx=1; $idx<$nRows; $idx++)
  { print ST "||stt[$allSignals{$rPVs->[$idx]}]";
  }

  print ST   ")\n".
             "    { $name"."On = TRUE;\n".
             "      pvPut($name"."On);\n".
             "    } state st_$name"."On\n".
             "  }\n".
             "\n".
# the 'all are off' state
             "  state st_$name"."On\n".
             "  { when(!stt[$allSignals{$rPVs->[0]}]";

  for( $idx=1; $idx<$nRows; $idx++)
  { print ST "&&!stt[$allSignals{$rPVs->[$idx]}]";
  }
  print ST   ")\n".
             "    { $name"."On = FALSE;\n".
             "      pvPut($name"."On);\n".
             "    } state st_$name"."Off\n".
             "  }\n".
             "}\n\n";
}
  close ST or die "Can't close output file: $!\n";


References:
Re: Maximum (Minimum) Vaue of a Set of Readback PVs kuner

Navigate by Date:
Prev: Setting TZ for RTEMS so that local time is correct Allison, Stephanie
Next: Segmentation faults and the ioc example Geoff Savage
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  <20032004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019 
Navigate by Thread:
Prev: Re: Maximum (Minimum) Vaue of a Set of Readback PVs kuner
Next: Setting TZ for RTEMS so that local time is correct Allison, Stephanie
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  <20032004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019 
ANJ, 10 Aug 2010 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·