Ejemplo n.º 1
0
        public uint SetProperty(
            IAdapterProperty Property,
            out IAdapterIoRequest RequestPtr)
        {
            RequestPtr = null;

            // sanity check
            if (Property == null)
            {
                return(ERROR_INVALID_PARAMETER);
            }

            // cast back IAdapterProperty to ZclCluster
            ZclCluster cluster = (ZclCluster)Property;

            // write new value for all attributes
            // note that it is assumed that BridgeRT has set the new value
            // for each attribute
            foreach (var item in cluster.InternalAttributeList)
            {
                var attribute = item.Value;
                if (attribute.Write(attribute.Value.Data))
                {
                    // give up at 1st write error
                    return((uint)ZclHelper.ZigBeeStatusToHResult(attribute.Status));
                }
            }

            return(ERROR_SUCCESS);
        }
Ejemplo n.º 2
0
        internal void SignalChangeOfAttributeValue(ZigBeeEndPoint endPoint, ZclCluster cluster, ZclAttribute attribute)
        {
            // find change of value signal of that end point (end point == bridgeRT device)
            var covSignal = endPoint.Signals.OfType <AdapterSignal>().FirstOrDefault(s => s.Name == Constants.CHANGE_OF_VALUE_SIGNAL);

            if (covSignal == null)
            {
                // no change of value signal
                return;
            }

            // set property and attribute param of COV signal
            // note that
            // - ZCL cluster correspond to BridgeRT property
            // - ZCL attribute correspond to BridgeRT attribute
            var param = covSignal.Params.FirstOrDefault(p => p.Name == Constants.COV__PROPERTY_HANDLE);

            if (param == null)
            {
                // signal doesn't have the expected parameter
                return;
            }
            param.Data = cluster;

            param = covSignal.Params.FirstOrDefault(p => p.Name == Constants.COV__ATTRIBUTE_HANDLE);
            if (param == null)
            {
                // signal doesn't have the expected parameter
                return;
            }
            param.Data = attribute;

            // signal change of value to BridgeRT
            NotifySignalListeners(covSignal);
        }
Ejemplo n.º 3
0
        public uint SetPropertyValue(
            IAdapterProperty Property,
            IAdapterValue Value,
            out IAdapterIoRequest RequestPtr)
        {
            RequestPtr = null;

            // sanity check
            if (Property == null)
            {
                return(ERROR_INVALID_PARAMETER);
            }

            // cast back IAdapterProperty to ZclCluster
            ZclCluster cluster = (ZclCluster)Property;

            // look for the attribute and write new data
            foreach (var item in cluster.InternalAttributeList)
            {
                var attribute = item.Value;
                if (attribute.Value.Name == Value.Name)
                {
                    if (attribute.Write(Value.Data))
                    {
                        return(ERROR_SUCCESS);
                    }
                    else
                    {
                        return((uint)ZclHelper.ZigBeeStatusToHResult(attribute.Status));
                    }
                }
            }

            return(ERROR_NOT_SUPPORTED);
        }
Ejemplo n.º 4
0
        public uint GetProperty(
            IAdapterProperty Property,
            out IAdapterIoRequest RequestPtr)
        {
            RequestPtr = null;

            // sanity check
            if (Property == null)
            {
                return(ERROR_INVALID_PARAMETER);
            }

            // cast back IAdapterProperty to ZclCluster
            ZclCluster cluster = (ZclCluster)Property;

            // read all attributes for the attribute
            foreach (var item in cluster.InternalAttributeList)
            {
                var    attribute = item.Value;
                object value;
                if (!attribute.Read(out value))
                {
                    // give up at 1st read error
                    return((uint)ZclHelper.ZigBeeStatusToHResult(attribute.Status));
                }
            }

            return(ERROR_SUCCESS);
        }
Ejemplo n.º 5
0
        internal ZclCommand(ZclCluster cluster, byte id, String name, bool specificResponseRequired)
        {
            m_cluster      = cluster;
            m_Id           = id;
            m_zigBeeStatus = ZclHelper.ZCL_ERROR_SUCCESS;

            // as far as ZigBeeCommand class is concerned a response will always be required
            // ZCL will use the Default Response if ZclCommand require no specific response
            m_responseRequired = true;
            if (specificResponseRequired)
            {
                m_useDefaultResponse = false;
            }
            else
            {
                m_useDefaultResponse = true;
            }

            this.Name        = m_cluster.Name + "_" + name;
            this.Description = null;
            this.HResult     = ZclHelper.ZigBeeStatusToHResult(m_zigBeeStatus);

            m_isZdoCommand = false;
            ZclHelper.SetClusterSpecificHeader(ref m_zclHeader, 0);
            int offset = ZclHelper.GetCommandIdOffset(ref m_zclHeader, 0);

            m_zclHeader[offset] = m_Id;

            m_zclInParamList = new List <ZclValue>();
            InputParams      = new List <IAdapterValue>();
            OutputParams     = new List <IAdapterValue>();
        }
Ejemplo n.º 6
0
        internal ZclCluster GetCluster(UInt16 clusterId)
        {
            ZclCluster cluster = null;

            // 1st check in in cluster list then in out cluster list (if necessary)
            if (!m_inClusters.TryGetValue(clusterId, out cluster))
            {
                m_outClusters.TryGetValue(clusterId, out cluster);
            }

            return(cluster);
        }
Ejemplo n.º 7
0
        public ZclCluster CreateClusterInstance(ZigBeeEndPoint endPoint, UInt16 clusterId, List <UInt16> supportedAttributes)
        {
            // create instance of cluster depending on its Id,
            // e.g.: create OnOffCluster instance if id correspond to OnOff cluster
            ZclCluster cluster = null;

            if (IsClusterSupported(clusterId))
            {
                switch (clusterId)
                {
                case PowerConfigurationCluster.CLUSTER_ID:
                    cluster = new PowerConfigurationCluster(endPoint, supportedAttributes);
                    break;

                case OnOffCluster.CLUSTER_ID:
                    cluster = new OnOffCluster(endPoint, supportedAttributes);
                    break;

                case LevelControlCluster.CLUSTER_ID:
                    cluster = new LevelControlCluster(endPoint, supportedAttributes);
                    break;

                case AlarmCluster.CLUSTER_ID:
                    cluster = new AlarmCluster(endPoint, supportedAttributes);
                    break;

                case DoorLockCluster.CLUSTER_ID:
                    cluster = new DoorLockCluster(endPoint, supportedAttributes);
                    break;

                case ColorControlCluster.CLUSTER_ID:
                    cluster = new ColorControlCluster(endPoint, supportedAttributes);
                    break;

                case TemperatureCluster.CLUSTER_ID:
                    cluster = new TemperatureCluster(endPoint, supportedAttributes);
                    break;

                case RelativeHumidityCluster.CLUSTER_ID:
                    cluster = new RelativeHumidityCluster(endPoint, supportedAttributes);
                    break;

                case IASZoneCluster.CLUSTER_ID:
                    cluster = new IASZoneCluster(endPoint, supportedAttributes);
                    break;
                }
            }
            return(cluster);
        }
Ejemplo n.º 8
0
        private void ZclReportAttributeReception(ZclReportAttributes.SOURCE_INFO deviceInfo, UInt16 attributeId, object newValue)
        {
            ZigBeeDevice   device    = null;
            ZigBeeEndPoint endPoint  = null;
            ZclCluster     cluster   = null;
            ZclAttribute   attribute = null;

            // look for corresponding ZigBee device
            lock (m_deviceMap)
            {
                if (!m_deviceMap.TryGetValue(deviceInfo.macAddress, out device))
                {
                    // unknown device => do nothing
                    return;
                }
            }

            // look for corresponding end point
            if (!device.EndPointList.TryGetValue(deviceInfo.endpointId, out endPoint))
            {
                // unknown end point => do nothing
                return;
            }

            // look for corresponding cluster
            cluster = endPoint.GetCluster(deviceInfo.clusterId);
            if (cluster == null)
            {
                // unknown cluster => do nothing
                return;
            }

            // look for the corresponding attribute
            if (cluster.InternalAttributeList.TryGetValue(attributeId, out attribute))
            {
                // unknown attribute => do nothing
                return;
            }

            // update value
            attribute.Value.Data = newValue;

            // signal value of attribute has changed
            SignalChangeOfAttributeValue(endPoint, cluster, attribute);
        }
Ejemplo n.º 9
0
        public uint GetPropertyValue(
            IAdapterProperty Property,
            string AttributeName,
            out IAdapterValue ValuePtr,
            out IAdapterIoRequest RequestPtr)
        {
            ValuePtr   = null;
            RequestPtr = null;

            // sanity check
            if (Property == null)
            {
                return(ERROR_INVALID_PARAMETER);
            }

            // cast back IAdapterProperty to ZclCluster
            ZclCluster cluster = (ZclCluster)Property;

            // look for the attribute
            foreach (var item in cluster.InternalAttributeList)
            {
                var attribute = item.Value;
                if (attribute.Value.Name == AttributeName)
                {
                    object value;
                    if (attribute.Read(out value))
                    {
                        ValuePtr = attribute.Value;
                        return(ERROR_SUCCESS);
                    }
                    else
                    {
                        return((uint)ZclHelper.ZigBeeStatusToHResult(attribute.Status));
                    }
                }
            }

            return(ERROR_NOT_SUPPORTED);
        }
Ejemplo n.º 10
0
        internal ZclAttribute(ZclCluster cluster, UInt16 id, String name, byte zigBeeType, bool isReadOnly = false, bool isOptional = false, bool isReportable = false)
        {
            // save parent cluster
            m_cluster = cluster;

            // attribute specific
            m_Id         = id;
            m_isReadOnly = isReadOnly;
            m_isOptional = isOptional;
            m_zigBeeType = zigBeeType;

            // ZigBee command specific
            m_isZdoCommand = false;
            int offset = ZclHelper.GetCommandIdOffset(ref m_zclHeader, 0);

            m_zclHeader[offset] = COMMAND_ID_READ_ATTRIBUTE;

            // BridgeRT specific
            Value       = new ZclValue(zigBeeType, name);
            Annotations = new Dictionary <string, string>();
            if (isReadOnly)
            {
                Access = E_ACCESS_TYPE.ACCESS_READ;
            }
            else
            {
                Access = E_ACCESS_TYPE.ACCESS_READWRITE;
            }
            if (isReportable)
            {
                COVBehavior = SignalBehavior.Always;
            }
            else
            {
                COVBehavior = SignalBehavior.Unspecified;
            }
        }
Ejemplo n.º 11
0
 public ZclServerCommand(ZclCluster cluster, byte commandId)
 {
     m_cluster   = cluster;
     m_commandId = commandId;
 }