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.core.i18n.CommunicationException;
18 import org.openhab.core.i18n.ConnectionException;
19 import org.openhab.core.util.HexUtils;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * Class for communicating with Sony Projectors through an IP connection
25 * using Pj Talk service (SDCP protocol)
27 * @author Markus Wehrle - Initial contribution
28 * @author Laurent Garnier - Refactoring to consider SonyProjectorConnector and add a full check of responses
31 public class SonyProjectorSdcpSimuConnector extends SonyProjectorSdcpConnector {
33 private final Logger logger = LoggerFactory.getLogger(SonyProjectorSdcpSimuConnector.class);
35 private byte[] lastItemCode = new byte[] { 0x00, 0x00 };
40 * @param model the projector model in use
42 public SonyProjectorSdcpSimuConnector(SonyProjectorModel model) {
43 super("127.0.0.1", null, null, model, true);
47 public synchronized void open() throws ConnectionException {
50 logger.debug("Simulated SDCP connection opened");
55 public synchronized void close() {
57 logger.debug("Simulated SDCP connection closed");
63 protected byte[] buildMessage(byte[] itemCode, boolean getCommand, byte[] data) {
64 lastItemCode = itemCode;
65 return super.buildMessage(itemCode, getCommand, data);
69 protected synchronized byte[] readResponse() throws CommunicationException {
70 byte[] message = new byte[34];
71 byte[] communityData = getCommunity().getBytes();
72 message[0] = HEADER[0];
73 message[1] = HEADER[1];
74 message[2] = communityData[0];
75 message[3] = communityData[1];
76 message[4] = communityData[2];
77 message[5] = communityData[3];
79 message[7] = lastItemCode[0];
80 message[8] = lastItemCode[1];
84 logger.debug("readResponse: {}", HexUtils.bytesToHex(message));