DPsim
pybind-dpsim-villas.cpp
1 // SPDX-License-Identifier: Apache-2.0
2 
3 #include <pybind11/complex.h>
4 #include <pybind11/pybind11.h>
5 #include <pybind11/stl.h>
6 
7 #include <dpsim-villas/InterfaceVillas.h>
8 
9 PYBIND11_DECLARE_HOLDER_TYPE(T, CPS::AttributePointer<T>);
10 
11 namespace py = pybind11;
12 using namespace py::literals;
13 using namespace villas;
14 
16 
17 public:
19 
20  PyInterfaceVillas(py::dict config, CPS::UInt queueLength,
21  CPS::UInt sampleLength, const CPS::String &name,
22  CPS::UInt downsampling)
23  : InterfaceVillas(
24  (py::str)py::module_::import("json").attr("dumps")(
25  config,
26  "indent"_a = py::none()), //json.dumps(config, indent=None)
27  queueLength, sampleLength, name, downsampling) {}
28 };
29 
30 PYBIND11_MODULE(dpsimpyvillas, m) {
31  py::object interface =
32  (py::object)py::module_::import("dpsimpy").attr("Interface");
33 
34  py::class_<PyInterfaceVillas, std::shared_ptr<PyInterfaceVillas>>(
35  m, "InterfaceVillas", interface)
36  .def(py::init<const CPS::String &, CPS::UInt, CPS::UInt,
37  const CPS::String &, CPS::UInt>(),
38  "config"_a, "queue_length"_a = 512, "sample_length"_a = 64,
39  "name"_a = "", "downsampling"_a = 1)
40  .def(py::init<py::dict, CPS::UInt, CPS::UInt, const CPS::String &,
41  CPS::UInt>(),
42  "config"_a, "queue_length"_a = 512, "sample_length"_a = 64,
43  "name"_a = "", "downsampling"_a = 1)
44  .def("import_attribute", &PyInterfaceVillas::importAttribute, "attr"_a,
45  // cppcheck-suppress assignBoolToPointer
46  "idx"_a, "block_on_read"_a = false, "sync_on_start"_a = true,
47  "name"_a = "", "unit"_a = "")
48  .def("export_attribute", &PyInterfaceVillas::exportAttribute, "attr"_a,
49  // cppcheck-suppress assignBoolToPointer
50  "idx"_a, "wait_for_on_write"_a = true, "name"_a = "", "unit"_a = "");
51 }
Interface type that can be used to import and export simulation attributes over any node type support...
InterfaceVillas(const String &nodeConfig, UInt queueLength=512, UInt sampleLength=64, const String &name="", UInt downsampling=1)
create a new InterfaceVillas instance