This commit is contained in:
2020-07-02 13:42:32 +02:00
parent a656668d73
commit 93c5505285
19 changed files with 522 additions and 629 deletions

View File

@ -41,8 +41,6 @@ char initErrorMessage[MAX_STR_LENGTH];
#ifdef VIRTUAL
pthread_t pthread_virtual_tid;
int virtual_status = 0;
int virtual_stop = 0;
uint64_t virtual_pattern[MAX_PATTERN_LENGTH];
int64_t virtual_currentFrameNumber = 2;
#endif
@ -434,10 +432,7 @@ void initStopServer() {
exit(EXIT_FAILURE);
}
#ifdef VIRTUAL
virtual_stop = 0;
if (!isControlServer) {
sharedMemory_setStop(virtual_stop);
}
sharedMemory_setStop(0);
#endif
}
@ -480,10 +475,7 @@ void setupDetector() {
naSamples = 1;
ndSamples = 1;
#ifdef VIRTUAL
virtual_status = 0;
if (isControlServer) {
sharedMemory_setStatus(virtual_status);
}
sharedMemory_setStatus(IDLE);
memset(virtual_pattern, 0, sizeof(virtual_pattern));
#endif
@ -2221,22 +2213,15 @@ int startStateMachine() {
return FAIL;
}
LOG(logINFOBLUE, ("Starting State Machine\n"));
if (isControlServer) {
virtual_stop = sharedMemory_getStop();
if (virtual_stop != 0) {
LOG(logERROR, ("Cant start acquisition. "
"Stop server has not updated stop status to 0\n"));
return FAIL;
}
virtual_status = 1;
sharedMemory_setStatus(virtual_status);
if (sharedMemory_getStop() != 0) {
LOG(logERROR, ("Cant start acquisition. "
"Stop server has not updated stop status to 0\n"));
return FAIL;
}
sharedMemory_setStatus(RUNNING);
if (pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
virtual_status = 0;
if (isControlServer) {
sharedMemory_setStatus(virtual_status);
}
sharedMemory_setStatus(IDLE);
return FAIL;
}
LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
@ -2297,10 +2282,8 @@ void *start_timer(void *arg) {
// loop over number of frames
for (int frameNr = 0; frameNr != numFrames; ++frameNr) {
// update the virtual stop from stop server
virtual_stop = sharedMemory_getStop();
// check if virtual_stop is high
if (virtual_stop == 1) {
// check if manual stop
if (sharedMemory_getStop() == 1) {
break;
}
@ -2349,10 +2332,7 @@ void *start_timer(void *arg) {
closeUDPSocket(0);
virtual_status = 0;
if (isControlServer) {
sharedMemory_setStatus(virtual_status);
}
sharedMemory_setStatus(IDLE);
LOG(logINFOBLUE, ("Finished Acquiring\n"));
return NULL;
}
@ -2360,24 +2340,17 @@ void *start_timer(void *arg) {
int stopStateMachine() {
LOG(logINFORED, ("Stopping State Machine\n"));
// if scan active, stop scan
if (sharedMemory_getScanStatus()) {
// if scan active, stop scan first
if (sharedMemory_getScanStatus() == RUNNING) {
sharedMemory_setScanStop(1);
}
#ifdef VIRTUAL
if (!isControlServer) {
virtual_stop = 1;
sharedMemory_setStop(virtual_stop);
// read till status is idle
int tempStatus = 1;
while (tempStatus == 1) {
tempStatus = sharedMemory_getStatus();
}
virtual_stop = 0;
sharedMemory_setStop(virtual_stop);
virtual_status = tempStatus;
LOG(logINFO, ("Stopped State Machine\n"));
}
sharedMemory_setStop(1);
// read till status is idle
while (sharedMemory_getStatus() == RUNNING)
;
sharedMemory_setStop(0);
LOG(logINFO, ("Stopped State Machine\n"));
return OK;
#endif
// stop state machine
@ -2391,19 +2364,23 @@ int stopStateMachine() {
enum runStatus getRunStatus() {
LOG(logDEBUG1, ("Getting status\n"));
// scan error or running
if (sharedMemory_getScanStatus() == ERROR) {
LOG(logINFOBLUE, ("Status: scan ERROR\n"));
return ERROR;
}
if (sharedMemory_getScanStatus() == RUNNING) {
LOG(logINFOBLUE, ("Status: scan RUNNING\n"));
return RUNNING;
}
#ifdef VIRTUAL
if (sharedMemory_getScanStatus() || sharedMemory_getStatus()) {
if (sharedMemory_getStatus() == RUNNING) {
LOG(logINFOBLUE, ("Status: RUNNING\n"));
return RUNNING;
}
LOG(logINFOBLUE, ("Status: IDLE\n"));
return IDLE;
#endif
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));
@ -2674,10 +2651,7 @@ int readFrameFromFifo() {
uint32_t runBusy() {
#ifdef VIRTUAL
if (!isControlServer) {
virtual_status = sharedMemory_getStatus();
}
return virtual_status;
return ((sharedMemory_getStatus() == RUNNING) ? 1 : 0);
#endif
uint32_t s = (bus_r(STATUS_REG) & STATUS_RN_BSY_MSK);
// LOG(logDEBUG1, ("Status Register: %08x\n", s));