Files
2022NoWayHome/NetworkTablesDesktopClient/src/main/java/NetworkTablesDesktopClient.java
T
nathanrsxtn 71e082e7bd Change path downloader to connect to real robot
Add explanation to path downloader
2022-03-04 00:02:34 -07:00

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();
}
}
}