Skip to main content
summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorDoug Schaefer2015-05-03 02:58:18 +0000
committerDoug Schaefer2015-05-04 20:34:10 +0000
commit076e141b69bb543d45f41b0c10317fde3ef959ea (patch)
tree026daf607667502db6169d401f2deb4068cc3da0 /native
parentcb16665cc776d9e46d5862e8ee283ff082063a90 (diff)
downloadorg.eclipse.cdt-076e141b69bb543d45f41b0c10317fde3ef959ea.tar.gz
org.eclipse.cdt-076e141b69bb543d45f41b0c10317fde3ef959ea.tar.xz
org.eclipse.cdt-076e141b69bb543d45f41b0c10317fde3ef959ea.zip
Bug 466209 - Initial commit of Arduino plugins.
Includes freemarker jar which we have CQ approval for. Change-Id: I8f36cd7f4539497bab5f106f84216f75a25da3a0
Diffstat (limited to 'native')
-rw-r--r--native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java81
1 files changed, 76 insertions, 5 deletions
diff --git a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java
index fc0f9f23833..b15c7178c8a 100644
--- a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java
+++ b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java
@@ -28,6 +28,8 @@ public class SerialPort {
private final String portName;
private boolean isOpen;
+ private boolean isPaused;
+ private Object pauseMutex = new Object();
private BaudRate baudRate = BaudRate.B115200;
private ByteSize byteSize = ByteSize.B8;
private Parity parity = Parity.None;
@@ -56,7 +58,19 @@ public class SerialPort {
while (true) {
rlen = read1(handle, rbuff, 0, rbuff.length);
if (rlen < 0) {
- return -1;
+ if (isPaused) {
+ synchronized (pauseMutex) {
+ while (isPaused) {
+ try {
+ pauseMutex.wait();
+ } catch (InterruptedException e) {
+ return -1;
+ }
+ }
+ }
+ } else {
+ return -1;
+ }
} else if (rlen > 0) {
break;
}
@@ -79,8 +93,22 @@ public class SerialPort {
System.arraycopy(rbuff, rpos, b, off, n);
rpos += n;
return n;
- } else {
- return read1(handle, b, off, len);
+ } else {
+ n = read1(handle, b, off, len);
+ if (n < 0 && isPaused) {
+ synchronized (pauseMutex) {
+ while (isPaused) {
+ try {
+ pauseMutex.wait();
+ } catch (InterruptedException e) {
+ return -1;
+ }
+ }
+ }
+ return read1(handle, b, off, len);
+ } else {
+ return n;
+ }
}
} else {
return -1;
@@ -97,14 +125,44 @@ public class SerialPort {
@Override
public void write(int b) throws IOException {
if (isOpen()) {
- write0(handle, b);
+ try {
+ write0(handle, b);
+ } catch (IOException e) {
+ if (isPaused) {
+ synchronized (pauseMutex) {
+ while (isPaused) {
+ try {
+ pauseMutex.wait();
+ } catch (InterruptedException e1) {
+ throw e;
+ }
+ }
+ }
+ write0(handle, b);
+ }
+ }
}
}
@Override
public void write(byte[] buff, int off, int len) throws IOException {
if (isOpen()) {
- write1(handle, buff, off, len);
+ try {
+ write1(handle, buff, off, len);
+ } catch (IOException e) {
+ if (isPaused) {
+ synchronized (pauseMutex) {
+ while (isPaused) {
+ try {
+ pauseMutex.wait();
+ } catch (InterruptedException e1) {
+ throw e;
+ }
+ }
+ }
+ write1(handle, buff, off, len);
+ }
+ }
}
}
@@ -212,6 +270,19 @@ public class SerialPort {
return isOpen;
}
+ public void pause() throws IOException {
+ isPaused = true;
+ close0(handle);
+ }
+
+ public void resume() throws IOException {
+ synchronized (pauseMutex) {
+ isPaused = false;
+ open();
+ pauseMutex.notifyAll();
+ }
+ }
+
public void setBaudRate(BaudRate rate) throws IOException {
if (isOpen) {
throw new IOException(PORT_OPEN);

Back to the top