mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
SCRIPT namespace replacements
This commit is contained in:
committed by
Peter Johnson
parent
ae6c043632
commit
9aca8e0fd6
@@ -59,19 +59,19 @@ bool server = false;
|
||||
struct CameraConfig {
|
||||
std::string name;
|
||||
std::string path;
|
||||
wpi::json config;
|
||||
wpi::util::json config;
|
||||
};
|
||||
|
||||
std::vector<CameraConfig> cameras;
|
||||
|
||||
bool ReadCameraConfig(const wpi::json& config) {
|
||||
bool ReadCameraConfig(const wpi::util::json& config) {
|
||||
CameraConfig c;
|
||||
|
||||
// name
|
||||
try {
|
||||
c.name = config.at("name").get<std::string>();
|
||||
} catch (const wpi::json::exception& e) {
|
||||
wpi::print(stderr, "config error in '{}': could not read camera name: {}\n",
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
wpi::util::print(stderr, "config error in '{}': could not read camera name: {}\n",
|
||||
configFile, e.what());
|
||||
return false;
|
||||
}
|
||||
@@ -79,8 +79,8 @@ bool ReadCameraConfig(const wpi::json& config) {
|
||||
// path
|
||||
try {
|
||||
c.path = config.at("path").get<std::string>();
|
||||
} catch (const wpi::json::exception& e) {
|
||||
wpi::print(stderr,
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
wpi::util::print(stderr,
|
||||
"config error in '{}': camera '{}': could not read path: {}\n",
|
||||
configFile, c.name, e.what());
|
||||
return false;
|
||||
@@ -94,26 +94,26 @@ bool ReadCameraConfig(const wpi::json& config) {
|
||||
|
||||
bool ReadConfig() {
|
||||
// open config file
|
||||
auto fileBuffer = wpi::MemoryBuffer::GetFile(configFile);
|
||||
auto fileBuffer = wpi::util::MemoryBuffer::GetFile(configFile);
|
||||
if (!fileBuffer) {
|
||||
wpi::print(stderr, "could not open '{}': {}\n", configFile,
|
||||
wpi::util::print(stderr, "could not open '{}': {}\n", configFile,
|
||||
fileBuffer.error().message());
|
||||
return false;
|
||||
}
|
||||
|
||||
// parse file
|
||||
wpi::json j;
|
||||
wpi::util::json j;
|
||||
try {
|
||||
j = wpi::json::parse(fileBuffer.value()->GetCharBuffer());
|
||||
} catch (const wpi::json::parse_error& e) {
|
||||
wpi::print(stderr, "config error in '{}': byte {}: {}\n", configFile,
|
||||
j = wpi::util::json::parse(fileBuffer.value()->GetCharBuffer());
|
||||
} catch (const wpi::util::json::parse_error& e) {
|
||||
wpi::util::print(stderr, "config error in '{}': byte {}: {}\n", configFile,
|
||||
e.byte, e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
// top level must be an object
|
||||
if (!j.is_object()) {
|
||||
wpi::print(stderr, "config error in '{}': must be JSON object\n",
|
||||
wpi::util::print(stderr, "config error in '{}': must be JSON object\n",
|
||||
configFile);
|
||||
return false;
|
||||
}
|
||||
@@ -121,8 +121,8 @@ bool ReadConfig() {
|
||||
// team number
|
||||
try {
|
||||
team = j.at("team").get<unsigned int>();
|
||||
} catch (const wpi::json::exception& e) {
|
||||
wpi::print(stderr, "config error in '{}': could not read team number: {}\n",
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
wpi::util::print(stderr, "config error in '{}': could not read team number: {}\n",
|
||||
configFile, e.what());
|
||||
return false;
|
||||
}
|
||||
@@ -131,18 +131,18 @@ bool ReadConfig() {
|
||||
if (j.count("ntmode") != 0) {
|
||||
try {
|
||||
auto str = j.at("ntmode").get<std::string>();
|
||||
if (wpi::equals_lower(str, "client")) {
|
||||
if (wpi::util::equals_lower(str, "client")) {
|
||||
server = false;
|
||||
} else if (wpi::equals_lower(str, "server")) {
|
||||
} else if (wpi::util::equals_lower(str, "server")) {
|
||||
server = true;
|
||||
} else {
|
||||
wpi::print(
|
||||
wpi::util::print(
|
||||
stderr,
|
||||
"config error in '{}': could not understand ntmode value '{}'\n",
|
||||
configFile, str);
|
||||
}
|
||||
} catch (const wpi::json::exception& e) {
|
||||
wpi::print(stderr, "config error in '{}': could not read ntmode: {}\n",
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
wpi::util::print(stderr, "config error in '{}': could not read ntmode: {}\n",
|
||||
configFile, e.what());
|
||||
}
|
||||
}
|
||||
@@ -154,8 +154,8 @@ bool ReadConfig() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch (const wpi::json::exception& e) {
|
||||
wpi::print(stderr, "config error in '{}': could not read cameras: {}\n",
|
||||
} catch (const wpi::util::json::exception& e) {
|
||||
wpi::util::print(stderr, "config error in '{}': could not read cameras: {}\n",
|
||||
configFile, e.what());
|
||||
return false;
|
||||
}
|
||||
@@ -164,9 +164,9 @@ bool ReadConfig() {
|
||||
}
|
||||
|
||||
void StartCamera(const CameraConfig& config) {
|
||||
wpi::print("Starting camera '{}' on {}\n", config.name, config.path);
|
||||
wpi::util::print("Starting camera '{}' on {}\n", config.name, config.path);
|
||||
auto camera =
|
||||
frc::CameraServer::StartAutomaticCapture(config.name, config.path);
|
||||
wpi::CameraServer::StartAutomaticCapture(config.name, config.path);
|
||||
|
||||
camera.SetConfigJson(config.config);
|
||||
}
|
||||
@@ -183,12 +183,12 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
// start NetworkTables
|
||||
auto ntinst = nt::NetworkTableInstance::GetDefault();
|
||||
auto ntinst = wpi::nt::NetworkTableInstance::GetDefault();
|
||||
if (server) {
|
||||
std::puts("Setting up NetworkTables server");
|
||||
ntinst.StartServer();
|
||||
} else {
|
||||
wpi::print("Setting up NetworkTables client for team {}\n", team);
|
||||
wpi::util::print("Setting up NetworkTables client for team {}\n", team);
|
||||
ntinst.StartClient("multicameraserver");
|
||||
ntinst.SetServerTeam(team);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "wpi/util/StringMap.hpp"
|
||||
#include "wpi/util/mutex.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi;
|
||||
|
||||
static constexpr char const* kPublishName = "/CameraPublisher";
|
||||
|
||||
@@ -61,7 +61,7 @@ struct SourcePublisher {
|
||||
nt::StringArrayPublisher streamsPublisher;
|
||||
nt::StringEntry modeEntry;
|
||||
nt::StringArrayPublisher modesPublisher;
|
||||
wpi::DenseMap<CS_Property, PropertyPublisher> properties;
|
||||
wpi::util::DenseMap<CS_Property, PropertyPublisher> properties;
|
||||
};
|
||||
|
||||
struct Instance {
|
||||
@@ -71,13 +71,13 @@ struct Instance {
|
||||
std::vector<std::string> GetSourceStreamValues(CS_Source source);
|
||||
void UpdateStreamValues();
|
||||
|
||||
wpi::mutex m_mutex;
|
||||
wpi::util::mutex m_mutex;
|
||||
std::atomic<int> m_defaultUsbDevice{0};
|
||||
std::string m_primarySourceName;
|
||||
wpi::StringMap<cs::VideoSource> m_sources;
|
||||
wpi::StringMap<cs::VideoSink> m_sinks;
|
||||
wpi::DenseMap<CS_Sink, CS_Source> m_fixedSources;
|
||||
wpi::DenseMap<CS_Source, SourcePublisher> m_publishers;
|
||||
wpi::util::StringMap<cs::VideoSource> m_sources;
|
||||
wpi::util::StringMap<cs::VideoSink> m_sinks;
|
||||
wpi::util::DenseMap<CS_Sink, CS_Source> m_fixedSources;
|
||||
wpi::util::DenseMap<CS_Source, SourcePublisher> m_publishers;
|
||||
std::shared_ptr<nt::NetworkTable> m_publishTable{
|
||||
nt::NetworkTableInstance::GetDefault().GetTable(kPublishName)};
|
||||
cs::VideoListener m_videoListener;
|
||||
@@ -94,7 +94,7 @@ static Instance& GetInstance() {
|
||||
}
|
||||
|
||||
static std::string_view MakeSourceValue(CS_Source source,
|
||||
wpi::SmallVectorImpl<char>& buf) {
|
||||
wpi::util::SmallVectorImpl<char>& buf) {
|
||||
CS_Status status = 0;
|
||||
buf.clear();
|
||||
switch (cs::GetSourceKind(source, &status)) {
|
||||
@@ -282,7 +282,7 @@ PropertyPublisher::PropertyPublisher(nt::NetworkTable& table,
|
||||
const cs::VideoEvent& event) {
|
||||
std::string name;
|
||||
std::string infoName;
|
||||
if (wpi::starts_with(event.name, "raw_")) {
|
||||
if (wpi::util::starts_with(event.name, "raw_")) {
|
||||
name = fmt::format("RawProperty/{}", event.name);
|
||||
infoName = fmt::format("RawPropertyInfo/{}", event.name);
|
||||
} else {
|
||||
@@ -361,9 +361,9 @@ SourcePublisher::SourcePublisher(Instance& inst,
|
||||
modeEntry{table->GetStringTopic("mode").GetEntry("")},
|
||||
modesPublisher{table->GetStringArrayTopic("modes").Publish()} {
|
||||
CS_Status status = 0;
|
||||
wpi::SmallString<64> buf;
|
||||
wpi::util::SmallString<64> buf;
|
||||
sourcePublisher.Set(MakeSourceValue(source, buf));
|
||||
wpi::SmallString<64> descBuf;
|
||||
wpi::util::SmallString<64> descBuf;
|
||||
descriptionPublisher.Set(cs::GetSourceDescription(source, descBuf, &status));
|
||||
connectedPublisher.Set(cs::IsSourceConnected(source, &status));
|
||||
streamsPublisher.Set(inst.GetSourceStreamValues(source));
|
||||
@@ -404,7 +404,7 @@ Instance::Instance() {
|
||||
case cs::VideoEvent::kSourceConnected:
|
||||
if (auto publisher = GetPublisher(event.sourceHandle)) {
|
||||
// update the description too (as it may have changed)
|
||||
wpi::SmallString<64> descBuf;
|
||||
wpi::util::SmallString<64> descBuf;
|
||||
publisher->descriptionPublisher.Set(cs::GetSourceDescription(
|
||||
event.sourceHandle, descBuf, &status));
|
||||
publisher->connectedPublisher.Set(true);
|
||||
@@ -543,7 +543,7 @@ cs::CvSink CameraServer::GetVideo() {
|
||||
|
||||
cs::CvSink CameraServer::GetVideo(const cs::VideoSource& camera) {
|
||||
auto& inst = ::GetInstance();
|
||||
wpi::SmallString<64> name{"opencv_"};
|
||||
wpi::util::SmallString<64> name{"opencv_"};
|
||||
name += camera.GetName();
|
||||
|
||||
{
|
||||
@@ -570,7 +570,7 @@ cs::CvSink CameraServer::GetVideo(const cs::VideoSource& camera) {
|
||||
cs::CvSink CameraServer::GetVideo(const cs::VideoSource& camera,
|
||||
cs::VideoMode::PixelFormat pixelFormat) {
|
||||
auto& inst = ::GetInstance();
|
||||
wpi::SmallString<64> name{"opencv_"};
|
||||
wpi::util::SmallString<64> name{"opencv_"};
|
||||
name += camera.GetName();
|
||||
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "wpi/util/mutex.hpp"
|
||||
|
||||
namespace {
|
||||
class DefaultCameraServerShared : public frc::CameraServerShared {
|
||||
class DefaultCameraServerShared : public wpi::CameraServerShared {
|
||||
public:
|
||||
void ReportUsage(std::string_view resource, std::string_view data) override {}
|
||||
void SetCameraServerErrorV(fmt::string_view format,
|
||||
@@ -25,10 +25,10 @@ class DefaultCameraServerShared : public frc::CameraServerShared {
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static std::unique_ptr<frc::CameraServerShared> cameraServerShared = nullptr;
|
||||
static wpi::mutex setLock;
|
||||
static std::unique_ptr<wpi::CameraServerShared> cameraServerShared = nullptr;
|
||||
static wpi::util::mutex setLock;
|
||||
|
||||
namespace frc {
|
||||
namespace wpi {
|
||||
CameraServerShared* GetCameraServerShared() {
|
||||
std::unique_lock lock(setLock);
|
||||
if (!cameraServerShared) {
|
||||
@@ -36,10 +36,10 @@ CameraServerShared* GetCameraServerShared() {
|
||||
}
|
||||
return cameraServerShared.get();
|
||||
}
|
||||
} // namespace frc
|
||||
} // namespace wpi
|
||||
|
||||
extern "C" {
|
||||
void CameraServer_SetCameraServerShared(frc::CameraServerShared* shared) {
|
||||
void CameraServer_SetCameraServerShared(wpi::CameraServerShared* shared) {
|
||||
std::unique_lock lock(setLock);
|
||||
cameraServerShared.reset(shared);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
#include "wpi/cameraserver/CameraServerShared.hpp"
|
||||
|
||||
using namespace frc;
|
||||
using namespace wpi::vision;
|
||||
|
||||
VisionRunnerBase::VisionRunnerBase(cs::VideoSource videoSource)
|
||||
: m_image(std::make_unique<cv::Mat>()),
|
||||
@@ -24,7 +24,7 @@ VisionRunnerBase::VisionRunnerBase(cs::VideoSource videoSource)
|
||||
VisionRunnerBase::~VisionRunnerBase() = default;
|
||||
|
||||
void VisionRunnerBase::RunOnce() {
|
||||
auto csShared = frc::GetCameraServerShared();
|
||||
auto csShared = wpi::vision::GetCameraServerShared();
|
||||
auto res = csShared->GetRobotMainThreadId();
|
||||
if (res.second && (std::this_thread::get_id() == res.first)) {
|
||||
csShared->SetVisionRunnerError(
|
||||
@@ -41,7 +41,7 @@ void VisionRunnerBase::RunOnce() {
|
||||
}
|
||||
|
||||
void VisionRunnerBase::RunForever() {
|
||||
auto csShared = frc::GetCameraServerShared();
|
||||
auto csShared = wpi::vision::GetCameraServerShared();
|
||||
auto res = csShared->GetRobotMainThreadId();
|
||||
if (res.second && (std::this_thread::get_id() == res.first)) {
|
||||
csShared->SetVisionRunnerError(
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
#include "wpi/cs/cscore_cv.hpp"
|
||||
|
||||
namespace frc {
|
||||
namespace wpi {
|
||||
|
||||
/**
|
||||
* Singleton class for creating and keeping camera servers.
|
||||
@@ -200,4 +200,4 @@ class CameraServer {
|
||||
CameraServer() = default;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
} // namespace wpi
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
namespace frc {
|
||||
namespace wpi {
|
||||
class CameraServerShared {
|
||||
public:
|
||||
virtual ~CameraServerShared() = default;
|
||||
@@ -42,9 +42,9 @@ class CameraServerShared {
|
||||
};
|
||||
|
||||
CameraServerShared* GetCameraServerShared();
|
||||
} // namespace frc
|
||||
} // namespace wpi
|
||||
|
||||
extern "C" {
|
||||
// Takes ownership
|
||||
void CameraServer_SetCameraServerShared(frc::CameraServerShared* shared);
|
||||
void CameraServer_SetCameraServerShared(wpi::CameraServerShared* shared);
|
||||
} // extern "C"
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace cv {
|
||||
class Mat;
|
||||
} // namespace cv
|
||||
|
||||
namespace frc {
|
||||
namespace wpi::vision {
|
||||
|
||||
/**
|
||||
* A vision pipeline is responsible for running a group of OpenCV algorithms to
|
||||
@@ -26,4 +26,4 @@ class VisionPipeline {
|
||||
*/
|
||||
virtual void Process(cv::Mat& mat) = 0;
|
||||
};
|
||||
} // namespace frc
|
||||
} // namespace wpi::vision
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "wpi/cs/cscore_cv.hpp"
|
||||
#include "wpi/vision/VisionPipeline.hpp"
|
||||
|
||||
namespace frc {
|
||||
namespace wpi::vision {
|
||||
|
||||
/**
|
||||
* Non-template base class for VisionRunner.
|
||||
@@ -111,4 +111,4 @@ class VisionRunner : public VisionRunnerBase {
|
||||
std::function<void(T&)> m_listener;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
} // namespace wpi::vision
|
||||
|
||||
Reference in New Issue
Block a user