mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-24 01:31:44 +00:00
Fix version verification with non-default networktable (#407)
Adds version verification to c++ too
This commit is contained in:
@@ -24,23 +24,34 @@
|
||||
|
||||
#include "photonlib/PhotonCamera.h"
|
||||
|
||||
#include <frc/Errors.h>
|
||||
|
||||
#include "PhotonVersion.h"
|
||||
#include "photonlib/Packet.h"
|
||||
|
||||
namespace photonlib {
|
||||
PhotonCamera::PhotonCamera(std::shared_ptr<nt::NetworkTable> rootTable)
|
||||
: rawBytesEntry(rootTable->GetEntry("rawBytes")),
|
||||
PhotonCamera::PhotonCamera(std::shared_ptr<nt::NetworkTableInstance> instance,
|
||||
const std::string& cameraName)
|
||||
: mainTable(instance->GetTable("photonvision")),
|
||||
rootTable(mainTable->GetSubTable(cameraName)),
|
||||
rawBytesEntry(rootTable->GetEntry("rawBytes")),
|
||||
driverModeEntry(rootTable->GetEntry("driverMode")),
|
||||
inputSaveImgEntry(rootTable->GetEntry("inputSaveImgCmd")),
|
||||
outputSaveImgEntry(rootTable->GetEntry("outputSaveImgCmd")),
|
||||
pipelineIndexEntry(rootTable->GetEntry("pipelineIndex")),
|
||||
ledModeEntry(mainTable->GetEntry("ledMode")) {}
|
||||
ledModeEntry(mainTable->GetEntry("ledMode")),
|
||||
versionEntry(mainTable->GetEntry("version")),
|
||||
path(rootTable->GetPath()) {}
|
||||
|
||||
PhotonCamera::PhotonCamera(const std::string& cameraName)
|
||||
: PhotonCamera(nt::NetworkTableInstance::GetDefault()
|
||||
.GetTable("photonvision")
|
||||
->GetSubTable(cameraName)) {}
|
||||
: PhotonCamera(std::make_shared<nt::NetworkTableInstance>(
|
||||
nt::NetworkTableInstance::GetDefault()),
|
||||
cameraName) {}
|
||||
|
||||
PhotonPipelineResult PhotonCamera::GetLatestResult() const {
|
||||
// Prints warning if not connected
|
||||
VerifyVersion();
|
||||
|
||||
// Clear the current packet.
|
||||
packet.Clear();
|
||||
|
||||
@@ -87,4 +98,20 @@ LEDMode PhotonCamera::GetLEDMode() const {
|
||||
void PhotonCamera::SetLEDMode(LEDMode mode) {
|
||||
ledModeEntry.SetDouble(static_cast<double>(static_cast<int>(mode)));
|
||||
}
|
||||
|
||||
void PhotonCamera::VerifyVersion() const {
|
||||
const std::string& versionString = versionEntry.GetString("");
|
||||
if (versionString.empty()) {
|
||||
std::string path_ = path;
|
||||
FRC_ReportError(
|
||||
frc::warn::Warning,
|
||||
"PhotonVision coprocessor at path {} not found on NetworkTables!",
|
||||
path_);
|
||||
} else if (!VersionMatches(versionString)) {
|
||||
FRC_ReportError(frc::warn::Warning,
|
||||
"Photon version {} does not match coprocessor version {}!",
|
||||
PhotonVersion::versionString, versionString);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace photonlib
|
||||
|
||||
@@ -26,8 +26,10 @@
|
||||
|
||||
namespace photonlib {
|
||||
|
||||
SimPhotonCamera::SimPhotonCamera(std::shared_ptr<nt::NetworkTable> rootTable)
|
||||
: PhotonCamera(rootTable) {}
|
||||
SimPhotonCamera::SimPhotonCamera(
|
||||
std::shared_ptr<nt::NetworkTableInstance> instance,
|
||||
const std::string& cameraName)
|
||||
: PhotonCamera(instance, cameraName) {}
|
||||
|
||||
SimPhotonCamera::SimPhotonCamera(const std::string& cameraName)
|
||||
: PhotonCamera(cameraName) {}
|
||||
|
||||
@@ -45,10 +45,15 @@ class PhotonCamera {
|
||||
public:
|
||||
/**
|
||||
* Constructs a PhotonCamera from a root table.
|
||||
* @param rootTable The root table that the camera is broadcasting information
|
||||
*
|
||||
* @param instance The NetworkTableInstance to pull data from. This can be a
|
||||
* custom instance in simulation, but should *usually* be the default
|
||||
* NTInstance from {@link NetworkTableInstance::getDefault}
|
||||
* @param cameraName The name of the camera, as seen in the UI.
|
||||
* over.
|
||||
*/
|
||||
explicit PhotonCamera(std::shared_ptr<nt::NetworkTable> rootTable);
|
||||
explicit PhotonCamera(std::shared_ptr<nt::NetworkTableInstance> instance,
|
||||
const std::string& cameraName);
|
||||
|
||||
/**
|
||||
* Constructs a PhotonCamera from the name of the camera.
|
||||
@@ -133,19 +138,23 @@ class PhotonCamera {
|
||||
"This method should be replaced with PhotonPipelineResult::HasTargets()")
|
||||
bool HasTargets() const { return GetLatestResult().HasTargets(); }
|
||||
|
||||
private:
|
||||
std::shared_ptr<nt::NetworkTable> mainTable =
|
||||
nt::NetworkTableInstance::GetDefault().GetTable("photonvision");
|
||||
|
||||
protected:
|
||||
std::shared_ptr<nt::NetworkTable> mainTable;
|
||||
std::shared_ptr<nt::NetworkTable> rootTable;
|
||||
nt::NetworkTableEntry rawBytesEntry;
|
||||
nt::NetworkTableEntry driverModeEntry;
|
||||
nt::NetworkTableEntry inputSaveImgEntry;
|
||||
nt::NetworkTableEntry outputSaveImgEntry;
|
||||
nt::NetworkTableEntry pipelineIndexEntry;
|
||||
nt::NetworkTableEntry ledModeEntry;
|
||||
nt::NetworkTableEntry versionEntry;
|
||||
|
||||
std::string path;
|
||||
|
||||
mutable Packet packet;
|
||||
|
||||
private:
|
||||
void VerifyVersion() const;
|
||||
};
|
||||
|
||||
} // namespace photonlib
|
||||
|
||||
@@ -44,10 +44,13 @@ class SimPhotonCamera : public PhotonCamera {
|
||||
/**
|
||||
* Constructs a Simulated PhotonCamera from a root table.
|
||||
*
|
||||
* @param rootTable The root table that the camera is broadcasting information
|
||||
* over.
|
||||
* @param instance The NetworkTableInstance to pull data from. This can be a
|
||||
* custom instance in simulation, but should *usually* be the default
|
||||
* NTInstance from {@link NetworkTableInstance::getDefault}
|
||||
* @param cameraName The name of the camera, as seen in the UI.
|
||||
*/
|
||||
explicit SimPhotonCamera(std::shared_ptr<nt::NetworkTable> rootTable);
|
||||
explicit SimPhotonCamera(std::shared_ptr<nt::NetworkTableInstance> instance,
|
||||
const std::string& cameraName);
|
||||
|
||||
/**
|
||||
* Constructs a Simulated PhotonCamera from the name of the camera.
|
||||
|
||||
Reference in New Issue
Block a user