QVariant Server::rpcLifeSign(const QVariant &requesterVar){ QString requester = requesterVar.toString(); if (!isRunning){ std::cout << std::endl << "starting the clock..." << std::endl; startTime = time(0); isRunning = true; } if (checkElapsedTime()) { stoppedRequester++; if (stoppedRequester == glb::connectedNodes.size() - 1) broadCastCheckConcat(); return QVariant::fromValue(QString("stop")); } if (critSectionBusy) { requestQueue.push_back(requester); return QVariant::fromValue(QString("wait")); } else { if (requestQueue.size() == 0 || requestQueue[requestQueue.size()-1] == requester) { if (requestQueue.size()>0) requestQueue.pop_back(); return QVariant::fromValue(QString("goOn")); } return QVariant::fromValue(QString("wait")); } //TODO catch every possible scenario }
void Tracking::centerBall() { ballScreenParameters tempBall = ball->getScreenParameters(); if(tempBall.onScreen) { if(FRAME_WIDTH/3 < tempBall.x && tempBall.x < FRAME_WIDTH*2/3 && FRAME_HEIGHT/3 < tempBall.y && tempBall.y < FRAME_HEIGHT*2/3) { //std::cout<<"Center"<<std::endl; //head.stopHead(); } else { clock_t timeStart = clock(); if(tempBall.x<FRAME_WIDTH*2/5) { std::cout<<"Left"<<std::endl; head.moveHead(DIRECTION_LEFT); while(tempBall.x<FRAME_WIDTH/3 && !checkElapsedTime(timeStart) && tempBall.onScreen) { tempBall = ball->getScreenParameters(); } head.stopHead(); } else if (tempBall.x>FRAME_WIDTH*2/5) { std::cout<<"Right"<<std::endl; head.moveHead(DIRECTION_RIGHT); while(tempBall.x>FRAME_WIDTH*2/3 && !checkElapsedTime(timeStart) && tempBall.onScreen) { tempBall = ball->getScreenParameters(); } head.stopHead(); } else if(tempBall.y<FRAME_HEIGHT*2/5) { std::cout<<"Up"<<std::endl; head.moveHead(DIRECTION_UP); while(tempBall.y<FRAME_HEIGHT/3 && !checkElapsedTime(timeStart) && tempBall.onScreen) { tempBall = ball->getScreenParameters(); } head.stopHead(); } else if (tempBall.y>FRAME_HEIGHT*2/5) { std::cout<<"Down"<<std::endl; head.moveHead(DIRECTION_DOWN); while(tempBall.y>FRAME_HEIGHT*2/3 && !checkElapsedTime(timeStart) && tempBall.onScreen) { tempBall = ball->getScreenParameters(); } head.stopHead(); } } } }
void updateAGCDisplay() { static bool displayTimeout = false; static int clockCounter = 0; if(checkElapsedTime(2)) displayTimeout = true; if(MON::FCLK) { if(MON::RUN) { // update every 2 seconds at the start of a new instruction if(displayTimeout || dskyChanged) { clockCounter++; if( (TPG::register_SG.read() == TP12 && SEQ::register_SNI.read() == 1) || (TPG::register_SG.read() == STBY) || clockCounter > 500 || dskyChanged) { MON::displayAGC(); displayTimeout = false; clockCounter = 0; dskyChanged = false; } } } else { static bool displayOnce = false; if(TPG::register_SG.read() == WAIT) { if(displayOnce == false) { MON::displayAGC(); displayOnce = true; clockCounter = 0; } } else { displayOnce = false; } } } else MON::displayAGC(); // When the clock is manual or slow, always update. }