mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-08-07 21:02:26 +02:00
tcp: Variable size array (#1492)
Build and Deploy on local RHEL9 / build (push) Successful in 2m4s
Build on RHEL9 docker image / build (push) Successful in 3m57s
Build on RHEL8 docker image / build (push) Successful in 5m6s
Build and Deploy on local RHEL8 / build (push) Successful in 5m9s
Run Simulator Tests on local RHEL9 / build (push) Successful in 20m7s
Run Simulator Tests on local RHEL8 / build (push) Successful in 23m40s
Build and Deploy on local RHEL9 / build (push) Successful in 2m4s
Build on RHEL9 docker image / build (push) Successful in 3m57s
Build on RHEL8 docker image / build (push) Successful in 5m6s
Build and Deploy on local RHEL8 / build (push) Successful in 5m9s
Run Simulator Tests on local RHEL9 / build (push) Successful in 20m7s
Run Simulator Tests on local RHEL8 / build (push) Successful in 23m40s
* templated variable vector size (sending/receive size before vector) in ClientSocket and Module:SendToReceiverVarVector * fix warnign * Another tcp function ironed out but for Detector * wip * fix * wip * wip * wip * wip * fix for execccomand * typo --------- Co-authored-by: AliceMazzoleni99 <alice.mazzoleni@psi.ch>
This commit is contained in:
@@ -831,32 +831,17 @@ int ClientInterface::get_file_index(Interface &socket) {
|
||||
|
||||
int ClientInterface::get_frame_index(Interface &socket) {
|
||||
auto retval = impl()->getCurrentFrameIndex();
|
||||
LOG(logDEBUG1) << "frames index:" << ToString(retval);
|
||||
auto size = static_cast<int>(retval.size());
|
||||
socket.Send(OK);
|
||||
socket.Send(size);
|
||||
socket.Send(retval);
|
||||
return OK;
|
||||
return socket.sendVariableResult(retval);
|
||||
}
|
||||
|
||||
int ClientInterface::get_missing_packets(Interface &socket) {
|
||||
auto missing_packets = impl()->getNumMissingPackets();
|
||||
LOG(logDEBUG1) << "missing packets:" << ToString(missing_packets);
|
||||
auto size = static_cast<int>(missing_packets.size());
|
||||
socket.Send(OK);
|
||||
socket.Send(size);
|
||||
socket.Send(missing_packets);
|
||||
return OK;
|
||||
return socket.sendVariableResult(missing_packets);
|
||||
}
|
||||
|
||||
int ClientInterface::get_frames_caught(Interface &socket) {
|
||||
auto retval = impl()->getFramesCaught();
|
||||
LOG(logDEBUG1) << "frames caught:" << ToString(retval);
|
||||
auto size = static_cast<int>(retval.size());
|
||||
socket.Send(OK);
|
||||
socket.Send(size);
|
||||
socket.Send(retval);
|
||||
return OK;
|
||||
return socket.sendVariableResult(retval);
|
||||
}
|
||||
|
||||
int ClientInterface::set_file_write(Interface &socket) {
|
||||
@@ -1113,37 +1098,39 @@ int ClientInterface::stream_rx_dummy_header(Interface &socket) {
|
||||
}
|
||||
|
||||
int ClientInterface::set_additional_json_header(Interface &socket) {
|
||||
std::map<std::string, std::string> json;
|
||||
auto size = socket.Receive<int>();
|
||||
if (size > 0) {
|
||||
std::string buff(size, '\0');
|
||||
socket.Receive(&buff[0], buff.size());
|
||||
std::istringstream iss(buff);
|
||||
std::string key, value;
|
||||
while (iss >> key) {
|
||||
iss >> value;
|
||||
json[key] = value;
|
||||
}
|
||||
}
|
||||
// verifyIdle(socket); allowing it to be set on the fly
|
||||
LOG(logDEBUG1) << "Setting additional json header: " << ToString(json);
|
||||
impl()->setAdditionalJsonHeader(json);
|
||||
|
||||
auto vec = socket.receiveVariableArgs<std::vector<char>>();
|
||||
// convert vector<char> to string (space separated)
|
||||
std::string longString(vec.begin(), vec.end());
|
||||
// convert string to map of key-value pairs
|
||||
std::map<std::string, std::string> args;
|
||||
std::istringstream iss(longString);
|
||||
std::string key, value;
|
||||
while (iss >> key) {
|
||||
iss >> value;
|
||||
args[key] = value;
|
||||
}
|
||||
LOG(logDEBUG1) << "Setting additional json header: " << ToString(args);
|
||||
|
||||
impl()->setAdditionalJsonHeader(args);
|
||||
return socket.Send(OK);
|
||||
}
|
||||
|
||||
int ClientInterface::get_additional_json_header(Interface &socket) {
|
||||
std::map<std::string, std::string> json = impl()->getAdditionalJsonHeader();
|
||||
LOG(logDEBUG1) << "additional json header:" << ToString(json);
|
||||
|
||||
// convert map to string (space separated) to send over socket
|
||||
std::ostringstream oss;
|
||||
for (auto &it : json) {
|
||||
oss << it.first << ' ' << it.second << ' ';
|
||||
}
|
||||
auto buff = oss.str();
|
||||
auto size = static_cast<int>(buff.size());
|
||||
socket.sendResult(size);
|
||||
if (size > 0)
|
||||
socket.Send(buff);
|
||||
return OK;
|
||||
auto longString = oss.str();
|
||||
|
||||
// conver to vector<char> to send over socket (variable vector length impl)
|
||||
std::vector<char> retval(longString.begin(), longString.end());
|
||||
return socket.sendVariableResult(retval);
|
||||
}
|
||||
|
||||
int ClientInterface::set_udp_socket_buffer_size(Interface &socket) {
|
||||
@@ -1612,16 +1599,13 @@ int ClientInterface::set_streaming_start_fnum(Interface &socket) {
|
||||
}
|
||||
|
||||
int ClientInterface::set_rate_correct(Interface &socket) {
|
||||
auto index = socket.Receive<int>();
|
||||
if (index <= 0) {
|
||||
throw RuntimeError("Invalid number of rate correction values: " +
|
||||
std::to_string(index));
|
||||
}
|
||||
LOG(logDEBUG) << "Number of detectors for rate correction: " << index;
|
||||
std::vector<int64_t> t(index);
|
||||
socket.Receive(t);
|
||||
verifyIdle(socket);
|
||||
LOG(logINFO) << "Setting rate corrections[" << index << ']';
|
||||
|
||||
auto t = socket.receiveVariableArgs<std::vector<int64_t>>();
|
||||
if (t.size() <= 0)
|
||||
throw RuntimeError("Invalid number of rate correction values: " +
|
||||
std::to_string(t.size()));
|
||||
LOG(logINFO) << "Setting rate corrections[" << t.size() << ']';
|
||||
impl()->setRateCorrections(t);
|
||||
return socket.Send(OK);
|
||||
}
|
||||
@@ -1748,58 +1732,41 @@ int ClientInterface::set_arping(Interface &socket) {
|
||||
int ClientInterface::get_receiver_roi(Interface &socket) {
|
||||
auto retvals = impl()->getPortROIs();
|
||||
LOG(logDEBUG1) << "Receiver roi retval:" << ToString(retvals);
|
||||
auto size = static_cast<int>(retvals.size());
|
||||
if (size != impl()->getNumberofUDPInterfaces()) {
|
||||
throw RuntimeError("Invalid number of ROIs received: " +
|
||||
std::to_string(size) + ". Expected: " +
|
||||
std::to_string(impl()->getNumberofUDPInterfaces()));
|
||||
}
|
||||
socket.Send(size);
|
||||
if (size > 0)
|
||||
socket.Send(retvals);
|
||||
return OK;
|
||||
return socket.sendVariableResult(retvals);
|
||||
}
|
||||
|
||||
int ClientInterface::set_receiver_roi(Interface &socket) {
|
||||
auto roiSize = socket.Receive<int>();
|
||||
std::vector<ROI> args(roiSize);
|
||||
if (roiSize > 0) {
|
||||
socket.Receive(args);
|
||||
}
|
||||
if (roiSize != impl()->getNumberofUDPInterfaces()) {
|
||||
throw RuntimeError("Invalid number of ROIs received: " +
|
||||
std::to_string(roiSize) + ". Expected: " +
|
||||
std::to_string(impl()->getNumberofUDPInterfaces()));
|
||||
}
|
||||
if (detType == CHIPTESTBOARD || detType == XILINX_CHIPTESTBOARD)
|
||||
functionNotImplemented();
|
||||
LOG(logDEBUG1) << "Set Receiver ROI: " << ToString(args);
|
||||
verifyIdle(socket);
|
||||
|
||||
auto args = socket.receiveVariableArgs<std::vector<ROI>>();
|
||||
auto numInterfaces = impl()->getNumberofUDPInterfaces();
|
||||
if (static_cast<int>(args.size()) != numInterfaces) {
|
||||
std::ostringstream oss;
|
||||
oss << "Invalid number of ROIs received: " << args.size()
|
||||
<< ". Expected: " << numInterfaces;
|
||||
throw RuntimeError(oss.str());
|
||||
}
|
||||
LOG(logDEBUG1) << "Set Receiver ROI: " << ToString(args);
|
||||
try {
|
||||
impl()->setPortROIs(args);
|
||||
} catch (const std::exception &e) {
|
||||
throw RuntimeError("Could not set Receiver ROI [" +
|
||||
std::string(e.what()) + ']');
|
||||
}
|
||||
|
||||
return socket.Send(OK);
|
||||
}
|
||||
|
||||
int ClientInterface::set_receiver_roi_metadata(Interface &socket) {
|
||||
auto roiSize = socket.Receive<int>();
|
||||
LOG(logDEBUG1) << "Number of ReceiverROI metadata: " << roiSize;
|
||||
if (roiSize < 1) {
|
||||
throw RuntimeError("Invalid number of ROIs received: " +
|
||||
std::to_string(roiSize) + ". Min: 1.");
|
||||
}
|
||||
std::vector<ROI> rois(roiSize);
|
||||
if (roiSize > 0) {
|
||||
socket.Receive(rois);
|
||||
}
|
||||
if (detType == CHIPTESTBOARD || detType == XILINX_CHIPTESTBOARD)
|
||||
functionNotImplemented();
|
||||
verifyIdle(socket);
|
||||
LOG(logINFO) << "Setting ReceiverROI metadata[" << roiSize << ']';
|
||||
|
||||
auto rois = socket.receiveVariableArgs<std::vector<ROI>>();
|
||||
if (rois.size() < 1)
|
||||
throw RuntimeError("Invalid number of ROI metadata: " +
|
||||
std::to_string(rois.size()) + ". Min: 1.");
|
||||
try {
|
||||
impl()->setMultiROIMetadata(rois);
|
||||
} catch (const std::exception &e) {
|
||||
@@ -1896,12 +1863,7 @@ int ClientInterface::get_roi_metadata(Interface &socket) {
|
||||
if (detType == CHIPTESTBOARD || detType == XILINX_CHIPTESTBOARD)
|
||||
functionNotImplemented();
|
||||
auto retvals = impl()->getMultiROIMetadata();
|
||||
LOG(logDEBUG1) << "Receiver ROI metadata retval:" << ToString(retvals);
|
||||
auto size = static_cast<int>(retvals.size());
|
||||
socket.Send(size);
|
||||
if (size > 0)
|
||||
socket.Send(retvals);
|
||||
return OK;
|
||||
return socket.sendVariableResult(retvals);
|
||||
}
|
||||
|
||||
int ClientInterface::set_readout_speed(Interface &socket) {
|
||||
@@ -1934,16 +1896,9 @@ int ClientInterface::set_readout_speed(Interface &socket) {
|
||||
}
|
||||
|
||||
int ClientInterface::set_udp_port_disable_meta(Interface &socket) {
|
||||
auto nports = socket.Receive<int>();
|
||||
std::vector<int> portsDisabled;
|
||||
if (nports > 0) {
|
||||
portsDisabled.resize(nports);
|
||||
socket.Receive(portsDisabled);
|
||||
LOG(logDEBUG1) << "Disabled Ports Metadata:" << ToString(portsDisabled);
|
||||
}
|
||||
verifyIdle(socket);
|
||||
auto portsDisabled = socket.receiveVariableArgs<std::vector<int>>();
|
||||
try {
|
||||
|
||||
impl()->setUDPPortsDisabledMetadata(portsDisabled);
|
||||
} catch (const std::exception &e) {
|
||||
throw RuntimeError("Could not update UDP ports disabled metadata [" +
|
||||
@@ -1954,14 +1909,7 @@ int ClientInterface::set_udp_port_disable_meta(Interface &socket) {
|
||||
|
||||
int ClientInterface::get_udp_port_disable_meta(Interface &socket) {
|
||||
auto retvals = impl()->getUDPPortsDisabledMetadata();
|
||||
LOG(logDEBUG1) << "Receiver disabled udp ports retval:"
|
||||
<< ToString(retvals);
|
||||
socket.Send(OK);
|
||||
auto size = static_cast<int>(retvals.size());
|
||||
socket.Send(size);
|
||||
if (size > 0)
|
||||
socket.Send(retvals);
|
||||
return OK;
|
||||
return socket.sendVariableResult(retvals);
|
||||
}
|
||||
|
||||
} // namespace sls
|
||||
|
||||
Reference in New Issue
Block a user