/**
 * Copyright (c) 2010-2017 by the respective copyright holders.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package de.csdev.ebus.core.connection;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.csdev.ebus.utils.Emulator;

/**
 * @author Christian Sowada - Initial contribution
 *
 */
public class EBusEmulatorConnection extends AbstractEBusConnection {

    private static final Logger logger = LoggerFactory.getLogger(EBusEmulatorConnection.class);

    private Emulator emu;

    public EBusEmulatorConnection() {
        emu = new Emulator();
    }

    @Override
    public boolean open() throws IOException {
        this.inputStream = emu.getInputStream();
        return true;
    }

    @Override
    public void writeByte(int b) throws IOException {
        emu.write((byte) b);
    }

    public void writeBytes(byte[] byteArray) {
        emu.write(byteArray);
    }

    public void writeBytesDelayed(byte[] byteArray, long delay) {

        try {
            Thread.sleep(delay);
        } catch (InterruptedException e) {
            logger.error("error!", e);
        }

        writeBytes(byteArray);
    }

    @Override
    public void reset() throws IOException {
        if (emu.getInputStream().available() > 0) {
            byte[] x = new byte[emu.getInputStream().available()];
            emu.getInputStream().read(x);
        }
    }

	@Override
	public boolean close() throws IOException {
		emu.close();
		return super.close();
	}

}

@@ -735,16 +735,54 @@
 r emu;%0A%0A
+    private boolean autoSync = true;%0A%0A
     publ
@@ -815,36 +815,102 @@
 ) %7B%0A
+%0A
     
+%7D%0A%0A
     
-emu = new Emulator()
+public EBusEmulatorConnection(boolean autoSync) %7B%0A        this.autoSync = autoSync
 ;%0A  
@@ -967,32 +967,73 @@
 s IOException %7B%0A
+        emu = new Emulator(1, autoSync);%0A
         this.inp
@@ -1656,17 +1656,20 @@
  byte%5B%5D 
-x
+data
  = new b
@@ -1745,17 +1745,20 @@
 ().read(
-x
+data
 );%0A     
@@ -1769,17 +1769,20 @@
 %0A    %7D%0A%0A
-%09
+    
 @Overrid
@@ -1783,17 +1783,20 @@
 verride%0A
-%09
+    
 public b
@@ -1831,18 +1831,24 @@
 ption %7B%0A
-%09%09
+        
 emu.clos
@@ -1856,10 +1856,16 @@
 ();%0A
-%09%09
+        
 retu
@@ -1886,9 +1886,12 @@
 ();%0A
-%09
+    
 %7D%0A%0A%7D

Add new autoSyn option to EmulatorConnection