use of jmri.jmrix.ieee802154.xbee.XBeeNode in project JMRI by JMRI.
the class ConnectionConfigXml method extendElement.
/**
* Write out the SerialNode objects too
*
* @param e Element being extended
*/
@Override
protected void extendElement(Element e) {
XBeeConnectionMemo xcm;
XBeeTrafficController xtc;
try {
xcm = (XBeeConnectionMemo) adapter.getSystemConnectionMemo();
xtc = (XBeeTrafficController) xcm.getTrafficController();
} catch (NullPointerException npe) {
// The adapter doesn't have a memo, so no nodes can be defined.
if (log.isDebugEnabled()) {
log.debug("No memo defined; no nodes to save.");
}
return;
}
try {
XBeeNode node = (XBeeNode) xtc.getNode(0);
int index = 1;
while (node != null) {
// add node as an element
Element n = new Element("node");
n.setAttribute("name", "" + node.getNodeAddress());
e.addContent(n);
// add parameters to the node as needed
n.addContent(makeParameter("address", "" + jmri.util.StringUtil.hexStringFromBytes(node.getUserAddress())));
n.addContent(makeParameter("PAN", "" + jmri.util.StringUtil.hexStringFromBytes(node.getPANAddress())));
n.addContent(makeParameter("GUID", "" + jmri.util.StringUtil.hexStringFromBytes(node.getGlobalAddress())));
n.addContent(makeParameter("name", node.getIdentifier()));
n.addContent(makeParameter("polled", node.getPoll() ? "yes" : "no"));
jmri.jmrix.AbstractStreamPortController pc = null;
if ((pc = node.getPortController()) != null) {
n.addContent(makeParameter("StreamController", pc.getClass().getName()));
}
// look for the next node
node = (XBeeNode) xtc.getNode(index);
index++;
}
} catch (java.lang.NullPointerException npe2) {
// no nodes defined.
return;
}
}
use of jmri.jmrix.ieee802154.xbee.XBeeNode in project JMRI by JMRI.
the class AddNodeFrame method addButtonActionPerformed.
/**
* Method to handle add button
*/
@Override
public void addButtonActionPerformed() {
if (nodeAddr64Field.getText().equals("") && nodeAddrField.getText().equals("")) {
// no address, just return.
return;
}
// Check that a node with this address does not exist
// if the 64 bit address field is blank, use the "Unknown" address".
XBee64BitAddress guid;
if (!(nodeAddr64Field.getText().equals(""))) {
byte[] GUID = jmri.util.StringUtil.bytesFromHexString(nodeAddr64Field.getText());
guid = new XBee64BitAddress(GUID);
} else {
guid = XBee64BitAddress.UNKNOWN_ADDRESS;
}
// if the 16 bit address field is blank, use the "Unknown" address".
XBee16BitAddress address;
if (!(nodeAddrField.getText().equals(""))) {
byte[] addr = jmri.util.StringUtil.bytesFromHexString(nodeAddrField.getText());
address = new XBee16BitAddress(addr);
} else {
address = XBee16BitAddress.UNKNOWN_ADDRESS;
}
String Identifier = nodeIdentifierField.getText();
// create the RemoteXBeeDevice for the node.
RemoteXBeeDevice remoteDevice = new RemoteXBeeDevice(xtc.getXBee(), guid, address, Identifier);
// get a XBeeNode corresponding to this node address if one exists
curNode = (XBeeNode) xtc.getNodeFromXBeeDevice(remoteDevice);
if (curNode != null) {
javax.swing.JOptionPane.showMessageDialog(this, Bundle.getMessage("Error1", remoteDevice), Bundle.getMessage("AddNodeErrorTitle"), JOptionPane.ERROR_MESSAGE);
return;
}
try {
// and then add it to the network
xtc.getXBee().getNetwork().addRemoteDevice(remoteDevice);
// create node (they register themselves)
XBeeNode node = new XBeeNode(remoteDevice);
xtc.registerNode(node);
parent.nodeListChanged();
} catch (TimeoutException toe) {
log.error("Timeout adding node {}.", remoteDevice);
javax.swing.JOptionPane.showMessageDialog(this, Bundle.getMessage("Error3"), Bundle.getMessage("AddNodeErrorTitle"), JOptionPane.ERROR_MESSAGE);
log.error("Error creating XBee Node, constructor returned null");
return;
} catch (XBeeException xbe) {
log.error("Exception adding node {}.", remoteDevice);
javax.swing.JOptionPane.showMessageDialog(this, Bundle.getMessage("Error3"), Bundle.getMessage("AddNodeErrorTitle"), JOptionPane.ERROR_MESSAGE);
log.error("Error creating XBee Node, constructor returned null");
return;
}
this.dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
}
use of jmri.jmrix.ieee802154.xbee.XBeeNode in project JMRI by JMRI.
the class EditNodeFrame method editButtonActionPerformed.
/**
* Method to handle edit button
*/
@Override
public void editButtonActionPerformed() {
if (nodeAddr64Field.getText().equals("") && nodeAddrField.getText().equals("")) {
// no address, just return.
return;
}
// to update the node's associated XBee Device, we have to
// create a new one, as the library provides no way to update
// the RemoteXBeeDevice object.
// Check that a node with this address does not exist
// if the 64 bit address field is blank, use the "Unknown" address".
XBee64BitAddress guid;
if (!(nodeAddr64Field.getText().equals(""))) {
byte[] GUID = jmri.util.StringUtil.bytesFromHexString(nodeAddr64Field.getText());
guid = new XBee64BitAddress(GUID);
} else {
guid = XBee64BitAddress.UNKNOWN_ADDRESS;
}
// if the 16 bit address field is blank, use the "Unknown" address".
XBee16BitAddress address;
if (!(nodeAddrField.getText().equals(""))) {
byte[] addr = jmri.util.StringUtil.bytesFromHexString(nodeAddrField.getText());
address = new XBee16BitAddress(addr);
} else {
address = XBee16BitAddress.UNKNOWN_ADDRESS;
}
String Identifier = nodeIdentifierField.getText();
// create the RemoteXBeeDevice for the node.
RemoteXBeeDevice remoteDevice = new RemoteXBeeDevice(xtc.getXBee(), guid, address, Identifier);
// get a XBeeNode corresponding to this node address if one exists
XBeeNode existingNode = (XBeeNode) xtc.getNodeFromXBeeDevice(remoteDevice);
if (existingNode != null) {
javax.swing.JOptionPane.showMessageDialog(this, Bundle.getMessage("Error1", remoteDevice), Bundle.getMessage("EditNodeErrorTitle"), JOptionPane.ERROR_MESSAGE);
return;
}
// save the old remote device
RemoteXBeeDevice oldDevice = ((XBeeNode) curNode).getXBee();
// and then add the new device to the network
xtc.getXBee().getNetwork().addRemoteDevice(remoteDevice);
// remove the old one from the network
xtc.getXBee().getNetwork().removeRemoteDevice(oldDevice);
//and update the current node.
((XBeeNode) curNode).setXBee(remoteDevice);
parent.nodeListChanged();
this.dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
}
use of jmri.jmrix.ieee802154.xbee.XBeeNode 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