예제 #1
0
        void IPayloadSerializable.Read(PayloadReader reader)
        {
            NodeID = reader.ReadByte();
            var basicType    = (BasicType)reader.ReadByte();
            var genericType  = (GenericType)reader.ReadByte();
            var specificType = reader.ReadSpecificType(genericType);

            NodeType = new NodeType(basicType, genericType, specificType);

            SupportedCommandClasses = reader
                                      .ReadBytes(reader.Length - reader.Position)
                                      .TakeWhile(x => x != 0xEF)
                                      .Select(x => (CommandClass)x)
                                      .OrderBy(element => element.ToString())
                                      .ToArray();
        }
예제 #2
0
        void IPayloadSerializable.Read(PayloadReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            Capability = reader.ReadByte();
            Security   = (Security)reader.ReadByte();
            Reserved   = reader.ReadByte();

            var basicType    = (BasicType)reader.ReadByte();
            var genericType  = (GenericType)reader.ReadByte();
            var specificType = reader.ReadSpecificType(genericType);

            NodeType = new NodeType(basicType, genericType, specificType);
        }
예제 #3
0
        /// <summary>
        /// Opens the controller
        /// </summary>
        /// <param name="softReset">True to perform a sofreset, False otherwise</param>
        /// <returns>A task that represents the asynchronous operation</returns>
        public async Task Open(bool softReset = false)
        {
            await Channel.Open(softReset);

            var getVersion = await Channel.Send <Payload>(new ControllerRequest(Function.GetVersion));

            using (var reader = new PayloadReader(getVersion))
            {
                Version = reader.ReadString();
            }

            var memoryGetId = await Channel.Send <Payload>(new ControllerRequest(Function.MemoryGetId));

            using (var reader = new PayloadReader(memoryGetId))
            {
                HomeID = reader.ReadUInt32();
                NodeID = reader.ReadByte();
            }

            var discoveryNodes = await Channel.Send <Payload>(new ControllerRequest(Function.DiscoveryNodes));

            using (var reader = new PayloadReader(discoveryNodes))
            {
                var version      = reader.ReadByte();
                var capabilities = reader.ReadByte();
                var length       = reader.ReadByte();
                var nodes        = reader.ReadBytes(length);

                var bits = new BitArray(nodes);
                for (byte i = 0; i < bits.Length; i++)
                {
                    if (bits[i])
                    {
                        var node = Factory.CreateNode((byte)(i + 1), this);

                        await node.Initialize();

                        Nodes.Add(node);
                    }
                }

                ChipType = (ZWaveChipType)reader.ReadUInt16();
            }
        }
예제 #4
0
        void IPayloadSerializable.Read(PayloadReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            State  = (NodeUpdateState)reader.ReadByte();
            NodeID = reader.ReadByte();

            var length = reader.ReadByte();

            if (length > 0 && State == NodeUpdateState.InfoReceived)
            {
                // push NodeID in the payload so NodeInfo has access to the node
                var payload = new Payload(new byte[] { NodeID }.Concat(reader.ReadBytes(reader.Length - reader.Position)));
                Info = payload.Deserialize <NodeInfo>();
            }
        }
예제 #5
0
        internal static SpecificType ReadSpecificType(this PayloadReader reader, GenericType genericType)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            var specificType = reader.ReadByte();

            if (specificType == 0)
            {
                return(SpecificType.NotUsed);
            }
            else
            {
                return((SpecificType)((int)genericType << 16 | specificType));
            }
        }