Besides limit checking the verification of a sequence of events may be important. This example demonstrates how to set up a monitor that checks the proper sequence of a counter. Let's assume we get a block TLM that contains a sequence number. This sequence number should be incrementing by one with every sample we receive. If we get a number that is not in sequence we want to report this in a separate log file and set the current sequence number to the one we just received. The block definition of the TLM block is given below:
TLM
{
ApID ,,,16;
Seq ,,,32;
Data[2000] ,,,16;
}
In this example the monitor has to maintain state information which is a simple value holding the last sequence number seen. The monitor function has to compare the value of the latest sequence number with the one stored and check if the sequence is in proper order. If so our local data needs to be updated. If not report and error and update the sequence number with the last sample received. Here the monitor function:
#
# Import block definitions, Monitor class and other stuff
#
from __main__ import *
import GseosMonitor
import Gseos
#
# Define our local sequence number and initialize to 0.
#
dwSeq = 0
#
# TLM Sequence Monitor
#
def fMonSeq(oBlock):
"TLM Sequence Monitor"
global dwSeq
if oBlock.Seq != dwSeq+1:
gseos.Log('error.log', 'TLM Sequence out order. Expected sequence number: %d, \
'received sequence number: %d' % dwSeq, oBlock.Seq)
dwSeq = oBlock.Seq
Now assign it to the TLM block:
#
# Create a new monitor.
#
oMonSeq = GseosMonitor.TMonitor('MonSeq', fMonSeq)
#
# Assign it to the TLM block.
#
TLM.Monitors.append(oMonSeq)