inline void
CoveredIDsRequest::handleCoveredIDsPacket(const CoveredIDsReplyPacket* packet)
{
   if ( packet->getStatus() != StringTable::OK ) {
      mc2dbg2 << "[CovR]: Got packet with "
             << " type = " << packet->getSubTypeAsString() 
             << "status "
             << packet->getStatusAsString() << endl;         
      SETSTATE(ERROR);
      return;
   }
   
   // Check if more packets need sending.
   if ( packet->isMapIDs() ) {
      int nbrMaps = packet->getNumberIDs();
      mc2dbg2 << "[CovR]: " << nbrMaps << " maps covered - sending more"
             << endl;
      for ( int i = 0; i < nbrMaps; ++i ) {
         uint32 curMapID = packet->getID(i);
         addPacketForSending(createCoveredIDsRequestPacket(curMapID),
                             MODULE_TYPE_MAP);   
      }
   } else {
      int nbrItems = packet->getNumberIDs();
      uint32 mapID = packet->getMapID();
      mc2dbg2 << "[CovR]: Got " << nbrItems << " items from map "
             << mapID << endl;
      
      for ( int i = 0; i < nbrItems; ++i ) {
      // Get the items and put them in the result.
         m_resultIDs.insert(make_pair(packet->getType(i),
                                      IDPair_t(mapID, packet->getID(i)) ) );
         
         mc2dbg8 << "[CovR]: Adding item " << IDPair_t(mapID, packet->getID(i))
                 << " with type " 
                 << ItemTypes::getItemTypeAsString(packet->getType(i))
                 << endl;
      }
   }
   
   if ( m_nbrOutstanding == 0 ) {
      // No packets to receive - we're done now.
      mc2dbg2 << "[CovR]: Done: Nbr resulting items = "
             << m_resultIDs.size()
             << endl;
      SETSTATE(DONE);
   }
}
void
CoveredIDsRequest::processPacket(PacketContainer* pack)
{
   --m_nbrOutstanding;
   // Assume right packettype.
   bool wrongPacket = false;
   Packet* packet = pack->getPacket();
   switch ( m_state ) {
      case SENDING_PACKETS:
         switch ( packet->getSubType() ) {
            case Packet::PACKETTYPE_COVEREDIDSREPLYPACKET:
               handleCoveredIDsPacket(
                  static_cast<CoveredIDsReplyPacket*>(packet));
               break;
            default:
               wrongPacket = true;
               break;
         };
         break;
      case DONE:
      case ERROR:
         mc2dbg << "[CovR]; Recevied packet in DONE or ERROR state which is "
                << "wrong"
                << endl;
         break;
   };
   if ( wrongPacket ) {
      mc2log << warn << "[CovR]: Wrong type of packet received" << endl;
      SETSTATE(ERROR);
   }
   delete pack;
}
Пример #3
0
bool PhdController::Dither(double pixels, bool raOnly, const SettleParams& settle, wxString *errMsg)
{
    if (ctrl.state != STATE_IDLE)
    {
        Debug.AddLine("PhdController::Dither reentrancy state = %d op = %d", ctrl.state, ctrl.settleOp);
        *errMsg = ReentrancyError("dither");
        return false;
    }

    Debug.AddLine("PhdController::Dither begins");

    bool error = pFrame->Dither(pixels, raOnly);
    if (error)
    {
        Debug.AddLine("PhdController::Dither pFrame->Dither failed");
        *errMsg = _T("Dither error");
        return false;
    }

    ctrl.settleOp = OP_DITHER;
    ctrl.settle = settle;
    SETSTATE(STATE_SETTLE_BEGIN);
    UpdateControllerState();

    return true;
}
Пример #4
0
static void do_fail(const wxString& msg)
{
    Debug.AddLine(wxString::Format("PhdController failed: %s", msg));
    ctrl.succeeded = false;
    ctrl.errorMsg = msg;
    SETSTATE(STATE_FINISH);
}
Пример #5
0
bool KeyPlayer::on_key(const SDL_keysym sym, const bool pressed) {
	SETSTATE(left, _left);
	SETSTATE(right, _right);
	SETSTATE(up, _up);
	SETSTATE(down, _down);
	SETSTATE(fire, _fire);
	SETSTATE(alt_fire, _alt_fire);
	SETSTATE(leave, leave);
	SETSTATE(hint_control, _hint_control);
	return false;
}
Пример #6
0
bool PhdController::Guide(bool recalibrate, const SettleParams& settle, wxString *error)
{
    if (ctrl.state != STATE_IDLE)
    {
        Debug.AddLine("PhdController::Guide reentrancy state = %d op = %d", ctrl.state, ctrl.settleOp);
        *error = ReentrancyError("guide");
        return false;
    }

    Debug.AddLine("PhdController::Guide begins");
    ctrl.forceCalibration = recalibrate;
    ctrl.settleOp = OP_GUIDE;
    ctrl.settle = settle;
    SETSTATE(STATE_SETUP);
    UpdateControllerState();
    return true;
}
Пример #7
0
void PhdController::UpdateControllerState(void)
{
    bool done = false;

    while (!done)
    {
        switch (ctrl.state) {
        case STATE_IDLE:
            done = true;
            break;

        case STATE_SETUP:
            Debug.AddLine("PhdController: setup");
            ctrl.haveSaveSticky = false;
            ctrl.autoFindAttemptsRemaining = 3;
            SETSTATE(STATE_ATTEMPT_START);
            break;

        case STATE_ATTEMPT_START:

            if (!all_gear_connected())
            {
                do_fail(_T("all equipment must be connected first"));
            }
            else if (pFrame->pGuider->IsCalibratingOrGuiding())
            {
                GUIDER_STATE state = pFrame->pGuider->GetState();
                Debug.AddLine("PhdController: guider state = %d", state);
                if (state == STATE_CALIBRATED || state == STATE_GUIDING)
                {
                    SETSTATE(STATE_SETTLE_BEGIN);
                }
                else
                {
                    SETSTATE(STATE_CALIBRATION_WAIT);
                    done = true;
                }
            }
            else if (!pFrame->CaptureActive)
            {
                Debug.AddLine("PhdController: start capturing");
                if (!start_capturing())
                {
                    do_fail(_T("unable to start capturing"));
                    break;
                }
                SETSTATE(STATE_SELECT_STAR);
                done = true;
            }
            else if (pFrame->pGuider->GetState() == STATE_SELECTED)
            {
                SETSTATE(STATE_CALIBRATE);
            }
            else
            {
                // capture is active, no star selected
                SETSTATE(STATE_SELECT_STAR);

                // if auto-exposure is enabled, reset to max exposure duration
                // and wait for the next camera frame
                if (pFrame->GetAutoExposureCfg().enabled)
                {
                    pFrame->ResetAutoExposure();
                    done = true;
                }
            }
            break;

        case STATE_SELECT_STAR: {
            bool error = pFrame->pGuider->AutoSelect();
            if (error)
            {
                Debug.AddLine("auto find star failed, attempts remaining = %d", ctrl.autoFindAttemptsRemaining);
                if (--ctrl.autoFindAttemptsRemaining == 0)
                {
                    do_fail(_T("failed to find a suitable guide star"));
                }
                else
                {
                    pFrame->pGuider->Reset(true);
                    SETSTATE(STATE_ATTEMPT_START);
                    done = true;
                }
            }
            else
            {
                SETSTATE(STATE_WAIT_SELECTED);
                ctrl.waitSelectedRemaining = 3;
                done = true;
            }
            break;
        }

        case STATE_WAIT_SELECTED:
            if (pFrame->pGuider->GetState() == STATE_SELECTED)
            {
                SETSTATE(STATE_CALIBRATE);
            }
            else
            {
                Debug.AddLine("waiting for star selected, attempts remaining = %d", ctrl.waitSelectedRemaining);
                if (--ctrl.waitSelectedRemaining == 0)
                {
                    SETSTATE(STATE_ATTEMPT_START);
                }
                done = true;
            }
            break;

        case STATE_CALIBRATE:
            if (ctrl.forceCalibration)
            {
                Debug.AddLine("PhdController: clearing calibration");
                if (pMount)
                    pMount->ClearCalibration();
                if (pSecondaryMount)
                    pSecondaryMount->ClearCalibration();
            }

            if ((pMount && !pMount->IsCalibrated()) ||
                    (pSecondaryMount && !pSecondaryMount->IsCalibrated()))
            {
                Debug.AddLine("PhdController: start calibration");

                ctrl.saveSticky = pFrame->pGuider->LockPosIsSticky();
                ctrl.haveSaveSticky = true;
                pFrame->pGuider->SetLockPosIsSticky(true);

                if (!start_guiding())
                {
                    pFrame->pGuider->SetLockPosIsSticky(ctrl.saveSticky);
                    do_fail(_T("could not start calibration"));
                    break;
                }

                SETSTATE(STATE_CALIBRATION_WAIT);
                done = true;
            }
            else
            {
                SETSTATE(STATE_GUIDE);
            }
            break;

        case STATE_CALIBRATION_WAIT:
            if ((!pMount || pMount->IsCalibrated()) &&
                    (!pSecondaryMount || pSecondaryMount->IsCalibrated()))
            {
                if (ctrl.haveSaveSticky)
                    pFrame->pGuider->SetLockPosIsSticky(ctrl.saveSticky);

                SETSTATE(STATE_SETTLE_BEGIN);
            }
            else
                done = true;
            break;

        case STATE_GUIDE:
            if (!start_guiding())
            {
                do_fail(_T("could not start guiding"));
                break;
            }
            SETSTATE(STATE_SETTLE_BEGIN);
            done = true;
            break;

        case STATE_SETTLE_BEGIN:
            ctrl.settlePriorFrameInRange = false;
            ctrl.settleTimeout->Start();
            SETSTATE(STATE_SETTLE_WAIT);
            GuideLog.NotifySettlingStateChange("Settling started");
            done = true;
            break;

        case STATE_SETTLE_WAIT: {
            bool lockedOnStar = pFrame->pGuider->IsLocked();
            double currentError = pFrame->pGuider->CurrentError();
            bool inRange = lockedOnStar && currentError <= ctrl.settle.tolerancePx;
            bool aoBumpInProgress = IsAoBumpInProgress();
            long timeInRange = 0;

            Debug.AddLine("PhdController: settling, locked = %d, distance = %.2f (%.2f) aobump = %d", lockedOnStar, currentError,
                          ctrl.settle.tolerancePx, aoBumpInProgress);

            if (inRange)
            {
                if (!ctrl.settlePriorFrameInRange)
                {
                    ctrl.settleInRange->Start();
                }
                else if (((timeInRange = ctrl.settleInRange->Time()) / 1000) >= ctrl.settle.settleTimeSec && !aoBumpInProgress)
                {
                    ctrl.succeeded = true;
                    SETSTATE(STATE_FINISH);
                    break;
                }
            }
            if ((ctrl.settleTimeout->Time() / 1000) >= ctrl.settle.timeoutSec)
            {
                do_fail(_T("timed-out waiting for guider to settle"));
                break;
            }
            EvtServer.NotifySettling(currentError, (double) timeInRange / 1000., ctrl.settle.settleTimeSec);
            ctrl.settlePriorFrameInRange = inRange;
            done = true;
            break;
        }

        case STATE_FINISH:
            do_notify();
            SETSTATE(STATE_IDLE);
            done = true;
            break;
        }
    }
}