]> git.basschouten.com Git - openhab-addons.git/blob
a2ed78ca6adc311e93fb40da88c0904bf2cae6fc
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.lifx.internal.dto;
14
15 import java.nio.ByteBuffer;
16
17 import org.openhab.binding.lifx.internal.fields.Field;
18 import org.openhab.binding.lifx.internal.fields.LittleField;
19 import org.openhab.binding.lifx.internal.fields.UInt32Field;
20 import org.openhab.binding.lifx.internal.fields.UInt8Field;
21
22 /**
23  * @author Tim Buckley - Initial contribution
24  * @author Karel Goderis - Enhancement for the V2 LIFX Firmware and LAN Protocol Specification
25  */
26 public class StateServiceResponse extends Packet {
27
28     public static final int TYPE = 0x03;
29
30     public static final Field<Integer> FIELD_SERVICE = new UInt8Field();
31     public static final Field<Long> FIELD_PORT = new LittleField<>(new UInt32Field());
32
33     private int service;
34     private long port;
35
36     public int getService() {
37         return service;
38     }
39
40     public long getPort() {
41         return port;
42     }
43
44     public StateServiceResponse() {
45     }
46
47     @Override
48     protected void parsePacket(ByteBuffer bytes) {
49         service = FIELD_SERVICE.value(bytes);
50         port = FIELD_PORT.value(bytes);
51     }
52
53     @Override
54     public int packetType() {
55         return TYPE;
56     }
57
58     @Override
59     protected int packetLength() {
60         return 5;
61     }
62
63     @Override
64     protected ByteBuffer packetBytes() {
65         return ByteBuffer.allocate(packetLength()).put(FIELD_SERVICE.bytes(service)).put(FIELD_PORT.bytes(port));
66     }
67
68     @Override
69     public int[] expectedResponses() {
70         return new int[] {};
71     }
72 }