use of com.digi.xbee.api.models.XBee16BitAddress 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());
}
use of com.digi.xbee.api.models.XBee16BitAddress in project JMRI by JMRI.
the class XBeeNodeTest method testGetPreferedNameAsGlobalAddress.
@Test
public void testGetPreferedNameAsGlobalAddress() {
// 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("FFFE"));
byte[] pan = { (byte) 0x00, (byte) 0x42 };
byte[] uad = { (byte) 0xFF, (byte) 0xFE };
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);
tc.registerNode(node);
node.setXBee(rd);
Assert.assertEquals("Global Address Name", "00 13 A2 00 40 A0 4D 2D ", node.getPreferedName());
}
use of com.digi.xbee.api.models.XBee16BitAddress 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.models.XBee16BitAddress in project JMRI by JMRI.
the class XBeeMessage method getRemoteDoutMessage.
/*
* Get an XBee Message requesting an digital output pin be turned on or off.
* @param address XBee Address of the node. This can be either
16 bit or 64 bit.
* @param pin the DIO Pin on the XBee to use.
* @param on boolean value stating whether or not the pin should be turned
* on (true) or off (false)
*/
@SuppressFBWarnings(value = { "BC_UNCONFIRMED_CAST" }, justification = "The passed address must be either a 16 bit address or a 64 bit address, and we check to see if the address is a 16 bit address, so it is redundant to also check for a 64 bit address")
public static XBeeMessage getRemoteDoutMessage(Object address, int pin, boolean on) {
byte[] onValue = { 0x5 };
byte[] offValue = { 0x4 };
if (address instanceof XBee16BitAddress) {
return new XBeeMessage(new RemoteATCommandPacket(XBeeAPIPacket.NO_FRAME_ID, XBee64BitAddress.COORDINATOR_ADDRESS, (XBee16BitAddress) address, 0, "D" + pin, on ? onValue : offValue));
} else {
return new XBeeMessage(new RemoteATCommandPacket(XBeeAPIPacket.NO_FRAME_ID, (XBee64BitAddress) address, XBee16BitAddress.UNKNOWN_ADDRESS, 0, "D" + pin, on ? onValue : offValue));
}
}
use of com.digi.xbee.api.models.XBee16BitAddress 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