diff --git a/slsDetectorServers/CMakeLists.txt b/slsDetectorServers/CMakeLists.txt index f185b732a..44abc709d 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/mythen3DetectorServer/CMakeLists.txt b/slsDetectorServers/mythen3DetectorServer/CMakeLists.txt index f6a4c841c..cf4269bed 100644 --- a/slsDetectorServers/mythen3DetectorServer/CMakeLists.txt +++ b/slsDetectorServers/mythen3DetectorServer/CMakeLists.txt @@ -10,6 +10,7 @@ add_executable(mythen3DetectorServer_virtual ../slsDetectorServer/src/LTC2620_Driver.c ../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c ../slsDetectorServer/src/programFpgaNios.c + ../slsDetectorServer/src/clogger.c ) include_directories( diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index 88f7db52d..8c4a3b68d 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -24,6 +24,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); @@ -32,6 +33,7 @@ int initCheckDone = 0; char initErrorMessage[MAX_STR_LENGTH]; #ifdef VIRTUAL +//int pipeFDs[2]; pthread_t pthread_virtual_tid; int virtual_status = 0; int virtual_stop = 0; @@ -1351,10 +1353,16 @@ int startStateMachine(){ LOG(logINFOBLUE, ("Starting State Machine\n")); // set status to running virtual_status = 1; + /*if (isControlServer) { + //write(pipeFDs[PIPE_WRITE], &virtual_status, sizeof(virtual_status)); + }*/ virtual_stop = 0; if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) { LOG(logERROR, ("Could not start Virtual acquisition thread\n")); virtual_status = 0; + /*if (isControlServer) { + //write(pipeFDs[PIPE_WRITE], &virtual_status, sizeof(virtual_status)); + }*/ return FAIL; } LOG(logINFOGREEN, ("Virtual Acquisition started\n")); @@ -1455,6 +1463,9 @@ void* start_timer(void* arg) { closeUDPSocket(0); virtual_status = 0; + /*if (isControlServer) { + //write(pipeFDs[PIPE_WRITE], &virtual_status, sizeof(virtual_status)); + } */ LOG(logINFOBLUE, ("Finished Acquiring\n")); return NULL; } @@ -1475,6 +1486,13 @@ int stopStateMachine(){ enum runStatus getRunStatus(){ #ifdef VIRTUAL + /*if (!isControlServer) { + LOG(logINFORED, ("***** reading\n")); + while (read(pipeFDs[PIPE_READ], &virtual_status, sizeof(virtual_status)) > 0) { + LOG(logINFORED, ("virtual status:%d\n", virtual_status)); + } + LOG(logINFORED, ("***** final %d\n", virtual_status)); + }*/ if(virtual_status == 0){ LOG(logINFOBLUE, ("Status: IDLE\n")); return IDLE; @@ -1550,6 +1568,12 @@ void readFrame(int *ret, char *mess) { u_int32_t runBusy() { #ifdef VIRTUAL + /*if (!isControlServer) { + LOG(logINFORED, ("runbusy \n")); + while (read(pipeFDs[PIPE_READ], &virtual_status, sizeof(virtual_status)) > 0) { + LOG(logINFORED, ("runbusy virtual status:%d\n", virtual_status)); + } + }*/ return virtual_status; #endif u_int32_t s = (bus_r(PAT_STATUS_REG) & PAT_STATUS_RUN_BUSY_MSK); diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h index 0486b21af..c41d0ef1d 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorServer_defs.h @@ -5,6 +5,9 @@ #define CTRL_SRVR_INIT_TIME_US (300 * 1000) +#define PIPE_WRITE 1 +#define PIPE_READ 0 + /* Hardware Definitions */ #define NCOUNTERS (3) #define MAX_COUNTER_MSK (0x7) diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer.c index 301b0e51b..d7b163324 100755 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer.c @@ -11,6 +11,7 @@ #include #include #include +#include // Global variables from communication_funcs extern int isControlServer; @@ -23,6 +24,9 @@ extern int checkModuleFlag; // Global variables from slsDetectorFunctionList +#ifdef VIRTUAL +//extern int pipeFDs[2]; +#endif #ifdef GOTTHARDD extern int phaseShift; #endif @@ -31,7 +35,8 @@ void error(char *msg){ perror(msg); } -int main(int argc, char *argv[]){ +int main(int argc, char *argv[]) { + // print version if (argc > 1 && !strcasecmp(argv[1], "-version")) { int version = 0; @@ -61,11 +66,7 @@ int main(int argc, char *argv[]){ { int i; for (i = 1; i < argc; ++i) { - if(!strcasecmp(argv[i],"-stopserver")) { - LOG(logINFO, ("Detected stop server\n")); - isControlServer = 0; - } - else if(!strcasecmp(argv[i],"-devel")){ + if(!strcasecmp(argv[i],"-devel")){ LOG(logINFO, ("Detected developer mode\n")); debugflag = 1; } @@ -82,7 +83,7 @@ int main(int argc, char *argv[]){ LOG(logERROR, ("cannot decode port value %s. Exiting.\n", argv[i + 1])); return -1; } - LOG(logINFO, ("Detected port: %d\n", portno)); + LOG(logINFO, ("Detected control port: %d\n", portno)); } #ifdef GOTTHARDD else if(!strcasecmp(argv[i],"-phaseshift")){ @@ -100,33 +101,53 @@ int main(int argc, char *argv[]){ } } + + // stop server #ifdef STOP_SERVER - char cmd[MAX_STR_LENGTH]; - memset(cmd, 0, MAX_STR_LENGTH); + + // create pipes to communicate with stop server +#ifdef VIRTUAL + /*if (pipe(pipeFDs) < 0) { + LOG(logERROR, ("Could not create pipes to communicate with stop server\n")); + return -1; + }*/ #endif - if (isControlServer) { - LOG(logINFO, ("Opening control server on port %d \n", portno)); -#ifdef STOP_SERVER - { - int i; - for (i = 0; i < argc; ++i) { - if (i > 0) { - strcat(cmd, " "); - } - strcat(cmd, argv[i]); - } - char temp[50]; - memset(temp, 0, sizeof(temp)); - sprintf(temp, " -stopserver -port %d &", portno + 1); - strcat(cmd, temp); - - LOG(logDEBUG1, ("Command to start stop server:%s\n", cmd)); - system(cmd); - } + + // fork stop server + pid_t cpid = fork(); + if (cpid < 0) { + LOG(logERROR, ("Could not create fork a stop server\n")); + return -1; + } + //fcntl(pipeFDs[PIPE_READ], F_SETFL, O_NONBLOCK); + //fcntl(pipeFDs[PIPE_WRITE], F_SETFL, O_NONBLOCK); + + // stop server (child process) + if (cpid == 0) { + isControlServer = 0; + ++portno; + LOG(logINFOBLUE, ("Stop server [%d]\n", portno)); + // change name of stop server to distinguish + char stopServerSuffix[30]; + memset(stopServerSuffix, 0, sizeof(stopServerSuffix)); + sprintf(stopServerSuffix, " Stop_Server %d", portno); + //strcat(argv[0], stopServerSuffix); +#ifdef VIRTUAL + //close(pipeFDs[PIPE_WRITE]); + //fcntl(pipeFDs[PIPE_READ], F_SETFL, O_NONBLOCK); #endif } else { - LOG(logINFO,("Opening stop server on port %d \n", portno)); + isControlServer = 1; + LOG(logINFOBLUE, ("Control server [%d]\n", portno)); +#ifdef VIRTUAL + //close(pipeFDs[PIPE_READ]); +#endif } +#endif + + + + init_detector(); @@ -142,7 +163,7 @@ int main(int argc, char *argv[]){ if (isControlServer) { LOG(logINFOBLUE, ("Control Server Ready...\n\n")); } else { - LOG(logINFO, ("Stop Server Ready...\n\n")); + LOG(logINFOBLUE, ("Stop Server Ready...\n\n")); } // waits for connection diff --git a/slsDetectorSoftware/tests/test-CmdProxy-global.cpp b/slsDetectorSoftware/tests/test-CmdProxy-global.cpp index 7ff52aef9..b8de30eea 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-global.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-global.cpp @@ -49,7 +49,6 @@ void test_onchip_dac(defs::dacIndex index, const std::string &dacname, int dacva auto dacValueStr = sls::ToStringHex(dacvalue); auto chipIndexStr = std::to_string(chipIndex); std::ostringstream oss_set, oss_get; - std::cout << "chipindexstr:"<