]> git.basschouten.com Git - openhab-addons.git/blob
873355ac60d7f5c3b9d59f0704073f1d4a300e05
[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.sinope.internal.core;
14
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.util.Arrays;
18
19 import org.openhab.binding.sinope.internal.core.base.SinopeAnswer;
20 import org.openhab.binding.sinope.internal.util.ByteUtil;
21
22 /**
23  * The Class SinopeDeviceReportAnswer.
24  * 
25  * @author Pascal Larin - Initial contribution
26  */
27 public class SinopeDeviceReportAnswer extends SinopeAnswer {
28
29     /** The Constant STATUS_SIZE. */
30     protected static final int STATUS_SIZE = 1;
31
32     /** The Constant DEVICE_ID_SIZE. */
33     protected static final int DEVICE_ID_SIZE = 4;
34
35     /**
36      * Instantiates a new sinope device report answer.
37      *
38      * @param r the r
39      * @throws IOException Signals that an I/O exception has occurred.
40      */
41     public SinopeDeviceReportAnswer(InputStream r) throws IOException {
42         super(r);
43     }
44
45     /**
46      * @see org.openhab.binding.sinope.internal.core.base.SinopeFrame#getCommand()
47      */
48     @Override
49     protected byte[] getCommand() {
50         return new byte[] { 0x01, 0x16 };
51     }
52
53     /**
54      * Gets the status.
55      *
56      * @return the status
57      */
58     public byte getStatus() {
59         byte[] b = this.getFrameData();
60         return b[0];
61     }
62
63     /**
64      * Gets the device id.
65      *
66      * @return the device id
67      */
68     public byte[] getDeviceId() {
69         byte[] b = this.getFrameData();
70         b = Arrays.copyOfRange(b, STATUS_SIZE, STATUS_SIZE + DEVICE_ID_SIZE);
71         return ByteUtil.reverse(b);
72     }
73
74     /**
75      * @see org.openhab.binding.sinope.internal.core.base.SinopeFrame#toString()
76      */
77     @Override
78     public String toString() {
79         StringBuilder sb = new StringBuilder();
80         sb.append(super.toString());
81         sb.append(String.format("\nStatus: 0x%02X ", getStatus()));
82         sb.append(String.format("\n\tDeviceId: %s", ByteUtil.toString(getDeviceId())));
83         return sb.toString();
84     }
85 }