Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2015-02-16 17:19:18 +0000
committerGerrit Code Review @ Eclipse.org2015-02-16 18:19:54 +0000
commit275feb68745a7eaf27d4010d4875abdd158cbc33 (patch)
tree53a50522fdb491eea480d89650eefcae19f59056 /core/org.eclipse.cdt.core.native
parent52c80c124ee2f4edccf292c472886d9cde8d6143 (diff)
downloadorg.eclipse.cdt-275feb68745a7eaf27d4010d4875abdd158cbc33.tar.gz
org.eclipse.cdt-275feb68745a7eaf27d4010d4875abdd158cbc33.tar.xz
org.eclipse.cdt-275feb68745a7eaf27d4010d4875abdd158cbc33.zip
Bug 459971 New SerialPort support. First step is Mac library.
Java classes are defined and a pretty simple native library for Mac is there. Tested with Arduino so I know reading works. This implementation should work for Linux as well. Windows is going to be the hard one. Not checking in the binaries yet until I get more testing with them. Also remove ppc native libraries for Mac since that hasn't been supported in a long time. Change-Id: If4ffbc6e73a7656a47c2f45b875be0842c482b05
Diffstat (limited to 'core/org.eclipse.cdt.core.native')
-rw-r--r--core/org.eclipse.cdt.core.native/.classpath14
-rw-r--r--core/org.eclipse.cdt.core.native/.settings/org.eclipse.jdt.core.prefs6
-rw-r--r--core/org.eclipse.cdt.core.native/META-INF/MANIFEST.MF3
-rw-r--r--core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/BaudRate.java49
-rw-r--r--core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/ByteSize.java29
-rw-r--r--core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/Parity.java19
-rw-r--r--core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/SerialPort.java185
-rw-r--r--core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/StopBits.java18
8 files changed, 312 insertions, 11 deletions
diff --git a/core/org.eclipse.cdt.core.native/.classpath b/core/org.eclipse.cdt.core.native/.classpath
index 2d1a4302f04..098194ca4b7 100644
--- a/core/org.eclipse.cdt.core.native/.classpath
+++ b/core/org.eclipse.cdt.core.native/.classpath
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/core/org.eclipse.cdt.core.native/.settings/org.eclipse.jdt.core.prefs b/core/org.eclipse.cdt.core.native/.settings/org.eclipse.jdt.core.prefs
index 0c036c2d5e5..84309ca7d50 100644
--- a/core/org.eclipse.cdt.core.native/.settings/org.eclipse.jdt.core.prefs
+++ b/core/org.eclipse.cdt.core.native/.settings/org.eclipse.jdt.core.prefs
@@ -1,8 +1,8 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@@ -77,7 +77,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disa
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
-org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.source=1.7
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
diff --git a/core/org.eclipse.cdt.core.native/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core.native/META-INF/MANIFEST.MF
index 881e6c66355..be4950c5819 100644
--- a/core/org.eclipse.cdt.core.native/META-INF/MANIFEST.MF
+++ b/core/org.eclipse.cdt.core.native/META-INF/MANIFEST.MF
@@ -9,7 +9,8 @@ Bundle-Localization: plugin
Export-Package: org.eclipse.cdt.core;native=split;mandatory:=native,
org.eclipse.cdt.utils;native=split;mandatory:=native,
org.eclipse.cdt.utils.pty;version="5.7",
+ org.eclipse.cdt.utils.serial,
org.eclipse.cdt.utils.spawner;version="5.7"
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.1.0,4.0.0)"
Bundle-ActivationPolicy: lazy
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-RequiredExecutionEnvironment: JavaSE-1.7
diff --git a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/BaudRate.java b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/BaudRate.java
new file mode 100644
index 00000000000..fd2151366e2
--- /dev/null
+++ b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/BaudRate.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2015 QNX Software Systems and others.
+ * 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
+ *
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.utils.serial;
+
+public enum BaudRate {
+
+ B0(0),
+ B50(50),
+ B75(75),
+ B110(110),
+ B134(134),
+ B150(150),
+ B200(200),
+ B300(300),
+ B600(600),
+ B1200(1200),
+ B1800(1800),
+ B2400(2400),
+ B4800(4800),
+ B7200(7200),
+ B9600(9600),
+ B14400(14400),
+ B19200(19200),
+ B28800(28800),
+ B38400(38400),
+ B57600(57600),
+ B76800(76800),
+ B115200(115200),
+ B230400(230400);
+
+ private final int rate;
+
+ private BaudRate(int rate) {
+ this.rate = rate;
+ }
+
+ public int getRate() {
+ return rate;
+ }
+
+}
diff --git a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/ByteSize.java b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/ByteSize.java
new file mode 100644
index 00000000000..7f0e639f367
--- /dev/null
+++ b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/ByteSize.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2015 QNX Software Systems and others.
+ * 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
+ *
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.utils.serial;
+
+public enum ByteSize {
+
+ B5(5),
+ B6(6),
+ B7(7),
+ B8(8);
+
+ private final int size;
+
+ private ByteSize(int size) {
+ this.size = size;
+ }
+
+ public int getSize() {
+ return size;
+ }
+}
diff --git a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/Parity.java b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/Parity.java
new file mode 100644
index 00000000000..276081c9e0a
--- /dev/null
+++ b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/Parity.java
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * Copyright (c) 2015 QNX Software Systems and others.
+ * 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
+ *
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.utils.serial;
+
+public enum Parity {
+
+ None,
+ Even,
+ Odd
+
+}
diff --git a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/SerialPort.java b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/SerialPort.java
new file mode 100644
index 00000000000..e5fc8545751
--- /dev/null
+++ b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/SerialPort.java
@@ -0,0 +1,185 @@
+/*******************************************************************************
+ * Copyright (c) 2015 QNX Software Systems and others.
+ * 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
+ *
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.utils.serial;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.Platform;
+
+public class SerialPort {
+
+ private final String portName;
+ private boolean isOpen;
+ private BaudRate baudRate = BaudRate.B115200;
+ private ByteSize byteSize = ByteSize.B8;
+ private Parity parity = Parity.None;
+ private StopBits stopBits = StopBits.S1;
+ private long handle;
+
+ private static final String PORT_OPEN = "Port is open";
+
+ static {
+ System.loadLibrary("serial"); //$NON-NLS-1$
+ }
+
+ /**
+ * Create a serial port that connect to the given serial device.
+ *
+ * @param portName name for the serial device.
+ */
+ public SerialPort(String portName) {
+ this.portName = portName;
+ }
+
+ /**
+ * List the available serial ports.
+ *
+ * @return serial ports
+ */
+ public static String[] list() {
+ if (Platform.getOS().equals(Platform.OS_MACOSX)) {
+ File dev = new File("/dev"); //$NON-NLS-1$
+ final Pattern pattern = Pattern.compile("tty\\.(usbserial|usbmodem).*"); //$NON-NLS-1$
+ File[] files = dev.listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return pattern.matcher(name).matches();
+ }
+ });
+
+ if (files == null) {
+ return new String[0];
+ }
+ String[] names = new String[files.length];
+ for (int i = 0; i < files.length; i++) {
+ names[i] = files[i].getAbsolutePath();
+ }
+ return names;
+ } else {
+ return new String[0];
+ }
+ }
+
+ /**
+ * Return the name for this serial port.
+ *
+ * @return serial port name
+ */
+ public String getPortName() {
+ return portName;
+ }
+
+ public void open() throws IOException {
+ handle = open0(portName, baudRate.getRate(), byteSize.getSize(), parity.ordinal(), stopBits.ordinal());
+ isOpen = true;
+ }
+
+ private native long open0(String portName, int baudRate, int byteSize, int parity, int stopBits) throws IOException;
+
+ public void close() throws IOException {
+ close0(handle);
+ isOpen = false;
+ }
+
+ private native void close0(long handle) throws IOException;
+
+ public boolean isOpen() {
+ return isOpen;
+ }
+
+ public void setBaudRate(BaudRate rate) throws IOException {
+ if (isOpen) {
+ throw new IOException(PORT_OPEN);
+ }
+ this.baudRate = rate;
+ }
+
+ public BaudRate getBaudRate() {
+ return baudRate;
+ }
+
+ public void setByteSize(ByteSize size) throws IOException {
+ if (isOpen) {
+ throw new IOException(PORT_OPEN);
+ }
+ this.byteSize = size;
+ }
+
+ public ByteSize getByteSize() {
+ return byteSize;
+ }
+
+ public void setParity(Parity parity) throws IOException {
+ if (isOpen) {
+ throw new IOException(PORT_OPEN);
+ }
+ this.parity = parity;
+ }
+
+ public Parity getParity() {
+ return parity;
+ }
+
+ public void setStopBit(StopBits stopBits) throws IOException {
+ if (isOpen) {
+ throw new IOException(PORT_OPEN);
+ }
+ this.stopBits = stopBits;
+ }
+
+ public StopBits getStopBits() {
+ return stopBits;
+ }
+
+ public InputStream getInputStream() {
+ return new InputStream() {
+ @Override
+ public int read() throws IOException {
+ if (isOpen()) {
+ return read0(handle);
+ } else {
+ return -1;
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ SerialPort.this.close();
+ }
+ };
+ }
+
+ private native int read0(long handle) throws IOException;
+
+ public OutputStream getOutputStream() {
+ return new OutputStream() {
+ @Override
+ public void write(int b) throws IOException {
+ if (isOpen()) {
+ write0(handle, b);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ SerialPort.this.close();
+ }
+ };
+ }
+
+ private native void write0(long handle, int b) throws IOException;
+
+}
diff --git a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/StopBits.java b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/StopBits.java
new file mode 100644
index 00000000000..1e9a7e07a33
--- /dev/null
+++ b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/serial/StopBits.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2015 QNX Software Systems and others.
+ * 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
+ *
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.utils.serial;
+
+public enum StopBits {
+
+ S1,
+ S2
+
+}

Back to the top