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 PiSprog3SerialDriverAdapter extends GcSerialDriverAdapter {
021
022    public PiSprog3SerialDriverAdapter() {
023        super("S");
024    }
025
026    /**
027     * Set up all of the other objects to operate with a SPROG Gen 5
028     * connected to this port.
029     */
030    @Override
031    public void configure() {
032
033        // Register the CAN traffic controller being used for this connection
034        // This connection has no actual CAN interface so set a fixed CAN ID
035        TrafficController tc = new MergTrafficController();
036        try {
037            tc.setCanId(127);
038        } catch (Exception e) {
039            log.error("Cannot parse CAN ID - check your preference settings", e);
040            log.error("Now using default CAN ID");
041        }
042
043        this.getSystemConnectionMemo().setTrafficController(tc);
044
045        // Now connect to the traffic controller
046        log.debug("Connecting port");
047        tc.connectPort(this);
048
049        this.getSystemConnectionMemo().setProtocol(getOptionState(option1Name));
050        this.getSystemConnectionMemo().setSubProtocol(ConfigurationManager.SubProtocol.NONE);
051        this.getSystemConnectionMemo().setProgModeSwitch(ConfigurationManager.ProgModeSwitch.EITHER);
052
053        // do central protocol-specific configuration
054        //jmri.jmrix.can.ConfigurationManager.configure(getOptionState(option1Name));
055        this.getSystemConnectionMemo().configureManagers();
056    }
057
058    /**
059     * {@inheritDoc}
060     */
061    @Override
062    public String[] validBaudRates() {
063        return new String[]{Bundle.getMessage("Baud115200")};
064    }
065
066    /**
067     * And the corresponding values.
068     */
069    @Override
070    public int[] validBaudNumbers() {
071        return new int[]{115200};
072    }
073
074    @Override
075    public int defaultBaudIndex() {
076        return 0;
077    }
078
079    private final static Logger log = LoggerFactory.getLogger(PiSprog3SerialDriverAdapter.class);
080
081}