001package jmri.jmrix.sprog.sprognano;
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 an SSPROG DCC SPROG Nano command station via a USB virtual 
012 * serial com port.
013 * <p>
014 * The current implementation only handles the 9,600 baud rate, and does not use
015 * any other options at configuration time.
016 *
017 * @author Andrew Crosland Copyright (C) 2016
018 */
019public class SprogNanoSerialDriverAdapter
020        extends jmri.jmrix.sprog.serialdriver.SerialDriverAdapter {
021
022    public SprogNanoSerialDriverAdapter() {
023        super(SprogMode.OPS);
024        options.put("NumSlots", // NOI18N
025                new Option(Bundle.getMessage("MakeLabel", Bundle.getMessage("NumSlotOptions")), // NOI18N
026                        new String[]{"16", "8", "32", "48", "64"}, true));
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("SprogNanoCSTitle"));
032    }
033    
034    /**
035     * Set up all of the other objects to operate with an Sprog command station
036     * connected to this port.
037     */
038    @Override
039    public void configure() {
040        String slots = getOptionState("NumSlots");
041        try {
042            numSlots = Integer.parseInt(slots);
043        }
044        catch (NumberFormatException e) {
045            log.warn("Could not parse number of slots {}", e.getMessage());
046            numSlots = 16;
047        }
048        
049        super.configure();
050    }
051
052    private final static Logger log = LoggerFactory.getLogger(SprogNanoSerialDriverAdapter.class);
053
054}