Search in sources :

Example 1 with RemoteXBeeDevice

use of com.digi.xbee.api.RemoteXBeeDevice in project JMRI by JMRI.

the class XBeeNodeManager method discoveryFinished.

/*
     * Discovery finished callback.
     */
@Override
public void discoveryFinished(String error) {
    if (error != null) {
        log.error("Node discovery processed finished with error: {}", error);
    } else {
        log.info("Node discovery process completed successfully wtih {} devices discovered", xbeeNetwork.getNumberOfDevices());
        // retrieve the node list from the network.
        List<RemoteXBeeDevice> nodeList = xbeeNetwork.getDevices();
        for (RemoteXBeeDevice device : nodeList) {
            XBeeNode node = (XBeeNode) xtc.getNodeFromXBeeDevice(device);
            if (node == null) {
                // the node does not exist, we're adding a new one.
                try {
                    node = new XBeeNode(device);
                    // register the node with the traffic controller
                    xtc.registerNode(node);
                } catch (com.digi.xbee.api.exceptions.TimeoutException t) {
                    log.error("Timeout registering device {}", device);
                } catch (com.digi.xbee.api.exceptions.XBeeException e) {
                    log.error("Exception registering device {}", device);
                }
            }
        }
    // and remove this class from the list of discovery listeners.
    // removing the listener here is causing a 
    // ConcurrentModificaitonException on an ArrayList in the library.
    // xbeeNetwork.removeDiscoveryListener(this);
    }
}
Also used : RemoteXBeeDevice(com.digi.xbee.api.RemoteXBeeDevice)

Example 2 with RemoteXBeeDevice

use of com.digi.xbee.api.RemoteXBeeDevice 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 3 with RemoteXBeeDevice

use of com.digi.xbee.api.RemoteXBeeDevice 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 4 with RemoteXBeeDevice

use of com.digi.xbee.api.RemoteXBeeDevice 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 5 with RemoteXBeeDevice

use of com.digi.xbee.api.RemoteXBeeDevice 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)

Aggregations

RemoteXBeeDevice (com.digi.xbee.api.RemoteXBeeDevice)11 XBee16BitAddress (com.digi.xbee.api.models.XBee16BitAddress)9 XBee64BitAddress (com.digi.xbee.api.models.XBee64BitAddress)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 AbstractStreamPortController (jmri.jmrix.AbstractStreamPortController)1 XBeeConnectionMemo (jmri.jmrix.ieee802154.xbee.XBeeConnectionMemo)1 XBeeTrafficController (jmri.jmrix.ieee802154.xbee.XBeeTrafficController)1 Element (org.jdom2.Element)1