001package jmri.jmrix.powerline.cp290; 002 003import java.util.Arrays; 004import jmri.jmrix.powerline.SerialPortController; 005import jmri.jmrix.powerline.SerialTrafficController; 006import org.slf4j.Logger; 007import org.slf4j.LoggerFactory; 008 009/** 010 * Provide access to Powerline devices via a serial com port. 011 * Derived from the Oaktree code. 012 * 013 * @author Bob Jacobsen Copyright (C) 2006, 2007, 2008 014 * @author Ken Cameron, (C) 2009, sensors from poll replies Converted to 015 * multiple connection 016 * @author kcameron Copyright (C) 2011 017 */ 018public class SpecificDriverAdapter extends SerialPortController { 019 020 public SpecificDriverAdapter() { 021 super(new SpecificSystemConnectionMemo()); 022 } 023 024 @Override 025 public String openPort(String portName, String appName) { 026 027 // get and open the primary port 028 currentSerialPort = activatePort(portName, log); 029 if (currentSerialPort == null) { 030 log.error("failed to connect CP290 to {}", portName); 031 return Bundle.getMessage("SerialPortNotFound", portName); 032 } 033 log.info("Connecting CP290 to {} {}", portName, currentSerialPort); 034 035 // try to set it for communication via SerialDriver 036 // find the baud rate value, configure comm options 037 int baud = currentBaudNumber(mBaudRate); 038 setBaudRate(currentSerialPort, baud); 039 configureLeads(currentSerialPort, true, true); 040 setFlowControl(currentSerialPort, FlowControl.NONE); 041 042 // report status 043 reportPortStatus(log, portName); 044 045 opened = true; 046 047 return null; // indicates OK return 048 } 049 050 /** 051 * set up all of the other objects to operate connected to this port 052 */ 053 @Override 054 public void configure() { 055 SerialTrafficController tc = null; 056 // create a CP290 port controller 057 //adaptermemo = new jmri.jmrix.powerline.cm11.SpecificSystemConnectionMemo(); 058 tc = new SpecificTrafficController(this.getSystemConnectionMemo()); 059 060 // connect to the traffic controller 061 this.getSystemConnectionMemo().setTrafficController(tc); 062 tc.setAdapterMemo(this.getSystemConnectionMemo()); 063 this.getSystemConnectionMemo().configureManagers(); 064 tc.connectPort(this); 065 // Configure the form of serial address validation for this connection 066 this.getSystemConnectionMemo().setSerialAddress(new jmri.jmrix.powerline.SerialAddress(this.getSystemConnectionMemo())); 067 } 068 069 /** 070 * {@inheritDoc} 071 */ 072 @Override 073 public String[] validBaudRates() { 074 return Arrays.copyOf(validSpeeds, validSpeeds.length); 075 } 076 077 /** 078 * {@inheritDoc} 079 */ 080 @Override 081 public int[] validBaudNumbers() { 082 return Arrays.copyOf(validSpeedValues, validSpeedValues.length); 083 } 084 085 @Override 086 public boolean status() { 087 return opened; 088 } 089 // private control members 090 091 protected String[] validSpeeds = new String[]{Bundle.getMessage("BaudAutomatic")}; 092 protected int[] validSpeedValues = new int[]{600}; 093 094 @Override 095 public int defaultBaudIndex() { 096 return 0; 097 } 098 099 private final static Logger log = LoggerFactory.getLogger(SpecificDriverAdapter.class); 100 101}