2 * Copyright (c) 2010-2020 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.powermax.internal.message;
15 import java.util.Arrays;
17 import org.openhab.binding.powermax.internal.state.PowermaxState;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
22 * A class for SETTINGS and SETTINGS_ITEM messages handling
24 * @author Laurent Garnier - Initial contribution
26 public class PowermaxSettingsMessage extends PowermaxBaseMessage {
28 private final Logger logger = LoggerFactory.getLogger(PowermaxSettingsMessage.class);
34 * the received message as a buffer of bytes
36 public PowermaxSettingsMessage(byte[] message) {
41 protected PowermaxState handleMessageInternal(PowermaxCommManager commManager) {
42 if (commManager == null) {
46 PowermaxState updatedState = commManager.createNewState();
48 byte[] message = getRawData();
49 int index = message[2] & 0x000000FF;
50 int page = message[3] & 0x000000FF;
53 debug("Page", page, Integer.toString(page));
54 debug("Index", index, Integer.toString(index));
56 if (getReceiveType() == PowermaxReceiveType.SETTINGS) {
57 length = message.length - 6;
58 updatedState.setUpdateSettings(Arrays.copyOfRange(message, 2, 2 + 2 + length));
59 } else if (getReceiveType() == PowermaxReceiveType.SETTINGS_ITEM) {
60 length = message[4] & 0x000000FF;
61 byte[] data = new byte[length + 2];
63 for (int j = 2; j <= 3; j++) {
64 data[i++] = message[j];
66 for (int j = 0; j < length; j++) {
67 data[i++] = message[j + 5];
69 updatedState.setUpdateSettings(data);
71 if (logger.isDebugEnabled()) {
72 logger.debug("Received Powermax setting page {} index {} length {}", String.format("%02X (%d)", page, page),
73 String.format("%02X (%d)", index, index), String.format("%02X (%d)", length, length));