mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-22 02:24:30 +01:00
template for sending to detector
This commit is contained in:
@@ -291,11 +291,20 @@ class slsDetector : public virtual slsDetectorDefs{
|
|||||||
*/
|
*/
|
||||||
int64_t getId(idMode mode);
|
int64_t getId(idMode mode);
|
||||||
|
|
||||||
|
int sendToDetector(int fnum, const void *args, size_t args_size,
|
||||||
int sendToDetector(int fnum, void* args, size_t args_size, void* retval, size_t retval_size);
|
void *retval, size_t retval_size);
|
||||||
int sendToDetector(int fnum);
|
|
||||||
|
|
||||||
int64_t getReceiverSoftwareVersion() const;
|
template <typename Arg, typename Ret>
|
||||||
|
typename std::enable_if<
|
||||||
|
!(std::is_pointer<Arg>::value & std::is_pointer<Ret>::value), int>::type
|
||||||
|
sendToDetector(int fnum, const Arg &args, Ret &retval);
|
||||||
|
int sendToDetectorStop(int fnum, const void *args, size_t args_size,
|
||||||
|
void *retval, size_t retval_size);
|
||||||
|
int sendToDetector(int fnum);
|
||||||
|
int sendToReceiver(int fnum, const void *args, size_t args_size,
|
||||||
|
void *retval, size_t retval_size);
|
||||||
|
|
||||||
|
int64_t getReceiverSoftwareVersion() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free shared memory without creating objects
|
* Free shared memory without creating objects
|
||||||
|
|||||||
@@ -97,10 +97,7 @@ int slsDetector::checkDetectorVersionCompatibility() {
|
|||||||
detector_shm()->onlineFlag = OFFLINE_FLAG;
|
detector_shm()->onlineFlag = OFFLINE_FLAG;
|
||||||
|
|
||||||
sendToDetector(fnum, &arg, sizeof(arg), nullptr, 0);
|
sendToDetector(fnum, &arg, sizeof(arg), nullptr, 0);
|
||||||
|
ret = sendToDetectorStop(fnum, &arg, sizeof(arg), nullptr, 0);
|
||||||
auto stop =
|
|
||||||
DetectorSocket(detector_shm()->hostname, detector_shm()->stopPort);
|
|
||||||
ret = stop.sendCommandThenRead(fnum, &arg, sizeof(arg), nullptr, 0);
|
|
||||||
|
|
||||||
// success
|
// success
|
||||||
detector_shm()->detectorControlAPIVersion = arg;
|
detector_shm()->detectorControlAPIVersion = arg;
|
||||||
@@ -661,27 +658,19 @@ int slsDetector::setControlPort(int port_number) {
|
|||||||
|
|
||||||
int slsDetector::setStopPort(int port_number) {
|
int slsDetector::setStopPort(int port_number) {
|
||||||
int fnum = F_SET_PORT;
|
int fnum = F_SET_PORT;
|
||||||
int ret = FAIL;
|
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
FILE_LOG(logDEBUG1) << "Setting stop port "
|
FILE_LOG(logDEBUG1) << "Setting stop port "
|
||||||
<< " to " << port_number;
|
<< " to " << port_number;
|
||||||
|
|
||||||
if (port_number >= 0 && port_number != detector_shm()->stopPort) {
|
if (port_number >= 0 && port_number != detector_shm()->stopPort) {
|
||||||
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
||||||
auto stop = DetectorSocket(detector_shm()->hostname,
|
sendToDetectorStop(fnum, &port_number, sizeof(port_number), &retval,
|
||||||
detector_shm()->stopPort);
|
sizeof(retval));
|
||||||
ret = stop.sendCommandThenRead(fnum, &port_number,
|
|
||||||
sizeof(port_number), &retval,
|
|
||||||
sizeof(retval));
|
|
||||||
detector_shm()->stopPort = retval;
|
detector_shm()->stopPort = retval;
|
||||||
FILE_LOG(logDEBUG1) << "Stop port: " << retval;
|
FILE_LOG(logDEBUG1) << "Stop port: " << retval;
|
||||||
} else {
|
} else {
|
||||||
detector_shm()->stopPort = port_number;
|
detector_shm()->stopPort = port_number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ret == FORCE_UPDATE) {
|
|
||||||
updateDetector();
|
|
||||||
}
|
|
||||||
return detector_shm()->stopPort;
|
return detector_shm()->stopPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -694,9 +683,9 @@ int slsDetector::setReceiverPort(int port_number) {
|
|||||||
|
|
||||||
if (port_number >= 0 && port_number != detector_shm()->receiverTCPPort) {
|
if (port_number >= 0 && port_number != detector_shm()->receiverTCPPort) {
|
||||||
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) {
|
||||||
auto stop = ReceiverSocket(detector_shm()->receiver_hostname,
|
auto receiver = ReceiverSocket(detector_shm()->receiver_hostname,
|
||||||
detector_shm()->receiverTCPPort);
|
detector_shm()->receiverTCPPort);
|
||||||
ret = stop.sendCommandThenRead(fnum, &port_number,
|
ret = receiver.sendCommandThenRead(fnum, &port_number,
|
||||||
sizeof(port_number), &retval,
|
sizeof(port_number), &retval,
|
||||||
sizeof(retval));
|
sizeof(retval));
|
||||||
detector_shm()->receiverTCPPort = retval;
|
detector_shm()->receiverTCPPort = retval;
|
||||||
@@ -1706,14 +1695,14 @@ int slsDetector::setDAC(int val, dacIndex index, int mV) {
|
|||||||
<< (mV != 0 ? "mV" : "dac units");
|
<< (mV != 0 ? "mV" : "dac units");
|
||||||
|
|
||||||
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
||||||
sendToDetector(fnum, args, sizeof(args), &retval, sizeof(retval));
|
sendToDetector(fnum, args, retval);
|
||||||
FILE_LOG(logDEBUG1) << "Dac index " << index << ": " << retval
|
FILE_LOG(logDEBUG1) << "Dac index " << index << ": " << retval
|
||||||
<< (mV != 0 ? "mV" : "dac units");
|
<< (mV != 0 ? "mV" : "dac units");
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
int slsDetector::sendToDetector(int fnum, void *args, size_t args_size,
|
int slsDetector::sendToDetector(int fnum, const void *args, size_t args_size,
|
||||||
void *retval, size_t retval_size) {
|
void *retval, size_t retval_size) {
|
||||||
auto client =
|
auto client =
|
||||||
DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
|
DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
|
||||||
@@ -1726,11 +1715,14 @@ int slsDetector::sendToDetector(int fnum, void *args, size_t args_size,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int slsDetector::sendToDetector(int fnum) {
|
template <typename Arg, typename Ret>
|
||||||
|
typename std::enable_if<
|
||||||
|
!(std::is_pointer<Arg>::value & std::is_pointer<Ret>::value), int>::type
|
||||||
|
slsDetector::sendToDetector(int fnum, const Arg &args, Ret &retval) {
|
||||||
auto client =
|
auto client =
|
||||||
DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
|
DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
|
||||||
auto ret =
|
auto ret = client.sendCommandThenRead(fnum, &args, sizeof(args), &retval,
|
||||||
client.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0);
|
sizeof(retval));
|
||||||
client.close();
|
client.close();
|
||||||
if (ret == FORCE_UPDATE) {
|
if (ret == FORCE_UPDATE) {
|
||||||
ret = updateDetector();
|
ret = updateDetector();
|
||||||
@@ -1738,6 +1730,43 @@ int slsDetector::sendToDetector(int fnum) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int slsDetector::sendToDetector(int fnum) {
|
||||||
|
auto client =
|
||||||
|
DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
|
||||||
|
auto ret = client.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0);
|
||||||
|
client.close();
|
||||||
|
if (ret == FORCE_UPDATE) {
|
||||||
|
ret = updateDetector();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int slsDetector::sendToDetectorStop(int fnum, const void *args, size_t args_size,
|
||||||
|
void *retval, size_t retval_size) {
|
||||||
|
auto client =
|
||||||
|
DetectorSocket(detector_shm()->hostname, detector_shm()->stopPort);
|
||||||
|
auto ret =
|
||||||
|
client.sendCommandThenRead(fnum, args, args_size, retval, retval_size);
|
||||||
|
client.close();
|
||||||
|
//no update on stop port
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int slsDetector::sendToReceiver(int fnum, const void *args, size_t args_size,
|
||||||
|
void *retval, size_t retval_size) {
|
||||||
|
|
||||||
|
auto receiver = ReceiverSocket(detector_shm()->receiver_hostname,
|
||||||
|
detector_shm()->receiverTCPPort);
|
||||||
|
|
||||||
|
auto ret = receiver.sendCommandThenRead(fnum, args, args_size, retval,
|
||||||
|
args_size);
|
||||||
|
receiver.close();
|
||||||
|
if (ret == FORCE_UPDATE) {
|
||||||
|
ret = updateCachedReceiverVariables();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int slsDetector::getADC(dacIndex index) {
|
int slsDetector::getADC(dacIndex index) {
|
||||||
int fnum = F_GET_ADC;
|
int fnum = F_GET_ADC;
|
||||||
int arg = static_cast<int>(index);
|
int arg = static_cast<int>(index);
|
||||||
@@ -1800,25 +1829,16 @@ int slsDetector::setReadOutFlags(readOutFlags flag) {
|
|||||||
updateTotalNumberOfChannels();
|
updateTotalNumberOfChannels();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sending to receiver
|
|
||||||
if (ret != FAIL) {
|
if (ret != FAIL) {
|
||||||
fnum = F_RECEIVER_SET_READOUT_FLAGS;
|
|
||||||
ret = FAIL;
|
|
||||||
arg = detector_shm()->roFlags;
|
|
||||||
retval = static_cast<readOutFlags>(-1);
|
|
||||||
FILE_LOG(logDEBUG1) << "Setting receiver readout flags to " << arg;
|
FILE_LOG(logDEBUG1) << "Setting receiver readout flags to " << arg;
|
||||||
|
|
||||||
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) {
|
||||||
auto receiver = ReceiverSocket(detector_shm()->receiver_hostname,
|
fnum = F_RECEIVER_SET_READOUT_FLAGS;
|
||||||
detector_shm()->receiverTCPPort);
|
ret = FAIL;
|
||||||
ret = receiver.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,
|
arg = detector_shm()->roFlags;
|
||||||
sizeof(retval));
|
retval = static_cast<readOutFlags>(-1);
|
||||||
|
sendToReceiver(fnum, &arg, sizeof(arg), &retval, sizeof(retval));
|
||||||
FILE_LOG(logDEBUG1) << "Receiver readout flag: " << retval;
|
FILE_LOG(logDEBUG1) << "Receiver readout flag: " << retval;
|
||||||
}
|
}
|
||||||
if (ret == FORCE_UPDATE) {
|
|
||||||
updateCachedReceiverVariables();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return detector_shm()->roFlags;
|
return detector_shm()->roFlags;
|
||||||
}
|
}
|
||||||
@@ -1831,7 +1851,7 @@ uint32_t slsDetector::writeRegister(uint32_t addr, uint32_t val) {
|
|||||||
<< "data: 0x" << std::hex << val << std::dec;
|
<< "data: 0x" << std::hex << val << std::dec;
|
||||||
|
|
||||||
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
||||||
sendToDetector(fnum, args, sizeof(args), &retval, sizeof(retval));
|
sendToDetector(fnum, args, retval);
|
||||||
FILE_LOG(logDEBUG1) << "Register 0x" << std::hex << addr << ": 0x"
|
FILE_LOG(logDEBUG1) << "Register 0x" << std::hex << addr << ": 0x"
|
||||||
<< std::hex << retval << std::dec;
|
<< std::hex << retval << std::dec;
|
||||||
}
|
}
|
||||||
@@ -1839,14 +1859,11 @@ uint32_t slsDetector::writeRegister(uint32_t addr, uint32_t val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t slsDetector::readRegister(uint32_t addr) {
|
uint32_t slsDetector::readRegister(uint32_t addr) {
|
||||||
int fnum = F_READ_REGISTER;
|
|
||||||
uint32_t retval = -1;
|
uint32_t retval = -1;
|
||||||
FILE_LOG(logDEBUG1) << "Reading register 0x" << std::hex << addr
|
FILE_LOG(logDEBUG1) << "Reading reg 0x" << std::hex << addr << std::dec;
|
||||||
<< std::dec;
|
|
||||||
|
|
||||||
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
||||||
sendToDetector(fnum, &addr, sizeof(addr), &retval, sizeof(retval));
|
sendToDetector(F_READ_REGISTER, addr, retval);
|
||||||
FILE_LOG(logDEBUG1) << "Register 0x" << std::hex << addr << ": 0x"
|
FILE_LOG(logDEBUG1) << "Reg 0x" << std::hex << addr << ": 0x"
|
||||||
<< std::hex << retval << std::dec;
|
<< std::hex << retval << std::dec;
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
@@ -2216,25 +2233,15 @@ int slsDetector::getClientStreamingPort() { return detector_shm()->zmqport; }
|
|||||||
void slsDetector::setReceiverStreamingPort(int port) {
|
void slsDetector::setReceiverStreamingPort(int port) {
|
||||||
// copy now else it is lost if rx_hostname not set yet
|
// copy now else it is lost if rx_hostname not set yet
|
||||||
detector_shm()->receiver_zmqport = port;
|
detector_shm()->receiver_zmqport = port;
|
||||||
|
|
||||||
int fnum = F_SET_RECEIVER_STREAMING_PORT;
|
int fnum = F_SET_RECEIVER_STREAMING_PORT;
|
||||||
int ret = FAIL;
|
|
||||||
int arg = detector_shm()->receiver_zmqport;
|
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
FILE_LOG(logDEBUG1) << "Sending receiver streaming port to receiver: "
|
FILE_LOG(logDEBUG1) << "Sending receiver streaming port to receiver: "
|
||||||
<< arg;
|
<< port;
|
||||||
|
|
||||||
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) {
|
||||||
auto receiver = ReceiverSocket(detector_shm()->receiver_hostname,
|
sendToReceiver(fnum, &port, sizeof(port), &retval, sizeof(retval));
|
||||||
detector_shm()->receiverTCPPort);
|
|
||||||
ret = receiver.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,
|
|
||||||
sizeof(retval));
|
|
||||||
FILE_LOG(logDEBUG1) << "Receiver streaming port: " << retval;
|
FILE_LOG(logDEBUG1) << "Receiver streaming port: " << retval;
|
||||||
detector_shm()->receiver_zmqport = retval;
|
detector_shm()->receiver_zmqport = retval;
|
||||||
}
|
}
|
||||||
if (ret == FORCE_UPDATE) {
|
|
||||||
updateCachedReceiverVariables();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int slsDetector::getReceiverStreamingPort() {
|
int slsDetector::getReceiverStreamingPort() {
|
||||||
@@ -2304,6 +2311,7 @@ void slsDetector::setReceiverStreamingIP(std::string sourceIP) {
|
|||||||
detector_shm()->receiverTCPPort);
|
detector_shm()->receiverTCPPort);
|
||||||
ret = receiver.sendCommandThenRead(fnum, args, sizeof(args), retvals,
|
ret = receiver.sendCommandThenRead(fnum, args, sizeof(args), retvals,
|
||||||
sizeof(retvals));
|
sizeof(retvals));
|
||||||
|
|
||||||
FILE_LOG(logDEBUG1) << "Receiver streaming port: " << retvals;
|
FILE_LOG(logDEBUG1) << "Receiver streaming port: " << retvals;
|
||||||
memset(detector_shm()->receiver_zmqip, 0, MAX_STR_LENGTH);
|
memset(detector_shm()->receiver_zmqip, 0, MAX_STR_LENGTH);
|
||||||
sls::strcpy_safe(detector_shm()->receiver_zmqip, retvals);
|
sls::strcpy_safe(detector_shm()->receiver_zmqip, retvals);
|
||||||
@@ -2337,9 +2345,8 @@ int slsDetector::setDetectorNetworkParameter(networkParameter index,
|
|||||||
std::string
|
std::string
|
||||||
slsDetector::setAdditionalJsonHeader(const std::string &jsonheader) {
|
slsDetector::setAdditionalJsonHeader(const std::string &jsonheader) {
|
||||||
int fnum = F_ADDITIONAL_JSON_HEADER;
|
int fnum = F_ADDITIONAL_JSON_HEADER;
|
||||||
int ret = FAIL;
|
char args[MAX_STR_LENGTH]{};
|
||||||
char args[MAX_STR_LENGTH] = {0};
|
char retvals[MAX_STR_LENGTH]{};
|
||||||
char retvals[MAX_STR_LENGTH] = {0};
|
|
||||||
sls::strcpy_safe(args, jsonheader.c_str());
|
sls::strcpy_safe(args, jsonheader.c_str());
|
||||||
FILE_LOG(logDEBUG1) << "Sending additional json header " << args;
|
FILE_LOG(logDEBUG1) << "Sending additional json header " << args;
|
||||||
|
|
||||||
@@ -2347,38 +2354,24 @@ slsDetector::setAdditionalJsonHeader(const std::string &jsonheader) {
|
|||||||
sls::strcpy_safe(detector_shm()->rxAdditionalJsonHeader,
|
sls::strcpy_safe(detector_shm()->rxAdditionalJsonHeader,
|
||||||
jsonheader.c_str());
|
jsonheader.c_str());
|
||||||
} else {
|
} else {
|
||||||
auto receiver = ReceiverSocket(detector_shm()->receiver_hostname,
|
sendToReceiver(fnum, args, sizeof(args), retvals, sizeof(retvals));
|
||||||
detector_shm()->receiverTCPPort);
|
|
||||||
ret = receiver.sendCommandThenRead(fnum, args, sizeof(args), retvals,
|
|
||||||
sizeof(retvals));
|
|
||||||
FILE_LOG(logDEBUG1) << "Additional json header: " << retvals;
|
FILE_LOG(logDEBUG1) << "Additional json header: " << retvals;
|
||||||
memset(detector_shm()->rxAdditionalJsonHeader, 0, MAX_STR_LENGTH);
|
memset(detector_shm()->rxAdditionalJsonHeader, 0, MAX_STR_LENGTH);
|
||||||
sls::strcpy_safe(detector_shm()->rxAdditionalJsonHeader, retvals);
|
sls::strcpy_safe(detector_shm()->rxAdditionalJsonHeader, retvals);
|
||||||
}
|
}
|
||||||
if (ret == FORCE_UPDATE) {
|
return detector_shm()->rxAdditionalJsonHeader;
|
||||||
updateCachedReceiverVariables();
|
|
||||||
}
|
|
||||||
return std::string(detector_shm()->rxAdditionalJsonHeader);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string slsDetector::getAdditionalJsonHeader() {
|
std::string slsDetector::getAdditionalJsonHeader() {
|
||||||
int fnum = F_GET_ADDITIONAL_JSON_HEADER;
|
int fnum = F_GET_ADDITIONAL_JSON_HEADER;
|
||||||
int ret = FAIL;
|
char retvals[MAX_STR_LENGTH]{};
|
||||||
char retvals[MAX_STR_LENGTH] = {0};
|
|
||||||
FILE_LOG(logDEBUG1) << "Getting additional json header ";
|
FILE_LOG(logDEBUG1) << "Getting additional json header ";
|
||||||
|
|
||||||
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) {
|
||||||
auto receiver = ReceiverSocket(detector_shm()->receiver_hostname,
|
sendToReceiver(fnum, nullptr, 0, retvals, sizeof(retvals));
|
||||||
detector_shm()->receiverTCPPort);
|
|
||||||
ret = receiver.sendCommandThenRead(fnum, nullptr, 0, retvals,
|
|
||||||
sizeof(retvals));
|
|
||||||
FILE_LOG(logDEBUG1) << "Additional json header: " << retvals;
|
FILE_LOG(logDEBUG1) << "Additional json header: " << retvals;
|
||||||
memset(detector_shm()->rxAdditionalJsonHeader, 0, MAX_STR_LENGTH);
|
memset(detector_shm()->rxAdditionalJsonHeader, 0, MAX_STR_LENGTH);
|
||||||
sls::strcpy_safe(detector_shm()->rxAdditionalJsonHeader, retvals);
|
sls::strcpy_safe(detector_shm()->rxAdditionalJsonHeader, retvals);
|
||||||
}
|
}
|
||||||
if (ret == FORCE_UPDATE) {
|
|
||||||
updateCachedReceiverVariables();
|
|
||||||
}
|
|
||||||
return std::string(detector_shm()->rxAdditionalJsonHeader);
|
return std::string(detector_shm()->rxAdditionalJsonHeader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2461,7 +2454,6 @@ std::string slsDetector::getAdditionalJsonParameter(const std::string &key) {
|
|||||||
return pairs[1];
|
return pairs[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return empty string as no match found with key
|
// return empty string as no match found with key
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
@@ -2493,21 +2485,13 @@ int64_t slsDetector::getReceiverUDPSocketBufferSize() {
|
|||||||
|
|
||||||
int64_t slsDetector::getReceiverRealUDPSocketBufferSize() {
|
int64_t slsDetector::getReceiverRealUDPSocketBufferSize() {
|
||||||
int fnum = F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE;
|
int fnum = F_RECEIVER_REAL_UDP_SOCK_BUF_SIZE;
|
||||||
int ret = FAIL;
|
|
||||||
int64_t retval = -1;
|
int64_t retval = -1;
|
||||||
FILE_LOG(logDEBUG1) << "Getting real UDP Socket Buffer size to receiver";
|
FILE_LOG(logDEBUG1) << "Getting real UDP Socket Buffer size to receiver";
|
||||||
|
|
||||||
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) {
|
||||||
auto receiver = ReceiverSocket(detector_shm()->receiver_hostname,
|
sendToReceiver(fnum, nullptr, 0, &retval, sizeof(retval));
|
||||||
detector_shm()->receiverTCPPort);
|
|
||||||
ret = receiver.sendCommandThenRead(fnum, nullptr, 0, &retval,
|
|
||||||
sizeof(retval));
|
|
||||||
FILE_LOG(logDEBUG1)
|
FILE_LOG(logDEBUG1)
|
||||||
<< "Real Receiver UDP Socket Buffer size: " << retval;
|
<< "Real Receiver UDP Socket Buffer size: " << retval;
|
||||||
}
|
}
|
||||||
if (ret == FORCE_UPDATE) {
|
|
||||||
updateCachedReceiverVariables();
|
|
||||||
}
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2576,10 +2560,6 @@ int slsDetector::setUDPConnection() {
|
|||||||
<< "Receiver UDP MAC2 returned : " << retvals[1];
|
<< "Receiver UDP MAC2 returned : " << retvals[1];
|
||||||
detector_shm()->receiverUDPMAC2 = retvals[1];
|
detector_shm()->receiverUDPMAC2 = retvals[1];
|
||||||
}
|
}
|
||||||
if (ret == FORCE_UPDATE) {
|
|
||||||
receiver.close();
|
|
||||||
ret = updateCachedReceiverVariables();
|
|
||||||
}
|
|
||||||
// configure detector with udp details
|
// configure detector with udp details
|
||||||
if (configureMAC() == FAIL) {
|
if (configureMAC() == FAIL) {
|
||||||
setReceiverOnline(OFFLINE_FLAG);
|
setReceiverOnline(OFFLINE_FLAG);
|
||||||
@@ -2587,7 +2567,6 @@ int slsDetector::setUDPConnection() {
|
|||||||
} else {
|
} else {
|
||||||
throw ReceiverError("setUDPConnection: Receiver is OFFLINE");
|
throw ReceiverError("setUDPConnection: Receiver is OFFLINE");
|
||||||
}
|
}
|
||||||
|
|
||||||
printReceiverConfiguration(logDEBUG1);
|
printReceiverConfiguration(logDEBUG1);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -2869,55 +2848,33 @@ int slsDetector::writeAdcRegister(uint32_t addr, uint32_t val) {
|
|||||||
int slsDetector::activate(int enable) {
|
int slsDetector::activate(int enable) {
|
||||||
int fnum = F_ACTIVATE;
|
int fnum = F_ACTIVATE;
|
||||||
int ret = FAIL;
|
int ret = FAIL;
|
||||||
int arg = enable;
|
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
FILE_LOG(logDEBUG1) << "Setting activate flag to " << arg;
|
FILE_LOG(logDEBUG1) << "Setting activate flag to " << enable;
|
||||||
|
|
||||||
// detector
|
|
||||||
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
||||||
ret = sendToDetector(fnum, &arg, sizeof(arg), &retval, sizeof(retval));
|
ret = sendToDetector(fnum, &enable, sizeof(enable), &retval, sizeof(retval));
|
||||||
FILE_LOG(logDEBUG1) << "Activate: " << retval;
|
FILE_LOG(logDEBUG1) << "Activate: " << retval;
|
||||||
detector_shm()->activated = static_cast<bool>(retval);
|
detector_shm()->activated = static_cast<bool>(retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
// receiver
|
|
||||||
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG && ret == OK) {
|
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG && ret == OK) {
|
||||||
fnum = F_RECEIVER_ACTIVATE;
|
fnum = F_RECEIVER_ACTIVATE;
|
||||||
arg = static_cast<int>(detector_shm()->activated);
|
enable = static_cast<int>(detector_shm()->activated);
|
||||||
retval = -1;
|
retval = -1;
|
||||||
FILE_LOG(logDEBUG1)
|
FILE_LOG(logDEBUG1)
|
||||||
<< "Setting activate flag " << arg << " to receiver";
|
<< "Setting activate flag " << enable << " to receiver";
|
||||||
|
sendToReceiver(fnum, &enable, sizeof(enable), &retval, sizeof(retval));
|
||||||
auto receiver = ReceiverSocket(detector_shm()->receiver_hostname,
|
|
||||||
detector_shm()->receiverTCPPort);
|
|
||||||
ret = receiver.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,
|
|
||||||
sizeof(retval));
|
|
||||||
if (ret == FORCE_UPDATE) {
|
|
||||||
receiver.close();
|
|
||||||
updateCachedReceiverVariables();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return static_cast<int>(detector_shm()->activated);
|
return static_cast<int>(detector_shm()->activated);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool slsDetector::setDeactivatedRxrPaddingMode(int padding) {
|
bool slsDetector::setDeactivatedRxrPaddingMode(int padding) {
|
||||||
int fnum = F_RECEIVER_DEACTIVATED_PADDING_ENABLE;
|
int fnum = F_RECEIVER_DEACTIVATED_PADDING_ENABLE;
|
||||||
int ret = OK;
|
|
||||||
int arg = padding;
|
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
FILE_LOG(logDEBUG1) << "Deactivated Receiver Padding Enable: " << arg;
|
FILE_LOG(logDEBUG1) << "Deactivated Receiver Padding Enable: " << padding;
|
||||||
|
|
||||||
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) {
|
||||||
auto receiver = ReceiverSocket(detector_shm()->receiver_hostname,
|
sendToReceiver(fnum, &padding, sizeof(padding), &retval, sizeof(retval));
|
||||||
detector_shm()->receiverTCPPort);
|
|
||||||
ret = receiver.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,
|
|
||||||
sizeof(retval));
|
|
||||||
FILE_LOG(logDEBUG1) << "Deactivated Receiver Padding Enable:" << retval;
|
FILE_LOG(logDEBUG1) << "Deactivated Receiver Padding Enable:" << retval;
|
||||||
detector_shm()->rxPadDeactivatedModules = static_cast<bool>(retval);
|
detector_shm()->rxPadDeactivatedModules = static_cast<bool>(retval);
|
||||||
}
|
}
|
||||||
if (ret == FORCE_UPDATE) {
|
|
||||||
updateCachedReceiverVariables();
|
|
||||||
}
|
|
||||||
return detector_shm()->rxPadDeactivatedModules;
|
return detector_shm()->rxPadDeactivatedModules;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2971,19 +2928,12 @@ int slsDetector::setAllTrimbits(int val) {
|
|||||||
int slsDetector::enableGapPixels(int val) {
|
int slsDetector::enableGapPixels(int val) {
|
||||||
if (val >= 0) {
|
if (val >= 0) {
|
||||||
int fnum = F_ENABLE_GAPPIXELS_IN_RECEIVER;
|
int fnum = F_ENABLE_GAPPIXELS_IN_RECEIVER;
|
||||||
int ret = OK;
|
|
||||||
int arg = val;
|
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
FILE_LOG(logDEBUG1) << "Sending gap pixels enable to receiver: " << arg;
|
FILE_LOG(logDEBUG1) << "Sending gap pixels enable to receiver: " << val;
|
||||||
|
|
||||||
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) {
|
||||||
auto receiver = ReceiverSocket(detector_shm()->receiver_hostname,
|
sendToReceiver(fnum, &val, sizeof(val), &retval, sizeof(retval));
|
||||||
detector_shm()->receiverTCPPort);
|
|
||||||
ret = receiver.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,
|
|
||||||
sizeof(retval));
|
|
||||||
FILE_LOG(logDEBUG1) << "Gap pixels enable to receiver:" << retval;
|
FILE_LOG(logDEBUG1) << "Gap pixels enable to receiver:" << retval;
|
||||||
detector_shm()->gappixels = retval;
|
detector_shm()->gappixels = retval;
|
||||||
|
|
||||||
// update databytes
|
// update databytes
|
||||||
detector_shm()->dataBytesInclGapPixels = 0;
|
detector_shm()->dataBytesInclGapPixels = 0;
|
||||||
if (detector_shm()->dynamicRange != 4) {
|
if (detector_shm()->dynamicRange != 4) {
|
||||||
@@ -2997,9 +2947,6 @@ int slsDetector::enableGapPixels(int val) {
|
|||||||
detector_shm()->dynamicRange / 8;
|
detector_shm()->dynamicRange / 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ret == FORCE_UPDATE) {
|
|
||||||
updateCachedReceiverVariables();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return detector_shm()->gappixels;
|
return detector_shm()->gappixels;
|
||||||
}
|
}
|
||||||
@@ -3066,51 +3013,33 @@ int slsDetector::pulseChip(int n) {
|
|||||||
|
|
||||||
int slsDetector::setThresholdTemperature(int val) {
|
int slsDetector::setThresholdTemperature(int val) {
|
||||||
int fnum = F_THRESHOLD_TEMP;
|
int fnum = F_THRESHOLD_TEMP;
|
||||||
int arg = val;
|
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
FILE_LOG(logDEBUG1) << "Setting threshold temperature to " << val;
|
FILE_LOG(logDEBUG1) << "Setting threshold temperature to " << val;
|
||||||
|
|
||||||
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
||||||
auto stop =
|
sendToDetectorStop(fnum, &val, sizeof(val), &retval, sizeof(retval));
|
||||||
DetectorSocket(detector_shm()->hostname, detector_shm()->stopPort);
|
|
||||||
stop.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,
|
|
||||||
sizeof(retval));
|
|
||||||
FILE_LOG(logDEBUG1) << "Threshold temperature: " << retval;
|
FILE_LOG(logDEBUG1) << "Threshold temperature: " << retval;
|
||||||
// no updateDetector as it is stop server
|
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
int slsDetector::setTemperatureControl(int val) {
|
int slsDetector::setTemperatureControl(int val) {
|
||||||
int fnum = F_TEMP_CONTROL;
|
int fnum = F_TEMP_CONTROL;
|
||||||
int arg = val;
|
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
FILE_LOG(logDEBUG1) << "Setting temperature control to " << val;
|
FILE_LOG(logDEBUG1) << "Setting temperature control to " << val;
|
||||||
|
|
||||||
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
||||||
auto stop =
|
sendToDetectorStop(fnum, &val, sizeof(val), &retval, sizeof(retval));
|
||||||
DetectorSocket(detector_shm()->hostname, detector_shm()->stopPort);
|
|
||||||
stop.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,
|
|
||||||
sizeof(retval));
|
|
||||||
FILE_LOG(logDEBUG1) << "Temperature control: " << retval;
|
FILE_LOG(logDEBUG1) << "Temperature control: " << retval;
|
||||||
// no updateDetector as it is stop server
|
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
int slsDetector::setTemperatureEvent(int val) {
|
int slsDetector::setTemperatureEvent(int val) {
|
||||||
int fnum = F_TEMP_EVENT;
|
int fnum = F_TEMP_EVENT;
|
||||||
int arg = val;
|
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
FILE_LOG(logDEBUG1) << "Setting temperature event to " << val;
|
FILE_LOG(logDEBUG1) << "Setting temperature event to " << val;
|
||||||
|
|
||||||
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
|
||||||
auto stop =
|
sendToDetectorStop(fnum, &val, sizeof(val), &retval, sizeof(retval));
|
||||||
DetectorSocket(detector_shm()->hostname, detector_shm()->stopPort);
|
|
||||||
stop.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,
|
|
||||||
sizeof(retval));
|
|
||||||
FILE_LOG(logDEBUG1) << "Temperature event: " << retval;
|
FILE_LOG(logDEBUG1) << "Temperature event: " << retval;
|
||||||
// no updateDetector as it is stop server
|
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ namespace sls {
|
|||||||
|
|
||||||
class ClientSocket : public DataSocket {
|
class ClientSocket : public DataSocket {
|
||||||
public:
|
public:
|
||||||
ClientSocket(std::string stype, const std::string &hostname, uint16_t port_number);
|
ClientSocket(std::string stype, const std::string &hostname,
|
||||||
|
uint16_t port_number);
|
||||||
ClientSocket(std::string stype, struct sockaddr_in addr);
|
ClientSocket(std::string stype, struct sockaddr_in addr);
|
||||||
int sendCommandThenRead(int fnum, void *args, size_t args_size, void *retval,
|
int sendCommandThenRead(int fnum, const void *args, size_t args_size,
|
||||||
size_t retval_size);
|
void *retval, size_t retval_size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void readReply(int &ret, void *retval, size_t retval_size);
|
void readReply(int &ret, void *retval, size_t retval_size);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
#ifndef FILELOG_MAX_LEVEL
|
#ifndef FILELOG_MAX_LEVEL
|
||||||
#define FILELOG_MAX_LEVEL logINFO
|
#define FILELOG_MAX_LEVEL logINFO
|
||||||
//#define FILELOG_MAX_LEVEL logDEBUG5
|
// #define FILELOG_MAX_LEVEL logDEBUG5
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,8 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
namespace sls {
|
namespace sls {
|
||||||
|
|
||||||
ClientSocket::ClientSocket(std::string stype, const std::string &host, uint16_t port)
|
ClientSocket::ClientSocket(std::string stype, const std::string &host,
|
||||||
|
uint16_t port)
|
||||||
: DataSocket(socket(AF_INET, SOCK_STREAM, 0)), socketType(stype) {
|
: DataSocket(socket(AF_INET, SOCK_STREAM, 0)), socketType(stype) {
|
||||||
|
|
||||||
struct addrinfo hints, *result;
|
struct addrinfo hints, *result;
|
||||||
@@ -20,22 +21,25 @@ ClientSocket::ClientSocket(std::string stype, const std::string &host, uint16_t
|
|||||||
hints.ai_flags |= AI_CANONNAME;
|
hints.ai_flags |= AI_CANONNAME;
|
||||||
|
|
||||||
if (getaddrinfo(host.c_str(), NULL, &hints, &result) != 0) {
|
if (getaddrinfo(host.c_str(), NULL, &hints, &result) != 0) {
|
||||||
std::string msg =
|
std::string msg = "ClientSocket cannot decode host:" + host +
|
||||||
"ClientSocket cannot decode host:" + host + " on port " + std::to_string(port) + "\n";
|
" on port " + std::to_string(port) + "\n";
|
||||||
throw SocketError(msg);
|
throw SocketError(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO! Erik, results could have multiple entries do we need to loop through them?
|
// TODO! Erik, results could have multiple entries do we need to loop
|
||||||
// struct sockaddr_in serverAddr {};
|
// through them? struct sockaddr_in serverAddr {};
|
||||||
serverAddr.sin_family = AF_INET;
|
serverAddr.sin_family = AF_INET;
|
||||||
serverAddr.sin_port = htons(port);
|
serverAddr.sin_port = htons(port);
|
||||||
memcpy((char *)&serverAddr.sin_addr.s_addr, &((struct sockaddr_in *)result->ai_addr)->sin_addr,
|
memcpy((char *)&serverAddr.sin_addr.s_addr,
|
||||||
|
&((struct sockaddr_in *)result->ai_addr)->sin_addr,
|
||||||
sizeof(in_addr_t));
|
sizeof(in_addr_t));
|
||||||
|
|
||||||
if (::connect(getSocketId(), (struct sockaddr *)&serverAddr, sizeof(serverAddr)) != 0) {
|
if (::connect(getSocketId(), (struct sockaddr *)&serverAddr,
|
||||||
|
sizeof(serverAddr)) != 0) {
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
std::string msg = "ClientSocket: Cannot connect to " + socketType + ":" +
|
std::string msg = "ClientSocket: Cannot connect to " + socketType +
|
||||||
host + " on port " + std::to_string(port) + "\n";
|
":" + host + " on port " + std::to_string(port) +
|
||||||
|
"\n";
|
||||||
throw SocketError(msg);
|
throw SocketError(msg);
|
||||||
}
|
}
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
@@ -47,13 +51,15 @@ ClientSocket::ClientSocket(std::string sType, struct sockaddr_in addr)
|
|||||||
if (::connect(getSocketId(), (struct sockaddr *)&addr, sizeof(addr)) != 0) {
|
if (::connect(getSocketId(), (struct sockaddr *)&addr, sizeof(addr)) != 0) {
|
||||||
char address[INET_ADDRSTRLEN];
|
char address[INET_ADDRSTRLEN];
|
||||||
inet_ntop(AF_INET, &addr.sin_addr, address, INET_ADDRSTRLEN);
|
inet_ntop(AF_INET, &addr.sin_addr, address, INET_ADDRSTRLEN);
|
||||||
std::string msg = "ClientSocket: Cannot connect to " + socketType + ":" + address + " on port " +
|
std::string msg = "ClientSocket: Cannot connect to " + socketType +
|
||||||
|
":" + address + " on port " +
|
||||||
std::to_string(addr.sin_port) + "\n";
|
std::to_string(addr.sin_port) + "\n";
|
||||||
throw SocketError(msg);
|
throw SocketError(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ClientSocket::sendCommandThenRead(int fnum, void *args, size_t args_size, void *retval,
|
int ClientSocket::sendCommandThenRead(int fnum, const void *args,
|
||||||
|
size_t args_size, void *retval,
|
||||||
size_t retval_size) {
|
size_t retval_size) {
|
||||||
int ret = slsDetectorDefs::FAIL;
|
int ret = slsDetectorDefs::FAIL;
|
||||||
sendData(&fnum, sizeof(fnum));
|
sendData(&fnum, sizeof(fnum));
|
||||||
@@ -69,7 +75,7 @@ void ClientSocket::readReply(int &ret, void *retval, size_t retval_size) {
|
|||||||
char mess[MAX_STR_LENGTH]{};
|
char mess[MAX_STR_LENGTH]{};
|
||||||
// get error message
|
// get error message
|
||||||
receiveData(mess, sizeof(mess));
|
receiveData(mess, sizeof(mess));
|
||||||
FILE_LOG(logERROR) << socketType << " returned error: " << mess;
|
FILE_LOG(logERROR) << socketType << " returned error: " << mess;
|
||||||
std::cout << "\n"; // needed to reset the color.
|
std::cout << "\n"; // needed to reset the color.
|
||||||
|
|
||||||
// Do we need to know hostname here?
|
// Do we need to know hostname here?
|
||||||
|
|||||||
Reference in New Issue
Block a user