]> git.basschouten.com Git - openhab-addons.git/blob
195d54a11154495b41bc34f9b9e3c979bbd21c67
[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     public DisplayInformation(String responsePayload) {
38         volumeDisplay = false;
39         guidIcon = false;
40         infoText = "";
41
42         // Example from Pioneer docs: When " [)(]DIGITAL EX " is displayed, response command is:
43         // FL000005064449474954414C00455800<CR+LF>
44
45         // first byte holds the two special flags
46         byte firstByte = (byte) Integer.parseInt(responsePayload.substring(0, 1), 16);
47
48         if ((firstByte & (1 << 0)) == (1 << 0)) {
49             guidIcon = true;
50         }
51         if ((firstByte & (1 << 1)) == (1 << 1)) {
52             volumeDisplay = true;
53         }
54
55         // convert the ascii values back to string
56         StringBuilder sb = new StringBuilder();
57         for (int i = 2; i < responsePayload.length() - 1; i += 2) {
58             String hexAsciiValue = responsePayload.substring(i, i + 2);
59             try {
60                 sb.append((char) Integer.parseInt(hexAsciiValue, 16));
61             } catch (Exception e) {
62                 logger.error("parsing string failed '{}'", responsePayload, e);
63             }
64         }
65         infoText = sb.toString();
66     }
67
68     public String getInfoText() {
69         return infoText;
70     }
71
72     public void setInfoText(String infoText) {
73         this.infoText = infoText;
74     }
75
76     public Boolean getVolumeDisplay() {
77         return volumeDisplay;
78     }
79
80     public Boolean getGuidIcon() {
81         return guidIcon;
82     }
83 }