예제 #1
0
        internal void Send()
        {
            byte[] tempBuffer = AdapterHelper.ToZigBeeFrame(m_device.MacAddress);
            m_payload = new byte[tempBuffer.Length + 1];

            Array.Copy(tempBuffer, m_payload, tempBuffer.Length);
            m_payload[tempBuffer.Length] = 0;

            // send command
            m_zigBeeStatus = ZdoHelper.ZDO_ERROR_SUCCESS;
            if (!SendCommand(m_device.Module, m_device))
            {
                m_zigBeeStatus = ZdoHelper.ZDO_ERROR_TIMEOUT;
            }
            HResult = ZdoHelper.ZigBeeStatusToHResult(m_zigBeeStatus);
        }
예제 #2
0
        public bool GetListOfAttributeIds(XBeeModule xbeeModule, ZigBeeDevice device, ZigBeeEndPoint endPoint, UInt16 clusterId, out List <UInt16> attributeIdList)
        {
            m_status = ZclHelper.ZCL_ERROR_SUCCESS;

            // reset list of attribute Ids
            attributeIdList = null;
            m_attributeIdList.Clear();
            m_discoveryCompleted = false;

            // set cluster Id
            m_clusterId         = clusterId;
            m_responseClusterId = clusterId;

            // add header and ZCL payload to command payload
            while (!m_discoveryCompleted)
            {
                m_payload = new byte[m_zclHeader.Length + m_zclPayload.Length];
                Array.Copy(m_zclHeader, m_payload, m_zclHeader.Length);
                // update start Id in Zcl payload if necessary
                if (m_attributeIdList.Count != 0)
                {
                    UInt16 lastId = m_attributeIdList.Last();
                    lastId++;
                    byte[] newStartId = AdapterHelper.ToZigBeeFrame(lastId);
                    Array.Copy(newStartId, 0, m_zclPayload, 0, newStartId.Length);
                }
                Array.Copy(m_zclPayload, 0, m_payload, m_zclHeader.Length, m_zclPayload.Length);

                // send command
                if (!SendCommand(xbeeModule, device, endPoint) ||
                    m_status != ZclHelper.ZCL_ERROR_SUCCESS)
                {
                    return(false);
                }
            }

            // set out value
            attributeIdList = m_attributeIdList;

            return(true);
        }
예제 #3
0
        public void GetEndPoints(XBeeModule xbeeModule, ZigBeeDevice device)
        {
            // sanity check
            if (null == device)
            {
                return;
            }

            // reset end point list
            m_endPointList.Clear();

            // set payload
            m_payload = AdapterHelper.ToZigBeeFrame(device.NetworkAddress);

            // send command
            if (!SendCommand(xbeeModule, device))
            {
                m_endPointList.Clear();
                return;
            }
        }
예제 #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
        public void GetDescriptor(XBeeModule xbeeModule, ZigBeeDevice device, byte endPointId)
        {
            // sanity check
            if (null == device)
            {
                return;
            }

            // reset (in case descriptor has already been set by previous GetDescriptor call)
            Reset();

            // set payload
            // (network address of device then end point Id)
            byte[] tempBytes = AdapterHelper.ToZigBeeFrame(device.NetworkAddress);
            Array.Copy(tempBytes, m_payload, tempBytes.Length);
            m_payload[tempBytes.Length] = endPointId;

            // send command
            if (!SendCommand(xbeeModule, device))
            {
                Reset();
            }
        }
예제 #7
0
        public static byte[] ToByteBuffer(object value)
        {
            byte[] buffer = null;
            if (value is byte ||
                value is sbyte)
            {
                buffer    = new byte[sizeof(byte)];
                buffer[0] = (byte)value;
            }
            else if (value is Int16)
            {
                buffer = AdapterHelper.ToZigBeeFrame((Int16)value);
            }
            else if (value is UInt16)
            {
                buffer = AdapterHelper.ToZigBeeFrame((UInt16)value);
            }
            else if (value is Int32)
            {
                buffer = AdapterHelper.ToZigBeeFrame((Int32)value);
            }
            else if (value is UInt32)
            {
                buffer = AdapterHelper.ToZigBeeFrame((UInt32)value);
            }
            else if (value is Int64)
            {
                buffer = AdapterHelper.ToZigBeeFrame((Int64)value);
            }
            else if (value is UInt64)
            {
                buffer = AdapterHelper.ToZigBeeFrame((UInt64)value);
            }

            return(buffer);
        }