/** * checkCond * @param evaluating - the condition_t to be evaluated, which contains the index of the sensor * to be evaluated, the operator type, and the count value to be compared against * @return TRUE representing if the condition_t checked was true or not. * INFO: This function takes in a condition_t, which is used by both pending commands for their wait conditions * and as the exit conditions. * The sensor ID is used to get the corresponding value from the last telemetry values. * There are TWO special IDs that are not onboard sensor IDs to identify relative and absolute time conditions. * Absolute time uses the current time (encoded in csunSatEpoch) and relative time subtracts the time the last * command was executed from the current time. * The "current" value is compared to the condition value and the boolean result of the comparison is returned. */ BOOL checkCond(condition_t evaluating){ //need to know sensor number being used for TIME value uint32_t sensor_val; BOOL ret = false; //get the most recent sensor value if(evaluating.sensor_id == PSENSOR_COMMAND_RELATIVE_TIME){ dprintf("relative time check - "); sensor_val = (csunSatEpoch(getRTC()) - Global->csSequence.lastCmdTime); //should always be a positive value... } else if (evaluating.sensor_id == PSENSOR_ABSOLUTE_TIME){ dprintf("time check - "); sensor_val = csunSatEpoch(getRTC()); } else{ dprintf("sensor %d val - ",evaluating.sensor_id); sensor_val = Global->csLastTelemetry.reading[evaluating.sensor_id]; } switch(evaluating.comparator){ case LESS: dprintf("%ld < %ld: ", sensor_val, evaluating.value); if(sensor_val<evaluating.value){ dprintf("true! "); ret = true; } break; case LESS_EQ: dprintf("%ld <= %ld: ", sensor_val, evaluating.value); if(sensor_val<=evaluating.value){ dprintf("true! "); ret = true; } break; case EQUAL: dprintf("%ld == %ld: ", sensor_val, evaluating.value); if(sensor_val==evaluating.value){ dprintf("true! "); ret = true; } break; case GREATER_EQ: dprintf("%ld >= %ld: ", sensor_val, evaluating.value); if(sensor_val >= evaluating.value){ dprintf("true! "); ret = true; } break; case GREATER: dprintf("%ld > %ld: ", sensor_val, evaluating.value); if(sensor_val>evaluating.value){ dprintf("true! "); ret = true; } break; //no default since all potential values are already covered } return ret; }
bool PresentationView::connectDPorts(std::string m_path, std::string pname, PortService_ptr p1) { std::vector<std::string> vrp = split(m_path, "\\"); if(vrp.size() > 1) { RTC::CorbaNaming namingserver(m_manager->getORB(), vrp[0].c_str()); TreeObject *to = new TreeObject(vrp[0].c_str()); std::vector<OtherPort> ops; rtc_get_rtclist(namingserver, ops, to, vrp[0]); RTC::PortService_var p; std::vector<std::string> s; OtherPort op = OtherPort(p, s); vrp.push_back(pname); if(getRTC(vrp, ops, op)) { //std::string tname = op.pb->get_port_profile()->name; PortService_var p = op.pb; //std::vector<std::string> pn = split(tname, "."); portConnect(p1, p); return true; } } return false; }
void eDVBLocalTimeHandler::updateTime( time_t tp_time, eDVBChannel *chan, int update_count ) { int time_difference; bool restart_tdt = false; if (!tp_time) restart_tdt = true; else if (tp_time == -1) { restart_tdt = true; /*if ( eSystemInfo::getInstance()->getHwType() == eSystemInfo::DM7020 || ( eSystemInfo::getInstance()->getHwType() == eSystemInfo::DM7000 && eSystemInfo::getInstance()->hasStandbyWakeupTimer() ) ) TODO !!!!!!! */ { eDebug("[eDVBLocalTimerHandler] no transponder tuned... or no TDT/TOT avail .. try to use RTC :)"); time_t rtc_time = getRTC(); if ( rtc_time ) // RTC Ready? { tm now; localtime_r(&rtc_time, &now); eDebug("[eDVBLocalTimerHandler] RTC time is %02d:%02d:%02d", now.tm_hour, now.tm_min, now.tm_sec); time_t linuxTime=time(0); localtime_r(&linuxTime, &now); eDebug("[eDVBLocalTimerHandler] Receiver time is %02d:%02d:%02d", now.tm_hour, now.tm_min, now.tm_sec); time_difference = rtc_time - linuxTime; eDebug("[eDVBLocalTimerHandler] RTC to Receiver time difference is %ld seconds", linuxTime - rtc_time ); if ( time_difference ) { eDebug("[eDVBLocalTimerHandler] set Linux Time to RTC Time"); timeval tnow; gettimeofday(&tnow,0); tnow.tv_sec=rtc_time; settimeofday(&tnow,0); } else if ( !time_difference ) eDebug("[eDVBLocalTimerHandler] no change needed"); else eDebug("[eDVBLocalTimerHandler] set to RTC time"); /*emit*/ m_timeUpdated(); } else eDebug("[eDVBLocalTimerHandler] getRTC returned time=0. RTC problem?"); } } else { std::map< eDVBChannelID, int >::iterator it( m_timeOffsetMap.find( chan->getChannelID() ) ); // current linux time time_t linuxTime = time(0); // difference between current enigma time and transponder time int enigma_diff = tp_time-linuxTime; int new_diff=0; bool updated = m_time_ready; if ( m_time_ready ) // ref time ready? { // difference between reference time (current enigma time) // and the transponder time eDebug("[eDVBLocalTimerHandler] diff is %d", enigma_diff); if ( abs(enigma_diff) < 120 ) { eDebug("[eDVBLocalTimerHandler] diff < 120 .. use Transponder Time"); m_timeOffsetMap[chan->getChannelID()] = 0; new_diff = enigma_diff; } else if ( it != m_timeOffsetMap.end() ) // correction saved? { eDebug("[eDVBLocalTimerHandler] we have correction %d", it->second); time_t CorrectedTpTime = tp_time+it->second; int ddiff = CorrectedTpTime-linuxTime; eDebug("[eDVBLocalTimerHandler] diff after add correction is %d", ddiff); if ( abs(it->second) < 300 ) // stored correction < 5 min { eDebug("[eDVBLocalTimerHandler] use stored correction(<5 min)"); new_diff = ddiff; } else if ( getRTC() ) { time_t rtc=getRTC(); m_timeOffsetMap[chan->getChannelID()] = rtc-tp_time; new_diff = rtc-linuxTime; // set enigma time to rtc eDebug("[eDVBLocalTimerHandler] update stored correction to %ld (calced against RTC time)", rtc-tp_time ); } else if ( abs(ddiff) <= 120 ) { // with stored correction calced time difference is lower 2 min // this don't help when a transponder have a clock running to slow or to fast // then its better to have a DM7020 with always running RTC eDebug("[eDVBLocalTimerHandler] use stored correction(corr < 2 min)"); new_diff = ddiff; } else // big change in calced correction.. hold current time and update correction { eDebug("[eDVBLocalTimerHandler] update stored correction to %d", -enigma_diff); m_timeOffsetMap[chan->getChannelID()] = -enigma_diff; } } else { eDebug("[eDVBLocalTimerHandler] no correction found... store calced correction(%d)",-enigma_diff); m_timeOffsetMap[chan->getChannelID()] = -enigma_diff; } } else // no time setted yet { if ( it != m_timeOffsetMap.end() ) { enigma_diff += it->second; eDebug("[eDVBLocalTimerHandler] we have correction (%d)... use", it->second ); } else eDebug("[eDVBLocalTimerHandler] dont have correction.. set Transponder Diff"); new_diff=enigma_diff; m_time_ready=true; } time_t t = linuxTime+new_diff; m_last_tp_time_difference=tp_time-t; if (!new_diff && updated) // overrride this check on first received TDT { eDebug("[eDVBLocalTimerHandler] not changed"); return; } if ( !update_count ) { // set rtc to calced transponder time when the first tdt is received on this // transponder setRTC(t); eDebug("[eDVBLocalTimerHandler] update RTC"); } else if (getRTC()) { if (abs(getRTC() - t) > 60) { eDebug("[eDVBLocalTimerHandler] difference between new linux time and RTC time is > 60 sec... transponder time looks not ok... use rtc time"); t = getRTC(); } else eDebug("[eDVBLocalTimerHandler] difference between linux time and RTC time is < 60 sec... so the transponder time looks ok"); } else eDebug("[eDVBLocalTimerHandler] no RTC available :("); tm now; localtime_r(&t, &now); eDebug("[eDVBLocalTimerHandler] time update to %02d:%02d:%02d", now.tm_hour, now.tm_min, now.tm_sec); time_difference = t - linuxTime; // calc our new linux_time -> enigma_time correction eDebug("[eDVBLocalTimerHandler] m_time_difference is %d", time_difference ); if ( time_difference ) { eDebug("[eDVBLocalTimerHandler] set Linux Time"); timeval tnow; gettimeofday(&tnow,0); tnow.tv_sec=t; settimeofday(&tnow,0); } /*emit*/ m_timeUpdated(); } if ( restart_tdt ) { std::map<iDVBChannel*, channel_data>::iterator it = m_knownChannels.find(chan); if ( it != m_knownChannels.end() ) { int updateCount = it->second.tdt->getUpdateCount(); it->second.tdt = 0; it->second.tdt = new TDT(chan, updateCount); it->second.tdt->startTimer(TIME_UPDATE_INTERVAL); // restart TDT for this transponder in 30min } } }
void eDVBLocalTimeHandler::updateTime( time_t tp_time, eDVBChannel *chan, int update_count ) { int time_difference; bool restart_tdt = false; if (!tp_time) restart_tdt = true; else if (tp_time == -1) { restart_tdt = true; eDebug("[eDVBLocalTimerHandler] no transponder tuned... or no TDT/TOT avail .. try to use RTC :)"); time_t rtc_time = getRTC(); if (rtc_time) // RTC Ready? { tm now; localtime_r(&rtc_time, &now); eDebug("[eDVBLocalTimerHandler] RTC time is %02d:%02d:%02d", now.tm_hour, now.tm_min, now.tm_sec); time_t linuxTime=time(0); localtime_r(&linuxTime, &now); eDebug("[eDVBLocalTimerHandler] Receiver time is %02d:%02d:%02d", now.tm_hour, now.tm_min, now.tm_sec); time_difference = rtc_time - linuxTime; eDebug("[eDVBLocalTimerHandler] RTC to Receiver time difference is %ld seconds", linuxTime - rtc_time ); if (time_difference) { if ((time_difference >= -15) && (time_difference <= 15)) { timeval tdelta, tolddelta; // Slew small diffs ... // Even good transponders can differ by 0-5 sec, if we would step these // the system clock would permanentely jump around when zapping. tdelta.tv_sec = time_difference; if(adjtime(&tdelta, &tolddelta) == 0) eDebug("[eDVBLocalTimerHandler] slewing Linux Time by %03d seconds", time_difference); else eDebug("[eDVBLocalTimerHandler] slewing Linux Time by %03d seconds FAILED", time_difference); } else { timeval tnow; // ... only step larger diffs gettimeofday(&tnow, 0); tnow.tv_sec = rtc_time; settimeofday(&tnow, 0); linuxTime = time(0); localtime_r(&linuxTime, &now); eDebug("[eDVBLocalTimerHandler] stepped Linux Time to %02d:%02d:%02d", now.tm_hour, now.tm_min, now.tm_sec); } } else if ( !time_difference ) eDebug("[eDVBLocalTimerHandler] no change needed"); else eDebug("[eDVBLocalTimerHandler] set to RTC time"); /*emit*/ m_timeUpdated(); } else eDebug("[eDVBLocalTimerHandler] getRTC returned time=0. RTC problem?"); } else { std::map< eDVBChannelID, int >::iterator it( m_timeOffsetMap.find( chan->getChannelID() ) ); // current linux time time_t linuxTime = time(0); // difference between current enigma time and transponder time int enigma_diff = tp_time-linuxTime; int new_diff=0; bool updated = m_time_ready; if ( m_time_ready ) // ref time ready? { // difference between reference time (current enigma time) // and the transponder time eDebug("[eDVBLocalTimerHandler] diff is %d", enigma_diff); if ( abs(enigma_diff) < 120 ) { eDebug("[eDVBLocalTimerHandler] diff < 120 .. use Transponder Time"); m_timeOffsetMap[chan->getChannelID()] = 0; new_diff = enigma_diff; } else if ( it != m_timeOffsetMap.end() ) // correction saved? { eDebug("[eDVBLocalTimerHandler] we have correction %d", it->second); time_t CorrectedTpTime = tp_time+it->second; int ddiff = CorrectedTpTime-linuxTime; eDebug("[eDVBLocalTimerHandler] diff after add correction is %d", ddiff); if ( abs(it->second) < 300 ) // stored correction < 5 min { eDebug("[eDVBLocalTimerHandler] use stored correction(<5 min)"); new_diff = ddiff; } else if ( getRTC() ) { time_t rtc=getRTC(); m_timeOffsetMap[chan->getChannelID()] = rtc-tp_time; new_diff = rtc-linuxTime; // set enigma time to rtc eDebug("[eDVBLocalTimerHandler] update stored correction to %ld (calced against RTC time)", rtc-tp_time ); } else if ( abs(ddiff) <= 120 ) { // with stored correction calced time difference is lower 2 min // this don't help when a transponder have a clock running to slow or to fast // then its better to have a DM7020 with always running RTC eDebug("[eDVBLocalTimerHandler] use stored correction(corr < 2 min)"); new_diff = ddiff; } else // big change in calced correction.. hold current time and update correction { eDebug("[eDVBLocalTimerHandler] update stored correction to %d", -enigma_diff); m_timeOffsetMap[chan->getChannelID()] = -enigma_diff; } } else { eDebug("[eDVBLocalTimerHandler] no correction found... store calced correction(%d)",-enigma_diff); m_timeOffsetMap[chan->getChannelID()] = -enigma_diff; } } else // no time setted yet { if ( it != m_timeOffsetMap.end() ) { enigma_diff += it->second; eDebug("[eDVBLocalTimerHandler] we have correction (%d)... use", it->second ); } else eDebug("[eDVBLocalTimerHandler] dont have correction.. set Transponder Diff"); new_diff=enigma_diff; m_time_ready=true; } time_t t = linuxTime+new_diff; m_last_tp_time_difference=tp_time-t; if (!new_diff && updated) // overrride this check on first received TDT { eDebug("[eDVBLocalTimerHandler] not changed"); return; } if ( !update_count ) { // set rtc to calced transponder time when the first tdt is received on this // transponder setRTC(t); eDebug("[eDVBLocalTimerHandler] update RTC"); } else if (getRTC()) { if (abs(getRTC() - t) > 60) { eDebug("[eDVBLocalTimerHandler] difference between new linux time and RTC time is > 60 sec... transponder time looks not ok... use rtc time"); t = getRTC(); } else eDebug("[eDVBLocalTimerHandler] difference between linux time and RTC time is < 60 sec... so the transponder time looks ok"); } else eDebug("[eDVBLocalTimerHandler] no RTC available :("); tm now; localtime_r(&t, &now); eDebug("[eDVBLocalTimerHandler] time update to %02d:%02d:%02d", now.tm_hour, now.tm_min, now.tm_sec); time_difference = t - linuxTime; // calc our new linux_time -> enigma_time correction eDebug("[eDVBLocalTimerHandler] m_time_difference is %d", time_difference ); if ( time_difference ) { eDebug("[eDVBLocalTimerHandler] set Linux Time"); timeval tnow; gettimeofday(&tnow,0); tnow.tv_sec=t; settimeofday(&tnow,0); } /*emit*/ m_timeUpdated(); } if ( restart_tdt ) { std::map<iDVBChannel*, channel_data>::iterator it = m_knownChannels.find(chan); if ( it != m_knownChannels.end() ) { int system = iDVBFrontend::feSatellite; ePtr<iDVBFrontendParameters> parms; chan->getCurrentFrontendParameters(parms); if (parms) { parms->getSystem(system); } int updateCount = it->second.timetable->getUpdateCount(); it->second.timetable = NULL; if (system == iDVBFrontend::feATSC) { it->second.timetable = new STT(chan, updateCount); } else { it->second.timetable = new TDT(chan, updateCount); } it->second.timetable->startTimer(TIME_UPDATE_INTERVAL); // restart TDT for this transponder in 30min } } }
void SkServer::dataReady() { QByteArray data; data = m_client->readAll(); qDebug() << data; QStringList commands; QString str; for (int i = 0; i < data.count(); i++) { if ((data.mid(i, 3) == "\r\n\n") || (data.mid(i, 3) == "\r\n")) { commands.append(str); i += 2; str.clear(); } else { str += data[i]; } } if (commands.count() == 0) { sendData(SKS_INVALID); return; } foreach (const QString &command, commands) { if (command.startsWith("Echo ", Qt::CaseInsensitive)) { sendData(command.mid(5).toLocal8Bit()); } else if (command.startsWith("SetPos ", Qt::CaseInsensitive)) { setRA_Dec(command.mid(6)); } else if (!command.compare("GetPos", Qt::CaseInsensitive)) { getPos(); } else if (!command.compare("GetJD", Qt::CaseInsensitive)) { getJD(); } else if (command.startsWith("SetJD ", Qt::CaseInsensitive)) { setJD(command.mid(5)); } else if (!command.compare("ZoomIn", Qt::CaseInsensitive)) { zoom(1); } else if (!command.compare("ZoomOut", Qt::CaseInsensitive)) { zoom(-1); } else if (command.startsWith("SetMode ", Qt::CaseInsensitive)) { setMode(command.mid(8)); } else if (!command.compare("ServerVer", Qt::CaseInsensitive)) { sendData(SK_SERVER_VERSION); } else if (!command.compare("SwVer", Qt::CaseInsensitive)) { sendData(SK_VERSION); } else if (command.startsWith("SetExtFrame ", Qt::CaseInsensitive)) { setExtFrame(command.mid(11)); } else if (!command.compare("GetExtFrame", Qt::CaseInsensitive)) { getExtFrame(); } else if (command.startsWith("SetRTC ", Qt::CaseInsensitive)) { setRTC(command.mid(7)); } else if (!command.compare("GetRTC", Qt::CaseInsensitive)) { getRTC(); } else if (!command.compare("Redraw", Qt::CaseInsensitive)) { m_mainWin->getView()->repaintMap(); sendData(SKS_OK); } else { sendData(SKS_UNKNOWN); } } }
void eDVBServiceController::TDTready(int error) { eDebug("TDTready %d", error); // receive new TDT every 60 minutes updateTDTTimer.start(60*60*1000,true); if (!error && transponder) { std::map<tsref,int> &tOffsMap = eTransponderList::getInstance()->TimeOffsetMap; std::map< tsref, int >::iterator it( tOffsMap.find( *transponder ) ); // current linux time time_t linuxTime = time(0); // current enigma time time_t nowTime=linuxTime+dvb.time_difference; // difference between current enigma time and transponder time int enigma_diff = tdt->UTC_time-nowTime; int new_diff=0; if (timeSet) // ref time ready? { // difference between reference time (current enigma time) // and the transponder time eDebug("[TIME] diff is %d", enigma_diff); if ( abs(enigma_diff) < 120 ) { eDebug("[TIME] diff < 120 .. use Transponder Time"); tOffsMap[*transponder] = 0; new_diff = enigma_diff; } else if ( it != tOffsMap.end() ) // correction saved? { eDebug("[TIME] we have correction %d", it->second); time_t CorrectedTpTime = tdt->UTC_time+it->second; int ddiff = CorrectedTpTime-nowTime; eDebug("[TIME] diff after add correction is %d", ddiff); if ( abs(it->second) < 300 ) // stored correction < 5 min { eDebug("[TIME] use stored correction(<5 min)"); new_diff = ddiff; } else if ( eSystemInfo::getInstance()->getHwType() == eSystemInfo::DM7020 && getRTC() ) { time_t rtc=getRTC(); tOffsMap[*transponder] = rtc-tdt->UTC_time; new_diff = rtc-nowTime; // set enigma time to rtc eDebug("[TIME] update stored correction to %d (calced against RTC time)", rtc-tdt->UTC_time ); } else if ( abs(ddiff) <= 120 ) { // with stored correction calced time difference is lower 2 min // this don't help when a transponder have a clock running to slow or to fast // then its better to have a DM7020 with always running RTC eDebug("[TIME] use stored correction(corr < 2 min)"); new_diff = ddiff; } else // big change in calced correction.. hold current time and update correction { eDebug("[TIME] update stored correction to %d", -enigma_diff); tOffsMap[*transponder] = -enigma_diff; } } else { eDebug("[TIME] no correction found... store calced correction(%d)",-enigma_diff); tOffsMap[*transponder] = -enigma_diff; } } else // no time setted yet { if ( it != tOffsMap.end() ) { enigma_diff += it->second; eDebug("[TIME] we have correction (%d)... use", it->second ); } else eDebug("[TIME] dont have correction.. set Transponder Diff"); new_diff=enigma_diff; } time_t t = nowTime+new_diff; lastTpTimeDifference=tdt->UTC_time-t; if (!new_diff) { eDebug("[TIME] not changed"); return; } tm now = *localtime(&t); eDebug("[TIME] time update to %02d:%02d:%02d", now.tm_hour, now.tm_min, now.tm_sec); dvb.time_difference = t - linuxTime; // calc our new linux_time -> enigma_time correction eDebug("[TIME] time_difference is %d", dvb.time_difference ); if ( eSystemInfo::getInstance()->getHwType() == eSystemInfo::DM7020 ) setRTC(t); if ( abs(dvb.time_difference) > 59 ) { eDebug("[TIME] set Linux Time"); timeval tnow; gettimeofday(&tnow,0); tnow.tv_sec=t; settimeofday(&tnow,0); for (ePtrList<eMainloop>::iterator it(eMainloop::existing_loops) ;it != eMainloop::existing_loops.end(); ++it) it->setTimerOffset(dvb.time_difference); dvb.time_difference=1; } else if ( !dvb.time_difference ) dvb.time_difference=1; timeSet = true; /*emit*/ dvb.timeUpdated(); } else if ( eSystemInfo::getInstance()->getHwType() == eSystemInfo::DM7020 || ( eSystemInfo::getInstance()->getHwType() == eSystemInfo::DM7000 && eSystemInfo::getInstance()->hasStandbyWakeupTimer() ) ) { eDebug("[TIME] no transponder tuned... or no TDT/TOT avail .. try to use RTC :)"); time_t rtc_time = getRTC(); if ( rtc_time ) // RTC Ready? { tm now = *localtime(&rtc_time); eDebug("[TIME] RTC time is %02d:%02d:%02d", now.tm_hour, now.tm_min, now.tm_sec); time_t linuxTime=time(0); time_t nowTime=linuxTime+dvb.time_difference; now = *localtime(&nowTime); eDebug("[TIME] Receiver time is %02d:%02d:%02d", now.tm_hour, now.tm_min, now.tm_sec); dvb.time_difference = rtc_time - linuxTime; eDebug("[TIME] RTC to Receiver time difference is %d seconds", nowTime - rtc_time ); if ( abs(dvb.time_difference) > 59 ) { eDebug("[TIME] set Linux Time to RTC Time"); timeval tnow; gettimeofday(&tnow,0); tnow.tv_sec=rtc_time; settimeofday(&tnow,0); for (ePtrList<eMainloop>::iterator it(eMainloop::existing_loops) ;it != eMainloop::existing_loops.end(); ++it) it->setTimerOffset(dvb.time_difference); dvb.time_difference=1; } else if ( !dvb.time_difference ) dvb.time_difference=1; else eDebug("[TIME] set to RTC time"); /*emit*/ dvb.timeUpdated(); } else eDebug("[TIME] shit RTC not ready :("); } }
/** * pendingProcess * INPUT: none * OUTPUT: none * INFO: The master function for pending command sequence execution. * This function is called from the pending process state in the state status monitoring * state machine once per second. While this should happen immediately after telemetry is * recorded, and therefore should not interfere with the telemetry interrupt, it is not * occurring within an interrupt and therefore is placed within an uninterrupted block (by adjusting the processor priority) * to prevent any interrupts from happening during it and potentially leaving the satellite in an * indeterminate or unsafe state. * * A sequence is only "ready" if there are commands loaded and the ready flag is set to true * * Exit conditions that are relative times are changed to absolute time exit conditions since * the time in which the link was closed (the time the sequence starts processing) is not tracked * anywhere within here (It's not quickly accessible because it may or may not be in the response poll that does * not keep track of opcode. The link could've timed out as well). * * The next item on the sequence is peeked at (to get a copy) so that we can quickly check the wait conditions after the exit conditions. * Exit conditions are checked first since we do not want to continue to process a sequence if the exit conditions evaluate to TRUE. * If they do evaluate to TRUE, the sequence is aborted and both response poll and the beacon is updated. * Next the conditions of the next item in the sequence are checked. If they are false nothing happens to the sequence. * If it evaluates to TRUE, that item is pulled off of the stack and executed, the response poll for it is updated, and if there are more * commands, then the current time is stored as the last command time (for relative time checks). * Since the pending process state is a special, transitory state in the state status response state machine, it needs to be put back into * its previous mode so it may resume other operations. * * Finally, the processor mode is returned to normal so interrupts may occur. */ void pendingProcess(){ //major issues could arise if the processing of the line is interrupted, especially due to the link being established //Does not take long and occurs immediately after gathering telemetry so should not cause any issues. //the contents of this function are as narrow as this window can be placed. cpu_priority_t priority = Metal_SetCPUPriority(UNINTERRUPTIBLE_PRIORITY); if( (Global->csSequence.cmd_queue.count > 0) && (Global->csSequence.seq_ready_flag != 0) /*&& (Link_GetMode() & ~(LINK_SEQUENCING | LINK_ACTIVE))*/){ //check the exit conditions and fix them if either is a relative time uint32_t time = csunSatEpoch(getRTC()); dprintf("time = %ld\r\n", time); conditions_t exitCheck = Global->csSequence.exit; if(exitCheck.left.sensor_id == 254){ //change this to an absolute time value dprintf("delta time of %ld being changed -",exitCheck.left.value); exitCheck.left.value += time; dprintf("now absolute of %ld\r\n",exitCheck.left.value); exitCheck.left.sensor_id = 255; G_SET(csSequence.exit, &exitCheck); } if(exitCheck.op != JUST){//AND or OR is the operator, meaning right comparator is present if(exitCheck.right.sensor_id == 254){ //change this to an absolute time value exitCheck.right.value += time; exitCheck.right.sensor_id = 255; G_SET(csSequence.exit, &exitCheck); } } dprintf("Checking pending Command sequence\r\n"); //going to place EXIT/WAIT checks for pending commands here. resp_poll_t updating; seq_command_t pendingCmd; PendCmdQueue_Peek(&Global->csSequence.cmd_queue, &pendingCmd); BOOL result = false; //first check to see if we need to EXIT //pull EXIT conditions dprintf("Exit condition check - "); exitCheck = Global->csSequence.exit; //select the appropriate analysis depending on operator switch(exitCheck.op){ case JUST: result = checkCond(exitCheck.left); updating.status = 1; break; case AND: result = (checkCond(exitCheck.left) && checkCond(exitCheck.right)); updating.status = 2; break; case OR: result = checkCond(exitCheck.left); if(result){ updating.status = 3; } result = result || checkCond(exitCheck.right); if(result && updating.status != 3){ updating.status = 4; } else if(result){ updating.status = 5; } break; //no default since these three cases are all possible values } if(result){ dprintf("ABORTING SEQUENCE!\r\n"); //if exit conditions met, ABORT SEQUENCE resetPayload(); abortSequence(updating.status, time); beaconMsgUpdateSingle(SOFTWARE_STATE,'D'); } else{ dprintf("Good!\r\nChecking wait conditons - "); result = false; //then, if we did NOT exit, peek at the next item in the sequence //break down the wait conditions and process according to JUST, AND, or OR switch(pendingCmd.wait.op){ case JUST: result = checkCond(pendingCmd.wait.left); updating.status = 1; break; case AND: result = (checkCond(pendingCmd.wait.left) && checkCond(pendingCmd.wait.right)); updating.status = 2; break; case OR: result = checkCond(pendingCmd.wait.left); if(result){ updating.status = 3; } result = result || checkCond(pendingCmd.wait.right); if(result && updating.status != 3){ updating.status = 4; } else if(result){ updating.status = 5; } break; //no default since these three cases are all possible values } //check to see if all necessary conditions have been met if(result){ dprintf("Executing next pending command!\r\n"); //pop & do the next item in the sequence PendCmdQueue queueTemp; memcpy(&queueTemp, &Global->csSequence.cmd_queue, sizeof(queueTemp)); //read PendCmdQueue_Dequeue(&queueTemp, &pendingCmd); //mod G_SET(csSequence.cmd_queue, &queueTemp); //write decodeAndRunPending(pendingCmd); updating.epoch = time; updating.cmd_ID = pendingCmd.cmd_id; updating.type = PENDING_COMPLETE; updating.status = 0; respPollUpdatePending(updating); //check if another item is waiting to be run if(PendCmdQueue_Count(&Global->csSequence.cmd_queue) > 0){ //if there is, check to see if the wait condition has a time PendCmdQueue_Peek(&Global->csSequence.cmd_queue, &pendingCmd); if(pendingCmd.wait.left.sensor_id == 254 || (pendingCmd.wait.op != JUST && pendingCmd.wait.right.sensor_id == 254)){ //if so, record the time so the delta can be calculated G_SET(csSequence.lastCmdTime,&time); } } else{ dprintf("Wait conditions not satisfied currently\r\n"); //if something needs to be done when a sequence is empty, add that code here } } } } //go back to whatever type of sub state it was in before if(Global->csState.statMonState == PENDING_PROCESS){ statMonStateToPrevious(); } //return processor to previous priority mode Metal_SetCPUPriority(priority); }