001package jmri.jmrix.cmri.serial;
002
003import jmri.implementation.AbstractSensor;
004import jmri.jmrix.cmri.CMRISystemConnectionMemo;
005
006import javax.annotation.Nonnull;
007import javax.annotation.CheckReturnValue;
008
009/**
010 * Extend jmri.AbstractSensor for C/MRI serial systems
011 *
012 * @author Bob Jacobsen Copyright (C) 2003
013 */
014public class SerialSensor extends AbstractSensor {
015
016    public SerialSensor(String systemName) {
017        super(systemName);
018        _knownState = UNKNOWN;
019    }
020
021    public SerialSensor(String systemName, String userName) {
022        super(systemName, userName);
023        _knownState = UNKNOWN;
024    }
025
026    // preserve the last state seen when polling the layout
027    // Filled from SerialNode.markChanges in response to a poll reply
028    int lastStateFromLayout = UNKNOWN;
029    
030    /**
031     * Request an update on status.
032     * <p>
033     * Since status is continually being updated, this isn't active now.
034     * Eventually, we may want to have this move the related AIU to the top of
035     * the polling queue.
036     */
037    @Override
038    public void requestUpdateFromLayout() {
039        try {
040            setKnownState(lastStateFromLayout);
041        } catch (jmri.JmriException e) {
042            // should not happen, so log as error
043            log.error("Exception while setting state", e);
044        }
045    }
046
047    /**
048     * {@inheritDoc} 
049     * 
050     * Sorts by node number and then by bit
051     */
052    @CheckReturnValue
053    @Override
054    public int compareSystemNameSuffix(@Nonnull String suffix1, @Nonnull String suffix2, @Nonnull jmri.NamedBean n) {
055        return CMRISystemConnectionMemo.compareSystemNameSuffix(suffix1, suffix2);
056    }
057
058    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(SerialSensor.class);
059}