001package jmri.jmrix.loconet.loconetovertcp;
002
003import jmri.jmrix.loconet.LnNetworkPortController;
004import jmri.jmrix.loconet.LocoNetSystemConnectionMemo;
005import org.slf4j.Logger;
006import org.slf4j.LoggerFactory;
007
008/**
009 * Implements SerialPortAdapter for the LocoNetOverTcp system network
010 * connection.
011 * <p>
012 * This connects a LocoNet via a telnet connection. Normally controlled by the
013 * LnTcpDriverFrame class.
014 *
015 * @author Bob Jacobsen Copyright (C) 2001, 2002, 2003
016 * @author Alex Shepherd Copyright (C) 2003, 2006
017 */
018public class LnTcpDriverAdapter extends LnNetworkPortController {
019
020    public LnTcpDriverAdapter(LocoNetSystemConnectionMemo m) {
021        super(m);
022        option2Name = "CommandStation";
023        option3Name = "TurnoutHandle";
024        options.put(option2Name, new Option(Bundle.getMessage("CommandStationTypeLabel"), commandStationNames, false));
025        options.put(option3Name, new Option(Bundle.getMessage("TurnoutHandling"),
026                new String[]{Bundle.getMessage("HandleNormal"), Bundle.getMessage("HandleSpread"), Bundle.getMessage("HandleOneOnly"), Bundle.getMessage("HandleBoth")})); // I18N
027        options.put("TranspondingPresent", new Option(Bundle.getMessage("TranspondingPresent"),
028                new String[]{Bundle.getMessage("ButtonNo"), Bundle.getMessage("ButtonYes")} )); // NOI18N
029        options.put("InterrogateOnStart", new Option(Bundle.getMessage("InterrogateOnStart"),
030                new String[]{Bundle.getMessage("ButtonYes"), Bundle.getMessage("ButtonNo")} )); // NOI18N
031        options.put("LoconetProtocolAutoDetect", new Option(Bundle.getMessage("LoconetProtocolAutoDetectLabel"),
032                new String[]{Bundle.getMessage("LoconetProtocolAutoDetect"),Bundle.getMessage("ButtonNo")} )); // NOI18N
033
034    }
035
036    public LnTcpDriverAdapter() {
037        this(new LocoNetSystemConnectionMemo());
038    }
039
040    /**
041     * Set up all of the other objects to operate with a LocoNet connected via
042     * this class.
043     */
044    @Override
045    public void configure() {
046
047        setCommandStationType(getOptionState(option2Name));
048        setTurnoutHandling(getOptionState(option3Name));
049        setTranspondingAvailable(getOptionState("TranspondingPresent"));
050        setInterrogateOnStart(getOptionState("InterrogateOnStart"));
051        setLoconetProtocolAutoDetect(getOptionState("LoconetProtocolAutoDetect"));
052
053
054        // connect to a packetizing traffic controller
055        LnOverTcpPacketizer packets = new LnOverTcpPacketizer(this.getSystemConnectionMemo());
056        packets.connectPort(this);
057
058        // create memo
059        this.getSystemConnectionMemo().setLnTrafficController(packets);
060        // do the common manager config
061        this.getSystemConnectionMemo().configureCommandStation(commandStationType,
062                mTurnoutNoRetry, mTurnoutExtraSpace, mTranspondingAvailable, mInterrogateAtStart, mLoconetProtocolAutoDetect);
063        this.getSystemConnectionMemo().configureManagers();
064
065        // start operation
066        packets.startThreads();
067    }
068
069    @Override
070    public boolean status() {
071        return opened;
072    }
073
074    // private control members
075    private final boolean opened = false;
076
077    @Override
078    public void configureOption1(String value) {
079        super.configureOption1(value);
080        log.debug("configureOption1: {}", value);
081        setCommandStationType(value);
082    }
083
084    private final static Logger log = LoggerFactory.getLogger(LnTcpDriverAdapter.class);
085
086}