2 * Copyright (c) 2010-2021 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.SonyProjectorException;
17 import org.openhab.binding.sonyprojector.internal.SonyProjectorModel;
18 import org.openhab.core.io.transport.serial.SerialPortManager;
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 a serial connection
26 * @author Laurent Garnier - Initial contribution
29 public class SonyProjectorSerialSimuConnector extends SonyProjectorSerialConnector {
31 private final Logger logger = LoggerFactory.getLogger(SonyProjectorSerialSimuConnector.class);
36 * @param serialPortManager the serial port manager
37 * @param model the projector model in use
39 public SonyProjectorSerialSimuConnector(SerialPortManager serialPortManager, SonyProjectorModel model) {
40 super(serialPortManager, "dummyPort", model, true);
44 public synchronized void open() throws SonyProjectorException {
47 logger.debug("Simulated serial connection opened");
52 public synchronized void close() {
54 logger.debug("Simulated serial connection closed");
60 protected synchronized byte[] readResponse() throws SonyProjectorException {
61 byte[] message = new byte[8];
62 message[0] = START_CODE;
63 message[1] = SonyProjectorSerialError.COMPLETE.getDataCode()[0];
64 message[2] = SonyProjectorSerialError.COMPLETE.getDataCode()[1];
65 message[3] = TYPE_ACK;
68 message[6] = computeCheckSum(message);
69 message[7] = END_CODE;
70 logger.debug("readResponse: {}", HexUtils.bytesToHex(message));
74 private byte computeCheckSum(byte[] message) {
76 for (int i = 1; i <= 5; i++) {
77 result |= (message[i] & 0x000000FF);