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:
@ -13,12 +13,18 @@ import argparse
|
|||||||
|
|
||||||
from parse import system_include_paths
|
from parse import system_include_paths
|
||||||
|
|
||||||
default_build_path = "/home/l_frojdh/sls/build/"
|
default_build_path = "/home/l_frojdh/sls/build/"
|
||||||
fpath = "../../slsDetectorSoftware/src/Detector.cpp"
|
fpath = "../../slsDetectorSoftware/src/Detector.cpp"
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
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()
|
cargs = parser.parse_args()
|
||||||
|
|
||||||
db = cindex.CompilationDatabase.fromDirectory(cargs.build_path)
|
db = cindex.CompilationDatabase.fromDirectory(cargs.build_path)
|
||||||
@ -26,7 +32,7 @@ index = cindex.Index.create()
|
|||||||
args = db.getCompileCommands(fpath)
|
args = db.getCompileCommands(fpath)
|
||||||
args = list(iter(args).__next__().arguments)[0:-1]
|
args = list(iter(args).__next__().arguments)[0:-1]
|
||||||
args = args + "-x c++ --std=c++11".split()
|
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]
|
incargs = ["-I" + inc for inc in syspath]
|
||||||
args = args + incargs
|
args = args + incargs
|
||||||
|
|
||||||
@ -39,6 +45,7 @@ ag = []
|
|||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
|
|
||||||
|
ag2 = []
|
||||||
|
|
||||||
def get_arguments(node):
|
def get_arguments(node):
|
||||||
args = [a.type.spelling for a in node.get_arguments()]
|
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()"
|
"py::arg() = Positions{}" if item == "sls::Positions" else "py::arg()"
|
||||||
for item in args
|
for item in args
|
||||||
]
|
]
|
||||||
args = ', '.join(args)
|
args = ", ".join(args)
|
||||||
if 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
|
return args
|
||||||
|
|
||||||
|
|
||||||
@ -62,23 +81,36 @@ def visit(node):
|
|||||||
):
|
):
|
||||||
m.append(child)
|
m.append(child)
|
||||||
args = get_arguments(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():
|
for child in node.get_children():
|
||||||
visit(child)
|
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)
|
visit(tu.cursor)
|
||||||
|
|
||||||
|
|
||||||
with open('../src/detector_in.cpp') as f:
|
with open("../src/detector_in.cpp") as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
s = ''.join(lines)
|
s = "".join(lines)
|
||||||
s += ';'
|
s += ";"
|
||||||
text = data.replace('[[FUNCTIONS]]', s)
|
text = data.replace("[[FUNCTIONS]]", s)
|
||||||
warning = '/* WARINING This file is auto generated any edits might be overwritten without warning */\n\n'
|
warning = "/* WARINING This file is auto generated any edits might be overwritten without warning */\n\n"
|
||||||
with open('../src/detector.cpp', 'w') as f:
|
with open("../src/detector.cpp", "w") as f:
|
||||||
f.write(warning)
|
f.write(warning)
|
||||||
f.write(text)
|
f.write(text)
|
||||||
|
|
||||||
# run clang format on the output
|
# 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) {
|
void init_det(py::module &m) {
|
||||||
using sls::Detector;
|
using sls::Detector;
|
||||||
using sls::Positions;
|
using sls::Positions;
|
||||||
|
using sls::Result;
|
||||||
|
using sls::defs;
|
||||||
|
|
||||||
py::class_<Detector> CppDetectorApi(m, "CppDetectorApi");
|
py::class_<Detector> CppDetectorApi(m, "CppDetectorApi");
|
||||||
CppDetectorApi
|
CppDetectorApi
|
||||||
|
@ -31,6 +31,8 @@ set(PUBLICHEADERS
|
|||||||
include/ToString.h
|
include/ToString.h
|
||||||
include/TimeHelper.h
|
include/TimeHelper.h
|
||||||
include/TypeTraits.h
|
include/TypeTraits.h
|
||||||
|
include/Timer.h
|
||||||
|
include/UdpRxSocket.h
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(slsSupportLib SHARED
|
add_library(slsSupportLib SHARED
|
||||||
|
@ -74,15 +74,6 @@ class UdpRxSocket {
|
|||||||
buff = new char[packet_size];
|
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() {
|
~UdpRxSocket() {
|
||||||
delete[] buff;
|
delete[] buff;
|
||||||
Shutdown();
|
Shutdown();
|
||||||
@ -93,12 +84,16 @@ class UdpRxSocket {
|
|||||||
|
|
||||||
bool ReceivePacket() noexcept { return ReceivePacket(buff); }
|
bool ReceivePacket() noexcept { return ReceivePacket(buff); }
|
||||||
|
|
||||||
bool ReceivePacket(char *dst) noexcept {
|
bool ReceivePacket(char *dst, int flags = 0) noexcept {
|
||||||
auto bytes_received =
|
auto bytes_received =
|
||||||
recvfrom(fd, dst, packet_size, 0, nullptr, nullptr);
|
recvfrom(fd, dst, packet_size, flags, nullptr, nullptr);
|
||||||
return bytes_received == packet_size;
|
return bytes_received == packet_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PeekPacket() noexcept{
|
||||||
|
return ReceivePacket(buff, MSG_PEEK);
|
||||||
|
}
|
||||||
|
|
||||||
// Only for backwards compatibility this function will be removed during
|
// Only for backwards compatibility this function will be removed during
|
||||||
// refactoring of the receiver
|
// refactoring of the receiver
|
||||||
ssize_t ReceiveDataOnly(char *dst) {
|
ssize_t ReceiveDataOnly(char *dst) {
|
||||||
|
@ -106,4 +106,30 @@ TEST_CASE("Receive an int to an external buffer"){
|
|||||||
write(fd, &to_send, sizeof(to_send));
|
write(fd, &to_send, sizeof(to_send));
|
||||||
CHECK(s.ReceivePacket(reinterpret_cast<char*>(&received)));
|
CHECK(s.ReceivePacket(reinterpret_cast<char*>(&received)));
|
||||||
CHECK(received == to_send);
|
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