Ignore:
Timestamp:
06/01/12 12:08:39 (12 years ago)
Author:
tbretz
Message:
Added audio-support; renamed Astro to Sun
File:
1 edited

Legend:

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

    r14009 r14014  
    6969// ========================================================================
    7070
    71 class Astro
     71class Sun
    7272{
    7373public:
     
    8989
    9090    bool isday;
     91    bool visible;
    9192
    9293public:
    93     Astro(double lon, double lat, const Time &t=Time()) :  time(t)
     94    Sun() : time(Time::none)
     95    {
     96    }
     97    Sun(double lon, double lat, const Time &t=Time()) :  time(t)
    9498    {
    9599#ifdef HAVE_LIBNOVA
     
    107111
    108112        // Warning: return code of 1 means circumpolar and is not checked!
    109         //ln_get_lunar_rst        (JD-0.5, &observer,      &moon);
    110113        ln_get_solar_rst        (JD-0.5, &observer,      &sun_day);
    111114        ln_get_solar_rst_horizon(JD-0.5, &observer, - 6, &sun_civil);
     
    126129        const bool is_night = JD>sun_dark.set;
    127130
    128         //ln_get_lunar_rst        (JD+0.5, &observer,      &moon);
    129131        ln_get_solar_rst        (JD+0.5, &observer,      &sun_day);
    130132        ln_get_solar_rst_horizon(JD+0.5, &observer, - 6, &sun_civil);
     
    151153        // case 1: sun-rise to sun-set  |  is_day && !is_night | set /rise
    152154        // case 2: sun-set  to midnight |  is_day &&  is_night | rise/set
    153         /*
    154         if (is_day^is_night)
    155         {
    156             cout << "SunSet:  " << fSunSetDayTime  << endl;
    157             cout << "SunRise: " << fSunRiseDayTime << endl;
    158         }
    159         else
    160         {
    161             cout << "SunRise: " << fSunRiseDayTime << endl;
    162             cout << "SunSet:  " << fSunSetDayTime  << endl;
    163         }*/
    164155
    165156        isday = is_day^is_night;
     
    205196        case 7: case 8:  color = HTML::kGreen;   break;
    206197        }
     198
     199        visible = state>=3 && state<=5;
    207200#endif
    208201    }
     
    212205{
    213206public:
     207    Time time;
     208
    214209    double ra;
    215210    double dec;
     
    226221    string color;
    227222
    228     Time time;
     223    Moon() : time(Time::none)
     224    {
     225    }
    229226
    230227    Moon(double lon, double lat, const Time &t=Time()) : time(t)
     
    391388    deque<float> fRateScanDataHist[41];
    392389
    393     bool fSunIsVisible;
    394     bool fMoonIsVisible;
    395 
    396     Time fTimeOfCivilTwilight;
     390    Sun   fSun;
     391    Moon  fMoon;
     392
     393    //bool fSunIsVisible;
     394    //bool fMoonIsVisible;
     395    //Time fTimeOfCivilTwilight;
     396    //float fMoonPhase;
     397
     398    // --------------------------- File header ----------------------------
    397399
    398400    int fHasError;
     401
     402    Time   fAudioTime;
     403    string fAudioName;
     404
     405    string Header(const Time &d)
     406    {
     407        ostringstream msg;
     408        msg << d.JavaDate() << '\t' << fAudioTime.JavaDate() << '\t' << fAudioName;
     409        return msg.str();
     410    }
     411
     412    string Header(const EventImp &d)
     413    {
     414        return Header(d.GetTime());
     415    }
     416
     417    void SetAudio(const string &name)
     418    {
     419        fAudioName = name;
     420        fAudioTime = Time();
     421    }
    399422
    400423    // ------------- Initialize variables before the Dim stuff ------------
     
    531554        ostringstream out;
    532555        out << setprecision(3);
    533         out << d.GetJavaDate() << '\n';
     556        out << Header(d) << '\n';
    534557        out << HTML::kWhite << '\t';
    535558
     
    562585        if (d.GetQoS()==-2 && fDimControl.scriptdepth==0)
    563586            fControlMessageHist.clear();
     587
     588        // Not that this will also "ding" just after program startup
     589        // if the dimctrl is still in state -3
     590        if (d.GetQoS()==-3 && fDimControl.scriptdepth==0)
     591            SetAudio("ding");
    564592
    565593        if (d.GetQoS()>=0)
     
    589617        }
    590618
     619        if (fMcpConfigurationState==MCP::State::kTakingData && d.GetQoS()==MCP::State::kIdle)
     620            SetAudio("sound_10");
     621
     622        if (fMcpConfigurationState==MCP::State::kTriggerOn && d.GetQoS()==MCP::State::kTakingData)
     623            SetAudio("losticks");
     624
    591625        fMcpConfigurationState     = d.GetQoS();
    592626        fMcpConfigurationMaxTime   = d.Get<uint64_t>();
     
    594628        fMcpConfigurationName      = d.Ptr<char>(16);
    595629
    596         if (d.GetQoS()==12)
     630        if (d.GetQoS()==MCP::State::kTakingData)
    597631            fMcpConfigurationRunStart = Time();
    598632
     
    643677        //const uint16_t idx = uint16_t(floor(fmod(fMagicWeatherHist[kDir].back()/22.5+360+11.25, 360)/22.5))%16;
    644678
    645         Astro astro(-(17.+53./60+26.525/3600), 28.+45./60+42.462/3600);
    646         Moon  moon (-(17.+53./60+26.525/3600), 28.+45./60+42.462/3600);
     679        Sun  sun (-(17.+53./60+26.525/3600), 28.+45./60+42.462/3600);
     680        Moon moon(-(17.+53./60+26.525/3600), 28.+45./60+42.462/3600);
    647681
    648682        ostringstream out;
    649683        out << d.GetJavaDate() << '\n';
    650         out << astro.color << '\t' << astro.description << '\n';
     684        out << sun.color << '\t' << sun.description << '\n';
    651685        out << setprecision(2);
    652         out << (astro.isday?HTML::kWhite:moon.color) << '\t' << moon.description << '\n';
     686        out << (sun.isday?HTML::kWhite:moon.color) << '\t' << moon.description << '\n';
    653687        out << setprecision(3);
    654688        for (int i=0; i<6; i++)
     
    661695            out << "\t\n";
    662696
    663         fSunIsVisible = astro.state>=3 && astro.state<=5;
    664         fMoonIsVisible = !fSunIsVisible && moon.visible;
    665 
    666         fTimeOfCivilTwilight = astro.fSunSetCivil;
     697        fSun  = sun;
     698        fMoon = moon;
    667699
    668700        ofstream(fPath+"/weather.data") << out.str();
    669701
    670702        out.str("");
    671         out << astro.time.JavaDate() << '\n';
    672         out << HTML::kWhite << '\t' << astro.fSunRiseDarkTime.GetAsStr("%H:%M") << '\n';
    673         out << HTML::kWhite << '\t' << astro.fSunRiseAstronomical.GetAsStr("%H:%M") << '\n';
    674         out << HTML::kWhite << '\t' << astro.fSunRiseCivil.GetAsStr("%H:%M") << '\n';
    675         out << HTML::kWhite << '\t' << astro.fSunRiseDayTime.GetAsStr("%H:%M") << '\n';
    676 
    677         out << HTML::kWhite << '\t' << astro.fSunSetDayTime.GetAsStr("%H:%M") << '\n';
    678         out << HTML::kWhite << '\t' << astro.fSunSetCivil.GetAsStr("%H:%M") << '\n';
    679         out << HTML::kWhite << '\t' << astro.fSunSetAstronomical.GetAsStr("%H:%M") << '\n';
    680         out << HTML::kWhite << '\t' << astro.fSunSetDarkTime.GetAsStr("%H:%M") << '\n';
     703        out << sun.time.JavaDate() << '\n';
     704        out << HTML::kWhite << '\t' << sun.fSunRiseDarkTime.GetAsStr("%H:%M") << '\n';
     705        out << HTML::kWhite << '\t' << sun.fSunRiseAstronomical.GetAsStr("%H:%M") << '\n';
     706        out << HTML::kWhite << '\t' << sun.fSunRiseCivil.GetAsStr("%H:%M") << '\n';
     707        out << HTML::kWhite << '\t' << sun.fSunRiseDayTime.GetAsStr("%H:%M") << '\n';
     708
     709        out << HTML::kWhite << '\t' << sun.fSunSetDayTime.GetAsStr("%H:%M") << '\n';
     710        out << HTML::kWhite << '\t' << sun.fSunSetCivil.GetAsStr("%H:%M") << '\n';
     711        out << HTML::kWhite << '\t' << sun.fSunSetAstronomical.GetAsStr("%H:%M") << '\n';
     712        out << HTML::kWhite << '\t' << sun.fSunSetDarkTime.GetAsStr("%H:%M") << '\n';
    681713
    682714        out << HTML::kWhite << '\t' << moon.fMoonRise.GetAsStr("%H:%M") << '\n';
     
    15901622        Time now;
    15911623        if (now-fLastUpdate<boost::posix_time::seconds(1))
    1592             return kStateRunning;
     1624            return fDimDNS.online() ? kStateRunning : kStateDimNetworkNA;
    15931625
    15941626        fLastUpdate=now;
     
    16751707
    16761708        ostringstream out;
    1677         out << now.JavaDate() << '\t' << haserror << '\t' << (fDimControl.state()>-3) << '\n';
     1709        out << Header(now) << '\t' << haserror << '\t' << (fDimControl.state()>-3) << '\n';
    16781710        out << setprecision(3);
    16791711        out << HTML::kWhite << '\t' << msg.str() << '\n';
     
    16901722
    16911723        out.str("");
    1692         out << now.JavaDate() << '\t' << fHasError << '\t' << (fDimControl.state()>-3) << '\n';
     1724        out << Header(now) << '\t' << fHasError << '\t' << (fDimControl.state()>-3) << '\n';
    16931725        out << setprecision(3);
    16941726
     
    17181750            const bool other =
    17191751                fDimRateControl.state()==RateControl::State::kSettingGlobalThreshold ||
    1720                 fDimRateScan.state()!=RateScan::State::kInProgress;
     1752                fDimRateScan.state()==RateScan::State::kInProgress;
    17211753
    17221754            if (other)
     
    18451877        else
    18461878            out << HTML::kWhite << '\t';
    1847         if (fSunIsVisible)
    1848         {
    1849             out << " &#9788;";
    1850             if (fTimeOfCivilTwilight.IsValid() && fDimDriveControl.state()<Drive::State::kArmed)
    1851                 out << " [" << fTimeOfCivilTwilight.MinutesTo() << "]";
    1852         }
    1853         else
    1854             if (fMoonIsVisible)
    1855                 out << " &#9790;";
    1856         out << '\n';
     1879        if (fSun.time.IsValid() && fMoon.time.IsValid())
     1880        {
     1881            if (fSun.visible)
     1882            {
     1883                out << " &#9788;";
     1884                if (fDimDriveControl.state()<Drive::State::kArmed)
     1885                    out << " [" << fSun.fSunSetCivil.MinutesTo() << "&darr;]";
     1886            }
     1887            else
     1888                if (!fSun.visible && fMoon.visible)
     1889                {
     1890                    out << " &#9790;";
     1891                    if (fDimDriveControl.state()<Drive::State::kArmed)
     1892                        out << " [" << fMoon.disk << "%]";
     1893                }
     1894            out << '\n';
     1895        }
    18571896
    18581897        // ------------------- FSC ------------------
     
    19762015
    19772016        out.str("");
    1978         out << now.JavaDate() << '\t' << fHasError << '\t' << (fDimControl.state()>-3) << '\n';
     2017        out << Header(now) << '\t' << fHasError << '\t' << (fDimControl.state()>-3) << '\n';
    19792018
    19802019        if (!fDimDNS.online())
     
    20312070        fRateScanDataId(0),
    20322071        fRateScanBoard(0),
    2033         fSunIsVisible(true),
    2034         fMoonIsVisible(false),
    2035         fTimeOfCivilTwilight(Time::none),
    20362072        fHasError(2),
    20372073        // ---
Note: See TracChangeset for help on using the changeset viewer.