Launched binary app
Esse commit está contido em:
@@ -5,3 +5,4 @@ OpenBCI_GUI/build/
|
||||
OpenBCI_GUI/temp.txt
|
||||
OpenBCI_GUI/t-temp.txt
|
||||
OpenBCI_GUI/build/source/*.java
|
||||
*.app
|
||||
|
||||
@@ -95,6 +95,7 @@ class OpenBCI_Ganglion {
|
||||
|
||||
private int tcpGanglionPort = 10996;
|
||||
private String tcpGanglionIP = "127.0.0.1";
|
||||
private boolean tcpClientActive = false;
|
||||
|
||||
private final float fs_Hz = 200.0f; //sample rate used by OpenBCI Ganglion board... set by its Arduino code
|
||||
private final float MCP3912_Vref = 1.2f; // reference voltage for ADC in MCP3912 set in hardware
|
||||
@@ -132,8 +133,12 @@ class OpenBCI_Ganglion {
|
||||
OpenBCI_Ganglion(PApplet applet) {
|
||||
//<>//
|
||||
// Initialize TCP connection
|
||||
tcpClient = new Client(applet, tcpGanglionIP, tcpGanglionPort);
|
||||
|
||||
if (startTCPClient(applet)) {
|
||||
println("Connection established with node server.");
|
||||
} else {
|
||||
println("Connection failed to establish with node server.");
|
||||
}
|
||||
|
||||
// For storing data into
|
||||
dataPacket = new DataPacket_ADS1299(nEEGValuesPerPacket, nAuxValuesPerPacket); //this should always be 8 channels
|
||||
for(int i = 0; i < nEEGValuesPerPacket; i++) {
|
||||
@@ -144,6 +149,21 @@ class OpenBCI_Ganglion {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @descirpiton Used to `try` and start the tcpClient
|
||||
* @param applet {PApplet} - The main applet.
|
||||
* @return {boolean} - True if able to start.
|
||||
*/
|
||||
public boolean startTCPClient(PApplet applet) {
|
||||
try {
|
||||
tcpClient = new Client(applet, tcpGanglionIP, tcpGanglionPort);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
println("startTCPClient: ConnectException: " + e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Return true if the display needs to be updated for the BLE list
|
||||
public void parseMessage(String msg) {
|
||||
String[] list = split(msg, ',');
|
||||
@@ -375,13 +395,19 @@ class OpenBCI_Ganglion {
|
||||
println("OpenBCI_Ganglion: stopDataTransfer(): sending \'" + command_stop);
|
||||
safeTCPWrite(TCP_CMD_COMMAND + "," + command_stop + TCP_STOP);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description Write to TCP server
|
||||
* @params out {String} - The string message to write to the server.
|
||||
* @returns {boolean} - True if able to write, false otherwise.
|
||||
*/
|
||||
public boolean safeTCPWrite(String out) {
|
||||
if (tcpClient != null) { //<>//
|
||||
if (tcpClient == null) return false;
|
||||
try {
|
||||
tcpClient.write(out);
|
||||
return true;
|
||||
} else {
|
||||
println("Error: Attempted to TCP write with no tcpClient initialized");
|
||||
} catch (NullPointerException e) {
|
||||
println("Error: Attempted to TCP write with no server connection initialized");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -412,4 +438,39 @@ class OpenBCI_Ganglion {
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Potential use for windows systems
|
||||
// public class ApplicationUtilities
|
||||
// {
|
||||
// public static void runApplication(String applicationFilePath) throws IOException, InterruptedException
|
||||
// {
|
||||
// File application = new File(applicationFilePath);
|
||||
// String applicationName = application.getName();
|
||||
//
|
||||
// if (!isProcessRunning(applicationName))
|
||||
// {
|
||||
// Desktop.getDesktop().open(application);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // http://stackoverflow.com/a/19005828/3764804
|
||||
// private static boolean isProcessRunning(String processName) throws IOException, InterruptedException
|
||||
// {
|
||||
// ProcessBuilder processBuilder = new ProcessBuilder("tasklist.exe");
|
||||
// Process process = processBuilder.start();
|
||||
// String tasksList = toString(process.getInputStream());
|
||||
//
|
||||
// return tasksList.contains(processName);
|
||||
// }
|
||||
//
|
||||
// // http://stackoverflow.com/a/5445161/3764804
|
||||
// private static String toString(InputStream inputStream)
|
||||
// {
|
||||
// Scanner scanner = new Scanner(inputStream, "UTF-8").useDelimiter("\\A");
|
||||
// String string = scanner.hasNext() ? scanner.next() : "";
|
||||
// scanner.close();
|
||||
//
|
||||
// return string;
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -30,7 +30,7 @@ import hypermedia.net.*; //for UDP networking
|
||||
import processing.net.*; // For TCP networking
|
||||
import grafica.*;
|
||||
import java.lang.reflect.*; // For callbacks
|
||||
|
||||
import java.io.InputStreamReader; // For input
|
||||
import java.awt.MouseInfo;
|
||||
|
||||
|
||||
@@ -202,6 +202,7 @@ int indices = 0;
|
||||
boolean synthesizeData = false;
|
||||
|
||||
Process nodeHubby;
|
||||
int hubPid = 0;
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Global Functions
|
||||
@@ -209,6 +210,9 @@ Process nodeHubby;
|
||||
|
||||
//========================SETUP============================//
|
||||
void setup() {
|
||||
// Try to start the node hub
|
||||
hubStart();
|
||||
|
||||
println("Welcome to the Processing-based OpenBCI GUI!"); //Welcome line.
|
||||
println("Last update: 6/25/2016"); //Welcome line.
|
||||
println("For more information about how to work with this code base, please visit: http://docs.openbci.com/tutorials/01-GettingStarted");
|
||||
@@ -256,14 +260,6 @@ void setup() {
|
||||
}
|
||||
);
|
||||
|
||||
// Try to start the node hub
|
||||
if (hubStart()) {
|
||||
ganglion = new OpenBCI_Ganglion(this);
|
||||
hubRunning = true;
|
||||
} else {
|
||||
println("failed to start node hub");
|
||||
}
|
||||
|
||||
//set up controlPanelCollapser button
|
||||
fontInfo = new PlotFontInfo();
|
||||
helpWidget = new HelpWidget(0, win_y - 30, win_x, 30);
|
||||
@@ -298,9 +294,11 @@ void setup() {
|
||||
}
|
||||
|
||||
myPresentation = new Presentation();
|
||||
|
||||
|
||||
// prepare the exit handler to stop the node hub process on shut down
|
||||
prepareExitHandler();
|
||||
|
||||
ganglion = new OpenBCI_Ganglion(this);
|
||||
}
|
||||
//====================== END-OF-SETUP ==========================//
|
||||
|
||||
@@ -315,7 +313,7 @@ void draw() {
|
||||
|
||||
//====================== END-OF-DRAW ==========================//
|
||||
|
||||
// must add "prepareExitHandler();" in setup() for Processing sketches
|
||||
// must add "prepareExitHandler();" in setup() for Processing sketches
|
||||
private void prepareExitHandler () {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
||||
public void run () {
|
||||
@@ -324,33 +322,75 @@ private void prepareExitHandler () {
|
||||
if (hubStop()) {
|
||||
System.out.println("SHUTDOWN HUB");
|
||||
} else {
|
||||
System.out.println("FAILED TO SHUTDOWN HUB");
|
||||
System.out.println("FAILED TO SHUTDOWN HUB");
|
||||
}
|
||||
} catch (Exception ex){
|
||||
ex.printStackTrace(); // not much else to do at this point
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
getRunningProcessMac();
|
||||
}
|
||||
|
||||
boolean hubStart() {
|
||||
void hubStart() {
|
||||
println("Launching application");
|
||||
//nodeHubby = launch("/Applications/Electron Boilerplate.app");
|
||||
return true;
|
||||
//delay(1000);
|
||||
//if (nodeHubby != null) {
|
||||
//return true;
|
||||
//} else {
|
||||
//return false;
|
||||
//}
|
||||
try {
|
||||
// https://forum.processing.org/two/discussion/13053/use-launch-for-applications-kept-in-data-folder
|
||||
getRunningProcessMac();
|
||||
if (isWindows()) {
|
||||
nodeHubby = launch(dataPath("Ganglion Hub.exe"));
|
||||
} else {
|
||||
nodeHubby = launch(dataPath("Ganglion Hub.app"));
|
||||
}
|
||||
hubPid = nodeHubby.pid;
|
||||
println("\n\n\n hubPid " + hubPid);
|
||||
hubRunning = true;
|
||||
} catch (Exception e) {
|
||||
println("hubStart: " + e);
|
||||
hubRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
boolean hubStop() {
|
||||
if (nodeHubby != null) {
|
||||
nodeHubby.destroy();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
endProcess();
|
||||
return true;
|
||||
// if (nodeHubby != null) {
|
||||
// nodeHubby.destroy();
|
||||
// return true;
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
|
||||
private boolean isWindows() {
|
||||
return System.getProperty("os.name").toLowerCase().indexOf("windows") > -1;
|
||||
}
|
||||
|
||||
void endProcess() {
|
||||
Runtime rt = Runtime.getRuntime();
|
||||
try {
|
||||
if (isWindows())
|
||||
rt.exec("taskkill Ganglion Hub.exe");
|
||||
else
|
||||
rt.exec("kill -9 Ganglion Hub");
|
||||
} catch (IOException err) {
|
||||
err.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
void getRunningProcessMac() {
|
||||
try {
|
||||
String line;
|
||||
Process p = Runtime.getRuntime().exec("ps -e");
|
||||
BufferedReader input =
|
||||
new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
while ((line = input.readLine()) != null) {
|
||||
System.out.println(line); //<-- Parse data here.
|
||||
}
|
||||
input.close();
|
||||
} catch (Exception err) {
|
||||
err.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -834,4 +874,4 @@ PVector getWindowLocation(String renderer) {
|
||||
}
|
||||
return l;
|
||||
}
|
||||
//END OF CODE FOR FIXING WEIRD EXIT CRASH ISSUE -- 7/27/16 ===========================
|
||||
//END OF CODE FOR FIXING WEIRD EXIT CRASH ISSUE -- 7/27/16 ===========================
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário