示例#1
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>();
        }
示例#2
0
        protected int GetZclCommandIdOffset(ref byte[] buffer)
        {
            int offset = GetZigBeePayloadOffset();

            offset += ZclHelper.GetCommandIdOffset(ref buffer, offset);
            return(offset);
        }
        public ZclDiscoverAttributes()
        {
            // ZigBee command specific
            m_isZdoCommand = false;
            int offset = ZclHelper.GetCommandIdOffset(ref m_zclHeader, 0);

            m_zclHeader[offset] = COMMAND_ID_DISCOVER_ATTRIBUTES;
        }
示例#4
0
        internal bool Write(object value)
        {
            // sanity check
            if (value == null)
            {
                return(false);
            }

            // get byte buffer from value to set
            byte[] attributeValueBuffer = ZclHelper.ToByteBufferWithType(value, m_zigBeeType);
            if (attributeValueBuffer == null)
            {
                return(false);
            }

            // set cluster Id
            m_clusterId         = m_cluster.Id;
            m_responseClusterId = m_cluster.Id;

            // set write command Id
            int offset = ZclHelper.GetCommandIdOffset(ref m_zclHeader, 0);

            m_zclHeader[offset] = COMMAND_ID_WRITE_ATTRIBUTE;

            // set payload
            byte[] tempBuffer = AdapterHelper.ToZigBeeFrame(m_Id);
            m_payload = new byte[m_zclHeader.Length + tempBuffer.Length + attributeValueBuffer.Length];
            Array.Copy(m_zclHeader, m_payload, m_zclHeader.Length);
            Array.Copy(tempBuffer, 0, m_payload, m_zclHeader.Length, tempBuffer.Length);
            Array.Copy(attributeValueBuffer, 0, m_payload, m_zclHeader.Length + tempBuffer.Length, attributeValueBuffer.Length);

            // send command
            m_responseRequired = false;
            if (!SendCommand(m_cluster.EndPoint.Device.Module, m_cluster.EndPoint.Device, m_cluster.EndPoint))
            {
                return(false);
            }

            return(true);
        }
示例#5
0
        internal bool Read(out object value)
        {
            // set value(s) to null
            Value.Data = null;
            value      = null;
            m_status   = ZclHelper.ZCL_ERROR_SUCCESS;

            // set cluster Id
            m_clusterId         = m_cluster.Id;
            m_responseClusterId = m_cluster.Id;

            // set read command Id
            int offset = ZclHelper.GetCommandIdOffset(ref m_zclHeader, 0);

            m_zclHeader[offset] = COMMAND_ID_READ_ATTRIBUTE;

            // set payload
            byte[] tempBuffer = AdapterHelper.ToZigBeeFrame(m_Id);
            m_payload = new byte[m_zclHeader.Length + tempBuffer.Length];
            Array.Copy(m_zclHeader, m_payload, m_zclHeader.Length);
            Array.Copy(tempBuffer, 0, m_payload, m_zclHeader.Length, tempBuffer.Length);

            // send command
            m_responseRequired = true;
            if (!SendCommand(m_cluster.EndPoint.Device.Module, m_cluster.EndPoint.Device, m_cluster.EndPoint))
            {
                m_status = ZclHelper.ZCL_ERROR_TIMEOUT;
                return(false);
            }

            // set out value
            if (Value.Data == null)
            {
                return(false);
            }

            value = Value.Data;

            return(true);
        }
示例#6
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;
            }
        }