Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'native/org.eclipse.cdt.native.serial')
-rw-r--r--native/org.eclipse.cdt.native.serial/.classpath7
-rw-r--r--native/org.eclipse.cdt.native.serial/.gitignore1
-rw-r--r--native/org.eclipse.cdt.native.serial/.project28
-rw-r--r--native/org.eclipse.cdt.native.serial/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--native/org.eclipse.cdt.native.serial/META-INF/MANIFEST.MF8
-rw-r--r--native/org.eclipse.cdt.native.serial/about.html24
-rw-r--r--native/org.eclipse.cdt.native.serial/about.ini24
-rw-r--r--native/org.eclipse.cdt.native.serial/about.mappings9
-rw-r--r--native/org.eclipse.cdt.native.serial/about.properties24
-rw-r--r--native/org.eclipse.cdt.native.serial/build.properties11
-rw-r--r--native/org.eclipse.cdt.native.serial/cdt_logo_icon32.pngbin0 -> 1885 bytes
-rw-r--r--native/org.eclipse.cdt.native.serial/jni/.gitignore1
-rw-r--r--native/org.eclipse.cdt.native.serial/jni/posix/Makefile69
-rw-r--r--native/org.eclipse.cdt.native.serial/jni/posix/serial.c125
-rwxr-xr-xnative/org.eclipse.cdt.native.serial/os/macosx/x86_64/libserial.jnilibbin0 -> 9492 bytes
-rw-r--r--native/org.eclipse.cdt.native.serial/pom.xml17
-rw-r--r--native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/BaudRate.java92
-rw-r--r--native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/ByteSize.java68
-rw-r--r--native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/Parity.java55
-rw-r--r--native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java228
-rw-r--r--native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/StopBits.java52
-rw-r--r--native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/internal/Messages.java31
-rw-r--r--native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/internal/messages.properties11
23 files changed, 892 insertions, 0 deletions
diff --git a/native/org.eclipse.cdt.native.serial/.classpath b/native/org.eclipse.cdt.native.serial/.classpath
new file mode 100644
index 00000000000..098194ca4b7
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/.classpath
@@ -0,0 +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/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/native/org.eclipse.cdt.native.serial/.gitignore b/native/org.eclipse.cdt.native.serial/.gitignore
new file mode 100644
index 00000000000..ae3c1726048
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/native/org.eclipse.cdt.native.serial/.project b/native/org.eclipse.cdt.native.serial/.project
new file mode 100644
index 00000000000..39705da7693
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.cdt.native.serial</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/native/org.eclipse.cdt.native.serial/.settings/org.eclipse.jdt.core.prefs b/native/org.eclipse.cdt.native.serial/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..f42de363afa
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/native/org.eclipse.cdt.native.serial/META-INF/MANIFEST.MF b/native/org.eclipse.cdt.native.serial/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..ea6bd38806d
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/META-INF/MANIFEST.MF
@@ -0,0 +1,8 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Serial Port
+Bundle-SymbolicName: org.eclipse.cdt.native.serial
+Bundle-Version: 1.0.0.qualifier
+Bundle-Vendor: Eclipse CDT
+Bundle-RequiredExecutionEnvironment: JavaSE-1.7
+Export-Package: org.eclipse.cdt.serial
diff --git a/native/org.eclipse.cdt.native.serial/about.html b/native/org.eclipse.cdt.native.serial/about.html
new file mode 100644
index 00000000000..d7c511887d6
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/about.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"><head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head>
+
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 22, 2007</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body></html> \ No newline at end of file
diff --git a/native/org.eclipse.cdt.native.serial/about.ini b/native/org.eclipse.cdt.native.serial/about.ini
new file mode 100644
index 00000000000..e07a7bb377e
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/about.ini
@@ -0,0 +1,24 @@
+# about.ini
+# contains information about a feature
+# java.io.Properties file (ISO 8859-1 with "\" escapes)
+# "%key" are externalized strings defined in about.properties
+# This file does not need to be translated.
+
+# Property "aboutText" contains blurb for "About" dialog (translated)
+aboutText=%blurb
+
+# Property "windowImage" contains path to window icon (16x16)
+# needed for primary features only
+
+# Property "featureImage" contains path to feature image (32x32)
+featureImage=cdt_logo_icon32.png
+
+# Property "aboutImage" contains path to product image (500x330 or 115x164)
+# needed for primary features only
+
+# Property "appName" contains name of the application (translated)
+# needed for primary features only
+
+# Property "welcomePerspective" contains the id of the perspective in which the
+# welcome page is to be opened.
+# optional
diff --git a/native/org.eclipse.cdt.native.serial/about.mappings b/native/org.eclipse.cdt.native.serial/about.mappings
new file mode 100644
index 00000000000..0824105e69d
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/about.mappings
@@ -0,0 +1,9 @@
+# about.mappings
+# contains fill-ins for about.properties
+# java.io.Properties file (ISO 8859-1 with "\" escapes)
+# This file does not need to be translated.
+
+# The following should contain the build version.
+# e.g. "0=20020612"
+# This value will be added automaticaly via the build scripts
+0=@build@ \ No newline at end of file
diff --git a/native/org.eclipse.cdt.native.serial/about.properties b/native/org.eclipse.cdt.native.serial/about.properties
new file mode 100644
index 00000000000..a090552503d
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/about.properties
@@ -0,0 +1,24 @@
+###############################################################################
+# Copyright (c) 2002, 2009 Wind River 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:
+# Wind River Systems - initial API and implementation
+###############################################################################
+# about.properties
+# contains externalized strings for about.ini
+# java.io.Properties file (ISO 8859-1 with "\" escapes)
+# fill-ins are supplied by about.mappings
+# This file should be translated.
+# NOTE TO TRANSLATOR: Please do not translate the featureVersion variable.
+
+blurb=Eclipse CDT P2 Customizations for SDK installation\n\
+\n\
+Version: {featureVersion}\n\
+Build id: {0}\n\
+\n\
+(c) Copyright Eclipse contributors and others, 2000, 2010. All rights reserved.\n\
+Visit http://www.eclipse.org/cdt
diff --git a/native/org.eclipse.cdt.native.serial/build.properties b/native/org.eclipse.cdt.native.serial/build.properties
new file mode 100644
index 00000000000..6fd7e5923e8
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/build.properties
@@ -0,0 +1,11 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ os/,\
+ about.html,\
+ about.ini,\
+ about.mappings,\
+ about.properties,\
+ cdt_logo_icon32.png
+src.includes = jni/
diff --git a/native/org.eclipse.cdt.native.serial/cdt_logo_icon32.png b/native/org.eclipse.cdt.native.serial/cdt_logo_icon32.png
new file mode 100644
index 00000000000..470ca81b327
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/cdt_logo_icon32.png
Binary files differ
diff --git a/native/org.eclipse.cdt.native.serial/jni/.gitignore b/native/org.eclipse.cdt.native.serial/jni/.gitignore
new file mode 100644
index 00000000000..5761abcfdf0
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/jni/.gitignore
@@ -0,0 +1 @@
+*.o
diff --git a/native/org.eclipse.cdt.native.serial/jni/posix/Makefile b/native/org.eclipse.cdt.native.serial/jni/posix/Makefile
new file mode 100644
index 00000000000..9952967f322
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/jni/posix/Makefile
@@ -0,0 +1,69 @@
+#*******************************************************************************
+# Copyright (c) 2002, 2009 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
+# Alex Blewitt - MacOSX with a 64-bit vm
+#*******************************************************************************/
+
+JAVA_HOME = $(shell echo /Library/Java/JavaVirtualMachines/jdk1.8.0_*.jdk/Contents/Home)
+UNAME = $(shell uname)
+
+# Defaults which can be overridden.
+ifeq ($(UNAME),Darwin)
+OS = macosx
+ARCHS = x86_64
+endif
+
+ARCH_X86 = x86
+ARCH_X86_64 = x86_64
+
+CC=gcc
+LD=libtool
+CPPFLAGS = -I. -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/darwin
+CFLAGS +=-fPIC -D_REENTRANT
+
+ARCH_FLAG_X86 = -arch i386
+ARCH_FLAG_X86_64 = -arch x86_64
+
+INSTALL_DIR_X86 = ../../os/$(OS)/$(ARCH_X86)
+INSTALL_DIR_X86_64 = ../../os/$(OS)/$(ARCH_X86_64)
+
+LIB_NAME_FULL_SERIAL_X86 = $(INSTALL_DIR_X86)/libserial.jnilib
+LIB_NAME_FULL_SERIAL_X86_64 = $(INSTALL_DIR_X86_64)/libserial.jnilib
+
+OBJS_SERIAL_X86 = serial_$(ARCH_X86).o
+OBJS_SERIAL_X86_64 = serial_$(ARCH_X86_64).o
+
+OBJS_X86 = $(OBJS_SERIAL_X86)
+OBJS_X86_64 = $(OBJS_SERIAL_X86_64)
+
+all: $(ARCHS)
+
+x86: $(LIB_NAME_FULL_SERIAL_X86)
+
+x86_64: $(LIB_NAME_FULL_SERIAL_X86_64)
+
+rebuild: clean all
+
+$(LIB_NAME_FULL_SERIAL_X86): $(OBJS_SERIAL_X86)
+ mkdir -p $(INSTALL_DIR_X86)
+ $(CC) -dynamiclib $(ARCH_FLAG_X86) -o $(LIB_NAME_FULL_SERIAL_X86) $(OBJS_SERIAL_X86) -lc -framework JavaVM
+
+$(LIB_NAME_FULL_SERIAL_X86_64): $(OBJS_SERIAL_X86_64)
+ mkdir -p $(INSTALL_DIR_X86_64)
+ $(CC) -dynamiclib $(ARCH_FLAG_X86_64) -o $(LIB_NAME_FULL_SERIAL_X86_64) $(OBJS_SERIAL_X86_64) -lc -framework JavaVM
+
+serial_$(ARCH_X86).o: serial.c
+ $(CC) $(CFLAGS) $(ARCH_FLAG_X86) $(CPPFLAGS) -c -o $@ serial.c
+
+serial_$(ARCH_X86_64).o: serial.c
+ $(CC) $(CFLAGS) $(ARCH_FLAG_X86_64) $(CPPFLAGS) -c -o $@ serial.c
+
+clean :
+ $(RM) $(OBJS_X86)
+ $(RM) $(OBJS_X86_64)
diff --git a/native/org.eclipse.cdt.native.serial/jni/posix/serial.c b/native/org.eclipse.cdt.native.serial/jni/posix/serial.c
new file mode 100644
index 00000000000..bf1e51da279
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/jni/posix/serial.c
@@ -0,0 +1,125 @@
+/*******************************************************************************
+ * 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
+ *******************************************************************************/
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/uio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <strings.h>
+#include <jni.h>
+
+#define FUNC(x) Java_org_eclipse_cdt_serial_SerialPort_ ## x
+
+JNIEXPORT jlong JNICALL FUNC(open0)(JNIEnv *env, jobject jobj, jstring portName, jint baudRate, jint byteSize, jint parity, jint stopBits)
+{
+ const char * cportName = (*env)->GetStringUTFChars(env, portName, NULL);
+ int fd = open(cportName, O_RDWR | O_NOCTTY | O_NDELAY);
+ if (fd < 0) {
+ return fd;
+ }
+
+ // Turn off all flags
+ fcntl(fd, F_SETFL, 0);
+
+ struct termios options;
+ tcgetattr(fd, &options);
+ options.c_cflag |= (CLOCAL | CREAD);
+
+ // Set baud rate
+ cfsetispeed(&options, baudRate);
+ cfsetospeed(&options, baudRate);
+
+ // set data size
+ options.c_cflag &= ~CSIZE;
+ switch (byteSize) {
+ case 5:
+ options.c_cflag |= CS5;
+ break;
+ case 6:
+ options.c_cflag |= CS6;
+ break;
+ case 7:
+ options.c_cflag |= CS7;
+ break;
+ case 8:
+ options.c_cflag |= CS8;
+ break;
+
+ }
+
+ // set parity
+ switch (parity) {
+ case 0: // None
+ options.c_cflag &= ~PARENB;
+ break;
+ case 1: // Even
+ options.c_cflag |= PARENB;
+ options.c_cflag &= ~PARODD;
+ break;
+ case 2: // Odd
+ options.c_cflag |= (PARENB | PARODD);
+ break;
+ }
+
+ switch (stopBits) {
+ case 0: // 1
+ options.c_cflag &= ~CSTOPB;
+ break;
+ case 1: // 2
+ options.c_cflag |= CSTOPB;
+ break;
+ }
+
+ // raw input
+ options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
+
+ // ignore parity
+ options.c_iflag |= IGNPAR;
+
+ options.c_cc[VMIN] = 0; // min chars to read
+ options.c_cc[VTIME] = 10; // 10ths second timeout
+
+ tcflush(fd, TCIFLUSH);
+ tcsetattr(fd, TCSANOW, &options);
+
+ return fd;
+}
+
+JNIEXPORT void JNICALL FUNC(close0)(JNIEnv *env, jobject jobj, jlong handle)
+ {
+ close(handle);
+ }
+
+JNIEXPORT jint JNICALL FUNC(read0)(JNIEnv *env, jobject jobj, jlong handle)
+ {
+ char buff;
+ int res = read(handle, &buff, 1);
+ return res < 0 ? -1 : buff;
+ }
+
+JNIEXPORT jint JNICALL FUNC(read1)(JNIEnv * env, jobject jobj, jlong handle, jbyteArray bytes, jint offset, jint size) {
+ jbyte buff[256];
+ int n = size < sizeof(buff) ? size : sizeof(buff);
+ n = read(handle, buff, n);
+ if (n > 0) {
+ (*env)->SetByteArrayRegion(env, bytes, offset, n, buff);
+ }
+ return n;
+}
+
+JNIEXPORT void JNICALL FUNC(write0)(JNIEnv *env, jobject jobj, jlong handle, jint b)
+ {
+ char buff = b;
+ write(handle, &buff, 1);
+ }
diff --git a/native/org.eclipse.cdt.native.serial/os/macosx/x86_64/libserial.jnilib b/native/org.eclipse.cdt.native.serial/os/macosx/x86_64/libserial.jnilib
new file mode 100755
index 00000000000..bf96f91430c
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/os/macosx/x86_64/libserial.jnilib
Binary files differ
diff --git a/native/org.eclipse.cdt.native.serial/pom.xml b/native/org.eclipse.cdt.native.serial/pom.xml
new file mode 100644
index 00000000000..71d47f62c60
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/pom.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.eclipse.cdt</groupId>
+ <artifactId>cdt-parent</artifactId>
+ <version>8.6.0-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <version>1.0.0-SNAPSHOT</version>
+ <artifactId>org.eclipse.cdt.native.serial</artifactId>
+ <packaging>eclipse-plugin</packaging>
+</project>
diff --git a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/BaudRate.java b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/BaudRate.java
new file mode 100644
index 00000000000..70965fdeed4
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/BaudRate.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * 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.serial;
+
+/**
+ * @since 1.0
+ */
+public enum BaudRate {
+
+ B110(110),
+ B300(300),
+ B600(600),
+ B1200(1200),
+ B2400(2400),
+ B4800(4800),
+ B9600(9600),
+ B14400(14400),
+ B19200(19200),
+ B38400(38400),
+ B57600(57600),
+ B115200(115200);
+
+ private final int rate;
+
+ private BaudRate(int rate) {
+ this.rate = rate;
+ }
+
+ public int getRate() {
+ return rate;
+ }
+
+ private static final String[] strings = {
+ "110", //$NON-NLS-1$
+ "300", //$NON-NLS-1$
+ "600", //$NON-NLS-1$
+ "1200", //$NON-NLS-1$
+ "2400", //$NON-NLS-1$
+ "4800", //$NON-NLS-1$
+ "9600", //$NON-NLS-1$
+ "14400", //$NON-NLS-1$
+ "19200", //$NON-NLS-1$
+ "38400", //$NON-NLS-1$
+ "57600", //$NON-NLS-1$
+ "115200" //$NON-NLS-1$
+ };
+
+ public static String[] getStrings() {
+ return strings;
+ }
+
+ private static final BaudRate[] rates = {
+ B110,
+ B300,
+ B600,
+ B1200,
+ B2400,
+ B4800,
+ B9600,
+ B14400,
+ B19200,
+ B38400,
+ B57600,
+ B115200
+ };
+
+ public static BaudRate fromStringIndex(int rate) {
+ return rates[rate];
+ }
+
+ public static int getStringIndex(BaudRate rate) {
+ for (int i = 0; i < rates.length; ++i) {
+ if (rate.equals(rates[i])) {
+ return i;
+ }
+ }
+ return getStringIndex(getDefault());
+ }
+
+ public static BaudRate getDefault() {
+ return B9600;
+ }
+
+}
diff --git a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/ByteSize.java b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/ByteSize.java
new file mode 100644
index 00000000000..ad37c63afc6
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/ByteSize.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * 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.serial;
+
+/**
+ * @since 5.8
+ */
+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;
+ }
+
+ private static final String[] strings = {
+ "5", //$NON-NLS-1$
+ "6", //$NON-NLS-1$
+ "7", //$NON-NLS-1$
+ "8" //$NON-NLS-1$
+ };
+
+ public static String[] getStrings() {
+ return strings;
+ }
+
+ private static final ByteSize[] sizes = {
+ B5,
+ B6,
+ B7,
+ B8
+ };
+
+ public static ByteSize fromStringIndex(int size) {
+ return sizes[size];
+ }
+
+ public static int getStringIndex(ByteSize size) {
+ for (int i = 0; i < sizes.length; ++i) {
+ if (size.equals(sizes[i])) {
+ return i;
+ }
+ }
+ return getStringIndex(getDefault());
+ }
+
+ public static ByteSize getDefault() {
+ return B8;
+ }
+
+}
diff --git a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/Parity.java b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/Parity.java
new file mode 100644
index 00000000000..c93fa815d16
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/Parity.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * 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.serial;
+
+/**
+ * @since 5.8
+ */
+public enum Parity {
+
+ None,
+ Even,
+ Odd;
+
+ private static final String[] strings = {
+ "None", //$NON-NLS-1$
+ "Even", //$NON-NLS-1$
+ "Odd" //$NON-NLS-1$
+ };
+
+ public static String[] getStrings() {
+ return strings;
+ }
+
+ private static final Parity[] parities = {
+ None,
+ Even,
+ Odd
+ };
+
+ public static Parity fromStringIndex(int index) {
+ return parities[index];
+ }
+
+ public static int getStringIndex(Parity parity) {
+ for (int i = 0; i < parities.length; ++i) {
+ if (parity.equals(parities[i])) {
+ return i;
+ }
+ }
+ return getStringIndex(getDefault());
+ }
+
+ public static Parity getDefault() {
+ return None;
+ }
+
+}
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
new file mode 100644
index 00000000000..62c7a9bdabb
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java
@@ -0,0 +1,228 @@
+/*******************************************************************************
+ * 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.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.cdt.serial.internal.Messages;
+
+/**
+ * @since 5.8
+ */
+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 SERIAL_KEY = "HARDWARE\\DEVICEMAP\\SERIALCOMM"; //$NON-NLS-1$
+ private static final String PORT_OPEN = Messages.getString("SerialPort.PortIsOpen"); //$NON-NLS-1$
+
+ static {
+ try {
+ System.loadLibrary("serial"); //$NON-NLS-1$
+ } catch (UnsatisfiedLinkError e) {
+ e.printStackTrace();
+ }
+ }
+
+ private InputStream inputStream = new InputStream() {
+ @Override
+ public int read() throws IOException {
+ if (isOpen()) {
+ return read0(handle);
+ } else {
+ return -1;
+ }
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ if (isOpen()) {
+ return read1(handle, b, off, len);
+ } else {
+ return -1;
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ SerialPort.this.close();
+ }
+ };
+
+ private OutputStream outputStream = new OutputStream() {
+ @Override
+ public void write(int b) throws IOException {
+ if (isOpen()) {
+ write0(handle, b);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ SerialPort.this.close();
+ }
+ };
+
+ /**
+ * 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 (System.getProperty("os.name").equals("Mac OS X")) { //$NON-NLS-1$//$NON-NLS-2$
+ 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 if (System.getProperty("os.name").equals("Windows NT")) { //$NON-NLS-1$//$NON-NLS-2$
+// WindowsRegistry reg = WindowsRegistry.getRegistry();
+// if (reg != null) {
+// List<String> ports = new ArrayList<>();
+// int i = 0;
+// String name = reg.getLocalMachineValueName(SERIAL_KEY, i);
+// while (name != null) {
+// String value = reg.getLocalMachineValue(SERIAL_KEY, name);
+// ports.add(value);
+// i++;
+// name = reg.getLocalMachineValueName(SERIAL_KEY, i);
+// }
+// return ports.toArray(new String[ports.size()]);
+// } else {
+// return new String[0];
+// }
+ return new String[0];
+ } else {
+ return new String[0];
+ }
+ }
+
+ private native long open0(String portName, int baudRate, int byteSize, int parity, int stopBits) throws IOException;
+
+ private native void close0(long handle) throws IOException;
+
+ private native int read0(long handle) throws IOException;
+
+ private native int read1(long handle, byte[] b, int off, int len);
+
+ private native void write0(long handle, int b) throws IOException;
+
+ /**
+ * Return the name for this serial port.
+ *
+ * @return serial port name
+ */
+ public String getPortName() {
+ return portName;
+ }
+
+ public InputStream getInputStream() {
+ return inputStream;
+ }
+
+ public OutputStream getOutputStream() {
+ return outputStream;
+ }
+
+ public void open() throws IOException {
+ handle = open0(portName, baudRate.getRate(), byteSize.getSize(), parity.ordinal(), stopBits.ordinal());
+ isOpen = true;
+ }
+
+ public synchronized void close() throws IOException {
+ if (isOpen) {
+ close0(handle);
+ isOpen = false;
+ handle = 0;
+ }
+ }
+
+ 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 setStopBits(StopBits stopBits) throws IOException {
+ if (isOpen) {
+ throw new IOException(PORT_OPEN);
+ }
+ this.stopBits = stopBits;
+ }
+
+ public StopBits getStopBits() {
+ return stopBits;
+ }
+
+}
diff --git a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/StopBits.java b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/StopBits.java
new file mode 100644
index 00000000000..92752ce8e19
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/StopBits.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * 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.serial;
+
+/**
+ * @since 5.8
+ */
+public enum StopBits {
+
+ S1,
+ S2;
+
+ private static final String[] strings = {
+ "1", //$NON-NLS-1$
+ "2" //$NON-NLS-1$
+ };
+
+ public static String[] getStrings() {
+ return strings;
+ }
+
+ private static final StopBits[] stopBits = {
+ S1,
+ S2
+ };
+
+ public static StopBits fromStringIndex(int index) {
+ return stopBits[index];
+ }
+
+ public static int getStringIndex(StopBits sb) {
+ for (int i = 0; i < stopBits.length; ++i) {
+ if (sb.equals(stopBits[i])) {
+ return i;
+ }
+ }
+ return getStringIndex(getDefault());
+ }
+
+ public static StopBits getDefault() {
+ return S1;
+ }
+
+}
diff --git a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/internal/Messages.java b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/internal/Messages.java
new file mode 100644
index 00000000000..45a3d53817a
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/internal/Messages.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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.serial.internal;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages {
+ private static final String BUNDLE_NAME = "org.eclipse.cdt.serial.internal.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
+
+ private Messages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
diff --git a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/internal/messages.properties b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/internal/messages.properties
new file mode 100644
index 00000000000..9a39f7958ce
--- /dev/null
+++ b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/internal/messages.properties
@@ -0,0 +1,11 @@
+##################################################################################
+# 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
+##################################################################################
+SerialPort.PortIsOpen=Port is open

Back to the top