Skip to content
Snippets Groups Projects
Commit a6777f1f authored by akwizgran's avatar akwizgran
Browse files

Ensure each reliability layer is started and stopped.

parent 19106ae0
No related branches found
No related tags found
No related merge requests found
......@@ -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();
}
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment