#!/usr/bin/env perl -w # -*- perl -*- # # Purpose: Take LRO Secondary Science packets and verifies # Coincidence Mask test of Long Form Functional # Inputs: SecScience packets processed into ASCII by rtlm # Outputs: Errors as detected #----------------------------------------------------------------------- ######################################################################## # Design Notes # # After initial setup (Bias ON, LLDs 80, CalAmp 128, CalLo ON, CalRate 2KHz) # we start a loop # Detectors On/Off as required # echo 0x01jj where jj goes from 1 to 63 # Coincidence Mask 1<1000; non-match <2 print "@SecSci" if ($Verbose>999); # Just to keep -w happyq ######################################################################## # The master program is here ######################################################################## &Setup; &Run; exit 0; ######################################################################## ######################################################################## ######################################################################## # Help message ######################################################################## sub Help { print STDOUT "Usage: $0 [-h] [-v] filename Processes LRO spacecraft data to verify coincidence mask test. flag -h prints out this help message -v verbose operation "; } ######################################################################## # Scan for a command echo # Args: command id, text for debugging # Sets: $Contents with command value # NB no error check on ; depends on LastValue following LastCmd # Returns 0 normally, 1 on discovering a Clear or Reset ######################################################################## sub CCheck { my $flag = $retval = 0; my ($foo,$bar,$name,$cmd); die 'no arg passed to &CCheck' if (!defined($_[0])); while ($foo=) { next if ($foo !~ /^$CMDLAST\s+$_[0]$/); # wait for specified cmd ($name,$cmd) = split(/\s/,$foo); die "no value associated with $name" if (!defined($cmd)); $bar=; ($name,$Contents) = split(/[ \t]/,$bar); # die "$CMDVALUE did not follow $CMDLAST" if ($name eq $CMDVALUE); print "ERR: $CMDVALUE did not follow $CMDLAST\nERR: $bar\n" if ($name !~ /$CMDVALUE/); if ($cmd == $DISCMD && ($Contents == $CLEAR || $Contents == $RESET)) { $retval++; last; # skip out if reset } die "Index to -Command is $cmd" if ($cmd>15 || $cmd<0); my $what = ( $cmd != $DISCMD ) ? $Command[$cmd] : $DCommand[$cmd]; printf "### Found %s : 0x%04x\n",$what,$Contents if ($Verbose && $cmd == $ECHO); $flag++; last; # found that for which we were looking } if (!$flag) { print "ERR: $_[0] not found\n"; exit 5; # no joy } return($retval); } ######################################################################## # Scan for a telemetry readout # Args: readout mnemonic (from rtlm -a) # Sets: $C1, $C2, $C3, $C4 with command value for mask # or $Contents for any other call # NB no error check on ######################################################################## sub TCheck { my $flag = $retval = 0; my ($foo,$bar,$name,$cmd); die 'no arg passed to &TCheck' if (!defined($_[0])); while ($foo=) { next if ($foo !~ /$_[0]/); # wait for specified cmd ($name,$C1,$C2,$C3,$C4) = split(/\s/,$foo); die "no value associated with $name" if (!defined($C1)); if ($_[0] eq "Mask") { # printf "### Found %s : %s %s %s %s\n",$name,$C1,$C2,$C3,$C4 if $Verbose } else { $Contents = $C1; # printf "### Found %s : 0x%04x\n",$name,$Contents if $Verbose; } $flag++; last; # found that for which we were looking } if (!$flag) { print "ERR: $_[0] not found\n"; exit 5; # no joy } return($retval); } ######################################################################## # Run the program ######################################################################## sub Run { my ($ii,$loop); $Contents = 0; # Get to the beginning of the coincidence mask test while ($Contents != 0x0100) { if (&CCheck($ECHO,"Start of test 0x0100")) { print "### Reset encountered\n" if $Verbose; next; } } # Now check each processing enable case for ($ii = 1; $ii<64; $ii++) { &CCheck($ECHO,"Echo mark"); # find next echo tag $loop = 0x0100 + $ii; if ($Contents != $loop) { printf "ERROR Echo 0x%04x encountered; expecting 0x%04x\n", $Contents, $loop; printf "ERROR Enable case $ii skipped\n"; $ii = $Contents - 0x0100; # reset up the loop counter exit if ($ii>=64); # don't run off the end } &Walk($ii); } } ######################################################################## # Walk up the coincidence mask bits # Arg: current setting of process enables # NB: $target is of form "fffffffffffffffe" which corresponds to # ProcEnable 000001 (D6->D1) ######################################################################## sub Walk { my ($jj,$kk,$mask,$ptmp,$target,@digit); my $proc = $_[0]; $ptmp = $proc; # this is the proc enable number $target = ""; for ($kk=0; $kk<16; $kk++) { # build target mask if ($ptmp==0) { $digit[$kk] = 1; } if ($ptmp==1) { $digit[$kk] = 2; } if ($ptmp==2) { $digit[$kk] = 4; } if ($ptmp==3) { $digit[$kk] = 8; } if ($ptmp<0 || $ptmp>3) { $digit[$kk] = 0; } $target = sprintf("%x",$digit[$kk]) . "$target"; $ptmp -= 4; } printf "### ProcEnable $proc : Targ mask <%s>\n", $target if $Verbose; for ($jj=0; $jj<64; $jj++) { # run through all mask bits &CCheck("$MASK","Can not find next mask set command"); &TCheck("Mask"); # find what the last command set it to $mask = "$C1" . "$C2" . "$C3" . "$C4"; $mask =~ s/\s//g; $ptmp = $jj; $expecting = ""; for ($kk=0; $kk<16; $kk++) { # build test mask if ($ptmp==0) { $digit[$kk] = 1; } if ($ptmp==1) { $digit[$kk] = 2; } if ($ptmp==2) { $digit[$kk] = 4; } if ($ptmp==3) { $digit[$kk] = 8; } if ($ptmp<0 || $ptmp>3) { $digit[$kk] = 0; } $expecting = sprintf("%x",$digit[$kk]) . "$expecting"; $ptmp -= 4; } if ($expecting ne $mask) { printf "ERROR Expecting mask %s, Got mask %s\n",$expecting,$mask; printf "ERROR Skipping to next case\n"; return; } printf "### Read mask <%s>\n",$mask if $Verbose; &TCheck($EVENTS); # skip this one &TCheck($EVENTS); # this one is good print "--- Found $Contents\n" if ($Verbose>1); if ( $Contents<$THRESHOLD ) { if ($mask ne $target) { next; } else { printf "ERROR Counts low for proc enable %d and mask %s\n", $proc, $mask; next; } } if ( $Contents>$THRESHOLD ) { if ($mask eq $target) { printf "STAT Enable $proc OK\n"; next; } else { printf "ERROR Counts high for proc enable %d and mask %s\n", $proc, $mask; next; } } } } ######################################################################## # Setup the program ######################################################################## sub Setup { my $foo; while ($foo = shift(@ARGV)) { if ($foo =~ /^-[hH]/) { &Help; exit 0; } if ($foo =~ /^-[vV]/) { $Verbose++; next; } if ($foo =~ /^-/) { print STDERR "Unknown flag $foo\n"; &Help; exit 1; } if (-r $foo) { $InputFile = $foo; next; } else { print STDERR "Could not read $foo as input\n"; exit 2; } } if (!$InputFile) { print STDERR "$0 requires an input file name\n"; &Help; exit 2; } if (! -r $InputFile) { print STDERR "Could not find $InputFile\n"; &Help; exit 2; } open(GET,"$DIR/rtlm -r $InputFile -a -t |") || die "open() failed"; } ######################################################################## # Pod follows ######################################################################## =for html CRaTER -- ar_conic_check =head2 NAME B -- Check the LFF Coincidence Mask Test Results =head2 USAGE ar_conic_check [-h] [-v] filename =head2 FLAGS -h provides help message -v verbose mode =head2 DESCRIPTION This script assumes the existance of a single file which contains the results of a Long Form Functional coincidence mask test. It depends on all the data tag echos being present. =head2 DATA MARKERS required =over =item 0x0100 -- start of test =item 0x01xx -- start of each mask scan; xx = Processing Enable setting =back =head2 ENVIRONMENT perl5.002 Minimum version of Perl interpreter required CRATERTOOLS Environment variable containing path to CRaTER utilities CRATER_GSE Environment variable containing EGSE machine name =head2 BUGS =head2 SEE ALSO rtlm =head2 AUTHOR Bob Goeke =head2 RCS Information $Id: ar_coinc_check,v 1.1 2008/09/12 19:44:49 goeke Exp goeke $ =cut ######################################################################## # history follows ######################################################################## # $Log: ar_coinc_check,v $ # Revision 1.1 2008/09/12 19:44:49 goeke # Initial revision # # Revision 1.2 2008/08/29 19:13:44 goeke # Added error processing for missing packets # # Revision 1.1 2008/08/29 18:37:01 goeke # Initial revision #