/**
         * Retrieves the 16-bit address of the given remote device.
         *
         * @param device The remote device to get the 16-bit address.
         *
         * @return The 16-bit address of the device, {@code null} if it does not
         *         contain a valid one.
         */
        private XBee16BitAddress Get16BitAddress(RemoteXBeeDevice device)
        {
            if (device == null)
            {
                return(null);
            }

            XBee16BitAddress address = null;

            switch (device.XBeeProtocol)
            {
            case XBeeProtocol.RAW_802_15_4:
                address = ((RemoteRaw802Device)device).Get16BitAddress();
                break;

            case XBeeProtocol.ZIGBEE:
                address = ((RemoteZigBeeDevice)device).Get16BitAddress();
                break;

            default:
                // TODO should we allow this operation for general remote devices?
                address = device.Get16BitAddress();
                break;
            }

            return(address);
        }
Exemplo n.º 2
0
        /*throws TimeoutException, XBeeException */
        /**
         * Sends the provided data to the given XBee device choosing the optimal
         * send method depending on the protocol of the local XBee device.
         *
         * <p>This method blocks till a success or error response arrives or the
         * configured receive timeout expires.</p>
         *
         * <p>The received timeout is configured using the {@code setReceiveTimeout}
         * method and can be consulted with {@code getReceiveTimeout} method.</p>
         *
         * <p>For non-blocking operations use the method
         * {@link #sendDataAsync(RemoteXBeeDevice, byte[])}.</p>
         *
         * @param xbeeDevice The XBee device of the network that will receive the
         *                   data.
         * @param data Byte array containing the data to be sent.
         *
         * @throws InterfaceNotOpenException if this device connection is not open.
         * @throws ArgumentNullException if {@code xbeeDevice == null} or
         *                              if {@code data == null}.
         * @throws TimeoutException if there is a timeout sending the data.
         * @throws XBeeException if there is any other XBee related exception.
         *
         * @see #getReceiveTimeout()
         * @see #setReceiveTimeout(int)
         * @see #sendDataAsync(RemoteXBeeDevice, byte[])
         */
        public void SendData(RemoteXBeeDevice xbeeDevice, byte[] data)
        {
            if (xbeeDevice == null)
                throw new ArgumentNullException("Remote XBee device cannot be null");

            switch (XBeeProtocol)
            {
                case XBeeProtocol.ZIGBEE:
                case XBeeProtocol.DIGI_POINT:
                    if (xbeeDevice.Get64BitAddress() != null && xbeeDevice.Get16BitAddress() != null)
                        SendData(xbeeDevice.Get64BitAddress(), xbeeDevice.Get16BitAddress(), data);
                    else
                        SendData(xbeeDevice.Get64BitAddress(), data);
                    break;
                case XBeeProtocol.RAW_802_15_4:
                    if (this is Raw802Device)
                    {
                        if (xbeeDevice.Get64BitAddress() != null)
                            ((Raw802Device)this).SendData(xbeeDevice.Get64BitAddress(), data);
                        else
                            ((Raw802Device)this).SendData(xbeeDevice.Get16BitAddress(), data);
                    }
                    else
                        SendData(xbeeDevice.Get64BitAddress(), data);
                    break;
                case XBeeProtocol.DIGI_MESH:
                default:
                    SendData(xbeeDevice.Get64BitAddress(), data);
                    break;
            }
        }
Exemplo n.º 3
0
        /**
         * Retrieves the 16-bit address of the given remote device.
         *
         * @param device The remote device to get the 16-bit address.
         *
         * @return The 16-bit address of the device, {@code null} if it does not
         *         contain a valid one.
         */
        private XBee16BitAddress Get16BitAddress(RemoteXBeeDevice device)
        {
            if (device == null)
                return null;

            XBee16BitAddress address = null;

            switch (device.XBeeProtocol)
            {
                case XBeeProtocol.RAW_802_15_4:
                    address = ((RemoteRaw802Device)device).Get16BitAddress();
                    break;
                case XBeeProtocol.ZIGBEE:
                    address = ((RemoteZigBeeDevice)device).Get16BitAddress();
                    break;
                default:
                    // TODO should we allow this operation for general remote devices?
                    address = device.Get16BitAddress();
                    break;
            }

            return address;
        }