コード例 #1
0
ファイル: Payload.cs プロジェクト: roblans/ZWave4Net-v2
        void IPayloadSerializable.Read(PayloadReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            _values = reader.ReadBytes(reader.Length - reader.Position);
        }
コード例 #2
0
        public static T ReadObject <T>(this PayloadReader reader) where T : IPayloadSerializable, new()
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            var instance = new T();

            instance.Read(reader);
            return(instance);
        }
コード例 #3
0
        public static T Deserialize <T>(this Payload payload) where T : IPayloadSerializable, new()
        {
            if (payload == null)
            {
                throw new ArgumentNullException(nameof(payload));
            }

            using (var reader = new PayloadReader(payload))
            {
                return(reader.ReadObject <T>());
            }
        }
コード例 #4
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();
        }
コード例 #5
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);
        }
コード例 #6
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));
            }
        }
コード例 #7
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();
            }
        }
コード例 #8
0
ファイル: NodeUpdate.cs プロジェクト: roblans/ZWave4Net-v2
        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>();
            }
        }