001package jmri.jmrix.loconet;
002
003import javax.annotation.Nonnull;
004
005/**
006 * Manage the LocoNet-specific Sensor implementation.
007 * System names are "LSnnn", where L is the user configurable system prefix,
008 * nnn is the sensor number without padding.  Valid sensor numbers are in the
009 * range 1 to 2048, inclusive.
010 *
011 * Provides a mechanism to perform the LocoNet "Interrogate" process in order
012 * to get initial values from those LocoNet devices which support the process
013 * and provide LocoNet Sensor (and/or LocoNet Turnout) functionality.
014 *
015 * @author Bob Jacobsen      Copyright (C) 2001
016 * @author B. Milhaupt       Copyright (C) 2020
017 * @author Daniel Bergqvist  Copyright (C) 2021
018 */
019public class LnStringIOManager extends jmri.managers.AbstractStringIOManager implements LocoNetListener {
020
021    protected final LnTrafficController tc;
022
023    public LnStringIOManager(LocoNetSystemConnectionMemo memo) {
024        super(memo);
025        tc = memo.getLnTrafficController();
026        if (tc == null) {
027            log.error("LnStringIOManager Created, yet there is no Traffic Controller");
028//            return;   // The return statement is not needed now since we don't register a listener.
029        }
030
031        // Don't register a listener now. But keep this line in case it's
032        // neede later.
033        // ctor has to register for LocoNet events
034//        tc.addLocoNetListener(~0, this);
035    }
036
037    /** {@inheritDoc} */
038    @Override
039    @Nonnull
040    public LocoNetSystemConnectionMemo getMemo() {
041        return (LocoNetSystemConnectionMemo) memo;
042    }
043
044    // to free resources when no longer used
045    /** {@inheritDoc} */
046    @Override
047    public void dispose() {
048        tc.removeLocoNetListener(~0, this);
049        super.dispose();
050    }
051
052    // LocoNet-specific methods
053
054    /**
055     * Listen for sensor messages, creating them as needed.
056     * @param l LocoNet message to be examined
057     */
058    @Override
059    public void message(LocoNetMessage l) {
060//        switch (l.getOpCode()) {
061//            case LnConstants.OPC_INPUT_REP:                /* page 9 of LocoNet PE */
062//                break;
063//            //$FALL-THROUGH$
064//            default:  // here we didn't find an interesting command
065//                return;
066//        }
067        // reach here for LocoNet sensor input command; make sure we know about this one
068    }
069
070    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LnStringIOManager.class);
071
072}