001package jmri.jmrix.can.adapters.gridconnect.sproggen5.serialdriver;
002
003import jmri.jmrix.can.ConfigurationManager;
004import jmri.jmrix.can.ConfigurationManager.ProgModeSwitch;
005import jmri.jmrix.can.TrafficController;
006import jmri.jmrix.can.adapters.gridconnect.GcSerialDriverAdapter;
007import jmri.jmrix.can.adapters.gridconnect.canrs.MergTrafficController;
008
009/**
010 * Implements SerialPortAdapter for SPROG Generation 5.
011 * <p>
012 * This connects a SPROG Generation 5 via a serial com port (real or virtual).
013 * Normally controlled by the SerialDriverFrame class.
014 *
015 * @author Andrew Crosland Copyright (C) 2008
016 * @author Bob Jacobsen Copyright (C) 2009
017 * @author Andrew Crosland Copyright (C) 2019, 2021
018 */
019public class Sprog3PlusSerialDriverAdapter extends GcSerialDriverAdapter {
020
021    public Sprog3PlusSerialDriverAdapter() {
022        super("S", FlowControl.RTSCTS);  // enable RTS/CTS flow control
023        option2Name = "CANID";
024        options.put(option2Name, new Option(Bundle.getMessage("JMRICANID"), new String[]{"127", "126", "125", "124", "123", "122", "121", "120"}));
025        _progMode = ConfigurationManager.ProgModeSwitch.SPROG3PLUS;
026    }
027
028    protected ProgModeSwitch _progMode;
029
030    /**
031     * Set up all of the other objects to operate with a SPROG Gen 5
032     * connected to this port.
033     */
034    @Override
035    public void configure() {
036
037        // Register the CAN traffic controller being used for this connection
038        TrafficController tc = new MergTrafficController();
039        try {
040            tc.setCanId(Integer.parseInt(getOptionState(option2Name)));
041        } catch (Exception e) {
042            log.error("Cannot parse CAN ID - check your preference settings", e);
043            log.error("Now using default CAN ID");
044        }
045
046        this.getSystemConnectionMemo().setTrafficController(tc);
047
048        // Now connect to the traffic controller
049        log.debug("Connecting port");
050        tc.connectPort(this);
051
052        this.getSystemConnectionMemo().setProtocol(getOptionState(option1Name));
053        this.getSystemConnectionMemo().setSubProtocol(ConfigurationManager.SubProtocol.CBUS);
054        this.getSystemConnectionMemo().setProgModeSwitch(_progMode);
055        this.getSystemConnectionMemo().setSupportsCVHints(true);
056        this.getSystemConnectionMemo().setPowerOnArst(false);
057
058        // do central protocol-specific configuration
059        //jmri.jmrix.can.ConfigurationManager.configure(getOptionState(option1Name));
060        this.getSystemConnectionMemo().configureManagers();
061    }
062
063    /**
064     * {@inheritDoc}
065     */
066    @Override
067    public String[] validBaudRates() {
068        return new String[]{Bundle.getMessage("Baud460800")};
069    }
070
071    /**
072     * And the corresponding values.
073     */
074    @Override
075    public int[] validBaudNumbers() {
076        return new int[]{460800};
077    }
078
079    @Override
080    public int defaultBaudIndex() {
081        return 0;
082    }
083
084    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(Sprog3PlusSerialDriverAdapter.class);
085
086}