use of jmri.jmrix.AbstractStreamPortController in project JMRI by JMRI.
the class ConnectionConfigXml method unpackElement.
@Override
protected void unpackElement(Element shared, Element perNode) {
List<Element> l = shared.getChildren("node");
// Trigger initialization of this Node to reflect these parameters
XBeeConnectionMemo xcm = (XBeeConnectionMemo) adapter.getSystemConnectionMemo();
XBeeTrafficController xtc = (XBeeTrafficController) xcm.getTrafficController();
for (int i = 0; i < l.size(); i++) {
Element n = l.get(i);
byte[] GUID = jmri.util.StringUtil.bytesFromHexString(findParmValue(n, "GUID"));
XBee64BitAddress guid = new XBee64BitAddress(GUID);
byte[] addr = jmri.util.StringUtil.bytesFromHexString(findParmValue(n, "address"));
XBee16BitAddress address = new XBee16BitAddress(addr);
String Identifier = findParmValue(n, "name");
// create the RemoteXBeeDevice for the node.
RemoteXBeeDevice remoteDevice = new RemoteXBeeDevice(xtc.getXBee(), guid, address, Identifier);
// Check to see if the node is a duplicate, if it is, move
// to the next one.
// get a XBeeNode corresponding to this node address if one exists
XBeeNode curNode = (XBeeNode) xtc.getNodeFromXBeeDevice(remoteDevice);
if (curNode != null) {
log.info("Read duplicate node {} from file", remoteDevice);
continue;
}
try {
// and then add it to the network
xtc.getXBee().getNetwork().addRemoteDevice(remoteDevice);
// create node (they register themselves)
XBeeNode node = new XBeeNode(remoteDevice);
String polled = findParmValue(n, "polled");
node.setPoll(polled.equals("yes"));
xtc.registerNode(node);
// if there is a stream port controller stored for this
// node, we need to load that after the node starts running.
// otherwise, the IOStream associated with the node has not
// been configured.
String streamController = findParmValue(n, "StreamController");
if (streamController != null) {
try {
// Class.forName cast is unchecked at this point
@SuppressWarnings("unchecked") java.lang.Class<jmri.jmrix.AbstractStreamPortController> T = (Class<AbstractStreamPortController>) Class.forName(streamController);
node.connectPortController(T);
} catch (java.lang.ClassNotFoundException cnfe) {
log.error("Unable to find class for stream controller : {}", streamController);
}
}
} catch (TimeoutException toe) {
log.error("Timeout adding node {} from configuration file.", remoteDevice);
} catch (XBeeException xbe) {
log.error("Exception adding node {} from configuration file.", remoteDevice);
}
}
}
Aggregations