/**
  * Class constructor. Instantiates a new {@code RemoteDigiPointDevice} object
  * with the given local {@code XBeeDevice} which contains the connection
  * interface to be used.
  *
  * @param localXBeeDevice The local XBee device that will behave as
  *                        connection interface to communicate with this
  *                        remote point-to-multipoint device.
  * @param addr64 The 64-bit address to identify this remote point-to-multipoint
  *               device.
  * @param id The node identifier of this remote point-to-multipoint device.
  *           It might be {@code null}.
  *
  * @throws ArgumentException if {@code localXBeeDevice.isRemote() == true} or
  *                                  if {@code localXBeeDevice.getXBeeProtocol() != XBeeProtocol.DIGI_POINT}.
  * @throws ArgumentNullException if {@code localXBeeDevice == null} or
  *                              if {@code addr64 == null}.
  *
  * @see com.digi.xbee.api.models.XBee64BitAddress
  */
 public RemoteDigiPointDevice(XBeeDevice localXBeeDevice, XBee64BitAddress addr64, string id)
     : base(localXBeeDevice, addr64, null, id)
 {
     // Verify the local device has point-to-multipoint protocol.
     if (localXBeeDevice.XBeeProtocol != XBeeProtocol.DIGI_POINT)
     {
         throw new ArgumentException("The protocol of the local XBee device is not " + XBeeProtocol.DIGI_POINT.GetDescription() + ".");
     }
 }
 /**
  * Class constructor. Instantiates a new {@code RemoteDigiMeshDevice} object
  * with the given local {@code XBeeDevice} which contains the connection
  * interface to be used.
  *
  * @param localXBeeDevice The local XBee device that will behave as
  *                        connection interface to communicate with this
  *                        remote DigiMesh device.
  * @param addr64 The 64-bit address to identify this remote DigiMesh device.
  * @param id The node identifier of this remote DigiMesh device. It might
  *           be {@code null}.
  *
  * @throws ArgumentException if {@code localXBeeDevice.isRemote() == true} or
  *                                  if {@code localXBeeDevice.getXBeeProtocol() != XBeeProtocol.DIGI_MESH}.
  * @throws ArgumentNullException if {@code localXBeeDevice == null} or
  *                              if {@code addr64 == null}.
  *
  * @see com.digi.xbee.api.models.XBee64BitAddress
  */
 public RemoteDigiMeshDevice(XBeeDevice localXBeeDevice, XBee64BitAddress addr64, string id)
     : base(localXBeeDevice, addr64, null, id)
 {
     // Verify the local device has DigiMesh protocol.
     if (localXBeeDevice.XBeeProtocol != Models.XBeeProtocol.DIGI_MESH)
     {
         throw new ArgumentException("The protocol of the local XBee device is not " + XBeeProtocol.DIGI_MESH.GetDescription() + ".");
     }
 }
 /**
  * Class constructor. Instantiates a new {@code RemoteZigBeeDevice} object
  * with the given local {@code XBeeDevice} which contains the connection
  * interface to be used.
  *
  * @param localXBeeDevice The local XBee device that will behave as
  *                        connection interface to communicate with this
  *                        remote ZigBee device.
  * @param addr64 The 64-bit address to identify this remote ZigBee device.
  *
  * @throws ArgumentException if {@code localXBeeDevice.isRemote() == true} or
  *                                  if {@code localXBeeDevice.getXBeeProtocol() != XBeeProtocol.ZIGBEE}.
  * @throws ArgumentNullException if {@code localXBeeDevice == null} or
  *                              if {@code addr64 == null}.
  *
  * @see com.digi.xbee.api.models.XBee64BitAddress
  */
 public RemoteZigBeeDevice(XBeeDevice localXBeeDevice, XBee64BitAddress addr64)
     : base(localXBeeDevice, addr64)
 {
     // Verify the local device has ZigBee protocol.
     if (localXBeeDevice.XBeeProtocol != XBeeProtocol.ZIGBEE)
     {
         throw new ArgumentException("The protocol of the local XBee device is not " + XBeeProtocol.ZIGBEE.GetDescription() + ".");
     }
 }
 /**
  * Class constructor. Instantiates a new {@code RemoteRaw802Device} object
  * with the given local {@code XBeeDevice} which contains the connection
  * interface to be used.
  *
  * @param localXBeeDevice The local XBee device that will behave as
  *                        connection interface to communicate with this
  *                        remote 802.15.4 device.
  * @param addr64 The 64-bit address to identify this remote 802.15.4 device.
  * @param addr16 The 16-bit address to identify this remote 802.15.4 device.
  *               It might be {@code null}.
  * @param id The node identifier of this remote 802.15.4 device. It might be
  *           {@code null}.
  *
  * @throws ArgumentException if {@code localXBeeDevice.isRemote() == true} or
  *                                  if {@code localXBeeDevice.getXBeeProtocol() != XBeeProtocol.RAW_802_15_4}
  * @throws ArgumentNullException if {@code localXBeeDevice == null} or
  *                              if {@code addr64 == null}.
  *
  * @see com.digi.xbee.api.models.XBee16BitAddress
  * @see com.digi.xbee.api.models.XBee64BitAddress
  */
 public RemoteRaw802Device(XBeeDevice localXBeeDevice, XBee64BitAddress addr64,
                           XBee16BitAddress addr16, string id)
     : base(localXBeeDevice, addr64, addr16, id)
 {
     // Verify the local device has 802.15.4 protocol.
     if (localXBeeDevice.XBeeProtocol != XBeeProtocol.RAW_802_15_4)
     {
         throw new ArgumentException("The protocol of the local XBee device is not " + XBeeProtocol.RAW_802_15_4.GetDescription() + ".");
     }
 }
        public async Task Discover()
        {
            var devices = await XBeeDevice.Discover();

            Assert.IsTrue(devices.Count > 0);
            foreach (var device in devices)
            {
                device.Dispose();
            }
        }
        /**
         * Class constructor. Instantiates a new {@code RemoteRaw802Device} object
         * interface to be used.
         *
         * @param localXBeeDevice The local 802.15.4 device that will behave as
         *                        connection interface to communicate with this
         *                        remote 802.15.4 device.
         * @param addr16 The 16-bit address to identify this remote 802.15.4
         *               device.
         *
         * @throws ArgumentException if {@code localXBeeDevice.getXBeeProtocol() != XBeeProtocol.RAW_802_15_4}.
         * @throws ArgumentNullException if {@code localXBeeDevice == null} or
         *                              if {@code addr16 == null}.
         *
         * @see com.digi.xbee.api.models.XBee16BitAddress
         */
        public RemoteRaw802Device(XBeeDevice localXBeeDevice, XBee16BitAddress addr16)
            : base(localXBeeDevice, XBee64BitAddress.UNKNOWN_ADDRESS)
        {
            // Verify the local device has 802.15.4 protocol.
            if (localXBeeDevice.XBeeProtocol != XBeeProtocol.RAW_802_15_4)
            {
                throw new ArgumentException("The protocol of the local XBee device is not " + XBeeProtocol.RAW_802_15_4.GetDescription() + ".");
            }

            this.xbee16BitAddress = addr16;
        }
        /**
         * Class constructor. Instantiates a new {@code DataReader} object for the
         * given connection interface using the given XBee operating mode and XBee
         * device.
         *
         * @param connectionInterface Connection interface to read data from.
         * @param mode XBee operating mode.
         * @param xbeeDevice Reference to the XBee device containing this
         *                   {@code DataReader} object.
         *
         * @throws ArgumentNullException if {@code connectionInterface == null} or
         *                                 {@code mode == null}.
         *
         * @see IConnectionInterface
         * @see com.digi.xbee.api.XBeeDevice
         * @see com.digi.xbee.api.models.OperatingMode
         */
        public DataReader(IConnectionInterface connectionInterface, OperatingMode mode, XBeeDevice xbeeDevice)
        {
            if (connectionInterface == null)
                throw new ArgumentNullException("Connection interface cannot be null.");
            if (mode == null)
                throw new ArgumentNullException("Operating mode cannot be null.");

            this.connectionInterface = connectionInterface;
            this.mode = mode;
            this.xbeeDevice = xbeeDevice;
            this.logger = LogManager.GetLogger<DataReader>();
            parser = new XBeePacketParser();
            xbeePacketsQueue = new XBeePacketsQueue();
        }
        /// <summary>
        /// Initializes a new instance of <see cref="XBeeNetwork"/>.
        /// </summary>
        /// <param name="device">A local XBee device to get the network from.</param>
        public XBeeNetwork(XBeeDevice device)
        {
            if (device == null)
            {
                throw new ArgumentNullException("Local XBee device cannot be null.");
            }

            localDevice        = device;
            remotesBy64BitAddr = new ConcurrentDictionary <XBee64BitAddress, RemoteXBeeDevice>();
            remotesBy16BitAddr = new ConcurrentDictionary <XBee16BitAddress, RemoteXBeeDevice>();
            nodeDiscovery      = new NodeDiscovery(localDevice);

            logger = LogManager.GetLogger(this.GetType());
        }
Beispiel #9
0
 public PacketListener(SerialPort serialPort, XBeeDevice xbeeDevice, int queueMaxSize = -1)
 {
     foreach (Reader.PacketReceivedHandler handler in xbeeDevice.GetXBeeDeviceCallbacks())
     {
         // Get list of internal callbacks from device, and subscribe them all to PacketReceivedAPI
         PacketReceivedAPI += handler;
     }
     this.xbeeDevice   = xbeeDevice;
     this.comPort      = serialPort;
     this.stop         = true;
     this.queueMaxSize = (queueMaxSize < 0) ? DEFAULT_QUEUE_MAX_SIZE : queueMaxSize;
     XBeeQueue         = new XBeeQueue(this.queueMaxSize);
     DataXBeeQueue     = new XBeeQueue(this.queueMaxSize);
     ExplicitXBeeQueue = new XBeeQueue(this.queueMaxSize);
     IPXBeeQueue       = new XBeeQueue(this.queueMaxSize);
 }
Beispiel #10
0
        /**
         * Class constructor. Instantiates a new {@code DataReader} object for the
         * given connection interface using the given XBee operating mode and XBee
         * device.
         *
         * @param connectionInterface Connection interface to read data from.
         * @param mode XBee operating mode.
         * @param xbeeDevice Reference to the XBee device containing this
         *                   {@code DataReader} object.
         *
         * @throws ArgumentNullException if {@code connectionInterface == null} or
         *                                 {@code mode == null}.
         *
         * @see IConnectionInterface
         * @see com.digi.xbee.api.XBeeDevice
         * @see com.digi.xbee.api.models.OperatingMode
         */
        public DataReader(IConnectionInterface connectionInterface, OperatingMode mode, XBeeDevice xbeeDevice)
        {
            if (connectionInterface == null)
            {
                throw new ArgumentNullException("Connection interface cannot be null.");
            }
            if (mode == null)
            {
                throw new ArgumentNullException("Operating mode cannot be null.");
            }

            this.connectionInterface = connectionInterface;
            this.mode        = mode;
            this.xbeeDevice  = xbeeDevice;
            this.logger      = LogManager.GetLogger <DataReader>();
            parser           = new XBeePacketParser();
            xbeePacketsQueue = new XBeePacketsQueue();
        }
        /**
         * Instantiates a new {@code NodeDiscovery} object.
         *
         * @param xbeeDevice XBee Device to perform the discovery operation.
         *
         * @throws ArgumentNullException If {@code xbeeDevice == null}.
         *
         * @see XBeeDevice
         */
        public NodeDiscovery(XBeeDevice xbeeDevice)
        {
            if (xbeeDevice == null)
            {
                throw new ArgumentNullException("Local XBee device cannot be null.");
            }

            this.xbeeDevice = xbeeDevice;

            frameID = globalFrameID;
            globalFrameID++;
            if (globalFrameID == 0xFF)
            {
                globalFrameID = 1;
            }

            logger = LogManager.GetLogger(this.GetType());
        }
        public static void Main()
        {
            var port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);

            port.Open();

            var xbee = new XBeeDevice(port, (Cpu.Pin) 17, (Cpu.Pin) 45);

            Debug.Print("MAC address : " + DumpU64(xbee.GetSerialNumber()));

            Debug.Print("Waiting for association...");
            while (xbee.GetAssociationState() != XBeeDevice.AssociationIndication.Success)
            {
                Thread.Sleep(100);
            }

            Debug.Print("Associated - Sending test packet");
            xbee.Send(0UL, "Hello there coordinator");

            xbee.Dispose();
        }
        public async Task Setup()
        {
            _devices = await XBeeDevice.Discover();

            Assert.IsTrue(_devices.Count > 1, "These tests require two or more nodes attached to the test computer!");
            int  retries = 10;
            bool success = false;

            do
            {
                int count = 0;
                foreach (var device in _devices)
                {
                    if (device.GetAssociationState() == XBeeDevice.AssociationIndication.Success)
                    {
                        ++count;
                    }
                }
                if (count == _devices.Count)
                {
                    success = true;
                    break;
                }
                else
                {
                    await Task.Delay(300);
                }
            } while (!success && --retries > 0);
            Assert.IsTrue(success, "Not all devices are associated yet.");
            if (success)
            {
                _mac[0] = _devices[0].GetSerialNumber();
                _mac[1] = _devices[1].GetSerialNumber();

                _devices[0].OnPacketReceived += SendReceiveTests_OnPacketReceived;
                _devices[1].OnPacketReceived += SendReceiveTests_OnPacketReceived;
            }
        }
        /**
         * Parses the given node discovery API data to create and return a remote
         * XBee Device.
         *
         * @param data Byte array with the data to parse.
         * @param localDevice The local device that received the remote XBee data.
         *
         * @return Discovered XBee device.
         */
        private async Task <RemoteXBeeDevice> ParseDiscoveryAPIData(byte[] data, XBeeDevice localDevice)
        {
            if (data == null)
            {
                return(null);
            }

            RemoteXBeeDevice device = null;
            XBee16BitAddress addr16 = null;
            XBee64BitAddress addr64 = null;
            String           id     = null;
            // TODO role of the device: coordinator, router, end device or unknown.
            //XBeeDeviceType role = XBeeDeviceType.UNKNOWN;
            int signalStrength = 0;

            byte[] profileID      = null;
            byte[] manufacturerID = null;

            using (var inputStream = new MemoryStream(data))
            {
                // Read 16 bit address.
                addr16 = new XBee16BitAddress(await ByteUtils.ReadBytes(2, inputStream));
                // Read 64 bit address.
                addr64 = new XBee64BitAddress(await ByteUtils.ReadBytes(8, inputStream));


                switch (localDevice.XBeeProtocol)
                {
                case XBeeProtocol.ZIGBEE:
                case XBeeProtocol.DIGI_MESH:
                case XBeeProtocol.ZNET:
                case XBeeProtocol.DIGI_POINT:
                case XBeeProtocol.XLR:
                // TODO [XLR_DM] The next version of the XLR will add DigiMesh support.
                // For the moment only point-to-multipoint is supported in this kind of devices.
                case XBeeProtocol.XLR_DM:
                    // Read node identifier.
                    id = ByteUtils.ReadString(inputStream);
                    // Read parent address.
                    XBee16BitAddress parentAddress = new XBee16BitAddress(await ByteUtils.ReadBytes(2, inputStream));
                    // TODO Read device type.
                    //role = XBeeDeviceType.get(inputStream.read());
                    // Consume status byte, it is not used yet.
                    await ByteUtils.ReadBytes(1, inputStream);

                    // Read profile ID.
                    profileID = await ByteUtils.ReadBytes(2, inputStream);

                    // Read manufacturer ID.
                    manufacturerID = await ByteUtils.ReadBytes(2, inputStream);

                    logger.DebugFormat("{0}Discovered {1} device: 16-bit[{2}], 64-bit[{3}], id[{4}], parent[{5}], profile[{6}], manufacturer[{7}].",
                                       xbeeDevice.ToString(), localDevice.XBeeProtocol.GetDescription(), addr16,
                                       addr64, id, parentAddress, HexUtils.ByteArrayToHexString(profileID),
                                       HexUtils.ByteArrayToHexString(manufacturerID));

                    break;

                case XBeeProtocol.RAW_802_15_4:
                    // Read strength signal byte.
                    signalStrength = inputStream.ReadByte();
                    // Read node identifier.
                    id = ByteUtils.ReadString(inputStream);

                    logger.DebugFormat("{0}Discovered {1} device: 16-bit[{2}], 64-bit[{3}], id[{4}], rssi[{5}].",
                                       xbeeDevice.ToString(), localDevice.XBeeProtocol.GetDescription(), addr16, addr64, id, signalStrength);

                    break;

                case XBeeProtocol.UNKNOWN:
                default:
                    logger.DebugFormat("{0}Discovered {1} device: 16-bit[{2}], 64-bit[{3}].",
                                       xbeeDevice.ToString(), localDevice.XBeeProtocol.GetDescription(), addr16, addr64);
                    break;
                }

                // Create device and fill with parameters.
                switch (localDevice.XBeeProtocol)
                {
                case XBeeProtocol.ZIGBEE:
                    device = new RemoteZigBeeDevice(localDevice, addr64, addr16, id /*, role*/);
                    // TODO profileID and manufacturerID
                    break;

                case XBeeProtocol.DIGI_MESH:
                    device = new RemoteDigiMeshDevice(localDevice, addr64, id /*, role*/);
                    // TODO profileID and manufacturerID
                    break;

                case XBeeProtocol.DIGI_POINT:
                    device = new RemoteDigiPointDevice(localDevice, addr64, id /*, role*/);
                    // TODO profileID and manufacturerID
                    break;

                case XBeeProtocol.RAW_802_15_4:
                    device = new RemoteRaw802Device(localDevice, addr64, addr16, id /*, role*/);
                    // TODO signalStrength
                    break;

                default:
                    device = new RemoteXBeeDevice(localDevice, addr64, addr16, id /*, role*/);
                    break;
                }
            }

            return(device);
        }
Beispiel #15
0
        public async Task Setup()
        {
            _devices = await XBeeDevice.Discover();

            Assert.IsTrue(_devices.Count > 0, "No devices found!");
        }
 /**
  * Class constructor. Instantiates a new {@code RemoteXBeeDevice} object
  * with the given local {@code XBeeDevice} which contains the connection
  * interface to be used.
  *
  * @param localXBeeDevice The local XBee device that will behave as
  *                        connection interface to communicate with this
  *                        remote XBee device.
  * @param addr64 The 64-bit address to identify this remote XBee device.
  *
  * @throws ArgumentException if {@code localXBeeDevice.isRemote() == true}.
  * @throws ArgumentNullException if {@code localXBeeDevice == null} or
  *                              if {@code addr64 == null}.
  *
  * @see com.digi.xbee.api.models.XBee64BitAddress
  */
 public RemoteXBeeDevice(XBeeDevice localXBeeDevice, XBee64BitAddress addr64)
     : base(localXBeeDevice, addr64)
 {
 }
 /**
  * Class constructor. Instantiates a new {@code RemoteXBeeDevice} object
  * with the given local {@code XBeeDevice} which contains the connection
  * interface to be used.
  *
  * @param localXBeeDevice The local XBee device that will behave as
  *                        connection interface to communicate with this
  *                        remote XBee device.
  * @param addr64 The 64-bit address to identify this remote XBee device.
  * @param addr16 The 16-bit address to identify this remote XBee device. It
  *               might be {@code null}.
  * @param ni The node identifier of this remote XBee device. It might be
  *           {@code null}.
  *
  * @throws ArgumentException if {@code localXBeeDevice.isRemote() == true}.
  * @throws ArgumentNullException if {@code localXBeeDevice == null} or
  *                              if {@code addr64 == null}.
  *
  * @see com.digi.xbee.api.models.XBee16BitAddress
  * @see com.digi.xbee.api.models.XBee64BitAddress
  */
 public RemoteXBeeDevice(XBeeDevice localXBeeDevice, XBee64BitAddress addr64,
                         XBee16BitAddress addr16, string ni)
     : base(localXBeeDevice, addr64, addr16, ni)
 {
 }
Beispiel #18
0
 private async void MainPage_Loaded(object sender, RoutedEventArgs e)
 {
     var devices = await XBeeDevice.Discover();
 }
Beispiel #19
0
 public XBGateway(XBeeDevice coordinator)
 {
     Coordinator = coordinator;
 }