Beispiel #1
0
        public static void TraceDeviceDetailed(UInt64 macAddress, byte endPointId, SimpleDescriptor descriptor)
        {
            if (!m_doTraceDeviceDiscovery ||
                descriptor == null)
            {
                return;
            }

            Debug.WriteLine("Device mac address 0x{0:X8}, EndPoint: 0x{1:X2}, Profile ID: 0x{2:X4}, Device ID: 0x{3:X4}", macAddress, endPointId, descriptor.ProfileId, descriptor.DeviceId);
        }
Beispiel #2
0
        private void AddDeviceInDeviceList(UInt16 networkAddress, UInt64 macAddress, bool isEndDevice)
        {
            bool         deviceFound     = false;
            bool         addDeviceInList = false;
            ZigBeeDevice device          = null;

            Logger.TraceDevice(networkAddress, macAddress);

            lock (m_deviceMap)
            {
                deviceFound = m_deviceMap.TryGetValue(macAddress, out device);
            }

            if (!deviceFound)
            {
                // the device isn't in the list yet
                device = new ZigBeeDevice(networkAddress, macAddress, isEndDevice);

                // get end points and supported clusters
                ActiveEndPoints activeEndPointsCommand = new ActiveEndPoints();
                activeEndPointsCommand.GetEndPoints(m_xBeeModule, device);

                foreach (var endPointId in activeEndPointsCommand.EndPointList)
                {
                    SimpleDescriptor descriptor = new SimpleDescriptor();
                    descriptor.GetDescriptor(m_xBeeModule, device, endPointId);
                    Logger.TraceDeviceDetailed(device.MacAddress, endPointId, descriptor);
                    foreach (var clusterId in descriptor.InClusterList)
                    {
                        if (m_zclClusterFactory.IsClusterSupported(clusterId) &&
                            device.AddClusterToEndPoint(true, endPointId, descriptor.ProfileId, descriptor.DeviceId, clusterId, this))
                        {
                            // only add device in list if at least 1 cluster is supported
                            addDeviceInList = true;
                        }
                    }
                    foreach (var clusterId in descriptor.OutClusterList)
                    {
                        if (m_zclClusterFactory.IsClusterSupported(clusterId) &&
                            device.AddClusterToEndPoint(false, endPointId, descriptor.ProfileId, descriptor.DeviceId, clusterId, this))
                        {
                            // only add device in list if at least 1 cluster is supported
                            addDeviceInList = true;
                        }
                    }
                }
            }
            else
            {
                // the device is already in list so just refresh its network address.
                // note that mac address will never change but network address can, e.g.: if end device connects to another router
                device.NetworkAddress = networkAddress;
            }

            // add device in list if necessary
            if (addDeviceInList)
            {
                lock (m_deviceMap)
                {
                    // add device in list if it has not been added between beginning of this routine and now
                    ZigBeeDevice tempDevice = null;
                    if (!m_deviceMap.TryGetValue(device.MacAddress, out tempDevice))
                    {
                        m_deviceMap.Add(device.MacAddress, device);
                    }
                    else
                    {
                        // device has been added => update network address of already existing device
                        // give up with device that has been created and use the already existing device instead
                        tempDevice.NetworkAddress = device.NetworkAddress;
                        device = tempDevice;
                    }
                }
            }

            // notify devices to bridgeRT
            // note end points are devices as far as BridgeRT is concerned
            foreach (var endpoint in device.EndPointList)
            {
                NotifyBridgeRT(endpoint.Value, Constants.DEVICE_ARRIVAL_SIGNAL, Constants.DEVICE_ARRIVAL__DEVICE_HANDLE);
            }
        }