default value for setDAC

This commit is contained in:
Erik Frojdh 2020-09-10 14:45:31 +02:00
parent 2733bc5320
commit 2bc33ad34a
3 changed files with 30 additions and 11 deletions

View File

@ -60,6 +60,23 @@ def get_arguments(node):
args = f", {args}" args = f", {args}"
return args return args
def get_arguments_with_default(node):
args = []
for arg in node.get_arguments():
tokens = [t.spelling for t in arg.get_tokens()]
print(tokens)
if '=' in tokens:
if arg.type.spelling == "sls::Positions": #TODO! automate
args.append("py::arg() = Positions{}")
else:
args.append('py::arg()' + ''.join(tokens[tokens.index('='):]))
else:
args.append('py::arg()')
args = ", ".join(args)
if args:
args = f", {args}"
return args
def get_fdec(node): def get_fdec(node):
args = [a.type.spelling for a in node.get_arguments()] args = [a.type.spelling for a in node.get_arguments()]
@ -86,7 +103,8 @@ def visit(node):
and child.access_specifier == cindex.AccessSpecifier.PUBLIC and child.access_specifier == cindex.AccessSpecifier.PUBLIC
): ):
m.append(child) m.append(child)
args = get_arguments(child) # args = get_arguments(child)
args = get_arguments_with_default(child)
fs = get_fdec(child) fs = get_fdec(child)
lines.append( lines.append(
f'.def("{child.spelling}",{fs} &Detector::{child.spelling}{args})' f'.def("{child.spelling}",{fs} &Detector::{child.spelling}{args})'

View File

@ -322,11 +322,11 @@ void init_det(py::module &m) {
(Result<int>(Detector::*)(defs::dacIndex, bool, sls::Positions) (Result<int>(Detector::*)(defs::dacIndex, bool, sls::Positions)
const) & const) &
Detector::getDAC, Detector::getDAC,
py::arg(), py::arg(), py::arg() = Positions{}) py::arg(), py::arg() = false, py::arg() = Positions{})
.def("setDAC", .def("setDAC",
(void (Detector::*)(defs::dacIndex, int, bool, sls::Positions)) & (void (Detector::*)(defs::dacIndex, int, bool, sls::Positions)) &
Detector::setDAC, Detector::setDAC,
py::arg(), py::arg(), py::arg(), py::arg() = Positions{}) py::arg(), py::arg(), py::arg() = false, py::arg() = Positions{})
.def("getOnChipDAC", .def("getOnChipDAC",
(Result<int>(Detector::*)(defs::dacIndex, int, sls::Positions) (Result<int>(Detector::*)(defs::dacIndex, int, sls::Positions)
const) & const) &
@ -488,14 +488,14 @@ void init_det(py::module &m) {
py::arg() = Positions{}) py::arg() = Positions{})
.def("setDestinationUDPPort", .def("setDestinationUDPPort",
(void (Detector::*)(int, int)) & Detector::setDestinationUDPPort, (void (Detector::*)(int, int)) & Detector::setDestinationUDPPort,
py::arg(), py::arg()) py::arg(), py::arg() = -1)
.def("getDestinationUDPPort2", .def("getDestinationUDPPort2",
(Result<int>(Detector::*)(sls::Positions) const) & (Result<int>(Detector::*)(sls::Positions) const) &
Detector::getDestinationUDPPort2, Detector::getDestinationUDPPort2,
py::arg() = Positions{}) py::arg() = Positions{})
.def("setDestinationUDPPort2", .def("setDestinationUDPPort2",
(void (Detector::*)(int, int)) & Detector::setDestinationUDPPort2, (void (Detector::*)(int, int)) & Detector::setDestinationUDPPort2,
py::arg(), py::arg()) py::arg(), py::arg() = -1)
.def("reconfigureUDPDestination", .def("reconfigureUDPDestination",
(void (Detector::*)(sls::Positions)) & (void (Detector::*)(sls::Positions)) &
Detector::reconfigureUDPDestination, Detector::reconfigureUDPDestination,
@ -568,7 +568,7 @@ void init_det(py::module &m) {
Detector::getRxPort, Detector::getRxPort,
py::arg() = Positions{}) py::arg() = Positions{})
.def("setRxPort", (void (Detector::*)(int, int)) & Detector::setRxPort, .def("setRxPort", (void (Detector::*)(int, int)) & Detector::setRxPort,
py::arg(), py::arg()) py::arg(), py::arg() = -1)
.def("getRxFifoDepth", .def("getRxFifoDepth",
(Result<int>(Detector::*)(sls::Positions) const) & (Result<int>(Detector::*)(sls::Positions) const) &
Detector::getRxFifoDepth, Detector::getRxFifoDepth,
@ -730,7 +730,7 @@ void init_det(py::module &m) {
py::arg() = Positions{}) py::arg() = Positions{})
.def("setRxZmqPort", .def("setRxZmqPort",
(void (Detector::*)(int, int)) & Detector::setRxZmqPort, py::arg(), (void (Detector::*)(int, int)) & Detector::setRxZmqPort, py::arg(),
py::arg()) py::arg() = -1)
.def("getRxZmqIP", .def("getRxZmqIP",
(Result<sls::IpAddr>(Detector::*)(sls::Positions) const) & (Result<sls::IpAddr>(Detector::*)(sls::Positions) const) &
Detector::getRxZmqIP, Detector::getRxZmqIP,
@ -745,7 +745,7 @@ void init_det(py::module &m) {
py::arg() = Positions{}) py::arg() = Positions{})
.def("setClientZmqPort", .def("setClientZmqPort",
(void (Detector::*)(int, int)) & Detector::setClientZmqPort, (void (Detector::*)(int, int)) & Detector::setClientZmqPort,
py::arg(), py::arg()) py::arg(), py::arg() = -1)
.def("getClientZmqIp", .def("getClientZmqIp",
(Result<sls::IpAddr>(Detector::*)(sls::Positions) const) & (Result<sls::IpAddr>(Detector::*)(sls::Positions) const) &
Detector::getClientZmqIp, Detector::getClientZmqIp,
@ -778,7 +778,8 @@ void init_det(py::module &m) {
(void (Detector::*)(int, defs::detectorSettings, bool, (void (Detector::*)(int, defs::detectorSettings, bool,
sls::Positions)) & sls::Positions)) &
Detector::setThresholdEnergy, Detector::setThresholdEnergy,
py::arg(), py::arg(), py::arg(), py::arg() = Positions{}) py::arg(), py::arg() = defs::STANDARD, py::arg() = true,
py::arg() = Positions{})
.def("getSettingsPath", .def("getSettingsPath",
(Result<std::string>(Detector::*)(sls::Positions) const) & (Result<std::string>(Detector::*)(sls::Positions) const) &
Detector::getSettingsPath, Detector::getSettingsPath,

View File

@ -367,9 +367,9 @@ class Detector {
/** gets list of dac enums for this detector */ /** gets list of dac enums for this detector */
std::vector<defs::dacIndex> getDacList() const; std::vector<defs::dacIndex> getDacList() const;
Result<int> getDAC(defs::dacIndex index, bool mV, Positions pos = {}) const; Result<int> getDAC(defs::dacIndex index, bool mV = false, Positions pos = {}) const;
void setDAC(defs::dacIndex index, int value, bool mV, Positions pos = {}); void setDAC(defs::dacIndex index, int value, bool mV = false, Positions pos = {});
/* [Gotthard2] */ /* [Gotthard2] */
Result<int> getOnChipDAC(defs::dacIndex index, int chipIndex, Result<int> getOnChipDAC(defs::dacIndex index, int chipIndex,