From 3a9d22c76b2f2d95a69f42c3ef278cccbb05db0e Mon Sep 17 00:00:00 2001 From: James Ward Date: Tue, 19 Nov 2024 13:28:07 +1100 Subject: [PATCH] Handle remote UUID mismatch properly (#1590) Check for no response Only throw if incorrect version, and not when missing Resolves #1569 --- photon-lib/py/photonlibpy/photonCamera.py | 69 +++++++++---------- .../main/native/cpp/photon/PhotonCamera.cpp | 1 + 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/photon-lib/py/photonlibpy/photonCamera.py b/photon-lib/py/photonlibpy/photonCamera.py index 03ab2cafbe..bcbc70d90b 100644 --- a/photon-lib/py/photonlibpy/photonCamera.py +++ b/photon-lib/py/photonlibpy/photonCamera.py @@ -298,43 +298,42 @@ def _versionCheck(self) -> None: # Check mdef UUID localUUID = PhotonPipelineResult.photonStruct.MESSAGE_VERSION - remoteUUID = str(self._rawBytesEntry.getTopic().getProperty("message_uuid")) + remoteUUID = self._rawBytesEntry.getTopic().getProperty("message_uuid") - if not remoteUUID: + if remoteUUID is None: wpilib.reportWarning( f"PhotonVision coprocessor at path {self._path} has not reported a message interface UUID - is your coprocessor's camera started?", True, ) - - assert isinstance(remoteUUID, str) - # ntcore hands us a JSON string with leading/trailing quotes - remove those - remoteUUID = remoteUUID.replace('"', "") - - if localUUID != remoteUUID: - # Verified version mismatch - - bfw = """ - \n\n\n - >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - >>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - >>> - >>> You are running an incompatible version - >>> of PhotonVision on your coprocessor! - >>> - >>> This is neither tested nor supported. - >>> You MUST update PhotonVision, - >>> PhotonLib, or both. - >>> - >>> Your code will now crash. - >>> We hope your day gets better. - >>> - >>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - \n\n - """ - - wpilib.reportWarning(bfw) - - errText = f"Photonlibpy version {PHOTONLIB_VERSION} (With message UUID {localUUID}) does not match coprocessor version {versionString} (with message UUID {remoteUUID}). Please install photonlibpy version {versionString}, or update your coprocessor to {PHOTONLIB_VERSION}." - wpilib.reportError(errText, True) - raise Exception(errText) + else: + # ntcore hands us a JSON string with leading/trailing quotes - remove those + remoteUUID = str(remoteUUID).replace('"', "") + + if localUUID != remoteUUID: + # Verified version mismatch + + bfw = """ + \n\n\n + >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + >>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + >>> + >>> You are running an incompatible version + >>> of PhotonVision on your coprocessor! + >>> + >>> This is neither tested nor supported. + >>> You MUST update PhotonVision, + >>> PhotonLib, or both. + >>> + >>> Your code will now crash. + >>> We hope your day gets better. + >>> + >>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + \n\n + """ + + wpilib.reportWarning(bfw) + + errText = f"Photonlibpy version {PHOTONLIB_VERSION} (With message UUID {localUUID}) does not match coprocessor version {versionString} (with message UUID {remoteUUID}). Please install photonlibpy version {versionString}, or update your coprocessor to {PHOTONLIB_VERSION}." + wpilib.reportError(errText, True) + raise Exception(errText) diff --git a/photon-lib/src/main/native/cpp/photon/PhotonCamera.cpp b/photon-lib/src/main/native/cpp/photon/PhotonCamera.cpp index ce0025394a..670f7c841b 100644 --- a/photon-lib/src/main/native/cpp/photon/PhotonCamera.cpp +++ b/photon-lib/src/main/native/cpp/photon/PhotonCamera.cpp @@ -305,6 +305,7 @@ void PhotonCamera::VerifyVersion() { FRC_ReportError(frc::warn::Warning, "Cannot find property message_uuid for PhotonCamera {}", path); + return; } std::string remote_uuid{remote_uuid_json};