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.sonyprojector.internal.communication.sdcp;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.sonyprojector.internal.SonyProjectorModel;
17 import org.openhab.binding.sonyprojector.internal.communication.SonyProjectorItem;
18 import org.openhab.core.i18n.CommunicationException;
19 import org.openhab.core.i18n.ConnectionException;
20 import org.openhab.core.util.HexUtils;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Class for communicating with Sony Projectors through an IP connection
26 * using Pj Talk service (SDCP protocol)
28 * @author Markus Wehrle - Initial contribution
29 * @author Laurent Garnier - Refactoring to consider SonyProjectorConnector and add a full check of responses
32 public class SonyProjectorSdcpSimuConnector extends SonyProjectorSdcpConnector {
34 private final Logger logger = LoggerFactory.getLogger(SonyProjectorSdcpSimuConnector.class);
36 private SonyProjectorItem lastItem = SonyProjectorItem.POWER;
41 * @param model the projector model in use
43 public SonyProjectorSdcpSimuConnector(SonyProjectorModel model) {
44 super("127.0.0.1", null, null, model, true);
48 public synchronized void open() throws ConnectionException {
51 logger.debug("Simulated SDCP connection opened");
56 public synchronized void close() {
58 logger.debug("Simulated SDCP connection closed");
64 protected byte[] buildMessage(SonyProjectorItem item, boolean getCommand, byte[] data) {
66 return super.buildMessage(item, getCommand, data);
70 protected synchronized byte[] readResponse() throws CommunicationException {
71 byte[] message = new byte[34];
72 byte[] communityData = getCommunity().getBytes();
73 message[0] = HEADER[0];
74 message[1] = HEADER[1];
75 message[2] = communityData[0];
76 message[3] = communityData[1];
77 message[4] = communityData[2];
78 message[5] = communityData[3];
80 message[7] = lastItem.getCode()[0];
81 message[8] = lastItem.getCode()[1];
85 logger.debug("readResponse: {}", HexUtils.bytesToHex(message));