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.serial;
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.io.transport.serial.SerialPortManager;
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 a serial connection
27 * @author Laurent Garnier - Initial contribution
30 public class SonyProjectorSerialSimuConnector extends SonyProjectorSerialConnector {
32 private final Logger logger = LoggerFactory.getLogger(SonyProjectorSerialSimuConnector.class);
37 * @param serialPortManager the serial port manager
38 * @param model the projector model in use
40 public SonyProjectorSerialSimuConnector(SerialPortManager serialPortManager, SonyProjectorModel model) {
41 super(serialPortManager, "dummyPort", model, true);
45 public synchronized void open() throws ConnectionException {
48 logger.debug("Simulated serial connection opened");
53 public synchronized void close() {
55 logger.debug("Simulated serial connection closed");
61 protected synchronized byte[] readResponse() throws CommunicationException {
62 byte[] message = new byte[8];
63 message[0] = START_CODE;
64 message[1] = SonyProjectorSerialError.COMPLETE.getDataCode()[0];
65 message[2] = SonyProjectorSerialError.COMPLETE.getDataCode()[1];
66 message[3] = TYPE_ACK;
69 message[6] = computeCheckSum(message);
70 message[7] = END_CODE;
71 logger.debug("readResponse: {}", HexUtils.bytesToHex(message));
75 private byte computeCheckSum(byte[] message) {
77 for (int i = 1; i <= 5; i++) {
78 result |= (message[i] & 0x000000FF);