]> git.basschouten.com Git - openhab-addons.git/blob
220af39f4c348cd261da0d7a35490f841000e83a
[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.pioneeravr.internal.protocol.utils;
14
15 import org.openhab.binding.pioneeravr.internal.protocol.avr.AvrConnectionException;
16
17 /**
18  *
19  * @author Antoine Besnard - Initial contribution
20  */
21 public class DisplayInformationConverter {
22
23     /**
24      * Convert an IpControl information message payload to a readable String.
25      *
26      * @param responsePayload
27      * @return
28      * @throws AvrConnectionException
29      */
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>
34
35         // First byte holds the two special flags. Do not use it to parse the
36         // message.
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);
41             try {
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);
46             }
47         }
48         return sb.toString();
49     }
50 }