]> git.basschouten.com Git - openhab-addons.git/blob
eb654d53d40f6dec46228e9ef9587b6c84af7958
[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;
14
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * Represents the display status message send by the Pioneer AV receiver
20  * (response to "?FL" request)
21  *
22  * @author Rainer Ostendorf - Initial contribution
23  */
24 public class DisplayInformation {
25
26     private final Logger logger = LoggerFactory.getLogger(DisplayInformation.class);
27
28     private Boolean volumeDisplay; // 1-light, 0-OFF
29     private Boolean guidIcon; // 1-light, 0-OFF
30     private String infoText = ""; // the actual display text
31
32     /**
33      * parse the display status text send from the receiver
34      *
35      * @param responsePayload the responses payload, that is without the leading "FL"
36      *
37      * @return
38      */
39     public DisplayInformation(String responsePayload) {
40         volumeDisplay = false;
41         guidIcon = false;
42         infoText = "";
43
44         // Example from Pioneer docs: When " [)(]DIGITAL EX " is displayed, response command is:
45         // FL000005064449474954414C00455800<CR+LF>
46
47         // first byte holds the two special flags
48         byte firstByte = (byte) Integer.parseInt(responsePayload.substring(0, 1), 16);
49
50         if ((firstByte & (1 << 0)) == (1 << 0)) {
51             guidIcon = true;
52         }
53         if ((firstByte & (1 << 1)) == (1 << 1)) {
54             volumeDisplay = true;
55         }
56
57         // convert the ascii values back to string
58         StringBuilder sb = new StringBuilder();
59         for (int i = 2; i < responsePayload.length() - 1; i += 2) {
60             String hexAsciiValue = responsePayload.substring(i, i + 2);
61             try {
62                 sb.append((char) Integer.parseInt(hexAsciiValue, 16));
63             } catch (Exception e) {
64                 logger.error("parsing string failed '{}'", responsePayload, e);
65             }
66         }
67         infoText = sb.toString();
68     }
69
70     public String getInfoText() {
71         return infoText;
72     }
73
74     public void setInfoText(String infoText) {
75         this.infoText = infoText;
76     }
77
78     public Boolean getVolumeDisplay() {
79         return volumeDisplay;
80     }
81
82     public Boolean getGuidIcon() {
83         return guidIcon;
84     }
85 }