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

Update to WPILib 2025.2.1 #235

Open
wants to merge 1 commit into
base: update-bookworm
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions deps/examples/cpp-multiCameraServer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#include <networktables/NetworkTableInstance.h>
#include <vision/VisionPipeline.h>
#include <vision/VisionRunner.h>
#include <wpi/MemoryBuffer.h>
#include <wpi/StringExtras.h>
#include <wpi/json.h>
#include <wpi/raw_istream.h>

#include "cameraserver/CameraServer.h"

Expand Down Expand Up @@ -149,17 +149,17 @@ bool ReadSwitchedCameraConfig(const wpi::json& config) {

bool ReadConfig() {
// open config file
std::error_code ec;
wpi::raw_fd_istream is(configFile, ec);
if (ec) {
fmt::print(stderr, "could not open '{}': {}", configFile, ec.message());
auto fileBuffer = wpi::MemoryBuffer::GetFile(configFile);
if (!fileBuffer) {
fmt::print(stderr, "could not open '{}': {}", configFile,
fileBuffer.error().message());
return false;
}

// parse file
wpi::json j;
try {
j = wpi::json::parse(is);
j = wpi::json::parse((*fileBuffer)->GetCharBuffer());
} catch (const wpi::json::parse_error& e) {
ParseError("byte {}: {}", e.byte, e.what());
return false;
Expand Down
1 change: 1 addition & 0 deletions deps/tools/configServer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ IMG_VERSION?=$(shell git describe)
-I${ALLWPILIB}/wpiutil/src/main/native/include \
-I${ALLWPILIB}/wpinet/src/main/native/include \
-I${ALLWPILIB}/cscore/src/main/native/include \
-I${ALLWPILIB}/wpiutil/src/main/native/thirdparty/expected/include \
-I${ALLWPILIB}/wpiutil/src/main/native/thirdparty/llvm/include \
-I${ALLWPILIB}/wpiutil/src/main/native/thirdparty/sigslot/include \
-I${ALLWPILIB}/wpiutil/src/main/native/thirdparty/fmtlib/include \
Expand Down
14 changes: 7 additions & 7 deletions deps/tools/configServer/src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ void Application::Set(std::string_view appType,
onFail("could not write " EXEC_HOME "/runCamera");
return;
}
fmt::print(os, "#!/bin/sh\n");
fmt::print(os, "{} {}\n", TYPE_TAG, appType);
fmt::print(os, "echo \"Waiting 5 seconds...\"\n");
fmt::print(os, "sleep 5\n");
if (!appDir.empty()) fmt::print(os, "cd {}\n", appDir);
if (!appEnv.empty()) fmt::print(os, "{}\n", appEnv);
fmt::print(os, "exec {}\n", appCommand);
wpi::print(os, "#!/bin/sh\n");
wpi::print(os, "{} {}\n", TYPE_TAG, appType);
wpi::print(os, "echo \"Waiting 5 seconds...\"\n");
wpi::print(os, "sleep 5\n");
if (!appDir.empty()) wpi::print(os, "cd {}\n", appDir);
if (!appEnv.empty()) wpi::print(os, "{}\n", appEnv);
wpi::print(os, "exec {}\n", appCommand);
}

// terminate vision process so it reloads
Expand Down
76 changes: 38 additions & 38 deletions deps/tools/configServer/src/NetworkSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,25 @@ static std::string BuildDhcpcdSetting(
// write generated config
switch (mode) {
case NetworkSettings::kDhcp:
fmt::print(os, "\n"); // nothing required
wpi::print(os, "\n"); // nothing required
break;
case NetworkSettings::kStatic:
fmt::print(os, "interface {}\n", iface);
fmt::print(os, "static ip_address={}/{}\n", addressOut.str(), cidr);
wpi::print(os, "interface {}\n", iface);
wpi::print(os, "static ip_address={}/{}\n", addressOut.str(), cidr);
if (!gatewayOut.empty())
fmt::print(os, "static routers={}\n", gatewayOut.str());
wpi::print(os, "static routers={}\n", gatewayOut.str());
if (!dnsOut.empty())
fmt::print(os, "static domain_name_servers={}\n", dnsOut.str());
wpi::print(os, "static domain_name_servers={}\n", dnsOut.str());
break;
case NetworkSettings::kDhcpStatic:
fmt::print(os, "profile static_{}\n", iface);
fmt::print(os, "static ip_address={}/{}\n", addressOut.str(), cidr);
wpi::print(os, "profile static_{}\n", iface);
wpi::print(os, "static ip_address={}/{}\n", addressOut.str(), cidr);
if (!gatewayOut.empty())
fmt::print(os, "static routers={}\n", gatewayOut.str());
wpi::print(os, "static routers={}\n", gatewayOut.str());
if (!dnsOut.empty())
fmt::print(os, "static domain_name_servers={}\n", dnsOut.str());
fmt::print(os, "interface {}\n", iface);
fmt::print(os, "fallback static_{}\n", iface);
wpi::print(os, "static domain_name_servers={}\n", dnsOut.str());
wpi::print(os, "interface {}\n", iface);
wpi::print(os, "fallback static_{}\n", iface);
break;
}
return os.str();
Expand Down Expand Up @@ -210,16 +210,16 @@ void NetworkSettings::Set(Mode mode, std::string_view address,
onFail("could not write " DHCPCD_CONF);
return;
}
for (auto&& line : lines) fmt::print(os, "{}\n", line);
for (auto&& line : lines) wpi::print(os, "{}\n", line);

// write marker
fmt::print(os, "{}\n", GEN_MARKER);
wpi::print(os, "{}\n", GEN_MARKER);

// write generated config
fmt::print(os, "{}\n", eth0);
fmt::print(os, "{}", wlan0);
wpi::print(os, "{}\n", eth0);
wpi::print(os, "{}", wlan0);
if (wifiAPMode == kAccessPoint) {
fmt::print(os, "nohook wpa_supplicant\n");
wpi::print(os, "nohook wpa_supplicant\n");
}
}
}
Expand All @@ -244,8 +244,8 @@ void NetworkSettings::Set(Mode mode, std::string_view address,
onFail("could not write " DNSMASQ_CONF);
return;
}
fmt::print(os, "interface=wlan0\n");
fmt::print(os, "dhcp-range={}.100,{}.200,{},5m\n", addr3part, addr3part,
wpi::print(os, "interface=wlan0\n");
wpi::print(os, "dhcp-range={}.100,{}.200,{},5m\n", addr3part, addr3part,
wifiMask);
} else {
// remove dnsmasq config file
Expand All @@ -262,20 +262,20 @@ void NetworkSettings::Set(Mode mode, std::string_view address,
onFail("could not write " HOSTAPD_CONF);
return;
}
fmt::print(os, "interface=wlan0\n");
fmt::print(os, "hw_mode=g\n");
fmt::print(os, "channel={}\n", wifiChannel);
fmt::print(os, "wmm_enabled=0\n");
fmt::print(os, "macaddr_acl=0\n");
fmt::print(os, "auth_algs=1\n");
fmt::print(os, "ignore_broadcast_ssid=0\n");
fmt::print(os, "ssid={}\n", wifiSsid);
wpi::print(os, "interface=wlan0\n");
wpi::print(os, "hw_mode=g\n");
wpi::print(os, "channel={}\n", wifiChannel);
wpi::print(os, "wmm_enabled=0\n");
wpi::print(os, "macaddr_acl=0\n");
wpi::print(os, "auth_algs=1\n");
wpi::print(os, "ignore_broadcast_ssid=0\n");
wpi::print(os, "ssid={}\n", wifiSsid);
if (!wifiWpa2.empty()) {
fmt::print(os, "wpa=2\n");
fmt::print(os, "wpa_key_mgmt=WPA-PSK\n");
fmt::print(os, "wpa_pairwise=TKIP\n");
fmt::print(os, "rsn_pairwise=CCMP\n");
fmt::print(os, "wpa_passphrase={}\n", wifiWpa2);
wpi::print(os, "wpa=2\n");
wpi::print(os, "wpa_key_mgmt=WPA-PSK\n");
wpi::print(os, "wpa_pairwise=TKIP\n");
wpi::print(os, "rsn_pairwise=CCMP\n");
wpi::print(os, "wpa_passphrase={}\n", wifiWpa2);
}
} else {
// remove hostapd config file
Expand Down Expand Up @@ -312,20 +312,20 @@ void NetworkSettings::Set(Mode mode, std::string_view address,
onFail("could not write " WPA_SUPPLICANT_CONF);
return;
}
for (auto&& line : lines) fmt::print(os, "{}\n", line);
for (auto&& line : lines) wpi::print(os, "{}\n", line);

// write marker
fmt::print(os, "{}\n", GEN_MARKER);
wpi::print(os, "{}\n", GEN_MARKER);

// write generated config
fmt::print(os, "network={\n");
fmt::print(os, " ssid=\"{}\"\n", wifiSsid);
wpi::print(os, "network={\n");
wpi::print(os, " ssid=\"{}\"\n", wifiSsid);
if (!wifiWpa2.empty()) {
fmt::print(os, " psk=\"{}\"\n", wifiWpa2);
wpi::print(os, " psk=\"{}\"\n", wifiWpa2);
} else {
fmt::print(os, " key_mgmt=NONE\n");
wpi::print(os, " key_mgmt=NONE\n");
}
fmt::print(os, "}\n");
wpi::print(os, "}\n");
}
}

Expand Down
38 changes: 18 additions & 20 deletions deps/tools/configServer/src/RomiStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ void RomiStatus::RunSvc(const char* cmd,
if (fd == -1) {
wpi::raw_svector_ostream os(r->err);
if (errno == ENXIO)
fmt::print(os, "unable to control service: supervise not running");
wpi::print(os, "unable to control service: supervise not running");
else
fmt::print(os, "unable to control service: {}", std::strerror(errno));
wpi::print(os, "unable to control service: {}", std::strerror(errno));
} else {
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK);
if (write(fd, r->cmd, std::strlen(r->cmd)) == -1) {
wpi::raw_svector_ostream os(r->err);
fmt::print(os, "error writing command: {}", std::strerror(errno));
wpi::print(os, "error writing command: {}", std::strerror(errno));
}
close(fd);
}
Expand Down Expand Up @@ -111,29 +111,29 @@ void RomiStatus::UpdateStatus() {
int fd = open(SERVICE "/supervise/ok", O_WRONLY | O_NDELAY);
if (fd == -1) {
if (errno == ENXIO)
fmt::print(os, "supervise not running");
wpi::print(os, "supervise not running");
else
fmt::print(os, "unable to open supervise/ok: {}", std::strerror(errno));
wpi::print(os, "unable to open supervise/ok: {}", std::strerror(errno));
return;
}
close(fd);

// read the status data
fd = open(SERVICE "/supervise/status", O_RDONLY | O_NDELAY);
if (fd == -1) {
fmt::print(os, "unable to open supervise/status: {}",
wpi::print(os, "unable to open supervise/status: {}",
std::strerror(errno));
return;
}
uint8_t status[18];
int nr = read(fd, status, sizeof status);
close(fd);
if (nr < static_cast<int>(sizeof status)) {
fmt::print(os, "unable to read supervise/status: ");
wpi::print(os, "unable to read supervise/status: ");
if (nr == -1)
fmt::print(os, "{}", std::strerror(errno));
wpi::print(os, "{}", std::strerror(errno));
else
fmt::print(os, "bad format");
wpi::print(os, "bad format");
return;
}

Expand Down Expand Up @@ -163,13 +163,13 @@ void RomiStatus::UpdateStatus() {

// convert to status string
if (pid)
fmt::print(os, "up (pid {}) ", pid);
wpi::print(os, "up (pid {}) ", pid);
else
fmt::print(os, "down ");
fmt::print(os, "{} seconds", when);
if (pid && paused) fmt::print(os, ", paused");
if (!pid && want == 'u') fmt::print(os, ", want up");
if (pid && want == 'd') fmt::print(os, ", want down");
wpi::print(os, "down ");
wpi::print(os, "{} seconds", when);
if (pid && paused) wpi::print(os, ", paused");
if (!pid && want == 'u') wpi::print(os, ", want up");
if (pid && want == 'd') wpi::print(os, ", want down");

if (pid) r->enabled = true;
});
Expand Down Expand Up @@ -237,19 +237,17 @@ void RomiStatus::UpdateConfig(std::function<void(std::string_view)> onFail) {
wpi::json RomiStatus::ReadRomiConfigFile(
std::function<void(std::string_view)> onFail) {
// Read config file
std::error_code ec;
std::unique_ptr<wpi::MemoryBuffer> fileBuffer =
wpi::MemoryBuffer::GetFile(ROMI_JSON, ec);
auto fileBuffer = wpi::MemoryBuffer::GetFile(ROMI_JSON);

if (fileBuffer == nullptr || ec) {
if (!fileBuffer) {
onFail("Could not read romi config file");
fmt::print(stderr, "could not read {}\n", ROMI_JSON);
return wpi::json();
}

wpi::json j;
try {
j = wpi::json::parse(fileBuffer->GetCharBuffer());
j = wpi::json::parse((*fileBuffer)->GetCharBuffer());
} catch(const wpi::json::parse_error& e) {
onFail("Parse error in config file");
fmt::print(stderr, "Parse error in {}: byte {}: {}\n", ROMI_JSON, e.byte,
Expand Down
8 changes: 3 additions & 5 deletions deps/tools/configServer/src/VisionSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,16 @@ void VisionSettings::Set(const wpi::json& data,
void VisionSettings::UpdateStatus() { status(GetStatusJson()); }

wpi::json VisionSettings::GetStatusJson() {
std::error_code ec;
std::unique_ptr<wpi::MemoryBuffer> fileBuffer =
wpi::MemoryBuffer::GetFile(FRC_JSON, ec);
auto fileBuffer = wpi::MemoryBuffer::GetFile(FRC_JSON);

if (fileBuffer == nullptr || ec) {
if (!fileBuffer) {
fmt::print(stderr, "could not read {}\n", FRC_JSON);
return wpi::json();
}

try {
wpi::json j = {{"type", "visionSettings"},
{"settings", wpi::json::parse(fileBuffer->GetCharBuffer())}};
{"settings", wpi::json::parse((*fileBuffer)->GetCharBuffer())}};
return j;
} catch (wpi::json::exception& e) {
fmt::print(stderr, "could not parse {}\n", FRC_JSON);
Expand Down
30 changes: 15 additions & 15 deletions deps/tools/configServer/src/VisionStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ void VisionStatus::RunSvc(const char* cmd,
if (fd == -1) {
wpi::raw_svector_ostream os(r->err);
if (errno == ENXIO)
fmt::print(os, "unable to control service: supervise not running");
wpi::print(os, "unable to control service: supervise not running");
else
fmt::print(os, "unable to control service: {}", std::strerror(errno));
wpi::print(os, "unable to control service: {}", std::strerror(errno));
} else {
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK);
if (write(fd, r->cmd, std::strlen(r->cmd)) == -1) {
wpi::raw_svector_ostream os(r->err);
fmt::print(os, "error writing command: {}", std::strerror(errno));
wpi::print(os, "error writing command: {}", std::strerror(errno));
}
close(fd);
}
Expand Down Expand Up @@ -196,29 +196,29 @@ void VisionStatus::UpdateStatus() {
int fd = open(SERVICE "/supervise/ok", O_WRONLY | O_NDELAY);
if (fd == -1) {
if (errno == ENXIO)
fmt::print(os, "supervise not running");
wpi::print(os, "supervise not running");
else
fmt::print(os, "unable to open supervise/ok: {}", std::strerror(errno));
wpi::print(os, "unable to open supervise/ok: {}", std::strerror(errno));
return;
}
close(fd);

// read the status data
fd = open(SERVICE "/supervise/status", O_RDONLY | O_NDELAY);
if (fd == -1) {
fmt::print(os, "unable to open supervise/status: {}",
wpi::print(os, "unable to open supervise/status: {}",
std::strerror(errno));
return;
}
uint8_t status[18];
int nr = read(fd, status, sizeof status);
close(fd);
if (nr < static_cast<int>(sizeof status)) {
fmt::print(os, "unable to read supervise/status: ");
wpi::print(os, "unable to read supervise/status: ");
if (nr == -1)
fmt::print(os, std::strerror(errno));
wpi::print(os, std::strerror(errno));
else
fmt::print(os, "bad format");
wpi::print(os, "bad format");
return;
}

Expand Down Expand Up @@ -248,13 +248,13 @@ void VisionStatus::UpdateStatus() {

// convert to status string
if (pid)
fmt::print(os, "up (pid {}) ", pid);
wpi::print(os, "up (pid {}) ", pid);
else
fmt::print(os, "down ");
fmt::print(os, "{} seconds", when);
if (pid && paused) fmt::print(os, ", paused");
if (!pid && want == 'u') fmt::print(os, ", want up");
if (pid && want == 'd') fmt::print(os, ", want down");
wpi::print(os, "down ");
wpi::print(os, "{} seconds", when);
if (pid && paused) wpi::print(os, ", paused");
if (!pid && want == 'u') wpi::print(os, ", want up");
if (pid && want == 'd') wpi::print(os, ", want down");

if (pid) r->enabled = true;
});
Expand Down
Loading
Loading