Create TSP Server in C++ photonlib (#1516)

Automatically starts a TCP server in C++. Also adds warnings to Python.
This commit is contained in:
Matt
2024-11-01 23:32:38 -07:00
committed by GitHub
parent 75e2498f53
commit fc8ecac376
8 changed files with 82 additions and 4 deletions

View File

@@ -25,6 +25,7 @@
#include "photon/PhotonCamera.h"
#include <hal/FRCUsageReporting.h>
#include <net/TimeSyncServer.h>
#include <string>
#include <string_view>
@@ -59,6 +60,11 @@ inline constexpr std::string_view bfw =
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"
"\n\n";
// bit of a hack -- start a TimeSync server on port 5810 (hard-coded)
static std::mutex g_timeSyncServerMutex;
static bool g_timeSyncServerStarted;
static wpi::tsp::TimeSyncServer timesyncServer{5810};
namespace photon {
constexpr const units::second_t VERSION_CHECK_INTERVAL = 5_s;
@@ -110,6 +116,14 @@ PhotonCamera::PhotonCamera(nt::NetworkTableInstance instance,
cameraName(cameraName) {
HAL_Report(HALUsageReporting::kResourceType_PhotonCamera, InstanceCount);
InstanceCount++;
{
std::lock_guard lock{g_timeSyncServerMutex};
if (!g_timeSyncServerStarted) {
timesyncServer.Start();
g_timeSyncServerStarted = true;
}
}
}
PhotonCamera::PhotonCamera(const std::string_view cameraName)