예제 #1
0
        private async Task Set(byte parameter, long value, bool signed, byte size = 0)
        {
            if (size == 0)
            {
                // extra roundtrip to get the correct size of the parameter
                var response = await Channel.Send(Node, new Command(Class, command.Get, parameter), command.Report);

                size = response[1];
            }

            var values = default(byte[]);

            switch (size)
            {
            case 1:
                values = signed ? PayloadConverter.GetBytes((sbyte)value) : PayloadConverter.GetBytes((byte)value);
                break;

            case 2:
                values = signed ? PayloadConverter.GetBytes((short)value) : PayloadConverter.GetBytes((ushort)value);
                break;

            case 4:
                values = signed ? PayloadConverter.GetBytes((int)value) : PayloadConverter.GetBytes((uint)value);
                break;

            case 8:
                values = signed ? PayloadConverter.GetBytes((long)value) : PayloadConverter.GetBytes((ulong)value);
                break;

            default:
                throw new NotSupportedException($"Size:{size} is not supported");
            }
            await Channel.Send(Node, new Command(Class, command.Set, new[] { parameter, (byte)values.Length }.Concat(values).ToArray()));
        }
예제 #2
0
        public async Task Set(ThermostatSetpointType type, float value, CancellationToken cancellationToken)
        {
            // encode value, decimals = 1, scale = 0 (°C)
            var encoded = PayloadConverter.GetBytes(value, decimals: 1, scale: 0);

            var payload = new byte[] { Convert.ToByte(type) }.Concat(encoded).ToArray();
            await Channel.Send(Node, new Command(Class, command.Set, payload), cancellationToken);
        }
예제 #3
0
 public async Task SetInterval(TimeSpan interval, byte targetNodeID)
 {
     var seconds = PayloadConverter.GetBytes((uint)interval.TotalSeconds);
     await Channel.Send(Node, new Command(Class, command.IntervalSet, seconds[1], seconds[2], seconds[3], targetNodeID));
 }