From bdf0f9e2b9697ea55a017fc866b675396ad484c8 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 7 Apr 2020 10:39:50 +0200 Subject: [PATCH] fixed start stop tests --- slsDetectorServers/CMakeLists.txt | 12 ++-- .../ctbDetectorServer/CMakeLists.txt | 1 + .../slsDetectorFunctionList.c | 60 ++++++++++++++-- .../eigerDetectorServer/CMakeLists.txt | 1 + .../slsDetectorFunctionList.c | 70 +++++++++++++++---- .../gotthard2DetectorServer/CMakeLists.txt | 1 + .../slsDetectorFunctionList.c | 58 +++++++++++++-- .../gotthardDetectorServer/CMakeLists.txt | 1 + .../slsDetectorFunctionList.c | 58 ++++++++++++++- .../jungfrauDetectorServer/CMakeLists.txt | 1 + .../slsDetectorFunctionList.c | 58 ++++++++++++++- .../moenchDetectorServer/CMakeLists.txt | 1 + .../slsDetectorFunctionList.c | 59 +++++++++++++++- .../slsDetectorFunctionList.c | 2 +- slsDetectorSoftware/tests/test-CmdProxy.cpp | 10 +-- 15 files changed, 352 insertions(+), 41 deletions(-) diff --git a/slsDetectorServers/CMakeLists.txt b/slsDetectorServers/CMakeLists.txt index 44abc709d..f185b732a 100644 --- a/slsDetectorServers/CMakeLists.txt +++ b/slsDetectorServers/CMakeLists.txt @@ -19,10 +19,10 @@ install(TARGETS slsProjectCWarnings ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) -#add_subdirectory(ctbDetectorServer) -#add_subdirectory(eigerDetectorServer) -#add_subdirectory(gotthardDetectorServer) -#add_subdirectory(jungfrauDetectorServer) +add_subdirectory(ctbDetectorServer) +add_subdirectory(eigerDetectorServer) +add_subdirectory(gotthardDetectorServer) +add_subdirectory(jungfrauDetectorServer) add_subdirectory(mythen3DetectorServer) -#add_subdirectory(gotthard2DetectorServer) -#add_subdirectory(moenchDetectorServer) +add_subdirectory(gotthard2DetectorServer) +add_subdirectory(moenchDetectorServer) diff --git a/slsDetectorServers/ctbDetectorServer/CMakeLists.txt b/slsDetectorServers/ctbDetectorServer/CMakeLists.txt index e2075eae6..0eeec6b6f 100644 --- a/slsDetectorServers/ctbDetectorServer/CMakeLists.txt +++ b/slsDetectorServers/ctbDetectorServer/CMakeLists.txt @@ -16,6 +16,7 @@ add_executable(ctbDetectorServer_virtual ../slsDetectorServer/src/LTC2620.c ../slsDetectorServer/src/MAX1932.c ../slsDetectorServer/src/programFpgaBlackfin.c + ../slsDetectorServer/src/communication_virtual.c ) include_directories( diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index e7228fd26..4e87de588 100755 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -10,6 +10,9 @@ #include "MAX1932.h" // hv #include "INA226.h" // i2c #include "ALTERA_PLL.h" // pll +#ifdef VIRTUAL +#include "communication_virtual.h" +#endif #include #include // usleep @@ -30,6 +33,7 @@ extern uint64_t udpFrameNumber; extern uint32_t udpPacketNumber; // Global variable from communication_funcs.c +extern int isControlServer; extern void getMacAddressinString(char* cmac, int size, uint64_t mac); 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")); exit(EXIT_FAILURE); } +#ifdef VIRTUAL + virtual_stop = 0; + if (!isControlServer) { + ComVirtual_setStop(virtual_stop); + } +#endif } @@ -469,7 +479,12 @@ void setupDetector() { digitalEnable = 0; naSamples = 1; ndSamples = 1; - +#ifdef VIRTUAL + virtual_status = 0; + if (isControlServer) { + ComVirtual_setStatus(virtual_status); + } +#endif ALTERA_PLL_ResetPLLAndReconfiguration(); resetCore(); @@ -2153,10 +2168,21 @@ int startStateMachine(){ } LOG(logINFOBLUE, ("Starting State Machine\n")); 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)) { LOG(logERROR, ("Could not start Virtual acquisition thread\n")); virtual_status = 0; + if (isControlServer) { + ComVirtual_setStatus(virtual_status); + } return FAIL; } LOG(logINFOGREEN, ("Virtual Acquisition started\n")); @@ -2190,6 +2216,10 @@ int startStateMachine(){ #ifdef VIRTUAL void* start_timer(void* arg) { + if (!isControlServer) { + return NULL; + } + int64_t periodNs = getPeriod(); int numFrames = (getNumFrames() * getNumTriggers() ); @@ -2216,6 +2246,8 @@ void* start_timer(void* arg) { // loop over number of frames for(frameNr = 0; frameNr != numFrames; ++frameNr ) { + // update the virtual stop from stop server + virtual_stop = ComVirtual_getStop(); //check if virtual_stop is high if(virtual_stop == 1){ break; @@ -2268,6 +2300,9 @@ void* start_timer(void* arg) { closeUDPSocket(0); virtual_status = 0; + if (isControlServer) { + ComVirtual_setStatus(virtual_status); + } LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; } @@ -2276,7 +2311,18 @@ void* start_timer(void* arg) { int stopStateMachine(){ LOG(logINFORED, ("Stopping State Machine\n")); #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; #endif //stop state machine @@ -2295,7 +2341,10 @@ int stopStateMachine(){ enum runStatus getRunStatus(){ #ifdef VIRTUAL - if(virtual_status == 0){ + if (!isControlServer) { + virtual_status = ComVirtual_getStatus(); + } + if(virtual_status == 0) { LOG(logINFOBLUE, ("Status: IDLE\n")); return IDLE; }else{ @@ -2567,6 +2616,9 @@ int readFrameFromFifo() { uint32_t runBusy() { #ifdef VIRTUAL + if (!isControlServer) { + virtual_status = ComVirtual_getStatus(); + } return virtual_status; #endif uint32_t s = (bus_r(STATUS_REG) & STATUS_RN_BSY_MSK); diff --git a/slsDetectorServers/eigerDetectorServer/CMakeLists.txt b/slsDetectorServers/eigerDetectorServer/CMakeLists.txt index 912f21bbf..b068ef4c4 100644 --- a/slsDetectorServers/eigerDetectorServer/CMakeLists.txt +++ b/slsDetectorServers/eigerDetectorServer/CMakeLists.txt @@ -5,6 +5,7 @@ set(src ../slsDetectorServer/src/communication_funcs.c ../slsDetectorServer/src/communication_funcs_UDP.c ../slsDetectorServer/src/common.c + ../slsDetectorServer/src/communication_virtual.c ) include_directories( diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 1b28e1efb..52a9ca195 100755 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -6,6 +6,8 @@ #ifndef VIRTUAL #include "FebControl.h" #include "Beb.h" +#else +#include "communication_virtual.h" #endif #include //to gethostname @@ -71,6 +73,9 @@ int eiger_tau_ns = 0; #ifdef VIRTUAL +pthread_t virtual_tid; +int virtual_status=0; +int virtual_stop = 0; //values for virtual server int64_t eiger_virtual_exptime = 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_frame=0; int eiger_virtual_transmission_flowcontrol_10g=0; -int eiger_virtual_status=0; int eiger_virtual_activate=1; -pthread_t eiger_virtual_tid; -int eiger_virtual_stop = 0; uint64_t eiger_virtual_startingframenumber = 0; int eiger_virtual_detPos[2] = {0, 0}; int eiger_virtual_test_mode = 0; @@ -353,6 +355,10 @@ void initControlServer() { void initStopServer() { #ifdef VIRTUAL getModuleConfiguration(); + virtual_stop = 0; + if (!isControlServer) { + ComVirtual_setStop(virtual_stop); + } return; #else 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")); //setting default measurement parameters @@ -1803,11 +1815,22 @@ int startStateMachine() { return FAIL; } LOG(logINFOBLUE, ("Starting State Machine\n")); - eiger_virtual_status = 1; - eiger_virtual_stop = 0; - if (pthread_create(&eiger_virtual_tid, NULL, &start_timer, NULL)) { + virtual_status = 1; + 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(&virtual_tid, NULL, &start_timer, NULL)) { LOG(logERROR, ("Could not start Virtual acquisition thread\n")); - eiger_virtual_status = 0; + virtual_status = 0; + if (isControlServer) { + ComVirtual_setStatus(virtual_status); + } return FAIL; } LOG(logINFO ,("Virtual Acquisition started\n")); @@ -1841,6 +1864,10 @@ int startStateMachine() { #ifdef VIRTUAL void* start_timer(void* arg) { + if (!isControlServer) { + return NULL; + } + int64_t periodNs = eiger_virtual_period; int numFrames = nimages_per_request; int64_t expUs = eiger_virtual_exptime / 1000; @@ -1900,8 +1927,10 @@ void* start_timer(void* arg) { usleep(eiger_virtual_transmission_delay_frame); + // update the virtual stop from stop server + virtual_stop = ComVirtual_getStop(); //check if virtual_stop is high - if(eiger_virtual_stop == 1){ + if(virtual_stop == 1){ break; } @@ -1997,7 +2026,10 @@ void* start_timer(void* arg) { closeUDPSocket(0); closeUDPSocket(1); - eiger_virtual_status = 0; + virtual_status = 0; + if (isControlServer) { + ComVirtual_setStatus(virtual_status); + } LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; } @@ -2009,7 +2041,18 @@ void* start_timer(void* arg) { int stopStateMachine() { LOG(logINFORED, ("Going to stop acquisition\n")); #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; #else if ((Feb_Control_StopAcquisition() != STATUS_IDLE) || (!Beb_StopAcquisition()) ) { @@ -2069,7 +2112,10 @@ int startReadOut() { enum runStatus getRunStatus() { #ifdef VIRTUAL - if (eiger_virtual_status == 0) { + if (!isControlServer) { + virtual_status = ComVirtual_getStatus(); + } + if (virtual_status == 0) { LOG(logINFO, ("Status: IDLE\n")); return IDLE; } else { @@ -2100,7 +2146,7 @@ enum runStatus getRunStatus() { void readFrame(int *ret, char *mess) { #ifdef VIRTUAL // wait for status to be done - while(eiger_virtual_status == 1){ + while(virtual_status == 1){ usleep(500); } LOG(logINFOGREEN, ("acquisition successfully finished\n")); diff --git a/slsDetectorServers/gotthard2DetectorServer/CMakeLists.txt b/slsDetectorServers/gotthard2DetectorServer/CMakeLists.txt index 7d2d6ed01..6b5cdbf5e 100644 --- a/slsDetectorServers/gotthard2DetectorServer/CMakeLists.txt +++ b/slsDetectorServers/gotthard2DetectorServer/CMakeLists.txt @@ -11,6 +11,7 @@ add_executable(gotthard2DetectorServer_virtual ../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c ../slsDetectorServer/src/ASIC_Driver.c ../slsDetectorServer/src/programFpgaNios.c + ../slsDetectorServer/src/communication_virtual.c ) include_directories( diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index 7ccae09df..bf9eff71f 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -9,6 +9,7 @@ #include "ASIC_Driver.h" #ifdef VIRTUAL #include "communication_funcs_UDP.h" +#include "communication_virtual.h" #endif #include @@ -27,6 +28,7 @@ extern udpStruct udpDetails; extern const enum detectorType myDetectorType; // Global variable from communication_funcs.c +extern int isControlServer; extern void getMacAddressinString(char* cmac, int size, uint64_t mac); 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")); 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 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")); // set status to running 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)) { LOG(logERROR, ("Could not start Virtual acquisition thread\n")); virtual_status = 0; + if (isControlServer) { + ComVirtual_setStatus(virtual_status); + } return FAIL; } LOG(logINFOGREEN, ("Virtual Acquisition started\n")); @@ -2028,6 +2052,10 @@ int startStateMachine(){ #ifdef VIRTUAL void* start_timer(void* arg) { + if (!isControlServer) { + return NULL; + } + int numRepeats = getNumTriggers(); if (getTiming() == AUTO_TIMING) { if (burstMode == BURST_OFF) { @@ -2067,6 +2095,8 @@ void* start_timer(void* arg) { // loop over number of frames for(frameNr = 0; frameNr != numFrames; ++frameNr ) { + // update the virtual stop from stop server + virtual_stop = ComVirtual_getStop(); //check if virtual_stop is high if(virtual_stop == 1){ break; @@ -2125,6 +2155,9 @@ void* start_timer(void* arg) { closeUDPSocket(0); virtual_status = 0; + if (isControlServer) { + ComVirtual_setStatus(virtual_status); + } LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; } @@ -2134,7 +2167,18 @@ void* start_timer(void* arg) { int stopStateMachine(){ LOG(logINFORED, ("Stopping State Machine\n")); #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; #endif //stop state machine @@ -2145,7 +2189,10 @@ int stopStateMachine(){ enum runStatus getRunStatus(){ #ifdef VIRTUAL - if(virtual_status == 0){ + if (!isControlServer) { + virtual_status = ComVirtual_getStatus(); + } + if(virtual_status == 0) { LOG(logINFOBLUE, ("Status: IDLE\n")); return IDLE; }else{ @@ -2219,6 +2266,9 @@ void readFrame(int *ret, char *mess) { u_int32_t runBusy() { #ifdef VIRTUAL + if (!isControlServer) { + virtual_status = ComVirtual_getStatus(); + } return virtual_status; #endif u_int32_t s = (bus_r(FLOW_STATUS_REG) & FLOW_STATUS_RUN_BUSY_MSK); diff --git a/slsDetectorServers/gotthardDetectorServer/CMakeLists.txt b/slsDetectorServers/gotthardDetectorServer/CMakeLists.txt index 8d38278af..eb2c60299 100644 --- a/slsDetectorServers/gotthardDetectorServer/CMakeLists.txt +++ b/slsDetectorServers/gotthardDetectorServer/CMakeLists.txt @@ -10,6 +10,7 @@ add_executable(gotthardDetectorServer_virtual ../slsDetectorServer/src/common.c ../slsDetectorServer/src/commonServerFunctions.c ../slsDetectorServer/src/communication_funcs_UDP.c + ../slsDetectorServer/src/communication_virtual.c ) include_directories( diff --git a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c index 959dd1c53..9a267e246 100755 --- a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c @@ -6,6 +6,7 @@ #include "LTC2620.h" // dacs #ifdef VIRTUAL #include "communication_funcs_UDP.h" +#include "communication_virtual.h" #endif #include "string.h" @@ -23,6 +24,7 @@ extern const enum detectorType myDetectorType; int phaseShift = DEFAULT_PHASE_SHIFT; // Global variable from communication_funcs.c +extern int isControlServer; extern void getMacAddressinString(char* cmac, int size, uint64_t mac); 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")); exit(EXIT_FAILURE); } +#ifdef VIRTUAL + virtual_stop = 0; + if (!isControlServer) { + ComVirtual_setStop(virtual_stop); + } +#endif } @@ -362,6 +370,13 @@ void initStopServer() { void setupDetector() { 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 setPhaseShiftOnce(); @@ -1496,10 +1511,21 @@ int startStateMachine(){ } LOG(logINFOBLUE, ("Starting State Machine\n")); 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)) { LOG(logERROR, ("Could not start Virtual acquisition thread\n")); virtual_status = 0; + if (isControlServer) { + ComVirtual_setStatus(virtual_status); + } return FAIL; } LOG(logINFOGREEN, ("Virtual Acquisition started\n")); @@ -1519,6 +1545,10 @@ int startStateMachine(){ #ifdef VIRTUAL void* start_timer(void* arg) { + if (!isControlServer) { + return NULL; + } + int64_t periodNs = getPeriod(); int numFrames = (getNumFrames() * getNumTriggers() ); @@ -1549,6 +1579,8 @@ void* start_timer(void* arg) { // loop over number of frames for(frameNr = 0; frameNr != numFrames; ++frameNr ) { + // update the virtual stop from stop server + virtual_stop = ComVirtual_getStop(); //check if virtual_stop is high if(virtual_stop == 1){ break; @@ -1595,6 +1627,9 @@ void* start_timer(void* arg) { closeUDPSocket(0); virtual_status = 0; + if (isControlServer) { + ComVirtual_setStatus(virtual_status); + } LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; } @@ -1603,7 +1638,18 @@ void* start_timer(void* arg) { int stopStateMachine(){ LOG(logINFORED, ("Stopping State Machine\n")); #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; #endif //stop state machine @@ -1625,7 +1671,10 @@ int stopStateMachine(){ enum runStatus getRunStatus(){ #ifdef VIRTUAL - if(virtual_status == 0){ + if (!isControlServer) { + virtual_status = ComVirtual_getStatus(); + } + if(virtual_status == 0) { LOG(logINFOBLUE, ("Status: IDLE\n")); return IDLE; }else{ @@ -1727,6 +1776,9 @@ void readFrame(int *ret, char *mess){ u_int32_t runBusy() { #ifdef VIRTUAL + if (!isControlServer) { + virtual_status = ComVirtual_getStatus(); + } return virtual_status; #endif return runState(logDEBUG1) & STATUS_RN_BSY_MSK; diff --git a/slsDetectorServers/jungfrauDetectorServer/CMakeLists.txt b/slsDetectorServers/jungfrauDetectorServer/CMakeLists.txt index 0215225ee..b3aac94aa 100644 --- a/slsDetectorServers/jungfrauDetectorServer/CMakeLists.txt +++ b/slsDetectorServers/jungfrauDetectorServer/CMakeLists.txt @@ -12,6 +12,7 @@ add_executable(jungfrauDetectorServer_virtual ../slsDetectorServer/src/MAX1932.c ../slsDetectorServer/src/programFpgaBlackfin.c ../slsDetectorServer/src/communication_funcs_UDP.c + ../slsDetectorServer/src/communication_virtual.c ) target_include_directories(jungfrauDetectorServer_virtual diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index 0d5237c6f..be97d17a2 100755 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -8,6 +8,7 @@ #include "common.h" #ifdef VIRTUAL #include "communication_funcs_UDP.h" +#include "communication_virtual.h" #endif #include @@ -25,6 +26,7 @@ extern udpStruct udpDetails; extern const enum detectorType myDetectorType; // Global variable from communication_funcs.c +extern int isControlServer; extern void getMacAddressinString(char* cmac, int size, uint64_t mac); 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")); exit(EXIT_FAILURE); } +#ifdef VIRTUAL + virtual_stop = 0; + if (!isControlServer) { + ComVirtual_setStop(virtual_stop); + } +#endif } @@ -394,6 +402,13 @@ void setupDetector() { clkPhase[i] = 0; } } +#ifdef VIRTUAL + virtual_status = 0; + if (isControlServer) { + ComVirtual_setStatus(virtual_status); + } +#endif + ALTERA_PLL_ResetPLL(); resetCore(); resetPeripheral(); @@ -1625,10 +1640,21 @@ int startStateMachine(){ } LOG(logINFOBLUE, ("starting state machine\n")); 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)) { LOG(logERROR, ("Could not start Virtual acquisition thread\n")); virtual_status = 0; + if (isControlServer) { + ComVirtual_setStatus(virtual_status); + } return FAIL; } LOG(logINFOGREEN, ("Virtual Acquisition started\n")); @@ -1649,6 +1675,10 @@ int startStateMachine(){ #ifdef VIRTUAL void* start_timer(void* arg) { + if (!isControlServer) { + return NULL; + } + int numInterfaces = getNumberofUDPInterfaces(); int64_t periodNs = getPeriod(); int numFrames = (getNumFrames() * @@ -1680,6 +1710,8 @@ void* start_timer(void* arg) { usleep(transmissionDelayUs); + // update the virtual stop from stop server + virtual_stop = ComVirtual_getStop(); //check if virtual_stop is high if(virtual_stop == 1){ break; @@ -1757,6 +1789,9 @@ void* start_timer(void* arg) { } virtual_status = 0; + if (isControlServer) { + ComVirtual_setStatus(virtual_status); + } LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; } @@ -1765,7 +1800,18 @@ void* start_timer(void* arg) { int stopStateMachine(){ LOG(logINFORED, ("Stopping State Machine\n")); #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; #endif //stop state machine @@ -1783,7 +1829,10 @@ int stopStateMachine(){ enum runStatus getRunStatus(){ #ifdef VIRTUAL - if(virtual_status == 0){ + if (!isControlServer) { + virtual_status = ComVirtual_getStatus(); + } + if(virtual_status == 0) { LOG(logINFOBLUE, ("Status: IDLE\n")); return IDLE; }else{ @@ -1857,6 +1906,9 @@ void readFrame(int *ret, char *mess){ u_int32_t runBusy() { #ifdef VIRTUAL + if (!isControlServer) { + virtual_status = ComVirtual_getStatus(); + } return virtual_status; #endif u_int32_t s = (bus_r(STATUS_REG) & RUN_BUSY_MSK); diff --git a/slsDetectorServers/moenchDetectorServer/CMakeLists.txt b/slsDetectorServers/moenchDetectorServer/CMakeLists.txt index b1acba756..ff6dd94a0 100644 --- a/slsDetectorServers/moenchDetectorServer/CMakeLists.txt +++ b/slsDetectorServers/moenchDetectorServer/CMakeLists.txt @@ -14,6 +14,7 @@ add_executable(moenchDetectorServer_virtual ../slsDetectorServer/src/MAX1932.c ../slsDetectorServer/src/programFpgaBlackfin.c ../slsDetectorServer/src/readDefaultPattern.c + ../slsDetectorServer/src/communication_virtual.c ) include_directories( diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c index 59f0763ee..9562adec2 100755 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c @@ -8,6 +8,9 @@ #include "MAX1932.h" // hv #include "ALTERA_PLL.h" // pll #include "common.h" +#ifdef VIRTUAL +#include "communication_virtual.h" +#endif #include #include // usleep @@ -28,6 +31,7 @@ extern uint64_t udpFrameNumber; extern uint32_t udpPacketNumber; // Global variable from communication_funcs.c +extern int isControlServer; extern void getMacAddressinString(char* cmac, int size, uint64_t mac); 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")); 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_10g = 0; nSamples = 1; +#ifdef VIRTUAL + virtual_status = 0; + if (isControlServer) { + ComVirtual_setStatus(virtual_status); + } +#endif ALTERA_PLL_ResetPLLAndReconfiguration(); resetCore(); @@ -1815,10 +1831,21 @@ int startStateMachine(){ } LOG(logINFOBLUE, ("Starting State Machine\n")); 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)) { LOG(logERROR, ("Could not start Virtual acquisition thread\n")); virtual_status = 0; + if (isControlServer) { + ComVirtual_setStatus(virtual_status); + } return FAIL; } LOG(logINFOGREEN, ("Virtual Acquisition started\n")); @@ -1852,6 +1879,10 @@ int startStateMachine(){ #ifdef VIRTUAL void* start_timer(void* arg) { + if (!isControlServer) { + return NULL; + } + int64_t periodNs = getPeriod(); int numFrames = (getNumFrames() * getNumTriggers() ); @@ -1878,6 +1909,8 @@ void* start_timer(void* arg) { // loop over number of frames for(frameNr = 0; frameNr != numFrames; ++frameNr ) { + // update the virtual stop from stop server + virtual_stop = ComVirtual_getStop(); //check if virtual_stop is high if(virtual_stop == 1){ break; @@ -1929,6 +1962,9 @@ void* start_timer(void* arg) { closeUDPSocket(0); virtual_status = 0; + if (isControlServer) { + ComVirtual_setStatus(virtual_status); + } LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; } @@ -1937,7 +1973,18 @@ void* start_timer(void* arg) { int stopStateMachine(){ LOG(logINFORED, ("Stopping State Machine\n")); #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; #endif //stop state machine @@ -1956,7 +2003,10 @@ int stopStateMachine(){ enum runStatus getRunStatus(){ #ifdef VIRTUAL - if(virtual_status == 0){ + if (!isControlServer) { + virtual_status = ComVirtual_getStatus(); + } + if(virtual_status == 0) { LOG(logINFOBLUE, ("Status: IDLE\n")); return IDLE; }else{ @@ -2191,6 +2241,9 @@ int readFrameFromFifo() { uint32_t runBusy() { #ifdef VIRTUAL + if (!isControlServer) { + virtual_status = ComVirtual_getStatus(); + } return virtual_status; #endif uint32_t s = (bus_r(STATUS_REG) & STATUS_RN_BSY_MSK); diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index 649645e7c..f34f6c124 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -1523,7 +1523,7 @@ enum runStatus getRunStatus(){ if (!isControlServer) { virtual_status = ComVirtual_getStatus(); } - if(virtual_status == 0){ + if(virtual_status == 0) { LOG(logINFOBLUE, ("Status: IDLE\n")); return IDLE; } else{ diff --git a/slsDetectorSoftware/tests/test-CmdProxy.cpp b/slsDetectorSoftware/tests/test-CmdProxy.cpp index c74922719..a69cb6870 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy.cpp @@ -868,7 +868,7 @@ TEST_CASE("start", "[.cmd][.rx][.new]") { // PUT only command REQUIRE_THROWS(proxy.Call("start", {}, -1, GET)); auto prev_val = det.getExptime(); - det.setExptime(std::chrono::seconds(10)); + det.setExptime(std::chrono::seconds(2)); { std::ostringstream oss; proxy.Call("start", {}, -1, PUT, oss); @@ -891,7 +891,7 @@ TEST_CASE("stop", "[.cmd][.rx][.new]") { // PUT only command REQUIRE_THROWS(proxy.Call("stop", {}, -1, GET)); auto prev_val = det.getExptime(); - det.setExptime(std::chrono::seconds(10)); + det.setExptime(std::chrono::seconds(2)); det.startDetector(); { std::ostringstream oss; @@ -917,14 +917,14 @@ TEST_CASE("status", "[.cmd][.rx][.new]") { Detector det; CmdProxy proxy(&det); auto prev_val = det.getExptime(); - det.setExptime(std::chrono::seconds(10)); - det.startReceiver(); + det.setExptime(std::chrono::seconds(2)); + det.startDetector(); { std::ostringstream oss; proxy.Call("status", {}, -1, GET, oss); REQUIRE(oss.str() == "status running\n"); } - det.stopReceiver(); + det.stopDetector(); { std::ostringstream oss; proxy.Call("status", {}, -1, GET, oss);