Ejemplo n.º 1
0
void QSICCD::addFITSKeywords(fitsfile *fptr, INDI::CCDChip *targetChip)
{
    INDI::CCD::addFITSKeywords(fptr, targetChip);

    int status = 0;
    double electronsPerADU;

    try
    {
        QSICam.get_ElectronsPerADU(&electronsPerADU);
    }
    catch (std::runtime_error &err)
    {
        DEBUGF(INDI::Logger::DBG_ERROR, "get_ElectronsPerADU failed. %s.", err.what());
        return;
    }

    // 2017-09-17 JM: electronsPerADU is wrong in auto mode. So we have to change it manually here.
    if (IUFindOnSwitchIndex(&GainSP) == GAIN_AUTO && PrimaryCCD.getBinX() > 1)
        electronsPerADU = 1.1;

    fits_update_key_s(fptr, TDOUBLE, "EPERADU", &electronsPerADU, "Electrons per ADU", &status);
}
Ejemplo n.º 2
0
bool ClientAPIForAlignmentDatabase::ClearSyncPoints()
{
    // Wait for driver to initialise if neccessary
    WaitForDriverCompletion();

    ISwitchVectorProperty * pAction = Action->getSwitch();
    ISwitchVectorProperty * pCommit = Commit->getSwitch();

    // Select the required action
    if (CLEAR != IUFindOnSwitchIndex(pAction))
    {
        // Request Clear mode
        IUResetSwitch(pAction);
        pAction->sp[CLEAR].s = ISS_ON;
        SetDriverBusy();
        BaseClient->sendNewSwitch(pAction);
        WaitForDriverCompletion();
        if (IPS_OK != pAction->s)
        {
            IDLog("ClearSyncPoints - Bad Action switch state %s\n", pstateStr(pAction->s));
            return false;
        }
    }

    IUResetSwitch(pCommit);
    pCommit->sp[0].s = ISS_ON;
    SetDriverBusy();
    BaseClient->sendNewSwitch(pCommit);
    WaitForDriverCompletion();
    if (IPS_OK != pCommit->s)
    {
        IDLog("ClearSyncPoints - Bad Commit switch state %s\n", pstateStr(pCommit->s));
        return false;
    }

    return true;
}
Ejemplo n.º 3
0
bool ScopeSim::Goto(double r, double d)
{
    targetRA  = r;
    targetDEC = d;
    char RAStr[64], DecStr[64];

    fs_sexa(RAStr, targetRA, 2, 3600);
    fs_sexa(DecStr, targetDEC, 2, 3600);

    double current_az = getAzimuth(currentRA, currentDEC);

    if (current_az > MIN_AZ_FLIP && current_az < MAX_AZ_FLIP)
    {
        double target_az = getAzimuth(r, d);

        //if (targetAz > currentAz && target_az > MIN_AZ_FLIP && target_az < MAX_AZ_FLIP)
        if (target_az >= current_az && target_az > MIN_AZ_FLIP)
        {
            forceMeridianFlip = true;
        }
    }

    if (IUFindOnSwitchIndex(&TrackModeSP) != SLEW_MAX)
    {
        IUResetSwitch(&TrackModeSP);
        TrackModeS[SLEW_MAX].s = ISS_ON;
        IDSetSwitch(&TrackModeSP, nullptr);
    }

    TrackState = SCOPE_SLEWING;

    EqNP.s = IPS_BUSY;

    LOGF_INFO("Slewing to RA: %s - DEC: %s", RAStr, DecStr);
    return true;
}
Ejemplo n.º 4
0
void NStep::TimerHit()
{
    if (isConnected() == false)
        return;

    double currentPosition = FocusAbsPosN[0].value;

    readPosition();

    // Check if we have a pending motion
    // and if we STOPPED, then let's take the next action
    if ( (FocusAbsPosNP.s == IPS_BUSY || FocusRelPosNP.s == IPS_BUSY) && isMoving() == false)
    {
        // Are we done moving?
        if (m_TargetDiff == 0)
        {
            FocusAbsPosNP.s = IPS_OK;
            FocusRelPosNP.s = IPS_OK;
            IDSetNumber(&FocusAbsPosNP, nullptr);
            IDSetNumber(&FocusRelPosNP, nullptr);
        }
        else
        {
            // 999 is the max we can go in one command
            // so we need to go 999 or LESS
            // therefore for larger movements, we break it down.
            int nextMotion = (std::abs(m_TargetDiff) > 999) ? 999 : std::abs(m_TargetDiff);
            int direction = m_TargetDiff > 0 ? FOCUS_OUTWARD : FOCUS_INWARD;
            int mode = IUFindOnSwitchIndex(&SteppingModeSP);
            char cmd[NSTEP_LEN] = {0};
            snprintf(cmd, NSTEP_LEN, ":F%d%d%03d#", direction, mode, nextMotion);
            if (sendCommand(cmd) == false)
            {
                LOG_ERROR("Failed to issue motion command.");
                if (FocusRelPosNP.s == IPS_BUSY)
                {
                    FocusRelPosNP.s = IPS_ALERT;
                    IDSetNumber(&FocusRelPosNP, nullptr);
                }
                if (FocusAbsPosNP.s == IPS_BUSY)
                {
                    FocusAbsPosNP.s = IPS_ALERT;
                    IDSetNumber(&FocusAbsPosNP, nullptr);
                }
            }
            else
                // Reduce target diff depending on the motion direction
                // Negative targetDiff increases eventually to zero
                // Positive targetDiff decreases eventually to zero
                m_TargetDiff = m_TargetDiff + (nextMotion * ((direction == FOCUS_INWARD) ? 1 : -1));
        }
        // Check if can update the absolute position in case it changed.
    }
    else if (currentPosition != FocusAbsPosN[0].value)
    {
        IDSetNumber(&FocusAbsPosNP, nullptr);
    }

    // Read temperature
    if (TemperatureNP.s == IPS_OK && m_TemperatureCounter++ == NSTEP_TEMPERATURE_FREQ)
    {
        m_TemperatureCounter = 0;
        if (readTemperature())
            IDSetNumber(&TemperatureNP, nullptr);
    }

    SetTimer(POLLMS);
}
Ejemplo n.º 5
0
bool NStep::ISNewSwitch(const char * dev, const char * name, ISState * states, char * names[], int n)
{
    if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
    {
        // Temperature Compensation Mode
        if (!strcmp(name, CompensationModeSP.name))
        {
            int prevIndex = IUFindOnSwitchIndex(&CompensationModeSP);
            IUUpdateSwitch(&CompensationModeSP, states, names, n);
            int mode = IUFindOnSwitchIndex(&CompensationModeSP);
            if (setCompensationMode(mode))
            {
                CompensationModeSP.s = IPS_OK;
                // If it was set to one shot, we put it back to off?
                switch (mode)
                {
                    case COMPENSATION_MODE_OFF:
                        LOG_INFO("Temperature compensation is disabled.");
                        break;

                    case COMPENSATION_MODE_ONE_SHOT:
                        IUResetSwitch(&CompensationModeSP);
                        CompensationModeS[COMPENSATION_MODE_OFF].s = ISS_ON;
                        LOG_INFO("One shot compensation applied.");
                        break;

                    case COMPENSATION_MODE_AUTO:
                        LOG_INFO("Automatic temperature compensation is enabled.");
                        break;
                }
            }
            else
            {
                IUResetSwitch(&CompensationModeSP);
                CompensationModeS[prevIndex].s = ISS_ON;
                CompensationModeSP.s = IPS_ALERT;
                LOG_ERROR("Failed to change temperature compnensation mode.");
            }

            IDSetSwitch(&CompensationModeSP, nullptr);
            return true;
        }

        // Manual Prime
        if (!strcmp(name, PrimeManualSP.name))
        {
            sendCommand(":TI");
            PrimeManualSP.s = IPS_OK;
            IDSetSwitch(&PrimeManualSP, nullptr);
            LOG_INFO("Prime for manual complete. Click One Shot to apply manual compensation once.");
            return true;
        }

        // Stepping Mode
        if (!strcmp(name, SteppingModeSP.name))
        {
            IUUpdateSwitch(&SteppingModeSP, states, names, n);
            SteppingModeSP.s = IPS_OK;
            IDSetSwitch(&SteppingModeSP, nullptr);
            return true;
        }

        // Coil Status after Move is done
        if (!strcmp(name, CoilStatusSP.name))
        {
            int prevIndex = IUFindOnSwitchIndex(&CoilStatusSP);
            IUUpdateSwitch(&CoilStatusSP, states, names, n);
            int state = IUFindOnSwitchIndex(&CoilStatusSP);
            if (setCoilStatus(state))
            {
                CoilStatusSP.s = IPS_OK;
                if (state == COIL_ENERGIZED_ON)
                    LOG_WARN("Coil shall be kept energized after motion is complete. Watch for motor heating!");
                else
                    LOG_INFO("Coil shall be de-energized after motion is complete.");
            }
            else
            {
                IUResetSwitch(&CoilStatusSP);
                CoilStatusS[prevIndex].s = ISS_ON;
                CoilStatusSP.s = IPS_ALERT;
                LOG_ERROR("Failed to update coil energization status.");
            }

            IDSetSwitch(&CoilStatusSP, nullptr);
            return true;
        }
    }

    return INDI::Focuser::ISNewSwitch(dev, name, states, names, n);
}
Ejemplo n.º 6
0
void MathPluginManagement::ProcessSwitchProperties(Telescope* pTelescope, const char *name, ISState *states, char *names[], int n)
{
    DEBUGFDEVICE(pTelescope->getDeviceName(), INDI::Logger::DBG_DEBUG, "ProcessSwitchProperties - name(%s)", name);
    if (strcmp(name, AlignmentSubsystemMathPluginsV.name) == 0)
    {
        int CurrentPlugin = IUFindOnSwitchIndex(&AlignmentSubsystemMathPluginsV);
        IUUpdateSwitch(&AlignmentSubsystemMathPluginsV, states, names, n);
        AlignmentSubsystemMathPluginsV.s = IPS_OK; // Assume OK for the time being
        int NewPlugin  = IUFindOnSwitchIndex(&AlignmentSubsystemMathPluginsV);
        if (NewPlugin != CurrentPlugin)
        {
            // New plugin requested
            // Unload old plugin if required
            if (0 != CurrentPlugin)
            {
                typedef void Destroy_t(MathPlugin *);
                Destroy_t* Destroy = (Destroy_t*)dlsym(LoadedMathPluginHandle, "Destroy");
                if (NULL != Destroy)
                {
                    Destroy(pLoadedMathPlugin);
                    pLoadedMathPlugin = NULL;
                    if (0 == dlclose(LoadedMathPluginHandle))
                    {
                        LoadedMathPluginHandle = NULL;

                    }
                    else
                    {
                        IDLog("MathPluginManagement - dlclose failed on loaded plugin - %s\n", dlerror());
                        AlignmentSubsystemMathPluginsV.s = IPS_ALERT;
                    }
                }
                else
                {
                    IDLog("MathPluginManagement - cannot get Destroy function - %s\n", dlerror());
                    AlignmentSubsystemMathPluginsV.s = IPS_ALERT;
                }
            }
            // Load the requested plugin if required
            if (0 != NewPlugin)
            {
                std::string PluginPath(MathPluginFiles[NewPlugin - 1]);
                if (NULL != (LoadedMathPluginHandle = dlopen(PluginPath.c_str(), RTLD_NOW)))
                {
                    typedef MathPlugin* Create_t();
                    Create_t* Create = (Create_t*)dlsym(LoadedMathPluginHandle, "Create");
                    if (NULL != Create)
                    {
                        pLoadedMathPlugin = Create();
                        IUSaveText(&AlignmentSubsystemCurrentMathPlugin, PluginPath.c_str());
                    }
                    else
                    {
                        IDLog("MathPluginManagement - cannot get Create function - %s\n", dlerror());
                        AlignmentSubsystemMathPluginsV.s = IPS_ALERT;
                    }
                }
                else
                {
                    IDLog("MathPluginManagement - cannot load plugin %s error %s\n", PluginPath.c_str(), dlerror());
                    AlignmentSubsystemMathPluginsV.s = IPS_ALERT;
                }
            }
            else
            {
                // It is in built plugin just set up the pointers
                pLoadedMathPlugin = &BuiltInPlugin;
            }
        }

        //  Update client
        IDSetSwitch(&AlignmentSubsystemMathPluginsV, NULL);
    }
    else if (strcmp(name, AlignmentSubsystemMathPluginInitialiseV.name) == 0)
    {
        AlignmentSubsystemMathPluginInitialiseV.s = IPS_OK;
        IUResetSwitch(&AlignmentSubsystemMathPluginInitialiseV);
        //  Update client display
        IDSetSwitch(&AlignmentSubsystemMathPluginInitialiseV, NULL);

        // Initialise or reinitialise the current math plugin
        Initialise(CurrentInMemoryDatabase);
    }
    else if (strcmp(name, AlignmentSubsystemActiveV.name) == 0)
    {
        AlignmentSubsystemActiveV.s=IPS_OK;
        if (0 == IUUpdateSwitch(&AlignmentSubsystemActiveV, states, names, n))
            //  Update client
            IDSetSwitch(&AlignmentSubsystemActiveV, NULL);
    }
}
Ejemplo n.º 7
0
void Mount::syncTelescopeInfo()
{
    INumberVectorProperty * nvp = currentTelescope->getBaseDevice()->getNumber("TELESCOPE_INFO");

    if (nvp)
    {

        primaryScopeGroup->setTitle(currentTelescope->getDeviceName());
        guideScopeGroup->setTitle(i18n("%1 guide scope", currentTelescope->getDeviceName()));

        INumber *np = NULL;

        np = IUFindNumber(nvp, "TELESCOPE_APERTURE");
        if (np && np->value > 0)
            primaryScopeApertureIN->setValue(np->value);

        np = IUFindNumber(nvp, "TELESCOPE_FOCAL_LENGTH");
        if (np && np->value > 0)
            primaryScopeFocalIN->setValue(np->value);

        np = IUFindNumber(nvp, "GUIDER_APERTURE");
        if (np && np->value > 0)
            guideScopeApertureIN->setValue(np->value);

        np = IUFindNumber(nvp, "GUIDER_FOCAL_LENGTH");
        if (np && np->value > 0)
            guideScopeFocalIN->setValue(np->value);

    }

    ISwitchVectorProperty *svp = currentTelescope->getBaseDevice()->getSwitch("TELESCOPE_SLEW_RATE");

    if (svp)
    {
        slewSpeedCombo->clear();
        slewSpeedCombo->setEnabled(true);

        for (int i=0; i < svp->nsp; i++)
            slewSpeedCombo->addItem(i18nc(libindi_strings_context, svp->sp[i].label));

        int index = IUFindOnSwitchIndex(svp);
        slewSpeedCombo->setCurrentIndex(index);
        connect(slewSpeedCombo, SIGNAL(activated(int)), currentTelescope, SLOT(setSlewRate(int)), Qt::UniqueConnection);
    }
    else
    {
        slewSpeedCombo->setEnabled(false);
        disconnect(slewSpeedCombo, SIGNAL(activated(int)), currentTelescope, SLOT(setSlewRate(int)));
    }

    if (currentTelescope->canPark())
    {
        parkB->setEnabled(!currentTelescope->isParked());
        unparkB->setEnabled(currentTelescope->isParked());
        connect(parkB, SIGNAL(clicked()), currentTelescope, SLOT(Park()), Qt::UniqueConnection);
        connect(unparkB, SIGNAL(clicked()), currentTelescope, SLOT(UnPark()), Qt::UniqueConnection);
    }
    else
    {
        parkB->setEnabled(false);
        unparkB->setEnabled(false);
        disconnect(parkB, SIGNAL(clicked()), currentTelescope, SLOT(Park()));
        disconnect(unparkB, SIGNAL(clicked()), currentTelescope, SLOT(UnPark()));
    }

}
Ejemplo n.º 8
0
bool QSICCD::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
{
    if(strcmp(dev,getDeviceName())==0)
    {

        /* Readout Speed */
        if (!strcmp(name, ReadOutSP.name))
        {
            if (IUUpdateSwitch(&ReadOutSP, states, names, n) < 0) return false;

            if (ReadOutS[0].s == ISS_ON)
            {
                try
                {
                 QSICam.put_ReadoutSpeed(QSICamera::HighImageQuality);
                } catch (std::runtime_error err)
                {
                        IUResetSwitch(&ReadOutSP);
                        ReadOutSP.s = IPS_ALERT;
                        DEBUGF(INDI::Logger::DBG_ERROR, "put_ReadoutSpeed() failed. %s.", err.what());
                        IDSetSwitch(&ReadOutSP, NULL);
                        return false;
                }

            }
            else
            {
                try
                {
                 QSICam.put_ReadoutSpeed(QSICamera::FastReadout);
                } catch (std::runtime_error err)
                {
                        IUResetSwitch(&ReadOutSP);
                        ReadOutSP.s = IPS_ALERT;
                        DEBUGF(INDI::Logger::DBG_ERROR, "put_ReadoutSpeed() failed. %s.", err.what());
                        IDSetSwitch(&ReadOutSP, NULL);
                        return false;
                }

                ReadOutSP.s = IPS_OK;
                IDSetSwitch(&ReadOutSP, NULL);

            }

            ReadOutSP.s = IPS_OK;
            IDSetSwitch(&ReadOutSP, NULL);
            return true;
        }


         /* Cooler */
        if (!strcmp (name, CoolerSP.name))
        {
          if (IUUpdateSwitch(&CoolerSP, states, names, n) < 0) return false;

          if (CoolerS[0].s == ISS_ON)
            activateCooler(true);
          else
              activateCooler(false);

          return true;
        }

        /* Shutter */
        if (!strcmp (name, ShutterSP.name))
        {
            if (IUUpdateSwitch(&ShutterSP, states, names, n) < 0) return false;
            shutterControl();
            return true;
        }

        if (!strcmp(name, GainSP.name))
        {
            int prevGain = IUFindOnSwitchIndex(&GainSP);
            IUUpdateSwitch(&GainSP, states, names, n);
            int targetGain = IUFindOnSwitchIndex(&GainSP);

            if (prevGain == targetGain)
            {
                GainSP.s = IPS_OK;
                IDSetSwitch(&GainSP, NULL);
                return true;
            }

            try
            {
                QSICam.put_CameraGain( ((QSICamera::CameraGain) targetGain));

            }  catch (std::runtime_error err)
            {
                                    IUResetSwitch(&GainSP);
                                    GainS[prevGain].s = ISS_ON;
                                    GainSP.s = IPS_ALERT;
                                    DEBUGF(INDI::Logger::DBG_ERROR, "put_CameraGain failed. %s.", err.what());
                                    IDSetSwitch(&GainSP, NULL);
                                    return false;
            }

            GainSP.s = IPS_OK;
            IDSetSwitch(&GainSP, NULL);
            return true;
        }

        if (!strcmp(name, FanSP.name))
        {
            int prevFan = IUFindOnSwitchIndex(&FanSP);
            IUUpdateSwitch(&FanSP, states, names, n);
            int targetFan = IUFindOnSwitchIndex(&FanSP);

            if (prevFan == targetFan)
            {
                FanSP.s = IPS_OK;
                IDSetSwitch(&FanSP, NULL);
                return true;
            }

            try
            {
                QSICam.put_FanMode( ((QSICamera::FanMode) targetFan));

            }  catch (std::runtime_error err)
            {
                                    IUResetSwitch(&FanSP);
                                    FanS[prevFan].s = ISS_ON;
                                    FanSP.s = IPS_ALERT;
                                    DEBUGF(INDI::Logger::DBG_ERROR, "put_FanMode failed. %s.", err.what());
                                    IDSetSwitch(&FanSP, NULL);
                                    return false;
            }

            FanSP.s = IPS_OK;
            IDSetSwitch(&FanSP, NULL);
            return true;
        }

        if (!strcmp(name, ABSP.name))
        {
            int prevAB = IUFindOnSwitchIndex(&ABSP);
            IUUpdateSwitch(&ABSP, states, names, n);
            int targetAB = IUFindOnSwitchIndex(&ABSP);

            if (prevAB == targetAB)
            {
                ABSP.s = IPS_OK;
                IDSetSwitch(&ABSP, NULL);
                return true;
            }

            try
            {
                QSICam.put_AntiBlooming( ((QSICamera::AntiBloom) targetAB));

            }  catch (std::runtime_error err)
            {
                IUResetSwitch(&ABSP);
                ABS[prevAB].s = ISS_ON;
                ABSP.s = IPS_ALERT;
                DEBUGF(INDI::Logger::DBG_ERROR, "put_AntiBlooming failed. %s.", err.what());
                IDSetSwitch(&ABSP, NULL);
                return false;
            }

            ABSP.s = IPS_OK;
            IDSetSwitch(&ABSP, NULL);
            return true;
        }

        /* Filter Wheel */
        if (!strcmp (name, FilterSP.name))
        {
            if (IUUpdateSwitch(&FilterSP, states, names, n) < 0) return false;
            turnWheel();
            return true;
        }
    }

        //  Nobody has claimed this, so, ignore it
        return INDI::CCD::ISNewSwitch(dev,name,states,names,n);
}
Ejemplo n.º 9
0
Archivo: ieqpro.cpp Proyecto: mp77/indi
bool IEQPro::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
{
    if (!strcmp (getDeviceName(), dev))
    {
        if (!strcmp(name, HomeSP.name))
        {
            IUUpdateSwitch(&HomeSP, states, names, n);

            IEQ_HOME_OPERATION operation = (IEQ_HOME_OPERATION) IUFindOnSwitchIndex(&HomeSP);

            IUResetSwitch(&HomeSP);

            switch (operation)
            {
                case IEQ_FIND_HOME:
                    if (firmwareInfo.Model.find("CEM") == std::string::npos)
                    {
                        HomeSP.s = IPS_IDLE;
                        IDSetSwitch(&HomeSP, NULL);
                        DEBUG(INDI::Logger::DBG_WARNING, "Home search is not supported in this model.");
                        return true;
                    }

                    if (find_ieqpro_home(PortFD) == false)
                    {
                        HomeSP.s = IPS_ALERT;
                        IDSetSwitch(&HomeSP, NULL);
                        return false;

                    }

                    HomeSP.s = IPS_OK;
                    IDSetSwitch(&HomeSP, NULL);
                    DEBUG(INDI::Logger::DBG_SESSION, "Searching for home position...");
                    return true;

                    break;

                case IEQ_SET_HOME:
                    if (set_ieqpro_current_home(PortFD) == false)
                    {
                        HomeSP.s = IPS_ALERT;
                        IDSetSwitch(&HomeSP, NULL);
                        return false;

                    }

                    HomeSP.s = IPS_OK;
                    IDSetSwitch(&HomeSP, NULL);
                    DEBUG(INDI::Logger::DBG_SESSION, "Home position set to current coordinates.");
                    return true;

                    break;

                case IEQ_GOTO_HOME:
                    if (goto_ieqpro_home(PortFD) == false)
                    {
                        HomeSP.s = IPS_ALERT;
                        IDSetSwitch(&HomeSP, NULL);
                        return false;

                    }

                    HomeSP.s = IPS_OK;
                    IDSetSwitch(&HomeSP, NULL);
                    DEBUG(INDI::Logger::DBG_SESSION, "Slewing to home position...");
                    return true;

                    break;
            }

            return true;
        }

        if (!strcmp(name, TrackModeSP.name))
        {
            IUUpdateSwitch(&TrackModeSP, states, names, n);

            TelescopeTrackMode mode = (TelescopeTrackMode) IUFindOnSwitchIndex(&TrackModeSP);

            IEQ_TRACK_RATE rate;

            switch (mode)
            {
                case TRACK_SIDEREAL:
                    rate = TR_SIDEREAL;
                    break;
                case TRACK_SOLAR:
                    rate = TR_SOLAR;
                    break;
                case TRACK_LUNAR:
                    rate = TR_LUNAR;
                    break;
                case TRACK_CUSTOM:
                    rate = TR_CUSTOM;
                    break;
            }

            if (set_ieqpro_track_mode(PortFD, rate))
            {
                if (TrackState == SCOPE_TRACKING)
                    TrackModeSP.s = IPS_BUSY;
                else
                    TrackModeSP.s = IPS_OK;
            }
            else
                TrackModeSP.s = IPS_ALERT;

        }

    }

    return INDI::Telescope::ISNewSwitch (dev, name, states, names,  n);
}
Ejemplo n.º 10
0
void SynscanDriver::mountSim()
{
    static struct timeval ltv;
    struct timeval tv;
    double dt, da, dx;
    int nlocked;

    /* update elapsed time since last poll, don't presume exactly POLLMS */
    gettimeofday(&tv, nullptr);

    if (ltv.tv_sec == 0 && ltv.tv_usec == 0)
        ltv = tv;

    dt  = tv.tv_sec - ltv.tv_sec + (tv.tv_usec - ltv.tv_usec) / 1e6;
    ltv = tv;
    double currentSlewRate = SIM_SLEW_RATE[IUFindOnSwitchIndex(&SlewRateSP)] * TRACKRATE_SIDEREAL / 3600.0;
    da  = currentSlewRate * dt;

    /* Process per current state. We check the state of EQUATORIAL_COORDS and act acoordingly */
    switch (TrackState)
    {
        case SCOPE_IDLE:
            CurrentRA += (TrackRateN[AXIS_RA].value / 3600.0 * dt) / 15.0;
            CurrentRA = range24(CurrentRA);
            break;

        case SCOPE_TRACKING:
            break;

        case SCOPE_SLEWING:
        case SCOPE_PARKING:
            /* slewing - nail it when both within one pulse @ SLEWRATE */
            nlocked = 0;

            dx = TargetRA - CurrentRA;

            // Take shortest path
            if (fabs(dx) > 12)
                dx *= -1;

            if (fabs(dx) <= da)
            {
                CurrentRA = TargetRA;
                nlocked++;
            }
            else if (dx > 0)
                CurrentRA += da / 15.;
            else
                CurrentRA -= da / 15.;

            if (CurrentRA < 0)
                CurrentRA += 24;
            else if (CurrentRA > 24)
                CurrentRA -= 24;

            dx = TargetDE - CurrentDE;
            if (fabs(dx) <= da)
            {
                CurrentDE = TargetDE;
                nlocked++;
            }
            else if (dx > 0)
                CurrentDE += da;
            else
                CurrentDE -= da;

            if (nlocked == 2)
            {
                if (TrackState == SCOPE_SLEWING)
                    TrackState = SCOPE_TRACKING;
                else
                    TrackState = SCOPE_PARKED;
            }

            break;

        default:
            break;
    }

    NewRaDec(CurrentRA, CurrentDE);
}
Ejemplo n.º 11
0
bool ioptronHC8406::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
    if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
    {

        // Sync type
        if (!strcmp(name, SyncCMRSP.name))
        {
            IUResetSwitch(&SyncCMRSP);
            IUUpdateSwitch(&SyncCMRSP, states, names, n);
            IUFindOnSwitchIndex(&SyncCMRSP);
            SyncCMRSP.s = IPS_OK;
            IDSetSwitch(&SyncCMRSP, nullptr);
            return true;
        }

        // Cursor move type
        if (!strcmp(name, CursorMoveSpeedSP.name))
        {
            int currentSwitch = IUFindOnSwitchIndex(&CursorMoveSpeedSP);
	    IUUpdateSwitch(&CursorMoveSpeedSP, states, names, n);
            if (setioptronHC8406CursorMoveSpeed(IUFindOnSwitchIndex(&CursorMoveSpeedSP)) == TTY_OK)
                CursorMoveSpeedSP.s = IPS_OK;
            else
            {
                IUResetSwitch(&CursorMoveSpeedSP);
                CursorMoveSpeedS[currentSwitch].s = ISS_ON;
                CursorMoveSpeedSP.s = IPS_ALERT;
            }
            return true;
        }

        // Guide Rate
        if (!strcmp(GuideRateSP.name, name))
        {
            int currentSwitch = IUFindOnSwitchIndex(&GuideRateSP);
            IUUpdateSwitch(&GuideRateSP, states, names, n);
            if (setioptronHC8406GuideRate(IUFindOnSwitchIndex(&GuideRateSP)) == TTY_OK)
            {
                GuideRateSP.s = IPS_OK;
		//Shows guide speed selected
		CursorMoveSpeedS[USE_GUIDE_SPEED].s = ISS_ON;
		CursorMoveSpeedS[USE_CENTERING_SPEED].s = ISS_OFF;
	        CursorMoveSpeedSP.s = IPS_OK;
	        IDSetSwitch(&CursorMoveSpeedSP, nullptr);
            } else {
                IUResetSwitch(&GuideRateSP);
                GuideRateS[currentSwitch].s = ISS_ON;
                GuideRateSP.s = IPS_ALERT;
            }

            IDSetSwitch(&GuideRateSP, nullptr);
            return true;
        }

        // Center Rate
        if (!strcmp(CenterRateSP.name, name))
        {
            int currentSwitch = IUFindOnSwitchIndex(&CenterRateSP);
            IUUpdateSwitch(&CenterRateSP, states, names, n);
            if (setioptronHC8406CenterRate(IUFindOnSwitchIndex(&CenterRateSP)) == TTY_OK)
	    {
                CenterRateSP.s = IPS_OK;
		//Shows centering speed selected
		CursorMoveSpeedS[USE_GUIDE_SPEED].s = ISS_OFF;
		CursorMoveSpeedS[USE_CENTERING_SPEED].s = ISS_ON;
	        CursorMoveSpeedSP.s = IPS_OK;
	        IDSetSwitch(&CursorMoveSpeedSP, nullptr);
            } else {
                IUResetSwitch(&CenterRateSP);
                CenterRateS[currentSwitch].s = ISS_ON;
                CenterRateSP.s = IPS_ALERT;
            }

            IDSetSwitch(&CenterRateSP, nullptr);
            return true;
        }

        // Slew Rate
        if (!strcmp(SlewRateSP.name, name))
        {
            int currentSwitch = IUFindOnSwitchIndex(&SlewRateSP);
            IUUpdateSwitch(&SlewRateSP, states, names, n);
            if (setioptronHC8406SlewRate(IUFindOnSwitchIndex(&SlewRateSP)) == TTY_OK)
                SlewRateSP.s = IPS_OK;
            else
            {
                IUResetSwitch(&SlewRateSP);
                SlewRateS[currentSwitch].s = ISS_ON;
                SlewRateSP.s = IPS_ALERT;
            }

            IDSetSwitch(&SlewRateSP, nullptr);
            return true;
        }

    }

    return LX200Generic::ISNewSwitch(dev, name, states, names, n);
}
Ejemplo n.º 12
0
bool ClientAPIForAlignmentDatabase::ReadSyncPoint(unsigned int Offset, AlignmentDatabaseEntry &CurrentValues)
{
    // Wait for driver to initialise if neccessary
    WaitForDriverCompletion();

    ISwitchVectorProperty * pAction = Action->getSwitch();
    INumberVectorProperty * pMandatoryNumbers = MandatoryNumbers->getNumber();
    IBLOBVectorProperty  * pBLOB = OptionalBinaryBlob->getBLOB();
    INumberVectorProperty * pCurrentEntry = CurrentEntry->getNumber();
    ISwitchVectorProperty * pCommit = Commit->getSwitch();

    // Select the required action
    if (READ != IUFindOnSwitchIndex(pAction))
    {
        // Request Read mode
        IUResetSwitch(pAction);
        pAction->sp[READ].s = ISS_ON;
        SetDriverBusy();
        BaseClient->sendNewSwitch(pAction);
        WaitForDriverCompletion();
        if (IPS_OK != pAction->s)
        {
            IDLog("ReadSyncPoint - Bad Action switch state %s\n", pstateStr(pAction->s));
            return false;
        }
    }

    // Send the offset
    pCurrentEntry->np[0].value = Offset;
    SetDriverBusy();
    BaseClient->sendNewNumber(pCurrentEntry);
    WaitForDriverCompletion();
    if (IPS_OK != pCurrentEntry->s)
    {
        IDLog("ReadSyncPoint - Bad Current Entry state %s\n", pstateStr(pCurrentEntry->s));
        return false;
    }

    // Commit the read
    IUResetSwitch(pCommit);
    pCommit->sp[0].s = ISS_ON;
    SetDriverBusy();
    BaseClient->sendNewSwitch(pCommit);
    WaitForDriverCompletion();
    if ((IPS_OK != pCommit->s) || (IPS_OK != pMandatoryNumbers->s) || (IPS_OK != pBLOB->s))
    {
        IDLog("ReadSyncPoint - Bad Commit/Mandatory numbers/Blob state %s %s %s\n", pstateStr(pCommit->s),
              pstateStr(pMandatoryNumbers->s),
              pstateStr(pBLOB->s));
        return false;
    }

    // Read the entry data
    CurrentValues.ObservationJulianDate = pMandatoryNumbers->np[ENTRY_OBSERVATION_JULIAN_DATE].value;
    CurrentValues.RightAscension = pMandatoryNumbers->np[ENTRY_RA].value;
    CurrentValues.Declination = pMandatoryNumbers->np[ENTRY_DEC].value;
    CurrentValues.TelescopeDirection.x = pMandatoryNumbers->np[ENTRY_VECTOR_X].value;
    CurrentValues.TelescopeDirection.y = pMandatoryNumbers->np[ENTRY_VECTOR_Y].value;
    CurrentValues.TelescopeDirection.z = pMandatoryNumbers->np[ENTRY_VECTOR_Z].value;

    return true;
}
Ejemplo n.º 13
0
bool LX200_16::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
{
   int index;

   if(strcmp(dev,getDeviceName())==0)
   {
       if (!strcmp(name, FanStatusSP.name))
       {
           IUResetSwitch(&FanStatusSP);
           IUUpdateSwitch(&FanStatusSP, states, names, n);
           index = IUFindOnSwitchIndex(&FanStatusSP);

          if (index == 0)
          {
            if (turnFanOn(PortFD) < 0)
            {
                FanStatusSP.s = IPS_ALERT;
                IDSetSwitch(&FanStatusSP, "Error changing fan status.");
                return false;
            }
          }
          else
          {
            if (turnFanOff(PortFD) < 0)
            {
                FanStatusSP.s = IPS_ALERT;
                IDSetSwitch(&FanStatusSP, "Error changing fan status.");
                return false;
            }
          }

          FanStatusSP.s = IPS_OK;
          IDSetSwitch (&FanStatusSP, index == 0 ? "Fan is ON" : "Fan is OFF");
          return true;
       }

       if (!strcmp(name, HomeSearchSP.name))
       {
          IUResetSwitch(&HomeSearchSP);
          IUUpdateSwitch(&HomeSearchSP, states, names, n);
          index = IUFindOnSwitchIndex(&HomeSearchSP);

          if (index == 0)
            seekHomeAndSave(PortFD);
          else
            seekHomeAndSet(PortFD);

          HomeSearchSP.s = IPS_BUSY;
          IDSetSwitch (&HomeSearchSP, index == 0 ? "Seek Home and Save" : "Seek Home and Set");
          return true;
       }

       if (!strcmp(name, FieldDeRotatorSP.name))
       {
          IUResetSwitch(&FieldDeRotatorSP);
          IUUpdateSwitch(&FieldDeRotatorSP, states, names, n);
          index = IUFindOnSwitchIndex(&FieldDeRotatorSP);

          if (index == 0)
            turnFieldDeRotatorOn(PortFD);
          else
            turnFieldDeRotatorOff(PortFD);

          FieldDeRotatorSP.s = IPS_OK;
          IDSetSwitch (&FieldDeRotatorSP, index == 0 ? "Field deRotator is ON" : "Field deRotator is OFF");
          return true;
       }
   }


    return LX200GPS::ISNewSwitch (dev, name, states, names, n);
}
Ejemplo n.º 14
0
/************************************************************************************
 *
* ***********************************************************************************/
bool BaaderDome::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
    if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
    {
        if (strcmp(name, CalibrateSP.name) == 0)
        {
            IUResetSwitch(&CalibrateSP);

            if (status == DOME_READY)
            {
                CalibrateSP.s = IPS_OK;
                DEBUG(INDI::Logger::DBG_SESSION, "Dome is already calibrated.");
                IDSetSwitch(&CalibrateSP, nullptr);
                return true;
            }

            if (CalibrateSP.s == IPS_BUSY)
            {
                Abort();
                DEBUG(INDI::Logger::DBG_SESSION, "Calibration aborted.");
                status        = DOME_UNKNOWN;
                CalibrateSP.s = IPS_IDLE;
                IDSetSwitch(&CalibrateSP, nullptr);
                return true;
            }

            status = DOME_CALIBRATING;

            DEBUG(INDI::Logger::DBG_SESSION, "Starting calibration procedure...");

            calibrationStage = CALIBRATION_STAGE1;

            calibrationStart = DomeAbsPosN[0].value;

            // Goal of procedure is to reach south point to hit sensor
            calibrationTarget1 = calibrationStart + 179;
            if (calibrationTarget1 > 360)
                calibrationTarget1 -= 360;

            if (MoveAbs(calibrationTarget1) == IPS_IDLE)
            {
                CalibrateSP.s = IPS_ALERT;
                DEBUG(INDI::Logger::DBG_ERROR, "Calibration failue due to dome motion failure.");
                status = DOME_UNKNOWN;
                IDSetSwitch(&CalibrateSP, nullptr);
                return false;
            }

            DomeAbsPosNP.s = IPS_BUSY;
            CalibrateSP.s  = IPS_BUSY;
            DEBUGF(INDI::Logger::DBG_SESSION, "Calibration is in progress. Moving to position %g.", calibrationTarget1);
            IDSetSwitch(&CalibrateSP, nullptr);
            return true;
        }

        if (strcmp(name, DomeFlapSP.name) == 0)
        {
            int ret        = 0;
            int prevStatus = IUFindOnSwitchIndex(&DomeFlapSP);
            IUUpdateSwitch(&DomeFlapSP, states, names, n);
            int FlapDome = IUFindOnSwitchIndex(&DomeFlapSP);

            // No change of status, let's return
            if (prevStatus == FlapDome)
            {
                DomeFlapSP.s = IPS_OK;
                IDSetSwitch(&DomeFlapSP, nullptr);
            }

            // go back to prev status in case of failure
            IUResetSwitch(&DomeFlapSP);
            DomeFlapS[prevStatus].s = ISS_ON;

            if (FlapDome == 0)
                ret = ControlDomeFlap(FLAP_OPEN);
            else
                ret = ControlDomeFlap(FLAP_CLOSE);

            if (ret == 0)
            {
                DomeFlapSP.s = IPS_OK;
                IUResetSwitch(&DomeFlapSP);
                DomeFlapS[FlapDome].s = ISS_ON;
                IDSetSwitch(&DomeFlapSP, "Flap is %s.", (FlapDome == 0 ? "open" : "closed"));
                return true;
            }
            else if (ret == 1)
            {
                DomeFlapSP.s = IPS_BUSY;
                IUResetSwitch(&DomeFlapSP);
                DomeFlapS[FlapDome].s = ISS_ON;
                IDSetSwitch(&DomeFlapSP, "Flap is %s...", (FlapDome == 0 ? "opening" : "closing"));
                return true;
            }

            DomeFlapSP.s = IPS_ALERT;
            IDSetSwitch(&DomeFlapSP, "Flap failed to %s.", (FlapDome == 0 ? "open" : "close"));
            return false;
        }
    }

    return INDI::Dome::ISNewSwitch(dev, name, states, names, n);
}
Ejemplo n.º 15
0
bool LX200GPS::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
    int index = 0;
    char msg[64];

    if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
    {
        /* GPS Power */
        if (!strcmp(name, GPSPowerSP.name))
        {
            int ret = 0;

            if (IUUpdateSwitch(&GPSPowerSP, states, names, n) < 0)
                return false;

            index = IUFindOnSwitchIndex(&GPSPowerSP);
            if (index == 0)
                ret = turnGPSOn(PortFD);
            else
                ret = turnGPSOff(PortFD);

            GPSPowerSP.s = IPS_OK;
            IDSetSwitch(&GPSPowerSP, index == 0 ? "GPS System is ON" : "GPS System is OFF");
            return true;
        }

        /* GPS Status Update */
        if (!strcmp(name, GPSStatusSP.name))
        {
            int ret = 0;

            if (IUUpdateSwitch(&GPSStatusSP, states, names, n) < 0)
                return false;

            index = IUFindOnSwitchIndex(&GPSStatusSP);

            if (index == 0)
            {
                ret = gpsSleep(PortFD);
                strncpy(msg, "GPS system is in sleep mode.", 64);
            }
            else if (index == 1)
            {
                ret = gpsWakeUp(PortFD);
                strncpy(msg, "GPS system is reactivated.", 64);
            }
            else
            {
                ret = gpsRestart(PortFD);
                strncpy(msg, "GPS system is restarting...", 64);
                sendScopeTime();
                sendScopeLocation();
            }

            GPSStatusSP.s = IPS_OK;
            IDSetSwitch(&GPSStatusSP, "%s", msg);
            return true;
        }

        /* GPS Update */
        if (!strcmp(name, GPSUpdateSP.name))
        {
            if (IUUpdateSwitch(&GPSUpdateSP, states, names, n) < 0)
                return false;

            index = IUFindOnSwitchIndex(&GPSUpdateSP);

            GPSUpdateSP.s = IPS_OK;

            if (index == 0)
            {
                IDSetSwitch(&GPSUpdateSP, "Updating GPS system. This operation might take few minutes to complete...");
                if (updateGPS_System(PortFD))
                {
                    IDSetSwitch(&GPSUpdateSP, "GPS system update successful.");
                    sendScopeTime();
                    sendScopeLocation();
                }
                else
                {
                    GPSUpdateSP.s = IPS_IDLE;
                    IDSetSwitch(&GPSUpdateSP, "GPS system update failed.");
                }
            }
            else
            {
                sendScopeTime();
                sendScopeLocation();
                IDSetSwitch(&GPSUpdateSP, "Client time and location is synced to LX200 GPS Data.");
            }
            return true;
        }

        /* Alt Dec Periodic Error correction */
        if (!strcmp(name, AltDecPecSP.name))
        {
            int ret = 0;

            if (IUUpdateSwitch(&AltDecPecSP, states, names, n) < 0)
                return false;

            index = IUFindOnSwitchIndex(&AltDecPecSP);

            if (index == 0)
            {
                ret = enableDecAltPec(PortFD);
                strncpy(msg, "Alt/Dec Compensation Enabled.", 64);
            }
            else
            {
                ret = disableDecAltPec(PortFD);
                strncpy(msg, "Alt/Dec Compensation Disabled.", 64);
            }

            AltDecPecSP.s = IPS_OK;
            IDSetSwitch(&AltDecPecSP, "%s", msg);

            return true;
        }

        /* Az RA periodic error correction */
        if (!strcmp(name, AzRaPecSP.name))
        {
            int ret = 0;

            if (IUUpdateSwitch(&AzRaPecSP, states, names, n) < 0)
                return false;

            index = IUFindOnSwitchIndex(&AzRaPecSP);

            if (index == 0)
            {
                ret = enableRaAzPec(PortFD);
                strncpy(msg, "Ra/Az Compensation Enabled.", 64);
            }
            else
            {
                ret = disableRaAzPec(PortFD);
                strncpy(msg, "Ra/Az Compensation Disabled.", 64);
            }

            AzRaPecSP.s = IPS_OK;
            IDSetSwitch(&AzRaPecSP, "%s", msg);

            return true;
        }

        if (!strcmp(name, AltDecBacklashSP.name))
        {
            int ret = 0;

            ret = activateAltDecAntiBackSlash(PortFD);
            AltDecBacklashSP.s = IPS_OK;
            IDSetSwitch(&AltDecBacklashSP, "Alt/Dec Anti-backlash enabled");
            return true;
        }

        if (!strcmp(name, AzRaBacklashSP.name))
        {
            int ret = 0;

            ret = activateAzRaAntiBackSlash(PortFD);
            AzRaBacklashSP.s = IPS_OK;
            IDSetSwitch(&AzRaBacklashSP, "Az/Ra Anti-backlash enabled");
            return true;
        }

        if (!strcmp(name, OTAUpdateSP.name))
        {
            IUResetSwitch(&OTAUpdateSP);

            if (getOTATemp(PortFD, &OTATempNP.np[0].value) < 0)
            {
                OTAUpdateSP.s = IPS_ALERT;
                OTATempNP.s   = IPS_ALERT;
                IDSetNumber(&OTATempNP, "Error: OTA temperature read timed out.");
                return false;
            }
            else
            {
                OTAUpdateSP.s = IPS_OK;
                OTATempNP.s   = IPS_OK;
                IDSetNumber(&OTATempNP, nullptr);
                IDSetSwitch(&OTAUpdateSP, nullptr);
                return true;
            }
        }
    }

    return LX200Autostar::ISNewSwitch(dev, name, states, names, n);
}
Ejemplo n.º 16
0
bool ArmPlat::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
    //IDLog( "NewSwitch: %s %s %s %d\n", dev, name, names[ 0 ], n );
    if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
    {
        /////////////////////////////////////////////
        // Connection!
        /////////////////////////////////////////////
        // if (!strcmp(name, ConnectionSP.name))
        // {
            // return true;
        // }
        /////////////////////////////////////////////
        // Backlash
        /////////////////////////////////////////////
        if (!strcmp(name, BacklashCompensationSP.name))
        {
            IUUpdateSwitch(&BacklashCompensationSP, states, names, n);
            bool rc = false;
            if (IUFindOnSwitchIndex(&BacklashCompensationSP) == BACKLASH_ENABLED)
                rc = setBacklash(BacklashN[0].value);
            else
                rc = setBacklash(0);

            BacklashCompensationSP.s = rc ? IPS_OK : IPS_ALERT;
            IDSetSwitch(&BacklashCompensationSP, nullptr);
            return true;
        }
        /////////////////////////////////////////////
        // Temp sensor in use
        /////////////////////////////////////////////
        else if (!strcmp(name, IntExtTempSensorSP.name))
        {
            IUUpdateSwitch(&IntExtTempSensorSP, states, names, n);
            tempSensInUse = IUFindOnSwitchIndex(&IntExtTempSensorSP);
            bool rc = setTempSensorInUse( IUFindOnSwitchIndex(&IntExtTempSensorSP));
            IntExtTempSensorSP.s = rc ? IPS_OK : IPS_ALERT;
            IDSetSwitch(&IntExtTempSensorSP, nullptr);
            return true;
        }
        /////////////////////////////////////////////
        // Halfstep
        /////////////////////////////////////////////
        else if (!strcmp(name, HalfStepSP.name))
        {
            IUUpdateSwitch(&HalfStepSP, states, names, n);
            bool rc = setHalfStep(IUFindOnSwitchIndex(&HalfStepSP) == HALFSTEP_ON );
            HalfStepSP.s = rc ? IPS_OK : IPS_ALERT;
            IDSetSwitch(&HalfStepSP, nullptr);
            return true;
        }
        /////////////////////////////////////////////
        // Wiring
        /////////////////////////////////////////////
        else if (!strcmp(name, WiringSP.name))
        {
            IUUpdateSwitch(&WiringSP, states, names, n);
            bool rc = setWiring(IUFindOnSwitchIndex(&WiringSP));
            WiringSP.s = rc ? IPS_OK : IPS_ALERT;
            IDSetSwitch(&WiringSP, nullptr);
            return true;
        }
        /////////////////////////////////////////////
        // Peripheral Port
        /////////////////////////////////////////////
        else if (!strcmp(name, PerPortSP.name))
        {
            IUUpdateSwitch(&PerPortSP, states, names, n);
            bool rc = setPort( IUFindOnSwitchIndex(&PerPortSP));
            PerPortSP.s = rc ? IPS_OK : IPS_ALERT;
            IDSetSwitch(&PerPortSP, nullptr);
            return true;
        }
        /////////////////////////////////////////////
        // Motor Type
        /////////////////////////////////////////////
        else if (!strcmp(name, MotorTypeSP.name))
        {
            IUUpdateSwitch(&MotorTypeSP, states, names, n);
            bool rc = setMotorType(IUFindOnSwitchIndex(&MotorTypeSP));
            MotorTypeSP.s = rc ? IPS_OK : IPS_ALERT;
            IDSetSwitch(&MotorTypeSP, nullptr);
            return true;
        }
    }

    return INDI::Focuser::ISNewSwitch(dev, name, states, names, n);
}
Ejemplo n.º 17
0
bool lacerta_mfoc::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
    if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
    {
        // Temp. Track Direction
        if (strcmp(TempTrackDirSP.name, name) == 0)
        {
            IUUpdateSwitch(&TempTrackDirSP, states, names, n);
            int tdir = 0;
            int index    = IUFindOnSwitchIndex(&TempTrackDirSP);
            char MFOC_cmd[32]  = ": I ";
            char MFOC_res[32]  = {0};
            int nbytes_read    = 0;
            int nbytes_written = 0;
            int MFOC_tdir_measd = 0;
            char MFOC_res_type[32]  = "0";

            switch (index)
            {
                case MODE_TDIR_BOTH:
                    tdir = 0;
                    strcat(MFOC_cmd, "0 #");
                    break;

                case MODE_TDIR_IN:
                    tdir = 1;
                    strcat(MFOC_cmd, "1 #");
                    break;

                case MODE_TDIR_OUT:
                    tdir = 2;
                    strcat(MFOC_cmd, "2 #");
                    break;

                default:
                    TempTrackDirSP.s = IPS_ALERT;
                    IDSetSwitch(&TempTrackDirSP, "Unknown mode index %d", index);
                    return true;
            }


            tty_write_string(PortFD, MFOC_cmd, &nbytes_written);
            LOGF_DEBUG("CMD <%s>", MFOC_cmd);
            tty_write_string(PortFD, ": W #", &nbytes_written);
            tty_read_section(PortFD, MFOC_res, 0xD, FOCUSMFOC_TIMEOUT, &nbytes_read);
            sscanf (MFOC_res, "%s %d", MFOC_res_type, &MFOC_tdir_measd);
            LOGF_DEBUG("RES <%s>", MFOC_res);

            if  (MFOC_tdir_measd == tdir)
            {
                TempTrackDirSP.s = IPS_OK;
            }
            else
            {
                TempTrackDirSP.s = IPS_ALERT;
            }

            IDSetSwitch(&TempTrackDirSP, nullptr);
            return true;
        }


        // Start at saved position
        if (strcmp(StartSavedPositionSP.name, name) == 0)
        {
            IUUpdateSwitch(&StartSavedPositionSP, states, names, n);
            int svstart = 0;
            int index    = IUFindOnSwitchIndex(&StartSavedPositionSP);
            char MFOC_cmd[32]  = ": F ";
            char MFOC_res[32]  = {0};
            int nbytes_read    = 0;
            int nbytes_written = 0;
            int MFOC_svstart_measd = 0;
            char MFOC_res_type[32]  = "0";

            switch (index)
            {
                case MODE_SAVED_ON:
                    svstart = 1;
                    strcat(MFOC_cmd, "1 #");
                    break;

                case MODE_SAVED_OFF:
                    svstart = 0;
                    strcat(MFOC_cmd, "0 #");
                    break;

                default:
                    StartSavedPositionSP.s = IPS_ALERT;
                    IDSetSwitch(&StartSavedPositionSP, "Unknown mode index %d", index);
                    return true;
            }

            tty_write_string(PortFD, MFOC_cmd, &nbytes_written);
            LOGF_DEBUG("CMD <%s>", MFOC_cmd);
            tty_write_string(PortFD, ": N #", &nbytes_written);
            tty_read_section(PortFD, MFOC_res, 0xD, FOCUSMFOC_TIMEOUT, &nbytes_read);
            sscanf (MFOC_res, "%s %d", MFOC_res_type, &MFOC_svstart_measd);

            LOGF_DEBUG("RES <%s>", MFOC_res);
            //            LOGF_DEBUG("Debug MFOC cmd sent %s", MFOC_cmd);
            if  (MFOC_svstart_measd == svstart)
            {
                StartSavedPositionSP.s = IPS_OK;
            }
            else
            {
                StartSavedPositionSP.s = IPS_ALERT;
            }

            IDSetSwitch(&StartSavedPositionSP, nullptr);
            return true;
        }
    }

    return INDI::Focuser::ISNewSwitch(dev, name, states, names, n);
}
Ejemplo n.º 18
0
bool ScopeSim::ReadScopeStatus()
{
    static struct timeval ltv { 0, 0 };
    struct timeval tv { 0, 0 };
    double dt = 0, da_ra = 0, da_dec = 0, dx = 0, dy = 0, ra_guide_dt = 0, dec_guide_dt = 0;
    static double last_dx = 0, last_dy = 0;
    int nlocked, ns_guide_dir = -1, we_guide_dir = -1;
    char RA_DISP[64], DEC_DISP[64], RA_GUIDE[64], DEC_GUIDE[64], RA_PE[64], DEC_PE[64], RA_TARGET[64], DEC_TARGET[64];

    /* update elapsed time since last poll, don't presume exactly POLLMS */
    gettimeofday(&tv, nullptr);

    if (ltv.tv_sec == 0 && ltv.tv_usec == 0)
        ltv = tv;

    dt  = tv.tv_sec - ltv.tv_sec + (tv.tv_usec - ltv.tv_usec) / 1e6;
    ltv = tv;

    if (fabs(targetRA - currentRA) * 15. >= GOTO_LIMIT)
        da_ra = GOTO_RATE * dt;
    else if (fabs(targetRA - currentRA) * 15. >= SLEW_LIMIT)
        da_ra = SLEW_RATE * dt;
    else
        da_ra = FINE_SLEW_RATE * dt;

    if (fabs(targetDEC - currentDEC) >= GOTO_LIMIT)
        da_dec = GOTO_RATE * dt;
    else if (fabs(targetDEC - currentDEC) >= SLEW_LIMIT)
        da_dec = SLEW_RATE * dt;
    else
        da_dec = FINE_SLEW_RATE * dt;

    if (MovementNSSP.s == IPS_BUSY || MovementWESP.s == IPS_BUSY)
    {
        int rate = IUFindOnSwitchIndex(&SlewRateSP);

        switch (rate)
        {
            case SLEW_GUIDE:
                da_ra  = FINE_SLEW_RATE * dt * 0.05;
                da_dec = FINE_SLEW_RATE * dt * 0.05;
                break;

            case SLEW_CENTERING:
                da_ra  = FINE_SLEW_RATE * dt * .1;
                da_dec = FINE_SLEW_RATE * dt * .1;
                break;

            case SLEW_FIND:
                da_ra  = SLEW_RATE * dt;
                da_dec = SLEW_RATE * dt;
                break;

            default:
                da_ra  = GOTO_RATE * dt;
                da_dec = GOTO_RATE * dt;
                break;
        }

        switch (MovementNSSP.s)
        {
            case IPS_BUSY:
                if (MovementNSS[DIRECTION_NORTH].s == ISS_ON)
                    currentDEC += da_dec;
                else if (MovementNSS[DIRECTION_SOUTH].s == ISS_ON)
                    currentDEC -= da_dec;
                break;

            default:
                break;
        }

        switch (MovementWESP.s)
        {
            case IPS_BUSY:

                if (MovementWES[DIRECTION_WEST].s == ISS_ON)
                    currentRA += da_ra / 15.;
                else if (MovementWES[DIRECTION_EAST].s == ISS_ON)
                    currentRA -= da_ra / 15.;
                break;

            default:
                break;
        }

        NewRaDec(currentRA, currentDEC);
        return true;
    }

    /* Process per current state. We check the state of EQUATORIAL_EOD_COORDS_REQUEST and act acoordingly */
    switch (TrackState)
    {
        /*case SCOPE_IDLE:
            EqNP.s = IPS_IDLE;
            break;*/
        case SCOPE_SLEWING:
        case SCOPE_PARKING:
            /* slewing - nail it when both within one pulse @ SLEWRATE */
            nlocked = 0;

            dx = targetRA - currentRA;

            // Always take the shortcut, don't go all around the globe
            // If the difference between target and current is more than 12 hours, then we need to take the shortest path
            if (dx > 12)
                dx -= 24;
            else if (dx < -12)
                dx += 24;

            // In meridian flip, alway force eastward motion (increasing RA) until target is reached.
            if (forceMeridianFlip)
            {
                dx = fabs(dx);
                if (dx == 0)
                {
                    dx    = 1;
                    da_ra = GOTO_LIMIT;
                }
            }

            if (fabs(dx) * 15. <= da_ra)
            {
                currentRA = targetRA;
                nlocked++;
            }
            else if (dx > 0)
                currentRA += da_ra / 15.;
            else
                currentRA -= da_ra / 15.;

            currentRA = range24(currentRA);

            dy = targetDEC - currentDEC;
            if (fabs(dy) <= da_dec)
            {
                currentDEC = targetDEC;
                nlocked++;
            }
            else if (dy > 0)
                currentDEC += da_dec;
            else
                currentDEC -= da_dec;

            EqNP.s = IPS_BUSY;

            if (nlocked == 2)
            {
                forceMeridianFlip = false;

                if (TrackState == SCOPE_SLEWING)
                {
                    // Initially no PE in both axis.
                    EqPEN[0].value = currentRA;
                    EqPEN[1].value = currentDEC;

                    IDSetNumber(&EqPENV, nullptr);

                    TrackState = SCOPE_TRACKING;

                    EqNP.s = IPS_OK;
                    DEBUG(INDI::Logger::DBG_SESSION, "Telescope slew is complete. Tracking...");
                }
                else
                {
                    SetParked(true);
                    EqNP.s = IPS_IDLE;
                }
            }

            break;

        case SCOPE_IDLE:
                 //currentRA += (TRACKRATE_SIDEREAL/3600.0 * dt) / 15.0;
                currentRA += (TrackRateN[AXIS_RA].value/3600.0 * dt) / 15.0;
                currentRA = range24(currentRA);
        break;

        case SCOPE_TRACKING:
            // In case of custom tracking rate
            if (TrackModeS[1].s == ISS_ON)
            {
                currentRA  += ( ((TRACKRATE_SIDEREAL/3600.0) - (TrackRateN[AXIS_RA].value/3600.0)) * dt) / 15.0;
                currentDEC += ( (TrackRateN[AXIS_DE].value/3600.0) * dt);
            }

            dt *= 1000;

            if (guiderNSTarget[GUIDE_NORTH] > 0)
            {
                DEBUGF(INDI::Logger::DBG_DEBUG, "Commanded to GUIDE NORTH for %g ms", guiderNSTarget[GUIDE_NORTH]);
                ns_guide_dir = GUIDE_NORTH;
            }
            else if (guiderNSTarget[GUIDE_SOUTH] > 0)
            {
                DEBUGF(INDI::Logger::DBG_DEBUG, "Commanded to GUIDE SOUTH for %g ms", guiderNSTarget[GUIDE_SOUTH]);
                ns_guide_dir = GUIDE_SOUTH;
            }

            // WE Guide Selection
            if (guiderEWTarget[GUIDE_WEST] > 0)
            {
                we_guide_dir = GUIDE_WEST;
                DEBUGF(INDI::Logger::DBG_DEBUG, "Commanded to GUIDE WEST for %g ms", guiderEWTarget[GUIDE_WEST]);
            }
            else if (guiderEWTarget[GUIDE_EAST] > 0)
            {
                we_guide_dir = GUIDE_EAST;
                DEBUGF(INDI::Logger::DBG_DEBUG, "Commanded to GUIDE EAST for %g ms", guiderEWTarget[GUIDE_EAST]);
            }

            if (ns_guide_dir != -1)
            {
                dec_guide_dt = TrackRateN[AXIS_RA].value/3600.0 * GuideRateN[DEC_AXIS].value * guiderNSTarget[ns_guide_dir] / 1000.0 *
                               (ns_guide_dir == GUIDE_NORTH ? 1 : -1);

                // If time remaining is more that dt, then decrement and
                if (guiderNSTarget[ns_guide_dir] >= dt)
                    guiderNSTarget[ns_guide_dir] -= dt;
                else
                    guiderNSTarget[ns_guide_dir] = 0;

                if (guiderNSTarget[ns_guide_dir] == 0)
                {
                    GuideNSNP.s = IPS_IDLE;
                    IDSetNumber(&GuideNSNP, nullptr);
                }

                EqPEN[DEC_AXIS].value += dec_guide_dt;
            }

            if (we_guide_dir != -1)
            {
                ra_guide_dt = (TrackRateN[AXIS_RA].value/3600.0) / 15.0 * GuideRateN[RA_AXIS].value * guiderEWTarget[we_guide_dir] / 1000.0 *
                              (we_guide_dir == GUIDE_WEST ? -1 : 1);

                if (guiderEWTarget[we_guide_dir] >= dt)
                    guiderEWTarget[we_guide_dir] -= dt;
                else
                    guiderEWTarget[we_guide_dir] = 0;

                if (guiderEWTarget[we_guide_dir] == 0)
                {
                    GuideWENP.s = IPS_IDLE;
                    IDSetNumber(&GuideWENP, nullptr);
                }

                EqPEN[RA_AXIS].value += ra_guide_dt;
            }

            //Mention the followng:
            // Current RA displacemet and direction
            // Current DEC displacement and direction
            // Amount of RA GUIDING correction and direction
            // Amount of DEC GUIDING correction and direction

            dx = EqPEN[RA_AXIS].value - targetRA;
            dy = EqPEN[DEC_AXIS].value - targetDEC;
            fs_sexa(RA_DISP, fabs(dx), 2, 3600);
            fs_sexa(DEC_DISP, fabs(dy), 2, 3600);

            fs_sexa(RA_GUIDE, fabs(ra_guide_dt), 2, 3600);
            fs_sexa(DEC_GUIDE, fabs(dec_guide_dt), 2, 3600);

            fs_sexa(RA_PE, EqPEN[RA_AXIS].value, 2, 3600);
            fs_sexa(DEC_PE, EqPEN[DEC_AXIS].value, 2, 3600);

            fs_sexa(RA_TARGET, targetRA, 2, 3600);
            fs_sexa(DEC_TARGET, targetDEC, 2, 3600);

            if (dx != last_dx || dy != last_dy || ra_guide_dt != 0.0 || dec_guide_dt != 0.0)
            {
                last_dx = dx;
                last_dy = dy;
                //DEBUGF(INDI::Logger::DBG_DEBUG, "dt is %g\n", dt);
                DEBUGF(INDI::Logger::DBG_DEBUG, "RA Displacement (%c%s) %s -- %s of target RA %s", dx >= 0 ? '+' : '-',
                       RA_DISP, RA_PE, (EqPEN[RA_AXIS].value - targetRA) > 0 ? "East" : "West", RA_TARGET);
                DEBUGF(INDI::Logger::DBG_DEBUG, "DEC Displacement (%c%s) %s -- %s of target RA %s", dy >= 0 ? '+' : '-',
                       DEC_DISP, DEC_PE, (EqPEN[DEC_AXIS].value - targetDEC) > 0 ? "North" : "South", DEC_TARGET);
                DEBUGF(INDI::Logger::DBG_DEBUG, "RA Guide Correction (%g) %s -- Direction %s", ra_guide_dt, RA_GUIDE,
                       ra_guide_dt > 0 ? "East" : "West");
                DEBUGF(INDI::Logger::DBG_DEBUG, "DEC Guide Correction (%g) %s -- Direction %s", dec_guide_dt, DEC_GUIDE,
                       dec_guide_dt > 0 ? "North" : "South");
            }

            if (ns_guide_dir != -1 || we_guide_dir != -1)
                IDSetNumber(&EqPENV, nullptr);

            break;

        default:
            break;
    }

    char RAStr[64], DecStr[64];

    fs_sexa(RAStr, currentRA, 2, 3600);
    fs_sexa(DecStr, currentDEC, 2, 3600);

    DEBUGF(DBG_SCOPE, "Current RA: %s Current DEC: %s", RAStr, DecStr);

    NewRaDec(currentRA, currentDEC);
    return true;
}
Ejemplo n.º 19
0
bool GPhotoCCD::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{

  if (strcmp(dev, getDeviceName()) == 0)
  {
      if (!strcmp(name, mIsoSP.name))
      {
          if (IUUpdateSwitch(&mIsoSP, states, names, n) < 0)
              return false;

          for (int i = 0; i < mIsoSP.nsp; i++)
          {
              if (mIsoS[i].s == ISS_ON)
              {
                  if (sim == false)
                      gphoto_set_iso(gphotodrv, i);
                  mIsoSP.s = IPS_OK;
                  IDSetSwitch(&mIsoSP, NULL);
                  break;
              }
          }
      }
      
      if (!strcmp(name, mFormatSP.name))
      {
          int prevSwitch = IUFindOnSwitchIndex(&mFormatSP);
          if (IUUpdateSwitch(&mFormatSP, states, names, n) < 0)
              return false;

          ISwitch *sp = IUFindOnSwitch(&mFormatSP);
          if (sp)
          {
              if (strstr(sp->label, "+"))
              {
                  DEBUGF(INDI::Logger::DBG_ERROR, "%s format is not supported.", sp->label);
                  IUResetSwitch(&mFormatSP);
                  mFormatSP.s = IPS_ALERT;
                  mFormatSP.sp[prevSwitch].s = ISS_ON;
                  IDSetSwitch(&mFormatSP, NULL);
                  return false;
              }
          }
          for (int i = 0; i < mFormatSP.nsp; i++)
          {
              if (mFormatS[i].s == ISS_ON)
              {
                  if (sim == false)
                    gphoto_set_format(gphotodrv, i);
                  mFormatSP.s = IPS_OK;
                  IDSetSwitch(&mFormatSP, NULL);
                  // We need to get frame W and H if format changes
                  frameInitialized = false;
                  break;
              }
          }
      }

      if (!strcmp(name, transferFormatSP.name))
      {
          IUUpdateSwitch(&transferFormatSP, states, names, n);
          transferFormatSP.s = IPS_OK;
          IDSetSwitch(&transferFormatSP, NULL);
          // We need to get frame W and H if transfer format changes
          frameInitialized = false;
          return true;
      }

      if (!strcmp(name, autoFocusSP.name))
      {
          IUResetSwitch(&autoFocusSP);
          if (gphoto_auto_focus(gphotodrv) == GP_OK)
              autoFocusSP.s = IPS_OK;
          else
              autoFocusSP.s = IPS_ALERT;

          IDSetSwitch(&autoFocusSP, NULL);
          return true;
      }

      if (!strcmp(name, UploadSP.name))
      {
          IUUpdateSwitch(&UploadSP, states, names, n);
          UploadSP.s = IPS_OK;
          IDSetSwitch(&UploadSP, NULL);

          if (!sim)
              gphoto_set_upload_settings(gphotodrv, IUFindOnSwitchIndex(&UploadSP));
          return true;
      }

      if (!strcmp(name, livePreviewSP.name))
      {
          IUUpdateSwitch(&livePreviewSP, states, names, n);
          if (livePreviewS[0].s == ISS_ON)
          {
              livePreviewSP.s = IPS_BUSY;
              SetTimer(STREAMPOLLMS);
          }
          else
              livePreviewSP.s = IPS_IDLE;
          IDSetSwitch(&livePreviewSP, NULL);
          return true;
      }

      if (strstr(name, "FOCUS"))
      {
          return processFocuserSwitch(dev, name, states, names, n);
      }

      if(CamOptions.find(name) != CamOptions.end())
      {
          cam_opt *opt = CamOptions[name];
          if (opt->widget->type != GP_WIDGET_RADIO
              && opt->widget->type != GP_WIDGET_MENU
              && opt->widget->type != GP_WIDGET_TOGGLE)
          {
              DEBUGF(INDI::Logger::DBG_ERROR, "ERROR: Property '%s'is not a switch (%d)", name, opt->widget->type);
              return false;
          }

          if (opt->widget->readonly)
          {
              DEBUGF(INDI::Logger::DBG_WARNING, "WARNING: Property %s is read-only", name);
              IDSetSwitch(&opt->prop.sw, NULL);
              return false;
          }

          if (IUUpdateSwitch(&opt->prop.sw, states, names, n) < 0)
              return false;

          if (opt->widget->type == GP_WIDGET_TOGGLE)
          {
              gphoto_set_widget_num(gphotodrv, opt->widget, opt->item.sw[ON_S].s == ISS_ON);
          } else
          {
              for (int i = 0; i < opt->prop.sw.nsp; i++)
              {
                  if (opt->item.sw[i].s == ISS_ON)
                  {
                      gphoto_set_widget_num(gphotodrv, opt->widget, i);
                      break;
                  }
              }
          }
          opt->prop.sw.s = IPS_OK;
          IDSetSwitch(&opt->prop.sw, NULL);
          return true;
      }            
  }

  return INDI::CCD::ISNewSwitch(dev, name, states, names, n);

}
Ejemplo n.º 20
0
bool ATIKCCD::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
{
    if (dev != nullptr && !strcmp(dev, getDeviceName()))
    {
        // Gain/Offset Presets
        if (!strcmp(name, ControlPresetsSP.name))
        {
            int prevIndex = IUFindOnSwitchIndex(&ControlPresetsSP);
            IUUpdateSwitch(&ControlPresetsSP, states, names, n);
            int targetIndex = IUFindOnSwitchIndex(&ControlPresetsSP);
            uint16_t value = static_cast<uint16_t>(targetIndex + 2);
            uint8_t *data = reinterpret_cast<uint8_t*>(&value);
            int rc = ArtemisCameraSpecificOptionSetData(hCam, ID_AtikHorizonGOPresetMode, data, 2);
            if (rc != ARTEMIS_OK)
            {
                ControlPresetsSP.s = IPS_ALERT;
                IUResetSwitch(&ControlPresetsSP);
                ControlPresetsS[prevIndex].s = ISS_ON;
            }
            else
                ControlPresetsSP.s = IPS_OK;

            IDSetSwitch(&ControlPresetsSP, nullptr);
            return true;
        }

        // Cooler controler
        if (!strcmp(name, CoolerSP.name))
        {
            if (IUUpdateSwitch(&CoolerSP, states, names, n) < 0)
            {
                CoolerSP.s = IPS_ALERT;
                IDSetSwitch(&CoolerSP, nullptr);
                return true;
            }

            bool enabled = (CoolerS[COOLER_ON].s == ISS_ON);

            // If user turns on cooler, but the requested temperature is higher than current temperature
            // then we set temperature to zero degrees. If that was still higher than current temperature
            // we return an error
            if (enabled && TemperatureRequest > TemperatureN[0].value)
            {
                TemperatureRequest = 0;
                // If current temperature is still lower than zero, then we shouldn't risk
                // setting temperature to any arbitrary value. Instead, we report an error and ask
                // user to explicitly set the requested temperature.
                if (TemperatureRequest > TemperatureN[0].value)
                {
                    CoolerS[COOLER_ON].s = ISS_OFF;
                    CoolerS[COOLER_OFF].s = ISS_OFF;
                    CoolerSP.s = IPS_ALERT;
                    LOGF_WARN("Cannot manually activate cooler since current temperature is %.2f. To activate cooler, request a lower temperature.", TemperatureN[0].value);
                    IDSetSwitch(&CoolerSP, nullptr);
                    return true;
                }

                SetTemperature(0);
                return true;
            }

            return activateCooler(enabled);
        }
    }

    return INDI::CCD::ISNewSwitch(dev, name, states, names, n);
}