示例#1
0
        public override bool ParseResponse(byte[] buffer)
        {
            UInt16 networkAddress;
            UInt64 macAddress;

            if (!IsResponseOK(buffer))
            {
                return(false);
            }

            // verify network address matches with payload (requested network address)
            int offset = GetZdoPayloadOffset();

            // skip 1st byte (ZDO command ref)
            offset++;

            // get network and Mac address
            networkAddress = AdapterHelper.UInt16FromZigBeeFrame(buffer, offset);
            offset        += sizeof(UInt16);
            macAddress     = AdapterHelper.UInt64FromZigBeeFrame(buffer, offset);

            // ignore capability (last byte)

            if (null != OnReception)
            {
                // execute notification callback asynchronously
                // can't determine is device is an end device from DeviceAnnce => assume it is one by default
                Task.Run(() => { OnReception(networkAddress, macAddress, true); });
            }

            return(true);
        }
示例#2
0
        public override bool ParseResponse(byte[] buffer)
        {
            if (!IsResponseOK(buffer))
            {
                return(false);
            }

            // verify network address matches with payload (requested network address)
            int offset = GetZdoPayloadOffset();

            for (int index = 0; index < m_payload.Length; index++)
            {
                if (m_payload[index] != buffer[offset + index])
                {
                    return(false);
                }
            }

            // get number of end points
            offset += m_payload.Length;
            int nbOfEndPoints = Convert.ToInt32(buffer[offset]);

            if (nbOfEndPoints == 0)
            {
                return(true);
            }

            // Logging MacAddress & count of end points - by 김진엽
            byte[] macBf = new byte[20];
            int    addr  = 0;

            for (int i = 7; i >= 0; i--)
            {
                macBf[addr] = buffer[i];
                addr++;
            }
            loggingServices.WriteLine <ActiveEndPoints>("[" + AdapterHelper.UInt64FromZigBeeFrame(macBf, 0).ToString() + "] Count of EndPoints = " + nbOfEndPoints.ToString());

            // get end points
            offset++;
            for (int index = 0; index < nbOfEndPoints; index++)
            {
                m_endPointList.Add(buffer[offset + index]);
            }

            return(true);
        }
示例#3
0
        public override bool ParseResponse(byte[] buffer)
        {
            if (!IsResponseOK(buffer))
            {
                return(false);
            }

            string bfString = "";

            foreach (byte b in buffer)
            {
                bfString = bfString + Convert.ToString(b) + " ";
            }
            loggingServices.WriteLine <ManagementLQI>("GetNeighbors buffer = " + bfString);

            // get number of neighbor
            int offset = GetZdoPayloadOffset();

            m_nbOfNeighbors = Convert.ToInt32(buffer[offset]);

            if (m_nbOfNeighbors == 0)
            {
                return(true);
            }

            // get start index and count in neighbor list
            offset++;
            int startIndex    = Convert.ToInt32(buffer[offset]);
            int neighborCount = Convert.ToInt32(buffer[offset + 1]);

            /*  2017.11.03 - by 김진엽
             *  Xbee 모듈에서 보내온 버퍼에 m_nbOfNeighbors가 홀수인 경우 루프를 1회 더 수행하면서 디바이스 정보를 중복으로 가지고 오게 되는 현상 발견.
             *  안테나는 ManagementLQI 커맨드를 받으면 2개씩 끊어서 디바이스 정보를 보내오는것을 확인.
             *  이후의 로직을 수행하며 디바이스가 끊겨버리는 현상을 발생시킴. 수정 */
            if (m_nbOfNeighbors % neighborCount > 0)
            {
                m_nbOfNeighbors--;
            }
            // get neighbors from table
            offset += 2;
            for (int index = 0; index < neighborCount; index++)
            {
                string strBuffer = "";
                for (int i = 0; i < SIZEOF_NEIGHBOR_TABLE_ENTRY; i++)
                {
                    strBuffer = strBuffer + Convert.ToString(buffer[offset + i]) + " ";
                }
                // get mac address and network address from neighbor table entry
                DeviceDescriptor descriptor = new DeviceDescriptor();
                descriptor.networkAddress = AdapterHelper.UInt16FromZigBeeFrame(buffer, offset + NEIGHBOR_TABLE_ENTRY_NETWORK_ADDRESS_OFFSET);
                descriptor.macAddress     = AdapterHelper.UInt64FromZigBeeFrame(buffer, offset + NEIGHBOR_TABLE_ENTRY_MAC_ADDRESS_OFFSET);
                byte deviceType = buffer[offset + NEIGHBOR_TABLE_ENTRY_DEVICE_TYPE_OFFSET];
                descriptor.isEndDevice = ((deviceType & NEIGHBOR_TABLE_ENTRY_DEVICE_TYPE_MASK) == END_DEVICE_TYPE);

                // add device descriptor in device list
                m_neighborList.Add(descriptor);

                loggingServices.WriteLine <ManagementLQI>("[" + descriptor.macAddress + "] : " + strBuffer);
                // set offset of next entry
                offset += SIZEOF_NEIGHBOR_TABLE_ENTRY;
            }

            return(true);
        }
示例#4
0
        public static bool GetValue(byte type, ref byte[] buffer, ref int offset, out object value)
        {
            value = null;

            switch (type)
            {
            case BOOLEAN_TYPE:
            {
                if (buffer.Length >= offset + sizeof(bool))
                {
                    bool tempVal = Convert.ToBoolean(buffer[offset]);
                    value   = tempVal;
                    offset += sizeof(bool);
                }
            }
            break;

            case CHAR_STRING_TYPE:
            {
                if (buffer.Length >= offset + sizeof(byte))
                {
                    int length = Convert.ToInt32(buffer[offset]);
                    if (length != 0 &&
                        buffer.Length >= (offset + (length + 1) * sizeof(byte)))
                    {
                        offset += sizeof(byte);
                        String tempVal = Encoding.UTF8.GetString(buffer, offset, length);
                        value   = tempVal;
                        offset += (length + 1) * sizeof(byte);
                    }
                }
            }
            break;

            case INT8_TYPE:
            {
                if (buffer.Length >= offset + sizeof(sbyte))
                {
                    sbyte tempVal = (sbyte)buffer[offset];
                    value   = tempVal;
                    offset += sizeof(sbyte);
                }
            }
            break;

            case ENUMERATION_8_BIT_TYPE:            // expected fall through
            case BITMAP_8_BIT_TYPE:                 // expected fall through
            case UINT8_TYPE:
            {
                if (buffer.Length >= offset + sizeof(byte))
                {
                    byte tempVal = buffer[offset];
                    value   = tempVal;
                    offset += sizeof(byte);
                }
            }
            break;

            case INT16_TYPE:
            {
                if (buffer.Length >= offset + sizeof(Int16))
                {
                    value   = AdapterHelper.Int16FromZigBeeFrame(buffer, offset);
                    offset += sizeof(Int16);
                }
            }
            break;

            case ENUMERATION_16_BIT_TYPE:            // expected fall through
            case BITMAP_16_BIT_TYPE:                 // expected fall through
            case UINT16_TYPE:
            {
                if (buffer.Length >= offset + sizeof(UInt16))
                {
                    value   = AdapterHelper.UInt16FromZigBeeFrame(buffer, offset);
                    offset += sizeof(UInt16);
                }
            }
            break;

            case INT32_TYPE:
            {
                if (buffer.Length >= offset + sizeof(Int32))
                {
                    value   = AdapterHelper.Int32FromZigBeeFrame(buffer, offset);
                    offset += sizeof(Int32);
                }
            }
            break;

            case UINT32_TYPE:
            {
                if (buffer.Length >= offset + sizeof(UInt32))
                {
                    value   = AdapterHelper.UInt32FromZigBeeFrame(buffer, offset);
                    offset += sizeof(UInt32);
                }
            }
            break;

            case IEEE_ADDRESS_TYPE:
            {
                if (buffer.Length >= offset + sizeof(UInt64))
                {
                    value   = AdapterHelper.UInt64FromZigBeeFrame(buffer, offset);
                    offset += sizeof(UInt64);
                }
            }
            break;
            }

            if (value != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }