Ignore:
Timestamp:
11/17/12 11:49:42 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Added a delayed logging of the AP settings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/checks.py

    r335 r338  
    666666#---------------------------------------------------------------------------------------
    667667
     668class APLogger(StateChangeLogger, DelayedChangeMixin):
     669    """Log the state of the autopilot."""
     670    @staticmethod
     671    def _logBoolean(logger, timestamp, what, value):
     672        """Log a boolean value.
     673
     674        what is the name of the value that is being logged."""
     675        message = what + " "
     676        if value is None:
     677            message += "cannot be detected, will not log"
     678        else:
     679            message += "is " + ("ON" if value else "OFF")
     680        logger.message(timestamp, message)
     681
     682    @staticmethod
     683    def _logNumeric(logger, timestamp, what, format, value):
     684        """Log a numerical value."""
     685        message = what
     686        if value is None:
     687            message += u" cannot be detected, will not log"
     688        else:
     689            message += u": " + format % (value,)
     690        logger.message(timestamp, message)
     691
     692    @staticmethod
     693    def _logAPMaster(logger, timestamp, state):
     694        """Log the AP master state."""
     695        APLogger._logBoolean(logger, timestamp, "AP master",
     696                             state.apMaster)
     697
     698    @staticmethod
     699    def _logAPHeadingHold(logger, timestamp, state):
     700        """Log the AP heading hold state."""
     701        APLogger._logBoolean(logger, timestamp, "AP heading hold",
     702                             state.apHeadingHold)
     703
     704    @staticmethod
     705    def _logAPHeading(logger, timestamp, state):
     706        """Log the AP heading."""
     707        APLogger._logNumeric(logger, timestamp, u"AP heading",
     708                             u"%03.0f\u00b0", state.apHeading)
     709
     710    @staticmethod
     711    def _logAPAltitudeHold(logger, timestamp, state):
     712        """Log the AP altitude hold state."""
     713        APLogger._logBoolean(logger, timestamp, "AP altitude hold",
     714                             state.apAltitudeHold)
     715
     716    @staticmethod
     717    def _logAPAltitude(logger, timestamp, state):
     718        """Log the AP heading."""
     719        APLogger._logNumeric(logger, timestamp, u"AP altitude",
     720                             u"%.0f ft", state.apAltitude)
     721
     722    def __init__(self):
     723        """Construct the state logger."""
     724        StateChangeLogger.__init__(self)
     725        DelayedChangeMixin.__init__(self)
     726        self._lastLoggedState = None
     727
     728    def _getValue(self, state):
     729        """Convert the relevant values from the given state into a tuple."""
     730        return (state.apMaster,
     731                state.apHeadingHold, state.apHeading,
     732                state.apAltitudeHold, state.apAltitude)
     733
     734    def _isDifferent(self, oldValue, newValue):
     735        """Determine if the given old and new values are different (enough) to
     736        be logged."""
     737        (oldAPMaster, oldAPHeadingHold, oldAPHeading,
     738         oldAPAltitudeHold, oldAPAltitude) = oldValue
     739        (apMaster, apHeadingHold, apHeading,
     740         apAltitudeHold, apAltitude) = newValue
     741
     742        if apMaster is not None and apMaster!=oldAPMaster:
     743            return True
     744        if apMaster is False:
     745            return False
     746
     747        if apHeadingHold is not None and apHeadingHold!=oldAPHeadingHold:
     748            return True
     749        if apHeadingHold is not False and apHeading is not None and \
     750            apHeading!=oldAPHeading:
     751            return True
     752
     753        if apAltitudeHold is not None and apAltitudeHold!=oldAPAltitudeHold:
     754            return True
     755        if apAltitudeHold is not False and apAltitude is not None and \
     756            apAltitude!=oldAPAltitude:
     757            return True
     758
     759        return False
     760
     761    def logState(self, flight, logger, state):
     762        """Log the autopilot state."""
     763        timestamp = DelayedChangeMixin._getLogTimestamp(self, state, False)
     764        if self._lastLoggedState is None:
     765            self._logAPMaster(logger, timestamp, state)
     766            if state.apMaster is not False or state.apHeadingHold is None:
     767                self._logAPHeadingHold(logger, timestamp, state)
     768            if state.apMaster is not False and \
     769               (state.apHeadingHold is not False or state.apHeading is None):
     770                self._logAPHeading(logger, timestamp, state)
     771            if state.apMaster is not False or state.apAltitudeHold is None:
     772                self._logAPAltitudeHold(logger, timestamp, state)
     773            if state.apMaster is not False and \
     774               (state.apAltitudeHold is not False or state.apAltitude is None):
     775                self._logAPAltitude(logger, timestamp, state)
     776            self._firstCall = False
     777        else:
     778            oldState = self._lastLoggedState
     779
     780            apMasterTurnedOn = False
     781            if state.apMaster is not None and state.apMaster!=oldState.apMaster:
     782                apMasterTurnedOn = state.apMaster
     783                self._logAPMaster(logger, timestamp, state)
     784
     785            if state.apMaster is not False:
     786                apHeadingHoldTurnedOn = False
     787                if state.apHeadingHold is not None and \
     788                   (state.apHeadingHold!=oldState.apHeadingHold or
     789                    apMasterTurnedOn):
     790                    apHeadingHoldTurnedOn = state.apHeadingHold
     791                    self._logAPHeadingHold(logger, timestamp, state)
     792
     793                if state.apHeadingHold is not False and \
     794                   state.apHeading is not None and \
     795                   (state.apHeading!=oldState.apHeading or apMasterTurnedOn or
     796                    apHeadingHoldTurnedOn):
     797                    self._logAPHeading(logger, timestamp, state)
     798
     799                apAltitudeHoldTurnedOn = False
     800                if state.apAltitudeHold is not None and \
     801                   (state.apAltitudeHold!=oldState.apAltitudeHold or
     802                    apMasterTurnedOn):
     803                    apAltitudeHoldTurnedOn = state.apAltitudeHold
     804                    self._logAPAltitudeHold(logger, timestamp, state)
     805
     806                if state.apAltitudeHold is not False and \
     807                   state.apAltitude is not None and \
     808                   (state.apAltitude!=oldState.apAltitude or apMasterTurnedOn or
     809                    apAltitudeHoldTurnedOn):
     810                    self._logAPAltitude(logger, timestamp, state)
     811
     812        self._lastLoggedState = state
     813
     814#---------------------------------------------------------------------------------------
     815
    668816class FaultChecker(StateChecker):
    669817    """Base class for checkers that look for faults."""
Note: See TracChangeset for help on using the changeset viewer.