001package jmri.jmrix.loconet.pr2;
002
003import jmri.jmrix.loconet.locobuffer.LocoBufferAdapter;
004import org.slf4j.Logger;
005import org.slf4j.LoggerFactory;
006
007/**
008 * Update the code in jmri.jmrix.loconet.locobuffer so that it refers to the
009 * switch settings on the new Digitrax PR2
010 *
011 * @author Bob Jacobsen Copyright (C) 2004, 2005, 2006
012 */
013public class PR2Adapter extends LocoBufferAdapter {
014
015    public PR2Adapter() {
016        super(new PR2SystemConnectionMemo());
017
018        options.remove(option2Name);
019        options.put(option2Name, new Option(Bundle.getMessage("CommandStationTypeLabel"), commandStationOptions(), false));
020    }
021
022    @Override
023    protected void reportOpen(String portName) {
024        log.info("Connecting PR2 via {} {}", portName, currentSerialPort);
025    }
026
027    /**
028     * Set up all of the other objects to operate with a PR2 connected to this
029     * port. This overrides the version in loconet.locobuffer, but it has to
030     * duplicate much of the functionality there, so the code is basically
031     * copied.
032     */
033    @Override
034    public void configure() {
035
036        setCommandStationType(getOptionState(option2Name));
037        setTurnoutHandling(getOptionState(option3Name));
038
039        // connect to a packetizing traffic controller
040        // that does echoing
041        jmri.jmrix.loconet.pr2.LnPr2Packetizer packets = new jmri.jmrix.loconet.pr2.LnPr2Packetizer();
042        packets.setLoconetUpdateSlotOnMessageCreation(Bundle.getMessage("ButtonYes").equals(getOptionState("LoconetUpdateSlotOnMessageCreation")));
043        packets.connectPort(this);
044
045        // create memo
046        this.getSystemConnectionMemo().setLnTrafficController(packets);
047        // do the common manager config
048        this.getSystemConnectionMemo().configureCommandStation(commandStationType,
049                mTurnoutNoRetry, mTurnoutExtraSpace, mTranspondingAvailable, mInterrogateAtStart, mLoconetProtocolAutoDetect);
050        this.getSystemConnectionMemo().configureManagers();
051
052        // start operation
053        packets.startThreads();
054    }
055
056    /**
057     * {@inheritDoc}
058     */
059    @Override
060    public String[] validBaudRates() {
061        return new String[]{"57,600 baud"}; // NOI18N
062    }
063
064    /**
065     * {@inheritDoc}
066     */
067    @Override
068    public int[] validBaudNumbers() {
069        return new int[]{57600};
070    }
071
072    @Override
073    public int defaultBaudIndex() {
074        return 0;
075    }
076
077    // Option 1 does flow control, inherited from LocoBufferAdapter
078
079    /**
080     * The PR2 has one mode
081     * @return a String[] containing appropriate options
082     */
083    public String[] commandStationOptions() {
084        return new String[]{jmri.jmrix.loconet.LnCommandStationType.COMMAND_STATION_PR2_ALONE.getName()};
085    }
086
087    private static final Logger log = LoggerFactory.getLogger(PR2Adapter.class);
088}