Skip to content

Commit

Permalink
Version mismatch is harder to miss. (#1088)
Browse files Browse the repository at this point in the history
  • Loading branch information
gerth2 authored Dec 30, 2023
1 parent ef039da commit e3eff87
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 14 deletions.
37 changes: 29 additions & 8 deletions photon-lib/py/photonlibpy/photonCamera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
28 changes: 25 additions & 3 deletions photon-lib/src/main/java/org/photonvision/PhotonCamera.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
34 changes: 31 additions & 3 deletions photon-lib/src/main/native/cpp/photon/PhotonCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include <hal/FRCUsageReporting.h>

#include <string_view>

#include <frc/Errors.h>
#include <frc/Timer.h>
#include <opencv2/core.hpp>
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit e3eff87

Please sign in to comment.