Unique path is not constant (#1681)

This commit is contained in:
Cameron (3539)
2025-01-06 00:00:55 -05:00
committed by GitHub
parent a84d681782
commit fa2034d30b
3 changed files with 44 additions and 0 deletions

View File

@@ -102,6 +102,8 @@ public sealed interface PVCameraInfo {
@Override
public String uniquePath() {
return Arrays.stream(super.otherPaths)
.sorted() // Must sort to ensure a consistent unique path as we can get more than one
// by-path and their order changes at random?
.filter(path -> path.contains("/by-path/"))
.findFirst()
.orElse(path());

View File

@@ -213,6 +213,7 @@ public class VisionSourceManager {
.equals(cameraInfo.uniquePath()))) {
logger.error(
"Camera unique-path already in use by active VisionModule! Cannot add " + cameraInfo);
return false;
}
var source = loadVisionSourceFromCamConfig(new CameraConfiguration(cameraInfo));

View File

@@ -193,6 +193,47 @@ public class VisionSourceManagerTest {
vsm.teardown();
}
@Test
public void testOtherPathsOrderChange() throws InterruptedException {
// GIVEN a VSM
var vsm = new TestVsm();
// AND one camera and camera config with flipped otherpaths order
var cam =
PVCameraInfo.fromUsbCameraInfo(
new UsbCameraInfo(
0,
"/dev/video0",
"Lifecam HD-3000",
new String[] {"/dev/v4l/by-path/usbv2/foobar1", "/dev/v4l/by-path/usb/foobar1"},
5940,
5940));
var camOtherPaths =
PVCameraInfo.fromUsbCameraInfo(
new UsbCameraInfo(
1,
"/dev/video1",
"Lifecam HD-3000",
new String[] {"/dev/v4l/by-path/usb/foobar1", "/dev/v4l/by-path/usbv2/foobar1"},
5940,
5940));
CameraConfiguration camOtherPathsConf = new CameraConfiguration(camOtherPaths);
camOtherPathsConf.nickname = "TestCamera";
camOtherPathsConf.deactivated = false;
vsm.registerLoadedConfigs(List.of(camOtherPathsConf));
vsm.assignUnmatchedCamera(cam);
assertEquals(0, vsm.getVsmState().disabledConfigs.size());
assertEquals(1, vsm.vmm.getModules().size());
assertEquals(cam.uniquePath(), camOtherPaths.uniquePath());
Thread.sleep(2000);
vsm.teardown();
}
@Test
public void testDuplicate() throws InterruptedException, IOException {
var fileCamera1 =