NeuronRobotics / nrjavaserial

A Java Serial Port system. This is a fork of the RXTX project that uses in jar loading of the native code.
Other
345 stars 143 forks source link

No support for illumos and solaris, but have patch? #139

Open sjorge opened 5 years ago

sjorge commented 5 years ago

While trying to use OpenHAB on illumos (SmartOS distro, more specific) I noticed there is no support in nrjavaserial so I cannot connect to my zwave serial device. It throws the following errors:

java.lang.ExceptionInInitializerError thrown while loading gnu.io.RXTXCommDriver
java.lang.NoClassDefFoundError: Could not initialize class gnu.io.RXTXCommDriver thrown while loading gnu.io.RXTXCommDriver
java.lang.NoClassDefFoundError: Could not initialize class gnu.io.RXTXCommDriver thrown while loading gnu.io.RXTXCommDriver
java.lang.NoClassDefFoundError: Could not initialize class gnu.io.RXTXCommDriver thrown while loading gnu.io.RXTXCommDriver

I made a quick and dirty hack to get the native bindings and have a patch:

diff --git a/Makefile b/Makefile
index 8ba0815..c53917c 100644
--- a/Makefile
+++ b/Makefile
@@ -25,6 +25,15 @@ freebsd32:
 freebsd64:
        gmake -C src/main/c freebsd64
        gradle build
+solaris:
+       gmake -C src/main/c solaris
+       gradle build
+solaris32:
+       gmake -C src/main/c solaris32
+       gradle build
+solaris64:
+       gmake -C src/main/c solaris64
+       gradle build
 arm:
        sudo apt-get install g++-arm-linux-gnueabihf g++-arm-linux-gnueabi
        make -C src/main/c arm7
diff --git a/src/main/c/Makefile b/src/main/c/Makefile
index 77c0bf5..be5f9d3 100644
--- a/src/main/c/Makefile
+++ b/src/main/c/Makefile
@@ -51,6 +51,16 @@ LINKBSD32=c++ -m32 -shared
 CCBSD64=cc $(BSDINCLUDE) -O3 -Wall -c -fmessage-length=0 -fPIC -m64 -MMD
 LINKBSD64=c++ -m64 -shared

+ILMOBJ=build/fixup.o build/fuserImp.o build/SerialImp.o
+ILMINCLUDE=-I"./include" -I"./include/target" -I/opt/local/java/openjdk8/include/ -I/opt/local/java/openjdk8/include/solaris/
+
+CCILM32=cc $(ILMINCLUDE) -O3 -Wall -c -fmessage-length=0 -fPIC -m32 -MMD
+LINKILM32=c++ -m32 -shared
+
+
+CCILM64=cc $(ILMINCLUDE) -O3 -Wall -c -fmessage-length=0 -fPIC -m64 -MMD
+LINKILM64=c++ -m64 -shared
+

 #Wine Windows
 WINLINKOPT = -shared -Wl,--add-stdcall-alias -DBUILD_DLL
@@ -103,6 +113,11 @@ dirs:
         mkdir -p resources/native/freebsd/x86_64/; \
         mkdir -p resources/native/freebsd/x86_32/; \
        fi
+       if (test -d resources/native/solaris);\
+        then echo "solaris native dir exists"; else\
+        mkdir -p resources/native/solaris/x86_64/; \
+        mkdir -p resources/native/solaris/x86_32/; \
+       fi

 windowsLocal:
        $(CCWIN64N) -c src/windows/init.c -o build/init.o
@@ -171,6 +186,22 @@ freebsd64:dirs
        #rm "resources/native/freebsd/x86_64/libNRJavaSerial.so"
        $(LINKBSD64) -o"resources/native/freebsd/x86_64/libNRJavaSerial.so" $(LINOBJ)
        rm build/*
+solaris:solaris32 solaris64
+       echo all solaris ok!
+solaris32:dirs
+       $(CCILM32) src/fixup.c -o build/fixup.o
+       $(CCILM32) src/fuserImp.c -o build/fuserImp.o
+       $(CCILM32) src/SerialImp.c -o build/SerialImp.o
+       #rm "resources/native/solaris/x86_32/libNRJavaSerial.so"
+       $(LINKILM32) -o"resources/native/solaris/x86_32/libNRJavaSerial.so" $(LINOBJ)
+       rm build/*
+solaris64:dirs
+       $(CCILM64) src/fixup.c -o build/fixup.o
+       $(CCILM64) src/fuserImp.c -o build/fuserImp.o
+       $(CCILM64) src/SerialImp.c -o build/SerialImp.o
+       #rm "resources/native/solaris/x86_64/libNRJavaSerial.so"
+       $(LINKILM64) -o"resources/native/solaris/x86_64/libNRJavaSerial.so" $(LINOBJ)
+       rm build/*

 .PHONY: arm
 arm:
diff --git a/src/main/java/gnu/io/NativeResource.java b/src/main/java/gnu/io/NativeResource.java
index 6467aca..997ccbf 100644
--- a/src/main/java/gnu/io/NativeResource.java
+++ b/src/main/java/gnu/io/NativeResource.java
@@ -191,6 +191,12 @@ public class NativeResource {
                        }else {
                                file="/native/freebsd/x86_32/" + name;
                        }
+               }else if(OSUtil.isSolaris()) {
+                       if(OSUtil.is64Bit()) {
+                               file="/native/solaris/x86_64/" + name;
+                       }else {
+                               file="/native/solaris/x86_32/" + name;
+                       }
                }else{
                        //System.err.println("Can't load native file: "+name+" for os arch: "+OSUtil.getOsArch());
                        return null;
@@ -317,6 +323,10 @@ public class NativeResource {
                        return getOsName().toLowerCase().startsWith("freebsd");
                }

+               public static boolean isSolaris() {
+                       return getOsName().toLowerCase().startsWith("sunos");
+               }
+
                public static boolean isOSX() {
                        return getOsName().toLowerCase().startsWith("mac");
                }
@@ -326,7 +336,7 @@ public class NativeResource {
                                return ".dll";
                        }

-                       if(isLinux() || isFreeBSD()) {
+                       if(isLinux() || isFreeBSD() || isSolaris()) {
                                return ".so";
                        }

diff --git a/src/main/java/gnu/io/RXTXCommDriver.java b/src/main/java/gnu/io/RXTXCommDriver.java
index 19e63c2..6579f52 100644
--- a/src/main/java/gnu/io/RXTXCommDriver.java
+++ b/src/main/java/gnu/io/RXTXCommDriver.java
@@ -603,11 +603,11 @@ public class RXTXCommDriver implements CommDriver
                                dev = new File( "/dev/term" );
                                if( dev.list().length > 0 )
                                        term[l++] ="term/";
-       /*
-                               dev = new File( "/dev/cua0" );
+
+                               dev = new File( "/dev/cua" );
                                if( dev.list().length > 0 )
                                        term[l++] = "cua/";
-       */
+
                                String[] temp = new String[l];
                                for(l--;l >= 0;l--)
                                        temp[l] = term[l];

Once I know for sure this is working, would there be interesting in a PR?

sjorge commented 5 years ago

illumos is fork of opensolaris, so I think I might need to rename illumos to solaris everywhere, pending testing with OpenHAB

Yep, as illumos still uses all the headers and include under 'solaris' directory, this needed to be rename.

I am still having issues with openhab so perhaps I need to find a simpler program to test if my modifications are correct instead of using something so complex from the get go.

sjorge commented 5 years ago

Looks like some more patching is needed, I'll look into it. The native lib still compiles but does not seem to work anymore for illumos/solaris. Not sure I can fix that as it is getting out reach of my skill set.

sjorge commented 5 years ago

I've update the diff in the first comment

2019-02-10 11:19:01.434 [INFO ] [ing.zwave.handler.ZWaveSerialHandler] - Connecting to serial port '/dev/cua/0'
2019-02-10 11:19:01.455 [INFO ] [ing.zwave.handler.ZWaveSerialHandler] - Serial port is initialized
2019-02-10 11:19:01.480 [INFO ] [ve.internal.protocol.ZWaveController] - Starting ZWave controller
2019-02-10 11:19:01.481 [INFO ] [ve.internal.protocol.ZWaveController] - ZWave timeout is set to 5000ms. Soft reset is false

Openhab now reports zwave as working! After compiling wit these patches and dropping the new library in /opt/openhab/addons!

Shall I open a PR?

sjorge commented 5 years ago

Just confirmed, openhab is seeing my zwave sensor perfectly with this patch applied.

madhephaestus commented 4 years ago

cool, submit a PR and add toolchain-build instructions to the readme for building under ubuntu 18.04.