fixed start stop tests

This commit is contained in:
maliakal_d 2020-04-07 10:39:50 +02:00
parent fad10273ed
commit bdf0f9e2b9
15 changed files with 352 additions and 41 deletions

View File

@ -19,10 +19,10 @@ install(TARGETS slsProjectCWarnings
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
) )
#add_subdirectory(ctbDetectorServer) add_subdirectory(ctbDetectorServer)
#add_subdirectory(eigerDetectorServer) add_subdirectory(eigerDetectorServer)
#add_subdirectory(gotthardDetectorServer) add_subdirectory(gotthardDetectorServer)
#add_subdirectory(jungfrauDetectorServer) add_subdirectory(jungfrauDetectorServer)
add_subdirectory(mythen3DetectorServer) add_subdirectory(mythen3DetectorServer)
#add_subdirectory(gotthard2DetectorServer) add_subdirectory(gotthard2DetectorServer)
#add_subdirectory(moenchDetectorServer) add_subdirectory(moenchDetectorServer)

View File

@ -16,6 +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
) )
include_directories( include_directories(

View File

@ -10,6 +10,9 @@
#include "MAX1932.h" // hv #include "MAX1932.h" // hv
#include "INA226.h" // i2c #include "INA226.h" // i2c
#include "ALTERA_PLL.h" // pll #include "ALTERA_PLL.h" // pll
#ifdef VIRTUAL
#include "communication_virtual.h"
#endif
#include <string.h> #include <string.h>
#include <unistd.h> // usleep #include <unistd.h> // usleep
@ -30,6 +33,7 @@ extern uint64_t udpFrameNumber;
extern uint32_t udpPacketNumber; extern uint32_t udpPacketNumber;
// Global variable from communication_funcs.c // Global variable from communication_funcs.c
extern int isControlServer;
extern void getMacAddressinString(char* cmac, int size, uint64_t mac); extern void getMacAddressinString(char* cmac, int size, uint64_t mac);
extern void getIpAddressinString(char* cip, uint32_t ip); extern void getIpAddressinString(char* cip, uint32_t ip);
@ -427,6 +431,12 @@ void initStopServer() {
LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n")); LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#ifdef VIRTUAL
virtual_stop = 0;
if (!isControlServer) {
ComVirtual_setStop(virtual_stop);
}
#endif
} }
@ -469,7 +479,12 @@ void setupDetector() {
digitalEnable = 0; digitalEnable = 0;
naSamples = 1; naSamples = 1;
ndSamples = 1; ndSamples = 1;
#ifdef VIRTUAL
virtual_status = 0;
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
#endif
ALTERA_PLL_ResetPLLAndReconfiguration(); ALTERA_PLL_ResetPLLAndReconfiguration();
resetCore(); resetCore();
@ -2153,10 +2168,21 @@ int startStateMachine(){
} }
LOG(logINFOBLUE, ("Starting State Machine\n")); LOG(logINFOBLUE, ("Starting State Machine\n"));
virtual_status = 1; virtual_status = 1;
virtual_stop = 0; if (isControlServer) {
ComVirtual_setStatus(virtual_status);
virtual_stop = ComVirtual_getStop();
if (virtual_stop != 0) {
LOG(logERROR, ("Cant start acquisition. "
"Stop server has not updated stop status to 0\n"));
return FAIL;
}
}
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; virtual_status = 0;
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
return FAIL; return FAIL;
} }
LOG(logINFOGREEN, ("Virtual Acquisition started\n")); LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
@ -2190,6 +2216,10 @@ int startStateMachine(){
#ifdef VIRTUAL #ifdef VIRTUAL
void* start_timer(void* arg) { void* start_timer(void* arg) {
if (!isControlServer) {
return NULL;
}
int64_t periodNs = getPeriod(); int64_t periodNs = getPeriod();
int numFrames = (getNumFrames() * int numFrames = (getNumFrames() *
getNumTriggers() ); getNumTriggers() );
@ -2216,6 +2246,8 @@ void* start_timer(void* arg) {
// loop over number of frames // loop over number of frames
for(frameNr = 0; frameNr != numFrames; ++frameNr ) { for(frameNr = 0; frameNr != numFrames; ++frameNr ) {
// update the virtual stop from stop server
virtual_stop = ComVirtual_getStop();
//check if virtual_stop is high //check if virtual_stop is high
if(virtual_stop == 1){ if(virtual_stop == 1){
break; break;
@ -2268,6 +2300,9 @@ void* start_timer(void* arg) {
closeUDPSocket(0); closeUDPSocket(0);
virtual_status = 0; virtual_status = 0;
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
LOG(logINFOBLUE, ("Finished Acquiring\n")); LOG(logINFOBLUE, ("Finished Acquiring\n"));
return NULL; return NULL;
} }
@ -2276,7 +2311,18 @@ void* start_timer(void* arg) {
int stopStateMachine(){ int stopStateMachine(){
LOG(logINFORED, ("Stopping State Machine\n")); LOG(logINFORED, ("Stopping State Machine\n"));
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_stop = 0; if (!isControlServer) {
virtual_stop = 1;
ComVirtual_setStop(virtual_stop);
// read till status is idle
int tempStatus = 1;
while(tempStatus == 1) {
tempStatus = ComVirtual_getStatus();
}
virtual_stop = 0;
ComVirtual_setStop(virtual_stop);
LOG(logINFO, ("Stopped State Machine\n"));
}
return OK; return OK;
#endif #endif
//stop state machine //stop state machine
@ -2295,7 +2341,10 @@ int stopStateMachine(){
enum runStatus getRunStatus(){ enum runStatus getRunStatus(){
#ifdef VIRTUAL #ifdef VIRTUAL
if(virtual_status == 0){ if (!isControlServer) {
virtual_status = ComVirtual_getStatus();
}
if(virtual_status == 0) {
LOG(logINFOBLUE, ("Status: IDLE\n")); LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE; return IDLE;
}else{ }else{
@ -2567,6 +2616,9 @@ int readFrameFromFifo() {
uint32_t runBusy() { uint32_t runBusy() {
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) {
virtual_status = ComVirtual_getStatus();
}
return virtual_status; 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);

View File

@ -5,6 +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
) )
include_directories( include_directories(

View File

@ -6,6 +6,8 @@
#ifndef VIRTUAL #ifndef VIRTUAL
#include "FebControl.h" #include "FebControl.h"
#include "Beb.h" #include "Beb.h"
#else
#include "communication_virtual.h"
#endif #endif
#include <unistd.h> //to gethostname #include <unistd.h> //to gethostname
@ -71,6 +73,9 @@ int eiger_tau_ns = 0;
#ifdef VIRTUAL #ifdef VIRTUAL
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;
@ -84,10 +89,7 @@ int eiger_virtual_transmission_delay_left=0;
int eiger_virtual_transmission_delay_right=0; int eiger_virtual_transmission_delay_right=0;
int eiger_virtual_transmission_delay_frame=0; int eiger_virtual_transmission_delay_frame=0;
int eiger_virtual_transmission_flowcontrol_10g=0; int eiger_virtual_transmission_flowcontrol_10g=0;
int eiger_virtual_status=0;
int eiger_virtual_activate=1; int eiger_virtual_activate=1;
pthread_t eiger_virtual_tid;
int eiger_virtual_stop = 0;
uint64_t eiger_virtual_startingframenumber = 0; uint64_t eiger_virtual_startingframenumber = 0;
int eiger_virtual_detPos[2] = {0, 0}; int eiger_virtual_detPos[2] = {0, 0};
int eiger_virtual_test_mode = 0; int eiger_virtual_test_mode = 0;
@ -353,6 +355,10 @@ void initControlServer() {
void initStopServer() { void initStopServer() {
#ifdef VIRTUAL #ifdef VIRTUAL
getModuleConfiguration(); getModuleConfiguration();
virtual_stop = 0;
if (!isControlServer) {
ComVirtual_setStop(virtual_stop);
}
return; return;
#else #else
getModuleConfiguration(); getModuleConfiguration();
@ -469,6 +475,12 @@ void setupDetector() {
} }
} }
} }
#ifdef VIRTUAL
virtual_status = 0;
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
#endif
LOG(logINFOBLUE, ("Setting Default Parameters\n")); LOG(logINFOBLUE, ("Setting Default Parameters\n"));
//setting default measurement parameters //setting default measurement parameters
@ -1803,11 +1815,22 @@ int startStateMachine() {
return FAIL; return FAIL;
} }
LOG(logINFOBLUE, ("Starting State Machine\n")); LOG(logINFOBLUE, ("Starting State Machine\n"));
eiger_virtual_status = 1; virtual_status = 1;
eiger_virtual_stop = 0; if (isControlServer) {
if (pthread_create(&eiger_virtual_tid, NULL, &start_timer, NULL)) { ComVirtual_setStatus(virtual_status);
virtual_stop = ComVirtual_getStop();
if (virtual_stop != 0) {
LOG(logERROR, ("Cant start acquisition. "
"Stop server has not updated stop status to 0\n"));
return FAIL;
}
}
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"));
eiger_virtual_status = 0; virtual_status = 0;
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
return FAIL; return FAIL;
} }
LOG(logINFO ,("Virtual Acquisition started\n")); LOG(logINFO ,("Virtual Acquisition started\n"));
@ -1841,6 +1864,10 @@ int startStateMachine() {
#ifdef VIRTUAL #ifdef VIRTUAL
void* start_timer(void* arg) { void* start_timer(void* arg) {
if (!isControlServer) {
return NULL;
}
int64_t periodNs = eiger_virtual_period; int64_t periodNs = eiger_virtual_period;
int numFrames = nimages_per_request; int numFrames = nimages_per_request;
int64_t expUs = eiger_virtual_exptime / 1000; int64_t expUs = eiger_virtual_exptime / 1000;
@ -1900,8 +1927,10 @@ void* start_timer(void* arg) {
usleep(eiger_virtual_transmission_delay_frame); usleep(eiger_virtual_transmission_delay_frame);
// update the virtual stop from stop server
virtual_stop = ComVirtual_getStop();
//check if virtual_stop is high //check if virtual_stop is high
if(eiger_virtual_stop == 1){ if(virtual_stop == 1){
break; break;
} }
@ -1997,7 +2026,10 @@ void* start_timer(void* arg) {
closeUDPSocket(0); closeUDPSocket(0);
closeUDPSocket(1); closeUDPSocket(1);
eiger_virtual_status = 0; virtual_status = 0;
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
LOG(logINFOBLUE, ("Finished Acquiring\n")); LOG(logINFOBLUE, ("Finished Acquiring\n"));
return NULL; return NULL;
} }
@ -2009,7 +2041,18 @@ void* start_timer(void* arg) {
int stopStateMachine() { int stopStateMachine() {
LOG(logINFORED, ("Going to stop acquisition\n")); LOG(logINFORED, ("Going to stop acquisition\n"));
#ifdef VIRTUAL #ifdef VIRTUAL
eiger_virtual_stop = 0; if (!isControlServer) {
virtual_stop = 1;
ComVirtual_setStop(virtual_stop);
// read till status is idle
int tempStatus = 1;
while(tempStatus == 1) {
tempStatus = ComVirtual_getStatus();
}
virtual_stop = 0;
ComVirtual_setStop(virtual_stop);
LOG(logINFO, ("Stopped State Machine\n"));
}
return OK; return OK;
#else #else
if ((Feb_Control_StopAcquisition() != STATUS_IDLE) || (!Beb_StopAcquisition()) ) { if ((Feb_Control_StopAcquisition() != STATUS_IDLE) || (!Beb_StopAcquisition()) ) {
@ -2069,7 +2112,10 @@ int startReadOut() {
enum runStatus getRunStatus() { enum runStatus getRunStatus() {
#ifdef VIRTUAL #ifdef VIRTUAL
if (eiger_virtual_status == 0) { if (!isControlServer) {
virtual_status = ComVirtual_getStatus();
}
if (virtual_status == 0) {
LOG(logINFO, ("Status: IDLE\n")); LOG(logINFO, ("Status: IDLE\n"));
return IDLE; return IDLE;
} else { } else {
@ -2100,7 +2146,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(eiger_virtual_status == 1){ while(virtual_status == 1){
usleep(500); usleep(500);
} }
LOG(logINFOGREEN, ("acquisition successfully finished\n")); LOG(logINFOGREEN, ("acquisition successfully finished\n"));

View File

@ -11,6 +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
) )
include_directories( include_directories(

View File

@ -9,6 +9,7 @@
#include "ASIC_Driver.h" #include "ASIC_Driver.h"
#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>
@ -27,6 +28,7 @@ extern udpStruct udpDetails;
extern const enum detectorType myDetectorType; extern const enum detectorType myDetectorType;
// Global variable from communication_funcs.c // Global variable from communication_funcs.c
extern int isControlServer;
extern void getMacAddressinString(char* cmac, int size, uint64_t mac); extern void getMacAddressinString(char* cmac, int size, uint64_t mac);
extern void getIpAddressinString(char* cip, uint32_t ip); extern void getIpAddressinString(char* cip, uint32_t ip);
@ -337,6 +339,12 @@ void initStopServer() {
LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n")); LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#ifdef VIRTUAL
virtual_stop = 0;
if (!isControlServer) {
ComVirtual_setStop(virtual_stop);
}
#endif
} }
@ -386,7 +394,12 @@ void setupDetector() {
} }
} }
} }
#ifdef VIRTUAL
virtual_status = 0;
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
#endif
// pll defines // pll defines
ALTERA_PLL_C10_SetDefines(REG_OFFSET, BASE_READOUT_PLL, BASE_SYSTEM_PLL, PLL_RESET_REG, PLL_RESET_REG, PLL_RESET_READOUT_MSK, PLL_RESET_SYSTEM_MSK, READOUT_PLL_VCO_FREQ_HZ, SYSTEM_PLL_VCO_FREQ_HZ); ALTERA_PLL_C10_SetDefines(REG_OFFSET, BASE_READOUT_PLL, BASE_SYSTEM_PLL, PLL_RESET_REG, PLL_RESET_REG, PLL_RESET_READOUT_MSK, PLL_RESET_SYSTEM_MSK, READOUT_PLL_VCO_FREQ_HZ, SYSTEM_PLL_VCO_FREQ_HZ);
@ -2006,10 +2019,21 @@ 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; virtual_status = 1;
virtual_stop = 0; if (isControlServer) {
ComVirtual_setStatus(virtual_status);
virtual_stop = ComVirtual_getStop();
if (virtual_stop != 0) {
LOG(logERROR, ("Cant start acquisition. "
"Stop server has not updated stop status to 0\n"));
return FAIL;
}
}
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; virtual_status = 0;
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
return FAIL; return FAIL;
} }
LOG(logINFOGREEN, ("Virtual Acquisition started\n")); LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
@ -2028,6 +2052,10 @@ int startStateMachine(){
#ifdef VIRTUAL #ifdef VIRTUAL
void* start_timer(void* arg) { void* start_timer(void* arg) {
if (!isControlServer) {
return NULL;
}
int numRepeats = getNumTriggers(); int numRepeats = getNumTriggers();
if (getTiming() == AUTO_TIMING) { if (getTiming() == AUTO_TIMING) {
if (burstMode == BURST_OFF) { if (burstMode == BURST_OFF) {
@ -2067,6 +2095,8 @@ void* start_timer(void* arg) {
// loop over number of frames // loop over number of frames
for(frameNr = 0; frameNr != numFrames; ++frameNr ) { for(frameNr = 0; frameNr != numFrames; ++frameNr ) {
// update the virtual stop from stop server
virtual_stop = ComVirtual_getStop();
//check if virtual_stop is high //check if virtual_stop is high
if(virtual_stop == 1){ if(virtual_stop == 1){
break; break;
@ -2125,6 +2155,9 @@ void* start_timer(void* arg) {
closeUDPSocket(0); closeUDPSocket(0);
virtual_status = 0; virtual_status = 0;
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
LOG(logINFOBLUE, ("Finished Acquiring\n")); LOG(logINFOBLUE, ("Finished Acquiring\n"));
return NULL; return NULL;
} }
@ -2134,7 +2167,18 @@ void* start_timer(void* arg) {
int stopStateMachine(){ int stopStateMachine(){
LOG(logINFORED, ("Stopping State Machine\n")); LOG(logINFORED, ("Stopping State Machine\n"));
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_stop = 0; if (!isControlServer) {
virtual_stop = 1;
ComVirtual_setStop(virtual_stop);
// read till status is idle
int tempStatus = 1;
while(tempStatus == 1) {
tempStatus = ComVirtual_getStatus();
}
virtual_stop = 0;
ComVirtual_setStop(virtual_stop);
LOG(logINFO, ("Stopped State Machine\n"));
}
return OK; return OK;
#endif #endif
//stop state machine //stop state machine
@ -2145,7 +2189,10 @@ int stopStateMachine(){
enum runStatus getRunStatus(){ enum runStatus getRunStatus(){
#ifdef VIRTUAL #ifdef VIRTUAL
if(virtual_status == 0){ if (!isControlServer) {
virtual_status = ComVirtual_getStatus();
}
if(virtual_status == 0) {
LOG(logINFOBLUE, ("Status: IDLE\n")); LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE; return IDLE;
}else{ }else{
@ -2219,6 +2266,9 @@ void readFrame(int *ret, char *mess) {
u_int32_t runBusy() { u_int32_t runBusy() {
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) {
virtual_status = ComVirtual_getStatus();
}
return virtual_status; 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);

View File

@ -10,6 +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
) )
include_directories( include_directories(

View File

@ -6,6 +6,7 @@
#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"
@ -23,6 +24,7 @@ extern const enum detectorType myDetectorType;
int phaseShift = DEFAULT_PHASE_SHIFT; int phaseShift = DEFAULT_PHASE_SHIFT;
// Global variable from communication_funcs.c // Global variable from communication_funcs.c
extern int isControlServer;
extern void getMacAddressinString(char* cmac, int size, uint64_t mac); extern void getMacAddressinString(char* cmac, int size, uint64_t mac);
extern void getIpAddressinString(char* cip, uint32_t ip); extern void getIpAddressinString(char* cip, uint32_t ip);
@ -354,6 +356,12 @@ void initStopServer() {
LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n")); LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#ifdef VIRTUAL
virtual_stop = 0;
if (!isControlServer) {
ComVirtual_setStop(virtual_stop);
}
#endif
} }
@ -362,6 +370,13 @@ void initStopServer() {
void setupDetector() { 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
virtual_status = 0;
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
#endif
// Initialization // Initialization
setPhaseShiftOnce(); setPhaseShiftOnce();
@ -1496,10 +1511,21 @@ int startStateMachine(){
} }
LOG(logINFOBLUE, ("Starting State Machine\n")); LOG(logINFOBLUE, ("Starting State Machine\n"));
virtual_status = 1; virtual_status = 1;
virtual_stop = 0; if (isControlServer) {
ComVirtual_setStatus(virtual_status);
virtual_stop = ComVirtual_getStop();
if (virtual_stop != 0) {
LOG(logERROR, ("Cant start acquisition. "
"Stop server has not updated stop status to 0\n"));
return FAIL;
}
}
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; virtual_status = 0;
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
return FAIL; return FAIL;
} }
LOG(logINFOGREEN, ("Virtual Acquisition started\n")); LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
@ -1519,6 +1545,10 @@ int startStateMachine(){
#ifdef VIRTUAL #ifdef VIRTUAL
void* start_timer(void* arg) { void* start_timer(void* arg) {
if (!isControlServer) {
return NULL;
}
int64_t periodNs = getPeriod(); int64_t periodNs = getPeriod();
int numFrames = (getNumFrames() * int numFrames = (getNumFrames() *
getNumTriggers() ); getNumTriggers() );
@ -1549,6 +1579,8 @@ void* start_timer(void* arg) {
// loop over number of frames // loop over number of frames
for(frameNr = 0; frameNr != numFrames; ++frameNr ) { for(frameNr = 0; frameNr != numFrames; ++frameNr ) {
// update the virtual stop from stop server
virtual_stop = ComVirtual_getStop();
//check if virtual_stop is high //check if virtual_stop is high
if(virtual_stop == 1){ if(virtual_stop == 1){
break; break;
@ -1595,6 +1627,9 @@ void* start_timer(void* arg) {
closeUDPSocket(0); closeUDPSocket(0);
virtual_status = 0; virtual_status = 0;
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
LOG(logINFOBLUE, ("Finished Acquiring\n")); LOG(logINFOBLUE, ("Finished Acquiring\n"));
return NULL; return NULL;
} }
@ -1603,7 +1638,18 @@ void* start_timer(void* arg) {
int stopStateMachine(){ int stopStateMachine(){
LOG(logINFORED, ("Stopping State Machine\n")); LOG(logINFORED, ("Stopping State Machine\n"));
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_stop = 0; if (!isControlServer) {
virtual_stop = 1;
ComVirtual_setStop(virtual_stop);
// read till status is idle
int tempStatus = 1;
while(tempStatus == 1) {
tempStatus = ComVirtual_getStatus();
}
virtual_stop = 0;
ComVirtual_setStop(virtual_stop);
LOG(logINFO, ("Stopped State Machine\n"));
}
return OK; return OK;
#endif #endif
//stop state machine //stop state machine
@ -1625,7 +1671,10 @@ int stopStateMachine(){
enum runStatus getRunStatus(){ enum runStatus getRunStatus(){
#ifdef VIRTUAL #ifdef VIRTUAL
if(virtual_status == 0){ if (!isControlServer) {
virtual_status = ComVirtual_getStatus();
}
if(virtual_status == 0) {
LOG(logINFOBLUE, ("Status: IDLE\n")); LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE; return IDLE;
}else{ }else{
@ -1727,6 +1776,9 @@ void readFrame(int *ret, char *mess){
u_int32_t runBusy() { u_int32_t runBusy() {
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) {
virtual_status = ComVirtual_getStatus();
}
return virtual_status; return virtual_status;
#endif #endif
return runState(logDEBUG1) & STATUS_RN_BSY_MSK; return runState(logDEBUG1) & STATUS_RN_BSY_MSK;

View File

@ -12,6 +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
) )
target_include_directories(jungfrauDetectorServer_virtual target_include_directories(jungfrauDetectorServer_virtual

View File

@ -8,6 +8,7 @@
#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 <string.h> #include <string.h>
@ -25,6 +26,7 @@ extern udpStruct udpDetails;
extern const enum detectorType myDetectorType; extern const enum detectorType myDetectorType;
// Global variable from communication_funcs.c // Global variable from communication_funcs.c
extern int isControlServer;
extern void getMacAddressinString(char* cmac, int size, uint64_t mac); extern void getMacAddressinString(char* cmac, int size, uint64_t mac);
extern void getIpAddressinString(char* cip, uint32_t ip); extern void getIpAddressinString(char* cip, uint32_t ip);
@ -373,6 +375,12 @@ void initStopServer() {
LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n")); LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#ifdef VIRTUAL
virtual_stop = 0;
if (!isControlServer) {
ComVirtual_setStop(virtual_stop);
}
#endif
} }
@ -394,6 +402,13 @@ void setupDetector() {
clkPhase[i] = 0; clkPhase[i] = 0;
} }
} }
#ifdef VIRTUAL
virtual_status = 0;
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
#endif
ALTERA_PLL_ResetPLL(); ALTERA_PLL_ResetPLL();
resetCore(); resetCore();
resetPeripheral(); resetPeripheral();
@ -1625,10 +1640,21 @@ int startStateMachine(){
} }
LOG(logINFOBLUE, ("starting state machine\n")); LOG(logINFOBLUE, ("starting state machine\n"));
virtual_status = 1; virtual_status = 1;
virtual_stop = 0; if (isControlServer) {
ComVirtual_setStatus(virtual_status);
virtual_stop = ComVirtual_getStop();
if (virtual_stop != 0) {
LOG(logERROR, ("Cant start acquisition. "
"Stop server has not updated stop status to 0\n"));
return FAIL;
}
}
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; virtual_status = 0;
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
return FAIL; return FAIL;
} }
LOG(logINFOGREEN, ("Virtual Acquisition started\n")); LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
@ -1649,6 +1675,10 @@ int startStateMachine(){
#ifdef VIRTUAL #ifdef VIRTUAL
void* start_timer(void* arg) { void* start_timer(void* arg) {
if (!isControlServer) {
return NULL;
}
int numInterfaces = getNumberofUDPInterfaces(); int numInterfaces = getNumberofUDPInterfaces();
int64_t periodNs = getPeriod(); int64_t periodNs = getPeriod();
int numFrames = (getNumFrames() * int numFrames = (getNumFrames() *
@ -1680,6 +1710,8 @@ void* start_timer(void* arg) {
usleep(transmissionDelayUs); usleep(transmissionDelayUs);
// update the virtual stop from stop server
virtual_stop = ComVirtual_getStop();
//check if virtual_stop is high //check if virtual_stop is high
if(virtual_stop == 1){ if(virtual_stop == 1){
break; break;
@ -1757,6 +1789,9 @@ void* start_timer(void* arg) {
} }
virtual_status = 0; virtual_status = 0;
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
LOG(logINFOBLUE, ("Finished Acquiring\n")); LOG(logINFOBLUE, ("Finished Acquiring\n"));
return NULL; return NULL;
} }
@ -1765,7 +1800,18 @@ void* start_timer(void* arg) {
int stopStateMachine(){ int stopStateMachine(){
LOG(logINFORED, ("Stopping State Machine\n")); LOG(logINFORED, ("Stopping State Machine\n"));
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_stop = 0; if (!isControlServer) {
virtual_stop = 1;
ComVirtual_setStop(virtual_stop);
// read till status is idle
int tempStatus = 1;
while(tempStatus == 1) {
tempStatus = ComVirtual_getStatus();
}
virtual_stop = 0;
ComVirtual_setStop(virtual_stop);
LOG(logINFO, ("Stopped State Machine\n"));
}
return OK; return OK;
#endif #endif
//stop state machine //stop state machine
@ -1783,7 +1829,10 @@ int stopStateMachine(){
enum runStatus getRunStatus(){ enum runStatus getRunStatus(){
#ifdef VIRTUAL #ifdef VIRTUAL
if(virtual_status == 0){ if (!isControlServer) {
virtual_status = ComVirtual_getStatus();
}
if(virtual_status == 0) {
LOG(logINFOBLUE, ("Status: IDLE\n")); LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE; return IDLE;
}else{ }else{
@ -1857,6 +1906,9 @@ void readFrame(int *ret, char *mess){
u_int32_t runBusy() { u_int32_t runBusy() {
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) {
virtual_status = ComVirtual_getStatus();
}
return virtual_status; 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);

View File

@ -14,6 +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
) )
include_directories( include_directories(

View File

@ -8,6 +8,9 @@
#include "MAX1932.h" // hv #include "MAX1932.h" // hv
#include "ALTERA_PLL.h" // pll #include "ALTERA_PLL.h" // pll
#include "common.h" #include "common.h"
#ifdef VIRTUAL
#include "communication_virtual.h"
#endif
#include <string.h> #include <string.h>
#include <unistd.h> // usleep #include <unistd.h> // usleep
@ -28,6 +31,7 @@ extern uint64_t udpFrameNumber;
extern uint32_t udpPacketNumber; extern uint32_t udpPacketNumber;
// Global variable from communication_funcs.c // Global variable from communication_funcs.c
extern int isControlServer;
extern void getMacAddressinString(char* cmac, int size, uint64_t mac); extern void getMacAddressinString(char* cmac, int size, uint64_t mac);
extern void getIpAddressinString(char* cip, uint32_t ip); extern void getIpAddressinString(char* cip, uint32_t ip);
@ -422,6 +426,12 @@ void initStopServer() {
LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n")); LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#ifdef VIRTUAL
virtual_stop = 0;
if (!isControlServer) {
ComVirtual_setStop(virtual_stop);
}
#endif
} }
@ -474,6 +484,12 @@ void setupDetector() {
adcEnableMask_1g = 0; adcEnableMask_1g = 0;
adcEnableMask_10g = 0; adcEnableMask_10g = 0;
nSamples = 1; nSamples = 1;
#ifdef VIRTUAL
virtual_status = 0;
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
#endif
ALTERA_PLL_ResetPLLAndReconfiguration(); ALTERA_PLL_ResetPLLAndReconfiguration();
resetCore(); resetCore();
@ -1815,10 +1831,21 @@ int startStateMachine(){
} }
LOG(logINFOBLUE, ("Starting State Machine\n")); LOG(logINFOBLUE, ("Starting State Machine\n"));
virtual_status = 1; virtual_status = 1;
virtual_stop = 0; if (isControlServer) {
ComVirtual_setStatus(virtual_status);
virtual_stop = ComVirtual_getStop();
if (virtual_stop != 0) {
LOG(logERROR, ("Cant start acquisition. "
"Stop server has not updated stop status to 0\n"));
return FAIL;
}
}
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; virtual_status = 0;
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
return FAIL; return FAIL;
} }
LOG(logINFOGREEN, ("Virtual Acquisition started\n")); LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
@ -1852,6 +1879,10 @@ int startStateMachine(){
#ifdef VIRTUAL #ifdef VIRTUAL
void* start_timer(void* arg) { void* start_timer(void* arg) {
if (!isControlServer) {
return NULL;
}
int64_t periodNs = getPeriod(); int64_t periodNs = getPeriod();
int numFrames = (getNumFrames() * int numFrames = (getNumFrames() *
getNumTriggers() ); getNumTriggers() );
@ -1878,6 +1909,8 @@ void* start_timer(void* arg) {
// loop over number of frames // loop over number of frames
for(frameNr = 0; frameNr != numFrames; ++frameNr ) { for(frameNr = 0; frameNr != numFrames; ++frameNr ) {
// update the virtual stop from stop server
virtual_stop = ComVirtual_getStop();
//check if virtual_stop is high //check if virtual_stop is high
if(virtual_stop == 1){ if(virtual_stop == 1){
break; break;
@ -1929,6 +1962,9 @@ void* start_timer(void* arg) {
closeUDPSocket(0); closeUDPSocket(0);
virtual_status = 0; virtual_status = 0;
if (isControlServer) {
ComVirtual_setStatus(virtual_status);
}
LOG(logINFOBLUE, ("Finished Acquiring\n")); LOG(logINFOBLUE, ("Finished Acquiring\n"));
return NULL; return NULL;
} }
@ -1937,7 +1973,18 @@ void* start_timer(void* arg) {
int stopStateMachine(){ int stopStateMachine(){
LOG(logINFORED, ("Stopping State Machine\n")); LOG(logINFORED, ("Stopping State Machine\n"));
#ifdef VIRTUAL #ifdef VIRTUAL
virtual_stop = 0; if (!isControlServer) {
virtual_stop = 1;
ComVirtual_setStop(virtual_stop);
// read till status is idle
int tempStatus = 1;
while(tempStatus == 1) {
tempStatus = ComVirtual_getStatus();
}
virtual_stop = 0;
ComVirtual_setStop(virtual_stop);
LOG(logINFO, ("Stopped State Machine\n"));
}
return OK; return OK;
#endif #endif
//stop state machine //stop state machine
@ -1956,7 +2003,10 @@ int stopStateMachine(){
enum runStatus getRunStatus(){ enum runStatus getRunStatus(){
#ifdef VIRTUAL #ifdef VIRTUAL
if(virtual_status == 0){ if (!isControlServer) {
virtual_status = ComVirtual_getStatus();
}
if(virtual_status == 0) {
LOG(logINFOBLUE, ("Status: IDLE\n")); LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE; return IDLE;
}else{ }else{
@ -2191,6 +2241,9 @@ int readFrameFromFifo() {
uint32_t runBusy() { uint32_t runBusy() {
#ifdef VIRTUAL #ifdef VIRTUAL
if (!isControlServer) {
virtual_status = ComVirtual_getStatus();
}
return virtual_status; 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);

View File

@ -1523,7 +1523,7 @@ enum runStatus getRunStatus(){
if (!isControlServer) { if (!isControlServer) {
virtual_status = ComVirtual_getStatus(); virtual_status = ComVirtual_getStatus();
} }
if(virtual_status == 0){ if(virtual_status == 0) {
LOG(logINFOBLUE, ("Status: IDLE\n")); LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE; return IDLE;
} else{ } else{

View File

@ -868,7 +868,7 @@ TEST_CASE("start", "[.cmd][.rx][.new]") {
// PUT only command // PUT only command
REQUIRE_THROWS(proxy.Call("start", {}, -1, GET)); REQUIRE_THROWS(proxy.Call("start", {}, -1, GET));
auto prev_val = det.getExptime(); auto prev_val = det.getExptime();
det.setExptime(std::chrono::seconds(10)); det.setExptime(std::chrono::seconds(2));
{ {
std::ostringstream oss; std::ostringstream oss;
proxy.Call("start", {}, -1, PUT, oss); proxy.Call("start", {}, -1, PUT, oss);
@ -891,7 +891,7 @@ TEST_CASE("stop", "[.cmd][.rx][.new]") {
// PUT only command // PUT only command
REQUIRE_THROWS(proxy.Call("stop", {}, -1, GET)); REQUIRE_THROWS(proxy.Call("stop", {}, -1, GET));
auto prev_val = det.getExptime(); auto prev_val = det.getExptime();
det.setExptime(std::chrono::seconds(10)); det.setExptime(std::chrono::seconds(2));
det.startDetector(); det.startDetector();
{ {
std::ostringstream oss; std::ostringstream oss;
@ -917,14 +917,14 @@ TEST_CASE("status", "[.cmd][.rx][.new]") {
Detector det; Detector det;
CmdProxy proxy(&det); CmdProxy proxy(&det);
auto prev_val = det.getExptime(); auto prev_val = det.getExptime();
det.setExptime(std::chrono::seconds(10)); det.setExptime(std::chrono::seconds(2));
det.startReceiver(); det.startDetector();
{ {
std::ostringstream oss; std::ostringstream oss;
proxy.Call("status", {}, -1, GET, oss); proxy.Call("status", {}, -1, GET, oss);
REQUIRE(oss.str() == "status running\n"); REQUIRE(oss.str() == "status running\n");
} }
det.stopReceiver(); det.stopDetector();
{ {
std::ostringstream oss; std::ostringstream oss;
proxy.Call("status", {}, -1, GET, oss); proxy.Call("status", {}, -1, GET, oss);