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.setLoconetUpdateSlotOnMessageCreation(Bundle.getMessage("ButtonYes").equals(getOptionState("LoconetUpdateSlotOnMessageCreation")));
042        packets.connectPort(this);
043
044        // create memo
045        this.getSystemConnectionMemo().setLnTrafficController(packets);
046        // do the common manager config
047        this.getSystemConnectionMemo().configureCommandStation(commandStationType,
048                mTurnoutNoRetry, mTurnoutExtraSpace, mTranspondingAvailable, mInterrogateAtStart ,false);
049        this.getSystemConnectionMemo().configureManagers();
050
051        // start operation
052        packets.startThreads();
053    }
054
055    /**
056     * {@inheritDoc}
057     */
058    @Override
059    public String[] validBaudRates() {
060        return Arrays.copyOf(validSpeeds, validSpeeds.length);
061    }
062
063    /**
064     * {@inheritDoc}
065     */
066    @Override
067    public int[] validBaudNumbers() {
068        return Arrays.copyOf(validSpeedValues, validSpeedValues.length);
069    }
070
071    /**
072     * Rephrase option 1, so that it doesn't talk about LocoBuffer.
073     * @return human readable string, TypeSerial.
074     */
075    public String option1Name() {
076        return Bundle.getMessage("XconnectionUsesLabel", Bundle.getMessage("TypeSerial"));
077    }
078
079    /**
080     * Provide just one valid command station value.
081     * @return single value array with name of COMMAND_STATION_IBX_TYPE_1 .
082     */
083    public String[] commandStationOptions() {
084        String[] retval = {
085            LnCommandStationType.COMMAND_STATION_IBX_TYPE_1.getName()
086        };
087        return retval;
088    }
089
090}