Search in sources :

Example 1 with XBee16BitAddress

use of com.digi.xbee.api.models.XBee16BitAddress 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));
}
Also used : XBee64BitAddress(com.digi.xbee.api.models.XBee64BitAddress) RemoteXBeeDevice(com.digi.xbee.api.RemoteXBeeDevice) WindowEvent(java.awt.event.WindowEvent) XBee16BitAddress(com.digi.xbee.api.models.XBee16BitAddress) XBeeException(com.digi.xbee.api.exceptions.XBeeException) XBeeNode(jmri.jmrix.ieee802154.xbee.XBeeNode) TimeoutException(com.digi.xbee.api.exceptions.TimeoutException)

Example 2 with XBee16BitAddress

use of com.digi.xbee.api.models.XBee16BitAddress 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());
}
Also used : XBee64BitAddress(com.digi.xbee.api.models.XBee64BitAddress) RemoteXBeeDevice(com.digi.xbee.api.RemoteXBeeDevice) XBee16BitAddress(com.digi.xbee.api.models.XBee16BitAddress) Test(org.junit.Test)

Example 3 with XBee16BitAddress

use of com.digi.xbee.api.models.XBee16BitAddress 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());
}
Also used : XBee64BitAddress(com.digi.xbee.api.models.XBee64BitAddress) RemoteXBeeDevice(com.digi.xbee.api.RemoteXBeeDevice) XBee16BitAddress(com.digi.xbee.api.models.XBee16BitAddress) Test(org.junit.Test)

Example 4 with XBee16BitAddress

use of com.digi.xbee.api.models.XBee16BitAddress 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());
}
Also used : XBee64BitAddress(com.digi.xbee.api.models.XBee64BitAddress) RemoteXBeeDevice(com.digi.xbee.api.RemoteXBeeDevice) XBee16BitAddress(com.digi.xbee.api.models.XBee16BitAddress) Test(org.junit.Test)

Example 5 with XBee16BitAddress

use of com.digi.xbee.api.models.XBee16BitAddress 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");
}
Also used : XBee64BitAddress(com.digi.xbee.api.models.XBee64BitAddress) RemoteXBeeDevice(com.digi.xbee.api.RemoteXBeeDevice) XBee16BitAddress(com.digi.xbee.api.models.XBee16BitAddress) Test(org.junit.Test)

Aggregations

XBee16BitAddress (com.digi.xbee.api.models.XBee16BitAddress)10 XBee64BitAddress (com.digi.xbee.api.models.XBee64BitAddress)10 RemoteXBeeDevice (com.digi.xbee.api.RemoteXBeeDevice)9 Test (org.junit.Test)6 XBeeNode (jmri.jmrix.ieee802154.xbee.XBeeNode)3 TimeoutException (com.digi.xbee.api.exceptions.TimeoutException)2 XBeeException (com.digi.xbee.api.exceptions.XBeeException)2 WindowEvent (java.awt.event.WindowEvent)2 RemoteATCommandPacket (com.digi.xbee.api.packet.common.RemoteATCommandPacket)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 AbstractStreamPortController (jmri.jmrix.AbstractStreamPortController)1 XBeeConnectionMemo (jmri.jmrix.ieee802154.xbee.XBeeConnectionMemo)1 XBeeTrafficController (jmri.jmrix.ieee802154.xbee.XBeeTrafficController)1 Element (org.jdom2.Element)1