public Task Set(byte parameter, object value, byte size, CancellationToken cancellationToken = default)
        {
            if (size < 1 || size > 4)
            {
                throw new ArgumentOutOfRangeException(nameof(size), size, "Size must be between 1 and 4");
            }

            using (var writer = new PayloadWriter())
            {
                writer.WriteByte(parameter);
                writer.WriteByte(size);
                switch (size)
                {
                case 1:
                    writer.WriteByte(Convert.ToByte(value));
                    break;

                case 2:
                    writer.WriteInt16(Convert.ToInt16(value));
                    break;

                case 3:
                    writer.WriteInt24(Convert.ToInt16(value));
                    break;

                case 4:
                    writer.WriteInt32(Convert.ToInt32(value));
                    break;
                }
                var command = new Command(CommandClass, ConfigurationCommand.Set, writer.ToPayload());
                return(Send(command, cancellationToken));
            }
        }
Example #2
0
        internal RequestMessage Encode(ControllerRequest command, byte?callbackID)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            // create writer to serialize te request
            using (var writer = new PayloadWriter())
            {
                // write the function
                writer.WriteByte((byte)command.Function);

                // does the command has payload?
                if (command.Payload != null)
                {
                    // yes, so write the payload
                    writer.WriteObject(command.Payload);
                }

                if (callbackID != null)
                {
                    // write the callback
                    writer.WriteByte(callbackID.Value);
                }

                // create a hostmessage, use the serialized payload
                return(new RequestMessage(writer.ToPayload()));
            }
        }
Example #3
0
        public Task SetInterval(TimeSpan interval, byte targetNodeID, CancellationToken cancellationToken = default)
        {
            using (var writer = new PayloadWriter())
            {
                writer.WriteInt24((int)interval.TotalSeconds);
                writer.WriteByte(targetNodeID);

                var command = new Command(CommandClass, WakeUpCommand.IntervalSet, writer.ToPayload());
                return(Send(command, cancellationToken));
            }
        }