001package jmri.jmrix.loconet.uhlenbrock.usb_63120; 002 003import jmri.jmrix.loconet.LnCommandStationType; 004import jmri.jmrix.loconet.locobuffer.LocoBufferAdapter; 005import java.util.Arrays; 006 007/** 008 * Extend the code in jmri.jmrix.loconet.locobuffer so that it operates 009 * correctly with the Uhlenbrock USB-adapter part no 63120. 010 * Status: EXPERIMENTAL - as added to title until confirmed by hardware users in 4.21.4 011 * 012 * Specs: 013 * PC - LocoNet Communication (from Uhlenbrock 63120 datasheet) 014 * Communication between PC and LocoNet must be according to the following schema: 015 * - Send message over USB and then wait to receive the sent message again, before a new message is sent. 016 * Process other messages received during the waiting period. 017 * - LACK (Long Acknowledge Message) treatment: If a message can be followed by a LACK (see LocoNet 018 * documentation, for messages which can be followed by a LACK). A flag must be set by COM Port after 019 * the send and receive procedure. If this flag is set and the next message received is a LACK message 020 * then it must be processed because it is a response to the sent message. 021 * If the next message received is not a LACK then the set flag is reset. This ensures that a LACK is 022 * not assigned to a wrong message. 023 * - Evaluate and process Received messages. 024 * 025 * @author Egbert Broerse Copyright (C) 2020 026 */ 027public class UsbUhlenbrock63120Adapter extends LocoBufferAdapter { 028 029 public UsbUhlenbrock63120Adapter() { 030 super(); 031 032 validSpeeds = new String[]{Bundle.getMessage("Baud19200"), Bundle.getMessage("Baud38400"), 033 Bundle.getMessage("Baud57600"), Bundle.getMessage("Baud115200")}; 034 validSpeedValues = new int[]{19200, 38400, 57600, 115200}; 035 configureBaudRate(validSpeeds[3]); // Set the default baud rate (localized) 036 setCommandStationType(LnCommandStationType.getByName(LnCommandStationType.COMMAND_STATION_IBX_TYPE_1.getName())); 037 // start off with Uhlenbrock IB--I CS product selected 038 } 039 040 /** 041 * {@inheritDoc} 042 */ 043 @Override 044 public String[] validBaudRates() { 045 return Arrays.copyOf(validSpeeds, validSpeeds.length); 046 } 047 048 /** 049 * {@inheritDoc} 050 */ 051 @Override 052 public int[] validBaudNumbers() { 053 return Arrays.copyOf(validSpeedValues, validSpeedValues.length); 054 } 055 056 @Override 057 public int defaultBaudIndex() { 058 return 3; 059 } 060 061 //private final static Logger log = LoggerFactory.getLogger(UsbUhlenbrock63120Adapter.class); 062 063}