From e3eff8731fb755762b5e0cd7f4d57b185f7c1d0a Mon Sep 17 00:00:00 2001 From: Chris Gerth Date: Sat, 30 Dec 2023 14:34:52 -0600 Subject: [PATCH] Version mismatch is harder to miss. (#1088) --- photon-lib/py/photonlibpy/photonCamera.py | 37 +++++++++++++++---- .../java/org/photonvision/PhotonCamera.java | 28 ++++++++++++-- .../main/native/cpp/photon/PhotonCamera.cpp | 34 +++++++++++++++-- 3 files changed, 85 insertions(+), 14 deletions(-) diff --git a/photon-lib/py/photonlibpy/photonCamera.py b/photon-lib/py/photonlibpy/photonCamera.py index fd3e0c8660..187013a286 100644 --- a/photon-lib/py/photonlibpy/photonCamera.py +++ b/photon-lib/py/photonlibpy/photonCamera.py @@ -165,11 +165,32 @@ def _versionCheck(self) -> None: versionString = self.versionEntry.get(defaultValue="") if len(versionString) > 0 and versionString != PHOTONVISION_VERSION: - wpilib.reportWarning( - "Photon version " - + PHOTONVISION_VERSION - + " does not match coprocessor version " - + versionString - + f"! Please install photonlibpy version {PHOTONLIB_VERSION}", - True, - ) + # 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 either PhotonVision, PhotonLib, or both. + >>> + >>> Your code will now crash. We hope your day gets better. + >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + \n\n + """ + + wpilib.reportWarning(bfw) + + errText = f"Photon version {PHOTONLIB_VERSION} does not match coprocessor version {versionString}. Please install photonlibpy version {PHOTONLIB_VERSION}." + wpilib.reportError(errText, True) + raise Exception(errText) diff --git a/photon-lib/src/main/java/org/photonvision/PhotonCamera.java b/photon-lib/src/main/java/org/photonvision/PhotonCamera.java index c5a704460b..f202b2c520 100644 --- a/photon-lib/src/main/java/org/photonvision/PhotonCamera.java +++ b/photon-lib/src/main/java/org/photonvision/PhotonCamera.java @@ -374,13 +374,35 @@ else if (!isConnected()) { if (!versionString.isEmpty() && !PhotonVersion.versionMatches(versionString)) { // Error on a verified version mismatch // But stay silent otherwise - DriverStation.reportWarning( + + String bfw = + "\n\n\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" + + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" + + ">>> ____ _________ ____ ________ ___________ __ \n" + + ">>> / __ \\/ ____/ | / __ \\ /_ __/ / / / _/ ___/ / / \n" + + ">>> / /_/ / __/ / /| | / / / / / / / /_/ // / \\__ \\ / / \n" + + ">>> / _, _/ /___/ ___ |/ /_/ / / / / __ // / ___/ / /_/ \n" + + ">>>/_/ |_/_____/_/ |_/_____/ /_/ /_/ /_/___//____/ (_) \n" + + ">>> \n" + + ">>> You are running an incompatible version \n" + + ">>> of PhotonVision on your coprocessor! \n" + + ">>> \n" + + ">>> This is neither tested nor supported. \n" + + ">>> You MUST update either PhotonVision, PhotonLib, or both. \n" + + ">>> \n" + + ">>> Your code will now crash. We hope your day gets better. \n" + + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" + + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n\n"; + + DriverStation.reportWarning(bfw, false); + var versionMismatchMessage = "Photon version " + PhotonVersion.versionString + " does not match coprocessor version " + versionString - + "!", - true); + + "!"; + DriverStation.reportError(versionMismatchMessage, false); + throw new UnsupportedOperationException(versionMismatchMessage); } } } diff --git a/photon-lib/src/main/native/cpp/photon/PhotonCamera.cpp b/photon-lib/src/main/native/cpp/photon/PhotonCamera.cpp index 02d9b46527..3ede0c3247 100644 --- a/photon-lib/src/main/native/cpp/photon/PhotonCamera.cpp +++ b/photon-lib/src/main/native/cpp/photon/PhotonCamera.cpp @@ -26,6 +26,8 @@ #include +#include + #include #include #include @@ -34,6 +36,29 @@ #include "PhotonVersion.h" #include "photon/dataflow/structures/Packet.h" +namespace { +static constexpr const std::string_view bfw = + "\n\n\n\n" + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" + ">>> ____ _________ ____ ________ ___________ __ \n" + ">>> / __ \\/ ____/ | / __ \\ /_ __/ / / / _/ ___/ / / \n" + ">>> / /_/ / __/ / /| | / / / / / / / /_/ // / \\__ \\ / / \n" + ">>> / _, _/ /___/ ___ |/ /_/ / / / / __ // / ___/ / /_/ \n" + ">>>/_/ |_/_____/_/ |_/_____/ /_/ /_/ /_/___//____/ (_) \n" + ">>> \n" + ">>> You are running an incompatible version \n" + ">>> of PhotonVision on your coprocessor! \n" + ">>> \n" + ">>> This is neither tested nor supported. \n" + ">>> You MUST update either PhotonVision, PhotonLib, or both. \n" + ">>> \n" + ">>> Your code will now crash. We hope your day gets better. \n" + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" + "\n\n"; +} // namespace + namespace photon { constexpr const units::second_t VERSION_CHECK_INTERVAL = 5_s; @@ -200,9 +225,12 @@ void PhotonCamera::VerifyVersion() { cameraNameOutString); } } else if (!VersionMatches(versionString)) { - FRC_ReportError(frc::warn::Warning, - "Photon version {} does not match coprocessor version {}!", - PhotonVersion::versionString, versionString); + FRC_ReportError(frc::warn::Warning, bfw); + std::string error_str = fmt::format( + "Photonlib version {} does not match coprocessor version {}!", + PhotonVersion::versionString, versionString); + FRC_ReportError(frc::err::Error, "{}", error_str); + throw std::runtime_error(error_str); } }