mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 18:17:59 +02:00
WIP
This commit is contained in:
@ -252,6 +252,7 @@ Result<ns> Detector::getPeriod(Positions pos) const {
|
||||
|
||||
void Detector::setPeriod(ns t, Positions pos) {
|
||||
pimpl->Parallel(&Module::setPeriod, pos, t.count());
|
||||
pimpl->Parallel3(&Receiver::setPeriod, t.count());
|
||||
}
|
||||
|
||||
Result<ns> Detector::getDelayAfterTrigger(Positions pos) const {
|
||||
@ -849,17 +850,16 @@ void Detector::setPartialFramesPadding(bool value, Positions pos) {
|
||||
}
|
||||
|
||||
Result<int64_t> Detector::getRxUDPSocketBufferSize(Positions pos) const {
|
||||
return pimpl->Parallel(&Module::getReceiverUDPSocketBufferSize, pos);
|
||||
return pimpl->Parallel3(&Receiver::getUDPSocketBufferSize);
|
||||
}
|
||||
|
||||
void Detector::setRxUDPSocketBufferSize(int64_t udpsockbufsize, Positions pos) {
|
||||
pimpl->Parallel(&Module::setReceiverUDPSocketBufferSize, pos,
|
||||
pimpl->Parallel3(&Receiver::setUDPSocketBufferSize,
|
||||
udpsockbufsize);
|
||||
}
|
||||
|
||||
Result<int64_t> Detector::getRxRealUDPSocketBufferSize(Positions pos) const {
|
||||
return pimpl->Parallel(&Module::getReceiverRealUDPSocketBufferSize,
|
||||
pos);
|
||||
return pimpl->Parallel3(&Receiver::getRealUDPSocketBufferSize);
|
||||
}
|
||||
|
||||
Result<bool> Detector::getRxLock(Positions pos) {
|
||||
@ -967,28 +967,28 @@ void Detector::setRxZmqTimer(int time_in_ms, Positions pos) {
|
||||
}
|
||||
|
||||
Result<int> Detector::getRxZmqPort(Positions pos) const {
|
||||
return pimpl->Parallel1(&Receiver::getReceiverZmqPort, pos, {});
|
||||
return pimpl->Parallel1(&Receiver::getZmqPort, pos, {});
|
||||
}
|
||||
|
||||
void Detector::setRxZmqPort(int port, int module_id) {
|
||||
if (module_id == -1) {
|
||||
for (int idet = 0; idet < size(); ++idet) {
|
||||
pimpl->Parallel1(&Receiver::setReceiverZmqPort, {idet},
|
||||
pimpl->Parallel1(&Receiver::setZmqPort, {idet},
|
||||
{}, port++);
|
||||
}
|
||||
} else {
|
||||
pimpl->Parallel1(&Receiver::setReceiverZmqPort, {module_id},
|
||||
pimpl->Parallel1(&Receiver::setZmqPort, {module_id},
|
||||
{}, port++);
|
||||
}
|
||||
}
|
||||
|
||||
Result<IpAddr> Detector::getRxZmqIP(Positions pos) const {
|
||||
return pimpl->Parallel(&Module::getReceiverStreamingIP, pos);
|
||||
return pimpl->Parallel3(&Receiver::getZmqIP);
|
||||
}
|
||||
|
||||
void Detector::setRxZmqIP(const IpAddr ip, Positions pos) {
|
||||
bool previouslyReceiverStreaming = getRxZmqDataStream(pos).squash(false);
|
||||
pimpl->Parallel(&Module::setReceiverStreamingIP, pos, ip);
|
||||
pimpl->Parallel3(&Receiver::setZmqIP, ip);
|
||||
if (previouslyReceiverStreaming) {
|
||||
setRxZmqDataStream(false, pos);
|
||||
setRxZmqDataStream(true, pos);
|
||||
@ -1012,12 +1012,12 @@ void Detector::setClientZmqPort(int port, int module_id) {
|
||||
}
|
||||
|
||||
Result<IpAddr> Detector::getClientZmqIp(Positions pos) const {
|
||||
return pimpl->Parallel(&Module::getClientStreamingIP, pos);
|
||||
return pimpl->Parallel3(&Receiver::getClientZmqIP);
|
||||
}
|
||||
|
||||
void Detector::setClientZmqIp(const IpAddr ip, Positions pos) {
|
||||
int previouslyClientStreaming = pimpl->enableDataStreamingToClient(-1);
|
||||
pimpl->Parallel(&Module::setClientStreamingIP, pos, ip);
|
||||
pimpl->Parallel3(&Receiver::setClientZmqIP, ip);
|
||||
if (previouslyClientStreaming != 0) {
|
||||
pimpl->enableDataStreamingToClient(0);
|
||||
pimpl->enableDataStreamingToClient(1);
|
||||
@ -1085,12 +1085,30 @@ void Detector::setSubDeadTime(ns value, Positions pos) {
|
||||
}
|
||||
|
||||
Result<int> Detector::getThresholdEnergy(Positions pos) const {
|
||||
if (getDetectorType().squash() == defs::MOENCH) {
|
||||
auto res = getAdditionalJsonParameter("threshold", pos);
|
||||
Result<int> intResult(res.size());
|
||||
try {
|
||||
for (unsigned int i = 0; i < res.size(); ++i) {
|
||||
intResult[i] = stoi(res[i]);
|
||||
}
|
||||
} catch (...) {
|
||||
throw RuntimeError(
|
||||
"Cannot find or convert threshold string to integer");
|
||||
}
|
||||
return intResult;
|
||||
}
|
||||
|
||||
return pimpl->Parallel(&Module::getThresholdEnergy, pos);
|
||||
}
|
||||
|
||||
void Detector::setThresholdEnergy(int threshold_ev,
|
||||
defs::detectorSettings settings,
|
||||
bool trimbits, Positions pos) {
|
||||
if (getDetectorType().squash() == defs::MOENCH) {
|
||||
setAdditionalJsonParameter("threshold",
|
||||
std::to_string(threshold_ev), pos);
|
||||
}
|
||||
pimpl->Parallel(&Module::setThresholdEnergy, pos, threshold_ev,
|
||||
settings, static_cast<int>(trimbits));
|
||||
}
|
||||
@ -1193,11 +1211,12 @@ Result<ns> Detector::getMeasuredSubFramePeriod(Positions pos) const {
|
||||
}
|
||||
|
||||
Result<bool> Detector::getActive(Positions pos) const {
|
||||
return pimpl->Parallel(&Module::activate, pos, -1);
|
||||
return pimpl->Parallel(&Module::getActivate, pos);
|
||||
}
|
||||
|
||||
void Detector::setActive(bool active, Positions pos) {
|
||||
pimpl->Parallel(&Module::activate, pos, static_cast<int>(active));
|
||||
pimpl->Parallel(&Module::setActivate, pos, active);
|
||||
pimpl->Parallel3(&Receiver::setActivate, active);
|
||||
}
|
||||
|
||||
Result<bool> Detector::getRxPadDeactivatedMode(Positions pos) const {
|
||||
@ -1321,11 +1340,16 @@ void Detector::setROI(defs::ROI value, int module_id) {
|
||||
if (module_id < 0 && size() > 1) {
|
||||
throw RuntimeError("Cannot set ROI for all modules simultaneously");
|
||||
}
|
||||
if (value.xmin < 0 || value.xmax >= getModuleSize({module_id})[0].x) {
|
||||
throw RuntimeError("roi arguments out of range");
|
||||
}
|
||||
pimpl->Parallel(&Module::setROI, {module_id}, value);
|
||||
pimpl->Parallel3(&Receiver::setROI, value);
|
||||
}
|
||||
|
||||
void Detector::clearROI(Positions pos) {
|
||||
pimpl->Parallel(&Module::clearROI, pos);
|
||||
pimpl->Parallel3(&Receiver::clearROI);
|
||||
}
|
||||
|
||||
Result<ns> Detector::getExptimeLeft(Positions pos) const {
|
||||
@ -1388,6 +1412,7 @@ Result<defs::burstMode> Detector::getBurstMode(Positions pos) {
|
||||
|
||||
void Detector::setBurstMode(defs::burstMode value, Positions pos) {
|
||||
pimpl->Parallel(&Module::setBurstMode, pos, value);
|
||||
pimpl->Parallel3(&Receiver::setBurstMode, value);
|
||||
}
|
||||
|
||||
Result<bool> Detector::getCurrentSource(Positions pos) const {
|
||||
@ -1502,7 +1527,11 @@ Result<uint32_t> Detector::getADCEnableMask(Positions pos) const {
|
||||
}
|
||||
|
||||
void Detector::setADCEnableMask(uint32_t mask, Positions pos) {
|
||||
if (getDetectorType().squash() == defs::MOENCH) {
|
||||
setAdditionalJsonParameter("adcmask_1g", std::to_string(mask), pos);
|
||||
}
|
||||
pimpl->Parallel(&Module::setADCEnableMask, pos, mask);
|
||||
pimpl->Parallel3(&Receiver::setADCEnableMask, mask);
|
||||
}
|
||||
|
||||
Result<uint32_t> Detector::getTenGigaADCEnableMask(Positions pos) const {
|
||||
@ -1510,7 +1539,11 @@ Result<uint32_t> Detector::getTenGigaADCEnableMask(Positions pos) const {
|
||||
}
|
||||
|
||||
void Detector::setTenGigaADCEnableMask(uint32_t mask, Positions pos) {
|
||||
if (getDetectorType().squash() == defs::MOENCH) {
|
||||
setAdditionalJsonParameter("adcmask_10g", std::to_string(mask), pos);
|
||||
}
|
||||
pimpl->Parallel(&Module::setTenGigaADCEnableMask, pos, mask);
|
||||
pimpl->Parallel3(&Receiver::setTenGigaADCEnableMask, mask);
|
||||
}
|
||||
|
||||
// CTB Specific
|
||||
@ -1603,19 +1636,19 @@ void Detector::setExternalSampling(bool value, Positions pos) {
|
||||
}
|
||||
|
||||
Result<std::vector<int>> Detector::getRxDbitList(Positions pos) const {
|
||||
return pimpl->Parallel(&Module::getReceiverDbitList, pos);
|
||||
return pimpl->Parallel3(&Receiver::getDbitList);
|
||||
}
|
||||
|
||||
void Detector::setRxDbitList(const std::vector<int>& list, Positions pos) {
|
||||
pimpl->Parallel(&Module::setReceiverDbitList, pos, list);
|
||||
pimpl->Parallel3(&Receiver::setDbitList, list);
|
||||
}
|
||||
|
||||
Result<int> Detector::getRxDbitOffset(Positions pos) const {
|
||||
return pimpl->Parallel(&Module::getReceiverDbitOffset, pos);
|
||||
return pimpl->Parallel3(&Receiver::getDbitOffset);
|
||||
}
|
||||
|
||||
void Detector::setRxDbitOffset(int value, Positions pos) {
|
||||
pimpl->Parallel(&Module::setReceiverDbitOffset, pos, value);
|
||||
pimpl->Parallel3(&Receiver::setDbitOffset, value);
|
||||
}
|
||||
|
||||
void Detector::setDigitalIODelay(uint64_t pinMask, int delay, Positions pos) {
|
||||
@ -1757,28 +1790,27 @@ void Detector::setPatternBitMask(uint64_t mask, Positions pos) {
|
||||
// Moench
|
||||
|
||||
Result<std::map<std::string, std::string>> Detector::getAdditionalJsonHeader(Positions pos) const {
|
||||
return pimpl->Parallel(&Module::getAdditionalJsonHeader, pos);
|
||||
return pimpl->Parallel3(&Receiver::getAdditionalJsonHeader);
|
||||
}
|
||||
|
||||
void Detector::setAdditionalJsonHeader(const std::map<std::string, std::string> &jsonHeader,
|
||||
Positions pos) {
|
||||
pimpl->Parallel(&Module::setAdditionalJsonHeader, pos, jsonHeader);
|
||||
pimpl->Parallel3(&Receiver::setAdditionalJsonHeader, jsonHeader);
|
||||
}
|
||||
|
||||
Result<std::string> Detector::getAdditionalJsonParameter(const std::string &key,
|
||||
Positions pos) const {
|
||||
return pimpl->Parallel(&Module::getAdditionalJsonParameter, pos, key);
|
||||
return pimpl->Parallel3(&Receiver::getAdditionalJsonParameter, key);
|
||||
}
|
||||
|
||||
void Detector::setAdditionalJsonParameter(const std::string &key, const std::string &value,
|
||||
Positions pos) {
|
||||
pimpl->Parallel(&Module::setAdditionalJsonParameter, pos, key, value);
|
||||
pimpl->Parallel3(&Receiver::setAdditionalJsonParameter, key, value);
|
||||
}
|
||||
|
||||
Result<int> Detector::getDetectorMinMaxEnergyThreshold(const bool isEmax,
|
||||
Positions pos) const {
|
||||
auto res = pimpl->Parallel(&Module::getAdditionalJsonParameter, pos,
|
||||
isEmax ? "emax" : "emin");
|
||||
auto res = getAdditionalJsonParameter(isEmax ? "emax" : "emin", pos);
|
||||
Result<int> intResult(res.size());
|
||||
try {
|
||||
for (unsigned int i = 0; i < res.size(); ++i) {
|
||||
@ -1794,13 +1826,12 @@ Result<int> Detector::getDetectorMinMaxEnergyThreshold(const bool isEmax,
|
||||
void Detector::setDetectorMinMaxEnergyThreshold(const bool isEmax,
|
||||
const int value,
|
||||
Positions pos) {
|
||||
pimpl->Parallel(&Module::setAdditionalJsonParameter, pos,
|
||||
isEmax ? "emax" : "emin", std::to_string(value));
|
||||
setAdditionalJsonParameter(isEmax ? "emax" : "emin",
|
||||
std::to_string(value), pos);
|
||||
}
|
||||
|
||||
Result<defs::frameModeType> Detector::getFrameMode(Positions pos) const {
|
||||
auto res = pimpl->Parallel(&Module::getAdditionalJsonParameter, pos,
|
||||
"frameMode");
|
||||
auto res = getAdditionalJsonParameter("frameMode", pos);
|
||||
Result<defs::frameModeType> intResult(res.size());
|
||||
try {
|
||||
for (unsigned int i = 0; i < res.size(); ++i) {
|
||||
@ -1815,13 +1846,11 @@ Result<defs::frameModeType> Detector::getFrameMode(Positions pos) const {
|
||||
}
|
||||
|
||||
void Detector::setFrameMode(defs::frameModeType value, Positions pos) {
|
||||
pimpl->Parallel(&Module::setAdditionalJsonParameter, pos, "frameMode",
|
||||
sls::ToString(value));
|
||||
setAdditionalJsonParameter("frameMode", sls::ToString(value), pos);
|
||||
}
|
||||
|
||||
Result<defs::detectorModeType> Detector::getDetectorMode(Positions pos) const {
|
||||
auto res = pimpl->Parallel(&Module::getAdditionalJsonParameter, pos,
|
||||
"detectorMode");
|
||||
auto res = getAdditionalJsonParameter("detectorMode", pos);
|
||||
Result<defs::detectorModeType> intResult(res.size());
|
||||
try {
|
||||
for (unsigned int i = 0; i < res.size(); ++i) {
|
||||
@ -1836,8 +1865,7 @@ Result<defs::detectorModeType> Detector::getDetectorMode(Positions pos) const {
|
||||
}
|
||||
|
||||
void Detector::setDetectorMode(defs::detectorModeType value, Positions pos) {
|
||||
pimpl->Parallel(&Module::setAdditionalJsonParameter, pos,
|
||||
"detectorMode", sls::ToString(value));
|
||||
setAdditionalJsonParameter("detectorMode", sls::ToString(value), pos);
|
||||
}
|
||||
|
||||
// Advanced
|
||||
|
@ -619,8 +619,8 @@ int DetectorImpl::createReceivingDataSockets(const bool destroy) {
|
||||
portnum += (iSocket % numSocketsPerDetector);
|
||||
try {
|
||||
zmqSocket.push_back(sls::make_unique<ZmqSocket>(
|
||||
detectors[iSocket / numSocketsPerDetector]
|
||||
->getClientStreamingIP()
|
||||
receivers[iSocket / numSocketsPerDetector][0]
|
||||
->getClientZmqIP()
|
||||
.str()
|
||||
.c_str(),
|
||||
portnum));
|
||||
|
@ -746,22 +746,6 @@ void Module::setSettings(detectorSettings isettings) {
|
||||
}
|
||||
|
||||
int Module::getThresholdEnergy() {
|
||||
// moench - get threshold energy from processor (due to different clients,
|
||||
// diff shm)
|
||||
if (shm()->myDetectorType == MOENCH) {
|
||||
// get json from rxr, parse for threshold and update shm
|
||||
getAdditionalJsonHeader();
|
||||
std::string result = getAdditionalJsonParameter("threshold");
|
||||
// convert to integer
|
||||
try {
|
||||
return std::stoi(result);
|
||||
}
|
||||
// not found or cannot scan integer
|
||||
catch (...) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
LOG(logDEBUG1) << "Getting threshold energy";
|
||||
int retval = -1;
|
||||
sendToDetector(F_GET_THRESHOLD_ENERGY, nullptr, retval);
|
||||
@ -771,18 +755,10 @@ int Module::getThresholdEnergy() {
|
||||
|
||||
void Module::setThresholdEnergy(int e_eV, detectorSettings isettings,
|
||||
int tb) {
|
||||
|
||||
// check as there is client processing
|
||||
if (shm()->myDetectorType == EIGER) {
|
||||
setThresholdEnergyAndSettings(e_eV, isettings, tb);
|
||||
}
|
||||
|
||||
// moench - send threshold energy to processor
|
||||
else if (shm()->myDetectorType == MOENCH) {
|
||||
setAdditionalJsonParameter("threshold", std::to_string(e_eV));
|
||||
}
|
||||
|
||||
else {
|
||||
} else {
|
||||
throw RuntimeError(
|
||||
"Set threshold energy not implemented for this detector");
|
||||
}
|
||||
@ -1077,10 +1053,6 @@ int64_t Module::getPeriod() {
|
||||
void Module::setPeriod(int64_t value) {
|
||||
LOG(logDEBUG1) << "Setting period to " << value << "ns";
|
||||
sendToDetector(F_SET_PERIOD, value, nullptr);
|
||||
if (shm()->useReceiver) {
|
||||
LOG(logDEBUG1) << "Sending period to Receiver: " << value;
|
||||
sendToReceiver(F_RECEIVER_SET_PERIOD, value, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
int64_t Module::getDelayAfterTrigger() {
|
||||
@ -1553,9 +1525,6 @@ void Module::setNumberofUDPInterfaces(int n) {
|
||||
LOG(logDEBUG1) << "Setting number of udp interfaces to " << n;
|
||||
sendToDetector(F_SET_NUM_INTERFACES, n, nullptr);
|
||||
shm()->numUDPInterfaces = n;
|
||||
if (shm()->useReceiver) {
|
||||
sendToReceiver(F_SET_RECEIVER_NUM_INTERFACES, n, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
int Module::getNumberofUDPInterfacesFromShm() {
|
||||
@ -1613,51 +1582,6 @@ std::string Module::printUDPConfiguration() {
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
void Module::setClientStreamingIP(const sls::IpAddr ip) {
|
||||
LOG(logDEBUG1) << "Setting client zmq ip to " << ip;
|
||||
if (ip == 0) {
|
||||
throw RuntimeError("Invalid client zmq ip address");
|
||||
}
|
||||
shm()->zmqip = ip;
|
||||
}
|
||||
|
||||
sls::IpAddr Module::getClientStreamingIP() { return shm()->zmqip; }
|
||||
|
||||
void Module::setReceiverStreamingIP(const sls::IpAddr ip) {
|
||||
if (!shm()->useReceiver) {
|
||||
throw RuntimeError("Set rx_hostname first to use receiver parameters (streaming ip)");
|
||||
}
|
||||
if (ip == 0) {
|
||||
throw RuntimeError("Invalid receiver zmq ip address");
|
||||
}
|
||||
|
||||
// if client zmqip is empty, update it
|
||||
if (shm()->zmqip == 0) {
|
||||
shm()->zmqip = ip;
|
||||
}
|
||||
sendToReceiver(F_SET_RECEIVER_STREAMING_SRC_IP, ip, nullptr);
|
||||
}
|
||||
|
||||
sls::IpAddr Module::getReceiverStreamingIP() {
|
||||
if (!shm()->useReceiver) {
|
||||
throw RuntimeError("Set rx_hostname first to use receiver parameters (streaming ip)");
|
||||
}
|
||||
return sendToReceiver<sls::IpAddr>(F_GET_RECEIVER_STREAMING_SRC_IP);
|
||||
}
|
||||
|
||||
void Module::updateReceiverStreamingIP() {
|
||||
auto ip = getReceiverStreamingIP();
|
||||
if (ip == 0) {
|
||||
// Hostname could be ip try to decode otherwise look up the hostname
|
||||
ip = sls::IpAddr{shm()->rxHostname};
|
||||
if (ip == 0) {
|
||||
ip = HostnameToIp(shm()->rxHostname);
|
||||
}
|
||||
LOG(logINFO) << "Setting default receiver " << moduleId << " streaming zmq ip to " << ip;
|
||||
}
|
||||
setReceiverStreamingIP(ip);
|
||||
}
|
||||
|
||||
bool Module::getTenGigaFlowControl() {
|
||||
int retval = -1;
|
||||
sendToDetector(F_GET_TEN_GIGA_FLOW_CONTROL, nullptr, retval);
|
||||
@ -1707,121 +1631,6 @@ void Module::setTransmissionDelayRight(int value) {
|
||||
sendToDetector(F_SET_TRANSMISSION_DELAY_RIGHT, value, nullptr);
|
||||
}
|
||||
|
||||
|
||||
void Module::setAdditionalJsonHeader(const std::map<std::string, std::string> &jsonHeader) {
|
||||
if (!shm()->useReceiver) {
|
||||
throw RuntimeError("Set rx_hostname first to use receiver parameters (zmq json header)");
|
||||
}
|
||||
for (auto &it : jsonHeader) {
|
||||
if (it.first.empty() || it.first.length() > SHORT_STR_LENGTH ||
|
||||
it.second.length() > SHORT_STR_LENGTH ) {
|
||||
throw RuntimeError(it.first + " or " + it.second + " pair has invalid size. "
|
||||
"Key cannot be empty. Both can have max 20 characters");
|
||||
}
|
||||
}
|
||||
const int size = jsonHeader.size();
|
||||
int fnum = F_SET_ADDITIONAL_JSON_HEADER;
|
||||
int ret = FAIL;
|
||||
LOG(logDEBUG) << "Sending to receiver additional json header " << ToString(jsonHeader);
|
||||
auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
|
||||
client.Send(&fnum, sizeof(fnum));
|
||||
client.Send(&size, sizeof(size));
|
||||
if (size > 0) {
|
||||
char args[size * 2][SHORT_STR_LENGTH];
|
||||
memset(args, 0, sizeof(args));
|
||||
int iarg = 0;
|
||||
for (auto &it : jsonHeader) {
|
||||
sls::strcpy_safe(args[iarg], it.first.c_str());
|
||||
sls::strcpy_safe(args[iarg + 1], it.second.c_str());
|
||||
iarg += 2;
|
||||
}
|
||||
client.Send(args, sizeof(args));
|
||||
}
|
||||
client.Receive(&ret, sizeof(ret));
|
||||
if (ret == FAIL) {
|
||||
char mess[MAX_STR_LENGTH]{};
|
||||
client.Receive(mess, MAX_STR_LENGTH);
|
||||
throw RuntimeError("Receiver " + std::to_string(moduleId) +
|
||||
" returned error: " + std::string(mess));
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> Module::getAdditionalJsonHeader() {
|
||||
if (!shm()->useReceiver) {
|
||||
throw RuntimeError("Set rx_hostname first to use receiver parameters (zmq json header)");
|
||||
}
|
||||
int fnum = F_GET_ADDITIONAL_JSON_HEADER;
|
||||
int ret = FAIL;
|
||||
int size = 0;
|
||||
auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
|
||||
client.Send(&fnum, sizeof(fnum));
|
||||
client.Receive(&ret, sizeof(ret));
|
||||
if (ret == FAIL) {
|
||||
char mess[MAX_STR_LENGTH]{};
|
||||
client.Receive(mess, MAX_STR_LENGTH);
|
||||
throw RuntimeError("Receiver " + std::to_string(moduleId) +
|
||||
" returned error: " + std::string(mess));
|
||||
} else {
|
||||
client.Receive(&size, sizeof(size));
|
||||
std::map<std::string, std::string> retval;
|
||||
if (size > 0) {
|
||||
char retvals[size * 2][SHORT_STR_LENGTH];
|
||||
memset(retvals, 0, sizeof(retvals));
|
||||
client.Receive(retvals, sizeof(retvals));
|
||||
for (int i = 0; i < size; ++i) {
|
||||
retval[retvals[2 * i]] = retvals[2 * i + 1];
|
||||
}
|
||||
}
|
||||
LOG(logDEBUG) << "Getting additional json header " << ToString(retval);
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
void Module::setAdditionalJsonParameter(const std::string &key, const std::string &value) {
|
||||
if (!shm()->useReceiver) {
|
||||
throw RuntimeError("Set rx_hostname first to use receiver parameters (zmq json parameter)");
|
||||
}
|
||||
if (key.empty() || key.length() > SHORT_STR_LENGTH ||
|
||||
value.length() > SHORT_STR_LENGTH ) {
|
||||
throw RuntimeError(key + " or " + value + " pair has invalid size. "
|
||||
"Key cannot be empty. Both can have max 2 characters");
|
||||
}
|
||||
char args[2][SHORT_STR_LENGTH]{};
|
||||
sls::strcpy_safe(args[0], key.c_str());
|
||||
sls::strcpy_safe(args[1], value.c_str());
|
||||
sendToReceiver(F_SET_ADDITIONAL_JSON_PARAMETER, args, nullptr);
|
||||
}
|
||||
|
||||
std::string Module::getAdditionalJsonParameter(const std::string &key) {
|
||||
if (!shm()->useReceiver) {
|
||||
throw RuntimeError("Set rx_hostname first to use receiver parameters (zmq json parameter)");
|
||||
}
|
||||
char arg[SHORT_STR_LENGTH]{};
|
||||
sls::strcpy_safe(arg, key.c_str());
|
||||
char retval[SHORT_STR_LENGTH]{};
|
||||
sendToReceiver(F_GET_ADDITIONAL_JSON_PARAMETER, arg, retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
int64_t Module::setReceiverUDPSocketBufferSize(int64_t udpsockbufsize) {
|
||||
LOG(logDEBUG1) << "Sending UDP Socket Buffer size to receiver: "
|
||||
<< udpsockbufsize;
|
||||
int64_t retval = -1;
|
||||
if (shm()->useReceiver) {
|
||||
sendToReceiver(F_RECEIVER_UDP_SOCK_BUF_SIZE, udpsockbufsize, retval);
|
||||
LOG(logDEBUG1) << "Receiver UDP Socket Buffer size: " << retval;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
int64_t Module::getReceiverUDPSocketBufferSize() {
|
||||
return setReceiverUDPSocketBufferSize();
|
||||
}
|
||||
|
||||
int64_t Module::getReceiverRealUDPSocketBufferSize() const {
|
||||
return sendToReceiver<int64_t>(F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE);
|
||||
}
|
||||
|
||||
void Module::executeFirmwareTest() {
|
||||
LOG(logDEBUG1) << "Executing firmware test";
|
||||
sendToDetector(F_SET_FIRMWARE_TEST);
|
||||
@ -1984,10 +1793,6 @@ void Module::setBurstMode(slsDetectorDefs::burstMode value) {
|
||||
int arg = static_cast<int>(value);
|
||||
LOG(logDEBUG1) << "Setting burst mode to " << arg;
|
||||
sendToDetector(F_SET_BURST_MODE, arg, nullptr);
|
||||
if (shm()->useReceiver) {
|
||||
LOG(logDEBUG1) << "Sending burst mode to Receiver: " << value;
|
||||
sendToReceiver(F_SET_RECEIVER_BURST_MODE, value, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
bool Module::getCurrentSource() {
|
||||
@ -2033,18 +1838,10 @@ void Module::clearROI() {
|
||||
}
|
||||
|
||||
void Module::setROI(slsDetectorDefs::ROI arg) {
|
||||
if (arg.xmin < 0 || arg.xmax >= getNumberOfChannels().x) {
|
||||
arg.xmin = -1;
|
||||
arg.xmax = -1;
|
||||
}
|
||||
std::array<int, 2> args{arg.xmin, arg.xmax};
|
||||
LOG(logDEBUG) << "Sending ROI to detector [" << arg.xmin << ", "
|
||||
<< arg.xmax << "]";
|
||||
sendToDetector(F_SET_ROI, args, nullptr);
|
||||
if (shm()->useReceiver) {
|
||||
LOG(logDEBUG1) << "Sending ROI to receiver";
|
||||
sendToReceiver(F_RECEIVER_SET_ROI, arg, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
slsDetectorDefs::ROI Module::getROI() {
|
||||
@ -2066,18 +1863,6 @@ void Module::setADCEnableMask(uint32_t mask) {
|
||||
|
||||
// update #nchan, as it depends on #samples, adcmask,
|
||||
updateNumberOfChannels();
|
||||
|
||||
// send to processor
|
||||
if (shm()->myDetectorType == MOENCH)
|
||||
setAdditionalJsonParameter("adcmask_1g", std::to_string(mask));
|
||||
|
||||
if (shm()->useReceiver) {
|
||||
int fnum = F_RECEIVER_SET_ADC_MASK;
|
||||
int retval = -1;
|
||||
LOG(logDEBUG1) << "Setting ADC Enable mask to 0x" << std::hex
|
||||
<< mask << std::dec << " in receiver";
|
||||
sendToReceiver(fnum, mask, retval);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Module::getADCEnableMask() {
|
||||
@ -2096,18 +1881,6 @@ void Module::setTenGigaADCEnableMask(uint32_t mask) {
|
||||
|
||||
// update #nchan, as it depends on #samples, adcmask,
|
||||
updateNumberOfChannels();
|
||||
|
||||
// send to processor
|
||||
if (shm()->myDetectorType == MOENCH)
|
||||
setAdditionalJsonParameter("adcmask_10g", std::to_string(mask));
|
||||
|
||||
if (shm()->useReceiver) {
|
||||
int fnum = F_RECEIVER_SET_ADC_MASK_10G;
|
||||
int retval = -1;
|
||||
LOG(logDEBUG1) << "Setting 10Gb ADC Enable mask to 0x" << std::hex
|
||||
<< mask << std::dec << " in receiver";
|
||||
sendToReceiver(fnum, mask, retval);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Module::getTenGigaADCEnableMask() {
|
||||
@ -2156,49 +1929,6 @@ int Module::setExternalSampling(int value) {
|
||||
|
||||
int Module::getExternalSampling() { return setExternalSampling(-1); }
|
||||
|
||||
void Module::setReceiverDbitList(const std::vector<int>& list) {
|
||||
if (!shm()->useReceiver) {
|
||||
throw RuntimeError("Set rx_hostname first to use receiver parameters (dbit list)");
|
||||
}
|
||||
|
||||
LOG(logDEBUG1) << "Setting Receiver Dbit List";
|
||||
|
||||
if (list.size() > 64) {
|
||||
throw sls::RuntimeError("Dbit list size cannot be greater than 64\n");
|
||||
}
|
||||
for (auto &it : list) {
|
||||
if (it < 0 || it > 63) {
|
||||
throw sls::RuntimeError(
|
||||
"Dbit list value must be between 0 and 63\n");
|
||||
}
|
||||
}
|
||||
sls::FixedCapacityContainer<int, MAX_RX_DBIT> arg = list;
|
||||
sendToReceiver(F_SET_RECEIVER_DBIT_LIST, arg, nullptr);
|
||||
}
|
||||
|
||||
std::vector<int> Module::getReceiverDbitList() const {
|
||||
if (!shm()->useReceiver) {
|
||||
throw RuntimeError("Set rx_hostname first to use receiver parameters (dbit list)");
|
||||
}
|
||||
sls::FixedCapacityContainer<int, MAX_RX_DBIT> retval;
|
||||
sendToReceiver(F_GET_RECEIVER_DBIT_LIST, nullptr, retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
void Module::setReceiverDbitOffset(int value) {
|
||||
if (!shm()->useReceiver) {
|
||||
throw RuntimeError("Set rx_hostname first to use receiver parameters (dbit offset)");
|
||||
}
|
||||
sendToReceiver(F_SET_RECEIVER_DBIT_OFFSET, value, nullptr);
|
||||
}
|
||||
|
||||
int Module::getReceiverDbitOffset() {
|
||||
if (!shm()->useReceiver) {
|
||||
throw RuntimeError("Set rx_hostname first to use receiver parameters (dbit offset)");
|
||||
}
|
||||
return sendToReceiver<int>(F_GET_RECEIVER_DBIT_OFFSET);
|
||||
}
|
||||
|
||||
void Module::writeAdcRegister(uint32_t addr, uint32_t val) {
|
||||
uint32_t args[]{addr, val};
|
||||
LOG(logDEBUG1) << "Writing to ADC register 0x" << std::hex << addr
|
||||
@ -2206,18 +1936,22 @@ void Module::writeAdcRegister(uint32_t addr, uint32_t val) {
|
||||
sendToDetector(F_WRITE_ADC_REG, args, nullptr);
|
||||
}
|
||||
|
||||
int Module::activate(int enable) {
|
||||
int retval = -1;
|
||||
LOG(logDEBUG1) << "Setting activate flag to " << enable;
|
||||
sendToDetector(F_ACTIVATE, enable, retval);
|
||||
sendToDetectorStop(F_ACTIVATE, enable, retval);
|
||||
bool Module::getActivate() {
|
||||
int retval = -1, arg = -1;
|
||||
LOG(logDEBUG1) << "Getting activate flag";
|
||||
sendToDetector(F_ACTIVATE, arg, retval);
|
||||
LOG(logDEBUG1) << "Activate: " << retval;
|
||||
if (shm()->useReceiver) {
|
||||
sendToReceiver(F_RECEIVER_ACTIVATE, retval, nullptr);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
void Module::setActivate(const bool enable) {
|
||||
int retval = -1;
|
||||
int arg = static_cast<int>(enable);
|
||||
LOG(logDEBUG1) << "Setting activate flag to " << arg;
|
||||
sendToDetector(F_ACTIVATE, arg, retval);
|
||||
sendToDetectorStop(F_ACTIVATE, arg, retval);
|
||||
}
|
||||
|
||||
bool Module::getDeactivatedRxrPaddingMode() {
|
||||
if (!shm()->useReceiver) {
|
||||
throw RuntimeError("Set rx_hostname first to use receiver parameters (deactivated padding)");
|
||||
|
@ -792,30 +792,6 @@ class Module : public virtual slsDetectorDefs {
|
||||
|
||||
std::string printUDPConfiguration();
|
||||
|
||||
/**
|
||||
* Sets the client zmq ip
|
||||
* @param ip client zmq ip
|
||||
*/
|
||||
void setClientStreamingIP(const sls::IpAddr ip);
|
||||
|
||||
/**
|
||||
* Returns the client zmq ip
|
||||
* @returns the client zmq ip
|
||||
*/
|
||||
sls::IpAddr getClientStreamingIP();
|
||||
|
||||
/**
|
||||
* Sets the receiver zmq ip
|
||||
* @param ip receiver zmq ip
|
||||
*/
|
||||
void setReceiverStreamingIP(const sls::IpAddr ip);
|
||||
|
||||
/**
|
||||
* Returns the receiver zmq ip
|
||||
* @returns the receiver zmq ip
|
||||
*/
|
||||
sls::IpAddr getReceiverStreamingIP();
|
||||
|
||||
/** update receiver stremaing ip from shm to receiver
|
||||
* if empty, use rx_hostname ip
|
||||
*/
|
||||
@ -858,35 +834,6 @@ class Module : public virtual slsDetectorDefs {
|
||||
*/
|
||||
void setTransmissionDelayRight(int value);
|
||||
|
||||
/** empty vector deletes entire additional json header */
|
||||
void setAdditionalJsonHeader(const std::map<std::string, std::string> &jsonHeader);
|
||||
std::map<std::string, std::string> getAdditionalJsonHeader();
|
||||
|
||||
/**
|
||||
* Sets the value for the additional json header parameter key if found, else
|
||||
* append it. If value empty, then deletes parameter */
|
||||
void setAdditionalJsonParameter(const std::string &key, const std::string &value);
|
||||
std::string getAdditionalJsonParameter(const std::string &key);
|
||||
|
||||
/**
|
||||
* Sets the receiver UDP socket buffer size
|
||||
* @param udpsockbufsize additional json header
|
||||
* @returns receiver udp socket buffer size
|
||||
*/
|
||||
int64_t setReceiverUDPSocketBufferSize(int64_t udpsockbufsize = -1);
|
||||
|
||||
/**
|
||||
* Returns the receiver UDP socket buffer size
|
||||
* @returns the receiver UDP socket buffer size
|
||||
*/
|
||||
int64_t getReceiverUDPSocketBufferSize();
|
||||
|
||||
/**
|
||||
* Returns the receiver real UDP socket buffer size
|
||||
* @returns the receiver real UDP socket buffer size
|
||||
*/
|
||||
int64_t getReceiverRealUDPSocketBufferSize() const;
|
||||
|
||||
/** [Gotthard][Jungfrau][CTB][Moench] */
|
||||
void executeFirmwareTest();
|
||||
|
||||
@ -964,28 +911,10 @@ class Module : public virtual slsDetectorDefs {
|
||||
*/
|
||||
slsDetectorDefs::ROI getROI();
|
||||
|
||||
/**
|
||||
* Set ADC Enable Mask (CTB, Moench)
|
||||
* @param mask ADC Enable mask
|
||||
*/
|
||||
|
||||
void setADCEnableMask(uint32_t mask);
|
||||
|
||||
/**
|
||||
* Get ADC Enable Mask (CTB, Moench)
|
||||
* @returns ADC Enable mask
|
||||
*/
|
||||
uint32_t getADCEnableMask();
|
||||
|
||||
/**
|
||||
* Set 10Gb ADC Enable Mask (CTB, Moench)
|
||||
* @param mask ADC Enable mask
|
||||
*/
|
||||
void setTenGigaADCEnableMask(uint32_t mask);
|
||||
|
||||
/**
|
||||
* Get 10Gb ADC Enable Mask (CTB, Moench)
|
||||
* @returns ADC Enable mask
|
||||
*/
|
||||
uint32_t getTenGigaADCEnableMask();
|
||||
|
||||
/**
|
||||
@ -1032,14 +961,6 @@ class Module : public virtual slsDetectorDefs {
|
||||
*/
|
||||
int getExternalSampling();
|
||||
|
||||
/** digital data bits enable (CTB only) */
|
||||
void setReceiverDbitList(const std::vector<int>& list);
|
||||
std::vector<int> getReceiverDbitList() const;
|
||||
|
||||
/** Set digital data offset in bytes (CTB only) */
|
||||
void setReceiverDbitOffset(int value);
|
||||
int getReceiverDbitOffset();
|
||||
|
||||
/**
|
||||
* Write to ADC register (Gotthard, Jungfrau, ChipTestBoard). For expert
|
||||
* users
|
||||
@ -1048,12 +969,10 @@ class Module : public virtual slsDetectorDefs {
|
||||
*/
|
||||
void writeAdcRegister(uint32_t addr, uint32_t val);
|
||||
|
||||
/**
|
||||
* Activates/Deactivates the detector (Eiger only)
|
||||
* @param enable active (1) or inactive (0), -1 gets
|
||||
* @returns 0 (inactive) or 1 (active)for activate mode
|
||||
*/
|
||||
int activate(int const enable = -1);
|
||||
/** [Eiger] */
|
||||
bool getActivate();
|
||||
/** [Eiger] */
|
||||
void setActivate(const bool enable);
|
||||
|
||||
bool getDeactivatedRxrPaddingMode();
|
||||
|
||||
|
@ -1,105 +1,12 @@
|
||||
#include "Receiver.h"
|
||||
#include "ClientSocket.h"
|
||||
#include "FixedCapacityContainer.h"
|
||||
#include "string_utils.h"
|
||||
#include "versionAPI.h"
|
||||
#include "ToString.h"
|
||||
|
||||
namespace sls {
|
||||
|
||||
void Receiver::sendToReceiver(int fnum, const void *args, size_t args_size,
|
||||
void *retval, size_t retval_size) {
|
||||
static_cast<const Receiver &>(*this).sendToReceiver(
|
||||
fnum, args, args_size, retval, retval_size);
|
||||
}
|
||||
|
||||
void Receiver::sendToReceiver(int fnum, const void *args, size_t args_size,
|
||||
void *retval, size_t retval_size) const {
|
||||
if (strlen(shm()->hostname) == 0) {
|
||||
throw RuntimeError("Reciver not added");
|
||||
}
|
||||
auto receiver = ReceiverSocket(shm()->hostname, shm()->tcpPort);
|
||||
receiver.sendCommandThenRead(fnum, args, args_size, retval, retval_size);
|
||||
receiver.close();
|
||||
}
|
||||
|
||||
template <typename Arg, typename Ret>
|
||||
void Receiver::sendToReceiver(int fnum, const Arg &args, Ret &retval) {
|
||||
sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval));
|
||||
}
|
||||
|
||||
template <typename Arg, typename Ret>
|
||||
void Receiver::sendToReceiver(int fnum, const Arg &args, Ret &retval) const {
|
||||
sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval));
|
||||
}
|
||||
|
||||
template <typename Arg>
|
||||
void Receiver::sendToReceiver(int fnum, const Arg &args, std::nullptr_t) {
|
||||
sendToReceiver(fnum, &args, sizeof(args), nullptr, 0);
|
||||
}
|
||||
|
||||
template <typename Arg>
|
||||
void Receiver::sendToReceiver(int fnum, const Arg &args,
|
||||
std::nullptr_t) const {
|
||||
sendToReceiver(fnum, &args, sizeof(args), nullptr, 0);
|
||||
}
|
||||
|
||||
template <typename Ret>
|
||||
void Receiver::sendToReceiver(int fnum, std::nullptr_t, Ret &retval) {
|
||||
sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval));
|
||||
}
|
||||
|
||||
template <typename Ret>
|
||||
void Receiver::sendToReceiver(int fnum, std::nullptr_t, Ret &retval) const {
|
||||
sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval));
|
||||
}
|
||||
|
||||
template <typename Ret>
|
||||
Ret Receiver::sendToReceiver(int fnum){
|
||||
LOG(logDEBUG1) << "Sending: ["
|
||||
<< getFunctionNameFromEnum(static_cast<slsDetectorDefs::detFuncs>(fnum))
|
||||
<< ", nullptr, 0, " << typeid(Ret).name() << ", " << sizeof(Ret) << "]";
|
||||
Ret retval{};
|
||||
sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval));
|
||||
LOG(logDEBUG1) << "Got back: " << retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
template <typename Ret>
|
||||
Ret Receiver::sendToReceiver(int fnum) const{
|
||||
LOG(logDEBUG1) << "Sending: ["
|
||||
<< getFunctionNameFromEnum(static_cast<slsDetectorDefs::detFuncs>(fnum))
|
||||
<< ", nullptr, 0, " << typeid(Ret).name() << ", " << sizeof(Ret) << "]";
|
||||
Ret retval{};
|
||||
sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval));
|
||||
LOG(logDEBUG1) << "Got back: " << retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
template <typename Ret, typename Arg>
|
||||
Ret Receiver::sendToReceiver(int fnum, const Arg &args){
|
||||
LOG(logDEBUG1) << "Sending: ["
|
||||
<< getFunctionNameFromEnum(static_cast<slsDetectorDefs::detFuncs>(fnum))
|
||||
<< ", " << args << ", " << sizeof(args) << ", " << typeid(Ret).name()
|
||||
<< ", " << sizeof(Ret) << "]";
|
||||
Ret retval{};
|
||||
sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval));
|
||||
LOG(logDEBUG1) << "Got back: " << retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
template <typename Ret, typename Arg>
|
||||
Ret Receiver::sendToReceiver(int fnum, const Arg &args) const{
|
||||
LOG(logDEBUG1) << "Sending: ["
|
||||
<< getFunctionNameFromEnum(static_cast<slsDetectorDefs::detFuncs>(fnum))
|
||||
<< ", " << args << ", " << sizeof(args) << ", " << typeid(Ret).name()
|
||||
<< ", " << sizeof(Ret) << "]";
|
||||
Ret retval{};
|
||||
sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval));
|
||||
LOG(logDEBUG1) << "Got back: " << retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
// create shm
|
||||
Receiver::Receiver(int detector_id, int module_id, int interface_id,
|
||||
int receiver_id, int tcp_port, std::string hostname,
|
||||
@ -377,25 +284,70 @@ void Receiver::setUDPPort(const int port) {
|
||||
}
|
||||
|
||||
/** ZMQ Streaming Parameters (Receiver<->Client) */
|
||||
void Receiver::setClientZmqPort(const int port) {
|
||||
shm()->zmqPort = port;
|
||||
}
|
||||
|
||||
int Receiver::getClientZmqPort() const {
|
||||
return shm()->zmqPort;
|
||||
}
|
||||
|
||||
void Receiver::setReceiverZmqPort(int port) {
|
||||
sendToReceiver(F_SET_RECEIVER_STREAMING_PORT, port, nullptr);
|
||||
void Receiver::setClientZmqPort(const int port) {
|
||||
shm()->zmqPort = port;
|
||||
}
|
||||
|
||||
int Receiver::getReceiverZmqPort() const {
|
||||
int Receiver::getZmqPort() const {
|
||||
return sendToReceiver<int>(F_GET_RECEIVER_STREAMING_PORT);
|
||||
}
|
||||
|
||||
void Receiver::setZmqPort(int port) {
|
||||
sendToReceiver(F_SET_RECEIVER_STREAMING_PORT, port, nullptr);
|
||||
}
|
||||
|
||||
|
||||
sls::IpAddr Receiver::getClientZmqIP() {
|
||||
return shm()->zmqIp;
|
||||
}
|
||||
|
||||
void Receiver::setClientZmqIP(const sls::IpAddr ip) {
|
||||
LOG(logDEBUG1) << "Setting client zmq ip to " << ip;
|
||||
if (ip == 0) {
|
||||
throw RuntimeError("Invalid client zmq ip address");
|
||||
}
|
||||
shm()->zmqIp = ip;
|
||||
}
|
||||
|
||||
sls::IpAddr Receiver::getZmqIP() {
|
||||
return sendToReceiver<sls::IpAddr>(F_GET_RECEIVER_STREAMING_SRC_IP);
|
||||
}
|
||||
|
||||
void Receiver::setZmqIP(const sls::IpAddr ip) {
|
||||
if (ip == 0) {
|
||||
throw RuntimeError("Invalid receiver zmq ip address");
|
||||
}
|
||||
|
||||
// if client zmqip is empty, update it
|
||||
if (shm()->zmqIp == 0) {
|
||||
shm()->zmqIp = ip;
|
||||
}
|
||||
sendToReceiver(F_SET_RECEIVER_STREAMING_SRC_IP, ip, nullptr);
|
||||
}
|
||||
|
||||
/** Receiver Parameters */
|
||||
|
||||
int64_t Receiver::getUDPSocketBufferSize() const {
|
||||
return sendToReceiver<int64_t>(F_GET_RECEIVER_UDP_SOCK_BUF_SIZE);
|
||||
}
|
||||
|
||||
void Receiver::setUDPSocketBufferSize(int64_t value) {
|
||||
LOG(logDEBUG1) << "Sending UDP Socket Buffer size to receiver: "
|
||||
<< value;
|
||||
sendToReceiver(F_SET_RECEIVER_UDP_SOCK_BUF_SIZE, value, nullptr);
|
||||
}
|
||||
|
||||
int64_t Receiver::getRealUDPSocketBufferSize() const {
|
||||
return sendToReceiver<int64_t>(F_GET_RECEIVER_REAL_UDP_SOCK_BUF_SIZE);
|
||||
}
|
||||
|
||||
|
||||
/** Detector Parameters */
|
||||
|
||||
void Receiver::setNumberOfFrames(int64_t value) {
|
||||
LOG(logDEBUG1) << "Sending number of frames to Receiver: " << value;
|
||||
sendToReceiver(F_RECEIVER_SET_NUM_FRAMES, value, nullptr);
|
||||
@ -426,6 +378,11 @@ void Receiver::setExptime(int64_t value) {
|
||||
sendToReceiver(F_RECEIVER_SET_EXPTIME, value, nullptr);
|
||||
}
|
||||
|
||||
void Receiver::setPeriod(int64_t value) {
|
||||
LOG(logDEBUG1) << "Sending period to Receiver: " << value;
|
||||
sendToReceiver(F_RECEIVER_SET_PERIOD, value, nullptr);
|
||||
}
|
||||
|
||||
void Receiver::setSubExptime(int64_t value) {
|
||||
LOG(logDEBUG1) << "Sending sub exptime to Receiver: " << value;
|
||||
sendToReceiver(F_RECEIVER_SET_SUB_EXPTIME, value, nullptr);
|
||||
@ -463,6 +420,95 @@ void Receiver::setReadNLines(const int value) {
|
||||
sendToReceiver(F_SET_RECEIVER_READ_N_LINES, value, nullptr);
|
||||
}
|
||||
|
||||
void Receiver::setADCEnableMask(uint32_t mask) {
|
||||
sendToReceiver(F_RECEIVER_SET_ADC_MASK, mask, nullptr);
|
||||
}
|
||||
|
||||
void Receiver::setTenGigaADCEnableMask(uint32_t mask) {
|
||||
sendToReceiver(F_RECEIVER_SET_ADC_MASK_10G, mask, nullptr);
|
||||
}
|
||||
|
||||
void Receiver::setBurstMode(slsDetectorDefs::burstMode value) {
|
||||
LOG(logDEBUG1) << "Sending burst mode to Receiver: " << value;
|
||||
sendToReceiver(F_SET_RECEIVER_BURST_MODE, value, nullptr);
|
||||
}
|
||||
|
||||
void Receiver::setROI(slsDetectorDefs::ROI arg) {
|
||||
std::array<int, 2> args{arg.xmin, arg.xmax};
|
||||
LOG(logDEBUG1) << "Sending ROI to receiver";
|
||||
sendToReceiver(F_RECEIVER_SET_ROI, args, nullptr);
|
||||
}
|
||||
|
||||
void Receiver::clearROI() {
|
||||
LOG(logDEBUG1) << "Clearing ROI";
|
||||
slsDetectorDefs::ROI arg;
|
||||
arg.xmin = -1;
|
||||
arg.xmax = -1;
|
||||
setROI(arg);
|
||||
}
|
||||
|
||||
std::vector<int> Receiver::getDbitList() const {
|
||||
sls::FixedCapacityContainer<int, MAX_RX_DBIT> retval;
|
||||
sendToReceiver(F_GET_RECEIVER_DBIT_LIST, nullptr, retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
void Receiver::setDbitList(const std::vector<int>& list) {
|
||||
LOG(logDEBUG1) << "Setting Receiver Dbit List";
|
||||
if (list.size() > 64) {
|
||||
throw sls::RuntimeError("Dbit list size cannot be greater than 64\n");
|
||||
}
|
||||
for (auto &it : list) {
|
||||
if (it < 0 || it > 63) {
|
||||
throw sls::RuntimeError(
|
||||
"Dbit list value must be between 0 and 63\n");
|
||||
}
|
||||
}
|
||||
sls::FixedCapacityContainer<int, MAX_RX_DBIT> arg = list;
|
||||
sendToReceiver(F_SET_RECEIVER_DBIT_LIST, arg, nullptr);
|
||||
}
|
||||
|
||||
int Receiver::getDbitOffset() {
|
||||
return sendToReceiver<int>(F_GET_RECEIVER_DBIT_OFFSET);
|
||||
}
|
||||
|
||||
void Receiver::setDbitOffset(int value) {
|
||||
sendToReceiver(F_SET_RECEIVER_DBIT_OFFSET, value, nullptr);
|
||||
}
|
||||
|
||||
void Receiver::setActivate(const bool enable) {
|
||||
int arg = static_cast<int>(enable);
|
||||
sendToReceiver(F_RECEIVER_ACTIVATE, arg, nullptr);
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> Receiver::getAdditionalJsonHeader() {
|
||||
int fnum = F_GET_ADDITIONAL_JSON_HEADER;
|
||||
int ret = FAIL;
|
||||
int size = 0;
|
||||
auto client = ReceiverSocket(shm()->hostname, shm()->tcpPort);
|
||||
client.Send(&fnum, sizeof(fnum));
|
||||
client.Receive(&ret, sizeof(ret));
|
||||
if (ret == FAIL) {
|
||||
char mess[MAX_STR_LENGTH]{};
|
||||
client.Receive(mess, MAX_STR_LENGTH);
|
||||
throw RuntimeError("Receiver " + std::to_string(moduleId) +
|
||||
" returned error: " + std::string(mess));
|
||||
} else {
|
||||
client.Receive(&size, sizeof(size));
|
||||
std::map<std::string, std::string> retval;
|
||||
if (size > 0) {
|
||||
char retvals[size * 2][SHORT_STR_LENGTH];
|
||||
memset(retvals, 0, sizeof(retvals));
|
||||
client.Receive(retvals, sizeof(retvals));
|
||||
for (int i = 0; i < size; ++i) {
|
||||
retval[retvals[2 * i]] = retvals[2 * i + 1];
|
||||
}
|
||||
}
|
||||
LOG(logDEBUG) << "Getting additional json header " << ToString(retval);
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
|
||||
void Receiver::setAdditionalJsonHeader(const std::map<std::string, std::string> &jsonHeader) {
|
||||
for (auto &it : jsonHeader) {
|
||||
if (it.first.empty() || it.first.length() > SHORT_STR_LENGTH ||
|
||||
@ -498,32 +544,12 @@ void Receiver::setAdditionalJsonHeader(const std::map<std::string, std::string>
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> Receiver::getAdditionalJsonHeader() {
|
||||
int fnum = F_GET_ADDITIONAL_JSON_HEADER;
|
||||
int ret = FAIL;
|
||||
int size = 0;
|
||||
auto client = ReceiverSocket(shm()->hostname, shm()->tcpPort);
|
||||
client.Send(&fnum, sizeof(fnum));
|
||||
client.Receive(&ret, sizeof(ret));
|
||||
if (ret == FAIL) {
|
||||
char mess[MAX_STR_LENGTH]{};
|
||||
client.Receive(mess, MAX_STR_LENGTH);
|
||||
throw RuntimeError("Receiver " + std::to_string(moduleId) +
|
||||
" returned error: " + std::string(mess));
|
||||
} else {
|
||||
client.Receive(&size, sizeof(size));
|
||||
std::map<std::string, std::string> retval;
|
||||
if (size > 0) {
|
||||
char retvals[size * 2][SHORT_STR_LENGTH];
|
||||
memset(retvals, 0, sizeof(retvals));
|
||||
client.Receive(retvals, sizeof(retvals));
|
||||
for (int i = 0; i < size; ++i) {
|
||||
retval[retvals[2 * i]] = retvals[2 * i + 1];
|
||||
}
|
||||
}
|
||||
LOG(logDEBUG) << "Getting additional json header " << ToString(retval);
|
||||
return retval;
|
||||
}
|
||||
std::string Receiver::getAdditionalJsonParameter(const std::string &key) {
|
||||
char arg[SHORT_STR_LENGTH]{};
|
||||
sls::strcpy_safe(arg, key.c_str());
|
||||
char retval[SHORT_STR_LENGTH]{};
|
||||
sendToReceiver(F_GET_ADDITIONAL_JSON_PARAMETER, arg, retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
void Receiver::setAdditionalJsonParameter(const std::string &key, const std::string &value) {
|
||||
@ -538,11 +564,97 @@ void Receiver::setAdditionalJsonParameter(const std::string &key, const std::str
|
||||
sendToReceiver(F_SET_ADDITIONAL_JSON_PARAMETER, args, nullptr);
|
||||
}
|
||||
|
||||
std::string Receiver::getAdditionalJsonParameter(const std::string &key) {
|
||||
char arg[SHORT_STR_LENGTH]{};
|
||||
sls::strcpy_safe(arg, key.c_str());
|
||||
char retval[SHORT_STR_LENGTH]{};
|
||||
sendToReceiver(F_GET_ADDITIONAL_JSON_PARAMETER, arg, retval);
|
||||
|
||||
void Receiver::sendToReceiver(int fnum, const void *args, size_t args_size,
|
||||
void *retval, size_t retval_size) {
|
||||
static_cast<const Receiver &>(*this).sendToReceiver(
|
||||
fnum, args, args_size, retval, retval_size);
|
||||
}
|
||||
|
||||
void Receiver::sendToReceiver(int fnum, const void *args, size_t args_size,
|
||||
void *retval, size_t retval_size) const {
|
||||
if (strlen(shm()->hostname) == 0) {
|
||||
throw RuntimeError("Reciver not added");
|
||||
}
|
||||
auto receiver = ReceiverSocket(shm()->hostname, shm()->tcpPort);
|
||||
receiver.sendCommandThenRead(fnum, args, args_size, retval, retval_size);
|
||||
receiver.close();
|
||||
}
|
||||
|
||||
template <typename Arg, typename Ret>
|
||||
void Receiver::sendToReceiver(int fnum, const Arg &args, Ret &retval) {
|
||||
sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval));
|
||||
}
|
||||
|
||||
template <typename Arg, typename Ret>
|
||||
void Receiver::sendToReceiver(int fnum, const Arg &args, Ret &retval) const {
|
||||
sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval));
|
||||
}
|
||||
|
||||
template <typename Arg>
|
||||
void Receiver::sendToReceiver(int fnum, const Arg &args, std::nullptr_t) {
|
||||
sendToReceiver(fnum, &args, sizeof(args), nullptr, 0);
|
||||
}
|
||||
|
||||
template <typename Arg>
|
||||
void Receiver::sendToReceiver(int fnum, const Arg &args,
|
||||
std::nullptr_t) const {
|
||||
sendToReceiver(fnum, &args, sizeof(args), nullptr, 0);
|
||||
}
|
||||
|
||||
template <typename Ret>
|
||||
void Receiver::sendToReceiver(int fnum, std::nullptr_t, Ret &retval) {
|
||||
sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval));
|
||||
}
|
||||
|
||||
template <typename Ret>
|
||||
void Receiver::sendToReceiver(int fnum, std::nullptr_t, Ret &retval) const {
|
||||
sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval));
|
||||
}
|
||||
|
||||
template <typename Ret>
|
||||
Ret Receiver::sendToReceiver(int fnum){
|
||||
LOG(logDEBUG1) << "Sending: ["
|
||||
<< getFunctionNameFromEnum(static_cast<slsDetectorDefs::detFuncs>(fnum))
|
||||
<< ", nullptr, 0, " << typeid(Ret).name() << ", " << sizeof(Ret) << "]";
|
||||
Ret retval{};
|
||||
sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval));
|
||||
LOG(logDEBUG1) << "Got back: " << retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
template <typename Ret>
|
||||
Ret Receiver::sendToReceiver(int fnum) const{
|
||||
LOG(logDEBUG1) << "Sending: ["
|
||||
<< getFunctionNameFromEnum(static_cast<slsDetectorDefs::detFuncs>(fnum))
|
||||
<< ", nullptr, 0, " << typeid(Ret).name() << ", " << sizeof(Ret) << "]";
|
||||
Ret retval{};
|
||||
sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval));
|
||||
LOG(logDEBUG1) << "Got back: " << retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
template <typename Ret, typename Arg>
|
||||
Ret Receiver::sendToReceiver(int fnum, const Arg &args){
|
||||
LOG(logDEBUG1) << "Sending: ["
|
||||
<< getFunctionNameFromEnum(static_cast<slsDetectorDefs::detFuncs>(fnum))
|
||||
<< ", " << args << ", " << sizeof(args) << ", " << typeid(Ret).name()
|
||||
<< ", " << sizeof(Ret) << "]";
|
||||
Ret retval{};
|
||||
sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval));
|
||||
LOG(logDEBUG1) << "Got back: " << retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
template <typename Ret, typename Arg>
|
||||
Ret Receiver::sendToReceiver(int fnum, const Arg &args) const{
|
||||
LOG(logDEBUG1) << "Sending: ["
|
||||
<< getFunctionNameFromEnum(static_cast<slsDetectorDefs::detFuncs>(fnum))
|
||||
<< ", " << args << ", " << sizeof(args) << ", " << typeid(Ret).name()
|
||||
<< ", " << sizeof(Ret) << "]";
|
||||
Ret retval{};
|
||||
sendToReceiver(fnum, &args, sizeof(args), &retval, sizeof(retval));
|
||||
LOG(logDEBUG1) << "Got back: " << retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -86,9 +86,21 @@ class Receiver : public virtual slsDetectorDefs {
|
||||
* ************************************************/
|
||||
int getClientZmqPort() const;
|
||||
void setClientZmqPort(const int port);
|
||||
int getReceiverZmqPort() const;
|
||||
void setReceiverZmqPort(int port);
|
||||
int getZmqPort() const;
|
||||
void setZmqPort(int port);
|
||||
sls::IpAddr getClientZmqIP();
|
||||
void setClientZmqIP(const sls::IpAddr ip);
|
||||
sls::IpAddr getZmqIP();
|
||||
void setZmqIP(const sls::IpAddr ip);
|
||||
|
||||
/**************************************************
|
||||
* *
|
||||
* Receiver Parameters *
|
||||
* *
|
||||
* ************************************************/
|
||||
int64_t getUDPSocketBufferSize() const;
|
||||
void setUDPSocketBufferSize(int64_t value);
|
||||
int64_t getRealUDPSocketBufferSize() const;
|
||||
|
||||
/**************************************************
|
||||
* *
|
||||
@ -101,6 +113,7 @@ class Receiver : public virtual slsDetectorDefs {
|
||||
void setNumberOfAnalogSamples(int value);
|
||||
void setNumberOfDigitalSamples(int value);
|
||||
void setExptime(int64_t value);
|
||||
void setPeriod(int64_t value);
|
||||
void setSubExptime(int64_t value);
|
||||
void setSubDeadTime(int64_t value);
|
||||
void setTimingMode(timingMode value);
|
||||
@ -108,21 +121,28 @@ class Receiver : public virtual slsDetectorDefs {
|
||||
void setReadoutMode(const readoutMode mode);
|
||||
void setQuad(const bool enable);
|
||||
void setReadNLines(const int value);
|
||||
void setADCEnableMask(uint32_t mask);
|
||||
void setTenGigaADCEnableMask(uint32_t mask);
|
||||
void setBurstMode(burstMode value);
|
||||
void setROI(slsDetectorDefs::ROI arg);
|
||||
void clearROI();
|
||||
std::vector<int> getDbitList() const;
|
||||
/** digital data bits enable (CTB only) */
|
||||
void setDbitList(const std::vector<int>& list);
|
||||
int getDbitOffset();
|
||||
/** Set digital data offset in bytes (CTB only) */
|
||||
void setDbitOffset(int value);
|
||||
void setActivate(const bool enable);
|
||||
|
||||
std::map<std::string, std::string> getAdditionalJsonHeader();
|
||||
/** empty vector deletes entire additional json header */
|
||||
void setAdditionalJsonHeader(const std::map<std::string, std::string> &jsonHeader);
|
||||
std::map<std::string, std::string> getAdditionalJsonHeader();
|
||||
std::string getAdditionalJsonParameter(const std::string &key);
|
||||
/** Sets the value for the additional json header parameter key if found,
|
||||
else append it. If value empty, then deletes parameter */
|
||||
void setAdditionalJsonParameter(const std::string &key, const std::string &value);
|
||||
std::string getAdditionalJsonParameter(const std::string &key);
|
||||
|
||||
|
||||
/**************************************************
|
||||
* *
|
||||
* Receiver Parameters *
|
||||
* *
|
||||
* ************************************************/
|
||||
|
||||
/**************************************************
|
||||
* *
|
||||
* File *
|
||||
|
Reference in New Issue
Block a user