diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c index c93fce420..f2fd33164 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorFunctionList.c @@ -2360,6 +2360,10 @@ void *start_timer(void *arg) { int stopStateMachine() { LOG(logINFORED, ("Stopping State Machine\n")); + // if scan active, stop scan + if (sharedMemory_getScanStatus()) { + sharedMemory_setScanStop(1); + } #ifdef VIRTUAL if (!isControlServer) { virtual_stop = 1; @@ -2380,26 +2384,25 @@ int stopStateMachine() { bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_STP_ACQSTN_MSK); usleep(WAIT_TIME_US_STP_ACQ); bus_w(CONTROL_REG, bus_r(CONTROL_REG) & ~CONTROL_STP_ACQSTN_MSK); - LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG))); return OK; } enum runStatus getRunStatus() { + LOG(logDEBUG1, ("Getting status\n")); #ifdef VIRTUAL - if (!isControlServer) { - virtual_status = sharedMemory_getStatus(); - } - if (virtual_status == 0) { - LOG(logINFOBLUE, ("Status: IDLE\n")); - return IDLE; - } else { + if (sharedMemory_getScanStatus() || sharedMemory_getStatus()) { LOG(logINFOBLUE, ("Status: RUNNING\n")); return RUNNING; } + LOG(logINFOBLUE, ("Status: IDLE\n")); + return IDLE; #endif - LOG(logDEBUG1, ("Getting status\n")); + if (sharedMemory_getScanStatus()) { + LOG(logINFOBLUE, ("Status: Scan RUNNING\n")); + return RUNNING; + } uint32_t retval = bus_r(STATUS_REG); LOG(logINFO, ("Status Register: %08x\n", retval)); diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 4358ec360..0a720b9c9 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -2219,7 +2219,11 @@ void *start_timer(void *arg) { #endif int stopStateMachine() { - LOG(logINFORED, ("Going to stop acquisition\n")); + LOG(logINFORED, ("Stopping state machine\n")); + // if scan active, stop scan + if (sharedMemory_getScanStatus()) { + sharedMemory_setScanStop(1); + } #ifdef VIRTUAL if (!isControlServer) { virtual_stop = 1; @@ -2289,19 +2293,19 @@ int startReadOut() { } enum runStatus getRunStatus() { + LOG(logDEBUG1, ("Getting status\n")); #ifdef VIRTUAL - if (!isControlServer) { - virtual_status = sharedMemory_getStatus(); - } - if (virtual_status == 0) { - LOG(logINFO, ("Status: IDLE\n")); - return IDLE; - } else { - LOG(logINFO, ("Status: RUNNING...\n")); + if (sharedMemory_getScanStatus() || sharedMemory_getStatus()) { + LOG(logINFOBLUE, ("Status: RUNNING\n")); return RUNNING; } + LOG(logINFOBLUE, ("Status: IDLE\n")); + return IDLE; #else - + if (sharedMemory_getScanStatus()) { + LOG(logINFOBLUE, ("Status: Scan RUNNING\n")); + return RUNNING; + } int i = Feb_Control_AcquisitionInProgress(); if (i == STATUS_ERROR) { LOG(logERROR, ("Status: ERROR reading status register\n")); diff --git a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c index 698402ab9..ffba4787f 100644 --- a/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthard2DetectorServer/slsDetectorFunctionList.c @@ -2407,6 +2407,10 @@ void *start_timer(void *arg) { int stopStateMachine() { LOG(logINFORED, ("Stopping State Machine\n")); + // if scan active, stop scan + if (sharedMemory_getScanStatus()) { + sharedMemory_setScanStop(1); + } #ifdef VIRTUAL if (!isControlServer) { virtual_stop = 1; @@ -2430,19 +2434,19 @@ int stopStateMachine() { } enum runStatus getRunStatus() { + LOG(logDEBUG1, ("Getting status\n")); #ifdef VIRTUAL - if (!isControlServer) { - virtual_status = sharedMemory_getStatus(); - } - if (virtual_status == 0) { - LOG(logINFOBLUE, ("Status: IDLE\n")); - return IDLE; - } else { + if (sharedMemory_getScanStatus() || sharedMemory_getStatus()) { LOG(logINFOBLUE, ("Status: RUNNING\n")); return RUNNING; } + LOG(logINFOBLUE, ("Status: IDLE\n")); + return IDLE; #endif - LOG(logDEBUG1, ("Getting status\n")); + if (sharedMemory_getScanStatus()) { + LOG(logINFOBLUE, ("Status: Scan RUNNING\n")); + return RUNNING; + } uint32_t retval = bus_r(FLOW_STATUS_REG); LOG(logINFO, ("Status Register: %08x\n", retval)); diff --git a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c index 9c4fd075a..5eb44f2ca 100644 --- a/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/gotthardDetectorServer/slsDetectorFunctionList.c @@ -1635,6 +1635,10 @@ void *start_timer(void *arg) { int stopStateMachine() { LOG(logINFORED, ("Stopping State Machine\n")); + // if scan active, stop scan + if (sharedMemory_getScanStatus()) { + sharedMemory_setScanStop(1); + } #ifdef VIRTUAL if (!isControlServer) { virtual_stop = 1; @@ -1669,20 +1673,19 @@ int stopStateMachine() { } enum runStatus getRunStatus() { + LOG(logDEBUG1, ("Getting status\n")); #ifdef VIRTUAL - if (!isControlServer) { - virtual_status = sharedMemory_getStatus(); - } - if (virtual_status == 0) { - LOG(logINFOBLUE, ("Status: IDLE\n")); - return IDLE; - } else { + if (sharedMemory_getScanStatus() || sharedMemory_getStatus()) { LOG(logINFOBLUE, ("Status: RUNNING\n")); return RUNNING; } + LOG(logINFOBLUE, ("Status: IDLE\n")); + return IDLE; #endif - LOG(logDEBUG1, ("Getting status\n")); - + if (sharedMemory_getScanStatus()) { + LOG(logINFOBLUE, ("Status: Scan RUNNING\n")); + return RUNNING; + } enum runStatus s = IDLE; u_int32_t retval = runState(logINFO); diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index 9c38f9d6e..21758f076 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -1829,6 +1829,10 @@ void *start_timer(void *arg) { int stopStateMachine() { LOG(logINFORED, ("Stopping State Machine\n")); + // if scan active, stop scan + if (sharedMemory_getScanStatus()) { + sharedMemory_setScanStop(1); + } #ifdef VIRTUAL if (!isControlServer) { virtual_stop = 1; @@ -1855,20 +1859,19 @@ int stopStateMachine() { } enum runStatus getRunStatus() { + LOG(logDEBUG1, ("Getting status\n")); #ifdef VIRTUAL - if (!isControlServer) { - virtual_status = sharedMemory_getStatus(); - } - if (virtual_status == 0) { - LOG(logINFOBLUE, ("Status: IDLE\n")); - return IDLE; - } else { + if (sharedMemory_getScanStatus() || sharedMemory_getStatus()) { LOG(logINFOBLUE, ("Status: RUNNING\n")); return RUNNING; } + LOG(logINFOBLUE, ("Status: IDLE\n")); + return IDLE; #endif - LOG(logDEBUG1, ("Getting status\n")); - + if (sharedMemory_getScanStatus()) { + LOG(logINFOBLUE, ("Status: Scan RUNNING\n")); + return RUNNING; + } enum runStatus s; u_int32_t retval = bus_r(STATUS_REG); LOG(logINFO, ("Status Register: %08x\n", retval)); diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c index 1cdf449b4..94f6af61f 100644 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/moenchDetectorServer/slsDetectorFunctionList.c @@ -1992,6 +1992,10 @@ void *start_timer(void *arg) { int stopStateMachine() { LOG(logINFORED, ("Stopping State Machine\n")); + // if scan active, stop scan + if (sharedMemory_getScanStatus()) { + sharedMemory_setScanStop(1); + } #ifdef VIRTUAL if (!isControlServer) { virtual_stop = 1; @@ -2019,20 +2023,19 @@ int stopStateMachine() { } enum runStatus getRunStatus() { + LOG(logDEBUG1, ("Getting status\n")); #ifdef VIRTUAL - if (!isControlServer) { - virtual_status = sharedMemory_getStatus(); - } - if (virtual_status == 0) { - LOG(logINFOBLUE, ("Status: IDLE\n")); - return IDLE; - } else { + if (sharedMemory_getScanStatus() || sharedMemory_getStatus()) { LOG(logINFOBLUE, ("Status: RUNNING\n")); return RUNNING; } + LOG(logINFOBLUE, ("Status: IDLE\n")); + return IDLE; #endif - LOG(logDEBUG1, ("Getting status\n")); - + if (sharedMemory_getScanStatus()) { + LOG(logINFOBLUE, ("Status: Scan RUNNING\n")); + return RUNNING; + } uint32_t retval = bus_r(STATUS_REG); LOG(logINFO, ("Status Register: %08x\n", retval)); diff --git a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c index 79b9a7679..f44d23b95 100644 --- a/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/mythen3DetectorServer/slsDetectorFunctionList.c @@ -2102,6 +2102,10 @@ void *start_timer(void *arg) { int stopStateMachine() { LOG(logINFORED, ("Stopping State Machine\n")); + // if scan active, stop scan + if (sharedMemory_getScanStatus()) { + sharedMemory_setScanStop(1); + } #ifdef VIRTUAL if (!isControlServer) { virtual_stop = 1; @@ -2125,19 +2129,19 @@ int stopStateMachine() { } enum runStatus getRunStatus() { + LOG(logDEBUG1, ("Getting status\n")); #ifdef VIRTUAL - if (!isControlServer) { - virtual_status = sharedMemory_getStatus(); - } - if (virtual_status == 0) { - LOG(logINFOBLUE, ("Status: IDLE\n")); - return IDLE; - } else { + if (sharedMemory_getScanStatus() || sharedMemory_getStatus()) { LOG(logINFOBLUE, ("Status: RUNNING\n")); return RUNNING; } + LOG(logINFOBLUE, ("Status: IDLE\n")); + return IDLE; #endif - LOG(logDEBUG1, ("Getting status\n")); + if (sharedMemory_getScanStatus()) { + LOG(logINFOBLUE, ("Status: Scan RUNNING\n")); + return RUNNING; + } uint32_t retval = bus_r(FLOW_STATUS_REG); LOG(logINFO, ("Status Register: %08x\n", retval)); diff --git a/slsDetectorServers/slsDetectorServer/include/sharedMemory.h b/slsDetectorServers/slsDetectorServer/include/sharedMemory.h index 4f2ce14eb..0276ea88f 100644 --- a/slsDetectorServers/slsDetectorServer/include/sharedMemory.h +++ b/slsDetectorServers/slsDetectorServer/include/sharedMemory.h @@ -12,8 +12,13 @@ int sharedMemory_detach(); int sharedMemory_remove(); void sharedMemory_lock(); void sharedMemory_unlock(); - +#ifdef VIRTUAL void sharedMemory_setStatus(int s); int sharedMemory_getStatus(); void sharedMemory_setStop(int s); int sharedMemory_getStop(); +#endif +void sharedMemory_setScanStatus(int s); +int sharedMemory_getScanStatus(); +void sharedMemory_setScanStop(int s); +int sharedMemory_getScanStop(); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/sharedMemory.c b/slsDetectorServers/slsDetectorServer/src/sharedMemory.c index d226f96ce..0612bd8d9 100644 --- a/slsDetectorServers/slsDetectorServer/src/sharedMemory.c +++ b/slsDetectorServers/slsDetectorServer/src/sharedMemory.c @@ -20,6 +20,8 @@ typedef struct Memory { int version; sem_t sem; + int scanStatus; + int scanStop; #ifdef VIRTUAL int status; int stop; @@ -139,6 +141,7 @@ void sharedMemory_lock() { sem_wait(&(shm->sem)); } void sharedMemory_unlock() { sem_post(&(shm->sem)); } +#ifdef VIRTUAL void sharedMemory_setStatus(int s) { sharedMemory_lock(); shm->status = s; @@ -166,3 +169,32 @@ int sharedMemory_getStop() { sharedMemory_unlock(); return s; } +#endif + +void sharedMemory_setScanStatus(int s) { + sharedMemory_lock(); + shm->scanStatus = s; + sharedMemory_unlock(); +} + +int sharedMemory_getScanStatus() { + int s = 0; + 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; +} \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index d2b6c5d56..efc78f33c 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -1,6 +1,7 @@ #include "slsDetectorServer_funcs.h" #include "clogger.h" #include "communication_funcs.h" +#include "sharedMemory.h" #include "slsDetectorFunctionList.h" #include "sls_detector_funcs.h" @@ -1725,10 +1726,19 @@ int start_state_machine(int blocking, int file_des) { LOG(logERROR, (mess)); } else { int times = 1; + // start of scan if (scan) { + sharedMemory_setScanStop(0); + sharedMemory_setScanStatus(1); times = numScanSteps; } for (int i = 0; i != times; ++i) { + // if scanstop + if (scan && sharedMemory_getScanStop()) { + LOG(logINFORED, ("Scan stopped!\n")); + sharedMemory_setScanStatus(0); + break; + } if (scanTrimbits) { LOG(logINFOBLUE, ("Trimbits scan %d/%d: [%d]\n", i, times, scanSteps[i])); @@ -1744,15 +1754,27 @@ int start_state_machine(int blocking, int file_des) { int retval = getDAC(scanDac, 0); if (abs(retval - scanSteps[i]) > 5) { ret = FAIL; - sprintf(mess, "Setting dac %d : wrote %d but read %d\n", + sprintf(mess, + "Could not scan. Setting dac %d : wrote %d but " + "read %d\n", scanDac, scanSteps[i], scanSteps[i]); LOG(logERROR, (mess)); + if (scan) { + sharedMemory_setScanStatus(0); + } break; } } else { LOG(logINFOBLUE, ("Normal Acquisition (not scan)\n")); } + // if scanstop + if (scan && sharedMemory_getScanStop()) { + LOG(logINFORED, ("Scan stopped!\n")); + sharedMemory_setScanStatus(0); + break; + } ret = startStateMachine(); + LOG(logDEBUG2, ("Starting Acquisition ret: %d\n", ret)); if (ret == FAIL) { #if defined(CHIPTESTBOARDD) || defined(MOENCHD) || defined(VIRTUAL) sprintf( @@ -1763,6 +1785,9 @@ int start_state_machine(int blocking, int file_des) { sprintf(mess, "Could not start acquisition\n"); #endif LOG(logERROR, (mess)); + if (scan) { + sharedMemory_setScanStatus(0); + } break; } // blocking or scan @@ -1771,7 +1796,10 @@ int start_state_machine(int blocking, int file_des) { } } } - LOG(logDEBUG2, ("Starting Acquisition ret: %d\n", ret)); + // end of scan + if (scan) { + sharedMemory_setScanStatus(0); + } } return Server_SendResult(file_des, INT32, NULL, 0); }