Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions rdev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ wrapper = "2027.0.0a3"

[params]

wpilib_bin_version = "2027.0.0-alpha-3"
wpilib_bin_url = "https://frcmaven.wpi.edu/artifactory/release-2027"
wpilib_bin_version = "2027.0.0-alpha-3-86-g418b381"
wpilib_bin_url = "https://frcmaven.wpi.edu/artifactory/development-2027"
# wpilib_bin_url = "https://frcmaven.wpi.edu/artifactory/development-2027"

# Don't update these maven artifacts
Expand Down
2 changes: 1 addition & 1 deletion subprojects/pyntcore/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pyntcore
========

Python pybind11 wrappers around the C++ ntcore library.
Python pybind11 wrappers around the C++ ntcore library.
40 changes: 20 additions & 20 deletions subprojects/pyntcore/ntcore/src/NetworkTable.cpp.inl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cls_NetworkTable
.def("getValue", [](const NetworkTable &self, std::string_view key, py::object defaultValue) -> py::object {
nt::NetworkTableEntry entry;
wpi::nt::NetworkTableEntry entry;
{
py::gil_scoped_release release;
entry = self.GetEntry(key);
Expand All @@ -9,48 +9,48 @@ cls_NetworkTable
}, py::arg("key"), py::arg("value"))

// double overload must come before boolean version
.def("putValue", [](nt::NetworkTable *self, std::string_view key, double value) {
return self->PutValue(key, nt::Value::MakeDouble(value));
.def("putValue", [](wpi::nt::NetworkTable *self, std::string_view key, double value) {
return self->PutValue(key, wpi::nt::Value::MakeDouble(value));
}, py::arg("key"), py::arg("value"), release_gil())
.def("putValue", [](nt::NetworkTable *self, std::string_view key, bool value) {
return self->PutValue(key, nt::Value::MakeBoolean(value));
.def("putValue", [](wpi::nt::NetworkTable *self, std::string_view key, bool value) {
return self->PutValue(key, wpi::nt::Value::MakeBoolean(value));
}, py::arg("key"), py::arg("value"), release_gil())
.def("putValue", [](nt::NetworkTable *self, std::string_view key, py::bytes value) {
auto v = nt::Value::MakeRaw(value.cast<std::span<const uint8_t>>());
.def("putValue", [](wpi::nt::NetworkTable *self, std::string_view key, py::bytes value) {
auto v = wpi::nt::Value::MakeRaw(value.cast<std::span<const uint8_t>>());
py::gil_scoped_release release;
return self->PutValue(key, v);
}, py::arg("key"), py::arg("value"))
.def("putValue", [](nt::NetworkTable *self, std::string_view key, std::string value) {
return self->PutValue(key, nt::Value::MakeString(std::move(value)));
.def("putValue", [](wpi::nt::NetworkTable *self, std::string_view key, std::string value) {
return self->PutValue(key, wpi::nt::Value::MakeString(std::move(value)));
}, py::arg("key"), py::arg("value"), release_gil())
.def("putValue", [](nt::NetworkTable *self, std::string_view key, py::sequence value) {
.def("putValue", [](wpi::nt::NetworkTable *self, std::string_view key, py::sequence value) {
auto v = pyntcore::py2ntvalue(value);
py::gil_scoped_release release;
return self->PutValue(key, v);
}, py::arg("key"), py::arg("value"))

// double overload must come before boolean version
.def("setDefaultValue", [](nt::NetworkTable *self, std::string_view key, double value) {
return self->SetDefaultValue(key, nt::Value::MakeDouble(value));
.def("setDefaultValue", [](wpi::nt::NetworkTable *self, std::string_view key, double value) {
return self->SetDefaultValue(key, wpi::nt::Value::MakeDouble(value));
}, py::arg("key"), py::arg("value"), release_gil())
.def("setDefaultValue", [](nt::NetworkTable *self, std::string_view key, bool value) {
return self->SetDefaultValue(key, nt::Value::MakeBoolean(value));
.def("setDefaultValue", [](wpi::nt::NetworkTable *self, std::string_view key, bool value) {
return self->SetDefaultValue(key, wpi::nt::Value::MakeBoolean(value));
}, py::arg("key"), py::arg("value"), release_gil())
.def("setDefaultValue", [](nt::NetworkTable *self, std::string_view key, py::bytes value) {
auto v = nt::Value::MakeRaw(value.cast<std::span<const uint8_t>>());
.def("setDefaultValue", [](wpi::nt::NetworkTable *self, std::string_view key, py::bytes value) {
auto v = wpi::nt::Value::MakeRaw(value.cast<std::span<const uint8_t>>());
py::gil_scoped_release release;
return self->SetDefaultValue(key, v);
}, py::arg("key"), py::arg("value"))
.def("setDefaultValue", [](nt::NetworkTable *self, std::string_view key, std::string value) {
return self->SetDefaultValue(key, nt::Value::MakeString(std::move(value)));
.def("setDefaultValue", [](wpi::nt::NetworkTable *self, std::string_view key, std::string value) {
return self->SetDefaultValue(key, wpi::nt::Value::MakeString(std::move(value)));
}, py::arg("key"), py::arg("value"), release_gil())
.def("setDefaultValue", [](nt::NetworkTable *self, std::string_view key, py::sequence value) {
.def("setDefaultValue", [](wpi::nt::NetworkTable *self, std::string_view key, py::sequence value) {
auto v = pyntcore::py2ntvalue(value);
py::gil_scoped_release release;
return self->SetDefaultValue(key, v);
}, py::arg("key"), py::arg("value"))

.def("__contains__", [](const nt::NetworkTable &self, std::string_view key) -> bool {
.def("__contains__", [](const wpi::nt::NetworkTable &self, std::string_view key) -> bool {
return self.ContainsKey(key);
}, release_gil())
;
40 changes: 20 additions & 20 deletions subprojects/pyntcore/ntcore/src/NetworkTableEntry.cpp.inl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cls_NetworkTableEntry
.def_property_readonly("value", [](const nt::NetworkTableEntry &self) {
nt::Value v;
.def_property_readonly("value", [](const wpi::nt::NetworkTableEntry &self) {
wpi::nt::Value v;
{
py::gil_scoped_release release;
v = self.GetValue();
Expand All @@ -9,40 +9,40 @@ cls_NetworkTableEntry
})

// double overload must come before boolean version
.def("setValue", [](nt::NetworkTableEntry *self, double value) {
return self->SetValue(nt::Value::MakeDouble(value));
.def("setValue", [](wpi::nt::NetworkTableEntry *self, double value) {
return self->SetValue(wpi::nt::Value::MakeDouble(value));
}, py::arg("value"), release_gil())
.def("setValue", [](nt::NetworkTableEntry *self, bool value) {
return self->SetValue(nt::Value::MakeBoolean(value));
.def("setValue", [](wpi::nt::NetworkTableEntry *self, bool value) {
return self->SetValue(wpi::nt::Value::MakeBoolean(value));
}, py::arg("value"), release_gil())
.def("setValue", [](nt::NetworkTableEntry *self, py::bytes value) {
auto v = nt::Value::MakeRaw(value.cast<std::span<const uint8_t>>());
.def("setValue", [](wpi::nt::NetworkTableEntry *self, py::bytes value) {
auto v = wpi::nt::Value::MakeRaw(value.cast<std::span<const uint8_t>>());
py::gil_scoped_release release;
return self->SetValue(v);
}, py::arg("value"))
.def("setValue", [](nt::NetworkTableEntry *self, std::string value) {
return self->SetValue(nt::Value::MakeString(value));
.def("setValue", [](wpi::nt::NetworkTableEntry *self, std::string value) {
return self->SetValue(wpi::nt::Value::MakeString(value));
}, py::arg("value"), release_gil())
.def("setValue", [](nt::NetworkTableEntry *self, py::sequence value) {
.def("setValue", [](wpi::nt::NetworkTableEntry *self, py::sequence value) {
return self->SetValue(pyntcore::py2ntvalue(value));
}, py::arg("value"))

// double overload must come before boolean version
.def("setDefaultValue", [](nt::NetworkTableEntry *self, double value) {
return self->SetDefaultValue(nt::Value::MakeDouble(value));
.def("setDefaultValue", [](wpi::nt::NetworkTableEntry *self, double value) {
return self->SetDefaultValue(wpi::nt::Value::MakeDouble(value));
}, py::arg("value"), release_gil())
.def("setDefaultValue", [](nt::NetworkTableEntry *self, bool value) {
return self->SetDefaultValue(nt::Value::MakeBoolean(value));
.def("setDefaultValue", [](wpi::nt::NetworkTableEntry *self, bool value) {
return self->SetDefaultValue(wpi::nt::Value::MakeBoolean(value));
}, py::arg("value"), release_gil())
.def("setDefaultValue", [](nt::NetworkTableEntry *self, py::bytes value) {
auto v = nt::Value::MakeRaw(value.cast<std::span<const uint8_t>>());
.def("setDefaultValue", [](wpi::nt::NetworkTableEntry *self, py::bytes value) {
auto v = wpi::nt::Value::MakeRaw(value.cast<std::span<const uint8_t>>());
py::gil_scoped_release release;
return self->SetDefaultValue(v);
}, py::arg("value"))
.def("setDefaultValue", [](nt::NetworkTableEntry *self, std::string value) {
return self->SetDefaultValue(nt::Value::MakeString(value));
.def("setDefaultValue", [](wpi::nt::NetworkTableEntry *self, std::string value) {
return self->SetDefaultValue(wpi::nt::Value::MakeString(value));
}, py::arg("value"), release_gil())
.def("setDefaultValue", [](nt::NetworkTableEntry *self, py::sequence value) {
.def("setDefaultValue", [](wpi::nt::NetworkTableEntry *self, py::sequence value) {
return self->SetDefaultValue(pyntcore::py2ntvalue(value));
}, py::arg("value"))
;
14 changes: 7 additions & 7 deletions subprojects/pyntcore/ntcore/src/nt_instance.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <semiwrap.h>
#include "nt_instance.h"
#include "ntcore_cpp.h"
#include "wpi/nt/ntcore_cpp.hpp"

#include <set>

Expand All @@ -9,24 +9,24 @@ static std::set<NT_Inst> g_known_instances;

namespace pyntcore {

void onInstanceStart(nt::NetworkTableInstance *instance) {
void onInstanceStart(wpi::nt::NetworkTableInstance *instance) {
g_known_instances.emplace(instance->GetHandle());

py::module::import("ntcore._logutil")
.attr("NtLogForwarder").attr("onInstanceStart")(instance);
}

void onInstancePreReset(nt::NetworkTableInstance *instance) {
void onInstancePreReset(wpi::nt::NetworkTableInstance *instance) {
py::module::import("ntcore._logutil")
.attr("NtLogForwarder").attr("onInstanceDestroy")(instance);
}

void onInstancePostReset(nt::NetworkTableInstance *instance) {
void onInstancePostReset(wpi::nt::NetworkTableInstance *instance) {
py::module::import("ntcore.util")
.attr("_NtProperty").attr("onInstancePostReset")(instance);
}

void onInstanceDestroy(nt::NetworkTableInstance *instance) {
void onInstanceDestroy(wpi::nt::NetworkTableInstance *instance) {
py::module::import("ntcore._logutil")
.attr("NtLogForwarder").attr("onInstanceDestroy")(instance);
py::module::import("ntcore.util")
Expand All @@ -43,12 +43,12 @@ void resetAllInstances()
known_instances.swap(g_known_instances);

// always reset the default instance
known_instances.emplace(nt::GetDefaultInstance());
known_instances.emplace(wpi::nt::GetDefaultInstance());

py::gil_scoped_release unlock;

for (auto &inst: known_instances) {
nt::ResetInstance(inst);
wpi::nt::ResetInstance(inst);
}
}

Expand Down
12 changes: 6 additions & 6 deletions subprojects/pyntcore/ntcore/src/nt_instance.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

#pragma once

#include <ntcore.h>
#include <networktables/NetworkTableInstance.h>
#include "wpi/nt/ntcore.h"
#include "wpi/nt/NetworkTableInstance.hpp"

namespace pyntcore {

void onInstanceStart(nt::NetworkTableInstance *instance);
void onInstancePreReset(nt::NetworkTableInstance *instance);
void onInstancePostReset(nt::NetworkTableInstance *instance);
void onInstanceDestroy(nt::NetworkTableInstance *instance);
void onInstanceStart(wpi::nt::NetworkTableInstance *instance);
void onInstancePreReset(wpi::nt::NetworkTableInstance *instance);
void onInstancePostReset(wpi::nt::NetworkTableInstance *instance);
void onInstanceDestroy(wpi::nt::NetworkTableInstance *instance);

void resetAllInstances();

Expand Down
46 changes: 23 additions & 23 deletions subprojects/pyntcore/ntcore/src/py2value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const char * nttype2str(NT_Type type) {
}


py::object ntvalue2py(const nt::Value &ntvalue) {
py::object ntvalue2py(const wpi::nt::Value &ntvalue) {
auto &v = ntvalue.value();
switch (v.type) {
case NT_BOOLEAN:
Expand Down Expand Up @@ -109,17 +109,17 @@ py::object ntvalue2py(const nt::Value &ntvalue) {
}
}

nt::Value py2ntvalue(py::handle h) {
wpi::nt::Value py2ntvalue(py::handle h) {
if (py::isinstance<py::bool_>(h)) {
return nt::Value::MakeBoolean(h.cast<bool>());
return wpi::nt::Value::MakeBoolean(h.cast<bool>());
} else if (py::isinstance<py::float_>(h)) {
return nt::Value::MakeDouble(h.cast<double>());
return wpi::nt::Value::MakeDouble(h.cast<double>());
} else if (py::isinstance<py::int_>(h)) {
return nt::Value::MakeInteger(h.cast<int64_t>());
return wpi::nt::Value::MakeInteger(h.cast<int64_t>());
} else if (py::isinstance<py::str>(h)) {
return nt::Value::MakeString(h.cast<std::string>());
return wpi::nt::Value::MakeString(h.cast<std::string>());
} else if (py::isinstance<py::bytes>(h)) {
return nt::Value::MakeRaw(h.cast<std::span<const uint8_t>>());
return wpi::nt::Value::MakeRaw(h.cast<std::span<const uint8_t>>());
} else if (py::isinstance<py::none>(h)) {
throw py::value_error("Cannot put None into NetworkTable");
}
Expand All @@ -132,45 +132,45 @@ nt::Value py2ntvalue(py::handle h) {
auto i1 = seq[0];
if (py::isinstance<py::bool_>(i1)) {
auto v = h.cast<std::vector<int>>();
return nt::Value::MakeBooleanArray(v);
return wpi::nt::Value::MakeBooleanArray(v);
} else if (py::isinstance<py::float_>(i1)) {
auto v = h.cast<std::vector<double>>();
return nt::Value::MakeDoubleArray(v);
return wpi::nt::Value::MakeDoubleArray(v);
} else if (py::isinstance<py::int_>(i1)) {
auto v = h.cast<std::vector<int64_t>>();
return nt::Value::MakeIntegerArray(v);
return wpi::nt::Value::MakeIntegerArray(v);
} else if (py::isinstance<py::str>(i1)) {
auto v = h.cast<std::vector<std::string>>();
return nt::Value::MakeStringArray(v);
return wpi::nt::Value::MakeStringArray(v);
} else {
throw py::value_error("Can only put bool/int/float/str/bytes or lists/tuples of them");
}
}

py::function valueFactoryByType(nt::NetworkTableType type) {
py::function valueFactoryByType(wpi::nt::NetworkTableType type) {
py::object PyNtValue = py::module::import("ntcore").attr("Value");
switch (type) {
case nt::NetworkTableType::kBoolean:
case wpi::nt::NetworkTableType::kBoolean:
return PyNtValue.attr("makeBoolean");
case nt::NetworkTableType::kDouble:
case wpi::nt::NetworkTableType::kDouble:
return PyNtValue.attr("makeDouble");
case nt::NetworkTableType::kString:
case wpi::nt::NetworkTableType::kString:
return PyNtValue.attr("makeString");
case nt::NetworkTableType::kRaw:
case wpi::nt::NetworkTableType::kRaw:
return PyNtValue.attr("makeRaw");
case nt::NetworkTableType::kBooleanArray:
case wpi::nt::NetworkTableType::kBooleanArray:
return PyNtValue.attr("makeBooleanArray");
case nt::NetworkTableType::kDoubleArray:
case wpi::nt::NetworkTableType::kDoubleArray:
return PyNtValue.attr("makeDoubleArray");
case nt::NetworkTableType::kStringArray:
case wpi::nt::NetworkTableType::kStringArray:
return PyNtValue.attr("makeStringArray");
case nt::NetworkTableType::kInteger:
case wpi::nt::NetworkTableType::kInteger:
return PyNtValue.attr("makeInteger");
case nt::NetworkTableType::kFloat:
case wpi::nt::NetworkTableType::kFloat:
return PyNtValue.attr("makeFloat");
case nt::NetworkTableType::kIntegerArray:
case wpi::nt::NetworkTableType::kIntegerArray:
return PyNtValue.attr("makeIntegerArray");
case nt::NetworkTableType::kFloatArray:
case wpi::nt::NetworkTableType::kFloatArray:
return PyNtValue.attr("makeFloatArray");
default:
throw py::type_error("empty nt value");
Expand Down
12 changes: 6 additions & 6 deletions subprojects/pyntcore/ntcore/src/py2value.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@

#include <semiwrap.h>
#include <networktables/NetworkTableValue.h>
#include <networktables/NetworkTableType.h>
#include "wpi/nt/NetworkTableValue.hpp"
#include "wpi/nt/NetworkTableType.hpp"
#include <fmt/format.h>

namespace pyntcore {

const char * nttype2str(NT_Type type);

py::object ntvalue2py(const nt::Value &ntvalue);
py::object ntvalue2py(const wpi::nt::Value &ntvalue);

nt::Value py2ntvalue(py::handle h);
wpi::nt::Value py2ntvalue(py::handle h);

py::function valueFactoryByType(nt::NetworkTableType type);
py::function valueFactoryByType(wpi::nt::NetworkTableType type);

inline void ensure_value_is(NT_Type expected, nt::Value *v) {
inline void ensure_value_is(NT_Type expected, wpi::nt::Value *v) {
if (v->type() != expected) {
throw py::value_error(fmt::format(
"Value type is {}, not {}", nttype2str(v->type()), nttype2str(expected)
Expand Down
Loading
Loading