Create timesync JNI for testing client (#1433)

This commit is contained in:
Matt
2024-10-31 08:27:19 -07:00
committed by GitHub
parent 937bafa8e2
commit 37aaa49b32
69 changed files with 2252 additions and 368 deletions

View File

@@ -0,0 +1,69 @@
/*
* Copyright (C) Photon Vision.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net;
import static org.junit.jupiter.api.Assertions.fail;
import edu.wpi.first.hal.HAL;
import java.io.IOException;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.photonvision.jni.PhotonTargetingJniLoader;
import org.photonvision.jni.TimeSyncClient;
import org.photonvision.jni.TimeSyncServer;
import org.photonvision.jni.WpilibLoader;
public class TimeSyncTest {
@BeforeAll
public static void load_wpilib() throws UnsatisfiedLinkError, IOException {
WpilibLoader.loadLibraries();
if (!PhotonTargetingJniLoader.load()) {
fail();
}
}
@AfterAll
public static void teardown() {
HAL.shutdown();
}
@Test
public void smoketest() throws InterruptedException {
HAL.initialize(1000, 0);
// NetworkTableInstance.getDefault().stopClient();
// NetworkTableInstance.getDefault().startServer();
var server = new TimeSyncServer(5810);
System.err.println("Waiting: PID=" + ProcessHandle.current().pid());
server.start();
var client = new TimeSyncClient("127.0.0.1", 5810, 0.5);
for (int i = 0; i < 5; i++) {
Thread.sleep(100);
System.out.println(client.getPingMetadata());
}
server.stop();
client.stop();
}
}

View File

@@ -42,7 +42,7 @@ class PacketTest {
@Test
void pipelineResultSerde() {
var ret1 = new PhotonPipelineResult(1, 2, 3, List.of());
var ret1 = new PhotonPipelineResult(1, 2, 3, 1024, List.of());
var p1 = new Packet(10);
PhotonPipelineResult.photonStruct.pack(p1, ret1);
var unpackedRet1 = PhotonPipelineResult.photonStruct.unpack(p1);
@@ -53,6 +53,7 @@ class PacketTest {
1,
2,
3,
1024,
List.of(
new PhotonTrackedTarget(
3.0,
@@ -106,6 +107,7 @@ class PacketTest {
3,
4,
5,
1024,
List.of(
new PhotonTrackedTarget(
3.0,

View File

@@ -39,6 +39,7 @@ public class PhotonPipelineResultTest {
3,
4,
5,
1024,
List.of(
new PhotonTrackedTarget(
3.0,
@@ -87,6 +88,7 @@ public class PhotonPipelineResultTest {
3,
4,
5,
1024,
List.of(
new PhotonTrackedTarget(
3.0,
@@ -137,6 +139,7 @@ public class PhotonPipelineResultTest {
3,
4,
5,
1024,
List.of(
new PhotonTrackedTarget(
3.0,
@@ -190,6 +193,7 @@ public class PhotonPipelineResultTest {
3,
4,
5,
1024,
List.of(
new PhotonTrackedTarget(
3.0,
@@ -248,6 +252,7 @@ public class PhotonPipelineResultTest {
3,
4,
5,
1024,
List.of(
new PhotonTrackedTarget(
3.0,
@@ -296,6 +301,7 @@ public class PhotonPipelineResultTest {
3,
4,
5,
1024,
List.of(
new PhotonTrackedTarget(
7.0,
@@ -346,6 +352,7 @@ public class PhotonPipelineResultTest {
3,
4,
5,
1024,
List.of(
new PhotonTrackedTarget(
3.0,
@@ -399,6 +406,7 @@ public class PhotonPipelineResultTest {
3,
4,
5,
1024,
List.of(
new PhotonTrackedTarget(
3.0,

View File

@@ -43,6 +43,7 @@ public class PhotonPipelineResultProtoTest {
3,
4,
5,
1024,
List.of(
new PhotonTrackedTarget(
3.0,
@@ -97,6 +98,7 @@ public class PhotonPipelineResultProtoTest {
3,
4,
5,
1024,
List.of(
new PhotonTrackedTarget(
3.0,