Skip to content

Commit

Permalink
Add hook to automatically open replay log in AdvantageScope
Browse files Browse the repository at this point in the history
  • Loading branch information
jwbonner committed Oct 31, 2024
1 parent 6dfe9ad commit 8c04c9b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions junction/core/src/org/littletonrobotics/junction/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ public static void end() {
replaySource.end();
}
receiverThread.interrupt();
try {
receiverThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
setMathShared(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import edu.wpi.first.wpilibj.RobotBase;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
Expand All @@ -38,6 +41,7 @@ public class WPILOGWriter implements LogDataReceiver {
private static final String defaultPathRio = "/U/logs";
private static final String defaultPathSim = "logs";
private static final DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yy-MM-dd_HH-mm-ss");
private static final String advantageScopeFileName = "ascope-log-path.txt";

private String folder;
private String filename;
Expand Down Expand Up @@ -132,6 +136,21 @@ public void start() {

public void end() {
log.close();

// Send log path to AdvantageScope in replay
if (Logger.hasReplaySource()) {
try {
String fullLogPath = FileSystems.getDefault().getPath(folder, filename).normalize().toAbsolutePath()
.toString();
Path advantageScopeTempPath = Paths.get(System.getProperty("java.io.tmpdir"), advantageScopeFileName);
PrintWriter writer = new PrintWriter(advantageScopeTempPath.toString(), "UTF-8");
writer.println(fullLogPath);
writer.close();
System.out.println("[AdvantageKit] Replay log sent to AdvantageScope.");
} catch (Exception e) {
DriverStation.reportError("[AdvantageKit] Failed to send log to AdvantageScope.", false);
}
}
}

public void putTable(LogTable table) {
Expand Down

0 comments on commit 8c04c9b

Please sign in to comment.