001package jmri.jmrix.loconet.uhlenbrock; 002 003import java.util.Arrays; 004import jmri.jmrix.loconet.LnCommandStationType; 005import jmri.jmrix.loconet.locobuffer.LocoBufferAdapter; 006import org.slf4j.Logger; 007import org.slf4j.LoggerFactory; 008 009/** 010 * Update the code in jmri.jmrix.loconet.locobuffer so that it operates 011 * correctly with the IC-COM and Intellibox II on-board USB port. Note that the 012 * jmri.jmrix.loconet.intellibox package is for the first version of Uhlenbrock 013 * Intellibox, whereas this package (jmri.jmrix.loconet.uhlenbrock) is for the 014 * Intellibox II and the IB-COM. 015 * <p> 016 * Since this is by definition connected to an Intellibox II or IB-COM, the 017 * command station prompt is suppressed. 018 * 019 * @author Alex Shepherd Copyright (C) 2004 020 * @author Bob Jacobsen Copyright (C) 2005, 2010 021 */ 022public class UhlenbrockAdapter extends LocoBufferAdapter { 023 024 public UhlenbrockAdapter() { 025 super(new UhlenbrockSystemConnectionMemo()); 026 027 // define command station options 028 options.remove(option2Name); 029 options.put(option2Name, new Option(Bundle.getMessage("CommandStationTypeLabel"), commandStationOptions(), false)); 030 options.put("InterrogateOnStart", new Option(Bundle.getMessage("InterrogateOnStart"), 031 new String[]{Bundle.getMessage("ButtonYes"), Bundle.getMessage("ButtonNo")} )); // NOI18N 032 033 validSpeeds = new String[]{Bundle.getMessage("Baud19200"), Bundle.getMessage("Baud38400"), 034 Bundle.getMessage("Baud57600"), Bundle.getMessage("Baud115200")}; 035 validSpeedValues = new int[]{19200, 38400, 57600, 115200}; 036 configureBaudRate(validSpeeds[3]); // Set the default baud rate (localized) 037 } 038 039 /** 040 * Set up all of the other objects to operate with an IB-II connected to 041 * this port. 042 */ 043 @Override 044 public void configure() { 045 046 setCommandStationType(getOptionState(option2Name)); 047 setTurnoutHandling(getOptionState(option3Name)); 048 setInterrogateOnStart(getOptionState("InterrogateOnStart")); 049 // connect to a packetizing traffic controller 050 UhlenbrockPacketizer packets = new UhlenbrockPacketizer(this.getSystemConnectionMemo()); 051 packets.connectPort(this); 052 053 // create memo 054 this.getSystemConnectionMemo().setLnTrafficController(packets); 055 // do the common manager config 056 this.getSystemConnectionMemo().configureCommandStation(commandStationType, 057 mTurnoutNoRetry, mTurnoutExtraSpace, mTranspondingAvailable, mInterrogateAtStart, false); //never Xp slots 058 this.getSystemConnectionMemo().configureManagers(); 059 060 // start operation 061 packets.startThreads(); 062 } 063 064 /** 065 * {@inheritDoc} 066 */ 067 @Override 068 public String[] validBaudRates() { 069 return Arrays.copyOf(validSpeeds, validSpeeds.length); 070 } 071 072 /** 073 * {@inheritDoc} 074 */ 075 @Override 076 public int[] validBaudNumbers() { 077 return Arrays.copyOf(validSpeedValues, validSpeedValues.length); 078 } 079 080 @Override 081 public int defaultBaudIndex() { 082 return 3; 083 } 084 085 @Override 086 public boolean okToSend() { 087 return true; 088 } 089 090 @Override 091 protected void reportOpen(String portName) { 092 log.info("Connecting Uhlenbrock via {} {}", portName, currentSerialPort); 093 } 094 095 /** 096 * Always off flow control 097 */ 098 @Override 099 protected void setLocalFlowControl() { 100 FlowControl flow = FlowControl.NONE; 101 setFlowControl(currentSerialPort, flow); 102 } 103 104 /** 105 * Provide just one valid command station value. 106 * @return array with single entry, name of COMMAND_STATION_IBX_TYPE_2 . 107 */ 108 public String[] commandStationOptions() { 109 String[] retval = { 110 LnCommandStationType.COMMAND_STATION_IBX_TYPE_2.getName() 111 }; 112 return retval; 113 } 114 115 private final static Logger log = LoggerFactory.getLogger(UhlenbrockAdapter.class); 116 117}