This commit is contained in:
Erik Frojdh
2020-07-23 14:01:59 +02:00
parent 3ddb264875
commit 5faf3c7336
12 changed files with 49 additions and 58 deletions

View File

@ -1,9 +1,9 @@
#include "slsDetectorFunctionList.h" #include "slsDetectorFunctionList.h"
#include "RegisterDefs.h" #include "RegisterDefs.h"
#include "clogger.h" #include "clogger.h"
#include "common.h"
#include "sharedMemory.h" #include "sharedMemory.h"
#include "versionAPI.h" #include "versionAPI.h"
#include "common.h"
#include "LTC2620.h" // dacs #include "LTC2620.h" // dacs
#ifdef VIRTUAL #ifdef VIRTUAL

View File

@ -2,7 +2,6 @@
#include <stdio.h> #include <stdio.h>
/** /**
* Convert a value from a range to a different range (eg voltage to dac or vice * Convert a value from a range to a different range (eg voltage to dac or vice
* versa) * versa)
@ -17,6 +16,4 @@
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin,
int outputMax, int inputValue, int *outputValue); int outputMax, int inputValue, int *outputValue);
int getAbsPath(char *buf, size_t bufSize, char *fname);
int getAbsPath(char* buf, size_t bufSize, char* fname);

View File

@ -2,8 +2,8 @@
#include "clogger.h" #include "clogger.h"
#include "sls_detector_defs.h" #include "sls_detector_defs.h"
#include <string.h>
#include <libgen.h> // dirname #include <libgen.h> // dirname
#include <string.h>
#include <unistd.h> // readlink #include <unistd.h> // readlink
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin, int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin,
@ -42,8 +42,7 @@ int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin,
return OK; return OK;
} }
int getAbsPath(char *buf, size_t bufSize, char *fname) {
int getAbsPath(char* buf, size_t bufSize, char* fname) {
// get path of current binary // get path of current binary
char path[bufSize]; char path[bufSize];
memset(path, 0, bufSize); memset(path, 0, bufSize);
@ -58,6 +57,6 @@ int getAbsPath(char* buf, size_t bufSize, char* fname) {
char *dir = dirname(path); char *dir = dirname(path);
memset(buf, 0, bufSize); memset(buf, 0, bufSize);
sprintf(buf, "%s/%s", dir, fname); sprintf(buf, "%s/%s", dir, fname);
LOG(logDEBUG1, ("full path for %s: %s\n", fname, buf)); LOG(logDEBUG1, ("full path for %s: %s\n", fname, buf));
return OK; return OK;
} }

View File

@ -1,9 +1,9 @@
#include "readDefaultPattern.h" #include "readDefaultPattern.h"
#include "ansi.h" #include "ansi.h"
#include "clogger.h" #include "clogger.h"
#include "common.h"
#include "slsDetectorServer_defs.h" #include "slsDetectorServer_defs.h"
#include "sls_detector_defs.h" #include "sls_detector_defs.h"
#include "common.h"
#include <string.h> #include <string.h>

View File

@ -992,7 +992,7 @@ enum DACINDEX getDACIndex(enum dacIndex ind) {
default: default:
#ifdef CHIPTESTBOARDD #ifdef CHIPTESTBOARDD
if (ind < NDAC_ONLY) { if (ind < NDAC_ONLY) {
//For CTB use the index directly, no conversion // For CTB use the index directly, no conversion
serverDacIndex = (enum DACINDEX)ind; serverDacIndex = (enum DACINDEX)ind;
break; break;
} }

View File

@ -9,8 +9,8 @@
#include "sls_detector_defs.h" #include "sls_detector_defs.h"
#include "versionAPI.h" #include "versionAPI.h"
#include <fstream>
#include <chrono> #include <chrono>
#include <fstream>
#include <thread> #include <thread>
namespace sls { namespace sls {

View File

@ -14,13 +14,13 @@
#include <array> #include <array>
#include <bitset> #include <bitset>
#include <cassert> #include <cassert>
#include <cmath>
#include <chrono> #include <chrono>
#include <thread> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include <iomanip> #include <iomanip>
#include <iterator> #include <iterator>
#include <sstream> #include <sstream>
#include <thread>
namespace sls { namespace sls {
@ -933,9 +933,7 @@ void Module::setFileIndex(int64_t file_index) {
sendToReceiver(F_SET_RECEIVER_FILE_INDEX, file_index, nullptr); sendToReceiver(F_SET_RECEIVER_FILE_INDEX, file_index, nullptr);
} }
void Module::incrementFileIndex() { void Module::incrementFileIndex() { sendToReceiver(F_INCREMENT_FILE_INDEX); }
sendToReceiver(F_INCREMENT_FILE_INDEX);
}
bool Module::getFileWrite() { bool Module::getFileWrite() {
return sendToReceiver<int>(F_GET_RECEIVER_FILE_WRITE); return sendToReceiver<int>(F_GET_RECEIVER_FILE_WRITE);
@ -1391,7 +1389,7 @@ void Module::setBurstPeriod(int64_t value) {
} }
std::array<int, 2> Module::getInjectChannel() { std::array<int, 2> Module::getInjectChannel() {
return sendToDetector<std::array<int, 2> >(F_GET_INJECT_CHANNEL); return sendToDetector<std::array<int, 2>>(F_GET_INJECT_CHANNEL);
} }
void Module::setInjectChannel(const int offsetChannel, void Module::setInjectChannel(const int offsetChannel,

View File

@ -9,50 +9,50 @@ TEST_CASE("Construction with a defined detector type") {
m.freeSharedMemory(); // clean up m.freeSharedMemory(); // clean up
} }
TEST_CASE("Read back detector type from shm"){ TEST_CASE("Read back detector type from shm") {
// Create specific detector in order to create shm // Create specific detector in order to create shm
sls::Module m(dt::JUNGFRAU); sls::Module m(dt::JUNGFRAU);
// New detector that reads type from shm // New detector that reads type from shm
sls::Module m2; sls::Module m2;
REQUIRE(m2.getDetectorType()== dt::JUNGFRAU); REQUIRE(m2.getDetectorType() == dt::JUNGFRAU);
// Now both objects point to the same shm so we can only // Now both objects point to the same shm so we can only
// free one! // free one!
m2.freeSharedMemory(); m2.freeSharedMemory();
} }
TEST_CASE("Is shm fixed pattern shm compatible"){ TEST_CASE("Is shm fixed pattern shm compatible") {
sls::Module m(dt::JUNGFRAU); sls::Module m(dt::JUNGFRAU);
// Should be true since we just created the shm // Should be true since we just created the shm
REQUIRE(m.isFixedPatternSharedMemoryCompatible() == true); REQUIRE(m.isFixedPatternSharedMemoryCompatible() == true);
// Set shm version to 0 // Set shm version to 0
sls::SharedMemory<sls::sharedSlsDetector> shm(0,0); sls::SharedMemory<sls::sharedSlsDetector> shm(0, 0);
REQUIRE(shm.IsExisting()== true); REQUIRE(shm.IsExisting() == true);
shm.OpenSharedMemory(); shm.OpenSharedMemory();
shm()->shmversion = 0; shm()->shmversion = 0;
// Should fail since version is set to 0 // Should fail since version is set to 0
REQUIRE(m.isFixedPatternSharedMemoryCompatible() == false); REQUIRE(m.isFixedPatternSharedMemoryCompatible() == false);
m.freeSharedMemory(); m.freeSharedMemory();
} }
TEST_CASE("Get default control port"){ TEST_CASE("Get default control port") {
sls::Module m(dt::MYTHEN3); sls::Module m(dt::MYTHEN3);
REQUIRE(m.getControlPort() == 1952); REQUIRE(m.getControlPort() == 1952);
m.freeSharedMemory(); m.freeSharedMemory();
} }
TEST_CASE("Get default stop port"){ TEST_CASE("Get default stop port") {
sls::Module m(dt::GOTTHARD2); sls::Module m(dt::GOTTHARD2);
REQUIRE(m.getStopPort() == 1953); REQUIRE(m.getStopPort() == 1953);
m.freeSharedMemory(); m.freeSharedMemory();
} }
TEST_CASE("Get default receiver TCP port"){ TEST_CASE("Get default receiver TCP port") {
sls::Module m(dt::MYTHEN3); sls::Module m(dt::MYTHEN3);
REQUIRE(m.getReceiverPort() == 1954); REQUIRE(m.getReceiverPort() == 1954);
m.freeSharedMemory(); m.freeSharedMemory();

View File

@ -8,15 +8,15 @@
#include "ZmqSocket.h" //just for the zmq port define #include "ZmqSocket.h" //just for the zmq port define
#include "file_utils.h" #include "file_utils.h"
#include <cerrno> //eperm #include <cerrno> //eperm
#include <chrono>
#include <cstdlib> //system #include <cstdlib> //system
#include <cstring> #include <cstring>
#include <cstring> //strcpy #include <cstring> //strcpy
#include <fstream> #include <fstream>
#include <chrono>
#include <thread>
#include <iostream> #include <iostream>
#include <sys/stat.h> // stat #include <sys/stat.h> // stat
#include <thread>
#include <unistd.h> #include <unistd.h>
/** cosntructor & destructor */ /** cosntructor & destructor */

View File

@ -3,10 +3,10 @@
#define APILIB 0x200409 #define APILIB 0x200409
#define APIRECEIVER 0x200409 #define APIRECEIVER 0x200409
#define APIGUI 0x200409 #define APIGUI 0x200409
#define APICTB 0x200723 #define APICTB 0x200723
#define APIGOTTHARD 0x200723 #define APIGOTTHARD 0x200723
#define APIGOTTHARD2 0x200723 #define APIGOTTHARD2 0x200723
#define APIJUNGFRAU 0x200723 #define APIJUNGFRAU 0x200723
#define APIMYTHEN3 0x200723 #define APIMYTHEN3 0x200723
#define APIMOENCH 0x200722 #define APIMOENCH 0x200722
#define APIEIGER 0x200723 #define APIEIGER 0x200723

View File

@ -1,22 +1,21 @@
#include "ZmqSocket.h" #include "ZmqSocket.h"
#include "logger.h" #include "logger.h"
#include "network_utils.h" //ip
#include <chrono>
#include <errno.h> #include <errno.h>
#include <iostream> #include <iostream>
#include <sstream>
#include <string.h> #include <string.h>
#include <chrono>
#include <thread> #include <thread>
#include <vector> #include <vector>
#include <sstream>
#include <zmq.h> #include <zmq.h>
#include "network_utils.h" //ip
using namespace rapidjson; using namespace rapidjson;
ZmqSocket::ZmqSocket(const char *const hostname_or_ip, ZmqSocket::ZmqSocket(const char *const hostname_or_ip,
const uint32_t portnumber) const uint32_t portnumber)
: portno(portnumber), sockfd(false) : portno(portnumber), sockfd(false) {
{
// Extra check that throws if conversion fails, could be removed // Extra check that throws if conversion fails, could be removed
auto ipstr = sls::HostnameToIp(hostname_or_ip).str(); auto ipstr = sls::HostnameToIp(hostname_or_ip).str();
std::ostringstream oss; std::ostringstream oss;
oss << "tcp://" << ipstr << ":" << portno; oss << "tcp://" << ipstr << ":" << portno;
sockfd.serverAddress = oss.str(); sockfd.serverAddress = oss.str();
@ -52,8 +51,7 @@ ZmqSocket::ZmqSocket(const char *const hostname_or_ip,
} }
ZmqSocket::ZmqSocket(const uint32_t portnumber, const char *ethip) ZmqSocket::ZmqSocket(const uint32_t portnumber, const char *ethip)
:portno(portnumber), sockfd(true) : portno(portnumber), sockfd(true) {
{
// create context // create context
sockfd.contextDescriptor = zmq_ctx_new(); sockfd.contextDescriptor = zmq_ctx_new();
if (sockfd.contextDescriptor == nullptr) if (sockfd.contextDescriptor == nullptr)
@ -124,11 +122,11 @@ int ZmqSocket::SendHeader(int index, zmqHeader header) {
"\"flippedDataX\":%u, " "\"flippedDataX\":%u, "
"\"quad\":%u" "\"quad\":%u"
; //"}\n"; ; //"}\n";
memset(header_buffer.get(),'\0',MAX_STR_LENGTH); //TODO! Do we need this memset(header_buffer.get(), '\0', MAX_STR_LENGTH); // TODO! Do we need this
sprintf(header_buffer.get(), jsonHeaderFormat, header.jsonversion, header.dynamicRange, sprintf(header_buffer.get(), jsonHeaderFormat, header.jsonversion,
header.fileIndex, header.ndetx, header.ndety, header.npixelsx, header.dynamicRange, header.fileIndex, header.ndetx, header.ndety,
header.npixelsy, header.imageSize, header.acqIndex, header.npixelsx, header.npixelsy, header.imageSize, header.acqIndex,
header.frameIndex, header.progress, header.fname.c_str(), header.frameIndex, header.progress, header.fname.c_str(),
header.data ? 1 : 0, header.completeImage ? 1 : 0, header.data ? 1 : 0, header.completeImage ? 1 : 0,
@ -186,14 +184,15 @@ int ZmqSocket::SendData(char *buf, int length) {
int ZmqSocket::ReceiveHeader(const int index, zmqHeader &zHeader, int ZmqSocket::ReceiveHeader(const int index, zmqHeader &zHeader,
uint32_t version) { uint32_t version) {
const int bytes_received = const int bytes_received = zmq_recv(sockfd.socketDescriptor,
zmq_recv(sockfd.socketDescriptor, header_buffer.get(), MAX_STR_LENGTH, 0); header_buffer.get(), MAX_STR_LENGTH, 0);
if (bytes_received > 0) { if (bytes_received > 0) {
#ifdef ZMQ_DETAIL #ifdef ZMQ_DETAIL
cprintf(BLUE, "Header %d [%d] Length: %d Header:%s \n", index, portno, cprintf(BLUE, "Header %d [%d] Length: %d Header:%s \n", index, portno,
bytes_received, buffer.data()); bytes_received, buffer.data());
#endif #endif
if (ParseHeader(index, bytes_received, header_buffer.get(), zHeader, version)) { if (ParseHeader(index, bytes_received, header_buffer.get(), zHeader,
version)) {
#ifdef ZMQ_DETAIL #ifdef ZMQ_DETAIL
cprintf(RED, "Parsed Header %d [%d] Length: %d Header:%s \n", index, cprintf(RED, "Parsed Header %d [%d] Length: %d Header:%s \n", index,
portno, bytes_received, buffer.data()); portno, bytes_received, buffer.data());

View File

@ -51,7 +51,7 @@ TEST_CASE("assign module", "[support]") {
CHECK(m3.nchan == 256 * 256 * 4); CHECK(m3.nchan == 256 * 256 * 4);
} }
TEST_CASE("default construct scanParameters"){ TEST_CASE("default construct scanParameters") {
slsDetectorDefs::scanParameters p; slsDetectorDefs::scanParameters p;
CHECK(p.dacSettleTime_ns == 0); CHECK(p.dacSettleTime_ns == 0);
CHECK(p.dacInd == slsDetectorDefs::DAC_0); CHECK(p.dacInd == slsDetectorDefs::DAC_0);
@ -59,10 +59,9 @@ TEST_CASE("default construct scanParameters"){
CHECK(p.startOffset == 0); CHECK(p.startOffset == 0);
CHECK(p.stopOffset == 0); CHECK(p.stopOffset == 0);
CHECK(p.stepSize == 0); CHECK(p.stepSize == 0);
} }
TEST_CASE("compare two scanParameters"){ TEST_CASE("compare two scanParameters") {
slsDetectorDefs::scanParameters p0; slsDetectorDefs::scanParameters p0;
slsDetectorDefs::scanParameters p1; slsDetectorDefs::scanParameters p1;
@ -70,5 +69,4 @@ TEST_CASE("compare two scanParameters"){
p0.enable = 1; p0.enable = 1;
CHECK_FALSE(p0 == p1); CHECK_FALSE(p0 == p1);
} }