001package jmri.jmrix.can.adapters.gridconnect.can2usbino.serialdriver;
002
003import jmri.jmrix.AbstractMRMessage;
004import jmri.jmrix.can.CanMessage;
005import jmri.jmrix.can.adapters.gridconnect.GcSerialDriverAdapter;
006import jmri.jmrix.can.adapters.gridconnect.GcTrafficController;
007import jmri.jmrix.can.adapters.gridconnect.can2usbino.GridConnectDoubledMessage;
008
009/**
010 * Implements SerialPortAdapter for GridConnect adapters.
011 * <p>
012 * This connects a CAN-USB CAN adapter via a serial com port. Normally
013 * controlled by the SerialDriverFrame class.
014 *
015 * This asserts XON/XOFF flow control.
016 *
017 * @author Andrew Crosland Copyright (C) 2008
018 * @author Bob Jacobsen Copyright (C) 2009, 2012
019 */
020public class SerialDriverAdapter extends GcSerialDriverAdapter {
021
022    public SerialDriverAdapter() {
023        super();
024        mBaudRate = Bundle.getMessage("Baud230400");
025    }
026
027    @Override
028    public String openPort(String portName, String appName) {
029        var retval = super.openPort(portName, appName);
030        
031        setFlowControl(currentSerialPort, FlowControl.XONXOFF);
032
033        return retval;
034    }
035
036    /**
037     * {@inheritDoc}
038     */
039    @Override
040    public String[] validBaudRates() {
041        return new String[]{Bundle.getMessage("Baud57600"), Bundle.getMessage("Baud115200"),
042                Bundle.getMessage("Baud230400"), Bundle.getMessage("Baud250000"),
043                Bundle.getMessage("Baud288000"), Bundle.getMessage("Baud333333"),
044                Bundle.getMessage("Baud460800")};
045    }
046
047    /**
048     * And the corresponding values.
049     */
050    @Override
051    public int[] validBaudNumbers() {
052        return new int[]{57600, 115200, 230400, 250000, 288000, 333333, 460800};
053    }
054
055    @Override
056    public int defaultBaudIndex() {
057        return 2;
058    }
059
060    @Override
061    protected GcTrafficController makeGcTrafficController() {
062        return new GcTrafficController() {
063            @Override
064            public AbstractMRMessage encodeForHardware(CanMessage m) {
065                //log.debug("Encoding for hardware");
066                return new GridConnectDoubledMessage(m);
067            }
068        };
069    }
070
071    // private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(SerialDriverAdapter.class);
072
073}