use of com.digi.xbee.api.RemoteXBeeDevice in project JMRI by JMRI.
the class XBeeNodeTest method testGetPreferedNameAsNodeIdentifier.
@Test
public void testGetPreferedNameAsNodeIdentifier() {
// Mock the remote device.
RemoteXBeeDevice rd = Mockito.mock(RemoteXBeeDevice.class);
Mockito.when(rd.getXBeeProtocol()).thenReturn(XBeeProtocol.UNKNOWN);
Mockito.when(rd.getNodeID()).thenReturn("Hello World");
Mockito.when(rd.get64BitAddress()).thenReturn(new XBee64BitAddress("0013A20040A04D2D"));
Mockito.when(rd.get16BitAddress()).thenReturn(new XBee16BitAddress("FFFF"));
byte[] pan = { (byte) 0x00, (byte) 0x42 };
byte[] uad = { (byte) 0xFF, (byte) 0xFF };
byte[] gad = { (byte) 0x00, (byte) 0x13, (byte) 0xA2, (byte) 0x00, (byte) 0x40, (byte) 0xA0, (byte) 0x4D, (byte) 0x2D };
XBeeNode node = new XBeeNode(pan, uad, gad);
node.setXBee(rd);
node.setIdentifier("Hello World");
tc.registerNode(node);
Assert.assertEquals("Identifier Name", node.getPreferedName(), "Hello World");
}
use of com.digi.xbee.api.RemoteXBeeDevice 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 com.digi.xbee.api.RemoteXBeeDevice 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);
}
}
}
use of com.digi.xbee.api.RemoteXBeeDevice in project JMRI by JMRI.
the class XBeeTrafficController method getNodeFromXBeeDevice.
/**
* Public method to identify an XBeeNode from its RemoteXBeeDevice object.
*
* @param device the RemoteXBeeDevice to search for.
* @return the node if found, or null otherwise.
*/
public synchronized jmri.jmrix.AbstractNode getNodeFromXBeeDevice(RemoteXBeeDevice device) {
log.debug("getNodeFromXBeeDevice called with {}", device);
for (int i = 0; i < numNodes; i++) {
XBeeNode node = (XBeeNode) getNode(i);
// examine the addresses of the two XBee Devices to see
// if they are the same.
RemoteXBeeDevice nodeXBee = node.getXBee();
if (nodeXBee.get16BitAddress().equals(device.get16BitAddress()) && nodeXBee.get64BitAddress().equals(device.get64BitAddress())) {
return node;
}
}
return (null);
}
use of com.digi.xbee.api.RemoteXBeeDevice in project JMRI by JMRI.
the class XBeeNodeTest method testGetPreferedTransmitGlobalAddressWithMaskRequired.
@Test
public void testGetPreferedTransmitGlobalAddressWithMaskRequired() {
// Mock the remote device.
RemoteXBeeDevice rd = Mockito.mock(RemoteXBeeDevice.class);
Mockito.when(rd.getXBeeProtocol()).thenReturn(XBeeProtocol.UNKNOWN);
Mockito.when(rd.getNodeID()).thenReturn("");
Mockito.when(rd.get64BitAddress()).thenReturn(new XBee64BitAddress("0013A20040A04D2D"));
Mockito.when(rd.get16BitAddress()).thenReturn(new XBee16BitAddress("FFFF"));
byte[] pan = { (byte) 0x00, (byte) 0x42 };
byte[] uad = { (byte) 0x0fffffff, (byte) 0x0ffffffe };
byte[] gad = { (byte) 0x00, (byte) 0x13, (byte) 0xA2, (byte) 0x00, (byte) 0x40, (byte) 0xA0, (byte) 0x4D, (byte) 0x2D };
XBeeNode node = new XBeeNode(pan, uad, gad);
node.setXBee(rd);
tc.registerNode(node);
Assert.assertEquals("Global Transmit Address", node.getXBeeAddress64(), node.getPreferedTransmitAddress());
}
Aggregations