001package jmri.jmrix.loconet.Intellibox;
002
003import java.util.Arrays;
004import jmri.jmrix.loconet.LnCommandStationType;
005import jmri.jmrix.loconet.locobuffer.LocoBufferAdapter;
006
007/**
008 * Update the code in jmri.jmrix.loconet.locobuffer so that it operates
009 * correctly with the Intellibox on-board serial port.
010 * <p>
011 * Since this is by definition connected to an Intellibox, the command station
012 * prompt has limited choices.
013 *
014 * @author Alex Shepherd Copyright (C) 2004
015 * @author Bob Jacobsen Copyright (C) 2005, 2010
016 */
017public class IntelliboxAdapter extends LocoBufferAdapter {
018
019    public IntelliboxAdapter() {
020        super();
021
022        // define command station options
023        options.remove(option2Name);
024        options.put(option2Name, new Option(Bundle.getMessage("CommandStationTypeLabel"), commandStationOptions(), false));
025
026        validSpeeds = new String[]{Bundle.getMessage("Baud19200"), Bundle.getMessage("Baud38400"), Bundle.getMessage("Baud115200")};
027        validSpeedValues = new int[]{19200, 38400, 115200};
028    }
029
030    /**
031     * Set up all of the other objects to operate with a LocoBuffer connected to
032     * this port.
033     */
034    @Override
035    public void configure() {
036
037        setCommandStationType(getOptionState(option2Name));
038        setTurnoutHandling(getOptionState(option3Name));
039        // connect to a packetizing traffic controller
040        IBLnPacketizer packets = new IBLnPacketizer();
041        packets.connectPort(this);
042
043        // create memo
044        this.getSystemConnectionMemo().setLnTrafficController(packets);
045        // do the common manager config
046        this.getSystemConnectionMemo().configureCommandStation(commandStationType,
047                mTurnoutNoRetry, mTurnoutExtraSpace, mTranspondingAvailable, mInterrogateAtStart ,false);
048        this.getSystemConnectionMemo().configureManagers();
049
050        // start operation
051        packets.startThreads();
052    }
053
054    /**
055     * {@inheritDoc}
056     */
057    @Override
058    public String[] validBaudRates() {
059        return Arrays.copyOf(validSpeeds, validSpeeds.length);
060    }
061
062    /**
063     * {@inheritDoc}
064     */
065    @Override
066    public int[] validBaudNumbers() {
067        return Arrays.copyOf(validSpeedValues, validSpeedValues.length);
068    }
069
070    /**
071     * Rephrase option 1, so that it doesn't talk about LocoBuffer.
072     * @return human readable string, TypeSerial.
073     */
074    public String option1Name() {
075        return Bundle.getMessage("XconnectionUsesLabel", Bundle.getMessage("TypeSerial"));
076    }
077
078    /**
079     * Provide just one valid command station value.
080     * @return single value array with name of COMMAND_STATION_IBX_TYPE_1 .
081     */
082    public String[] commandStationOptions() {
083        String[] retval = {
084            LnCommandStationType.COMMAND_STATION_IBX_TYPE_1.getName()
085        };
086        return retval;
087    }
088
089}