The reliability layer should run when the modem is off the hook.

This commit is contained in:
akwizgran
2012-12-07 16:20:53 +00:00
parent ef8841e712
commit 068d3b1dbd

View File

@@ -49,7 +49,6 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
connected = new AtomicBoolean(false); connected = new AtomicBoolean(false);
line = new byte[MAX_LINE_LENGTH]; line = new byte[MAX_LINE_LENGTH];
reliabilityLayer = new ReliabilityLayer(this); reliabilityLayer = new ReliabilityLayer(this);
reliabilityLayer.start();
} }
public void start() throws IOException { public void start() throws IOException {
@@ -92,12 +91,8 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
} }
public void stop() throws IOException { public void stop() throws IOException {
if(offHook.tryAcquire()) { if(offHook.tryAcquire()) offHook.release();
reliabilityLayer.stop(); else hangUp();
offHook.release();
} else {
hangUp();
}
try { try {
port.closePort(); port.closePort();
} catch(SerialPortException e) { } catch(SerialPortException e) {
@@ -111,6 +106,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
LOG.info("Not dialling - call in progress"); LOG.info("Not dialling - call in progress");
return false; return false;
} }
reliabilityLayer.start();
if(LOG.isLoggable(INFO)) LOG.info("Dialling"); if(LOG.isLoggable(INFO)) LOG.info("Dialling");
try { try {
port.writeBytes(("ATDT" + number + "\r\n").getBytes("US-ASCII")); port.writeBytes(("ATDT" + number + "\r\n").getBytes("US-ASCII"));
@@ -150,7 +146,6 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
} }
reliabilityLayer.stop(); reliabilityLayer.stop();
reliabilityLayer = new ReliabilityLayer(this); reliabilityLayer = new ReliabilityLayer(this);
reliabilityLayer.start();
connected.set(false); connected.set(false);
offHook.release(); offHook.release();
} }
@@ -244,6 +239,7 @@ class ModemImpl implements Modem, WriteHandler, SerialPortEventListener {
LOG.info("Not answering - call in progress"); LOG.info("Not answering - call in progress");
return; return;
} }
reliabilityLayer.start();
if(LOG.isLoggable(INFO)) LOG.info("Answering"); if(LOG.isLoggable(INFO)) LOG.info("Answering");
try { try {
port.writeBytes("ATA\r\n".getBytes("US-ASCII")); port.writeBytes("ATA\r\n".getBytes("US-ASCII"));