Navigation Menu

Skip to content

Commit

Permalink
catch some fixed prefix length managers XNet
Browse files Browse the repository at this point in the history
  • Loading branch information
silverailscolo committed Apr 30, 2019
1 parent 4b7892a commit 9a47628
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 43 deletions.
2 changes: 1 addition & 1 deletion java/src/jmri/jmrix/dcc/DccTurnoutManager.java
Expand Up @@ -23,7 +23,7 @@ public String getSystemPrefix() {
@Override
public Turnout createNewTurnout(String systemName, String userName) {
Turnout t;
int addr = Integer.parseInt(systemName.substring(2));
int addr = Integer.parseInt(systemName.substring(2)); // fixed length prefix, so (2) is OK here
t = new DccTurnout(addr);
t.setUserName(userName);

Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrix/ecos/EcosSensorManager.java
Expand Up @@ -46,7 +46,7 @@ public String getSystemPrefix() {

@Override
public Sensor createNewSensor(String systemName, String userName) {
//int ports = Integer.parseInt(systemName.substring(2));
//int ports = Integer.parseInt(systemName.substring(getSystemPrefix().length() + 1));
Sensor s = new EcosSensor(systemName, userName);
//s.setUserName(userName);

Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrix/lenz/XNetAddress.java
Expand Up @@ -52,7 +52,7 @@ public static int getBitFromSystemName(String systemName, String prefix) {
if( ( systemName.charAt(prefix.length())=='S' ||
systemName.charAt(prefix.length())=='s' ) &&
curAddress.contains(":")) {
//Address format passed is in the form of encoderAddress:input or T:turnout address
// Address format passed is in the form of encoderAddress:input or T:turnout address
int seperator = curAddress.indexOf(":");
int encoderAddress = Integer.parseInt(curAddress.substring(0, seperator));
int input = Integer.parseInt(curAddress.substring(seperator + 1));
Expand Down
Expand Up @@ -6,7 +6,7 @@

/**
* Provides load and store functionality for configuring XNetTurnoutManagers.
* <P>
* <p>
* Uses the store method from the abstract base class, but provides a load
* method here.
*
Expand Down
@@ -1,6 +1,7 @@
package jmri.jmrix.lenz.hornbyelite;

import jmri.Turnout;
import jmri.jmrix.lenz.XNetAddress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -22,8 +23,14 @@ public EliteXNetTurnoutManager(jmri.jmrix.lenz.XNetTrafficController controller,

@Override
public Turnout createNewTurnout(String systemName, String userName) {
int addr = Integer.parseInt(systemName.substring(2));
Turnout t = new EliteXNetTurnout(prefix, addr, tc);
bitNum
// check if the output bit is available
int bitNum = XNetAddress.getBitFromSystemName(systemName, prefix);
if (bitNum == -1) {
return (null);
}
// create the new Turnout object
Turnout t = new EliteXNetTurnout(prefix, bitNum, tc);
t.setUserName(userName);
return t;
}
Expand Down
3 changes: 1 addition & 2 deletions java/src/jmri/jmrix/ztc/ZTCConnectionTypeList.java
Expand Up @@ -5,11 +5,10 @@

/**
* Returns a list of valid ZTC Connection Types. Note that
* most ZTC Connection types are Lenz (ZTC uses XpressNet )
* most ZTC Connection types are Lenz (ZTC uses XpressNet).
*
* @author Bob Jacobsen Copyright (C) 2010
* @author Kevin Dickerson Copyright (C) 2010
*
*/
@ServiceProvider(service = ConnectionTypeList.class)
public class ZTCConnectionTypeList implements jmri.jmrix.ConnectionTypeList {
Expand Down
8 changes: 4 additions & 4 deletions java/src/jmri/jmrix/ztc/ztc611/ZTC611Adapter.java
Expand Up @@ -47,14 +47,14 @@ public String openPort(String portName, String appName) {
try {
setSerialPort();
} catch (UnsupportedCommOperationException e) {
log.error("Cannot set serial parameters on port " + portName + ": " + e.getMessage());
log.error("Cannot set serial parameters on port {}: {}", portName, e.getMessage());
return "Cannot set serial parameters on port " + portName + ": " + e.getMessage();
}

// set timeout
activeSerialPort.enableReceiveTimeout(10);
log.debug("Serial timeout was observed as: " + activeSerialPort.getReceiveTimeout()
+ " " + activeSerialPort.isReceiveTimeoutEnabled());
log.debug("Serial timeout was observed as: {} {}", activeSerialPort.getReceiveTimeout(),
activeSerialPort.isReceiveTimeoutEnabled());

// get and save stream
serialStream = activeSerialPort.getInputStream();
Expand Down Expand Up @@ -132,7 +132,7 @@ public DataOutputStream getOutputStream() {
try {
return new DataOutputStream(activeSerialPort.getOutputStream());
} catch (IOException e) {
log.error("getOutputStream exception: " + e.getMessage());
log.error("getOutputStream exception: ", e.getMessage());
}
return null;
}
Expand Down
Expand Up @@ -9,12 +9,12 @@
import org.slf4j.LoggerFactory;

/**
* This class performs Command Station dependant initilization for The ZTC
* This class performs Command Station dependant initialization for the ZTC
* ZTC611. It adds the appropriate Managers via the Instance Manager based
* on the Command Station Type.
*
* @author Paul Bender Copyright (C) 2003,2008
*/
* @author Paul Bender Copyright (C) 2003, 2008
*/
public class ZTC611XNetInitializationManager extends AbstractXNetInitializationManager {

public ZTC611XNetInitializationManager(XNetSystemConnectionMemo memo) {
Expand All @@ -23,13 +23,8 @@ public ZTC611XNetInitializationManager(XNetSystemConnectionMemo memo) {

@Override
protected void init() {
if (log.isDebugEnabled()) {
log.debug("Init called");
}

if (log.isDebugEnabled()) {
log.debug("Command Station is ZTC ZTC611 (manually identified).");
}
log.debug("Init called");
log.debug("Command Station is ZTC ZTC611 (manually identified).");

/* First, we load things that should work on all systems */

Expand All @@ -54,9 +49,7 @@ protected void init() {
systemMemo.setSensorManager(new jmri.jmrix.lenz.XNetSensorManager(systemMemo.getXNetTrafficController(), systemMemo.getSystemPrefix()));
jmri.InstanceManager.setSensorManager(systemMemo.getSensorManager());

if (log.isDebugEnabled()) {
log.debug("XpressNet Initialization Complete");
}
log.debug("XpressNet Initialization Complete");
}

private final static Logger log = LoggerFactory.getLogger(ZTC611XNetInitializationManager.class);
Expand Down
18 changes: 7 additions & 11 deletions java/src/jmri/jmrix/ztc/ztc611/ZTC611XNetPacketizer.java
Expand Up @@ -10,12 +10,11 @@
/**
* This is an extention of the XNetPacketizer to handle the device specific
* requirements of the ZTC611.
* <P>
* <p>
* In particular, ZTC611XNetPacketizer adds functions to add and remove the 0xFF
* bytes that appear prior to some messages.
*
* @author Paul Bender Copyright (C) 2006
*
*/
public class ZTC611XNetPacketizer extends XNetPacketizer {

Expand All @@ -26,9 +25,9 @@ public ZTC611XNetPacketizer(jmri.jmrix.lenz.LenzCommandStation pCommandStation)

/**
* Get characters from the input source, and file a message.
* <P>
* <p>
* Returns only when the message is complete.
* <P>
* <p>
* Only used in the Receive thread.
*
* @param msg message to fill
Expand All @@ -38,16 +37,14 @@ public ZTC611XNetPacketizer(jmri.jmrix.lenz.LenzCommandStation pCommandStation)
@Override
protected void loadChars(jmri.jmrix.AbstractMRReply msg, java.io.DataInputStream istream) throws java.io.IOException {
int i;
if (log.isDebugEnabled()) {
log.debug("loading characters from port");
}
log.debug("loading characters from port");
for (i = 0; i < msg.maxSize(); i++) {
byte char1 = readByteProtected(istream);
// This is a test for the ZTC611 device
while ((i == 0) && ((char1 & 0xF0) == 0xF0)) {
if ((char1 & 0xFF) != 0xF0 && (char1 & 0xFF) != 0xF2) {
if (log.isDebugEnabled()) {
log.debug("Filtering 0x" + Integer.toHexString(char1 & 0xFF) + " from stream");
log.debug("Filtering 0x{} from stream", Integer.toHexString(char1 & 0xFF));
}
// toss this byte and read the next one
char1 = readByteProtected(istream);
Expand All @@ -59,11 +56,10 @@ protected void loadChars(jmri.jmrix.AbstractMRReply msg, java.io.DataInputStream
}
}
if (log.isDebugEnabled()) {
log.debug("Accepted Message: " + msg.toString());
log.debug("Accepted Message: {}", msg.toString());
}
}

private final static Logger log = LoggerFactory.getLogger(ZTC611XNetPacketizer.class);
}


}
2 changes: 1 addition & 1 deletion java/src/jmri/jmrix/ztc/ztc611/ZTC611XNetTurnout.java
Expand Up @@ -7,7 +7,7 @@
* connections. See XNetTurnout for further documentation.
*
* @author Paul Bender Copyright (C) 2008,2017
*/
*/
public class ZTC611XNetTurnout extends jmri.jmrix.lenz.XNetTurnout {

public ZTC611XNetTurnout(String prefix, int pNumber, XNetTrafficController tc) { // a human-readable turnout number must be specified!
Expand Down
11 changes: 8 additions & 3 deletions java/src/jmri/jmrix/ztc/ztc611/ZTC611XNetTurnoutManager.java
@@ -1,14 +1,15 @@
package jmri.jmrix.ztc.ztc611;

import jmri.Turnout;
import jmri.jmrix.lenz.XNetAddress;

/**
* Implement turnout manager - Specific to ZTC ZTC611
* <p>
* System names are "XTnnn", where X is the user-configurable system prefix,
* nnn is the turnout number without padding.
*
* @author Paul Bender Copyright (C) 2008,2017
* @author Paul Bender Copyright (C) 2008, 2017
*/
public class ZTC611XNetTurnoutManager extends jmri.jmrix.lenz.XNetTurnoutManager implements jmri.jmrix.lenz.XNetListener {

Expand All @@ -19,8 +20,12 @@ public ZTC611XNetTurnoutManager(jmri.jmrix.lenz.XNetTrafficController controller
// XNet-specific methods
@Override
public Turnout createNewTurnout(String systemName, String userName) {
int addr = Integer.parseInt(systemName.substring(2));
Turnout t = new ZTC611XNetTurnout(prefix, addr, tc);
// check if the output bit is available
int bitNum = XNetAddress.getBitFromSystemName(systemName, prefix);
if (bitNum == -1) {
return (null);
}
Turnout t = new ZTC611XNetTurnout(prefix, bitNum, tc);
t.setUserName(userName);
return t;
}
Expand Down
Expand Up @@ -8,7 +8,7 @@
* Handle XML persistance of layout connections by persistening the
* ZTC611Adapter (and connections). Note this is named as the XML version of a
* ConnectionConfig object, but it's actually persisting the ZTC611Adapter.
* <P>
* <p>
* This class is invoked from jmrix.JmrixConfigPaneXml on write, as that class
* is the one actually registered. Reads are brought here directly via the class
* attribute in the XML.
Expand Down
Expand Up @@ -5,8 +5,9 @@
import org.slf4j.LoggerFactory;

/**
* Provides load and store functionality for configuring XNetTurnoutManagers.
* <P>
* Provides load and store functionality for configuring XNetTurnoutManagers
* and ZTC611 in particular.
* <p>
* Uses the store method from the abstract base class, but provides a load
* method here.
*
Expand Down

0 comments on commit 9a47628

Please sign in to comment.