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.pioneeravr.internal.protocol.utils;
15 import org.openhab.binding.pioneeravr.internal.protocol.avr.AvrConnectionException;
19 * @author Antoine Besnard - Initial contribution
21 public class DisplayInformationConverter {
24 * Convert an IpControl information message payload to a readable String.
26 * @param responsePayload
28 * @throws AvrConnectionException
30 public static String convertMessageFromIpControl(String responsePayload) throws AvrConnectionException {
31 // Example from Pioneer docs: When " [)(]DIGITAL EX " is displayed,
32 // response command is:
33 // FL000005064449474954414C00455800<CR+LF>
35 // First byte holds the two special flags. Do not use it to parse the
37 // Convert the ASCII values back to string
38 StringBuilder sb = new StringBuilder();
39 for (int i = 2; i < responsePayload.length() - 1; i += 2) {
40 String hexAsciiValue = responsePayload.substring(i, i + 2);
42 sb.append((char) Integer.parseInt(hexAsciiValue, 16));
43 } catch (Exception e) {
44 throw new AvrConnectionException(
45 "Failed to parse the reponsePayload as an IpControl information message.", e);