Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version mismatch is harder to miss. #1088

Merged
merged 5 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
"""
mcm001 marked this conversation as resolved.
Show resolved Hide resolved

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