Esempio n. 1
0
        public static AttributeBaseResponse Create(byte[] payload)
        {
            bool isManufacturerSpecific = BitHelpers.GetBit(payload[0], 6);
            var  commandID = isManufacturerSpecific ? payload[7] : payload[6];

            switch (commandID)
            {
            case 0x01: return(new ReadAttributesResponse(payload));

            case 0x0A: return(new ReportAttributesResponse(payload));

            case 0x0B: return(new DefaultAttributesResponse(payload));

            case 0x0D: return(new DiscoverAttributesResponse(payload));

            default: return(new UnknownAttributeResponse(payload));
            }
        }
Esempio n. 2
0
 public Attribute(byte[] data)
 {
     AttributeID = BitHelpers.ToUInt16(data, 0);
     DataType    = (ZigbeeDataType)data[2];
 }
Esempio n. 3
0
        internal AttributeRecord(byte[] data, int start, out int length, bool includeStatusByte = false)
        {
            AttributeID = BitHelpers.ToUInt16(data, start);
            if (includeStatusByte)
            {
                Success = data[start + 1] == 0x00;
            }
            int offset = includeStatusByte ? 1 : 0;

            DataType = (ZigbeeDataType)data[start + 2 + offset];
            length   = 3 + offset;

            switch (DataType)
            {
            case ZigbeeDataType.UInt8:
            case ZigbeeDataType.GeneralData8Bit:
            case ZigbeeDataType.Enumeration8:
                Data = data[start + length++];
                break;

            case ZigbeeDataType.GeneralData16Bit:
                Data    = data.Skip(start + length).Take(2).ToArray();
                length += 2;
                break;

            case ZigbeeDataType.GeneralData24Bit:
                Data    = data.Skip(start + length).Take(3).ToArray();
                length += 3;
                break;

            case ZigbeeDataType.GeneralData32Bit:
                Data    = data.Skip(start + length).Take(4).ToArray();
                length += 4;
                break;

            case ZigbeeDataType.GeneralData40Bit:
                Data    = data.Skip(start + length).Take(5).ToArray();
                length += 5;
                break;

            case ZigbeeDataType.GeneralData48Bit:
                Data    = data.Skip(start + length).Take(6).ToArray();
                length += 6;
                break;

            case ZigbeeDataType.GeneralData56Bit:
                Data    = data.Skip(start + length).Take(7).ToArray();
                length += 7;
                break;

            case ZigbeeDataType.GeneralData64Bit:
                Data    = data.Skip(start + length).Take(8).ToArray();
                length += 8;
                break;

            case ZigbeeDataType.Boolean:
                Data = data[start + length++] == 0x01;                         //TODO: 0xff means invalid
                break;

            case ZigbeeDataType.Array:
                ushort len = BitHelpers.ToUInt16(data, 0);
                length += 2;
                Data    = data.Skip(start + length).Take(len).ToArray();
                break;

            case ZigbeeDataType.UInt16:
            case ZigbeeDataType.Enumeration16:
            case ZigbeeDataType.ClusterID:
            case ZigbeeDataType.AttributeID:
                Data    = BitHelpers.ToUInt16(data, start + length);
                length += 2;
                break;

            case ZigbeeDataType.UInt32:
                Data    = BitHelpers.ToUInt32(data, start + length);
                length += 4;
                break;

            case ZigbeeDataType.UInt48:
                Data = BitHelpers.ToUInt64((new byte[] { 0x00, 0x00 }).Concat(data.Skip(start + length).Take(6)).ToArray(), 0);
                System.Diagnostics.Debug.WriteLine("UInt48 not supported");
                length += 6;
                break;

            case ZigbeeDataType.UInt64:
                Data    = BitHelpers.ToUInt64(data, start + length);
                length += 8;
                break;

            case ZigbeeDataType.Int16:
                Data    = BitHelpers.ToInt16(data, start + length);
                length += 2;
                break;

            case ZigbeeDataType.TimeOfDay:
                Data    = new TimeSpan(data[start + length], data[start + length + 1], data[start + length + 2], data[start + length + 3] + 10);
                length += 4;
                break;

            case ZigbeeDataType.Date:
                Data    = new DateTime(data[start + length] + 1900, data[start + length + 1], data[start + length + 2]);
                length += 4;
                break;

            case ZigbeeDataType.UtcTime:
                Data    = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(BitHelpers.ToUInt32(data, start + length));
                length += 4;
                break;

            case ZigbeeDataType.Null:
                break;

            default:
                //TODO
                System.Diagnostics.Debug.WriteLine("Unknown data type: " + DataType.ToString());
                break;
            }
        }