2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.sinope.internal.core;
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.util.Arrays;
19 import org.openhab.binding.sinope.internal.core.base.SinopeAnswer;
20 import org.openhab.binding.sinope.internal.util.ByteUtil;
23 * The Class SinopeApiLoginAnswer.
25 * @author Pascal Larin - Initial contribution
27 public class SinopeApiLoginAnswer extends SinopeAnswer {
29 /** The Constant STATUS_SIZE. */
30 protected static final int STATUS_SIZE = 1;
32 /** The Constant BACKOFF_SIZE. */
33 protected static final int BACKOFF_SIZE = 2;
35 /** The Constant SW_REV_MAJ_SIZE. */
36 protected static final int SW_REV_MAJ_SIZE = 1;
38 /** The Constant SW_REV_MIN_SIZE. */
39 protected static final int SW_REV_MIN_SIZE = 1;
41 /** The Constant SW_REV_BUG_SIZE. */
42 protected static final int SW_REV_BUG_SIZE = 1;
44 /** The Constant DEVICE_ID_SIZE. */
45 protected static final int DEVICE_ID_SIZE = 4;
48 * Instantiates a new sinope api login answer.
51 * @throws IOException Signals that an I/O exception has occurred.
53 public SinopeApiLoginAnswer(InputStream r) throws IOException {
58 * @see org.openhab.binding.sinope.internal.core.base.SinopeFrame#getCommand()
61 protected byte[] getCommand() {
62 return new byte[] { 0x01, 0x11 };
70 public byte getStatus() {
71 byte[] b = this.getFrameData();
80 public byte[] getBackoff() {
81 byte[] b = this.getFrameData();
82 b = Arrays.copyOfRange(b, STATUS_SIZE, STATUS_SIZE + BACKOFF_SIZE);
87 * Gets the sw rev maj.
89 * @return the sw rev maj
91 public byte getSwRevMaj() {
92 byte[] b = this.getFrameData();
93 return b[STATUS_SIZE + BACKOFF_SIZE];
97 * Gets the sw rev min.
99 * @return the sw rev min
101 public byte getSwRevMin() {
102 byte[] b = this.getFrameData();
103 return b[STATUS_SIZE + BACKOFF_SIZE + SW_REV_MAJ_SIZE];
107 * Gets the sw rev bug.
109 * @return the sw rev bug
111 public byte getSwRevBug() {
112 byte[] b = this.getFrameData();
113 return b[STATUS_SIZE + BACKOFF_SIZE + SW_REV_MAJ_SIZE + SW_REV_MIN_SIZE];
117 * Gets the device id.
119 * @return the device id
121 public byte[] getDeviceId() {
122 byte[] b = this.getFrameData();
123 b = Arrays.copyOfRange(b, STATUS_SIZE + BACKOFF_SIZE + SW_REV_MAJ_SIZE + SW_REV_MIN_SIZE + SW_REV_BUG_SIZE,
124 STATUS_SIZE + BACKOFF_SIZE + SW_REV_MAJ_SIZE + SW_REV_MIN_SIZE + SW_REV_BUG_SIZE + DEVICE_ID_SIZE);
125 return ByteUtil.reverse(b);
129 * @see org.openhab.binding.sinope.internal.core.base.SinopeFrame#toString()
132 public String toString() {
133 StringBuilder sb = new StringBuilder();
134 sb.append(super.toString());
135 sb.append(String.format("\nData: %s", ByteUtil.toString(getFrameData())));
136 sb.append(String.format("\n\tStatus: 0x%02X ", getStatus()));
137 sb.append(String.format("\n\tBackoff: %s", ByteUtil.toString(getBackoff())));
138 sb.append(String.format("\n\tSwRevMaj: 0x%02X ", getSwRevMaj()));
139 sb.append(String.format("\n\tSwRevMin: 0x%02X ", getSwRevMin()));
140 sb.append(String.format("\n\tSwRevBug: 0x%02X ", getSwRevBug()));
141 sb.append(String.format("\n\tDeviceID: %s", ByteUtil.toString(getDeviceId())));
143 return sb.toString();