use of com.digi.xbee.api.models.XBee64BitAddress 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 com.digi.xbee.api.models.XBee64BitAddress in project JMRI by JMRI.
the class XBeeNodeTest method testGetPreferedTransmitUserAddress.
@Test
public void testGetPreferedTransmitUserAddress() {
// 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("6D97"));
byte[] pan = { (byte) 0x00, (byte) 0x42 };
byte[] uad = { (byte) 0x6D, (byte) 0x97 };
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("Short Transmit Address", node.getXBeeAddress16(), node.getPreferedTransmitAddress());
}
use of com.digi.xbee.api.models.XBee64BitAddress in project JMRI by JMRI.
the class XBeeNodeTest method testGetPreferedNameAsUserAddress.
@Test
public void testGetPreferedNameAsUserAddress() {
// 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("6D97"));
byte[] pan = { (byte) 0x00, (byte) 0x42 };
byte[] uad = { (byte) 0x6D, (byte) 0x97 };
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("Short Address Name", "6D 97 ", node.getPreferedName());
}
use of com.digi.xbee.api.models.XBee64BitAddress in project JMRI by JMRI.
the class XBeeNodeTest method testGetPreferedTransmitGlobalAddress.
@Test
public void testGetPreferedTransmitGlobalAddress() {
// 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) 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);
tc.registerNode(node);
Assert.assertEquals("Global Transmit Address", node.getXBeeAddress64(), node.getPreferedTransmitAddress());
}
use of com.digi.xbee.api.models.XBee64BitAddress 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");
}
Aggregations