Skip to content

Commit

Permalink
ping device under dbug
Browse files Browse the repository at this point in the history
  • Loading branch information
sblantipodi committed Jan 9, 2025
1 parent 3208158 commit 8360956
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/dpsoftware/FireflyLuciferin.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void start(Stage stage) throws Exception {
}
}
grabberManager.getFPS();
grabberManager.pingDevices();
grabberManager.pingDevice();
imageProcessor.calculateBorders();
// If this instance spawns new instances, don't launch grabbers here.
if (!(MainSingleton.getInstance().spawnInstances && MainSingleton.getInstance().config.getMultiMonitor() > 1)) {
Expand Down
21 changes: 1 addition & 20 deletions src/main/java/org/dpsoftware/NativeExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ public final class NativeExecutor {
*
* @param cmdToRunUsingArgs Command to run and args, in an array
* @param waitForOutput Example: If you need to exit the app you don't need to wait for the output or the app will not exit (millis)
* @param throwException throws exception on error
* @return A list of string containing the output, empty list if command does not exist
*/
public static List<String> runNative(String[] cmdToRunUsingArgs, int waitForOutput, boolean throwException) {
public static List<String> runNative(String[] cmdToRunUsingArgs, int waitForOutput) {
ArrayList<String> cmdOutput = new ArrayList<>();
try {
log.trace("Executing cmd={}", Arrays.stream(cmdToRunUsingArgs).toList());
Expand All @@ -87,32 +86,14 @@ public static List<String> runNative(String[] cmdToRunUsingArgs, int waitForOutp
} else {
log.error("The command {} has exceeded the time limit and has been terminated.", Arrays.toString(cmdToRunUsingArgs));
process.destroy();
if (throwException) {
throw new RuntimeException();
}
}
}
} catch (Exception e) {
log.error(e.getMessage());
if (throwException) {
throw new RuntimeException(e);
}
}
return cmdOutput;
}

/**
* This is the real runner that executes command.
* Don't use this method directly and prefer the runNativeWaitForOutput() or runNativeNoWaitForOutput() shortcut.
*
* @param cmdToRunUsingArgs Command to run and args, in an array
* @param waitForOutput Example: If you need to exit the app you don't need to wait for the output or the app will not exit (millis)
* @return A list of string containing the output, empty list if command does not exist
*/
public static List<String> runNative(String[] cmdToRunUsingArgs, int waitForOutput) {
return runNative(cmdToRunUsingArgs, waitForOutput, false);
}

/**
* Spawn new Luciferin Native instance
*
Expand Down
25 changes: 6 additions & 19 deletions src/main/java/org/dpsoftware/grabber/GrabberManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,31 +254,18 @@ public void getFPS() {
scheduledExecutorService.scheduleAtFixedRate(framerateTask, 0, 5, TimeUnit.SECONDS);
}

// TODO
private static void ping(String ip) {
List<String> pingCmd = new ArrayList<>(Arrays.stream(NativeExecutor.isWindows() ? Constants.PING_WINDOWS : Constants.PING_LINUX).toList());
pingCmd.add(ip);
NativeExecutor.runNative(pingCmd.toArray(String[]::new), 3000);
}

// TODO
/**
* Ping devices
* Ping device
*/
public void pingDevices() {
if (MainSingleton.getInstance().config.isFullFirmware()) {
public void pingDevice() {
if (MainSingleton.getInstance().config.isFullFirmware() && log.isDebugEnabled()) {
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
Runnable framerateTask = () -> {
// if (!CommonUtility.getDeviceToUseWithSatellites().isEmpty()) {
// for (GlowWormDevice sat : CommonUtility.getDeviceToUseWithSatellites()) {
// if (sat != null && sat.getDeviceIP() != null && NetworkManager.isValidIp(sat.getDeviceIP())) {
// ping(sat.getDeviceIP());
// }
// }
// }
if (CommonUtility.getDeviceToUse() != null && CommonUtility.getDeviceToUse().getDeviceIP() != null
&& NetworkManager.isValidIp(CommonUtility.getDeviceToUse().getDeviceIP())) {
ping(CommonUtility.getDeviceToUse().getDeviceIP());
List<String> pingCmd = new ArrayList<>(Arrays.stream(NativeExecutor.isWindows() ? Constants.PING_WINDOWS : Constants.PING_LINUX).toList());
pingCmd.add(CommonUtility.getDeviceToUse().getDeviceIP());
NativeExecutor.runNative(pingCmd.toArray(String[]::new), 3000);
}
};
scheduledExecutorService.scheduleAtFixedRate(framerateTask, 0, 5, TimeUnit.SECONDS);
Expand Down

0 comments on commit 8360956

Please sign in to comment.