Search in sources :

Example 1 with AbstractStreamPortController

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);
        }
    }
}
Also used : XBee64BitAddress(com.digi.xbee.api.models.XBee64BitAddress) XBeeConnectionMemo(jmri.jmrix.ieee802154.xbee.XBeeConnectionMemo) Element(org.jdom2.Element) RemoteXBeeDevice(com.digi.xbee.api.RemoteXBeeDevice) XBee16BitAddress(com.digi.xbee.api.models.XBee16BitAddress) XBeeException(com.digi.xbee.api.exceptions.XBeeException) XBeeTrafficController(jmri.jmrix.ieee802154.xbee.XBeeTrafficController) AbstractStreamPortController(jmri.jmrix.AbstractStreamPortController) XBeeNode(jmri.jmrix.ieee802154.xbee.XBeeNode) TimeoutException(com.digi.xbee.api.exceptions.TimeoutException)

Aggregations

RemoteXBeeDevice (com.digi.xbee.api.RemoteXBeeDevice)1 TimeoutException (com.digi.xbee.api.exceptions.TimeoutException)1 XBeeException (com.digi.xbee.api.exceptions.XBeeException)1 XBee16BitAddress (com.digi.xbee.api.models.XBee16BitAddress)1 XBee64BitAddress (com.digi.xbee.api.models.XBee64BitAddress)1 AbstractStreamPortController (jmri.jmrix.AbstractStreamPortController)1 XBeeConnectionMemo (jmri.jmrix.ieee802154.xbee.XBeeConnectionMemo)1 XBeeNode (jmri.jmrix.ieee802154.xbee.XBeeNode)1 XBeeTrafficController (jmri.jmrix.ieee802154.xbee.XBeeTrafficController)1 Element (org.jdom2.Element)1