more of sendToDetector

This commit is contained in:
Erik Frojdh 2019-04-24 14:39:08 +02:00
parent 834b1e58ea
commit dbf927901f
5 changed files with 230 additions and 331 deletions

View File

@ -4,9 +4,19 @@
#include "tests/globals.h"
#include <iostream>
TEST_CASE("Set and get dacs", "[.eigerintegration][cli]") {
multiSlsDetector d(0, true, true);
class MultiDetectorFixture {
protected:
multiSlsDetector d;
public:
MultiDetectorFixture() : d(0, true, true) {
d.setHostname(hostname.c_str());
}
~MultiDetectorFixture() { d.freeSharedMemory(); }
};
TEST_CASE_METHOD(MultiDetectorFixture, "Set and get dacs",
"[.eigerintegration][cli]") {
auto th = 1000;
// set and read back each individual dac of EIGER
@ -64,14 +74,10 @@ TEST_CASE("Set and get dacs", "[.eigerintegration][cli]") {
CHECK(d.setDAC(-1, di::THRESHOLD, 0, 0) == -1);
CHECK(d.setDAC(-1, di::THRESHOLD, 0, 1) == -1);
}
d.freeSharedMemory();
}
TEST_CASE("Read temperatures", "[.eigerintegration][cli]") {
multiSlsDetector d(0, true, true);
d.setHostname(hostname.c_str());
TEST_CASE_METHOD(MultiDetectorFixture, "Read temperatures",
"[.eigerintegration][cli]") {
std::vector<di> tempindex{di::TEMPERATURE_FPGA, di::TEMPERATURE_FPGA2,
di::TEMPERATURE_FPGA3};
for (auto index : tempindex) {
@ -83,19 +89,15 @@ TEST_CASE("Read temperatures", "[.eigerintegration][cli]") {
}
}
int to_time(uint32_t reg){
int to_time(uint32_t reg) {
uint32_t clocks = reg >> 3;
uint32_t exponent = (reg & 0b111)+1;
return clocks*pow(10, exponent);
// clocks = register >> 3
// exponent = register & 0b111
// return clocks*10**exponent / 100e6
uint32_t exponent = (reg & 0b111) + 1;
return clocks * pow(10, exponent);
}
TEST_CASE("Read/write register", "[.eigerintegration][cli]"){
multiSlsDetector d(0, true, true);
d.setHostname(hostname.c_str());
TEST_CASE_METHOD(MultiDetectorFixture, "Read/write register",
"[.eigerintegration][cli]") {
d.setTimer(ti::MEASUREMENTS_NUMBER, 1);
d.setNumberOfFrames(1);
d.setExposureTime(10000);
d.acquire();
@ -103,5 +105,83 @@ TEST_CASE("Read/write register", "[.eigerintegration][cli]"){
d.writeRegister(0x4, 500);
CHECK(d.readRegister(0x4) == 500);
}
TEST_CASE_METHOD(MultiDetectorFixture, "Set dynamic range",
"[.eigerintegration][cli]") {
std::vector<int> dynamic_range{4, 8, 16, 32};
for (auto dr : dynamic_range) {
d.setDynamicRange(dr);
CHECK(d.setDynamicRange() == dr);
}
}
TEST_CASE_METHOD(MultiDetectorFixture, "Set clock divider",
"[.eigerintegration][cli]") {
for (int i = 0; i != 3; ++i) {
d.setSpeed(sv::CLOCK_DIVIDER, i);
CHECK(d.setSpeed(sv::CLOCK_DIVIDER) == i);
}
}
TEST_CASE_METHOD(MultiDetectorFixture, "Get time left",
"[.eigerintegration][cli]") {
CHECK_THROWS(d.getTimeLeft(ti::PROGRESS));
}
TEST_CASE_METHOD(MultiDetectorFixture, "Get ID", "[.eigerintegration][cli]") {
std::string hn = hostname;
hn.erase(std::remove(begin(hn), end(hn), 'b'), end(hn));
hn.erase(std::remove(begin(hn), end(hn), 'e'), end(hn));
auto hostnames = sls::split(hn, '+');
CHECK(hostnames.size() == d.getNumberOfDetectors());
for (int i = 0; i != d.getNumberOfDetectors(); ++i) {
CHECK(d.getId(defs::DETECTOR_SERIAL_NUMBER, 0) ==
std::stoi(hostnames[0]));
}
}
TEST_CASE_METHOD(MultiDetectorFixture, "Lock server",
"[.eigerintegration][cli]") {
d.lockServer(1);
CHECK(d.lockServer() == 1);
d.lockServer(0);
CHECK(d.lockServer() == 0);
}
TEST_CASE_METHOD(MultiDetectorFixture, "Settings", "[.eigerintegration][cli]") {
CHECK(d.setSettings(defs::STANDARD) == defs::STANDARD);
}
TEST_CASE_METHOD(MultiDetectorFixture, "Set readout flags",
"[.eigerintegration][cli]") {
d.setReadOutFlags(defs::PARALLEL);
CHECK((d.setReadOutFlags() & defs::PARALLEL));
d.setReadOutFlags(defs::NONPARALLEL);
CHECK_FALSE((d.setReadOutFlags() & defs::PARALLEL));
CHECK((d.setReadOutFlags() & defs::NONPARALLEL));
}
TEST_CASE_METHOD(MultiDetectorFixture, "Flow control 10gbe",
"[.eigerintegration][cli]") {
d.setFlowControl10G(1);
CHECK(d.setFlowControl10G() == 1);
d.setFlowControl10G(0);
CHECK(d.setFlowControl10G() == 0);
}
TEST_CASE_METHOD(MultiDetectorFixture, "activate", "[.eigerintegration][cli]") {
d.activate(0);
CHECK(d.activate() == 0);
d.activate(1);
CHECK(d.activate() == 1);
}
TEST_CASE_METHOD(MultiDetectorFixture, "all trimbits", "[.eigerintegration][cli]") {
d.setAllTrimbits(32);
CHECK(d.setAllTrimbits(-1) == 32);
}

View File

@ -15,13 +15,14 @@
// Header holding all configurations for different detectors
#include "tests/config.h"
#include "tests/globals.h"
using dt = slsDetectorDefs::detectorType;
extern std::string hostname;
extern std::string detector_type;
extern dt type;
// using dt = slsDetectorDefs::detectorType;
// extern std::string hostname;
// extern std::string detector_type;
// extern dt type;
TEST_CASE("Single detector no receiver", "[.integration][cli]") {
TEST_CASE("Single detector no receiver", "[.integration][.single]") {
auto t = slsDetector::getTypeFromDetector(hostname);
CHECK(t == type);
@ -35,9 +36,57 @@ TEST_CASE("Single detector no receiver", "[.integration][cli]") {
d.setOnline(true);
CHECK(d.getOnlineFlag() == true);
CHECK(d.setDetectorType() == type);
d.freeSharedMemory();
}
TEST_CASE("Set control port then create a new object with this control port",
"[.integration][.single]") {
/*
TODO!
Standard port but should not be hardcoded
Is this the best way to initialize the detectors
Using braces to make the object go out of scope
*/
int old_cport = DEFAULT_PORTNO;
int old_sport = DEFAULT_PORTNO + 1;
int new_cport = 1993;
int new_sport = 2000;
{
slsDetector d(type);
d.setHostname(hostname);
d.setOnline(true);
CHECK(d.getControlPort() == old_cport);
d.setControlPort(new_cport);
CHECK(d.getStopPort() == old_sport);
d.setStopPort(new_sport);
d.freeSharedMemory();
}
{
slsDetector d(type);
d.setHostname(hostname);
d.setControlPort(new_cport);
d.setStopPort(new_sport);
CHECK(d.getControlPort() == new_cport);
CHECK(d.getStopPort() == new_sport);
d.setOnline(true);
// Reset standard ports
d.setControlPort(old_cport);
d.setStopPort(old_sport);
d.freeSharedMemory();
}
slsDetector d(type);
d.setHostname(hostname);
d.setOnline(true);
CHECK(d.getStopPort() == DEFAULT_PORTNO + 1);
d.freeSharedMemory();
}
TEST_CASE("single EIGER detector no receiver basic set and get",
"[.integration][eiger]") {
// TODO! this test should take command line arguments for config
@ -91,63 +140,11 @@ TEST_CASE("single EIGER detector no receiver basic set and get",
d.freeSharedMemory();
}
TEST_CASE("Set control port then create a new object with this control port",
"[.integration]") {
/*
TODO!
Standard port but should not be hardcoded
Is this the best way to initialize the detectors
Using braces to make the object go out of scope
*/
int old_cport = DEFAULT_PORTNO;
int old_sport = DEFAULT_PORTNO + 1;
int new_cport = 1993;
int new_sport = 2000;
SingleDetectorConfig c;
{
auto type = slsDetector::getTypeFromDetector(c.hostname);
CHECK(type == c.type_enum);
slsDetector d(type);
d.setHostname(c.hostname);
d.setOnline(true);
CHECK(d.getControlPort() == old_cport);
d.setControlPort(new_cport);
CHECK(d.getStopPort() == old_sport);
d.setStopPort(new_sport);
d.freeSharedMemory();
}
{
auto type = slsDetector::getTypeFromDetector(c.hostname, new_cport);
CHECK(type == c.type_enum);
slsDetector d(type);
d.setHostname(c.hostname);
d.setControlPort(new_cport);
d.setStopPort(new_sport);
CHECK(d.getControlPort() == new_cport);
CHECK(d.getStopPort() == new_sport);
d.setOnline(true);
// Reset standard ports
d.setControlPort(old_cport);
d.setStopPort(old_sport);
d.freeSharedMemory();
}
auto type = slsDetector::getTypeFromDetector(c.hostname);
CHECK(type == c.type_enum);
TEST_CASE("Locking mechanism and last ip", "[.integration][.single]") {
slsDetector d(type);
d.setHostname(c.hostname);
d.setOnline(true);
CHECK(d.getStopPort() == DEFAULT_PORTNO + 1);
d.freeSharedMemory();
}
TEST_CASE("Locking mechanism and last ip", "[.integration]") {
SingleDetectorConfig c;
auto type = slsDetector::getTypeFromDetector(c.hostname);
slsDetector d(type);
d.setHostname(c.hostname);
d.setHostname(hostname);
d.setOnline(true);
// Check that detector server is unlocked then lock
@ -164,10 +161,18 @@ TEST_CASE("Locking mechanism and last ip", "[.integration]") {
d.lockServer(0);
CHECK(d.lockServer() == 0);
CHECK(d.getLastClientIP() == c.my_ip);
CHECK(d.getLastClientIP() == my_ip);
d.freeSharedMemory();
}
TEST_CASE("Set settings", "[.integration][.single]"){
slsDetector d(type);
d.setHostname(hostname);
d.setOnline(true);
CHECK(d.setSettings(defs::STANDARD) == defs::STANDARD);
}
TEST_CASE("Timer functions", "[.integration][cli]") {
// FRAME_NUMBER, /**< number of real time frames: total number of
// acquisitions is number or frames*number of cycles */ ACQUISITION_TIME,

View File

@ -139,10 +139,6 @@ int slsDetector::checkReceiverVersionCompatibility() {
}
int64_t slsDetector::getId(idMode mode) {
int arg = static_cast<int>(mode);
int64_t retval = -1;
FILE_LOG(logDEBUG1) << "Getting id type " << mode;
// These should not go to detector...
assert(mode != THIS_SOFTWARE_VERSION);
assert(mode != RECEIVER_VERSION);
@ -150,17 +146,13 @@ int64_t slsDetector::getId(idMode mode) {
assert(mode != CLIENT_RECEIVER_API_VERSION);
int fnum = F_GET_ID;
int ret = FAIL;
int arg = static_cast<int>(mode);
int64_t retval = -1;
FILE_LOG(logDEBUG1) << "Getting id type " << mode;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,
sizeof(retval));
}
FILE_LOG(logDEBUG1) << "Id (" << mode << "): 0x" << std::hex << retval
<< std::dec;
if (ret == FORCE_UPDATE) {
updateDetector();
sendToDetector(fnum, &arg, sizeof(arg), &retval, sizeof(retval));
FILE_LOG(logDEBUG1)
<< "Id (" << mode << "): 0x" << std::hex << retval << std::dec;
}
return retval;
}
@ -497,16 +489,10 @@ int slsDetector::setDetectorType(detectorType const type) {
// if unspecified, then get from detector
if (type == GET_DETECTOR_TYPE) {
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, nullptr, 0, &retval,
sizeof(retval));
ret = sendToDetector(fnum, nullptr, 0, &retval, sizeof(retval));
detector_shm()->myDetectorType = static_cast<detectorType>(retval);
FILE_LOG(logDEBUG1) << "Detector Type: " << retval;
}
if (ret == FORCE_UPDATE) {
ret = updateDetector();
}
} else {
ret = OK;
}
@ -619,7 +605,6 @@ int slsDetector::setOnline(int value) {
detector_shm()->onlineFlag = OFFLINE_FLAG;
if (value == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
client.close();
@ -661,16 +646,11 @@ std::string slsDetector::checkOnline() {
int slsDetector::setControlPort(int port_number) {
int fnum = F_SET_PORT;
int ret = FAIL;
int retval = -1;
FILE_LOG(logDEBUG1) << "Setting control port to " << port_number;
if (port_number >= 0 && port_number != detector_shm()->controlPort) {
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &port_number,
sizeof(port_number), &retval,
sendToDetector(fnum, &port_number, sizeof(port_number), &retval,
sizeof(retval));
detector_shm()->controlPort = retval;
FILE_LOG(logDEBUG1) << "Control port: " << retval;
@ -678,9 +658,6 @@ int slsDetector::setControlPort(int port_number) {
detector_shm()->controlPort = port_number;
}
}
if (ret == FORCE_UPDATE) {
updateDetector();
}
return detector_shm()->controlPort;
}
@ -747,39 +724,24 @@ int slsDetector::getStopPort() const { return detector_shm()->stopPort; }
int slsDetector::lockServer(int lock) {
int fnum = F_LOCK_SERVER;
int ret = FAIL;
int retval = -1;
FILE_LOG(logDEBUG1) << "Setting detector server lock to " << lock;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &lock, sizeof(lock), &retval,
sizeof(retval));
sendToDetector(fnum, &lock, sizeof(lock), &retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Lock: " << retval;
}
if (ret == FORCE_UPDATE) {
updateDetector();
}
return retval;
}
std::string slsDetector::getLastClientIP() {
int fnum = F_GET_LAST_CLIENT_IP;
int ret = FAIL;
char retval[INET_ADDRSTRLEN]{};
FILE_LOG(logDEBUG1) << "Getting last client ip to detector server";
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, nullptr, 0, &retval,
sizeof(retval));
sendToDetector(fnum, nullptr, 0, &retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Last client IP to detector: " << retval;
}
if (ret == FORCE_UPDATE) {
updateDetector();
}
return retval;
}
@ -800,16 +762,12 @@ int slsDetector::exitServer() {
int slsDetector::execCommand(const std::string &cmd) {
int fnum = F_EXEC_COMMAND;
int ret = FAIL;
char arg[MAX_STR_LENGTH] = {};
char retval[MAX_STR_LENGTH] = {};
char arg[MAX_STR_LENGTH]{};
char retval[MAX_STR_LENGTH]{};
sls::strcpy_safe(arg, cmd.c_str());
FILE_LOG(logDEBUG1) << "Sending command to detector " << arg;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, arg, sizeof(arg), retval,
sizeof(retval));
ret = sendToDetector(fnum, arg, sizeof(arg), retval, sizeof(retval));
if (strlen(retval) != 0u) {
FILE_LOG(logINFO) << "Detector " << detId << " returned:\n"
<< retval;
@ -1115,22 +1073,15 @@ slsDetector::setSettings(detectorSettings isettings) {
slsDetectorDefs::detectorSettings
slsDetector::sendSettingsOnly(detectorSettings isettings) {
int fnum = F_SET_SETTINGS;
int ret = FAIL;
int arg = static_cast<int>(isettings);
int retval = -1;
FILE_LOG(logDEBUG1) << "Setting settings to " << arg;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,
sizeof(retval));
sendToDetector(fnum, &arg, sizeof(arg), &retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Settings: " << retval;
detector_shm()->currentSettings = static_cast<detectorSettings>(retval);
}
if (ret == FORCE_UPDATE) {
updateDetector();
}
return detector_shm()->currentSettings;
}
@ -1153,22 +1104,14 @@ int slsDetector::getThresholdEnergy() {
}
}
int fnum = F_GET_THRESHOLD_ENERGY;
int ret = FAIL;
int retval = -1;
FILE_LOG(logDEBUG1) << "Getting threshold energy";
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, nullptr, 0, &retval,
sizeof(retval));
int fnum = F_GET_THRESHOLD_ENERGY;
int retval = -1;
sendToDetector(fnum, nullptr, 0, &retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Threshold: " << retval;
detector_shm()->currentThresholdEV = retval;
}
if (ret == FORCE_UPDATE) {
updateDetector();
}
return detector_shm()->currentThresholdEV;
}
@ -1630,10 +1573,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t) {
// send to detector
int64_t oldtimer = detector_shm()->timerValue[index];
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, args, sizeof(args), &retval,
sizeof(retval));
ret = sendToDetector(fnum, args, sizeof(args), &retval, sizeof(retval));
FILE_LOG(logDEBUG1) << getTimerType(index) << ": " << retval;
detector_shm()->timerValue[index] = retval;
// update #nchans and databytes, as it depends on #samples, roi,
@ -1643,10 +1583,6 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t) {
detector_shm()->myDetectorType == MOENCH)) {
updateTotalNumberOfChannels();
}
if (ret == FORCE_UPDATE) {
client.close();
ret = updateDetector();
}
}
// setting timers consequences (eiger (ratecorr) )
@ -1666,7 +1602,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t) {
}
// send to reciever
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG && ret == OK) {
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG && ret != FAIL) {
auto receiver = ReceiverSocket(detector_shm()->receiver_hostname,
detector_shm()->receiverTCPPort);
// char mess[MAX_STR_LENGTH]{};
@ -1739,22 +1675,15 @@ int64_t slsDetector::getTimeLeft(timerIndex index) {
int slsDetector::setSpeed(speedVariable sp, int value, int mode) {
int fnum = F_SET_SPEED;
int ret = FAIL;
int args[]{static_cast<int>(sp), value, mode};
int retval = -1;
FILE_LOG(logDEBUG1) << "Setting speed index " << sp << " to " << value
<< " mode: " << mode;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, args, sizeof(args), &retval,
sizeof(retval));
sendToDetector(fnum, args, sizeof(args), &retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Speed index " << sp << ": " << retval;
}
if (ret == FORCE_UPDATE) {
updateDetector();
}
return retval;
}
@ -1765,20 +1694,12 @@ int slsDetector::setDynamicRange(int n) {
int retval = -1;
FILE_LOG(logDEBUG1) << "Setting dynamic range to " << n;
// send to detector
int olddr = detector_shm()->dynamicRange;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
// char mess[MAX_STR_LENGTH] = {};
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &n, sizeof(n), &retval,
sizeof(retval));
sendToDetector(fnum, &n, sizeof(n), &retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Dynamic Range: " << retval;
detector_shm()->dynamicRange = retval;
if (ret == FORCE_UPDATE) {
client.close();
ret = updateDetector();
}
}
// only for eiger
@ -1838,15 +1759,15 @@ int slsDetector::setDAC(int val, dacIndex index, int mV) {
return retval;
}
int slsDetector::sendToDetector(int fnum, void* args, size_t args_size, void* retval, size_t retval_size)
{
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
auto ret = client.sendCommandThenRead(fnum, args, args_size, retval, retval_size);
int slsDetector::sendToDetector(int fnum, void *args, size_t args_size,
void *retval, size_t retval_size) {
auto client =
DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort);
auto ret =
client.sendCommandThenRead(fnum, args, args_size, retval, retval_size);
client.close();
if (ret == FORCE_UPDATE) {
updateDetector();
ret = updateDetector();
}
return ret;
}
@ -1912,10 +1833,7 @@ int slsDetector::setReadOutFlags(readOutFlags flag) {
FILE_LOG(logDEBUG1) << "Setting readout flags to " << flag;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,
sizeof(retval));
ret = sendToDetector(fnum, &arg, sizeof(arg), &retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Readout flag: " << retval;
detector_shm()->roFlags = retval;
// update #nchans and databytes, as it depends on #samples, roi,
@ -1924,9 +1842,6 @@ int slsDetector::setReadOutFlags(readOutFlags flag) {
updateTotalNumberOfChannels();
}
}
if (ret == FORCE_UPDATE) {
ret = updateDetector();
}
// sending to receiver
if (ret != FAIL) {
@ -2448,23 +2363,16 @@ std::string slsDetector::getReceiverStreamingIP() {
int slsDetector::setDetectorNetworkParameter(networkParameter index,
int delay) {
int fnum = F_SET_NETWORK_PARAMETER;
int ret = FAIL;
int args[2]{static_cast<int>(index), delay};
int retval = -1;
FILE_LOG(logDEBUG1) << "Setting network parameter index " << index << " to "
<< delay;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, args, sizeof(args), &retval,
sizeof(retval));
sendToDetector(fnum, args, sizeof(args), &retval, sizeof(retval));
FILE_LOG(logDEBUG1)
<< "Network Parameter (" << index << "): " << retval;
}
if (ret == FORCE_UPDATE) {
updateDetector();
}
return retval;
}
@ -2728,22 +2636,15 @@ int slsDetector::setUDPConnection() {
int slsDetector::digitalTest(digitalTestMode mode, int ival) {
int fnum = F_DIGITAL_TEST;
int ret = FAIL;
int args[2]{static_cast<int>(mode), ival};
int args[]{static_cast<int>(mode), ival};
int retval = -1;
FILE_LOG(logDEBUG1) << "Sending digital test of mode " << mode << ", ival "
<< ival;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, args, sizeof(args), &retval,
sizeof(retval));
sendToDetector(fnum, args, sizeof(args), &retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Digital Test returned: " << retval;
}
if (ret == FORCE_UPDATE) {
updateDetector();
}
return retval;
}
@ -2810,18 +2711,13 @@ int slsDetector::getCounterBlock(int16_t image[], int startACQ) {
int fnum = F_READ_COUNTER_BLOCK;
int ret = FAIL;
int nChan = getTotalNumberOfChannels();
int args[2] = {startACQ, nChan};
int args[] = {startACQ, nChan};
FILE_LOG(logDEBUG1) << "Reading Counter block with startacq: " << startACQ;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, args, sizeof(args), image,
ret = sendToDetector(fnum, args, sizeof(args), image,
nChan * sizeof(int16_t));
}
if (ret == FORCE_UPDATE) {
ret = updateDetector();
}
return ret;
}
@ -2830,35 +2726,20 @@ int slsDetector::resetCounterBlock(int startACQ) {
int ret = FAIL;
int arg = startACQ;
FILE_LOG(logDEBUG1) << "Resetting Counter with startacq: " << startACQ;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), nullptr, 0);
}
if (ret == FORCE_UPDATE) {
ret = updateDetector();
ret = sendToDetector(fnum, &arg, sizeof(arg), nullptr, 0);
}
return ret;
}
int slsDetector::setCounterBit(int i) {
int fnum = F_SET_COUNTER_BIT;
int ret = FAIL;
int arg = i;
int retval = -1;
FILE_LOG(logDEBUG1) << "Sending counter bit " << arg;
FILE_LOG(logDEBUG1) << "Sending counter bit " << i;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,
sizeof(retval));
sendToDetector(fnum, &i, sizeof(i), &retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Counter bit: " << retval;
}
if (ret == FORCE_UPDATE) {
updateDetector();
}
return retval;
}
@ -3022,12 +2903,7 @@ int slsDetector::writeAdcRegister(uint32_t addr, uint32_t val) {
<< "data: 0x" << std::hex << val << std::dec;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, args, sizeof(args), nullptr, 0);
}
if (ret == FORCE_UPDATE) {
ret = updateDetector();
ret = sendToDetector(fnum, args, sizeof(args), nullptr, 0);
}
return ret;
}
@ -3041,16 +2917,10 @@ int slsDetector::activate(int enable) {
// detector
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,
sizeof(retval));
ret = sendToDetector(fnum, &arg, sizeof(arg), &retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Activate: " << retval;
detector_shm()->activated = static_cast<bool>(retval);
}
if (ret == FORCE_UPDATE) {
ret = updateDetector();
}
// receiver
if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG && ret == OK) {
@ -3131,21 +3001,12 @@ int slsDetector::setFlippedData(dimension d, int value) {
int slsDetector::setAllTrimbits(int val) {
int fnum = F_SET_ALL_TRIMBITS;
int ret = FAIL;
int arg = val;
int retval = -1;
FILE_LOG(logDEBUG1) << "Setting all trimbits to " << val;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,
sizeof(retval));
sendToDetector(fnum, &val, sizeof(val), &retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "All trimbit value: " << retval;
}
if (ret == FORCE_UPDATE) {
updateDetector();
}
return retval;
}
@ -3213,17 +3074,11 @@ std::vector<int> slsDetector::getTrimEn() {
int slsDetector::pulsePixel(int n, int x, int y) {
int fnum = F_PULSE_PIXEL;
int ret = FAIL;
int args[3] = {n, x, y};
int args[]{n, x, y};
FILE_LOG(logDEBUG1) << "Pulsing pixel " << n << " number of times at (" << x
<< "," << y << ")";
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, args, sizeof(args), nullptr, 0);
}
if (ret == FORCE_UPDATE) {
ret = updateDetector();
ret = sendToDetector(fnum, args, sizeof(args), nullptr, 0);
}
return ret;
}
@ -3231,18 +3086,12 @@ int slsDetector::pulsePixel(int n, int x, int y) {
int slsDetector::pulsePixelNMove(int n, int x, int y) {
int fnum = F_PULSE_PIXEL_AND_MOVE;
int ret = FAIL;
int args[3] = {n, x, y};
int args[]{n, x, y};
FILE_LOG(logDEBUG1) << "Pulsing pixel " << n
<< " number of times and move by delta (" << x << ","
<< y << ")";
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, args, sizeof(args), nullptr, 0);
}
if (ret == FORCE_UPDATE) {
ret = updateDetector();
ret = sendToDetector(fnum, args, sizeof(args), nullptr, 0);
}
return ret;
}
@ -3250,16 +3099,9 @@ int slsDetector::pulsePixelNMove(int n, int x, int y) {
int slsDetector::pulseChip(int n) {
int fnum = F_PULSE_CHIP;
int ret = FAIL;
int arg = n;
FILE_LOG(logDEBUG1) << "Pulsing chip " << n << " number of times";
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), nullptr, 0);
}
if (ret == FORCE_UPDATE) {
ret = updateDetector();
ret = sendToDetector(fnum, &n, sizeof(n), nullptr, 0);
}
return ret;
}
@ -3317,21 +3159,12 @@ int slsDetector::setTemperatureEvent(int val) {
int slsDetector::setStoragecellStart(int pos) {
int fnum = F_STORAGE_CELL_START;
int ret = FAIL;
int arg = pos;
int retval = -1;
FILE_LOG(logDEBUG1) << "Setting storage cell start to " << pos;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,
sizeof(retval));
sendToDetector(fnum, &pos, sizeof(pos), &retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Storage cell start: " << retval;
}
if (ret == FORCE_UPDATE) {
updateDetector();
}
return retval;
}
@ -3445,12 +3278,7 @@ int slsDetector::resetFPGA() {
int ret = FAIL;
FILE_LOG(logDEBUG1) << "Sending reset FPGA";
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0);
}
if (ret == FORCE_UPDATE) {
ret = updateDetector();
ret = sendToDetector(fnum, nullptr, 0, nullptr, 0);
}
return ret;
}
@ -3459,15 +3287,13 @@ int slsDetector::copyDetectorServer(const std::string &fname,
const std::string &hostname) {
int fnum = F_COPY_DET_SERVER;
int ret = FAIL;
char args[2][MAX_STR_LENGTH] = {};
char args[][MAX_STR_LENGTH]{};
sls::strcpy_safe(args[0], fname.c_str());
sls::strcpy_safe(args[1], hostname.c_str());
FILE_LOG(logINFO) << "Sending detector server " << args[0] << " from host "
<< args[1];
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, args, sizeof(args), nullptr, 0);
ret = sendToDetector(fnum, args, sizeof(args), nullptr, 0);
}
return ret;
}
@ -3493,45 +3319,26 @@ int slsDetector::rebootController() {
int slsDetector::powerChip(int ival) {
int fnum = F_POWER_CHIP;
int ret = FAIL;
int arg = ival;
int retval = -1;
FILE_LOG(logDEBUG1) << "Setting power chip to " << ival;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,
sizeof(retval));
sendToDetector(fnum, &ival, sizeof(ival), &retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Power chip: " << retval;
}
if (ret == FORCE_UPDATE) {
updateDetector();
}
return retval;
}
int slsDetector::setAutoComparatorDisableMode(int ival) {
int fnum = F_AUTO_COMP_DISABLE;
int ret = FAIL;
int arg = ival;
int retval = -1;
FILE_LOG(logDEBUG1) << "Setting auto comp disable mode to " << ival;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval,
sizeof(retval));
sendToDetector(fnum, &ival, sizeof(ival), &retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Auto comp disable: " << retval;
}
if (ret == FORCE_UPDATE) {
updateDetector();
}
return retval;
}
int slsDetector::setModule(sls_detector_module& module, int tb) {
int fnum = F_SET_MODULE;
int ret = FAIL;

View File

@ -3,6 +3,9 @@ using dt = slsDetectorDefs::detectorType;
using di = slsDetectorDefs::dacIndex;
using ti = slsDetectorDefs::timerIndex;
using ro = slsDetectorDefs::readOutFlags;
using sv = slsDetectorDefs::speedVariable;
using defs = slsDetectorDefs;
extern std::string hostname;
extern std::string detector_type;
extern dt type;
extern std::string my_ip;

View File

@ -14,16 +14,20 @@ using dt = slsDetectorDefs::detectorType;
std::string hostname;
std::string detector_type;
std::string my_ip;
dt type;
int main(int argc, char *argv[]) {
Catch::Session session;
my_ip = "undefined";
Catch::Session session;
auto cli = session.cli() |
Opt(hostname, "hostname")["-hn"]["--hostname"](
"Detector hostname for integration tests") |
Opt(detector_type, "detector_type")["-dt"]["--detector_type"](
"Detector type for integration tests");
"Detector type for integration tests") |
Opt(my_ip, "my_ip")["-hip"]["--host_ip"](
"Host ip address");
session.cli(cli);