Merge pull request #111 from slsdetectorgroup/shm

Shm
This commit is contained in:
Dhanya Thattil
2020-07-07 13:35:52 +02:00
committed by GitHub
50 changed files with 1646 additions and 1170 deletions

View File

@ -16,7 +16,7 @@ add_executable(ctbDetectorServer_virtual
../slsDetectorServer/src/LTC2620.c ../slsDetectorServer/src/LTC2620.c
../slsDetectorServer/src/MAX1932.c ../slsDetectorServer/src/MAX1932.c
../slsDetectorServer/src/programFpgaBlackfin.c ../slsDetectorServer/src/programFpgaBlackfin.c
../slsDetectorServer/src/communication_virtual.c ../slsDetectorServer/src/sharedMemory.c
) )
include_directories( include_directories(

View File

@ -6,13 +6,13 @@ support_lib = ../../slsSupportLib/include/
CROSS = bfin-uclinux- CROSS = bfin-uclinux-
CC = $(CROSS)gcc CC = $(CROSS)gcc
CFLAGS += -Wall -std=gnu99 -DCHIPTESTBOARDD -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir) #-DDEBUG1 #-DVERBOSEI #-DVERBOSE CFLAGS += -Wall -std=gnu99 -DCHIPTESTBOARDD -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir) #-DDEBUG1 #-DVERBOSEI #-DVERBOSE
LDLIBS += -lm LDLIBS += -lm -lrt -pthread
PROGS = ctbDetectorServer PROGS = ctbDetectorServer
DESTDIR ?= bin DESTDIR ?= bin
INSTMODE = 0777 INSTMODE = 0777
SRCS = slsDetectorFunctionList.c SRCS = slsDetectorFunctionList.c
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)communication_funcs_UDP.c $(main_src)UDPPacketHeaderGenerator.c $(main_src)AD7689.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)I2C.c $(main_src)INA226.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programFpgaBlackfin.c SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)communication_funcs_UDP.c $(main_src)UDPPacketHeaderGenerator.c $(main_src)AD7689.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)I2C.c $(main_src)INA226.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programFpgaBlackfin.c $(main_src)/sharedMemory.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)

View File

@ -1,5 +1,6 @@
#include "slsDetectorFunctionList.h" #include "slsDetectorFunctionList.h"
#include "clogger.h" #include "clogger.h"
#include "sharedMemory.h"
#include "versionAPI.h" #include "versionAPI.h"
#include "AD7689.h" // slow adcs #include "AD7689.h" // slow adcs
@ -10,9 +11,6 @@
#include "UDPPacketHeaderGenerator.h" #include "UDPPacketHeaderGenerator.h"
#include "common.h" #include "common.h"
#include "communication_funcs_UDP.h" #include "communication_funcs_UDP.h"
#ifdef VIRTUAL
#include "communication_virtual.h"
#endif
#include <netinet/in.h> #include <netinet/in.h>
#include <string.h> #include <string.h>
@ -43,9 +41,8 @@ char initErrorMessage[MAX_STR_LENGTH];
#ifdef VIRTUAL #ifdef VIRTUAL
pthread_t pthread_virtual_tid; pthread_t pthread_virtual_tid;
int virtual_status = 0;
int virtual_stop = 0;
uint64_t virtual_pattern[MAX_PATTERN_LENGTH]; uint64_t virtual_pattern[MAX_PATTERN_LENGTH];
int64_t virtual_currentFrameNumber = 2;
#endif #endif
// 1g readout // 1g readout
@ -435,10 +432,7 @@ void initStopServer() {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_stop = 0; sharedMemory_setStop(0);
if (!isControlServer) {
ComVirtual_setStop(virtual_stop);
}
#endif #endif
} }
@ -481,10 +475,7 @@ void setupDetector() {
naSamples = 1; naSamples = 1;
ndSamples = 1; ndSamples = 1;
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
memset(virtual_pattern, 0, sizeof(virtual_pattern)); memset(virtual_pattern, 0, sizeof(virtual_pattern));
#endif #endif
@ -2222,22 +2213,15 @@ int startStateMachine() {
return FAIL; return FAIL;
} }
LOG(logINFOBLUE, ("Starting State Machine\n")); LOG(logINFOBLUE, ("Starting State Machine\n"));
virtual_status = 1; if (sharedMemory_getStop() != 0) {
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
virtual_stop = ComVirtual_getStop();
if (virtual_stop != 0) {
LOG(logERROR, ("Cant start acquisition. " LOG(logERROR, ("Cant start acquisition. "
"Stop server has not updated stop status to 0\n")); "Stop server has not updated stop status to 0\n"));
return FAIL; return FAIL;
} }
} sharedMemory_setStatus(RUNNING);
if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) { if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
LOG(logERROR, ("Could not start Virtual acquisition thread\n")); LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
return FAIL; return FAIL;
} }
LOG(logINFOGREEN, ("Virtual Acquisition started\n")); LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
@ -2295,14 +2279,11 @@ void *start_timer(void *arg) {
} }
// Send data // Send data
{
// loop over number of frames // loop over number of frames
for (int frameNr = 0; frameNr != numFrames; ++frameNr) { for (int frameNr = 0; frameNr != numFrames; ++frameNr) {
// update the virtual stop from stop server // check if manual stop
virtual_stop = ComVirtual_getStop(); if (sharedMemory_getStop() == 1) {
// check if virtual_stop is high
if (virtual_stop == 1) {
break; break;
} }
@ -2318,11 +2299,10 @@ void *start_timer(void *arg) {
char packetData[packetSize]; char packetData[packetSize];
memset(packetData, 0, packetSize); memset(packetData, 0, packetSize);
// set header // set header
sls_detector_header *header = sls_detector_header *header = (sls_detector_header *)(packetData);
(sls_detector_header *)(packetData);
header->detType = (uint16_t)myDetectorType; header->detType = (uint16_t)myDetectorType;
header->version = SLS_DETECTOR_HEADER_VERSION - 1; header->version = SLS_DETECTOR_HEADER_VERSION - 1;
header->frameNumber = frameNr; header->frameNumber = virtual_currentFrameNumber;
header->packetNumber = i; header->packetNumber = i;
header->modId = 0; header->modId = 0;
header->row = detPos[X]; header->row = detPos[X];
@ -2335,10 +2315,11 @@ void *start_timer(void *arg) {
sendUDPPacket(0, packetData, packetSize); sendUDPPacket(0, packetData, packetSize);
} }
LOG(logINFO, ("Sent frame: %d\n", frameNr)); LOG(logINFO, ("Sent frame: %d [%lld]\n", frameNr,
(long long unsigned int)virtual_currentFrameNumber));
clock_gettime(CLOCK_REALTIME, &end); clock_gettime(CLOCK_REALTIME, &end);
int64_t timeNs = ((end.tv_sec - begin.tv_sec) * 1E9 + int64_t timeNs =
(end.tv_nsec - begin.tv_nsec)); ((end.tv_sec - begin.tv_sec) * 1E9 + (end.tv_nsec - begin.tv_nsec));
// sleep for (period - exptime) // sleep for (period - exptime)
if (frameNr < numFrames) { // if there is a next frame if (frameNr < numFrames) { // if there is a next frame
@ -2346,15 +2327,12 @@ void *start_timer(void *arg) {
usleep((periodNs - timeNs) / 1000); usleep((periodNs - timeNs) / 1000);
} }
} }
} ++virtual_currentFrameNumber;
} }
closeUDPSocket(0); closeUDPSocket(0);
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
LOG(logINFOBLUE, ("Finished Acquiring\n")); LOG(logINFOBLUE, ("Finished Acquiring\n"));
return NULL; return NULL;
} }
@ -2362,46 +2340,47 @@ void *start_timer(void *arg) {
int stopStateMachine() { int stopStateMachine() {
LOG(logINFORED, ("Stopping State Machine\n")); LOG(logINFORED, ("Stopping State Machine\n"));
// if scan active, stop scan first
if (sharedMemory_getScanStatus() == RUNNING) {
sharedMemory_setScanStop(1);
}
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { sharedMemory_setStop(1);
virtual_stop = 1;
ComVirtual_setStop(virtual_stop);
// read till status is idle // read till status is idle
int tempStatus = 1; while (sharedMemory_getStatus() == RUNNING)
while (tempStatus == 1) { ;
tempStatus = ComVirtual_getStatus(); sharedMemory_setStop(0);
}
virtual_stop = 0;
ComVirtual_setStop(virtual_stop);
LOG(logINFO, ("Stopped State Machine\n")); LOG(logINFO, ("Stopped State Machine\n"));
}
return OK; return OK;
#endif #endif
// stop state machine // stop state machine
bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_STP_ACQSTN_MSK); bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_STP_ACQSTN_MSK);
usleep(WAIT_TIME_US_STP_ACQ); usleep(WAIT_TIME_US_STP_ACQ);
bus_w(CONTROL_REG, bus_r(CONTROL_REG) & ~CONTROL_STP_ACQSTN_MSK); bus_w(CONTROL_REG, bus_r(CONTROL_REG) & ~CONTROL_STP_ACQSTN_MSK);
LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG))); LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG)));
return OK; return OK;
} }
enum runStatus getRunStatus() { enum runStatus getRunStatus() {
#ifdef VIRTUAL LOG(logDEBUG1, ("Getting status\n"));
if (!isControlServer) { // scan error or running
virtual_status = ComVirtual_getStatus(); if (sharedMemory_getScanStatus() == ERROR) {
LOG(logINFOBLUE, ("Status: scan ERROR\n"));
return ERROR;
} }
if (virtual_status == 0) { if (sharedMemory_getScanStatus() == RUNNING) {
LOG(logINFOBLUE, ("Status: IDLE\n")); LOG(logINFOBLUE, ("Status: scan RUNNING\n"));
return IDLE; return RUNNING;
} else { }
#ifdef VIRTUAL
if (sharedMemory_getStatus() == RUNNING) {
LOG(logINFOBLUE, ("Status: RUNNING\n")); LOG(logINFOBLUE, ("Status: RUNNING\n"));
return RUNNING; return RUNNING;
} }
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
#endif #endif
LOG(logDEBUG1, ("Getting status\n"));
uint32_t retval = bus_r(STATUS_REG); uint32_t retval = bus_r(STATUS_REG);
LOG(logINFO, ("Status Register: %08x\n", retval)); LOG(logINFO, ("Status Register: %08x\n", retval));
@ -2672,10 +2651,7 @@ int readFrameFromFifo() {
uint32_t runBusy() { uint32_t runBusy() {
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { return ((sharedMemory_getStatus() == RUNNING) ? 1 : 0);
virtual_status = ComVirtual_getStatus();
}
return virtual_status;
#endif #endif
uint32_t s = (bus_r(STATUS_REG) & STATUS_RN_BSY_MSK); uint32_t s = (bus_r(STATUS_REG) & STATUS_RN_BSY_MSK);
// LOG(logDEBUG1, ("Status Register: %08x\n", s)); // LOG(logDEBUG1, ("Status Register: %08x\n", s));

View File

@ -5,7 +5,7 @@ set(src
../slsDetectorServer/src/communication_funcs.c ../slsDetectorServer/src/communication_funcs.c
../slsDetectorServer/src/communication_funcs_UDP.c ../slsDetectorServer/src/communication_funcs_UDP.c
../slsDetectorServer/src/common.c ../slsDetectorServer/src/common.c
../slsDetectorServer/src/communication_virtual.c ../slsDetectorServer/src/sharedMemory.c
) )
include_directories( include_directories(

View File

@ -7,13 +7,13 @@ BLACKFIN_CC = bfin-uclinux-gcc
CROSS = powerpc-4xx-softfloat- CROSS = powerpc-4xx-softfloat-
CC = $(CROSS)gcc CC = $(CROSS)gcc
CFLAGS += -Wall -std=gnu99 -DEIGERD -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir) #-DDEBUG1 #-DVERBOSEI #-DVERBOSE CFLAGS += -Wall -std=gnu99 -DEIGERD -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir) #-DDEBUG1 #-DVERBOSEI #-DVERBOSE
LDLIBS += -lm LDLIBS += -lm -lrt -pthread
PROGS = eigerDetectorServer PROGS = eigerDetectorServer
DESTDIR = bin DESTDIR = bin
INSTMODE = 0777 INSTMODE = 0777
SRCS = slsDetectorFunctionList.c HardwareIO.c LocalLinkInterface.c FebInterface.c FebControl.c Beb.c SRCS = slsDetectorFunctionList.c HardwareIO.c LocalLinkInterface.c FebInterface.c FebControl.c Beb.c
SRCS += $(main_src)communication_funcs.c $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs_UDP.c $(main_src)common.c SRCS += $(main_src)communication_funcs.c $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs_UDP.c $(main_src)common.c $(main_src)/sharedMemory.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)

View File

@ -1,13 +1,12 @@
#include "slsDetectorFunctionList.h" #include "slsDetectorFunctionList.h"
#include "clogger.h" #include "clogger.h"
#include "common.h" #include "common.h"
#include "sharedMemory.h"
#include "versionAPI.h" #include "versionAPI.h"
#ifndef VIRTUAL #ifndef VIRTUAL
#include "Beb.h" #include "Beb.h"
#include "FebControl.h" #include "FebControl.h"
#else
#include "communication_virtual.h"
#endif #endif
#include <string.h> #include <string.h>
@ -71,8 +70,6 @@ int eiger_tau_ns = 0;
#ifdef VIRTUAL #ifdef VIRTUAL
pthread_t virtual_tid; pthread_t virtual_tid;
int virtual_status = 0;
int virtual_stop = 0;
// values for virtual server // values for virtual server
int64_t eiger_virtual_exptime = 0; int64_t eiger_virtual_exptime = 0;
int64_t eiger_virtual_subexptime = 0; int64_t eiger_virtual_subexptime = 0;
@ -251,7 +248,8 @@ u_int64_t getDetectorMAC() {
// execute and get address // execute and get address
char output[255]; char output[255];
#ifdef VIRTUAL #ifdef VIRTUAL
FILE *sysFile = popen("cat /sys/class/net/$(ip route show default | awk " FILE *sysFile =
popen("cat /sys/class/net/$(ip route show default | grep -v vpn | awk "
"'/default/ {print $5}')/address", "'/default/ {print $5}')/address",
"r"); "r");
#else #else
@ -288,7 +286,8 @@ u_int32_t getDetectorIP() {
// execute and get address // execute and get address
char output[255]; char output[255];
#ifdef VIRTUAL #ifdef VIRTUAL
FILE *sysFile = popen("ifconfig $(ip route show default | awk '/default/ " FILE *sysFile =
popen("ifconfig $(ip route show default | grep -v vpn | awk '/default/ "
"{print $5}') | grep 'inet ' | cut -d ' ' -f10", "{print $5}') | grep 'inet ' | cut -d ' ' -f10",
"r"); "r");
#else #else
@ -363,10 +362,7 @@ void initStopServer() {
#ifdef VIRTUAL #ifdef VIRTUAL
LOG(logINFOBLUE, ("Configuring Stop server\n")); LOG(logINFOBLUE, ("Configuring Stop server\n"));
getModuleConfiguration(); getModuleConfiguration();
virtual_stop = 0; sharedMemory_setStop(0);
if (!isControlServer) {
ComVirtual_setStop(virtual_stop);
}
// get top/master in virtual // get top/master in virtual
readConfigFile(); readConfigFile();
#else #else
@ -668,10 +664,7 @@ void setupDetector() {
} }
} }
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
#endif #endif
LOG(logINFOBLUE, ("Setting Default Parameters\n")); LOG(logINFOBLUE, ("Setting Default Parameters\n"));
@ -1274,6 +1267,7 @@ int setHighVoltage(int val) {
if (master) { if (master) {
// set // set
if (val != -1) { if (val != -1) {
LOG(logINFO, ("Setting High voltage: %d V\n", val));
eiger_theo_highvoltage = val; eiger_theo_highvoltage = val;
} }
return eiger_theo_highvoltage; return eiger_theo_highvoltage;
@ -1986,33 +1980,26 @@ int startStateMachine() {
return FAIL; return FAIL;
} }
LOG(logINFOBLUE, ("Starting State Machine\n")); LOG(logINFOBLUE, ("Starting State Machine\n"));
virtual_status = 1; if (sharedMemory_getStop() != 0) {
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
virtual_stop = ComVirtual_getStop();
if (virtual_stop != 0) {
LOG(logERROR, ("Cant start acquisition. " LOG(logERROR, ("Cant start acquisition. "
"Stop server has not updated stop status to 0\n")); "Stop server has not updated stop status to 0\n"));
return FAIL; return FAIL;
} }
} sharedMemory_setStatus(RUNNING);
if (pthread_create(&virtual_tid, NULL, &start_timer, NULL)) { if (pthread_create(&virtual_tid, NULL, &start_timer, NULL)) {
LOG(logERROR, ("Could not start Virtual acquisition thread\n")); LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
return FAIL; return FAIL;
} }
LOG(logINFO, ("Virtual Acquisition started\n")); LOG(logINFO, ("Virtual Acquisition started\n"));
return OK; return OK;
#else #else
LOG(logINFOBLUE, ("Starting State Machine\n")); LOG(logINFO, ("Acquisition started bit toggled\n"));
int ret = OK, prev_flag; int ret = OK, prev_flag;
// get the DAQ toggle bit // get the DAQ toggle bit
prev_flag = Feb_Control_AcquisitionStartedBit(); prev_flag = Feb_Control_AcquisitionStartedBit();
LOG(logINFO, ("Going to start acquisition\n")); LOG(logINFOBLUE, ("Starting State Machine\n"));
Feb_Control_StartAcquisition(); Feb_Control_StartAcquisition();
LOG(logINFO, ("requesting images right after start\n")); LOG(logINFO, ("requesting images right after start\n"));
@ -2106,10 +2093,8 @@ void *start_timer(void *arg) {
usleep(eiger_virtual_transmission_delay_frame); usleep(eiger_virtual_transmission_delay_frame);
// update the virtual stop from stop server // check if manual stop
virtual_stop = ComVirtual_getStop(); if (sharedMemory_getStop() == 1) {
// check if virtual_stop is high
if (virtual_stop == 1) {
setStartingFrameNumber(frameNr + iframes + 1); setStartingFrameNumber(frameNr + iframes + 1);
break; break;
} }
@ -2208,30 +2193,25 @@ void *start_timer(void *arg) {
closeUDPSocket(0); closeUDPSocket(0);
closeUDPSocket(1); closeUDPSocket(1);
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
LOG(logINFOBLUE, ("Finished Acquiring\n")); LOG(logINFOBLUE, ("Finished Acquiring\n"));
return NULL; return NULL;
} }
#endif #endif
int stopStateMachine() { int stopStateMachine() {
LOG(logINFORED, ("Going to stop acquisition\n")); LOG(logINFORED, ("Stopping state machine\n"));
// if scan active, stop scan
if (sharedMemory_getScanStatus() == RUNNING) {
sharedMemory_setScanStop(1);
}
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { sharedMemory_setStop(1);
virtual_stop = 1;
ComVirtual_setStop(virtual_stop);
// read till status is idle // read till status is idle
int tempStatus = 1; while (sharedMemory_getStatus() == RUNNING)
while (tempStatus == 1) { ;
tempStatus = ComVirtual_getStatus(); sharedMemory_setStop(0);
}
virtual_stop = 0;
ComVirtual_setStop(virtual_stop);
LOG(logINFO, ("Stopped State Machine\n")); LOG(logINFO, ("Stopped State Machine\n"));
}
return OK; return OK;
#else #else
if ((Feb_Control_StopAcquisition() != STATUS_IDLE) || if ((Feb_Control_StopAcquisition() != STATUS_IDLE) ||
@ -2287,19 +2267,24 @@ int startReadOut() {
} }
enum runStatus getRunStatus() { enum runStatus getRunStatus() {
#ifdef VIRTUAL LOG(logDEBUG1, ("Getting status\n"));
if (!isControlServer) { // scan error or running
virtual_status = ComVirtual_getStatus(); if (sharedMemory_getScanStatus() == ERROR) {
LOG(logINFOBLUE, ("Status: scan ERROR\n"));
return ERROR;
} }
if (virtual_status == 0) { if (sharedMemory_getScanStatus() == RUNNING) {
LOG(logINFO, ("Status: IDLE\n")); LOG(logINFOBLUE, ("Status: scan RUNNING\n"));
return IDLE;
} else {
LOG(logINFO, ("Status: RUNNING...\n"));
return RUNNING; return RUNNING;
} }
#ifdef VIRTUAL
if (sharedMemory_getStatus() == RUNNING) {
LOG(logINFOBLUE, ("Status: RUNNING\n"));
return RUNNING;
}
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
#else #else
int i = Feb_Control_AcquisitionInProgress(); int i = Feb_Control_AcquisitionInProgress();
if (i == STATUS_ERROR) { if (i == STATUS_ERROR) {
LOG(logERROR, ("Status: ERROR reading status register\n")); LOG(logERROR, ("Status: ERROR reading status register\n"));
@ -2324,7 +2309,7 @@ enum runStatus getRunStatus() {
void readFrame(int *ret, char *mess) { void readFrame(int *ret, char *mess) {
#ifdef VIRTUAL #ifdef VIRTUAL
// wait for status to be done // wait for status to be done
while (virtual_status == 1) { while (sharedMemory_getStatus() == RUNNING) {
usleep(500); usleep(500);
} }
LOG(logINFOGREEN, ("acquisition successfully finished\n")); LOG(logINFOGREEN, ("acquisition successfully finished\n"));

View File

@ -11,7 +11,7 @@ add_executable(gotthard2DetectorServer_virtual
../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c ../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c
../slsDetectorServer/src/ASIC_Driver.c ../slsDetectorServer/src/ASIC_Driver.c
../slsDetectorServer/src/programFpgaNios.c ../slsDetectorServer/src/programFpgaNios.c
../slsDetectorServer/src/communication_virtual.c ../slsDetectorServer/src/sharedMemory.c
) )
include_directories( include_directories(

View File

@ -6,13 +6,13 @@ support_lib = ../../slsSupportLib/include/
CROSS = nios2-buildroot-linux-gnu- CROSS = nios2-buildroot-linux-gnu-
CC = $(CROSS)gcc CC = $(CROSS)gcc
CFLAGS += -Wall -std=gnu99 -DGOTTHARD2D -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir) #-DDEBUG1 #-DVERBOSEI #-DVERBOSE CFLAGS += -Wall -std=gnu99 -DGOTTHARD2D -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir) #-DDEBUG1 #-DVERBOSEI #-DVERBOSE
LDLIBS += -lm LDLIBS += -lm -lrt -pthread
PROGS = gotthard2DetectorServer PROGS = gotthard2DetectorServer
DESTDIR ?= bin DESTDIR ?= bin
INSTMODE = 0777 INSTMODE = 0777
SRCS = slsDetectorFunctionList.c SRCS = slsDetectorFunctionList.c
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)nios.c $(main_src)common.c $(main_src)DAC6571.c $(main_src)LTC2620_Driver.c $(main_src)ALTERA_PLL_CYCLONE10.c $(main_src)ASIC_Driver.c $(main_src)/programFpgaNios.c SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)nios.c $(main_src)common.c $(main_src)DAC6571.c $(main_src)LTC2620_Driver.c $(main_src)ALTERA_PLL_CYCLONE10.c $(main_src)ASIC_Driver.c $(main_src)/programFpgaNios.c $(main_src)/sharedMemory.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)

View File

@ -6,10 +6,10 @@
#include "RegisterDefs.h" #include "RegisterDefs.h"
#include "clogger.h" #include "clogger.h"
#include "common.h" #include "common.h"
#include "sharedMemory.h"
#include "versionAPI.h" #include "versionAPI.h"
#ifdef VIRTUAL #ifdef VIRTUAL
#include "communication_funcs_UDP.h" #include "communication_funcs_UDP.h"
#include "communication_virtual.h"
#endif #endif
#include <netinet/in.h> #include <netinet/in.h>
@ -37,8 +37,7 @@ char initErrorMessage[MAX_STR_LENGTH];
#ifdef VIRTUAL #ifdef VIRTUAL
pthread_t pthread_virtual_tid; pthread_t pthread_virtual_tid;
int virtual_status = 0; int64_t virtual_currentFrameNumber = 2;
int virtual_stop = 0;
#endif #endif
enum detectorSettings thisSettings = UNINITIALIZED; enum detectorSettings thisSettings = UNINITIALIZED;
@ -342,10 +341,7 @@ void initStopServer() {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_stop = 0; sharedMemory_setStop(0);
if (!isControlServer) {
ComVirtual_setStop(virtual_stop);
}
#endif #endif
} }
@ -393,10 +389,7 @@ void setupDetector() {
} }
} }
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
#endif #endif
// pll defines // pll defines
@ -1205,16 +1198,10 @@ int setHighVoltage(int val) {
val = HV_SOFT_MAX_VOLTAGE; val = HV_SOFT_MAX_VOLTAGE;
} }
#ifdef VIRTUAL
if (val >= 0)
highvoltage = val;
return highvoltage;
#endif
// setting hv // setting hv
if (val >= 0) { if (val >= 0) {
LOG(logINFO, ("Setting High voltage: %d V\n", val)); LOG(logINFO, ("Setting High voltage: %d V\n", val));
DAC6571_Set(val); if (DAC6571_Set(val) == OK)
highvoltage = val; highvoltage = val;
} }
return highvoltage; return highvoltage;
@ -2240,22 +2227,15 @@ int startStateMachine() {
} }
LOG(logINFOBLUE, ("Starting State Machine\n")); LOG(logINFOBLUE, ("Starting State Machine\n"));
// set status to running // set status to running
virtual_status = 1; if (sharedMemory_getStop() != 0) {
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
virtual_stop = ComVirtual_getStop();
if (virtual_stop != 0) {
LOG(logERROR, ("Cant start acquisition. " LOG(logERROR, ("Cant start acquisition. "
"Stop server has not updated stop status to 0\n")); "Stop server has not updated stop status to 0\n"));
return FAIL; return FAIL;
} }
} sharedMemory_setStatus(RUNNING);
if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) { if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
LOG(logERROR, ("Could not start Virtual acquisition thread\n")); LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
return FAIL; return FAIL;
} }
LOG(logINFOGREEN, ("Virtual Acquisition started\n")); LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
@ -2310,8 +2290,6 @@ void *start_timer(void *arg) {
*((uint16_t *)(vetoData + i)) = i; *((uint16_t *)(vetoData + i)) = i;
} }
{
int frameHeaderNr = 0;
// loop over number of repeats // loop over number of repeats
for (int repeatNr = 0; repeatNr != numRepeats; ++repeatNr) { for (int repeatNr = 0; repeatNr != numRepeats; ++repeatNr) {
@ -2321,10 +2299,8 @@ void *start_timer(void *arg) {
// loop over number of frames // loop over number of frames
for (int frameNr = 0; frameNr != numFrames; ++frameNr) { for (int frameNr = 0; frameNr != numFrames; ++frameNr) {
// update the virtual stop from stop server // check if manual stop
virtual_stop = ComVirtual_getStop(); if (sharedMemory_getStop() == 1) {
// check if virtual_stop is high
if (virtual_stop == 1) {
break; break;
} }
@ -2337,11 +2313,10 @@ void *start_timer(void *arg) {
char packetData[packetsize]; char packetData[packetsize];
memset(packetData, 0, packetsize); memset(packetData, 0, packetsize);
// set header // set header
sls_detector_header *header = sls_detector_header *header = (sls_detector_header *)(packetData);
(sls_detector_header *)(packetData);
header->detType = (uint16_t)myDetectorType; header->detType = (uint16_t)myDetectorType;
header->version = SLS_DETECTOR_HEADER_VERSION - 1; header->version = SLS_DETECTOR_HEADER_VERSION - 1;
header->frameNumber = frameHeaderNr; header->frameNumber = virtual_currentFrameNumber;
header->packetNumber = 0; header->packetNumber = 0;
header->modId = 0; header->modId = 0;
header->row = detPos[X]; header->row = detPos[X];
@ -2358,7 +2333,7 @@ void *start_timer(void *arg) {
if (vetoEnabled && numInterfaces == 2) { if (vetoEnabled && numInterfaces == 2) {
// set header // set header
veto_header *header = (veto_header *)(packetData2); veto_header *header = (veto_header *)(packetData2);
header->frameNumber = frameHeaderNr; header->frameNumber = virtual_currentFrameNumber;
header->bunchId = 0; header->bunchId = 0;
// fill data // fill data
memcpy(packetData2 + sizeof(veto_header), vetoData, memcpy(packetData2 + sizeof(veto_header), vetoData,
@ -2366,11 +2341,10 @@ void *start_timer(void *arg) {
// send 1 packet = 1 frame // send 1 packet = 1 frame
sendUDPPacket(1, packetData2, vetopacketsize); sendUDPPacket(1, packetData2, vetopacketsize);
} }
++frameHeaderNr;
clock_gettime(CLOCK_REALTIME, &end);
LOG(logINFO, LOG(logINFO,
("Sent frame: %d (bursts: %d)\n", frameNr, repeatNr)); ("Sent frame: %d (bursts: %d) [%lld]\n", frameNr, repeatNr,
(long long unsigned int)virtual_currentFrameNumber));
clock_gettime(CLOCK_REALTIME, &end);
int64_t timeNs = ((end.tv_sec - begin.tv_sec) * 1E9 + int64_t timeNs = ((end.tv_sec - begin.tv_sec) * 1E9 +
(end.tv_nsec - begin.tv_nsec)); (end.tv_nsec - begin.tv_nsec));
@ -2380,6 +2354,7 @@ void *start_timer(void *arg) {
usleep((periodNs - timeNs) / 1000); usleep((periodNs - timeNs) / 1000);
} }
} }
++virtual_currentFrameNumber;
} }
clock_gettime(CLOCK_REALTIME, &rend); clock_gettime(CLOCK_REALTIME, &rend);
int64_t timeNs = ((rend.tv_sec - rbegin.tv_sec) * 1E9 + int64_t timeNs = ((rend.tv_sec - rbegin.tv_sec) * 1E9 +
@ -2392,17 +2367,13 @@ void *start_timer(void *arg) {
} }
} }
} }
}
closeUDPSocket(0); closeUDPSocket(0);
if (vetoEnabled && numInterfaces == 2) { if (vetoEnabled && numInterfaces == 2) {
closeUDPSocket(1); closeUDPSocket(1);
} }
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
LOG(logINFOBLUE, ("Finished Acquiring\n")); LOG(logINFOBLUE, ("Finished Acquiring\n"));
return NULL; return NULL;
} }
@ -2410,19 +2381,16 @@ void *start_timer(void *arg) {
int stopStateMachine() { int stopStateMachine() {
LOG(logINFORED, ("Stopping State Machine\n")); LOG(logINFORED, ("Stopping State Machine\n"));
// if scan active, stop scan
if (sharedMemory_getScanStatus() == RUNNING) {
sharedMemory_setScanStop(1);
}
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { sharedMemory_setStop(1);
virtual_stop = 1; while (sharedMemory_getStatus() == RUNNING)
ComVirtual_setStop(virtual_stop); ;
// read till status is idle sharedMemory_setStop(0);
int tempStatus = 1;
while (tempStatus == 1) {
tempStatus = ComVirtual_getStatus();
}
virtual_stop = 0;
ComVirtual_setStop(virtual_stop);
LOG(logINFO, ("Stopped State Machine\n")); LOG(logINFO, ("Stopped State Machine\n"));
}
return OK; return OK;
#endif #endif
// stop state machine // stop state machine
@ -2432,19 +2400,24 @@ int stopStateMachine() {
} }
enum runStatus getRunStatus() { enum runStatus getRunStatus() {
#ifdef VIRTUAL LOG(logDEBUG1, ("Getting status\n"));
if (!isControlServer) { // scan error or running
virtual_status = ComVirtual_getStatus(); if (sharedMemory_getScanStatus() == ERROR) {
LOG(logINFOBLUE, ("Status: scan ERROR\n"));
return ERROR;
} }
if (virtual_status == 0) { if (sharedMemory_getScanStatus() == RUNNING) {
LOG(logINFOBLUE, ("Status: IDLE\n")); LOG(logINFOBLUE, ("Status: scan RUNNING\n"));
return IDLE; return RUNNING;
} else { }
#ifdef VIRTUAL
if (sharedMemory_getStatus() == RUNNING) {
LOG(logINFOBLUE, ("Status: RUNNING\n")); LOG(logINFOBLUE, ("Status: RUNNING\n"));
return RUNNING; return RUNNING;
} }
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
#endif #endif
LOG(logDEBUG1, ("Getting status\n"));
uint32_t retval = bus_r(FLOW_STATUS_REG); uint32_t retval = bus_r(FLOW_STATUS_REG);
LOG(logINFO, ("Status Register: %08x\n", retval)); LOG(logINFO, ("Status Register: %08x\n", retval));
@ -2511,10 +2484,7 @@ void readFrame(int *ret, char *mess) {
u_int32_t runBusy() { u_int32_t runBusy() {
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { return ((sharedMemory_getStatus() == RUNNING) ? 1 : 0);
virtual_status = ComVirtual_getStatus();
}
return virtual_status;
#endif #endif
u_int32_t s = (bus_r(FLOW_STATUS_REG) & FLOW_STATUS_RUN_BUSY_MSK); u_int32_t s = (bus_r(FLOW_STATUS_REG) & FLOW_STATUS_RUN_BUSY_MSK);
// LOG(logDEBUG1, ("Status Register: %08x\n", s)); // LOG(logDEBUG1, ("Status Register: %08x\n", s));

View File

@ -10,7 +10,7 @@ add_executable(gotthardDetectorServer_virtual
../slsDetectorServer/src/common.c ../slsDetectorServer/src/common.c
../slsDetectorServer/src/commonServerFunctions.c ../slsDetectorServer/src/commonServerFunctions.c
../slsDetectorServer/src/communication_funcs_UDP.c ../slsDetectorServer/src/communication_funcs_UDP.c
../slsDetectorServer/src/communication_virtual.c ../slsDetectorServer/src/sharedMemory.c
) )
include_directories( include_directories(

View File

@ -6,13 +6,13 @@ support_lib = ../../slsSupportLib/include/
CROSS = bfin-uclinux- CROSS = bfin-uclinux-
CC = $(CROSS)gcc CC = $(CROSS)gcc
CFLAGS += -Wall -std=gnu99 -DGOTTHARDD -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE CFLAGS += -Wall -std=gnu99 -DGOTTHARDD -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE
LDLIBS += -lm LDLIBS += -lm -lrt -pthread
PROGS = gotthardDetectorServer PROGS = gotthardDetectorServer
DESTDIR ?= bin DESTDIR ?= bin
INSTMODE = 0777 INSTMODE = 0777
SRCS = slsDetectorFunctionList.c SRCS = slsDetectorFunctionList.c
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)AD9252.c $(main_src)AD9257.c $(main_src)LTC2620.c $(main_src)common.c $(main_src)commonServerFunctions.c SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)AD9252.c $(main_src)AD9257.c $(main_src)LTC2620.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)/sharedMemory.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)
all: clean $(PROGS) all: clean $(PROGS)

View File

@ -1,12 +1,12 @@
#include "slsDetectorFunctionList.h" #include "slsDetectorFunctionList.h"
#include "RegisterDefs.h" #include "RegisterDefs.h"
#include "clogger.h" #include "clogger.h"
#include "sharedMemory.h"
#include "versionAPI.h" #include "versionAPI.h"
#include "LTC2620.h" // dacs #include "LTC2620.h" // dacs
#ifdef VIRTUAL #ifdef VIRTUAL
#include "communication_funcs_UDP.h" #include "communication_funcs_UDP.h"
#include "communication_virtual.h"
#endif #endif
#include "string.h" #include "string.h"
@ -34,9 +34,8 @@ char initErrorMessage[MAX_STR_LENGTH];
#ifdef VIRTUAL #ifdef VIRTUAL
pthread_t pthread_virtual_tid; pthread_t pthread_virtual_tid;
int virtual_status = 0;
int virtual_stop = 0;
int highvoltage = 0; int highvoltage = 0;
int64_t virtual_currentFrameNumber = 2;
#endif #endif
int detPos[2] = {}; int detPos[2] = {};
@ -356,10 +355,7 @@ void initStopServer() {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_stop = 0; sharedMemory_setStop(0);
if (!isControlServer) {
ComVirtual_setStop(virtual_stop);
}
#endif #endif
} }
@ -369,10 +365,7 @@ void setupDetector() {
LOG(logINFO, ("This Server is for 1 Gotthard module (1280 channels)\n")); LOG(logINFO, ("This Server is for 1 Gotthard module (1280 channels)\n"));
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
#endif #endif
// Initialization // Initialization
@ -1516,22 +1509,15 @@ int startStateMachine() {
return FAIL; return FAIL;
} }
LOG(logINFOBLUE, ("Starting State Machine\n")); LOG(logINFOBLUE, ("Starting State Machine\n"));
virtual_status = 1; if (sharedMemory_getStop() != 0) {
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
virtual_stop = ComVirtual_getStop();
if (virtual_stop != 0) {
LOG(logERROR, ("Cant start acquisition. " LOG(logERROR, ("Cant start acquisition. "
"Stop server has not updated stop status to 0\n")); "Stop server has not updated stop status to 0\n"));
return FAIL; return FAIL;
} }
} sharedMemory_setStatus(RUNNING);
if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) { if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
LOG(logERROR, ("Could not start Virtual acquisition thread\n")); LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
return FAIL; return FAIL;
} }
LOG(logINFOGREEN, ("Virtual Acquisition started\n")); LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
@ -1576,15 +1562,11 @@ void *start_timer(void *arg) {
} }
// Send data // Send data
{
uint16_t frameHeaderNr = 2;
// loop over number of frames // loop over number of frames
for (int frameNr = 0; frameNr != numFrames; ++frameNr) { for (int frameNr = 0; frameNr != numFrames; ++frameNr) {
// update the virtual stop from stop server // check if manual stop
virtual_stop = ComVirtual_getStop(); if (sharedMemory_getStop() == 1) {
// check if virtual_stop is high
if (virtual_stop == 1) {
break; break;
} }
@ -1600,8 +1582,8 @@ void *start_timer(void *arg) {
char packetData[packetSize]; char packetData[packetSize];
memset(packetData, 0, packetSize); memset(packetData, 0, packetSize);
// set header // set header
*((uint16_t *)(packetData)) = frameHeaderNr; *((uint16_t *)(packetData)) = virtual_currentFrameNumber;
++frameHeaderNr; ++virtual_currentFrameNumber;
// fill data // fill data
memcpy(packetData + 4, imageData + srcOffset, dataSize); memcpy(packetData + 4, imageData + srcOffset, dataSize);
@ -1609,10 +1591,11 @@ void *start_timer(void *arg) {
sendUDPPacket(0, packetData, packetSize); sendUDPPacket(0, packetData, packetSize);
} }
LOG(logINFO, ("Sent frame: %d\n", frameNr)); LOG(logINFO,
("Sent frame: %d [%d]\n", frameNr, virtual_currentFrameNumber));
clock_gettime(CLOCK_REALTIME, &end); clock_gettime(CLOCK_REALTIME, &end);
int64_t timeNs = ((end.tv_sec - begin.tv_sec) * 1E9 + int64_t timeNs =
(end.tv_nsec - begin.tv_nsec)); ((end.tv_sec - begin.tv_sec) * 1E9 + (end.tv_nsec - begin.tv_nsec));
// sleep for (period - exptime) // sleep for (period - exptime)
if (frameNr < numFrames) { // if there is a next frame if (frameNr < numFrames) { // if there is a next frame
@ -1621,14 +1604,10 @@ void *start_timer(void *arg) {
} }
} }
} }
}
closeUDPSocket(0); closeUDPSocket(0);
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
LOG(logINFOBLUE, ("Finished Acquiring\n")); LOG(logINFOBLUE, ("Finished Acquiring\n"));
return NULL; return NULL;
} }
@ -1636,17 +1615,17 @@ void *start_timer(void *arg) {
int stopStateMachine() { int stopStateMachine() {
LOG(logINFORED, ("Stopping State Machine\n")); LOG(logINFORED, ("Stopping State Machine\n"));
// if scan active, stop scan
if (sharedMemory_getScanStatus() == RUNNING) {
sharedMemory_setScanStop(1);
}
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { if (!isControlServer) {
virtual_stop = 1; sharedMemory_setStop(1);
ComVirtual_setStop(virtual_stop);
// read till status is idle // read till status is idle
int tempStatus = 1; while (sharedMemory_getStatus() == RUNNING)
while (tempStatus == 1) { ;
tempStatus = ComVirtual_getStatus(); sharedMemory_setStop(0);
}
virtual_stop = 0;
ComVirtual_setStop(virtual_stop);
LOG(logINFO, ("Stopped State Machine\n")); LOG(logINFO, ("Stopped State Machine\n"));
} }
return OK; return OK;
@ -1669,19 +1648,24 @@ int stopStateMachine() {
} }
enum runStatus getRunStatus() { enum runStatus getRunStatus() {
#ifdef VIRTUAL LOG(logDEBUG1, ("Getting status\n"));
if (!isControlServer) { // scan error or running
virtual_status = ComVirtual_getStatus(); if (sharedMemory_getScanStatus() == ERROR) {
LOG(logINFOBLUE, ("Status: scan ERROR\n"));
return ERROR;
} }
if (virtual_status == 0) { if (sharedMemory_getScanStatus() == RUNNING) {
LOG(logINFOBLUE, ("Status: IDLE\n")); LOG(logINFOBLUE, ("Status: scan RUNNING\n"));
return IDLE; return RUNNING;
} else { }
#ifdef VIRTUAL
if (sharedMemory_getStatus() == RUNNING) {
LOG(logINFOBLUE, ("Status: RUNNING\n")); LOG(logINFOBLUE, ("Status: RUNNING\n"));
return RUNNING; return RUNNING;
} }
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
#endif #endif
LOG(logDEBUG1, ("Getting status\n"));
enum runStatus s = IDLE; enum runStatus s = IDLE;
u_int32_t retval = runState(logINFO); u_int32_t retval = runState(logINFO);
@ -1751,7 +1735,7 @@ enum runStatus getRunStatus() {
void readFrame(int *ret, char *mess) { void readFrame(int *ret, char *mess) {
#ifdef VIRTUAL #ifdef VIRTUAL
while (virtual_status) { while (sharedMemory_getStatus() == RUNNING) {
// LOG(logERROR, ("Waiting for finished flag\n"); // LOG(logERROR, ("Waiting for finished flag\n");
usleep(5000); usleep(5000);
} }
@ -1775,17 +1759,14 @@ void readFrame(int *ret, char *mess) {
u_int32_t runBusy() { u_int32_t runBusy() {
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { return ((sharedMemory_getStatus() == RUNNING) ? 1 : 0);
virtual_status = ComVirtual_getStatus();
}
return virtual_status;
#endif #endif
return runState(logDEBUG1) & STATUS_RN_BSY_MSK; return runState(logDEBUG1) & STATUS_RN_BSY_MSK;
} }
u_int32_t runState(enum TLogLevel lev) { u_int32_t runState(enum TLogLevel lev) {
#ifdef VIRTUAL #ifdef VIRTUAL
return virtual_status; return (int)sharedMemory_getStatus();
#endif #endif
u_int32_t s = bus_r(STATUS_REG); u_int32_t s = bus_r(STATUS_REG);
LOG(lev, ("Status Register: 0x%08x\n", s)); LOG(lev, ("Status Register: 0x%08x\n", s));

View File

@ -12,7 +12,7 @@ add_executable(jungfrauDetectorServer_virtual
../slsDetectorServer/src/MAX1932.c ../slsDetectorServer/src/MAX1932.c
../slsDetectorServer/src/programFpgaBlackfin.c ../slsDetectorServer/src/programFpgaBlackfin.c
../slsDetectorServer/src/communication_funcs_UDP.c ../slsDetectorServer/src/communication_funcs_UDP.c
../slsDetectorServer/src/communication_virtual.c ../slsDetectorServer/src/sharedMemory.c
) )
target_include_directories(jungfrauDetectorServer_virtual target_include_directories(jungfrauDetectorServer_virtual

View File

@ -6,13 +6,13 @@ support_lib = ../../slsSupportLib/include/
CROSS = bfin-uclinux- CROSS = bfin-uclinux-
CC = $(CROSS)gcc CC = $(CROSS)gcc
CFLAGS += -Wall -std=gnu99 -DJUNGFRAUD -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE CFLAGS += -Wall -std=gnu99 -DJUNGFRAUD -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE
LDLIBS += -lm LDLIBS += -lm -lrt -pthread
PROGS = jungfrauDetectorServer PROGS = jungfrauDetectorServer
DESTDIR ?= bin DESTDIR ?= bin
INSTMODE = 0777 INSTMODE = 0777
SRCS = slsDetectorFunctionList.c SRCS = slsDetectorFunctionList.c
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programFpgaBlackfin.c SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programFpgaBlackfin.c $(main_src)/sharedMemory.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)

View File

@ -1,5 +1,6 @@
#include "slsDetectorFunctionList.h" #include "slsDetectorFunctionList.h"
#include "clogger.h" #include "clogger.h"
#include "sharedMemory.h"
#include "versionAPI.h" #include "versionAPI.h"
#include "ALTERA_PLL.h" // pll #include "ALTERA_PLL.h" // pll
@ -8,7 +9,6 @@
#include "common.h" #include "common.h"
#ifdef VIRTUAL #ifdef VIRTUAL
#include "communication_funcs_UDP.h" #include "communication_funcs_UDP.h"
#include "communication_virtual.h"
#endif #endif
#include <netinet/in.h> #include <netinet/in.h>
@ -36,8 +36,6 @@ char initErrorMessage[MAX_STR_LENGTH];
#ifdef VIRTUAL #ifdef VIRTUAL
pthread_t pthread_virtual_tid; pthread_t pthread_virtual_tid;
int virtual_status = 0;
int virtual_stop = 0;
int virtual_image_test_mode = 0; int virtual_image_test_mode = 0;
#endif #endif
@ -363,10 +361,7 @@ void initStopServer() {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_stop = 0; sharedMemory_setStop(0);
if (!isControlServer) {
ComVirtual_setStop(virtual_stop);
}
// temp threshold and reset event (read by stop server) // temp threshold and reset event (read by stop server)
setThresholdTemperature(DEFAULT_TMP_THRSHLD); setThresholdTemperature(DEFAULT_TMP_THRSHLD);
setTemperatureEvent(0); setTemperatureEvent(0);
@ -382,10 +377,7 @@ void setupDetector() {
clkPhase[i] = 0; clkPhase[i] = 0;
} }
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
#endif #endif
ALTERA_PLL_ResetPLL(); ALTERA_PLL_ResetPLL();
@ -1672,22 +1664,15 @@ int startStateMachine() {
return FAIL; return FAIL;
} }
LOG(logINFOBLUE, ("starting state machine\n")); LOG(logINFOBLUE, ("starting state machine\n"));
virtual_status = 1; if (sharedMemory_getStop() != 0) {
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
virtual_stop = ComVirtual_getStop();
if (virtual_stop != 0) {
LOG(logERROR, ("Cant start acquisition. " LOG(logERROR, ("Cant start acquisition. "
"Stop server has not updated stop status to 0\n")); "Stop server has not updated stop status to 0\n"));
return FAIL; return FAIL;
} }
} sharedMemory_setStatus(RUNNING);
if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) { if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
LOG(logERROR, ("Could not start Virtual acquisition thread\n")); LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
return FAIL; return FAIL;
} }
LOG(logINFOGREEN, ("Virtual Acquisition started\n")); LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
@ -1740,10 +1725,8 @@ void *start_timer(void *arg) {
usleep(transmissionDelayUs); usleep(transmissionDelayUs);
// update the virtual stop from stop server // check if manual stop
virtual_stop = ComVirtual_getStop(); if (sharedMemory_getStop() == 1) {
// check if virtual_stop is high
if (virtual_stop == 1) {
setStartingFrameNumber(frameNr + iframes + 1); setStartingFrameNumber(frameNr + iframes + 1);
break; break;
} }
@ -1818,10 +1801,7 @@ void *start_timer(void *arg) {
closeUDPSocket(1); closeUDPSocket(1);
} }
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
LOG(logINFOBLUE, ("Finished Acquiring\n")); LOG(logINFOBLUE, ("Finished Acquiring\n"));
return NULL; return NULL;
} }
@ -1829,19 +1809,17 @@ void *start_timer(void *arg) {
int stopStateMachine() { int stopStateMachine() {
LOG(logINFORED, ("Stopping State Machine\n")); LOG(logINFORED, ("Stopping State Machine\n"));
// if scan active, stop scan
if (sharedMemory_getScanStatus() == RUNNING) {
sharedMemory_setScanStop(1);
}
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { sharedMemory_setStop(1);
virtual_stop = 1;
ComVirtual_setStop(virtual_stop);
// read till status is idle // read till status is idle
int tempStatus = 1; while (sharedMemory_getStatus() == RUNNING)
while (tempStatus == 1) { ;
tempStatus = ComVirtual_getStatus(); sharedMemory_setStop(0);
}
virtual_stop = 0;
ComVirtual_setStop(virtual_stop);
LOG(logINFO, ("Stopped State Machine\n")); LOG(logINFO, ("Stopped State Machine\n"));
}
return OK; return OK;
#endif #endif
// stop state machine // stop state machine
@ -1854,19 +1832,24 @@ int stopStateMachine() {
} }
enum runStatus getRunStatus() { enum runStatus getRunStatus() {
#ifdef VIRTUAL LOG(logDEBUG1, ("Getting status\n"));
if (!isControlServer) { // scan error or running
virtual_status = ComVirtual_getStatus(); if (sharedMemory_getScanStatus() == ERROR) {
LOG(logINFOBLUE, ("Status: scan ERROR\n"));
return ERROR;
} }
if (virtual_status == 0) { if (sharedMemory_getScanStatus() == RUNNING) {
LOG(logINFOBLUE, ("Status: IDLE\n")); LOG(logINFOBLUE, ("Status: scan RUNNING\n"));
return IDLE; return RUNNING;
} else { }
#ifdef VIRTUAL
if (sharedMemory_getStatus() == RUNNING) {
LOG(logINFOBLUE, ("Status: RUNNING\n")); LOG(logINFOBLUE, ("Status: RUNNING\n"));
return RUNNING; return RUNNING;
} }
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
#endif #endif
LOG(logDEBUG1, ("Getting status\n"));
enum runStatus s; enum runStatus s;
u_int32_t retval = bus_r(STATUS_REG); u_int32_t retval = bus_r(STATUS_REG);
@ -1928,10 +1911,7 @@ void readFrame(int *ret, char *mess) {
u_int32_t runBusy() { u_int32_t runBusy() {
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { return ((sharedMemory_getStatus() == RUNNING) ? 1 : 0);
virtual_status = ComVirtual_getStatus();
}
return virtual_status;
#endif #endif
u_int32_t s = (bus_r(STATUS_REG) & RUN_BUSY_MSK); u_int32_t s = (bus_r(STATUS_REG) & RUN_BUSY_MSK);
LOG(logDEBUG1, ("Status Register: %08x\n", s)); LOG(logDEBUG1, ("Status Register: %08x\n", s));

View File

@ -14,7 +14,7 @@ add_executable(moenchDetectorServer_virtual
../slsDetectorServer/src/MAX1932.c ../slsDetectorServer/src/MAX1932.c
../slsDetectorServer/src/programFpgaBlackfin.c ../slsDetectorServer/src/programFpgaBlackfin.c
../slsDetectorServer/src/readDefaultPattern.c ../slsDetectorServer/src/readDefaultPattern.c
../slsDetectorServer/src/communication_virtual.c ../slsDetectorServer/src/sharedMemory.c
) )
include_directories( include_directories(

View File

@ -6,13 +6,13 @@ support_lib = ../../slsSupportLib/include/
CROSS = bfin-uclinux- CROSS = bfin-uclinux-
CC = $(CROSS)gcc CC = $(CROSS)gcc
CFLAGS += -Wall -std=gnu99 -DMOENCHD -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE CFLAGS += -Wall -std=gnu99 -DMOENCHD -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir)#-DVERBOSEI #-DVERBOSE
LDLIBS += -lm LDLIBS += -lm -lrt -pthread
PROGS = moenchDetectorServer PROGS = moenchDetectorServer
DESTDIR ?= bin DESTDIR ?= bin
INSTMODE = 0777 INSTMODE = 0777
SRCS = slsDetectorFunctionList.c SRCS = slsDetectorFunctionList.c
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)communication_funcs_UDP.c $(main_src)UDPPacketHeaderGenerator.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programFpgaBlackfin.c $(main_src)readDefaultPattern.c SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)blackfin.c $(main_src)common.c $(main_src)commonServerFunctions.c $(main_src)communication_funcs_UDP.c $(main_src)UDPPacketHeaderGenerator.c $(main_src)AD9257.c $(main_src)ALTERA_PLL.c $(main_src)LTC2620.c $(main_src)MAX1932.c $(main_src)programFpgaBlackfin.c $(main_src)readDefaultPattern.c $(main_src)/sharedMemory.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)

View File

@ -1,5 +1,6 @@
#include "slsDetectorFunctionList.h" #include "slsDetectorFunctionList.h"
#include "clogger.h" #include "clogger.h"
#include "sharedMemory.h"
#include "versionAPI.h" #include "versionAPI.h"
#include "ALTERA_PLL.h" // pll #include "ALTERA_PLL.h" // pll
@ -8,9 +9,6 @@
#include "UDPPacketHeaderGenerator.h" #include "UDPPacketHeaderGenerator.h"
#include "common.h" #include "common.h"
#include "communication_funcs_UDP.h" #include "communication_funcs_UDP.h"
#ifdef VIRTUAL
#include "communication_virtual.h"
#endif
#include <netinet/in.h> #include <netinet/in.h>
#include <string.h> #include <string.h>
@ -41,9 +39,8 @@ char initErrorMessage[MAX_STR_LENGTH];
#ifdef VIRTUAL #ifdef VIRTUAL
pthread_t pthread_virtual_tid; pthread_t pthread_virtual_tid;
int virtual_status = 0;
int virtual_stop = 0;
uint64_t virtual_pattern[MAX_PATTERN_LENGTH]; uint64_t virtual_pattern[MAX_PATTERN_LENGTH];
int64_t virtual_currentFrameNumber = 2;
#endif #endif
// 1g readout // 1g readout
@ -431,10 +428,7 @@ void initStopServer() {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_stop = 0; sharedMemory_setStop(0);
if (!isControlServer) {
ComVirtual_setStop(virtual_stop);
}
#endif #endif
} }
@ -487,10 +481,7 @@ void setupDetector() {
adcEnableMask_10g = 0; adcEnableMask_10g = 0;
nSamples = 1; nSamples = 1;
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
memset(virtual_pattern, 0, sizeof(virtual_pattern)); memset(virtual_pattern, 0, sizeof(virtual_pattern));
#endif #endif
@ -1855,22 +1846,15 @@ int startStateMachine() {
return FAIL; return FAIL;
} }
LOG(logINFOBLUE, ("Starting State Machine\n")); LOG(logINFOBLUE, ("Starting State Machine\n"));
virtual_status = 1; if (sharedMemory_getStop() != 0) {
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
virtual_stop = ComVirtual_getStop();
if (virtual_stop != 0) {
LOG(logERROR, ("Cant start acquisition. " LOG(logERROR, ("Cant start acquisition. "
"Stop server has not updated stop status to 0\n")); "Stop server has not updated stop status to 0\n"));
return FAIL; return FAIL;
} }
} sharedMemory_setStatus(RUNNING);
if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) { if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
LOG(logERROR, ("Could not start Virtual acquisition thread\n")); LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
return FAIL; return FAIL;
} }
LOG(logINFOGREEN, ("Virtual Acquisition started\n")); LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
@ -1931,10 +1915,8 @@ void *start_timer(void *arg) {
// loop over number of frames // loop over number of frames
for (int frameNr = 0; frameNr != numFrames; ++frameNr) { for (int frameNr = 0; frameNr != numFrames; ++frameNr) {
// update the virtual stop from stop server // check if manual stop
virtual_stop = ComVirtual_getStop(); if (sharedMemory_getStop() == 1) {
// check if virtual_stop is high
if (virtual_stop == 1) {
break; break;
} }
@ -1952,7 +1934,7 @@ void *start_timer(void *arg) {
sls_detector_header *header = (sls_detector_header *)(packetData); sls_detector_header *header = (sls_detector_header *)(packetData);
header->detType = (uint16_t)myDetectorType; header->detType = (uint16_t)myDetectorType;
header->version = SLS_DETECTOR_HEADER_VERSION - 1; header->version = SLS_DETECTOR_HEADER_VERSION - 1;
header->frameNumber = frameNr; header->frameNumber = virtual_currentFrameNumber;
header->packetNumber = i; header->packetNumber = i;
header->modId = 0; header->modId = 0;
header->row = detPos[X]; header->row = detPos[X];
@ -1965,7 +1947,8 @@ void *start_timer(void *arg) {
sendUDPPacket(0, packetData, packetSize); sendUDPPacket(0, packetData, packetSize);
} }
LOG(logINFO, ("Sent frame: %d\n", frameNr)); LOG(logINFO, ("Sent frame: %d [%lld]\n", frameNr,
(long long unsigned int)virtual_currentFrameNumber));
clock_gettime(CLOCK_REALTIME, &end); clock_gettime(CLOCK_REALTIME, &end);
int64_t timeNs = int64_t timeNs =
((end.tv_sec - begin.tv_sec) * 1E9 + (end.tv_nsec - begin.tv_nsec)); ((end.tv_sec - begin.tv_sec) * 1E9 + (end.tv_nsec - begin.tv_nsec));
@ -1976,14 +1959,12 @@ void *start_timer(void *arg) {
usleep((periodNs - timeNs) / 1000); usleep((periodNs - timeNs) / 1000);
} }
} }
++virtual_currentFrameNumber;
} }
closeUDPSocket(0); closeUDPSocket(0);
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
LOG(logINFOBLUE, ("Finished Acquiring\n")); LOG(logINFOBLUE, ("Finished Acquiring\n"));
return NULL; return NULL;
} }
@ -1991,19 +1972,17 @@ void *start_timer(void *arg) {
int stopStateMachine() { int stopStateMachine() {
LOG(logINFORED, ("Stopping State Machine\n")); LOG(logINFORED, ("Stopping State Machine\n"));
// if scan active, stop scan
if (sharedMemory_getScanStatus() == RUNNING) {
sharedMemory_setScanStop(1);
}
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { sharedMemory_setStop(1);
virtual_stop = 1;
ComVirtual_setStop(virtual_stop);
// read till status is idle // read till status is idle
int tempStatus = 1; while (sharedMemory_getStatus() == RUNNING)
while (tempStatus == 1) { ;
tempStatus = ComVirtual_getStatus(); sharedMemory_setStop(0);
}
virtual_stop = 0;
ComVirtual_setStop(virtual_stop);
LOG(logINFO, ("Stopped State Machine\n")); LOG(logINFO, ("Stopped State Machine\n"));
}
return OK; return OK;
#endif #endif
// stop state machine // stop state machine
@ -2017,19 +1996,24 @@ int stopStateMachine() {
} }
enum runStatus getRunStatus() { enum runStatus getRunStatus() {
#ifdef VIRTUAL LOG(logDEBUG1, ("Getting status\n"));
if (!isControlServer) { // scan error or running
virtual_status = ComVirtual_getStatus(); if (sharedMemory_getScanStatus() == ERROR) {
LOG(logINFOBLUE, ("Status: scan ERROR\n"));
return ERROR;
} }
if (virtual_status == 0) { if (sharedMemory_getScanStatus() == RUNNING) {
LOG(logINFOBLUE, ("Status: IDLE\n")); LOG(logINFOBLUE, ("Status: scan RUNNING\n"));
return IDLE; return RUNNING;
} else { }
#ifdef VIRTUAL
if (sharedMemory_getStatus() == RUNNING) {
LOG(logINFOBLUE, ("Status: RUNNING\n")); LOG(logINFOBLUE, ("Status: RUNNING\n"));
return RUNNING; return RUNNING;
} }
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
#endif #endif
LOG(logDEBUG1, ("Getting status\n"));
uint32_t retval = bus_r(STATUS_REG); uint32_t retval = bus_r(STATUS_REG);
LOG(logINFO, ("Status Register: %08x\n", retval)); LOG(logINFO, ("Status Register: %08x\n", retval));
@ -2258,10 +2242,7 @@ int readFrameFromFifo() {
uint32_t runBusy() { uint32_t runBusy() {
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { return ((sharedMemory_getStatus() == RUNNING) ? 1 : 0);
virtual_status = ComVirtual_getStatus();
}
return virtual_status;
#endif #endif
uint32_t s = (bus_r(STATUS_REG) & STATUS_RN_BSY_MSK); uint32_t s = (bus_r(STATUS_REG) & STATUS_RN_BSY_MSK);
// LOG(logDEBUG1, ("Status Register: %08x\n", s)); // LOG(logDEBUG1, ("Status Register: %08x\n", s));

View File

@ -10,7 +10,7 @@ add_executable(mythen3DetectorServer_virtual
../slsDetectorServer/src/LTC2620_Driver.c ../slsDetectorServer/src/LTC2620_Driver.c
../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c ../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c
../slsDetectorServer/src/programFpgaNios.c ../slsDetectorServer/src/programFpgaNios.c
../slsDetectorServer/src/communication_virtual.c ../slsDetectorServer/src/sharedMemory.c
) )
include_directories( include_directories(

View File

@ -6,13 +6,13 @@ support_lib = ../../slsSupportLib/include/
CROSS = nios2-buildroot-linux-gnu- CROSS = nios2-buildroot-linux-gnu-
CC = $(CROSS)gcc CC = $(CROSS)gcc
CFLAGS += -Wall -std=gnu99 -DMYTHEN3D -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir) #-DDEBUG1 #-DVERBOSEI #-DVERBOSE CFLAGS += -Wall -std=gnu99 -DMYTHEN3D -DSTOP_SERVER -I$(main_inc) -I$(support_lib) -I$(current_dir) #-DDEBUG1 #-DVERBOSEI #-DVERBOSE
LDLIBS += -lm LDLIBS += -lm -lrt -pthread
PROGS = mythen3DetectorServer PROGS = mythen3DetectorServer
DESTDIR ?= bin DESTDIR ?= bin
INSTMODE = 0777 INSTMODE = 0777
SRCS = slsDetectorFunctionList.c SRCS = slsDetectorFunctionList.c
SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)nios.c $(main_src)DAC6571.c $(main_src)common.c $(main_src)LTC2620_Driver.c $(main_src)ALTERA_PLL_CYCLONE10.c $(main_src)/programFpgaNios.c SRCS += $(main_src)slsDetectorServer.c $(main_src)slsDetectorServer_funcs.c $(main_src)communication_funcs.c $(main_src)nios.c $(main_src)DAC6571.c $(main_src)common.c $(main_src)LTC2620_Driver.c $(main_src)ALTERA_PLL_CYCLONE10.c $(main_src)/programFpgaNios.c $(main_src)/sharedMemory.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)

View File

@ -5,10 +5,10 @@
#include "RegisterDefs.h" #include "RegisterDefs.h"
#include "clogger.h" #include "clogger.h"
#include "common.h" #include "common.h"
#include "sharedMemory.h"
#include "versionAPI.h" #include "versionAPI.h"
#ifdef VIRTUAL #ifdef VIRTUAL
#include "communication_funcs_UDP.h" #include "communication_funcs_UDP.h"
#include "communication_virtual.h"
#endif #endif
#include <netinet/in.h> #include <netinet/in.h>
@ -35,8 +35,7 @@ char initErrorMessage[MAX_STR_LENGTH];
#ifdef VIRTUAL #ifdef VIRTUAL
pthread_t pthread_virtual_tid; pthread_t pthread_virtual_tid;
int virtual_status = 0; int64_t virtual_currentFrameNumber = 2;
int virtual_stop = 0;
#endif #endif
sls_detector_module *detectorModules = NULL; sls_detector_module *detectorModules = NULL;
@ -331,10 +330,7 @@ void initStopServer() {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_stop = 0; sharedMemory_setStop(0);
if (!isControlServer) {
ComVirtual_setStop(virtual_stop);
}
#endif #endif
} }
@ -388,10 +384,7 @@ void setupDetector() {
clkPhase[i] = 0; clkPhase[i] = 0;
} }
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
#endif #endif
// pll defines // pll defines
@ -1140,16 +1133,11 @@ int setHighVoltage(int val) {
if (val > HV_SOFT_MAX_VOLTAGE) { if (val > HV_SOFT_MAX_VOLTAGE) {
val = HV_SOFT_MAX_VOLTAGE; val = HV_SOFT_MAX_VOLTAGE;
} }
#ifdef VIRTUAL
if (val >= 0)
highvoltage = val;
return highvoltage;
#endif
// setting hv // setting hv
if (val >= 0) { if (val >= 0) {
LOG(logINFO, ("Setting High voltage: %d V\n", val)); LOG(logINFO, ("Setting High voltage: %d V\n", val));
DAC6571_Set(val); if (DAC6571_Set(val) == OK)
highvoltage = val; highvoltage = val;
} }
return highvoltage; return highvoltage;
@ -1980,22 +1968,15 @@ int startStateMachine() {
} }
LOG(logINFOBLUE, ("Starting State Machine\n")); LOG(logINFOBLUE, ("Starting State Machine\n"));
// set status to running // set status to running
virtual_status = 1; if (sharedMemory_getStop() != 0) {
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
virtual_stop = ComVirtual_getStop();
if (virtual_stop != 0) {
LOG(logERROR, ("Cant start acquisition. " LOG(logERROR, ("Cant start acquisition. "
"Stop server has not updated stop status to 0\n")); "Stop server has not updated stop status to 0\n"));
return FAIL; return FAIL;
} }
} sharedMemory_setStatus(RUNNING);
if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) { if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
LOG(logERROR, ("Could not start Virtual acquisition thread\n")); LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
return FAIL; return FAIL;
} }
LOG(logINFOGREEN, ("Virtual Acquisition started\n")); LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
@ -2037,10 +2018,8 @@ void *start_timer(void *arg) {
// loop over number of frames // loop over number of frames
for (int frameNr = 0; frameNr != numFrames; ++frameNr) { for (int frameNr = 0; frameNr != numFrames; ++frameNr) {
// update the virtual stop from stop server // check if manual stop
virtual_stop = ComVirtual_getStop(); if (sharedMemory_getStop() == 1) {
// check if virtual_stop is high
if (virtual_stop == 1) {
break; break;
} }
@ -2059,7 +2038,7 @@ void *start_timer(void *arg) {
sls_detector_header *header = (sls_detector_header *)(packetData); sls_detector_header *header = (sls_detector_header *)(packetData);
header->detType = (uint16_t)myDetectorType; header->detType = (uint16_t)myDetectorType;
header->version = SLS_DETECTOR_HEADER_VERSION - 1; header->version = SLS_DETECTOR_HEADER_VERSION - 1;
header->frameNumber = frameNr + 1; header->frameNumber = virtual_currentFrameNumber;
header->packetNumber = i; header->packetNumber = i;
header->modId = 0; header->modId = 0;
header->row = detPos[X]; header->row = detPos[X];
@ -2072,7 +2051,8 @@ void *start_timer(void *arg) {
sendUDPPacket(0, packetData, packetSize); sendUDPPacket(0, packetData, packetSize);
} }
LOG(logINFO, ("Sent frame: %d\n", frameNr)); LOG(logINFO, ("Sent frame: %d [%lld]\n", frameNr,
(long long unsigned int)virtual_currentFrameNumber));
clock_gettime(CLOCK_REALTIME, &end); clock_gettime(CLOCK_REALTIME, &end);
int64_t timeNs = int64_t timeNs =
((end.tv_sec - begin.tv_sec) * 1E9 + (end.tv_nsec - begin.tv_nsec)); ((end.tv_sec - begin.tv_sec) * 1E9 + (end.tv_nsec - begin.tv_nsec));
@ -2083,14 +2063,12 @@ void *start_timer(void *arg) {
usleep((periodNs - timeNs) / 1000); usleep((periodNs - timeNs) / 1000);
} }
} }
++virtual_currentFrameNumber;
} }
closeUDPSocket(0); closeUDPSocket(0);
virtual_status = 0; sharedMemory_setStatus(IDLE);
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
LOG(logINFOBLUE, ("Finished Acquiring\n")); LOG(logINFOBLUE, ("Finished Acquiring\n"));
return NULL; return NULL;
} }
@ -2098,17 +2076,17 @@ void *start_timer(void *arg) {
int stopStateMachine() { int stopStateMachine() {
LOG(logINFORED, ("Stopping State Machine\n")); LOG(logINFORED, ("Stopping State Machine\n"));
// if scan active, stop scan
if (sharedMemory_getScanStatus() == RUNNING) {
sharedMemory_setScanStop(1);
}
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { if (!isControlServer) {
virtual_stop = 1; sharedMemory_setStop(1);
ComVirtual_setStop(virtual_stop);
// read till status is idle // read till status is idle
int tempStatus = 1; while (sharedMemory_getStatus() == RUNNING)
while (tempStatus == 1) { ;
tempStatus = ComVirtual_getStatus(); sharedMemory_setStop(0);
}
virtual_stop = 0;
ComVirtual_setStop(virtual_stop);
LOG(logINFO, ("Stopped State Machine\n")); LOG(logINFO, ("Stopped State Machine\n"));
} }
return OK; return OK;
@ -2120,19 +2098,25 @@ int stopStateMachine() {
} }
enum runStatus getRunStatus() { enum runStatus getRunStatus() {
#ifdef VIRTUAL LOG(logDEBUG1, ("Getting status\n"));
if (!isControlServer) { // scan error or running
virtual_status = ComVirtual_getStatus(); if (sharedMemory_getScanStatus() == ERROR) {
LOG(logINFOBLUE, ("Status: scan ERROR\n"));
return ERROR;
} }
if (virtual_status == 0) { if (sharedMemory_getScanStatus() == RUNNING) {
LOG(logINFOBLUE, ("Status: IDLE\n")); LOG(logINFOBLUE, ("Status: scan RUNNING\n"));
return IDLE; return RUNNING;
} else { }
#ifdef VIRTUAL
if (sharedMemory_getStatus() == RUNNING) {
LOG(logINFOBLUE, ("Status: RUNNING\n")); LOG(logINFOBLUE, ("Status: RUNNING\n"));
return RUNNING; return RUNNING;
} }
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
#endif #endif
LOG(logDEBUG1, ("Getting status\n"));
uint32_t retval = bus_r(FLOW_STATUS_REG); uint32_t retval = bus_r(FLOW_STATUS_REG);
LOG(logINFO, ("Status Register: %08x\n", retval)); LOG(logINFO, ("Status Register: %08x\n", retval));
@ -2200,10 +2184,7 @@ void readFrame(int *ret, char *mess) {
u_int32_t runBusy() { u_int32_t runBusy() {
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) { return ((sharedMemory_getStatus() == RUNNING) ? 1 : 0);
virtual_status = ComVirtual_getStatus();
}
return virtual_status;
#endif #endif
u_int32_t s = (bus_r(FLOW_STATUS_REG) & FLOW_STATUS_RUN_BUSY_MSK); u_int32_t s = (bus_r(FLOW_STATUS_REG) & FLOW_STATUS_RUN_BUSY_MSK);
// LOG(logDEBUG1, ("Status Register: %08x\n", s)); // LOG(logDEBUG1, ("Status Register: %08x\n", s));

View File

@ -1,16 +0,0 @@
#pragma once
#ifdef VIRTUAL
// communciate between control and stop server
int ComVirtual_createFiles(const int port);
void ComVirtual_setFileNames(const int port);
void ComVirtual_setStatus(int value);
int ComVirtual_getStatus();
void ComVirtual_setStop(int value);
int ComVirtual_getStop();
int ComVirtual_writeToFile(int value, const char *fname,
const char *serverName);
int ComVirtual_readFromFile(int *value, const char *fname,
const char *serverName);
#endif

View File

@ -0,0 +1,23 @@
#pragma once
#include "sls_detector_defs.h"
#include <semaphore.h>
void sharedMemory_print();
int sharedMemory_create(int port);
void sharedMemory_initialize();
int sharedMemory_open(int port);
int sharedMemory_attach();
int sharedMemory_detach();
int sharedMemory_remove();
void sharedMemory_lock();
void sharedMemory_unlock();
#ifdef VIRTUAL
void sharedMemory_setStatus(enum runStatus s);
enum runStatus sharedMemory_getStatus();
void sharedMemory_setStop(int s);
int sharedMemory_getStop();
#endif
void sharedMemory_setScanStatus(enum runStatus s);
enum runStatus sharedMemory_getScanStatus();
void sharedMemory_setScanStop(int s);
int sharedMemory_getScanStop();

View File

@ -36,6 +36,8 @@ int set_firmware_test(int);
int set_bus_test(int); int set_bus_test(int);
int set_image_test_mode(int); int set_image_test_mode(int);
int get_image_test_mode(int); int get_image_test_mode(int);
enum DACINDEX getDACIndex(enum dacIndex ind);
int validateAndSetDac(enum dacIndex ind, int val, int mV);
int set_dac(int); int set_dac(int);
int get_adc(int); int get_adc(int);
int write_register(int); int write_register(int);
@ -43,6 +45,8 @@ int read_register(int);
int set_module(int); int set_module(int);
int set_settings(int); int set_settings(int);
int get_threshold_energy(int); int get_threshold_energy(int);
int acquire(int blocking, int file_des);
void *start_state_machine(void *arg);
int start_acquisition(int); int start_acquisition(int);
int stop_acquisition(int); int stop_acquisition(int);
int get_run_status(int); int get_run_status(int);
@ -88,6 +92,7 @@ int get_last_client_ip(int);
int set_port(int); int set_port(int);
int calibrate_pedestal(int); int calibrate_pedestal(int);
int enable_ten_giga(int); int enable_ten_giga(int);
int validateAndSetAllTrimbits(int arg);
int set_all_trimbits(int); int set_all_trimbits(int);
int set_pattern_io_control(int); int set_pattern_io_control(int);
int set_pattern_word(int); int set_pattern_word(int);
@ -118,7 +123,6 @@ int program_fpga(int);
int reset_fpga(int); int reset_fpga(int);
int power_chip(int); int power_chip(int);
int set_activate(int); int set_activate(int);
int prepare_acquisition(int);
int threshold_temp(int); int threshold_temp(int);
int temp_control(int); int temp_control(int);
int temp_event(int); int temp_event(int);
@ -222,3 +226,6 @@ int get_gate_delay_all_gates(int);
int get_veto(int); int get_veto(int);
int set_veto(int); int set_veto(int);
int set_pattern(int); int set_pattern(int);
int get_scan(int);
int set_scan(int);
int get_scan_error_message(int);

View File

@ -1,121 +0,0 @@
#ifdef VIRTUAL
#include "communication_virtual.h"
#include "clogger.h"
#include <string.h>
#include <unistd.h> // usleep
#define FILE_STATUS "/tmp/sls_virtual_server_status_"
#define FILE_STOP "/tmp/sls_virtual_server_stop_"
#define FD_STATUS 0
#define FD_STOP 1
#define FILE_NAME_LENGTH 1000
FILE *fd[2] = {NULL, NULL};
char fnameStatus[FILE_NAME_LENGTH];
char fnameStop[FILE_NAME_LENGTH];
int portNumber = 0;
int ComVirtual_createFiles(const int port) {
portNumber = port;
// control server writign status file
memset(fnameStatus, 0, FILE_NAME_LENGTH);
sprintf(fnameStatus, "%s%d", FILE_STATUS, port);
FILE *fd = NULL;
if (NULL == (fd = fopen(fnameStatus, "w"))) {
LOG(logERROR, ("Could not open the file %s for virtual communication\n",
fnameStatus));
return 0;
}
fclose(fd);
LOG(logINFOBLUE, ("Created status file %s\n", fnameStatus));
// stop server writing stop file
memset(fnameStop, 0, FILE_NAME_LENGTH);
sprintf(fnameStop, "%s%d", FILE_STOP, port);
if (NULL == (fd = fopen(fnameStop, "w"))) {
LOG(logERROR, ("Could not open the file %s for virtual communication\n",
fnameStop));
return 0;
}
fclose(fd);
LOG(logINFOBLUE, ("Created stop file %s\n", fnameStop));
return 1;
}
void ComVirtual_setFileNames(const int port) {
portNumber = port;
memset(fnameStatus, 0, FILE_NAME_LENGTH);
memset(fnameStop, 0, FILE_NAME_LENGTH);
sprintf(fnameStatus, "%s%d", FILE_STATUS, port);
sprintf(fnameStop, "%s%d", FILE_STOP, port);
}
void ComVirtual_setStatus(int value) {
while (!ComVirtual_writeToFile(value, fnameStatus, "Control")) {
usleep(100);
}
}
int ComVirtual_getStatus() {
int retval = 0;
while (!ComVirtual_readFromFile(&retval, fnameStatus, "Stop")) {
usleep(100);
}
return retval;
}
void ComVirtual_setStop(int value) {
while (!ComVirtual_writeToFile(value, fnameStop, "Stop")) {
usleep(100);
}
}
int ComVirtual_getStop() {
int retval = 0;
while (!ComVirtual_readFromFile(&retval, fnameStop, "Control")) {
usleep(100);
}
return retval;
}
int ComVirtual_writeToFile(int value, const char *fname,
const char *serverName) {
FILE *fd = NULL;
if (NULL == (fd = fopen(fname, "w"))) {
LOG(logERROR, ("Vritual %s Server [%d] could not open "
"the file %s for writing\n",
serverName, portNumber, fname));
return 0;
}
while (fwrite(&value, sizeof(value), 1, fd) < 1) {
LOG(logERROR, ("Vritual %s Server [%d] could not write "
"to file %s\n",
serverName, portNumber, fname));
return 0;
}
fclose(fd);
return 1;
}
int ComVirtual_readFromFile(int *value, const char *fname,
const char *serverName) {
FILE *fd = NULL;
if (NULL == (fd = fopen(fname, "r"))) {
LOG(logERROR, ("Vritual %s Server [%d] could not open "
"the file %s for reading\n",
serverName, portNumber, fname));
return 0;
}
while (fread(value, sizeof(int), 1, fd) < 1) {
LOG(logERROR, ("Vritual %s Server [%d] could not read "
"from file %s\n",
serverName, portNumber, fname));
return 0;
}
fclose(fd);
return 1;
}
#endif

View File

@ -0,0 +1,189 @@
#include "sharedMemory.h"
#include "clogger.h"
#include <errno.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <unistd.h>
#define SHM_NAME "sls_server_shared_memory"
#define SHM_VERSION 0x200625
#define SHM_KEY 5678
typedef struct Memory {
int version;
sem_t sem;
enum runStatus scanStatus; // idle, running or error
int scanStop;
#ifdef VIRTUAL
enum runStatus status;
int stop;
#endif
} sharedMem;
sharedMem *shm = NULL;
int shmFd = -1;
extern int isControlServer;
void sharedMemory_print() {
LOG(logINFO, ("%s Shared Memory:\n", isControlServer ? "c" : "s"));
LOG(logINFO,
("%s version:0x%x\n", isControlServer ? "c" : "s", shm->version));
LOG(logINFO, ("%s scan status: %d\n", isControlServer ? "c" : "s",
(int)shm->scanStatus));
LOG(logINFO,
("%s scan stop: %d\n", isControlServer ? "c" : "s", shm->scanStop));
#ifdef VIRTUAL
LOG(logINFO,
("%s status: %d\n", isControlServer ? "c" : "s", (int)shm->status));
LOG(logINFO, ("%s stop: %d\n", isControlServer ? "c" : "s", shm->stop));
#endif
}
int sharedMemory_create(int port) {
// if sham existed, delete old shm and create again
shmFd =
shmget(SHM_KEY + port, sizeof(sharedMem), IPC_CREAT | IPC_EXCL | 0666);
if (shmFd == -1 && errno == EEXIST) {
char cmd[MAX_STR_LENGTH];
memset(cmd, 0, MAX_STR_LENGTH);
sprintf(cmd, "ipcrm -M 0x%x", SHM_KEY + port);
system(cmd);
LOG(logWARNING,
("Removed old shared memory with id 0x%x\n", SHM_KEY + port));
shmFd = shmget(SHM_KEY + port, sizeof(sharedMem),
IPC_CREAT | IPC_EXCL | 0666);
}
if (shmFd == -1) {
LOG(logERROR, ("Create shared memory failed: %s\n", strerror(errno)));
return FAIL;
}
LOG(logINFO, ("Shared memory created\n"));
if (sharedMemory_attach() == FAIL) {
return FAIL;
}
sharedMemory_initialize();
return OK;
}
void sharedMemory_initialize() {
shm->version = SHM_VERSION;
sem_init(&(shm->sem), 1, 1);
shm->scanStatus = IDLE;
shm->scanStop = 0;
#ifdef VIRTUAL
shm->status = IDLE;
shm->stop = 0;
#endif
LOG(logINFO, ("Shared memory initialized\n"))
}
int sharedMemory_open(int port) {
shmFd = shmget(SHM_KEY + port, sizeof(sharedMem), 0666);
if (shmFd == -1) {
LOG(logERROR, ("Open shared memory failed: %s\n", strerror(errno)));
return FAIL;
}
if (sharedMemory_attach() == FAIL) {
return FAIL;
}
if (shm->version != SHM_VERSION) {
LOG(logERROR,
("Shared memory version 0x%x does not match! (expected: 0x%x)\n",
shm->version, SHM_VERSION));
}
LOG(logINFO, ("Shared memory opened\n"));
return OK;
}
int sharedMemory_attach() {
shm = (sharedMem *)shmat(shmFd, NULL, 0);
if (shm == (void *)-1) {
LOG(logERROR, ("could not attach: %s\n", strerror(errno)));
return FAIL;
}
LOG(logINFO, ("Shared memory attached\n"));
return OK;
}
int sharedMemory_detach() {
if (shmdt(shm) == -1) {
LOG(logERROR, ("could not detach: %s\n", strerror(errno)));
return FAIL;
}
LOG(logINFO, ("Shared memory detached\n"));
return OK;
}
int sharedMemory_remove() {
if (shmctl(shmFd, IPC_RMID, NULL) == -1) {
LOG(logERROR, ("could not remove: %s\n", strerror(errno)));
return FAIL;
}
LOG(logINFO, ("Shared memory removed\n"));
return OK;
}
void sharedMemory_lock() { sem_wait(&(shm->sem)); }
void sharedMemory_unlock() { sem_post(&(shm->sem)); }
#ifdef VIRTUAL
void sharedMemory_setStatus(enum runStatus s) {
sharedMemory_lock();
shm->status = s;
sharedMemory_unlock();
}
enum runStatus sharedMemory_getStatus() {
enum runStatus s = 0;
sharedMemory_lock();
s = shm->status;
sharedMemory_unlock();
return s;
}
void sharedMemory_setStop(int s) {
sharedMemory_lock();
shm->stop = s;
sharedMemory_unlock();
}
int sharedMemory_getStop() {
int s = 0;
sharedMemory_lock();
s = shm->stop;
sharedMemory_unlock();
return s;
}
#endif
void sharedMemory_setScanStatus(enum runStatus s) {
sharedMemory_lock();
shm->scanStatus = s;
sharedMemory_unlock();
}
enum runStatus sharedMemory_getScanStatus() {
enum runStatus s = IDLE;
sharedMemory_lock();
s = shm->scanStatus;
sharedMemory_unlock();
return s;
}
void sharedMemory_setScanStop(int s) {
sharedMemory_lock();
shm->scanStop = s;
sharedMemory_unlock();
}
int sharedMemory_getScanStop() {
int s = 0;
sharedMemory_lock();
s = shm->scanStop;
sharedMemory_unlock();
return s;
}

View File

@ -3,13 +3,11 @@
#include "clogger.h" #include "clogger.h"
#include "communication_funcs.h" #include "communication_funcs.h"
#include "sharedMemory.h"
#include "slsDetectorServer_defs.h" #include "slsDetectorServer_defs.h"
#include "slsDetectorServer_funcs.h" #include "slsDetectorServer_funcs.h"
#include "sls_detector_defs.h" #include "sls_detector_defs.h"
#include "versionAPI.h" #include "versionAPI.h"
#ifdef VIRTUAL
#include "communication_virtual.h"
#endif
#include <signal.h> #include <signal.h>
#include <string.h> #include <string.h>
@ -100,6 +98,10 @@ int main(int argc, char *argv[]) {
// control server // control server
if (isControlServer) { if (isControlServer) {
LOG(logINFOBLUE, ("Control Server [%d]\n", portno));
if (sharedMemory_create(portno) == FAIL) {
return -1;
}
#ifdef STOP_SERVER #ifdef STOP_SERVER
// start stop server process // start stop server process
char cmd[MAX_STR_LENGTH]; char cmd[MAX_STR_LENGTH];
@ -121,21 +123,14 @@ int main(int argc, char *argv[]) {
LOG(logDEBUG1, ("Command to start stop server:%s\n", cmd)); LOG(logDEBUG1, ("Command to start stop server:%s\n", cmd));
system(cmd); system(cmd);
LOG(logINFOBLUE, ("Control Server [%d]\n", portno));
#ifdef VIRTUAL
// creating files for virtual servers to communicate with each other
if (!ComVirtual_createFiles(portno)) {
return -1;
}
#endif
#endif #endif
} }
// stop server // stop server
else { else {
LOG(logINFOBLUE, ("Stop Server [%d]\n", portno)); LOG(logINFOBLUE, ("Stop Server [%d]\n", portno));
#ifdef VIRTUAL if (sharedMemory_open(portno - 1) == FAIL) {
ComVirtual_setFileNames(portno - 1); return -1;
#endif }
} }
init_detector(); init_detector();
@ -164,6 +159,17 @@ int main(int argc, char *argv[]) {
exitServer(sockfd); exitServer(sockfd);
// detach shared memory
if (sharedMemory_detach() == FAIL) {
return -1;
}
// remove shared memory (control server)
if (isControlServer) {
if (sharedMemory_remove() == FAIL) {
return -1;
}
}
if (retval == REBOOT) { if (retval == REBOOT) {
LOG(logINFORED, ("Rebooting!\n")); LOG(logINFORED, ("Rebooting!\n"));
fflush(stdout); fflush(stdout);

View File

@ -1,10 +1,12 @@
#include "slsDetectorServer_funcs.h" #include "slsDetectorServer_funcs.h"
#include "clogger.h" #include "clogger.h"
#include "communication_funcs.h" #include "communication_funcs.h"
#include "sharedMemory.h"
#include "slsDetectorFunctionList.h" #include "slsDetectorFunctionList.h"
#include "sls_detector_funcs.h" #include "sls_detector_funcs.h"
#include <arpa/inet.h> #include <arpa/inet.h>
#include <pthread.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@ -49,6 +51,16 @@ int detectorId = -1;
// Local variables // Local variables
int (*flist[NUM_DET_FUNCTIONS])(int); int (*flist[NUM_DET_FUNCTIONS])(int);
pthread_t pthread_tid;
// scan variables
int scan = 0;
int numScanSteps = 0;
int *scanSteps = NULL;
int64_t scanSettleTime_ns = 0;
enum dacIndex scanGlobalIndex = 0;
int scanTrimbits = 0;
char scanErrMessage[MAX_STR_LENGTH] = "";
/* initialization functions */ /* initialization functions */
@ -232,7 +244,6 @@ void function_table() {
flist[F_RESET_FPGA] = &reset_fpga; flist[F_RESET_FPGA] = &reset_fpga;
flist[F_POWER_CHIP] = &power_chip; flist[F_POWER_CHIP] = &power_chip;
flist[F_ACTIVATE] = &set_activate; flist[F_ACTIVATE] = &set_activate;
flist[F_PREPARE_ACQUISITION] = &prepare_acquisition;
flist[F_THRESHOLD_TEMP] = &threshold_temp; flist[F_THRESHOLD_TEMP] = &threshold_temp;
flist[F_TEMP_CONTROL] = &temp_control; flist[F_TEMP_CONTROL] = &temp_control;
flist[F_TEMP_EVENT] = &temp_event; flist[F_TEMP_EVENT] = &temp_event;
@ -332,6 +343,9 @@ void function_table() {
flist[F_GET_VETO] = &get_veto; flist[F_GET_VETO] = &get_veto;
flist[F_SET_VETO] = &set_veto; flist[F_SET_VETO] = &set_veto;
flist[F_SET_PATTERN] = &set_pattern; flist[F_SET_PATTERN] = &set_pattern;
flist[F_GET_SCAN] = get_scan;
flist[F_SET_SCAN] = set_scan;
flist[F_GET_SCAN_ERROR_MESSAGE] = get_scan_error_message;
// check // check
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
@ -700,20 +714,8 @@ int get_image_test_mode(int file_des) {
return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
} }
int set_dac(int file_des) { enum DACINDEX getDACIndex(enum dacIndex ind) {
ret = OK; enum DACINDEX serverDacIndex = -1;
memset(mess, 0, sizeof(mess));
int args[3] = {-1, -1, -1};
int retval = -1;
if (receiveData(file_des, args, sizeof(args), INT32) < 0)
return printSocketReadError();
enum dacIndex ind = args[0];
int mV = args[1];
int val = args[2];
enum DACINDEX serverDacIndex = 0;
// check if dac exists for this detector // check if dac exists for this detector
switch (ind) { switch (ind) {
#ifdef GOTTHARDD #ifdef GOTTHARDD
@ -990,15 +992,14 @@ int set_dac(int file_des) {
modeNotImplemented("Dac Index", (int)ind); modeNotImplemented("Dac Index", (int)ind);
break; break;
} }
return serverDacIndex;
}
int validateAndSetDac(enum dacIndex ind, int val, int mV) {
int retval = -1;
enum DACINDEX serverDacIndex = getDACIndex(ind);
// index exists
if (ret == OK) { if (ret == OK) {
LOG(logDEBUG1, ("Setting DAC %d to %d %s\n", serverDacIndex, val,
(mV ? "mV" : "dac units")));
// set & get
if ((val == GET_FLAG) || (Server_VerifyLock() == OK)) {
switch (ind) { switch (ind) {
// adc vpp // adc vpp
@ -1126,11 +1127,10 @@ int set_dac(int file_des) {
} }
retval = getVchip(); retval = getVchip();
LOG(logDEBUG1, ("Vchip: %d\n", retval)); LOG(logDEBUG1, ("Vchip: %d\n", retval));
if (ret == OK && val != GET_FLAG && val != -100 && if (ret == OK && val != GET_FLAG && val != -100 && retval != val) {
retval != val) {
ret = FAIL; ret = FAIL;
sprintf(mess, "Could not set vchip. Set %d, but read %d\n", sprintf(mess, "Could not set vchip. Set %d, but read %d\n", val,
val, retval); retval);
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} }
break; break;
@ -1179,8 +1179,7 @@ int set_dac(int file_des) {
sprintf(mess, sprintf(mess,
"Could not set dac %d to value %d. " "Could not set dac %d to value %d. "
"Exceeds voltage limit %d.\n", "Exceeds voltage limit %d.\n",
ind, (mV ? val : dacToVoltage(val)), ind, (mV ? val : dacToVoltage(val)), getVLimit());
getVLimit());
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} else } else
#endif #endif
@ -1188,7 +1187,7 @@ int set_dac(int file_des) {
retval = getDAC(serverDacIndex, mV); retval = getDAC(serverDacIndex, mV);
} }
#ifdef EIGERD #ifdef EIGERD
if (val != GET_FLAG) { if (val != GET_FLAG && getSettings() != UNDEFINED) {
// changing dac changes settings to undefined // changing dac changes settings to undefined
switch (serverDacIndex) { switch (serverDacIndex) {
case E_VCMP_LL: case E_VCMP_LL:
@ -1198,8 +1197,7 @@ int set_dac(int file_des) {
case E_VRPREAMP: case E_VRPREAMP:
case E_VCP: case E_VCP:
setSettings(UNDEFINED); setSettings(UNDEFINED);
LOG(logERROR, LOG(logERROR, ("Settings has been changed "
("Settings has been changed "
"to undefined (changed specific dacs)\n")); "to undefined (changed specific dacs)\n"));
break; break;
default: default:
@ -1223,6 +1221,27 @@ int set_dac(int file_des) {
break; break;
} }
} }
return retval;
}
int set_dac(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int args[3] = {-1, -1, -1};
int retval = -1;
if (receiveData(file_des, args, sizeof(args), INT32) < 0)
return printSocketReadError();
enum dacIndex ind = args[0];
int mV = args[1];
int val = args[2];
LOG(logDEBUG1,
("Setting DAC %d to %d %s\n", ind, val, (mV ? "mV" : "dac units")));
// set & get
if ((val == GET_FLAG) || (Server_VerifyLock() == OK)) {
retval = validateAndSetDac(ind, val, mV);
} }
return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
} }
@ -1637,11 +1656,14 @@ int get_threshold_energy(int file_des) {
return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
} }
int start_acquisition(int file_des) { int acquire(int blocking, int file_des) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
if (blocking) {
LOG(logDEBUG1, ("Starting Acquisition\n")); LOG(logINFOBLUE, ("Blocking Acquisition\n"));
} else {
LOG(logINFOBLUE, ("Unblocking Acquisition\n"));
}
// only set // only set
if (Server_VerifyLock() == OK) { if (Server_VerifyLock() == OK) {
#if defined(MOENCHD) #if defined(MOENCHD)
@ -1706,23 +1728,124 @@ int start_acquisition(int file_des) {
strcpy(mess, "Could not start acquisition because "); strcpy(mess, "Could not start acquisition because ");
strcat(mess, configureMessage); strcat(mess, configureMessage);
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} else if (sharedMemory_getScanStatus() == RUNNING) {
ret = FAIL;
strcpy(mess, "Could not start acquisition because a scan is "
"already running!\n");
LOG(logERROR, (mess));
} else { } else {
memset(scanErrMessage, 0, MAX_STR_LENGTH);
sharedMemory_setScanStop(0);
sharedMemory_setScanStatus(IDLE); // if it was error
if (pthread_create(&pthread_tid, NULL, &start_state_machine,
&blocking)) {
ret = FAIL;
strcpy(mess, "Could not start acquisition thread!\n");
LOG(logERROR, (mess));
} else {
if (blocking) {
pthread_join(pthread_tid, NULL);
}
}
}
}
return Server_SendResult(file_des, INT32, NULL, 0);
}
void *start_state_machine(void *arg) {
int *blocking = (int *)arg;
int times = 1;
// start of scan
if (scan) {
sharedMemory_setScanStatus(RUNNING);
times = numScanSteps;
}
for (int i = 0; i != times; ++i) {
// normal acquisition
if (scan == 0) {
LOG(logINFOBLUE, ("Normal Acquisition (not scan)\n"));
}
// scan
else {
// check scan stop
if (sharedMemory_getScanStop()) {
LOG(logINFORED, ("Scan manually stopped!\n"));
sharedMemory_setScanStatus(IDLE);
break;
}
// trimbits scan
if (scanTrimbits) {
LOG(logINFOBLUE,
("Trimbits scan %d/%d: [%d]\n", i, times, scanSteps[i]));
validateAndSetAllTrimbits(scanSteps[i]);
if (ret == FAIL) {
sprintf(scanErrMessage, "Cannot scan trimbit %d. ",
scanSteps[i]);
strcat(scanErrMessage, mess);
sharedMemory_setScanStatus(ERROR);
break;
}
}
// dac scan
else {
LOG(logINFOBLUE, ("Dac [%d] scan %d/%d: [%d]\n",
scanGlobalIndex, i, times, scanSteps[i]));
validateAndSetDac(scanGlobalIndex, scanSteps[i], 0);
if (ret == FAIL) {
sprintf(scanErrMessage, "Cannot scan dac %d at %d. ",
scanGlobalIndex, scanSteps[i]);
strcat(scanErrMessage, mess);
sharedMemory_setScanStatus(ERROR);
break;
}
}
// check scan stop
if (sharedMemory_getScanStop()) {
LOG(logINFORED, ("Scan manually stopped!\n"));
sharedMemory_setScanStatus(IDLE);
break;
}
usleep(scanSettleTime_ns / 1000);
}
#ifdef EIGERD
prepareAcquisition();
#endif
ret = startStateMachine(); ret = startStateMachine();
LOG(logDEBUG2, ("Starting Acquisition ret: %d\n", ret));
if (ret == FAIL) { if (ret == FAIL) {
#if defined(CHIPTESTBOARDD) || defined(MOENCHD) || defined(VIRTUAL) #if defined(CHIPTESTBOARDD) || defined(MOENCHD) || defined(VIRTUAL)
sprintf(mess, sprintf(mess, "Could not start acquisition. Could not create udp "
"Could not start acquisition. Could not create udp "
"socket in server. Check udp_dstip & udp_dstport.\n"); "socket in server. Check udp_dstip & udp_dstport.\n");
#else #else
sprintf(mess, "Could not start acquisition\n"); sprintf(mess, "Could not start acquisition\n");
#endif #endif
LOG(logERROR, (mess)); LOG(logERROR, (mess));
if (scan) {
sprintf(scanErrMessage, "Cannot scan at %d. ", scanSteps[i]);
strcat(scanErrMessage, mess);
sharedMemory_setScanStatus(ERROR);
}
break;
}
// blocking or scan
if (*blocking || times > 1) {
readFrame(&ret, mess);
if (ret == FAIL && scan) {
sprintf(scanErrMessage, "Cannot scan at %d. ", scanSteps[i]);
strcat(scanErrMessage, mess);
sharedMemory_setScanStatus(ERROR);
break;
} }
} }
LOG(logDEBUG2, ("Starting Acquisition ret: %d\n", ret));
} }
return Server_SendResult(file_des, INT32, NULL, 0); // end of scan
if (scan && sharedMemory_getScanStatus() != ERROR) {
sharedMemory_setScanStatus(IDLE);
} }
return NULL;
}
int start_acquisition(int file_des) { return acquire(0, file_des); }
int stop_acquisition(int file_des) { int stop_acquisition(int file_des) {
ret = OK; ret = OK;
@ -1753,100 +1876,7 @@ int get_run_status(int file_des) {
return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
} }
int start_and_read_all(int file_des) { int start_and_read_all(int file_des) { return acquire(1, file_des); }
ret = OK;
memset(mess, 0, sizeof(mess));
LOG(logDEBUG1, ("Starting Acquisition and read all frames\n"));
// start state machine
LOG(logDEBUG1, ("Starting Acquisition\n"));
// only set
if (Server_VerifyLock() == OK) {
#if defined(MOENCHD)
if (getNumAnalogSamples() <= 0) {
ret = FAIL;
sprintf(mess,
"Could not start acquisition. Invalid number of analog "
"samples: %d.\n",
getNumAnalogSamples());
LOG(logERROR, (mess));
} else
#endif
#if defined(CHIPTESTBOARDD)
if ((getReadoutMode() == ANALOG_AND_DIGITAL ||
getReadoutMode() == ANALOG_ONLY) &&
(getNumAnalogSamples() <= 0)) {
ret = FAIL;
sprintf(mess,
"Could not start acquisition. Invalid number of analog "
"samples: %d.\n",
getNumAnalogSamples());
LOG(logERROR, (mess));
} else if ((getReadoutMode() == ANALOG_AND_DIGITAL ||
getReadoutMode() == DIGITAL_ONLY) &&
(getNumDigitalSamples() <= 0)) {
ret = FAIL;
sprintf(mess,
"Could not start acquisition. Invalid number of digital "
"samples: %d.\n",
getNumDigitalSamples());
LOG(logERROR, (mess));
} else
#endif
#ifdef EIGERD
// check for hardware mac and hardware ip
if (udpDetails.srcmac != getDetectorMAC()) {
ret = FAIL;
uint64_t sourcemac = getDetectorMAC();
char src_mac[50];
getMacAddressinString(src_mac, 50, sourcemac);
sprintf(mess,
"Invalid udp source mac address for this detector. Must be "
"same as hardware detector mac address %s\n",
src_mac);
LOG(logERROR, (mess));
} else if (!enableTenGigabitEthernet(GET_FLAG) &&
(udpDetails.srcip != getDetectorIP())) {
ret = FAIL;
uint32_t sourceip = getDetectorIP();
char src_ip[INET_ADDRSTRLEN];
getIpAddressinString(src_ip, sourceip);
sprintf(
mess,
"Invalid udp source ip address for this detector. Must be same "
"as hardware detector ip address %s in 1G readout mode \n",
src_ip);
LOG(logERROR, (mess));
} else
#endif
if (configured == FAIL) {
ret = FAIL;
strcpy(mess, "Could not start acquisition because ");
strcat(mess, configureMessage);
LOG(logERROR, (mess));
} else {
ret = startStateMachine();
if (ret == FAIL) {
#if defined(VIRTUAL) || defined(CHIPTESTBOARDD) || defined(MOENCHD)
sprintf(mess,
"Could not start acquisition. Could not create udp "
"socket in server. Check udp_dstip & udp_dstport.\n");
#else
sprintf(mess, "Could not start acquisition\n");
#endif
LOG(logERROR, (mess));
}
}
LOG(logDEBUG2, ("Starting Acquisition ret: %d\n", ret));
}
// lock or acquisition start error
if (ret == FAIL)
return Server_SendResult(file_des, INT32, NULL, 0);
// read all (again validate lock, but should pass and not fail)
return read_all(file_des);
}
int read_all(int file_des) { int read_all(int file_des) {
ret = OK; ret = OK;
@ -1866,8 +1896,14 @@ int get_num_frames(int file_des) {
int64_t retval = -1; int64_t retval = -1;
// get only // get only
if (!scan) {
retval = getNumFrames(); retval = getNumFrames();
LOG(logDEBUG1, ("retval num frames %lld\n", (long long int)retval)); LOG(logDEBUG1, ("retval num frames %lld\n", (long long int)retval));
} else {
retval = numScanSteps;
LOG(logDEBUG1, ("retval num frames (num scan steps) %lld\n",
(long long int)retval));
}
return Server_SendResult(file_des, INT64, &retval, sizeof(retval)); return Server_SendResult(file_des, INT64, &retval, sizeof(retval));
} }
@ -1882,6 +1918,17 @@ int set_num_frames(int file_des) {
// only set // only set
if (Server_VerifyLock() == OK) { if (Server_VerifyLock() == OK) {
// only set number of frames if normal mode (not scan)
if (scan) {
if (arg != numScanSteps) {
ret = FAIL;
sprintf(mess,
"Could not set number of frames %lld. In scan mode, it "
"is number of steps %d\n",
(long long unsigned int)arg, numScanSteps);
LOG(logERROR, (mess));
}
} else {
#ifdef GOTTHARD2D #ifdef GOTTHARD2D
// validate #frames in burst mode // validate #frames in burst mode
if (getBurstMode() != BURST_OFF && arg > MAX_FRAMES_IN_BURST_MODE) { if (getBurstMode() != BURST_OFF && arg > MAX_FRAMES_IN_BURST_MODE) {
@ -1896,10 +1943,12 @@ int set_num_frames(int file_des) {
if (ret == OK) { if (ret == OK) {
setNumFrames(arg); setNumFrames(arg);
int64_t retval = getNumFrames(); int64_t retval = getNumFrames();
LOG(logDEBUG1, ("retval num frames %lld\n", (long long int)retval)); LOG(logDEBUG1,
("retval num frames %lld\n", (long long int)retval));
validate64(arg, retval, "set number of frames", DEC); validate64(arg, retval, "set number of frames", DEC);
} }
} }
}
return Server_SendResult(file_des, INT64, NULL, 0); return Server_SendResult(file_des, INT64, NULL, 0);
} }
@ -2819,6 +2868,40 @@ int enable_ten_giga(int file_des) {
return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
} }
int validateAndSetAllTrimbits(int arg) {
int retval = -1;
#if !defined(EIGERD) && !defined(MYTHEN3D)
functionNotImplemented();
#else
// set
if (arg >= 0) {
if (arg > MAX_TRIMBITS_VALUE) {
ret = FAIL;
sprintf(mess, "Cannot set all trimbits. Range: 0 - %d\n",
MAX_TRIMBITS_VALUE);
LOG(logERROR, (mess));
} else {
ret = setAllTrimbits(arg);
#ifdef EIGERD
// changes settings to undefined
if (getSettings() != UNDEFINED) {
setSettings(UNDEFINED);
LOG(logERROR,
("Settings has been changed to undefined (change all "
"trimbits)\n"));
}
#endif
}
}
// get
retval = getAllTrimbits();
LOG(logDEBUG1, ("All trimbits: %d\n", retval));
validate(arg, retval, "set all trimbits", DEC);
#endif
return retval;
}
int set_all_trimbits(int file_des) { int set_all_trimbits(int file_des) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
@ -2829,32 +2912,10 @@ int set_all_trimbits(int file_des) {
return printSocketReadError(); return printSocketReadError();
LOG(logDEBUG1, ("Set all trmbits to %d\n", arg)); LOG(logDEBUG1, ("Set all trmbits to %d\n", arg));
#if !defined(EIGERD) && !defined(MYTHEN3D) if ((arg >= 0 && Server_VerifyLock() == OK) || arg < 0) {
functionNotImplemented(); retval = validateAndSetAllTrimbits(arg);
#else }
// set
if (arg >= 0 && Server_VerifyLock() == OK) {
if (arg > MAX_TRIMBITS_VALUE) {
ret = FAIL;
sprintf(mess, "Cannot set all trimbits. Range: 0 - %d\n",
MAX_TRIMBITS_VALUE);
LOG(logERROR, (mess));
} else {
ret = setAllTrimbits(arg);
#ifdef EIGERD
// changes settings to undefined
setSettings(UNDEFINED);
LOG(logERROR, ("Settings has been changed to undefined (change all "
"trimbits)\n"));
#endif
}
}
// get
retval = getAllTrimbits();
LOG(logDEBUG1, ("All trimbits: %d\n", retval));
validate(arg, retval, "set all trimbits", DEC);
#endif
return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
} }
@ -2875,7 +2936,7 @@ int set_pattern_io_control(int file_des) {
retval = writePatternIOControl(arg); retval = writePatternIOControl(arg);
LOG(logDEBUG1, LOG(logDEBUG1,
("Pattern IO Control retval: 0x%llx\n", (long long int)retval)); ("Pattern IO Control retval: 0x%llx\n", (long long int)retval));
validate64(arg, retval, "Pattern IO Control", HEX); validate64(arg, retval, "set Pattern IO Control", HEX);
} }
#endif #endif
return Server_SendResult(file_des, INT64, &retval, sizeof(retval)); return Server_SendResult(file_des, INT64, &retval, sizeof(retval));
@ -2965,8 +3026,9 @@ int set_pattern_loop_addresses(int file_des) {
startAddr, stopAddr)); startAddr, stopAddr));
retvals[0] = startAddr; retvals[0] = startAddr;
retvals[1] = stopAddr; retvals[1] = stopAddr;
validate(args[1], startAddr, "Pattern loops' start address", HEX); validate(args[1], startAddr, "set Pattern loops' start address",
validate(args[2], stopAddr, "Pattern loops' stop address", HEX); HEX);
validate(args[2], stopAddr, "set Pattern loops' stop address", HEX);
} }
} }
#endif #endif
@ -3004,7 +3066,8 @@ int set_pattern_loop_cycles(int file_des) {
retval = numLoops; retval = numLoops;
LOG(logDEBUG1, LOG(logDEBUG1,
("Pattern loop cycles retval: (ncycles:%d)\n", retval)); ("Pattern loop cycles retval: (ncycles:%d)\n", retval));
validate(args[1], retval, "Pattern loops' number of cycles", DEC); validate(args[1], retval, "set Pattern loops' number of cycles",
DEC);
} }
} }
#endif #endif
@ -3047,7 +3110,7 @@ int set_pattern_wait_addr(int file_des) {
} else { } else {
retval = setPatternWaitAddress(loopLevel, addr); retval = setPatternWaitAddress(loopLevel, addr);
LOG(logDEBUG1, ("Pattern wait address retval: 0x%x\n", retval)); LOG(logDEBUG1, ("Pattern wait address retval: 0x%x\n", retval));
validate(addr, retval, "Pattern wait address", HEX); validate(addr, retval, "set Pattern wait address", HEX);
} }
} }
#endif #endif
@ -3082,7 +3145,7 @@ int set_pattern_wait_time(int file_des) {
retval = setPatternWaitTime(loopLevel, timeval); retval = setPatternWaitTime(loopLevel, timeval);
LOG(logDEBUG1, LOG(logDEBUG1,
("Pattern wait time retval: 0x%llx\n", (long long int)retval)); ("Pattern wait time retval: 0x%llx\n", (long long int)retval));
validate64(timeval, retval, "Pattern wait time", HEX); validate64(timeval, retval, "set Pattern wait time", HEX);
} }
} }
#endif #endif
@ -3107,7 +3170,7 @@ int set_pattern_mask(int file_des) {
uint64_t retval64 = getPatternMask(); uint64_t retval64 = getPatternMask();
LOG(logDEBUG1, LOG(logDEBUG1,
("Pattern mask: 0x%llx\n", (long long unsigned int)retval64)); ("Pattern mask: 0x%llx\n", (long long unsigned int)retval64));
validate64(arg, retval64, "Set Pattern Mask", HEX); validate64(arg, retval64, "set Pattern Mask", HEX);
} }
#endif #endif
return Server_SendResult(file_des, INT32, NULL, 0); return Server_SendResult(file_des, INT32, NULL, 0);
@ -3150,7 +3213,7 @@ int set_pattern_bit_mask(int file_des) {
uint64_t retval64 = getPatternBitMask(); uint64_t retval64 = getPatternBitMask();
LOG(logDEBUG1, LOG(logDEBUG1,
("Pattern bit mask: 0x%llx\n", (long long unsigned int)retval64)); ("Pattern bit mask: 0x%llx\n", (long long unsigned int)retval64));
validate64(arg, retval64, "Set Pattern Bit Mask", HEX); validate64(arg, retval64, "set Pattern Bit Mask", HEX);
} }
#endif #endif
return Server_SendResult(file_des, INT32, NULL, 0); return Server_SendResult(file_des, INT32, NULL, 0);
@ -3815,26 +3878,6 @@ int set_activate(int file_des) {
return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
} }
int prepare_acquisition(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
LOG(logDEBUG1, ("Preparing Acquisition\n"));
#ifndef EIGERD
functionNotImplemented();
#else
// only set
if (Server_VerifyLock() == OK) {
ret = prepareAcquisition();
if (ret == FAIL) {
strcpy(mess, "Could not prepare acquisition\n");
LOG(logERROR, (mess));
}
}
#endif
return Server_SendResult(file_des, INT32, NULL, 0);
}
// stop server // stop server
int threshold_temp(int file_des) { int threshold_temp(int file_des) {
ret = OK; ret = OK;
@ -4076,7 +4119,7 @@ int led(int file_des) {
if ((arg == GET_FLAG) || (Server_VerifyLock() == OK)) { if ((arg == GET_FLAG) || (Server_VerifyLock() == OK)) {
retval = setLEDEnable(arg); retval = setLEDEnable(arg);
LOG(logDEBUG1, ("LED Enable: %d\n", retval)); LOG(logDEBUG1, ("LED Enable: %d\n", retval));
validate(arg, retval, "LED Enable", DEC); validate(arg, retval, "enable/disable LED", DEC);
} }
#endif #endif
return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
@ -4378,7 +4421,7 @@ int set_external_sampling_source(int file_des) {
} else { } else {
retval = setExternalSamplingSource(arg); retval = setExternalSamplingSource(arg);
LOG(logDEBUG1, ("External Sampling source: %d\n", retval)); LOG(logDEBUG1, ("External Sampling source: %d\n", retval));
validate(arg, retval, "External sampling source", DEC); validate(arg, retval, "set external sampling source", DEC);
} }
} }
#endif #endif
@ -4403,7 +4446,7 @@ int set_external_sampling(int file_des) {
arg = (arg > 0) ? 1 : arg; arg = (arg > 0) ? 1 : arg;
retval = setExternalSampling(arg); retval = setExternalSampling(arg);
LOG(logDEBUG1, ("External Sampling enable: %d\n", retval)); LOG(logDEBUG1, ("External Sampling enable: %d\n", retval));
validate(arg, retval, "External sampling enable", DEC); validate(arg, retval, "set external sampling enable", DEC);
} }
#endif #endif
return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
@ -4793,7 +4836,8 @@ int set_detector_position(int file_des) {
int check_detector_idle() { int check_detector_idle() {
enum runStatus status = getRunStatus(); enum runStatus status = getRunStatus();
if (status != IDLE && status != RUN_FINISHED && status != STOPPED) { if (status != IDLE && status != RUN_FINISHED && status != STOPPED &&
status != ERROR) {
ret = FAIL; ret = FAIL;
sprintf(mess, sprintf(mess,
"Cannot configure mac when detector is not idle. Detector at " "Cannot configure mac when detector is not idle. Detector at "
@ -6630,7 +6674,7 @@ int set_current_source(int file_des) {
setCurrentSource(arg); setCurrentSource(arg);
int retval = getCurrentSource(); int retval = getCurrentSource();
LOG(logDEBUG1, ("current source enable retval: %u\n", retval)); LOG(logDEBUG1, ("current source enable retval: %u\n", retval));
validate(arg, retval, "current source enable", DEC); validate(arg, retval, "set current source enable", DEC);
} }
#endif #endif
return Server_SendResult(file_des, INT32, NULL, 0); return Server_SendResult(file_des, INT32, NULL, 0);
@ -6837,7 +6881,11 @@ int get_receiver_parameters(int file_des) {
return printSocketReadError(); return printSocketReadError();
// frames // frames
if (!scan) {
i64 = getNumFrames(); i64 = getNumFrames();
} else {
i64 = numScanSteps;
}
n += sendData(file_des, &i64, sizeof(i64), INT64); n += sendData(file_des, &i64, sizeof(i64), INT64);
if (n < 0) if (n < 0)
return printSocketReadError(); return printSocketReadError();
@ -7383,7 +7431,7 @@ int set_pattern(int file_des) {
#ifndef MYTHEN3D #ifndef MYTHEN3D
if (ret == OK) { if (ret == OK) {
retval64 = writePatternIOControl(patioctrl); retval64 = writePatternIOControl(patioctrl);
validate64(patioctrl, retval64, "Pattern IO Control", HEX); validate64(patioctrl, retval64, "set pattern IO Control", HEX);
} }
#endif #endif
if (ret == OK) { if (ret == OK) {
@ -7391,9 +7439,9 @@ int set_pattern(int file_des) {
retval0 = patlimits[0]; retval0 = patlimits[0];
retval1 = patlimits[1]; retval1 = patlimits[1];
setPatternLoop(-1, &retval0, &retval1, &numLoops); setPatternLoop(-1, &retval0, &retval1, &numLoops);
validate(patlimits[0], retval0, "Pattern Limits start address", validate(patlimits[0], retval0, "set pattern Limits start address",
HEX); HEX);
validate(patlimits[1], retval1, "Pattern Limits start address", validate(patlimits[1], retval1, "set pattern Limits start address",
HEX); HEX);
} }
if (ret == OK) { if (ret == OK) {
@ -7401,56 +7449,200 @@ int set_pattern(int file_des) {
retval1 = patloop[1]; retval1 = patloop[1];
numLoops = patnloop[0]; numLoops = patnloop[0];
setPatternLoop(0, &patloop[0], &patloop[1], &numLoops); setPatternLoop(0, &patloop[0], &patloop[1], &numLoops);
validate(patloop[0], retval0, "Pattern Loop 0 start address", HEX); validate(patloop[0], retval0, "set pattern Loop 0 start address",
validate(patloop[1], retval1, "Pattern Loop 0 stop address", HEX); HEX);
validate(patnloop[0], numLoops, "Pattern Loop 0 num loops", HEX); validate(patloop[1], retval1, "set pattern Loop 0 stop address",
HEX);
validate(patnloop[0], numLoops, "set pattern Loop 0 num loops",
HEX);
} }
if (ret == OK) { if (ret == OK) {
retval0 = patloop[2]; retval0 = patloop[2];
retval1 = patloop[3]; retval1 = patloop[3];
numLoops = patnloop[1]; numLoops = patnloop[1];
setPatternLoop(1, &patloop[2], &patloop[3], &numLoops); setPatternLoop(1, &patloop[2], &patloop[3], &numLoops);
validate(patloop[2], retval0, "Pattern Loop 1 start address", HEX); validate(patloop[2], retval0, "set pattern Loop 1 start address",
validate(patloop[3], retval1, "Pattern Loop 1 stop address", HEX); HEX);
validate(patnloop[1], numLoops, "Pattern Loop 1 num loops", HEX); validate(patloop[3], retval1, "set pattern Loop 1 stop address",
HEX);
validate(patnloop[1], numLoops, "set pattern Loop 1 num loops",
HEX);
} }
if (ret == OK) { if (ret == OK) {
retval0 = patloop[4]; retval0 = patloop[4];
retval1 = patloop[5]; retval1 = patloop[5];
numLoops = patnloop[2]; numLoops = patnloop[2];
setPatternLoop(2, &patloop[4], &patloop[5], &numLoops); setPatternLoop(2, &patloop[4], &patloop[5], &numLoops);
validate(patloop[4], retval0, "Pattern Loop 2 start address", HEX); validate(patloop[4], retval0, "set pattern Loop 2 start address",
validate(patloop[5], retval1, "Pattern Loop 2 stop address", HEX); HEX);
validate(patnloop[2], numLoops, "Pattern Loop 2 num loops", HEX); validate(patloop[5], retval1, "set pattern Loop 2 stop address",
HEX);
validate(patnloop[2], numLoops, "set pattern Loop 2 num loops",
HEX);
} }
if (ret == OK) { if (ret == OK) {
retval0 = setPatternWaitAddress(0, patwait[0]); retval0 = setPatternWaitAddress(0, patwait[0]);
validate(patwait[0], retval0, "Pattern Loop 0 wait address", HEX); validate(patwait[0], retval0, "set pattern Loop 0 wait address",
HEX);
} }
if (ret == OK) { if (ret == OK) {
retval0 = setPatternWaitAddress(1, patwait[1]); retval0 = setPatternWaitAddress(1, patwait[1]);
validate(patwait[1], retval0, "Pattern Loop 1 wait address", HEX); validate(patwait[1], retval0, "set pattern Loop 1 wait address",
HEX);
} }
if (ret == OK) { if (ret == OK) {
retval0 = setPatternWaitAddress(2, patwait[2]); retval0 = setPatternWaitAddress(2, patwait[2]);
validate(patwait[2], retval0, "Pattern Loop 2 wait address", HEX); validate(patwait[2], retval0, "set pattern Loop 2 wait address",
HEX);
} }
if (ret == OK) { if (ret == OK) {
uint64_t retval64 = setPatternWaitTime(0, patwaittime[0]); uint64_t retval64 = setPatternWaitTime(0, patwaittime[0]);
validate64(patwaittime[0], retval64, "Pattern Loop 0 wait time", validate64(patwaittime[0], retval64, "set pattern Loop 0 wait time",
HEX); HEX);
} }
if (ret == OK) { if (ret == OK) {
retval64 = setPatternWaitTime(1, patwaittime[1]); retval64 = setPatternWaitTime(1, patwaittime[1]);
validate64(patwaittime[1], retval64, "Pattern Loop 1 wait time", validate64(patwaittime[1], retval64, "set pattern Loop 1 wait time",
HEX); HEX);
} }
if (ret == OK) { if (ret == OK) {
retval64 = setPatternWaitTime(2, patwaittime[2]); retval64 = setPatternWaitTime(2, patwaittime[2]);
validate64(patwaittime[1], retval64, "Pattern Loop 2 wait time", validate64(patwaittime[1], retval64, "set pattern Loop 2 wait time",
HEX); HEX);
} }
} }
#endif #endif
return Server_SendResult(file_des, INT32, NULL, 0); return Server_SendResult(file_des, INT32, NULL, 0);
} }
int get_scan(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int retvals[5] = {0, 0, 0, 0, 0};
int64_t retvals_dacTime = 0;
LOG(logDEBUG1, ("Getting scan\n"));
// get only
retvals[0] = scan;
if (scan) {
retvals[1] = scanGlobalIndex;
retvals[2] = scanSteps[0];
retvals[3] = scanSteps[numScanSteps - 1];
retvals[4] = scanSteps[1] - scanSteps[0];
retvals_dacTime = scanSettleTime_ns;
}
LOG(logDEBUG1, ("scan retval: [%s, dac:%d, start:%d, stop:%d, step:%d, "
"dacTime:%lldns]\n",
retvals[0] ? "enabled" : "disabled", retvals[1], retvals[2],
retvals[3], retvals[4], (long long int)retvals_dacTime));
Server_SendResult(file_des, INT32, NULL, 0);
if (ret != FAIL) {
sendData(file_des, retvals, sizeof(retvals), INT32);
sendData(file_des, &retvals_dacTime, sizeof(retvals_dacTime), INT64);
}
return ret;
}
int set_scan(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int args[5] = {-1, -1, -1, -1, -1};
int64_t dacTime = -1;
int64_t retval = -1;
if (receiveData(file_des, args, sizeof(args), INT32) < 0)
return printSocketReadError();
if (receiveData(file_des, &dacTime, sizeof(dacTime), INT64) < 0)
return printSocketReadError();
// only set
if (Server_VerifyLock() == OK) {
int enable = args[0];
enum dacIndex index = args[1];
int start = args[2];
int stop = args[3];
int step = args[4];
// disable scan
if (enable == 0) {
LOG(logINFOBLUE, ("Disabling scan"));
scan = 0;
numScanSteps = 0;
// setting number of frames to 1
int64_t arg = 1;
setNumFrames(arg);
retval = getNumFrames();
LOG(logDEBUG1, ("retval num frames %lld\n", (long long int)retval));
validate64(arg, retval, "set number of frames", DEC);
}
// enable scan
else {
if ((start < stop && step <= 0) || (stop < start && step >= 0)) {
ret = FAIL;
sprintf(mess, "Invalid scan parameters\n");
LOG(logERROR, (mess));
} else {
// trimbit scan
if (index == TRIMBIT_SCAN) {
LOG(logINFOBLUE, ("Trimbit scan enabled\n"));
scanTrimbits = 1;
scanGlobalIndex = index;
scanSettleTime_ns = dacTime;
}
// dac scan
else {
getDACIndex(index);
if (ret == OK) {
LOG(logINFOBLUE, ("Dac [%d] scan enabled\n", index));
scanTrimbits = 0;
scanGlobalIndex = index;
scanSettleTime_ns = dacTime;
}
}
}
// valid scan
if (ret == OK) {
scan = 1;
numScanSteps = (abs(stop - start) / abs(step)) + 1;
if (scanSteps != NULL) {
free(scanSteps);
}
scanSteps = malloc(numScanSteps * sizeof(int));
for (int i = 0; i != numScanSteps; ++i) {
scanSteps[i] = start + i * step;
LOG(logDEBUG1, ("scansteps[%d]:%d\n", i, scanSteps[i]));
}
LOG(logINFOBLUE, ("Enabling scan for %s, start[%d], stop[%d], "
"step[%d], nsteps[%d]\n",
scanTrimbits == 1 ? "trimbits" : "dac", start,
stop, step, numScanSteps));
// setting number of frames to scansteps
int64_t arg = 1;
setNumFrames(arg);
retval = getNumFrames();
LOG(logDEBUG1,
("retval num frames %lld\n", (long long int)retval));
validate64(arg, retval, "set number of frames", DEC);
retval = numScanSteps;
}
}
}
return Server_SendResult(file_des, INT64, &retval, sizeof(retval));
}
int get_scan_error_message(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
char retvals[MAX_STR_LENGTH];
memset(retvals, 0, MAX_STR_LENGTH);
LOG(logDEBUG1, ("Getting scan error message\n"));
// get only
strcpy(retvals, scanErrMessage);
LOG(logDEBUG1, ("scan retval err message: [%s]\n", retvals));
return Server_SendResult(file_des, OTHER, retvals, sizeof(retvals));
}

View File

@ -394,7 +394,16 @@ class Detector {
/** [Eiger] Sends an internal software trigger to the detector */ /** [Eiger] Sends an internal software trigger to the detector */
void sendSoftwareTrigger(Positions pos = {}); void sendSoftwareTrigger(Positions pos = {});
// TODO: remove resetframescaught in receiver Result<defs::scanParameters> getScan(Positions pos = {}) const;
/** enables/ disables scans for dac, trimbits [Eiger/ Mythen3]
* TRIMBIT_SCAN. Enabling scan sets number of frames to number of steps in
* receiver. Disabling scan sets number of frames to 1 */
void setScan(const defs::scanParameters t);
/** gets scan error message in case of error during scan in case of non
* blocking acquisition (startDetector, not acquire) */
Result<std::string> getScanErrorMessage(Positions pos = {}) const;
/************************************************** /**************************************************
* * * *

View File

@ -178,7 +178,7 @@ std::string CmdProxy::VirtualServer(int action) {
return os.str(); return os.str();
} }
std::string CmdProxy::acquire(int action) { std::string CmdProxy::Acquire(int action) {
std::ostringstream os; std::ostringstream os;
if (action == defs::HELP_ACTION) { if (action == defs::HELP_ACTION) {
os << cmd << " - Acquire the number of frames set up.\n"; os << cmd << " - Acquire the number of frames set up.\n";
@ -991,6 +991,60 @@ std::string CmdProxy::DetectorStatus(int action) {
return os.str(); return os.str();
} }
std::string CmdProxy::Scan(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[dac_name|0|trimbit_scan] [start_val] [stop_val] "
"[step_size] [dac settling time ns|us|ms|s]\n\tConfigures to "
"scan dac and sets number of frames to number of steps. Must "
"acquire after this. To cancel the scan configuration "
"set dac to '0' without further arguments. This also sets number "
"of frames back to 1."
"\n\t[Eiger]Use trimbit_scan as dac name for a trimbit scan."
<< '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto t = det->getScan();
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (det_id != -1) {
throw sls::RuntimeError(
"Cannot configure scan at module level");
}
// disable
if (args.size() == 1) {
if (StringTo<int>(args[0]) != 0) {
throw sls::RuntimeError("Did you mean '0' to disable?");
}
det->setScan(defs::scanParameters());
}
// enable without settling time
else if (args.size() == 4) {
det->setScan(defs::scanParameters(
StringTo<defs::dacIndex>(args[0]), StringTo<int>(args[1]),
StringTo<int>(args[2]), StringTo<int>(args[3])));
}
// enable with all parameters
else if (args.size() == 5) {
std::string time_str(args[4]);
std::string unit = RemoveUnit(time_str);
auto t = StringTo<time::ns>(time_str, unit);
det->setScan(defs::scanParameters(
StringTo<defs::dacIndex>(args[0]), StringTo<int>(args[1]),
StringTo<int>(args[2]), StringTo<int>(args[3]), t));
} else {
WrongNumberOfParameters(4);
}
os << ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
/* Network Configuration (Detector<->Receiver) */ /* Network Configuration (Detector<->Receiver) */
std::string CmdProxy::UDPDestinationIP(int action) { std::string CmdProxy::UDPDestinationIP(int action) {

View File

@ -612,7 +612,7 @@ class CmdProxy {
{"gappixels", &CmdProxy::GapPixels}, {"gappixels", &CmdProxy::GapPixels},
/* acquisition parameters */ /* acquisition parameters */
{"acquire", &CmdProxy::acquire}, {"acquire", &CmdProxy::Acquire},
{"frames", &CmdProxy::frames}, {"frames", &CmdProxy::frames},
{"triggers", &CmdProxy::triggers}, {"triggers", &CmdProxy::triggers},
{"exptime", &CmdProxy::Exptime}, {"exptime", &CmdProxy::Exptime},
@ -737,6 +737,8 @@ class CmdProxy {
{"rx_missingpackets", &CmdProxy::rx_missingpackets}, {"rx_missingpackets", &CmdProxy::rx_missingpackets},
{"startingfnum", &CmdProxy::startingfnum}, {"startingfnum", &CmdProxy::startingfnum},
{"trigger", &CmdProxy::trigger}, {"trigger", &CmdProxy::trigger},
{"scan", &CmdProxy::Scan},
{"scanerrmsg", &CmdProxy::scanerrmsg},
/* Network Configuration (Detector<->Receiver) */ /* Network Configuration (Detector<->Receiver) */
{"numinterfaces", &CmdProxy::numinterfaces}, {"numinterfaces", &CmdProxy::numinterfaces},
@ -965,7 +967,7 @@ class CmdProxy {
std::string SettingsList(int action); std::string SettingsList(int action);
std::string GapPixels(int action); std::string GapPixels(int action);
/* acquisition parameters */ /* acquisition parameters */
std::string acquire(int action); std::string Acquire(int action);
std::string Exptime(int action); std::string Exptime(int action);
std::string Speed(int action); std::string Speed(int action);
std::string Adcphase(int action); std::string Adcphase(int action);
@ -983,6 +985,7 @@ class CmdProxy {
/* acquisition */ /* acquisition */
std::string ReceiverStatus(int action); std::string ReceiverStatus(int action);
std::string DetectorStatus(int action); std::string DetectorStatus(int action);
std::string Scan(int action);
/* Network Configuration (Detector<->Receiver) */ /* Network Configuration (Detector<->Receiver) */
std::string UDPDestinationIP(int action); std::string UDPDestinationIP(int action);
std::string UDPDestinationIP2(int action); std::string UDPDestinationIP2(int action);
@ -1552,6 +1555,10 @@ class CmdProxy {
trigger, sendSoftwareTrigger, trigger, sendSoftwareTrigger,
"\n\t[Eiger] Sends software trigger signal to detector."); "\n\t[Eiger] Sends software trigger signal to detector.");
GET_COMMAND(scanerrmsg, getScanErrorMessage,
"\n\tGets Scan error message if scan ended in error for non "
"blocking acquisitions.");
/* Network Configuration (Detector<->Receiver) */ /* Network Configuration (Detector<->Receiver) */
INTEGER_COMMAND( INTEGER_COMMAND(

View File

@ -525,9 +525,6 @@ void Detector::startReceiver() { pimpl->Parallel(&Module::startReceiver, {}); }
void Detector::stopReceiver() { pimpl->Parallel(&Module::stopReceiver, {}); } void Detector::stopReceiver() { pimpl->Parallel(&Module::stopReceiver, {}); }
void Detector::startDetector() { void Detector::startDetector() {
if (getDetectorType().squash() == defs::EIGER) {
pimpl->Parallel(&Module::prepareAcquisition, {});
}
pimpl->Parallel(&Module::startAcquisition, {}); pimpl->Parallel(&Module::startAcquisition, {});
} }
@ -562,6 +559,18 @@ void Detector::sendSoftwareTrigger(Positions pos) {
pimpl->Parallel(&Module::sendSoftwareTrigger, pos); pimpl->Parallel(&Module::sendSoftwareTrigger, pos);
} }
Result<defs::scanParameters> Detector::getScan(Positions pos) const {
return pimpl->Parallel(&Module::getScan, pos);
}
void Detector::setScan(const defs::scanParameters t) {
pimpl->Parallel(&Module::setScan, {}, t);
}
Result<std::string> Detector::getScanErrorMessage(Positions pos) const {
return pimpl->Parallel(&Module::getScanErrorMessage, pos);
}
// Network Configuration (Detector<->Receiver) // Network Configuration (Detector<->Receiver)
Result<int> Detector::getNumberofUDPInterfaces(Positions pos) const { Result<int> Detector::getNumberofUDPInterfaces(Positions pos) const {

View File

@ -1046,9 +1046,6 @@ int DetectorImpl::acquire() {
// start and read all // start and read all
try { try {
if (multi_shm()->multiDetectorType == EIGER) {
Parallel(&Module::prepareAcquisition, {});
}
Parallel(&Module::startAndReadAll, {}); Parallel(&Module::startAndReadAll, {});
} catch (...) { } catch (...) {
if (receiver) if (receiver)

View File

@ -367,8 +367,6 @@ void Module::stopReceiver() {
sendToReceiver(F_STOP_RECEIVER, arg, nullptr); sendToReceiver(F_STOP_RECEIVER, arg, nullptr);
} }
void Module::prepareAcquisition() { sendToDetector(F_PREPARE_ACQUISITION); }
void Module::startAcquisition() { void Module::startAcquisition() {
shm()->stoppedFlag = false; shm()->stoppedFlag = false;
sendToDetector(F_START_ACQUISITION); sendToDetector(F_START_ACQUISITION);
@ -451,6 +449,22 @@ void Module::setStartingFrameNumber(uint64_t value) {
void Module::sendSoftwareTrigger() { sendToDetectorStop(F_SOFTWARE_TRIGGER); } void Module::sendSoftwareTrigger() { sendToDetectorStop(F_SOFTWARE_TRIGGER); }
defs::scanParameters Module::getScan() {
return sendToDetector<defs::scanParameters>(F_GET_SCAN);
}
void Module::setScan(const defs::scanParameters t) {
auto retval = sendToDetector<int64_t>(F_SET_SCAN, t);
// if disabled, retval is 1, else its number of steps
setNumberOfFrames(retval);
}
std::string Module::getScanErrorMessage() {
char retval[MAX_STR_LENGTH]{};
sendToDetector(F_GET_SCAN_ERROR_MESSAGE, nullptr, retval);
return retval;
}
// Network Configuration (Detector<->Receiver) // Network Configuration (Detector<->Receiver)
int Module::getNumberofUDPInterfacesFromShm() { int Module::getNumberofUDPInterfacesFromShm() {

View File

@ -155,7 +155,6 @@ class Module : public virtual slsDetectorDefs {
* ************************************************/ * ************************************************/
void startReceiver(); void startReceiver();
void stopReceiver(); void stopReceiver();
void prepareAcquisition();
void startAcquisition(); void startAcquisition();
void stopAcquisition(); void stopAcquisition();
void startAndReadAll(); void startAndReadAll();
@ -167,6 +166,9 @@ class Module : public virtual slsDetectorDefs {
uint64_t getStartingFrameNumber(); uint64_t getStartingFrameNumber();
void setStartingFrameNumber(uint64_t value); void setStartingFrameNumber(uint64_t value);
void sendSoftwareTrigger(); void sendSoftwareTrigger();
defs::scanParameters getScan();
void setScan(const defs::scanParameters t);
std::string getScanErrorMessage();
/************************************************** /**************************************************
* * * *

View File

@ -1178,6 +1178,134 @@ TEST_CASE("startingfnum", "[.cmd][.new]") {
} }
} }
TEST_CASE("scan", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
defs::dacIndex ind = defs::DAC_0;
defs::dacIndex notImplementedInd = defs::DAC_0;
auto det_type = det.getDetectorType().squash();
switch (det_type) {
case defs::CHIPTESTBOARD:
ind = defs::DAC_0;
notImplementedInd = defs::VSVP;
break;
case defs::EIGER:
ind = defs::VCMP_LL;
notImplementedInd = defs::VCASCP_PB;
break;
case defs::JUNGFRAU:
ind = defs::VB_COMP;
notImplementedInd = defs::VSVP;
break;
case defs::GOTTHARD:
ind = defs::VREF_DS;
notImplementedInd = defs::VSVP;
break;
case defs::MOENCH:
ind = defs::VBP_COLBUF;
notImplementedInd = defs::VSVP;
break;
case defs::GOTTHARD2:
ind = defs::VB_COMP_FE;
notImplementedInd = defs::VSVP;
break;
case defs::MYTHEN3:
ind = defs::VTH2;
notImplementedInd = defs::VSVP;
break;
default:
break;
}
// when taking acquisition
// auto previous = det.getDAC(ind, false);
// auto notImplementedPrevious = det.getDAC(notImplementedInd, false);
{
std::ostringstream oss;
proxy.Call("scan", {sls::ToString(ind), "500", "1500", "500"}, -1, PUT,
oss);
REQUIRE(oss.str() ==
"scan [" + sls::ToString(ind) + ", 500, 1500, 500]\n");
}
{
std::ostringstream oss;
proxy.Call("scan", {}, -1, GET, oss);
REQUIRE(oss.str() == "scan [[enabled\ndac " + sls::ToString(ind) +
"\nstart 500\nstop 1500\nstep "
"500\nsettleTime 1ms\n]]\n");
}
{
std::ostringstream oss;
proxy.Call("scan", {sls::ToString(ind), "500", "1500", "500", "2s"}, -1,
PUT, oss);
REQUIRE(oss.str() ==
"scan [" + sls::ToString(ind) + ", 500, 1500, 500, 2s]\n");
}
{
std::ostringstream oss;
proxy.Call("scan", {}, -1, GET, oss);
REQUIRE(oss.str() == "scan [[enabled\ndac " + sls::ToString(ind) +
"\nstart 500\nstop 1500\nstep "
"500\nsettleTime 2s\n]]\n");
}
{
std::ostringstream oss;
proxy.Call("scan", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "scan [0]\n");
}
{
std::ostringstream oss;
proxy.Call("scan", {}, -1, GET, oss);
REQUIRE(oss.str() == "scan [[disabled]]\n");
}
{
std::ostringstream oss;
proxy.Call("scan", {sls::ToString(ind), "1500", "500", "-500"}, -1, PUT,
oss);
REQUIRE(oss.str() ==
"scan [" + sls::ToString(ind) + ", 1500, 500, -500]\n");
}
REQUIRE_THROWS(proxy.Call(
"scan", {sls::ToString(notImplementedInd), "500", "1500", "500"}, -1,
PUT));
REQUIRE_THROWS(proxy.Call(
"scan", {sls::ToString(ind), "500", "1500", "-500"}, -1, PUT));
REQUIRE_THROWS(proxy.Call(
"scan", {sls::ToString(ind), "1500", "500", "500"}, -1, PUT));
if (det_type == defs::MYTHEN3 || defs::EIGER) {
{
std::ostringstream oss;
proxy.Call("scan", {"trimbit_scan", "0", "63", "16", "2s"}, -1, PUT,
oss);
REQUIRE(oss.str() == "scan [trimbit_scan, 0, 63, 16, 2s]\n");
}
{
std::ostringstream oss;
proxy.Call("scan", {}, -1, GET, oss);
REQUIRE(oss.str() ==
"scan [[enabled\ndac trimbit_scan\nstart 0\nstop 48\nstep "
"16\nsettleTime 2s\n]]\n");
}
}
// acquire for each?
// when taking acquisition
// Reset all dacs to previous value
// for (int i = 0; i != det.size(); ++i) {
// det.setDAC(ind, previous[i], false, {i});
// det.setDAC(notImplementedInd, notImplementedPrevious[i], false, {i});
// }
}
TEST_CASE("scanerrmsg", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
REQUIRE_NOTHROW(proxy.Call("scanerrmsg", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("scanerrmsg", {""}, -1, PUT));
}
TEST_CASE("gappixels", "[.cmd][.new]") { TEST_CASE("gappixels", "[.cmd][.new]") {
Detector det; Detector det;
CmdProxy proxy(&det); CmdProxy proxy(&det);

View File

@ -47,8 +47,10 @@ std::ostream &operator<<(std::ostream &os,
std::string ToString(const slsDetectorDefs::patternParameters &r); std::string ToString(const slsDetectorDefs::patternParameters &r);
std::ostream &operator<<(std::ostream &os, std::ostream &operator<<(std::ostream &os,
const slsDetectorDefs::patternParameters &r); const slsDetectorDefs::patternParameters &r);
std::string ToString(const slsDetectorDefs::scanParameters &r);
std::ostream &operator<<(std::ostream &os,
const slsDetectorDefs::scanParameters &r);
const std::string &ToString(const std::string &s); const std::string &ToString(const std::string &s);
/** Convert std::chrono::duration with specified output unit */ /** Convert std::chrono::duration with specified output unit */
template <typename T, typename Rep = double> template <typename T, typename Rep = double>
typename std::enable_if<is_duration<T>::value, std::string>::type typename std::enable_if<is_duration<T>::value, std::string>::type

View File

@ -19,6 +19,7 @@
#include "sls_detector_exceptions.h" #include "sls_detector_exceptions.h"
#include <algorithm> #include <algorithm>
#include <bitset> #include <bitset>
#include <chrono>
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#else #else
@ -303,6 +304,7 @@ typedef struct {
TEMPERATURE_SODR, TEMPERATURE_SODR,
TEMPERATURE_FPGA2, TEMPERATURE_FPGA2,
TEMPERATURE_FPGA3, TEMPERATURE_FPGA3,
TRIMBIT_SCAN,
V_POWER_A = 100, V_POWER_A = 100,
V_POWER_B = 101, V_POWER_B = 101,
V_POWER_C = 102, V_POWER_C = 102,
@ -450,6 +452,36 @@ typedef struct {
uint32_t patwait[3]{}; uint32_t patwait[3]{};
uint64_t patwaittime[3]{}; uint64_t patwaittime[3]{};
} __attribute__((packed)); } __attribute__((packed));
/** scan structure */
struct scanParameters {
int enable;
dacIndex dacInd;
int startOffset;
int stopOffset;
int stepSize;
int64_t dacSettleTime_ns;
/** disable scan */
scanParameters()
: enable(0), dacInd(DAC_0), startOffset(0), stopOffset(0),
stepSize(0), dacSettleTime_ns{0} {}
/** enable scan */
scanParameters(
dacIndex dac, int start, int stop, int step,
std::chrono::nanoseconds t = std::chrono::milliseconds{1})
: enable(1), dacInd(dac), startOffset(start), stopOffset(stop),
stepSize(step) {
dacSettleTime_ns = t.count();
}
bool operator==(const scanParameters &other) const {
return ((enable == other.enable) && (dacInd == other.dacInd) &&
(startOffset == other.startOffset) &&
(stopOffset == other.stopOffset) &&
(stepSize == other.stepSize) &&
(dacSettleTime_ns == other.dacSettleTime_ns));
}
} __attribute__((packed));
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -101,7 +101,6 @@ enum detFuncs {
F_RESET_FPGA, F_RESET_FPGA,
F_POWER_CHIP, F_POWER_CHIP,
F_ACTIVATE, F_ACTIVATE,
F_PREPARE_ACQUISITION,
F_THRESHOLD_TEMP, F_THRESHOLD_TEMP,
F_TEMP_CONTROL, F_TEMP_CONTROL,
F_TEMP_EVENT, F_TEMP_EVENT,
@ -201,6 +200,9 @@ enum detFuncs {
F_GET_VETO, F_GET_VETO,
F_SET_VETO, F_SET_VETO,
F_SET_PATTERN, F_SET_PATTERN,
F_GET_SCAN,
F_SET_SCAN,
F_GET_SCAN_ERROR_MESSAGE,
NUM_DET_FUNCTIONS, NUM_DET_FUNCTIONS,
RECEIVER_ENUM_START = 256, /**< detector function should not exceed this RECEIVER_ENUM_START = 256, /**< detector function should not exceed this
@ -400,7 +402,6 @@ const char* getFunctionNameFromEnum(enum detFuncs func) {
case F_RESET_FPGA: return "F_RESET_FPGA"; case F_RESET_FPGA: return "F_RESET_FPGA";
case F_POWER_CHIP: return "F_POWER_CHIP"; case F_POWER_CHIP: return "F_POWER_CHIP";
case F_ACTIVATE: return "F_ACTIVATE"; case F_ACTIVATE: return "F_ACTIVATE";
case F_PREPARE_ACQUISITION: return "F_PREPARE_ACQUISITION";
case F_THRESHOLD_TEMP: return "F_THRESHOLD_TEMP"; case F_THRESHOLD_TEMP: return "F_THRESHOLD_TEMP";
case F_TEMP_CONTROL: return "F_TEMP_CONTROL"; case F_TEMP_CONTROL: return "F_TEMP_CONTROL";
case F_TEMP_EVENT: return "F_TEMP_EVENT"; case F_TEMP_EVENT: return "F_TEMP_EVENT";
@ -500,6 +501,9 @@ const char* getFunctionNameFromEnum(enum detFuncs func) {
case F_GET_VETO: return "F_GET_VETO"; case F_GET_VETO: return "F_GET_VETO";
case F_SET_VETO: return "F_SET_VETO"; case F_SET_VETO: return "F_SET_VETO";
case F_SET_PATTERN: return "F_SET_PATTERN"; case F_SET_PATTERN: return "F_SET_PATTERN";
case F_GET_SCAN: return "F_GET_SCAN";
case F_SET_SCAN: return "F_SET_SCAN";
case F_GET_SCAN_ERROR_MESSAGE: return "F_GET_SCAN_ERROR_MESSAGE";
case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS";
case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";

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 APIEIGER 0x200623 #define APICTB 0x200703
#define APICTB 0x200623 #define APIGOTTHARD 0x200703
#define APIGOTTHARD 0x200623 #define APIGOTTHARD2 0x200703
#define APIGOTTHARD2 0x200623 #define APIJUNGFRAU 0x200703
#define APIJUNGFRAU 0x200623 #define APIMYTHEN3 0x200703
#define APIMYTHEN3 0x200623 #define APIMOENCH 0x200702
#define APIMOENCH 0x200623 #define APIEIGER 0x200703

View File

@ -102,6 +102,30 @@ std::ostream &operator<<(std::ostream &os,
return os << ToString(r); return os << ToString(r);
} }
std::string ToString(const slsDetectorDefs::scanParameters &r) {
std::ostringstream oss;
oss << '[';
if (r.enable) {
oss << "enabled" << std::endl
<< "dac " << ToString(r.dacInd) << std::endl
<< "start " << r.startOffset << std::endl
<< "stop " << r.stopOffset << std::endl
<< "step " << r.stepSize << std::endl
<< "settleTime "
<< ToString(std::chrono::nanoseconds{r.dacSettleTime_ns})
<< std::endl;
} else {
oss << "disabled";
}
oss << ']';
return oss.str();
}
std::ostream &operator<<(std::ostream &os,
const slsDetectorDefs::scanParameters &r) {
return os << ToString(r);
}
std::string ToString(const defs::runStatus s) { std::string ToString(const defs::runStatus s) {
switch (s) { switch (s) {
case defs::ERROR: case defs::ERROR:
@ -465,6 +489,12 @@ std::string ToString(const defs::dacIndex s) {
return std::string("vipre_cds"); return std::string("vipre_cds");
case defs::IBIAS_SFP: case defs::IBIAS_SFP:
return std::string("ibias_sfp"); return std::string("ibias_sfp");
case defs::TRIMBIT_SCAN:
return std::string("trimbit_scan");
case defs::HIGH_VOLTAGE:
return std::string("vhighvoltage");
case defs::IO_DELAY:
return std::string("iodelay");
default: default:
return std::string("Unknown"); return std::string("Unknown");
} }
@ -818,6 +848,13 @@ template <> defs::dacIndex StringTo(const std::string &s) {
return defs::VIPRE_CDS; return defs::VIPRE_CDS;
if (s == "ibias_sfp") if (s == "ibias_sfp")
return defs::IBIAS_SFP; return defs::IBIAS_SFP;
if (s == "trimbit_scan")
return defs::TRIMBIT_SCAN;
if (s == "vhighvoltage")
return defs::HIGH_VOLTAGE;
if (s == "iodelay")
return defs::IO_DELAY;
throw sls::RuntimeError("Unknown dac Index " + s); throw sls::RuntimeError("Unknown dac Index " + s);
} }

View File

@ -274,3 +274,28 @@ TEST_CASE("int or uin64_t to a string in hex") {
r = ToStringHex(temp, 8); r = ToStringHex(temp, 8);
REQUIRE(r == "[0x000000f4, 0x0000ffff, 0x001900b6]"); REQUIRE(r == "[0x000000f4, 0x0000ffff, 0x001900b6]");
} }
TEST_CASE("Streaming of slsDetectorDefs::scanParameters") {
using namespace sls;
{
defs::scanParameters t{};
std::ostringstream oss;
oss << t;
REQUIRE(oss.str() == "[disabled]");
}
{
defs::scanParameters t{defs::VTH2, 500, 1500, 500};
std::ostringstream oss;
oss << t;
REQUIRE(oss.str() == "[enabled\ndac vth2\nstart 500\nstop 1500\nstep "
"500\nsettleTime 1ms\n]");
}
{
defs::scanParameters t{defs::VTH2, 500, 1500, 500,
std::chrono::milliseconds{500}};
std::ostringstream oss;
oss << t;
REQUIRE(oss.str() == "[enabled\ndac vth2\nstart 500\nstop 1500\nstep "
"500\nsettleTime 0.5s\n]");
}
}

View File

@ -50,3 +50,25 @@ TEST_CASE("assign module", "[support]") {
CHECK(m3.iodelay == 750); CHECK(m3.iodelay == 750);
CHECK(m3.nchan == 256 * 256 * 4); CHECK(m3.nchan == 256 * 256 * 4);
} }
TEST_CASE("default construct scanParameters"){
slsDetectorDefs::scanParameters p;
CHECK(p.dacSettleTime_ns == 0);
CHECK(p.dacInd == slsDetectorDefs::DAC_0);
CHECK(p.enable == 0);
CHECK(p.startOffset == 0);
CHECK(p.stopOffset == 0);
CHECK(p.stepSize == 0);
}
TEST_CASE("compare two scanParameters"){
slsDetectorDefs::scanParameters p0;
slsDetectorDefs::scanParameters p1;
CHECK(p0 == p1);
p0.enable = 1;
CHECK_FALSE(p0 == p1);
}