Ensure each reliability layer is started and stopped.

This commit is contained in:
akwizgran
2012-12-07 15:40:03 +00:00
parent 19106ae044
commit a6777f1fe1
2 changed files with 3 additions and 1 deletions

View File

@@ -49,6 +49,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
connected = new AtomicBoolean(false);
line = new byte[MAX_LINE_LENGTH];
reliabilityLayer = new ReliabilityLayer(this);
reliabilityLayer.start();
}
public void start() throws IOException {
@@ -69,7 +70,6 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
}
if(!foundBaudRate)
throw new IOException("Could not find a suitable baud rate");
reliabilityLayer.start();
port.addEventListener(this);
port.purgePort(PURGE_RXCLEAR | PURGE_TXCLEAR);
port.writeBytes("ATZ\r\n".getBytes("US-ASCII")); // Reset
@@ -150,6 +150,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
}
reliabilityLayer.stop();
reliabilityLayer = new ReliabilityLayer(this);
reliabilityLayer.start();
connected.set(false);
offHook.release();
}

View File

@@ -70,6 +70,7 @@ class ReliabilityLayer implements ReadHandler, WriteHandler {
}
void stop() {
if(!running) throw new IllegalStateException();
running = false;
receiver.invalidate();
writes.add(new byte[0]); // Poison pill