/// <summary>
 /// Class constructor. Instantiates a new <see cref="RemoteZigBeeDevice"/> object with the given
 /// local <see cref="XBeeDevice"/> which contains the connection interface to be used.
 /// </summary>
 /// <param name="localXBeeDevice">The local XBee device that will behave as connection
 /// interface to communicate with this remote ZigBee device.</param>
 /// <param name="addr64">The 64-bit address to identify this remote ZigBee device.</param>
 /// <param name="addr16">The 16-bit address to identify this remote ZigBee device. It might
 /// be<c>null</c>.</param>
 /// <param name="ni">The node identifier of this remote ZigBee device. It might be <c>null</c>.</param>
 /// <exception cref="ArgumentException">If <paramref name="localXBeeDevice"/> is remote
 /// or if <c><paramref name="localXBeeDevice"/> != <see cref="XBeeProtocol.ZIGBEE"/></c>.</exception>
 /// <exception cref="ArgumentNullException">If <c><paramref name="localXBeeDevice"/> == null</c>
 /// or if <c><paramref name="addr64"/> == null</c>.</exception>
 /// <seealso cref="XBeeDevice"/>
 /// <seealso cref="XBee16BitAddress"/>
 /// <seealso cref="XBee64BitAddress"/>
 public RemoteZigBeeDevice(AbstractXBeeDevice localXBeeDevice, XBee64BitAddress addr64,
                           XBee16BitAddress addr16, string ni)
     : base(localXBeeDevice, addr64, addr16, ni)
 {
     // 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() + ".");
     }
 }
        /// <summary>
        /// Class constructor. Instantiates a new <see cref="RemoteRaw802Device"/> object with the given
        /// local <see cref="XBeeDevice"/> which contains the connection interface to be used.
        /// </summary>
        /// <param name="localXBeeDevice">The local XBee device that will behave as connection
        /// interface to communicate with this remote 802.15.4 device.</param>
        /// <param name="addr16">The 16-bit address to identify this remote 802.15.4 device.</param>
        /// <exception cref="ArgumentException">If <paramref name="localXBeeDevice"/> is remote
        /// or if <c><paramref name="localXBeeDevice"/> != <see cref="XBeeProtocol.RAW_802_15_4"/></c>.</exception>
        /// <exception cref="ArgumentNullException">If <c><paramref name="localXBeeDevice"/> == null</c>
        /// or if <c><paramref name="addr16"/> == null</c>.</exception>
        /// <seealso cref="XBeeDevice"/>
        /// <seealso cref="XBee16BitAddress"/>
        public RemoteRaw802Device(AbstractXBeeDevice 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() + ".");
            }

            XBee16BitAddr = addr16;
        }
示例#3
0
        /// <summary>
        /// Class constructor. Instantiates a new <see cref="DataReader"/> object for the given connection
        /// interface using the given XBee operating mode and XBee device.
        /// </summary>
        /// <param name="connectionInterface">Connection interface to read data from.</param>
        /// <param name="mode">XBee operating mode.</param>
        /// <param name="xbeeDevice">Reference to the XBee device containing this <see cref="DataReader"/>
        /// object.</param>
        /// <exception cref="ArgumentNullException">If <c><paramref name="connectionInterface"/> == null</c>.</exception>
        /// <seealso cref="IConnectionInterface"/>
        /// <seealso cref="XBeeDevice"/>
        /// <seealso cref="OperatingMode"/>
        public DataReader(IConnectionInterface connectionInterface, OperatingMode mode, AbstractXBeeDevice xbeeDevice)
        {
            this.connectionInterface = connectionInterface ?? throw new ArgumentNullException("Connection interface cannot be null.");
            this.mode        = mode;
            this.xbeeDevice  = xbeeDevice;
            logger           = LogManager.GetLogger <DataReader>();
            parser           = new XBeePacketParser();
            XBeePacketsQueue = new XBeePacketsQueue();

            // Create the task.
            task = new Task(() => { Run(); }, TaskCreationOptions.LongRunning);
        }
示例#4
0
        /// <summary>
        /// Class constructor. Instantiates a new <see cref="XBeeNetwork"/> object with the provided
        /// parameters.
        /// </summary>
        /// <param name="device">The local XBee device to get the network from.</param>
        /// <exception cref="ArgumentNullException">If <c><paramref name="device"/> == null</c>.</exception>
        internal XBeeNetwork(AbstractXBeeDevice device)
        {
            localDevice = device ?? throw new ArgumentNullException("Local XBee device cannot be null.");

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

            PanId   = "?";
            Channel = "?";

            logger = LogManager.GetLogger(GetType());
        }
示例#5
0
        /// <summary>
        /// Class constructor. Instantiates a new <see cref="NodeDiscovery"/> object with the provided
        /// parameters.
        /// </summary>
        /// <param name="xbeeDevice">XBee Device where to perform the node discovery.</param>
        /// <exception cref="ArgumentNullException">If <c><paramref name="xbeeDevice"/> == null</c>.</exception>
        public NodeDiscovery(AbstractXBeeDevice xbeeDevice)
        {
            this.xbeeDevice = xbeeDevice ?? throw new ArgumentNullException("Local XBee device cannot be null.");
            if (xbeeDevice.IsRemote)
            {
                localDevice = ((RemoteXBeeDevice)this.xbeeDevice).GetLocalXBeeDevice();
            }
            else
            {
                localDevice = xbeeDevice;
            }

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

            logger = LogManager.GetLogger(GetType());
        }
示例#6
0
 /// <summary>
 /// Class constructor. Instantiates a new <see cref="RemoteXBeeDevice"/> object with the given
 /// local <see cref="XBeeDevice"/> which contains the connection interface to be used.
 /// </summary>
 /// <param name="localXBeeDevice">The local XBee device that will behave as connection
 /// interface to communicate with this remote XBee device.</param>
 /// <param name="addr64">The 64-bit address to identify this remote XBee device.</param>
 /// <param name="addr16">The 16-bit address to identify this remote XBee device. It might
 /// be <c>null</c>.</param>
 /// <param name="ni">The node identifier of this remote XBee device. It might be <c>null</c>.</param>
 /// <exception cref="ArgumentException">If <paramref name="localXBeeDevice"/> is remote.</exception>
 /// <exception cref="ArgumentNullException">If <c><paramref name="localXBeeDevice"/> == null</c>
 /// or if <c><paramref name="addr64"/> == null</c>.</exception>
 /// <seealso cref="XBeeDevice"/>
 /// <seealso cref="XBee16BitAddress"/>
 /// <seealso cref="XBee64BitAddress"/>
 public RemoteXBeeDevice(AbstractXBeeDevice localXBeeDevice, XBee64BitAddress addr64,
                         XBee16BitAddress addr16, string ni)
     : base(localXBeeDevice, addr64, addr16, ni)
 {
 }
示例#7
0
 /// <summary>
 /// Class constructor. Instantiates a new <see cref="RemoteXBeeDevice"/> object with the given
 /// local <see cref="XBeeDevice"/> which contains the connection interface to be used.
 /// </summary>
 /// <param name="localXBeeDevice">The local XBee device that will behave as connection
 /// interface to communicate with this remote XBee device.</param>
 /// <param name="addr64">The 64-bit address to identify this remote XBee device.</param>
 /// <exception cref="ArgumentException">If <paramref name="localXBeeDevice"/> is remote.</exception>
 /// <exception cref="ArgumentNullException">If <c><paramref name="localXBeeDevice"/> == null</c>
 /// or if <c><paramref name="addr64"/> == null</c>.</exception>
 /// <seealso cref="XBeeDevice"/>
 /// <seealso cref="XBee64BitAddress"/>
 public RemoteXBeeDevice(AbstractXBeeDevice localXBeeDevice, XBee64BitAddress addr64)
     : base(localXBeeDevice, addr64)
 {
 }
示例#8
0
 /// <summary>
 /// Class constructor. Instantiates a new <seealso cref="BluetoothAuthentication"/> with the
 /// given parameters.
 /// </summary>
 /// <param name="device">XBee device.</param>
 /// <param name="password">Bluetooth password.</param>
 /// <seealso cref="XBeeDevice"/>
 public BluetoothAuthentication(AbstractXBeeDevice device, string password)
 {
     this.device   = device;
     this.password = password;
 }
示例#9
0
        /// <summary>
        /// Parses the given node discovery API data to create and return a remote
        /// XBee Device.
        /// </summary>
        /// <param name="data">Byte array with the data to parse.</param>
        /// <param name="localDevice">The local device that received the remote XBee data.</param>
        /// <returns>The discovered XBee device.</returns>
        private async Task <RemoteXBeeDevice> ParseDiscoveryAPIData(byte[] data, AbstractXBeeDevice 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:
                case XBeeProtocol.SX:
                    // 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);
        }