示例#1
0
        private bool GetOnOffStateFromDevice()
        {
            ZclAttribute attributeOnOff = null;

            System.Object value;

            // look for OnOff cluster of this end point and get the value of the on/off attribute
            var onOffCluster = m_endPoint.GetCluster(OnOffCluster.CLUSTER_ID);

            if (onOffCluster != null &&
                onOffCluster.InternalAttributeList.TryGetValue(OnOffCluster.ATTRIBUTE_ONOFF, out attributeOnOff) &&
                attributeOnOff.Read(out value) &&
                value is bool)
            {
                m_onOffState = (bool)value;
            }

            return(m_onOffState);
        }
示例#2
0
        uint GetLevelFromDevice()
        {
            if (LampDetails_Dimmable)
            {
                ZclAttribute  attributeLevel = null;
                System.Object value;

                // look for level control cluster of this end point and get the value of the current level attribute
                var levelControlCluster = m_endPoint.GetCluster(LevelControlCluster.CLUSTER_ID);
                if (levelControlCluster != null &&
                    levelControlCluster.InternalAttributeList.TryGetValue(LevelControlCluster.ATTRIBUTE_CURRENTLEVEL, out attributeLevel) &&
                    attributeLevel.Read(out value) &&
                    value is byte)
                {
                    if ((byte)(m_level / LIGHTLEVEL_SCALERATIO) != (byte)value)
                    {
                        // set m_level only if it represents different light level internally
                        m_level = LIGHTLEVEL_SCALERATIO * (byte)value;
                    }
                }
            }

            return(m_level);
        }
示例#3
0
        internal void Initialize(ZigBeeDevice device)
        {
            LoggingServices loggingServices = new LoggingServices();
            ZclAttribute    attribute       = null;

            // save away parent device
            m_device          = device;
            m_managementLeave = new ManagementLeave(m_device);

            ZigBeeProfileLibrary profileLibrary = ZigBeeProfileLibrary.Instance;
            string profileName;
            string deviceType;

            profileLibrary.GetProfileAndDeviceNames(m_originalProfileId, DeviceId, out profileName, out deviceType, out m_commandProfileId);

            // set name and description
            this.Description = profileName + " - " + deviceType;
            this.Name        = deviceType;

            //get some information from Basic cluster, e.g.: manufacturer name, model name, HW version, application version...
            if (m_basicCluster.InternalAttributeList.TryGetValue(BasicCluster.ATTRIBUTE_MANUFACTURER_NAME, out attribute))
            {
                object value;
                if (attribute.Read(out value))
                {
                    this.Vendor = (String)value;
                    //loggingServices.WriteLine<ZigBeeEndPoint>(" Vendor = ["+ this.Vendor + "]");
                }
                //else
                //{
                //    loggingServices.WriteLine<ZigBeeEndPoint>(" No Vendor");
                //}
            }
            if (m_basicCluster.InternalAttributeList.TryGetValue(BasicCluster.ATTRIBUTE_MODEL_IDENTIFIER, out attribute))
            {
                object value;
                if (attribute.Read(out value))
                {
                    this.Model = (String)value;
                    //loggingServices.WriteLine<ZigBeeEndPoint>(" Model = [" + this.Model + "]");
                }
                //else
                //{
                //    loggingServices.WriteLine<ZigBeeEndPoint>(" No Model");
                //}
            }
            if (m_basicCluster.InternalAttributeList.TryGetValue(BasicCluster.ATTRIBUTE_HW_VERSION, out attribute))
            {
                object value;
                if (attribute.Read(out value))
                {
                    this.FirmwareVersion = Convert.ToUInt32((byte)value).ToString();
                    //loggingServices.WriteLine<ZigBeeEndPoint>(" FirmwareVersion = [" + this.FirmwareVersion + "]");
                }
                //else
                //{
                //    loggingServices.WriteLine<ZigBeeEndPoint>(" No FirmwareVersion");
                //}
            }
            if (m_basicCluster.InternalAttributeList.TryGetValue(BasicCluster.ATTRIBUTE_APPLICATION_VERSION, out attribute))
            {
                object value;
                if (attribute.Read(out value))
                {
                    this.Version = Convert.ToUInt32((byte)value).ToString();
                    //loggingServices.WriteLine<ZigBeeEndPoint>(" Version = [" + this.Version + "]");
                }
                //else
                //{
                //    loggingServices.WriteLine<ZigBeeEndPoint>(" No Version");
                //}
            }

            // create AllJoyn LSF if this device is a light
            ZigBeeProfileLibrary.DeviceType zigBeeDeviceType;
            if (profileLibrary.IsLight(m_originalProfileId, DeviceId, out zigBeeDeviceType))
            {
                m_lsfHandler = new LSFHandler(this, zigBeeDeviceType);
            }

            // create signals
            CreateSignals();
        }