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