|
27 | 27 | #include <hal/FRCUsageReporting.h> |
28 | 28 | #include <net/TimeSyncServer.h> |
29 | 29 |
|
| 30 | +#include <stdexcept> |
30 | 31 | #include <string> |
31 | 32 | #include <string_view> |
32 | 33 | #include <vector> |
33 | 34 |
|
| 35 | +#include <WPILibVersion.h> |
34 | 36 | #include <frc/Errors.h> |
35 | 37 | #include <frc/RobotController.h> |
36 | 38 | #include <frc/Timer.h> |
|
39 | 41 | #include <wpi/json.h> |
40 | 42 |
|
41 | 43 | #include "PhotonVersion.h" |
| 44 | +#include "opencv2/core/utility.hpp" |
42 | 45 | #include "photon/dataflow/structures/Packet.h" |
43 | 46 |
|
44 | | -inline constexpr std::string_view bfw = |
45 | | - "\n\n\n\n" |
46 | | - ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" |
47 | | - ">>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" |
48 | | - ">>> \n" |
49 | | - ">>> You are running an incompatible version \n" |
50 | | - ">>> of PhotonVision on your coprocessor! \n" |
51 | | - ">>> \n" |
52 | | - ">>> This is neither tested nor supported. \n" |
53 | | - ">>> You MUST update PhotonVision, \n" |
54 | | - ">>> PhotonLib, or both. \n" |
55 | | - ">>> \n" |
56 | | - ">>> Your code will now crash. \n" |
57 | | - ">>> We hope your day gets better. \n" |
58 | | - ">>> \n" |
59 | | - ">>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" |
60 | | - ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" |
61 | | - "\n\n"; |
| 47 | +inline void verifyDependencies() { |
| 48 | + if (!(std::string_view{GetWPILibVersion()} == |
| 49 | + std::string_view{photon::PhotonVersion::wpilibTargetVersion})) { |
| 50 | + std::string bfw = |
| 51 | + "\n\n\n\n\n" |
| 52 | + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" |
| 53 | + ">>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" |
| 54 | + ">>> \n" |
| 55 | + ">>> You are running an incompatible version \n" |
| 56 | + ">>> of PhotonVision ! \n" |
| 57 | + ">>> \n" |
| 58 | + ">>> PhotonLib "; |
| 59 | + bfw += photon::PhotonVersion::versionString; |
| 60 | + bfw += " is built for WPILib "; |
| 61 | + bfw += photon::PhotonVersion::wpilibTargetVersion; |
| 62 | + bfw += |
| 63 | + "\n" |
| 64 | + ">>> but you are using WPILib "; |
| 65 | + bfw += GetWPILibVersion(); |
| 66 | + bfw += |
| 67 | + "\n>>> \n" |
| 68 | + ">>> This is neither tested nor supported. \n" |
| 69 | + ">>> You MUST update PhotonVision, \n" |
| 70 | + ">>> PhotonLib, or both. \n" |
| 71 | + ">>> Verify the output of `./gradlew dependencies` \n" |
| 72 | + ">>> \n" |
| 73 | + ">>> Your code will now crash. \n" |
| 74 | + ">>> We hope your day gets better. \n" |
| 75 | + ">>> \n" |
| 76 | + ">>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" |
| 77 | + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"; |
| 78 | + |
| 79 | + FRC_ReportWarning(bfw); |
| 80 | + FRC_ReportError(frc::err::Error, bfw); |
| 81 | + throw new std::runtime_error(std::string{bfw}); |
| 82 | + } |
| 83 | + if (!(std::string_view{cv::getVersionString()} == |
| 84 | + std::string_view{photon::PhotonVersion::opencvTargetVersion})) { |
| 85 | + std::string bfw = |
| 86 | + "\n\n\n\n\n" |
| 87 | + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" |
| 88 | + ">>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" |
| 89 | + ">>> \n" |
| 90 | + ">>> You are running an incompatible version \n" |
| 91 | + ">>> of PhotonVision ! \n" |
| 92 | + ">>> \n" |
| 93 | + ">>> PhotonLib "; |
| 94 | + bfw += photon::PhotonVersion::versionString; |
| 95 | + bfw += " is built for OpenCV "; |
| 96 | + bfw += photon::PhotonVersion::opencvTargetVersion; |
| 97 | + bfw += |
| 98 | + "\n" |
| 99 | + ">>> but you are using OpenCV "; |
| 100 | + bfw += cv::getVersionString(); |
| 101 | + bfw += |
| 102 | + "\n>>> \n" |
| 103 | + ">>> This is neither tested nor supported. \n" |
| 104 | + ">>> You MUST update PhotonVision, \n" |
| 105 | + ">>> PhotonLib, or both. \n" |
| 106 | + ">>> Verify the output of `./gradlew dependencies` \n" |
| 107 | + ">>> \n" |
| 108 | + ">>> Your code will now crash. \n" |
| 109 | + ">>> We hope your day gets better. \n" |
| 110 | + ">>> \n" |
| 111 | + ">>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" |
| 112 | + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"; |
| 113 | + |
| 114 | + FRC_ReportWarning(bfw); |
| 115 | + FRC_ReportError(frc::err::Error, bfw); |
| 116 | + throw new std::runtime_error(std::string{bfw}); |
| 117 | + } |
| 118 | +} |
62 | 119 |
|
63 | 120 | // bit of a hack -- start a TimeSync server on port 5810 (hard-coded). We want |
64 | 121 | // to avoid calling this from static initialization |
@@ -125,6 +182,7 @@ PhotonCamera::PhotonCamera(nt::NetworkTableInstance instance, |
125 | 182 | topicNameSubscriber(instance, PHOTON_PREFIX, {.topicsOnly = true}), |
126 | 183 | path(rootTable->GetPath()), |
127 | 184 | cameraName(cameraName) { |
| 185 | + verifyDependencies(); |
128 | 186 | HAL_Report(HALUsageReporting::kResourceType_PhotonCamera, InstanceCount); |
129 | 187 | InstanceCount++; |
130 | 188 |
|
@@ -310,7 +368,25 @@ void PhotonCamera::VerifyVersion() { |
310 | 368 | std::string remote_uuid{remote_uuid_json}; |
311 | 369 |
|
312 | 370 | if (local_uuid != remote_uuid) { |
313 | | - FRC_ReportError(frc::warn::Warning, bfw); |
| 371 | + constexpr std::string_view bfw = |
| 372 | + "\n\n\n\n" |
| 373 | + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" |
| 374 | + ">>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" |
| 375 | + ">>> \n" |
| 376 | + ">>> You are running an incompatible version \n" |
| 377 | + ">>> of PhotonVision on your coprocessor! \n" |
| 378 | + ">>> \n" |
| 379 | + ">>> This is neither tested nor supported. \n" |
| 380 | + ">>> You MUST update PhotonVision, \n" |
| 381 | + ">>> PhotonLib, or both. \n" |
| 382 | + ">>> \n" |
| 383 | + ">>> Your code will now crash. \n" |
| 384 | + ">>> We hope your day gets better. \n" |
| 385 | + ">>> \n" |
| 386 | + ">>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" |
| 387 | + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" |
| 388 | + "\n\n"; |
| 389 | + FRC_ReportWarning(bfw); |
314 | 390 | std::string error_str = fmt::format( |
315 | 391 | "Photonlib version {} (message definition version {}) does not match " |
316 | 392 | "coprocessor version {} (message definition version {})!", |
|
0 commit comments