001package jmri.jmrix.dccpp.dccppovertcp;
002
003import jmri.jmrix.dccpp.DCCppCommandStation;
004import jmri.jmrix.dccpp.DCCppInitializationManager;
005import jmri.jmrix.dccpp.DCCppNetworkPortController;
006import jmri.jmrix.dccpp.DCCppSystemConnectionMemo;
007import org.slf4j.Logger;
008import org.slf4j.LoggerFactory;
009
010/**
011 * Implements DCCppPortController for the DCCppOverTcp system network
012 * connection.
013 * <p>
014 * This connects a DCC++ via a telnet connection. Normally controlled by the
015 * DCCppTcpDriverFrame class. Based on LnTcpDriverAdapter.
016 *
017 * @author Bob Jacobsen Copyright (C) 2001, 2002, 2003
018 * @author Alex Shepherd Copyright (C) 2003, 2006
019 * @author Mark Underwood Copyright (C) 2015
020 */
021public class DCCppTcpDriverAdapter extends DCCppNetworkPortController {
022    
023    public DCCppTcpDriverAdapter() {
024        super(new DCCppSystemConnectionMemo());
025        // TODO: Figure out what these options are, and should be.
026        //option2Name = "CommandStation";
027        //option3Name = "TurnoutHandle";
028        //options.put(option2Name, new Option("Command station type:", commandStationNames, false));
029        //options.put(option3Name, new Option("Turnout command handling:", new String[]{"Normal", "Spread", "One Only", "Both"}));
030    }
031    
032    /**
033     * Set up all of the other objects to operate with a DCC++ connected via
034     * this class.
035     */
036    @Override
037    public void configure() {
038        
039        //setCommandStationType(getOptionState(option2Name));
040        //setTurnoutHandling(getOptionState(option3Name));
041        // connect to a packetizing traffic controller
042        DCCppOverTcpPacketizer packets = new DCCppOverTcpPacketizer(new DCCppCommandStation());
043        packets.connectPort(this);
044        
045        // set the traffic controller
046        this.getSystemConnectionMemo().setDCCppTrafficController(packets);
047        // do the common manager config
048        
049        new DCCppInitializationManager(this.getSystemConnectionMemo());
050        
051        // start operation
052        packets.startThreads();
053    }
054    
055    @Override
056    public boolean status() {
057        return opened;
058    }
059    
060    // private control members
061    private boolean opened = false;
062    
063    @Override
064    public void configureOption1(String value) {
065        super.configureOption1(value);
066        log.debug("configureOption1: {}", value);
067        setCommandStationType(value);
068    }
069    
070    @Override
071    public void setOutputBufferEmpty(boolean s) {
072    }
073    
074    @Override
075    public boolean okToSend() { return true; }
076    
077    private final static Logger log = LoggerFactory.getLogger(DCCppTcpDriverAdapter.class);
078
079}