001package jmri.jmrix.can.adapters.loopback; 002 003import java.io.DataInputStream; 004import java.io.DataOutputStream; 005 006import jmri.jmrix.AbstractSerialPortController; 007import jmri.jmrix.can.CanSystemConnectionMemo; 008 009/** 010 * Loopback connection to simulate a CAN link. 011 * 012 * @author Bob Jacobsen Copyright (C) 2008, 2010 013 */ 014public class Port extends AbstractSerialPortController { 015 016 public Port() { 017 super(new jmri.jmrix.can.CanSystemConnectionMemo()); 018 option1Name = "Protocol"; // NOI18N 019 options.put(option1Name, new Option(Bundle.getMessage("ConnectionProtocol"), jmri.jmrix.can.ConfigurationManager.getSystemOptions())); 020 mPort = "(none)"; // is hidden from user in connection config UI 021 } 022 023 @Override 024 public void configure() { 025 026 // register the CAN traffic controller being used for this connection 027 this.getSystemConnectionMemo().setTrafficController(new LoopbackTrafficController()); 028 029 // do central protocol-specific configuration 030 this.getSystemConnectionMemo().setProtocol(getOptionState(option1Name)); 031 032 this.getSystemConnectionMemo().configureManagers(); 033 034 } 035 036 // check that this object is ready to operate 037 @Override 038 public boolean status() { 039 return true; 040 } 041 042 ////////////// 043 // not used // 044 ////////////// 045 // Streams not used in simulations 046 @Override 047 public DataInputStream getInputStream() { 048 return null; 049 } 050 051 @Override 052 public DataOutputStream getOutputStream() { 053 return null; 054 } 055 056 /** 057 * {@inheritDoc} 058 */ 059 @Override 060 public String[] validBaudRates() { 061 return new String[]{"None"}; 062 } // is hidden from user in connection config UI 063 064 /** 065 * {@inheritDoc} 066 */ 067 @Override 068 public int[] validBaudNumbers() { 069 return new int[]{0}; // array length must match that of validBaudRates 070 } 071 072 @Override 073 public String openPort(String portName, String appName) { 074 return "invalid request"; 075 } 076 077 @Override 078 public java.util.Vector<String> getPortNames() { 079 java.util.Vector<String> v = new java.util.Vector<>(); 080 v.addElement(Bundle.getMessage("none")); 081 return v; 082 } 083 084 @Override 085 public CanSystemConnectionMemo getSystemConnectionMemo() { 086 return (CanSystemConnectionMemo) super.getSystemConnectionMemo(); 087 } 088 089}