migrate to return values

This commit is contained in:
Erik Frojdh
2020-05-11 11:39:11 +02:00
parent 1998f9541e
commit bbe9108fb9

View File

@ -8,19 +8,13 @@
#include "string_utils.h" #include "string_utils.h"
#include "versionAPI.h" #include "versionAPI.h"
#include <arpa/inet.h> #include <algorithm>
#include <array> #include <array>
#include <bitset> #include <bitset>
#include <cassert> #include <cassert>
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include <iomanip> #include <iomanip>
#include <sys/shm.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <algorithm>
namespace sls { namespace sls {
@ -101,34 +95,22 @@ void Module::checkReceiverVersionCompatibility() {
} }
int64_t Module::getFirmwareVersion() { int64_t Module::getFirmwareVersion() {
int64_t retval = -1; return sendToDetector<int64_t>(F_GET_FIRMWARE_VERSION);
sendToDetector(F_GET_FIRMWARE_VERSION, nullptr, retval);
LOG(logDEBUG1) << "firmware version: 0x" << std::hex << retval << std::dec;
return retval;
} }
int64_t Module::getDetectorServerVersion() { int64_t Module::getDetectorServerVersion() {
int64_t retval = -1; return sendToDetector<int64_t>(F_GET_SERVER_VERSION);
sendToDetector(F_GET_SERVER_VERSION, nullptr, retval);
LOG(logDEBUG1) << "detector server version: 0x" << std::hex << retval
<< std::dec;
return retval;
} }
int64_t Module::getSerialNumber() { int64_t Module::getSerialNumber() {
int64_t retval = -1; return sendToDetector<int64_t>(F_GET_SERIAL_NUMBER);
sendToDetector(F_GET_SERIAL_NUMBER, nullptr, retval);
LOG(logDEBUG1) << "serial number: 0x" << std::hex << retval << std::dec;
return retval;
} }
int64_t Module::getReceiverSoftwareVersion() const { int64_t Module::getReceiverSoftwareVersion() const {
LOG(logDEBUG1) << "Getting receiver version";
int64_t retval = -1;
if (shm()->useReceiverFlag) { if (shm()->useReceiverFlag) {
sendToReceiver(F_GET_RECEIVER_VERSION, nullptr, retval); return sendToReceiver<int64_t>(F_GET_RECEIVER_VERSION);
} }
return retval; return -1;
} }
void Module::sendToDetector(int fnum, const void *args, size_t args_size, void Module::sendToDetector(int fnum, const void *args, size_t args_size,
@ -647,17 +629,12 @@ bool Module::lockServer(int lock) {
} }
sls::IpAddr Module::getLastClientIP() { sls::IpAddr Module::getLastClientIP() {
sls::IpAddr retval; return sendToDetector<sls::IpAddr>(F_GET_LAST_CLIENT_IP);
LOG(logDEBUG1) << "Getting last client ip to detector server";
sendToDetector(F_GET_LAST_CLIENT_IP, nullptr, retval);
LOG(logDEBUG1) << "Last client IP to detector: " << retval;
return retval;
} }
void Module::exitServer() { void Module::exitServer() {
LOG(logDEBUG1) << "Sending exit command to detector server"; LOG(logDEBUG1) << "Sending exit command to detector server";
sendToDetector(F_EXIT_SERVER); sendToDetector(F_EXIT_SERVER);
LOG(logINFO) << "Shutting down the Detector server";
} }
void Module::execCommand(const std::string &cmd) { void Module::execCommand(const std::string &cmd) {
@ -1293,11 +1270,7 @@ void Module::setTimingMode(timingMode value) {
} }
int Module::getDynamicRange() { int Module::getDynamicRange() {
int arg = -1; return sendToDetector<int>(F_SET_DYNAMIC_RANGE, -1);
int retval = -1;
sendToDetector(F_SET_DYNAMIC_RANGE, arg, retval);
LOG(logDEBUG1) << "Dynamic Range: " << retval;
return retval;
} }
void Module::setDynamicRange(int n) { void Module::setDynamicRange(int n) {
@ -1402,11 +1375,8 @@ void Module::setOverFlowMode(const bool enable) {
} }
bool Module::getOverFlowMode() { bool Module::getOverFlowMode() {
int retval = -1; auto r = sendToDetector<int>(F_GET_OVERFLOW_MODE);
LOG(logDEBUG1) << "Getting overflow mode"; return static_cast<bool>(r);
sendToDetector(F_GET_OVERFLOW_MODE, nullptr, retval);
LOG(logDEBUG1) << "overflow mode: " << retval;
return static_cast<bool>(retval);
} }
void Module::setStoreInRamMode(const bool enable) { void Module::setStoreInRamMode(const bool enable) {
@ -1416,11 +1386,8 @@ void Module::setStoreInRamMode(const bool enable) {
} }
bool Module::getStoreInRamMode() { bool Module::getStoreInRamMode() {
int retval = -1; auto r = sendToDetector<int>(F_GET_STOREINRAM_MODE);
LOG(logDEBUG1) << "Getting store in ram mode"; return static_cast<bool>(r);
sendToDetector(F_GET_STOREINRAM_MODE, nullptr, retval);
LOG(logDEBUG1) << "store in ram mode: " << retval;
return static_cast<bool>(retval);
} }
void Module::setReadoutMode(const slsDetectorDefs::readoutMode mode) { void Module::setReadoutMode(const slsDetectorDefs::readoutMode mode) {
@ -1437,11 +1404,8 @@ void Module::setReadoutMode(const slsDetectorDefs::readoutMode mode) {
} }
slsDetectorDefs::readoutMode Module::getReadoutMode() { slsDetectorDefs::readoutMode Module::getReadoutMode() {
int retval = -1; auto r = sendToDetector<int>(F_GET_READOUT_MODE);
LOG(logDEBUG1) << "Getting readout mode"; return static_cast<readoutMode>(r);
sendToDetector(F_GET_READOUT_MODE, nullptr, retval);
LOG(logDEBUG1) << "Readout mode: " << retval;
return static_cast<readoutMode>(retval);
} }
void Module::setInterruptSubframe(const bool enable) { void Module::setInterruptSubframe(const bool enable) {
@ -1451,8 +1415,8 @@ void Module::setInterruptSubframe(const bool enable) {
} }
bool Module::getInterruptSubframe() { bool Module::getInterruptSubframe() {
auto retval = sendToDetector<int>(F_GET_INTERRUPT_SUBFRAME); auto r = sendToDetector<int>(F_GET_INTERRUPT_SUBFRAME);
return static_cast<bool>(retval); return static_cast<bool>(r);
} }
uint32_t Module::writeRegister(uint32_t addr, uint32_t val) { uint32_t Module::writeRegister(uint32_t addr, uint32_t val) {
@ -1600,11 +1564,7 @@ void Module::setSourceUDPMAC(const sls::MacAddr mac) {
} }
sls::MacAddr Module::getSourceUDPMAC() { sls::MacAddr Module::getSourceUDPMAC() {
sls::MacAddr retval(0LU); return sendToDetector<sls::MacAddr>(F_GET_SOURCE_UDP_MAC);
LOG(logDEBUG1) << "Getting source udp mac";
sendToDetector(F_GET_SOURCE_UDP_MAC, nullptr, retval);
LOG(logDEBUG1) << "Source udp mac: " << retval;
return retval;
} }
void Module::setSourceUDPMAC2(const sls::MacAddr mac) { void Module::setSourceUDPMAC2(const sls::MacAddr mac) {
@ -1616,11 +1576,7 @@ void Module::setSourceUDPMAC2(const sls::MacAddr mac) {
} }
sls::MacAddr Module::getSourceUDPMAC2() { sls::MacAddr Module::getSourceUDPMAC2() {
sls::MacAddr retval(0LU); return sendToDetector<sls::MacAddr>(F_GET_SOURCE_UDP_MAC2);
LOG(logDEBUG1) << "Getting source udp mac2";
sendToDetector(F_GET_SOURCE_UDP_MAC2, nullptr, retval);
LOG(logDEBUG1) << "Source udp mac2: " << retval;
return retval;
} }
void Module::setSourceUDPIP(const IpAddr ip) { void Module::setSourceUDPIP(const IpAddr ip) {
@ -1628,16 +1584,11 @@ void Module::setSourceUDPIP(const IpAddr ip) {
if (ip == 0) { if (ip == 0) {
throw RuntimeError("Invalid source udp ip address"); throw RuntimeError("Invalid source udp ip address");
} }
sendToDetector(F_SET_SOURCE_UDP_IP, ip, nullptr); sendToDetector(F_SET_SOURCE_UDP_IP, ip, nullptr);
} }
sls::IpAddr Module::getSourceUDPIP() { sls::IpAddr Module::getSourceUDPIP() {
sls::IpAddr retval(0U); return sendToDetector<sls::IpAddr>(F_GET_SOURCE_UDP_IP);
LOG(logDEBUG1) << "Getting source udp ip";
sendToDetector(F_GET_SOURCE_UDP_IP, nullptr, retval);
LOG(logDEBUG1) << "Source udp ip: " << retval;
return retval;
} }
void Module::setSourceUDPIP2(const IpAddr ip) { void Module::setSourceUDPIP2(const IpAddr ip) {
@ -1645,16 +1596,11 @@ void Module::setSourceUDPIP2(const IpAddr ip) {
if (ip == 0) { if (ip == 0) {
throw RuntimeError("Invalid source udp ip address2"); throw RuntimeError("Invalid source udp ip address2");
} }
sendToDetector(F_SET_SOURCE_UDP_IP2, ip, nullptr); sendToDetector(F_SET_SOURCE_UDP_IP2, ip, nullptr);
} }
sls::IpAddr Module::getSourceUDPIP2() { sls::IpAddr Module::getSourceUDPIP2() {
sls::IpAddr retval(0U); return sendToDetector<sls::IpAddr>(F_GET_SOURCE_UDP_IP2);
LOG(logDEBUG1) << "Getting source udp ip2";
sendToDetector(F_GET_SOURCE_UDP_IP2, nullptr, retval);
LOG(logDEBUG1) << "Source udp ip2: " << retval;
return retval;
} }
void Module::setDestinationUDPIP(const IpAddr ip) { void Module::setDestinationUDPIP(const IpAddr ip) {
@ -3323,29 +3269,26 @@ std::array<int, 2> Module::setPatternLoopAddresses(int level, int start,
int Module::setPatternLoopCycles(int level, int n) { int Module::setPatternLoopCycles(int level, int n) {
int args[]{level, n}; int args[]{level, n};
int retval = -1;
LOG(logDEBUG1) << "Setting Pat Loop cycles, level: " << level LOG(logDEBUG1) << "Setting Pat Loop cycles, level: " << level
<< ",nloops: " << n; << ",nloops: " << n;
sendToDetector(F_SET_PATTERN_LOOP_CYCLES, args, retval); auto retval = sendToDetector<int>(F_SET_PATTERN_LOOP_CYCLES, args);
LOG(logDEBUG1) << "Set Pat Loop Cycles: " << retval; LOG(logDEBUG1) << "Set Pat Loop Cycles: " << retval;
return retval; return retval;
} }
int Module::setPatternWaitAddr(int level, int addr) { int Module::setPatternWaitAddr(int level, int addr) {
int retval = -1;
int args[]{level, addr}; int args[]{level, addr};
LOG(logDEBUG1) << "Setting Pat Wait Addr, level: " << level << ", addr: 0x" LOG(logDEBUG1) << "Setting Pat Wait Addr, level: " << level << ", addr: 0x"
<< std::hex << addr << std::dec; << std::hex << addr << std::dec;
sendToDetector(F_SET_PATTERN_WAIT_ADDR, args, retval); auto retval = sendToDetector<int>(F_SET_PATTERN_WAIT_ADDR, args);
LOG(logDEBUG1) << "Set Pat Wait Addr: " << retval; LOG(logDEBUG1) << "Set Pat Wait Addr: " << retval;
return retval; return retval;
} }
uint64_t Module::setPatternWaitTime(int level, uint64_t t) { uint64_t Module::setPatternWaitTime(int level, uint64_t t) {
uint64_t retval = -1;
uint64_t args[]{static_cast<uint64_t>(level), t}; uint64_t args[]{static_cast<uint64_t>(level), t};
LOG(logDEBUG1) << "Setting Pat Wait Time, level: " << level << ", t: " << t; LOG(logDEBUG1) << "Setting Pat Wait Time, level: " << level << ", t: " << t;
sendToDetector(F_SET_PATTERN_WAIT_TIME, args, retval); auto retval = sendToDetector<uint64_t>(F_SET_PATTERN_WAIT_TIME, args);
LOG(logDEBUG1) << "Set Pat Wait Time: " << retval; LOG(logDEBUG1) << "Set Pat Wait Time: " << retval;
return retval; return retval;
} }