Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import javax.swing.JFrame;

Expand Down Expand Up @@ -82,9 +83,40 @@ public boolean isExeRunning(String exeName) {
return false;
}
}

public boolean isExeRunningMacOS(String exeName) {
try {
Process process = Runtime.getRuntime().exec(new String[]{"pgrep", "-x", exeName});
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
boolean found = reader.readLine() != null;

if (!process.waitFor(5, TimeUnit.SECONDS)) { // Wait up to 5 seconds
process.destroy(); // Terminate the process if it doesn't exit
System.err.println("pgrep process timed out.");
return false; // Consider it not found or an error
}

return found;
} catch (IOException e) {
System.err.println("Error executing pgrep command: " + e.getMessage());
e.printStackTrace();
return false;
} catch (InterruptedException e) {
System.err.println("Thread interrupted while waiting for pgrep process: " + e.getMessage());
Thread.currentThread().interrupt(); // Restore the interrupted status
return false;
}
}

public boolean isServerRunning() {
if(UtilShimmer.isOsMac()) {
return isExeRunningMacOS(mExeNameMac);
} else {
return isExeRunning(mExeNameWindows);
}
}

public int startServer() throws Exception {


int port = getFreePort();

System.out.println(port + " is free");
Expand Down Expand Up @@ -117,7 +149,6 @@ public int startServer() throws Exception {
processThread.start();
return port;
// You can continue with other tasks here

}

public void stopServer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,29 +539,29 @@ public void disconnect() throws ShimmerException {
setBluetoothRadioState(BT_STATE.DISCONNECTED);
}

private void closeConnection(){
try {
if (mIOThread != null) {
mIOThread.stop = true;
// Closing serial port before before thread is finished stopping throws an error so waiting here
while(mIOThread != null && mIOThread.isAlive());

mIOThread = null;
if(mUseProcessingThread){
mPThread.stop = true;
mPThread = null;
}
}
mIsStreaming = false;
mIsInitialised = false;

setBluetoothRadioState(BT_STATE.DISCONNECTED);
} catch (Exception ex) {
consolePrintException(ex.getMessage(), ex.getStackTrace());
setBluetoothRadioState(BT_STATE.DISCONNECTED);
}
private void closeConnection() {
try {
if (mIOThread != null) {
mIOThread.stop = true;
mIOThread.interrupt();
mIOThread.join(); // Wait until the thread terminates
mIOThread = null;
if (mUseProcessingThread) {
mPThread.stop = true;
mPThread.interrupt();
mPThread.join();
mPThread = null;
}
}
mIsStreaming = false;
mIsInitialised = false;

setBluetoothRadioState(BT_STATE.DISCONNECTED);
} catch (Exception ex) {
consolePrintException(ex.getMessage(), ex.getStackTrace());
setBluetoothRadioState(BT_STATE.DISCONNECTED);
}
}

//Need to override here because ShimmerDevice class uses a different map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class BasicShimmerBluetoothManagerPc extends ShimmerBluetoothManager {
List<VerisenseDevice> verisenseDeviceList = new ArrayList<VerisenseDevice>();
List<ShimmerGRPC> shimmer3BleDeviceList = new ArrayList<ShimmerGRPC>();
public static int mGRPCPort;
private GrpcBLERadioByteTools grpcTool;

public BasicShimmerBluetoothManagerPc() {
startGrpc();
Expand All @@ -54,7 +55,7 @@ public BasicShimmerBluetoothManagerPc(boolean enableGRPC) {

protected void startGrpc(String path) {
try {
GrpcBLERadioByteTools grpcTool = new GrpcBLERadioByteTools("ShimmerBLEGrpc.exe",path);
grpcTool = new GrpcBLERadioByteTools("ShimmerBLEGrpc.exe",path);
mGRPCPort = grpcTool.startServer();
} catch(Exception e) {
e.printStackTrace();
Expand All @@ -63,12 +64,16 @@ protected void startGrpc(String path) {

protected void startGrpc() {
try {
GrpcBLERadioByteTools grpcTool = new GrpcBLERadioByteTools();
grpcTool = new GrpcBLERadioByteTools();
mGRPCPort = grpcTool.startServer();
} catch(Exception e) {
e.printStackTrace();
}
}

public boolean isGrpcServerRunning() {
return grpcTool.isServerRunning();
}

public void setPathToVeriBLEApp(String path) {
mPathToVeriBLEApp = path;
Expand Down