Esempio n. 1
0
IPState RollOff::Move(DomeDirection dir, DomeMotionCommand operation)
{
    if (operation == MOTION_START)
    {
        // DOME_CW --> OPEN. If can we are ask to "open" while we are fully opened as the limit switch indicates, then we simply return false.
        if (dir == DOME_CW && fullOpenLimitSwitch == ISS_ON)
        {
            DEBUG(INDI::Logger::DBG_WARNING, "Roof is already fully opened.");
            return IPS_ALERT;
        }
        else if (dir == DOME_CW && getWeatherState() == IPS_ALERT)
        {
            DEBUG(INDI::Logger::DBG_WARNING, "Weather conditions are in the danger zone. Cannot open roof.");
            return IPS_ALERT;
        }
        else if (dir == DOME_CCW && fullClosedLimitSwitch == ISS_ON)
        {
            DEBUG(INDI::Logger::DBG_WARNING, "Roof is already fully closed.");
            return IPS_ALERT;
        }

        fullOpenLimitSwitch   = ISS_OFF;
        fullClosedLimitSwitch = ISS_OFF;
        MotionRequest = ROLLOFF_DURATION;
        gettimeofday(&MotionStart,NULL);
        SetTimer(1000);
        return IPS_BUSY;
    }
    else
    {
        return (Dome::Abort() ? IPS_OK : IPS_ALERT);

    }

    return IPS_ALERT;

}
Esempio n. 2
0
void MaxDomeII::TimerHit()
{
    SH_Status nShutterStatus;
    AZ_Status nAzimuthStatus;
    unsigned nHomePosition;
    float nAz;
    int nError;
    int nRetry = 1;

    if(isConnected() == false)
        return;  //  No need to reset timer if we are not connected anymore

    nError = Status_MaxDomeII(PortFD, &nShutterStatus, &nAzimuthStatus, &nCurrentTicks, &nHomePosition);
    handle_driver_error(&nError, &nRetry); // This is a timer, we will not repeat in order to not delay the execution.
    
    // Increment movment time counter
    if (nTimeSinceShutterStart >= 0)
        nTimeSinceShutterStart++;
    if (nTimeSinceAzimuthStart >= 0)
        nTimeSinceAzimuthStart++;

    // Watch dog
    nTimeSinceLastCommunication++;
    if (WatchDogNP.np[0].value > 0 && WatchDogNP.np[0].value <= nTimeSinceLastCommunication)
    {
        // Close Shutter if it is not
        if (nShutterStatus != Ss_CLOSED)
        {
            DomeShutterSP.s = ControlShutter(SHUTTER_CLOSE);
            IDSetSwitch(&DomeShutterSP, "Closing shutter due watch dog");
        }

    }
    
    if (getWeatherState() == IPS_ALERT)
    {
        // Close Shutter if it is not
        if (nShutterStatus != Ss_CLOSED)
        {
            DomeShutterSP.s = ControlShutter(SHUTTER_CLOSE);
            IDSetSwitch(&DomeShutterSP, "Closing shutter due Weather conditions");
        }
    }

    if (!nError)
    {
        // Shutter
        switch(nShutterStatus)
        {
        case Ss_CLOSED:
            if (DomeShutterS[1].s == ISS_ON) // Close Shutter
            {
                if (DomeShutterSP.s == IPS_BUSY || DomeShutterSP.s == IPS_ALERT)
                {
                    DomeShutterSP.s = IPS_OK; // Shutter close movement ends.
                    nTimeSinceShutterStart = -1;
                    IDSetSwitch (&DomeShutterSP, "Shutter is closed");
                }
            }
            else
            {
                if (nTimeSinceShutterStart >= 0)
                { // A movement has started. Warn but don't change
                    if (nTimeSinceShutterStart >= 4)
                    {
                        DomeShutterSP.s = IPS_ALERT; // Shutter close movement ends.
                        IDSetSwitch (&DomeShutterSP, "Shutter still closed");
                    }
                }
                else
                { // For some reason (manual operation?) the shutter has closed
                    DomeShutterSP.s = IPS_IDLE;
                    DomeShutterS[1].s = ISS_ON;
                    DomeShutterS[0].s = ISS_OFF;
                    IDSetSwitch (&DomeShutterSP, "Unexpected shutter closed");
                }
            }
            break;
        case Ss_OPENING:
            if (DomeShutterS[0].s == ISS_OFF) // not opening Shutter
            {  // For some reason the shutter is opening (manual operation?)
                DomeShutterSP.s = IPS_ALERT;
                DomeShutterS[1].s = ISS_OFF;
                DomeShutterS[0].s = ISS_OFF;
                IDSetSwitch (&DomeShutterSP, "Unexpected shutter opening");
            }
            else if (nTimeSinceShutterStart < 0)
            {	// For some reason the shutter is opening (manual operation?)
                DomeShutterSP.s = IPS_ALERT;
                nTimeSinceShutterStart = 0;
                IDSetSwitch (&DomeShutterSP, "Unexpected shutter opening");
            }
            else if (DomeShutterSP.s == IPS_ALERT)
            {	// The alert has corrected
                DomeShutterSP.s = IPS_BUSY;
                IDSetSwitch (&DomeShutterSP, "Shutter is opening");
            }
            break;
        case Ss_OPEN:
            if (DomeShutterS[0].s == ISS_ON) // Open Shutter
            {
                if (DomeShutterSP.s == IPS_BUSY || DomeShutterSP.s == IPS_ALERT)
                {
                    DomeShutterSP.s = IPS_OK; // Shutter open movement ends.
                    nTimeSinceShutterStart = -1;
                    IDSetSwitch (&DomeShutterSP, "Shutter is open");
                }
            }
            else
            {
                if (nTimeSinceShutterStart >= 0)
                { // A movement has started. Warn but don't change
                    if (nTimeSinceShutterStart >= 4)
                    {
                        DomeShutterSP.s = IPS_ALERT; // Shutter open movement alert.
                        IDSetSwitch (&DomeShutterSP, "Shutter still open");
                    }
                }
                else
                { // For some reason (manual operation?) the shutter has open
                    DomeShutterSP.s = IPS_IDLE;
                    DomeShutterS[1].s = ISS_ON;
                    DomeShutterS[0].s = ISS_OFF;
                    IDSetSwitch (&DomeShutterSP, "Unexpected shutter open");
                }
            }
            break;
        case Ss_CLOSING:
            if (DomeShutterS[1].s == ISS_OFF) // Not closing Shutter
            {	// For some reason the shutter is closing (manual operation?)
                DomeShutterSP.s = IPS_ALERT;
                DomeShutterS[1].s = ISS_ON;
                DomeShutterS[0].s = ISS_OFF;
                IDSetSwitch (&DomeShutterSP, "Unexpected shutter closing");
            }
            else  if (nTimeSinceShutterStart < 0)
            {	// For some reason the shutter is opening (manual operation?)
                DomeShutterSP.s = IPS_ALERT;
                nTimeSinceShutterStart = 0;
                IDSetSwitch (&DomeShutterSP, "Unexpected shutter closing");
            }
            else if (DomeShutterSP.s == IPS_ALERT)
            {	// The alert has corrected
                DomeShutterSP.s = IPS_BUSY;
                IDSetSwitch (&DomeShutterSP, "Shutter is closing");
            }
            break;
        case Ss_ABORTED:
        case Ss_ERROR:
        default:
            if (nTimeSinceShutterStart >= 0)
            {
                DomeShutterSP.s = IPS_ALERT; // Shutter movement aborted.
                DomeShutterS[1].s = ISS_OFF;
                DomeShutterS[0].s = ISS_OFF;
                nTimeSinceShutterStart = -1;
                IDSetSwitch (&DomeShutterSP, "Unknown shutter status");
            }
            break;
        }

        // Azimuth
        nAz = TicksToAzimuth(nCurrentTicks);
        if (DomeAbsPosN[0].value != nAz)
        {	// Only refresh position if it changed
            DomeAbsPosN[0].value = nAz;
            //sprintf(buf,"%d", nCurrentTicks);
            IDSetNumber(&DomeAbsPosNP, NULL);
        }

        switch(nAzimuthStatus)
        {
        case As_IDLE:
        case As_IDEL2:
            if (nTimeSinceAzimuthStart > 3)
            {
                if (nTargetAzimuth >= 0 && AzimuthDistance(nTargetAzimuth,nCurrentTicks) > 3) // Maximum difference allowed: 3 ticks
                {
                    DomeAbsPosNP.s = IPS_ALERT;
                    nTimeSinceAzimuthStart = -1;
                    IDSetNumber(&DomeAbsPosNP, "Could not position right");
                }
                else
                {   // Succesfull end of movement
                    if (DomeAbsPosNP.s != IPS_OK)
                    {
                        setDomeState(DOME_SYNCED);
                        nTimeSinceAzimuthStart = -1;
                        DEBUG(INDI::Logger::DBG_SESSION, "Dome is on target position");
                    }
                    if (HomeS[0].s == ISS_ON)
                    {
                        HomeS[0].s = ISS_OFF;
                        HomeSP.s = IPS_OK;
                        nTimeSinceAzimuthStart = -1;
                        IDSetSwitch(&HomeSP, "Dome is homed");
                    }

                }
            }
            break;
        case As_MOVING_WE:
        case As_MOVING_EW:
            if (nTimeSinceAzimuthStart < 0)
            {
                nTimeSinceAzimuthStart = 0;
                nTargetAzimuth = -1;
                DomeAbsPosNP.s = IPS_ALERT;
                IDSetNumber(&DomeAbsPosNP, "Unexpected dome moving");
            }
            break;
        case As_ERROR:
            if (nTimeSinceAzimuthStart >= 0)
            {
                DomeAbsPosNP.s = IPS_ALERT;
                nTimeSinceAzimuthStart = -1;
                nTargetAzimuth = -1;
                IDSetNumber(&DomeAbsPosNP, "Dome Error");
            }
        default:
            break;
        }


    }
    else
    {
        DEBUGF(INDI::Logger::DBG_DEBUG, "Error: %s. Please reconnect and try again.",ErrorMessages[-nError]);
        return;
    }

    SetTimer(POLLMS);
    return;
}