Ignore:
Timestamp:
08/20/19 12:33:46 (5 years ago)
Author:
tbretz
Message:
Automatically reload sources if source is not found in list. Print only changes to source list when reloading (when so far nothing was printed). Iplemented a PREPARE_GRB command which combines STOP and RELOAD_SOURCES for a small speed improvement.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/drivectrl.cc

    r19553 r19572  
    130130    double offset;
    131131    array<double, 2> angles;
     132
     133    bool operator!=(const Source &cmp)
     134    {
     135        return
     136            name      != cmp.name      ||
     137            ra        != cmp.ra        ||
     138            dec       != cmp.dec       ||
     139            mag       != cmp.mag       ||
     140            offset    != cmp.offset    ||
     141            angles[0] != cmp.angles[0] ||
     142            angles[1] != cmp.angles[1];
     143    }
    132144};
    133145
     
    20932105        const string name(ptr);
    20942106
    2095         const sources::const_iterator it = fSources.find(name);
    2096         if (it==fSources.end())
    2097         {
    2098             T::Error("Source '"+name+"' not found in list.");
    2099             throw uint32_t(T::GetCurrentState());
    2100         }
    2101 
    2102         return it;
     2107        sources::const_iterator it = fSources.find(name);
     2108        if (it!=fSources.end())
     2109            return it;
     2110
     2111        T::Warn("Source '"+name+"' not found in list... reloading database.");
     2112
     2113        ReloadSources();
     2114
     2115        it = fSources.find(name);
     2116        if (it!=fSources.end())
     2117            return it;
     2118
     2119        T::Error("Source '"+name+"' still not found in list.");
     2120        throw uint32_t(T::GetCurrentState());
    21032121    }
    21042122
     
    22372255    }
    22382256
    2239     int StopMovement()
     2257    int StopMovement(bool reload=false)
    22402258    {
    22412259        fDrive.SetAcceleration(fAccMax);
     
    22452263
    22462264        fDrive.UpdateSource(Time(), "", false);
     2265
     2266        if (reload)
     2267            ReloadSources();
    22472268
    22482269        return State::kStopping;
     
    29052926
    29062927        T::AddEvent("STOP")(State::kUnavailable)(State::kAvailable)(State::kArmed)(State::kInitialized)(State::kStopping)(State::kParking)(State::kMoving)(State::kApproaching)(State::kTracking)(State::kOnTrack)
    2907             (bind(&StateMachineDrive::StopMovement, this))
     2928            (bind(&StateMachineDrive::StopMovement, this, false))
    29082929            ("Stop any kind of movement.");
     2930
     2931        T::AddEvent("PREPARE_GRB")(State::kUnavailable)(State::kAvailable)(State::kArmed)(State::kInitialized)(State::kStopping)(State::kParking)(State::kMoving)(State::kApproaching)(State::kTracking)(State::kOnTrack)
     2932            (bind(&StateMachineDrive::StopMovement, this, true))
     2933            ("Combines STOP and RELOAD_SOURCES");
    29092934
    29102935        T::AddEvent("RESET", State::kPositioningFailed, State::kAllowedRangeExceeded, State::kInvalidCoordinates, State::kHardwareWarning)
     
    29953020        const mysqlpp::StoreQueryResult res =
    29963021            db.query("SELECT fSourceName, fRightAscension, fDeclination, fWobbleOffset, fWobbleAngle0, fWobbleAngle1, fMagnitude FROM Source").store();
     3022
     3023        auto old = fSources;
    29973024
    29983025        fSources.clear();
     
    30113038            AddSource(name, src);
    30123039
    3013             if (!print)
    3014                 continue;
    3015 
    30163040            ostringstream msg;
    30173041            msg << " " << name << setprecision(8) << ":   Ra=" << src.ra << "h Dec=" << src.dec << "deg";
    30183042            msg << " Wobble=[" << src.offset << "," << src.angles[0] << "," << src.angles[1] << "] Mag=" << src.mag;
    3019             T::Message(msg);
     3043
     3044            const auto it = old.find(name);
     3045            if (it==old.end())
     3046               T::Message(" +"+msg.str());
     3047            else
     3048            {
     3049                if (print || it->second!=src)
     3050                {
     3051                   T::Message(" c"+msg.str());
     3052                   old.erase(it);
     3053                }
     3054            }
     3055        }
     3056
     3057        for (auto it=old.begin(); it!=old.end(); it++)
     3058        {
     3059            const auto &src = it->second;
     3060
     3061            ostringstream msg;
     3062            msg << " - " << it->first << setprecision(8) << ":   Ra=" << src.ra << "h Dec=" << src.dec << "deg";
     3063            msg << " Wobble=[" << src.offset << "," << src.angles[0] << "," << src.angles[1] << "] Mag=" << src.mag;
     3064            T::Message(msg.str());
    30203065        }
    30213066#else
Note: See TracChangeset for help on using the changeset viewer.