Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FreeBSD support #81

Open
wants to merge 1 commit into
base: 2.8.1-experimental
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/cpp/_nix_based/jssc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ JNIEXPORT jbyteArray JNICALL Java_jssc_SerialNativeInterface_readBytes
FD_CLR(portHandle, &read_fd_set);
jbyteArray returnArray = env->NewByteArray(byteCount);
env->SetByteArrayRegion(returnArray, 0, byteCount, lpBuffer);
delete lpBuffer;
delete[] lpBuffer;
return returnArray;
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/cpp/jssc_SerialNativeInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ extern "C" {
#define jssc_SerialNativeInterface_OS_SOLARIS 2L
#undef jssc_SerialNativeInterface_OS_MAC_OS_X
#define jssc_SerialNativeInterface_OS_MAC_OS_X 3L
#undef jssc_SerialNativeInterface_FREEBSD
#define jssc_SerialNativeInterface_FREEBSD 4L
#undef jssc_SerialNativeInterface_ERR_PORT_BUSY
#define jssc_SerialNativeInterface_ERR_PORT_BUSY -1LL
#undef jssc_SerialNativeInterface_ERR_PORT_NOT_FOUND
Expand Down
49 changes: 31 additions & 18 deletions src/main/java/jssc/SerialNativeAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ else if(osName.equals("Mac OS X") || osName.equals("Darwin")){//os.name "Darwin"
osName = "mac_os_x";
osType = SerialNativeInterface.OS_MAC_OS_X;
}//<- since 0.9.0
else if(osName.equals("FreeBSD")){
osName = "freebsd";
osType = SerialNativeInterface.OS_FREEBSD;
}

if(architecture.equals("i386") || architecture.equals("i686")){
architecture = "x86";
Expand All @@ -87,28 +91,37 @@ else if(architecture.equals("amd64") || architecture.equals("universal")){//os.a
architecture = "x86_64";
}
else if(architecture.equals("arm")) {//since 2.1.0
String floatStr = "sf";
if(javaLibPath.toLowerCase().contains("gnueabihf") || javaLibPath.toLowerCase().contains("armhf")){
floatStr = "hf";
}
else {
try {
Process readelfProcess = Runtime.getRuntime().exec("readelf -A /proc/self/exe");
BufferedReader reader = new BufferedReader(new InputStreamReader(readelfProcess.getInputStream()));
String buffer = "";
while((buffer = reader.readLine()) != null && !buffer.isEmpty()){
if(buffer.toLowerCase().contains("Tag_ABI_VFP_args".toLowerCase())){
floatStr = "hf";
break;
if(osName.equals("Linux")){
String floatStr = "sf";
if(javaLibPath.toLowerCase().contains("gnueabihf") || javaLibPath.toLowerCase().contains("armhf")){
floatStr = "hf";
}
else {
try {
Process readelfProcess = Runtime.getRuntime().exec("readelf -A /proc/self/exe");
BufferedReader reader = new BufferedReader(new InputStreamReader(readelfProcess.getInputStream()));
String buffer = "";
while((buffer = reader.readLine()) != null && !buffer.isEmpty()){
if(buffer.toLowerCase().contains("Tag_ABI_VFP_args".toLowerCase())){
floatStr = "hf";
break;
}
}
reader.close();
}
catch (Exception ex) {
//Do nothing
}
reader.close();
}
catch (Exception ex) {
//Do nothing
architecture = "arm" + floatStr;
}
else if(osName.equals("FreeBSD")){
String floatStr = "";
if(javaLibPath.toLowerCase().contains("armhf")){
floatStr = "hf";
}
architecture = "arm" + floatStr;
}
architecture = "arm" + floatStr;
}

libFolderPath = libRootFolder + fileSeparator + ".jssc" + fileSeparator + osName;
Expand Down Expand Up @@ -268,4 +281,4 @@ public SerialNativeInterface getInterface() {
// public String getLibraryMinorSuffix() {
// return libMinorSuffix;
// }
}
}
1 change: 1 addition & 0 deletions src/main/java/jssc/SerialNativeInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class SerialNativeInterface {
public static final int OS_WINDOWS = 1;
public static final int OS_SOLARIS = 2;//since 0.9.0
public static final int OS_MAC_OS_X = 3;//since 0.9.0
public static final int OS_FREEBSD = 4;

/**
* @since 2.3.0
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/org/scream3r/jssc/SerialPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ public boolean setEventsMask(int mask) throws SerialPortException {
checkPortOpened("setEventsMask()");
if(SerialNativeAccess.getInstance().getOsType() == SerialNativeInterface.OS_LINUX ||
SerialNativeAccess.getInstance().getOsType() == SerialNativeInterface.OS_SOLARIS ||
SerialNativeAccess.getInstance().getOsType() == SerialNativeInterface.OS_MAC_OS_X){//since 0.9.0
SerialNativeAccess.getInstance().getOsType() == SerialNativeInterface.OS_MAC_OS_X || //since 0.9.0
SerialNativeAccess.getInstance().getOsType() == SerialNativeInterface.OS_FREEBSD){
linuxMask = mask;
if(mask > 0){
maskAssigned = true;
Expand Down Expand Up @@ -299,7 +300,8 @@ public int getEventsMask() throws SerialPortException {
checkPortOpened("getEventsMask()");
if(SerialNativeAccess.getInstance().getOsType() == SerialNativeInterface.OS_LINUX ||
SerialNativeAccess.getInstance().getOsType() == SerialNativeInterface.OS_SOLARIS ||
SerialNativeAccess.getInstance().getOsType() == SerialNativeInterface.OS_MAC_OS_X){//since 0.9.0
SerialNativeAccess.getInstance().getOsType() == SerialNativeInterface.OS_MAC_OS_X || //since 0.9.0
SerialNativeAccess.getInstance().getOsType() == SerialNativeInterface.OS_FREEBSD){
return linuxMask;
}
return serialInterface.getEventsMask(portHandle);
Expand Down Expand Up @@ -1042,7 +1044,8 @@ private void addEventListener(SerialPortEventListener listener, int mask, boolea
private EventThread getNewEventThread() {
if(SerialNativeAccess.getInstance().getOsType() == SerialNativeInterface.OS_LINUX ||
SerialNativeAccess.getInstance().getOsType() == SerialNativeInterface.OS_SOLARIS ||
SerialNativeAccess.getInstance().getOsType() == SerialNativeInterface.OS_MAC_OS_X){//since 0.9.0
SerialNativeAccess.getInstance().getOsType() == SerialNativeInterface.OS_MAC_OS_X || //since 0.9.0
SerialNativeAccess.getInstance().getOsType() == SerialNativeInterface.OS_FREEBSD){
return new LinuxEventThread();
}
return new EventThread();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/scream3r/jssc/SerialPortList.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public class SerialPortList {
PORTNAMES_PATH = "/dev/";
break;
}
case SerialNativeInterface.OS_FREEBSD: {
PORTNAMES_REGEXP = Pattern.compile("(cuaU)[0-9]{1,3}");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern should be "(cuaU)[0-9]{1,3}$" to pull in only the base cuaU* nodes and not the .init/.lock devices.

PORTNAMES_PATH = "/dev/";
break;
}
case SerialNativeInterface.OS_WINDOWS: {
PORTNAMES_REGEXP = Pattern.compile("");
PORTNAMES_PATH = "";
Expand Down