001package jmri.jmrix.sprog.pi.pisprogonecs;
002
003import jmri.jmrix.sprog.SprogConstants.SprogMode;
004
005import org.slf4j.Logger;
006import org.slf4j.LoggerFactory;
007
008/**
009 * Implements SerialPortAdapter for the Sprog system.
010 * <p>
011 * This connects a Pi-SPROG One command station via a serial com port.
012 * <p>
013 * The current implementation only handles the 115,200 baud rate, and does not use
014 * any other options at configuration time.
015 *
016 * @author Andrew Crosland Copyright (C) 2016
017 */
018public class PiSprogOneCSSerialDriverAdapter
019        extends jmri.jmrix.sprog.serialdriver.SerialDriverAdapter {
020
021    public PiSprogOneCSSerialDriverAdapter() {
022        super(SprogMode.OPS, 115200);
023        options.put("NumSlots", // NOI18N
024                new Option(Bundle.getMessage("MakeLabel", Bundle.getMessage("NumSlotOptions")), // NOI18N
025                        new String[]{"16", "8", "32", "48", "64"}, true));
026
027        options.put("TrackPowerState", new Option(Bundle.getMessage("OptionTrackPowerLabel"),
028                new String[]{Bundle.getMessage("PowerStateOff"), Bundle.getMessage("PowerStateOn")},
029                true)); // first element (TrackPowerState) NOI18N
030        //Set the username to match name, once refactored to handle multiple connections or user setable names/prefixes then this can be removed
031        this.getSystemConnectionMemo().setUserName(Bundle.getMessage("PiSprog1CSTitle"));
032    }
033
034    /**
035     * {@inheritDoc}
036     * Currently only 115,200 bps
037     */
038    @Override
039    public String[] validBaudRates() {
040        return new String[]{"115,200 bps"};
041    }
042
043    /**
044     * {@inheritDoc}
045     */
046    @Override
047    public int[] validBaudNumbers() {
048        return new int[]{115200};
049    }
050    
051    /**
052     * Set up all of the other objects to operate with an Sprog command station
053     * connected to this port.
054     */
055    @Override
056    public void configure() {
057        String slots = getOptionState("NumSlots");
058        try {
059            numSlots = Integer.parseInt(slots);
060        }
061        catch (NumberFormatException e) {
062            log.warn("Could not parse number of slots {}", e.getMessage() );
063            numSlots = 16;
064        }
065        
066        super.configure();
067    }
068
069    private final static Logger log = LoggerFactory.getLogger(PiSprogOneCSSerialDriverAdapter.class);
070
071}