mirror of
https://github.com/Team4388/2022NoWayHome.git
synced 2026-06-09 08:48:07 -06:00
71e082e7bd
Add explanation to path downloader
37 lines
1.3 KiB
Java
37 lines
1.3 KiB
Java
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.util.Scanner;
|
|
|
|
import edu.wpi.first.networktables.EntryListenerFlags;
|
|
import edu.wpi.first.networktables.NetworkTableInstance;
|
|
|
|
/**
|
|
* Connects to the NetworkTables server and listens for changes to the "Recording" table. When a
|
|
* change is detected, it writes the value to a file.
|
|
*/
|
|
public class NetworkTablesDesktopClient {
|
|
public static void main(String[] args) {
|
|
NetworkTableInstance instance = NetworkTableInstance.getDefault();
|
|
instance.getTable("Recording").addEntryListener((table, key, entry, value, flags) -> {
|
|
Path path = Path.of("..", "src", "main", "deploy", "pathplanner", key);
|
|
File file = path.toFile();
|
|
try {
|
|
System.err.println("Creating path " + key);
|
|
file.createNewFile();
|
|
Files.writeString(file.toPath(), value.getString());
|
|
System.err.println("Recorded path to " + file.getPath());
|
|
} catch (IOException exception) {
|
|
exception.printStackTrace();
|
|
}
|
|
}, EntryListenerFlags.kNew);
|
|
instance.startClientTeam(4388);
|
|
instance.startDSClient();
|
|
try (Scanner scanner = new Scanner(System.in)) {
|
|
System.err.println("Press enter to stop...");
|
|
scanner.nextLine();
|
|
}
|
|
}
|
|
}
|