debian/0000755000000000000000000000000012265550152007171 5ustar debian/clean0000644000000000000000000000001712263653700010175 0ustar libjSSC-2.6.so debian/README.Source0000644000000000000000000000031512263653700011310 0ustar The watch file tracks releases, but the source code is located at: https://github.com/scream3r/java-simple-serial-connector/ Upstream doesn't tag github yet, so we have to manually create source tarballs. debian/compat0000644000000000000000000000000212263653700010370 0ustar 9 debian/copyright0000644000000000000000000000230212264312727011124 0ustar Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0 Upstream-Name: Java Simple Serial Connector (jSSC) Upstream-contact: Alexey Sokolov Source: https://github.com/scream3r/java-simple-serial-connector Files: * Copyright: 2010-2013 Alexey Sokolov License: LGPL-3+ Files: debian/* Copyright: 2013 Scott Howard License: LGPL-3+ License: LGPL-3+ jSSC is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. . jSSC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. . You should have received a copy of the GNU Lesser General Public License along with jSSC. On Debian systems it can be found at /usr/share/common-licenses/LGPL-3. . If you use jSSC in public project you can inform me about this by e-mail, of course if you want it. debian/source/0000755000000000000000000000000012263653700010472 5ustar debian/source/format0000644000000000000000000000001412263653700011700 0ustar 3.0 (quilt) debian/libjssc-java-doc.javadoc0000644000000000000000000000001112263653700013626 0ustar internal debian/patches/0000755000000000000000000000000012265550152010620 5ustar debian/patches/0002-Make-it-possible-to-retrieve-information-about-the-U.patch0000644000000000000000000002746012265550152024214 0ustar From: gohai Date: Wed, 11 Sep 2013 00:07:55 -0700 Subject: Make it possible to retrieve information about the USB device that provides the serial port getPortProperties() returns a map with keys and values as strings. The currently available keys are: idProduct (lowercase hexadecimal zero-padded to four digits), idVendor (as idProduct), manufacturer, product, serial. This is currently implemented for Linux and Mac OS X. Origin: other, https://github.com/gohai/java-simple-serial-connector/commit/5c61d622b71ee5ece5ab3b31397e2cca34eed8e9 Forwarded: https://github.com/scream3r/java-simple-serial-connector/pull/33 Bug-Debian: http://bugs.debian.org/734820 --- src/cpp/_nix_based/jssc.cpp | 135 +++++++++++++++++++++++++++++++ src/cpp/jssc_SerialNativeInterface.h | 8 ++ src/java/jssc/SerialNativeInterface.java | 2 + src/java/jssc/SerialPortList.java | 75 +++++++++++++++++ 4 files changed, 220 insertions(+) diff --git a/src/cpp/_nix_based/jssc.cpp b/src/cpp/_nix_based/jssc.cpp index 230e248..9468bc0 100644 --- a/src/cpp/_nix_based/jssc.cpp +++ b/src/cpp/_nix_based/jssc.cpp @@ -40,7 +40,12 @@ #include //Needed for select() function #endif #ifdef __APPLE__ + #include + #include + #include + #include #include //Needed for IOSSIOSPEED in Mac OS X (Non standard baudrate) + #include // Needed for MAXPATHLEN #endif #include @@ -865,3 +870,133 @@ JNIEXPORT jintArray JNICALL Java_jssc_SerialNativeInterface_getLinesStatus env->SetIntArrayRegion(returnArray, 0, 4, returnValues); return returnArray; } + +JNIEXPORT jobjectArray JNICALL Java_jssc_SerialNativeInterface_getPortProperties + (JNIEnv *env, jclass cls, jstring portName) { + const char* portNameChar = (const char*)env->GetStringUTFChars(portName, NULL); + jclass stringClass = env->FindClass("Ljava/lang/String;"); + jobjectArray ret = env->NewObjectArray(5, stringClass, NULL); + +#ifdef __APPLE__ + + // this code is based on QtSerialPort + CFMutableDictionaryRef matching = IOServiceMatching(kIOSerialBSDServiceValue); + io_iterator_t iter = 0; + kern_return_t kr = IOServiceGetMatchingServices(kIOMasterPortDefault, matching, &iter); + if (kr != kIOReturnSuccess) { + env->ReleaseStringUTFChars(portName, portNameChar); + return ret; + } + + io_registry_entry_t service; + while ((service = IOIteratorNext(iter))) { + + // compare portName against cu and tty devices + bool found = false; + + CFTypeRef cu = 0; + cu = IORegistryEntrySearchCFProperty(service, kIOServicePlane, CFSTR(kIOCalloutDeviceKey), kCFAllocatorDefault, 0); + if (cu) { + char buffer[MAXPATHLEN]; + CFStringGetCString(CFStringRef(cu), buffer, sizeof(buffer), kCFStringEncodingUTF8); + //fprintf(stdout, "getPortProperties: %s\n", buffer); + //fflush(stdout); + if (strcmp(portNameChar, buffer) == 0) { + found = true; + } + CFRelease(cu); + } + + CFTypeRef tty = 0; + tty = IORegistryEntrySearchCFProperty(service, kIOServicePlane, CFSTR(kIODialinDeviceKey), kCFAllocatorDefault, 0); + if (tty) { + char buffer[MAXPATHLEN]; + CFStringGetCString(CFStringRef(tty), buffer, sizeof(buffer), kCFStringEncodingUTF8); + //fprintf(stdout, "getPortProperties: %s\n", buffer); + //fflush(stdout); + if (strcmp(portNameChar, buffer) == 0) { + found = true; + } + CFRelease(tty); + } + + if (!found) { + // not port we're looking for + //fprintf(stderr, "getPortProperties: %s not found", portNameChar); + //fflush(stderr); + IOObjectRelease(service); + continue; + } + + io_registry_entry_t entry = service; + do { + int val = 0; + char buffer[255]; + + CFTypeRef idProduct = 0; + idProduct = IORegistryEntrySearchCFProperty(entry, kIOServicePlane, CFSTR(kUSBProductID), kCFAllocatorDefault, 0); + if (idProduct && !env->GetObjectArrayElement(ret, 0)) { + CFNumberGetValue(CFNumberRef(idProduct), kCFNumberIntType, &val); + sprintf(buffer, "%04x", val); + jstring tmp = env->NewStringUTF(buffer); + env->SetObjectArrayElement(ret, 0, tmp); + env->DeleteLocalRef(tmp); + CFRelease(idProduct); + } + + CFTypeRef idVendor = 0; + idVendor = IORegistryEntrySearchCFProperty(entry, kIOServicePlane, CFSTR(kUSBVendorID), kCFAllocatorDefault, 0); + if (idVendor && !env->GetObjectArrayElement(ret, 1)) { + CFNumberGetValue(CFNumberRef(idVendor), kCFNumberIntType, &val); + sprintf(buffer, "%04x", val); + jstring tmp = env->NewStringUTF(buffer); + env->SetObjectArrayElement(ret, 1, tmp); + env->DeleteLocalRef(tmp); + CFRelease(idVendor); + } + + CFTypeRef manufacturer = 0; + manufacturer = IORegistryEntrySearchCFProperty(entry, kIOServicePlane, CFSTR(kUSBVendorString), kCFAllocatorDefault, 0); + if (manufacturer && !env->GetObjectArrayElement(ret, 2)) { + CFStringGetCString(CFStringRef(manufacturer), buffer, sizeof(buffer), kCFStringEncodingUTF8); + jstring tmp = env->NewStringUTF(buffer); + env->SetObjectArrayElement(ret, 2, tmp); + env->DeleteLocalRef(tmp); + CFRelease(manufacturer); + } + + CFTypeRef product = 0; + product = IORegistryEntrySearchCFProperty(entry, kIOServicePlane, CFSTR(kUSBProductString), kCFAllocatorDefault, 0); + if (product && !env->GetObjectArrayElement(ret, 3)) { + CFStringGetCString(CFStringRef(product), buffer, sizeof(buffer), kCFStringEncodingUTF8); + jstring tmp = env->NewStringUTF(buffer); + env->SetObjectArrayElement(ret, 3, tmp); + env->DeleteLocalRef(tmp); + CFRelease(product); + } + + CFTypeRef serial = 0; + serial = IORegistryEntrySearchCFProperty(entry, kIOServicePlane, CFSTR(kUSBSerialNumberString), kCFAllocatorDefault, 0); + if (serial && !env->GetObjectArrayElement(ret, 4)) { + CFStringGetCString(CFStringRef(serial), buffer, sizeof(buffer), kCFStringEncodingUTF8); + jstring tmp = env->NewStringUTF(buffer); + env->SetObjectArrayElement(ret, 4, tmp); + env->DeleteLocalRef(tmp); + CFRelease(serial); + } + + kr = IORegistryEntryGetParentEntry(entry, kIOServicePlane, &entry); + } while (kr == kIOReturnSuccess); + + IOObjectRelease(entry); + + IOObjectRelease(service); + } + + IOObjectRelease(iter); + +#endif // __APPLE__ + + env->ReleaseStringUTFChars(portName, portNameChar); + return ret; +} diff --git a/src/cpp/jssc_SerialNativeInterface.h b/src/cpp/jssc_SerialNativeInterface.h index e3182e1..3d64631 100644 --- a/src/cpp/jssc_SerialNativeInterface.h +++ b/src/cpp/jssc_SerialNativeInterface.h @@ -183,6 +183,14 @@ JNIEXPORT jintArray JNICALL Java_jssc_SerialNativeInterface_getLinesStatus JNIEXPORT jboolean JNICALL Java_jssc_SerialNativeInterface_sendBreak (JNIEnv *, jobject, jlong, jint); +/* + * Class: jssc_SerialNativeInterface + * Method: getPortIdProduct + * Signature: (Ljava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_jssc_SerialNativeInterface_getPortProperties + (JNIEnv *, jclass, jstring); + #ifdef __cplusplus } #endif diff --git a/src/java/jssc/SerialNativeInterface.java b/src/java/jssc/SerialNativeInterface.java index 50eec84..443b791 100644 --- a/src/java/jssc/SerialNativeInterface.java +++ b/src/java/jssc/SerialNativeInterface.java @@ -469,4 +469,6 @@ public class SerialNativeInterface { * @since 0.8 */ public native boolean sendBreak(long handle, int duration); + + public static native String[] getPortProperties(String portName); } diff --git a/src/java/jssc/SerialPortList.java b/src/java/jssc/SerialPortList.java index e65df18..0e4b238 100644 --- a/src/java/jssc/SerialPortList.java +++ b/src/java/jssc/SerialPortList.java @@ -25,7 +25,11 @@ package jssc; import java.io.File; +import java.io.FileReader; import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; import java.util.TreeSet; import java.util.regex.Pattern; @@ -296,6 +300,77 @@ public class SerialPortList { return getUnixBasedPortNames(searchPath, pattern, comparator); } + public static Map getPortProperties(String portName) { + if(SerialNativeInterface.getOsType() == SerialNativeInterface.OS_LINUX) { + return getLinuxPortProperties(portName); + } else if(SerialNativeInterface.getOsType() == SerialNativeInterface.OS_MAC_OS_X) { + return getNativePortProperties(portName); + } else if(SerialNativeInterface.getOsType() == SerialNativeInterface.OS_WINDOWS){ + // TODO + return new HashMap(); + } else { + return new HashMap(); + } + } + + public static Map getLinuxPortProperties(String portName) { + Map props = new HashMap(); + try { + // portName has the format /dev/ttyUSB0 + String dev = portName.split("/")[2]; + File sysfsNode = new File("/sys/bus/usb-serial/devices/"+dev); + + // resolve the symbolic link and store the resulting components in an array + String[] sysfsPath = sysfsNode.getCanonicalPath().split("/"); + + // walk the tree to the root + for (int i=sysfsPath.length-2; 0 < i; i--) { + String curPath = "/"; + for (int j=1; j <= i; j++) { + curPath += sysfsPath[j]+"/"; + } + + // look for specific attributes + String[] attribs = { "idProduct", "idVendor", "manufacturer", "product", "serial" }; + for (int j=0; j < attribs.length; j++) { + try { + Scanner in = new Scanner(new FileReader(curPath+attribs[j])); + // we treat the values just as strings + props.put(attribs[j], in.next()); + } catch (Exception e) { + // ignore the attribute + } + } + + // stop once we have at least one attribute + if (0 < props.size()) { + break; + } + } + } catch (Exception e) { + // nothing to do, return what we have so far + } + return props; + } + + public static Map getNativePortProperties(String portName) { + Map props = new HashMap(); + try { + // use JNI functions to read those properties + String[] names = { "idProduct", "idVendor", "manufacturer", "product", "serial" }; + String[] values = SerialNativeInterface.getPortProperties(portName); + + for (int i=0; i < names.length; i++) { + if (values[i] != null) { + props.put(names[i], values[i]); + } + } + } catch (Exception e) { + // nothing to do, return what we have so far + } + return props; + } + /** * Get serial port names in Windows * debian/patches/series0000644000000000000000000000015712265550152012040 0ustar 0001-Look-in-usr-lib-jni-for-libjSSC-.so.patch 0002-Make-it-possible-to-retrieve-information-about-the-U.patch debian/patches/0001-Look-in-usr-lib-jni-for-libjSSC-.so.patch0000644000000000000000000000246112265550151020432 0ustar From: Scott Howard Date: Mon, 16 Dec 2013 14:54:42 -0400 Subject: Look in /usr/lib/jni for libjSSC*.so --- src/java/jssc/SerialNativeInterface.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/java/jssc/SerialNativeInterface.java b/src/java/jssc/SerialNativeInterface.java index 37a85d4..50eec84 100644 --- a/src/java/jssc/SerialNativeInterface.java +++ b/src/java/jssc/SerialNativeInterface.java @@ -87,7 +87,7 @@ public class SerialNativeInterface { String tmpFolder = System.getProperty("java.io.tmpdir"); //since 2.3.0 -> - String libRootFolder = new File(userHome).canWrite() ? userHome : tmpFolder; + String libRootFolder = "/usr/lib/jni"; //<- since 2.3.0 String javaLibPath = System.getProperty("java.library.path");//since 2.1.0 @@ -140,8 +140,8 @@ public class SerialNativeInterface { architecture = "arm" + floatStr; } - libFolderPath = libRootFolder + fileSeparator + ".jssc" + fileSeparator + osName; - libName = "jSSC-" + libVersion + "_" + architecture; + libFolderPath = libRootFolder; + libName = "jSSC-" + libVersion; libName = System.mapLibraryName(libName); if(libName.endsWith(".dylib")){//Since 2.1.0 MacOSX 10.8 fix debian/javabuild0000644000000000000000000000002712263653700011055 0ustar jssc.jar src/java/jssc debian/install0000644000000000000000000000003112264312727010557 0ustar libjSSC-*.so usr/lib/jni debian/control0000644000000000000000000000221012265550140010564 0ustar Source: jssc Section: java Priority: optional Maintainer: Debian Java Maintainers Uploaders: Scott Howard Build-Depends: debhelper (>= 9), default-jdk, javahelper (>= 0.43) Standards-Version: 3.9.5 Homepage: http://code.google.com/p/java-simple-serial-connector/ Vcs-Browser: http://anonscm.debian.org/gitweb/?p=pkg-java/jssc.git Vcs-Git: git://anonscm.debian.org/pkg-java/jssc.git Package: libjssc-java Architecture: any Depends: ${java:Depends}, ${misc:Depends}, ${shlibs:Depends} Recommends: ${java:Recommends} Description: library for working with serial ports from Java Java Simple Serial Connector (jSSC) is a Java library for interacting with serial ports from Java. . This package contains both the Java library and JNI native interface. Package: libjssc-java-doc Architecture: all Section: doc Depends: ${java:Depends}, ${misc:Depends} Recommends: ${java:Recommends} Description: library for working with serial ports from Java - doc Java Simple Serial Connector (jSSC) is a Java library for interacting with serial ports from Java. . This package contains the Javadoc API debian/rules0000755000000000000000000000075412263653700010260 0ustar #!/usr/bin/make -f export JAVA_HOME=/usr/lib/jvm/default-java # Put depended upon jars in here # export CLASSPATH= LIBRARY_VERSION=$(shell ls src/java/libs/linux/libjSSC-*_x86.so | sed 's/.*\([1-9]\.[1-9]\).*/\1/') %: dh $@ --with javahelper override_dh_auto_build: dh_auto_build cc $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS) -I$(JAVA_HOME)/include -fPIC -shared -o libjSSC-$(LIBRARY_VERSION).so src/cpp/_nix_based/jssc.cpp override_dh_installchangelogs: dh_installchangelogs -k README.txt debian/changelog0000644000000000000000000000061512265550152011045 0ustar jssc (2.6.0-2) unstable; urgency=medium * Team upload * Make it possible to retrieve information about the USB device that provides the serial port (Closes: #734820) -- David Prévot Sat, 11 Jan 2014 15:27:42 -0400 jssc (2.6.0-1) unstable; urgency=low * Initial release. (Closes: #731189) -- Scott Howard Mon, 16 Dec 2013 11:23:17 -0500 debian/watch0000644000000000000000000000022312263653700010220 0ustar version=3 http://code.google.com/p/java-simple-serial-connector/downloads/list .*/jSSC-(\d\S*)-Release\.(?:zip|tgz|tbz|txz|(?:tar\.(?:gz|bz2|xz))) debian/libjssc-java.jlibs0000644000000000000000000000001112263653700012557 0ustar jssc.jar