mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 18:17:59 +02:00
Merge branch 'developer' of github.com:slsdetectorgroup/slsDetectorPackage into developer
This commit is contained in:
@ -18,7 +18,13 @@ fpath = "../../slsDetectorSoftware/src/Detector.cpp"
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-p", "--build_path", help="Path to the build database", type = str, default=default_build_path)
|
||||
parser.add_argument(
|
||||
"-p",
|
||||
"--build_path",
|
||||
help="Path to the build database",
|
||||
type=str,
|
||||
default=default_build_path,
|
||||
)
|
||||
cargs = parser.parse_args()
|
||||
|
||||
db = cindex.CompilationDatabase.fromDirectory(cargs.build_path)
|
||||
@ -26,7 +32,7 @@ index = cindex.Index.create()
|
||||
args = db.getCompileCommands(fpath)
|
||||
args = list(iter(args).__next__().arguments)[0:-1]
|
||||
args = args + "-x c++ --std=c++11".split()
|
||||
syspath = system_include_paths('clang++')
|
||||
syspath = system_include_paths("clang++")
|
||||
incargs = ["-I" + inc for inc in syspath]
|
||||
args = args + incargs
|
||||
|
||||
@ -39,6 +45,7 @@ ag = []
|
||||
|
||||
lines = []
|
||||
|
||||
ag2 = []
|
||||
|
||||
def get_arguments(node):
|
||||
args = [a.type.spelling for a in node.get_arguments()]
|
||||
@ -46,9 +53,21 @@ def get_arguments(node):
|
||||
"py::arg() = Positions{}" if item == "sls::Positions" else "py::arg()"
|
||||
for item in args
|
||||
]
|
||||
args = ', '.join(args)
|
||||
args = ", ".join(args)
|
||||
if args:
|
||||
args = f', {args}'
|
||||
args = f", {args}"
|
||||
return args
|
||||
|
||||
|
||||
def get_fdec(node):
|
||||
args = [a.type.spelling for a in node.get_arguments()]
|
||||
if node.result_type.spelling:
|
||||
return_type = node.result_type.spelling
|
||||
else:
|
||||
return_type = 'void'
|
||||
|
||||
args = ", ".join(args)
|
||||
args = f'({return_type}(Detector::*)({args}))'
|
||||
return args
|
||||
|
||||
|
||||
@ -62,23 +81,36 @@ def visit(node):
|
||||
):
|
||||
m.append(child)
|
||||
args = get_arguments(child)
|
||||
lines.append(f'.def(\"{child.spelling}\", &Detector::{child.spelling}{args})')
|
||||
fs = get_fdec(child)
|
||||
lines.append(
|
||||
f'.def("{child.spelling}",{fs} &Detector::{child.spelling}{args})'
|
||||
)
|
||||
for child in node.get_children():
|
||||
visit(child)
|
||||
|
||||
# .def("setRxHostname",
|
||||
# (void (Detector::*)(const std::string &, Positions)) &
|
||||
# Detector::setRxHostname,
|
||||
# py::arg(), py::arg() = Positions{})
|
||||
# .def("setRxHostname",
|
||||
# (void (Detector::*)(const std::vector<std::string> &)) &
|
||||
# Detector::setRxHostname,
|
||||
# py::arg())
|
||||
|
||||
|
||||
visit(tu.cursor)
|
||||
|
||||
|
||||
with open('../src/detector_in.cpp') as f:
|
||||
with open("../src/detector_in.cpp") as f:
|
||||
data = f.read()
|
||||
s = ''.join(lines)
|
||||
s += ';'
|
||||
text = data.replace('[[FUNCTIONS]]', s)
|
||||
warning = '/* WARINING This file is auto generated any edits might be overwritten without warning */\n\n'
|
||||
with open('../src/detector.cpp', 'w') as f:
|
||||
s = "".join(lines)
|
||||
s += ";"
|
||||
text = data.replace("[[FUNCTIONS]]", s)
|
||||
warning = "/* WARINING This file is auto generated any edits might be overwritten without warning */\n\n"
|
||||
with open("../src/detector.cpp", "w") as f:
|
||||
f.write(warning)
|
||||
f.write(text)
|
||||
|
||||
# run clang format on the output
|
||||
subprocess.run(['clang-format', '../src/detector.cpp', '-i'])
|
||||
subprocess.run(["clang-format", "../src/detector.cpp", "-i"])
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -12,6 +12,8 @@ namespace py = pybind11;
|
||||
void init_det(py::module &m) {
|
||||
using sls::Detector;
|
||||
using sls::Positions;
|
||||
using sls::Result;
|
||||
using sls::defs;
|
||||
|
||||
py::class_<Detector> CppDetectorApi(m, "CppDetectorApi");
|
||||
CppDetectorApi
|
||||
|
@ -31,6 +31,8 @@ set(PUBLICHEADERS
|
||||
include/ToString.h
|
||||
include/TimeHelper.h
|
||||
include/TypeTraits.h
|
||||
include/Timer.h
|
||||
include/UdpRxSocket.h
|
||||
)
|
||||
|
||||
add_library(slsSupportLib SHARED
|
||||
|
@ -74,15 +74,6 @@ class UdpRxSocket {
|
||||
buff = new char[packet_size];
|
||||
}
|
||||
|
||||
// // Delegating constructor to allow drop in replacement for old socket class
|
||||
// // This one might be removed in the future
|
||||
// UdpRxSocket(unsigned short int const port_number,
|
||||
// genericSocket::communicationProtocol p,
|
||||
// int ps = DEFAULT_PACKET_SIZE, const char *eth = NULL,
|
||||
// int hsize = 0, uint64_t buf_size = SOCKET_BUFFER_SIZE)
|
||||
// : UdpRxSocket(port_number, ps, InterfaceNameToIp(eth).str().c_str(),
|
||||
// buf_size) {}
|
||||
|
||||
~UdpRxSocket() {
|
||||
delete[] buff;
|
||||
Shutdown();
|
||||
@ -93,12 +84,16 @@ class UdpRxSocket {
|
||||
|
||||
bool ReceivePacket() noexcept { return ReceivePacket(buff); }
|
||||
|
||||
bool ReceivePacket(char *dst) noexcept {
|
||||
bool ReceivePacket(char *dst, int flags = 0) noexcept {
|
||||
auto bytes_received =
|
||||
recvfrom(fd, dst, packet_size, 0, nullptr, nullptr);
|
||||
recvfrom(fd, dst, packet_size, flags, nullptr, nullptr);
|
||||
return bytes_received == packet_size;
|
||||
}
|
||||
|
||||
bool PeekPacket() noexcept{
|
||||
return ReceivePacket(buff, MSG_PEEK);
|
||||
}
|
||||
|
||||
// Only for backwards compatibility this function will be removed during
|
||||
// refactoring of the receiver
|
||||
ssize_t ReceiveDataOnly(char *dst) {
|
||||
|
@ -107,3 +107,29 @@ TEST_CASE("Receive an int to an external buffer"){
|
||||
CHECK(s.ReceivePacket(reinterpret_cast<char*>(&received)));
|
||||
CHECK(received == to_send);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("PEEK data"){
|
||||
int to_send = 5;
|
||||
int to_send2 = 12;
|
||||
int received = -1;
|
||||
auto fd = open_socket(default_port);
|
||||
sls::UdpRxSocket s(default_port, sizeof(int));
|
||||
write(fd, &to_send, sizeof(to_send));
|
||||
write(fd, &to_send2, sizeof(to_send));
|
||||
CHECK(s.PeekPacket());
|
||||
memcpy(&received, s.LastPacket(), sizeof(int));
|
||||
CHECK(received == to_send);
|
||||
|
||||
CHECK(s.PeekPacket());
|
||||
memcpy(&received, s.LastPacket(), sizeof(int));
|
||||
CHECK(received == to_send);
|
||||
|
||||
CHECK(s.ReceivePacket());
|
||||
memcpy(&received, s.LastPacket(), sizeof(int));
|
||||
CHECK(received == to_send);
|
||||
|
||||
CHECK(s.ReceivePacket());
|
||||
memcpy(&received, s.LastPacket(), sizeof(int));
|
||||
CHECK(received == to_send2);
|
||||
}
|
||||
|
Reference in New Issue
Block a user