Changeset 18408


Ignore:
Timestamp:
01/06/16 12:38:37 (9 years ago)
Author:
tbretz
Message:
Added PFmini and some new alarms
File:
1 edited

Legend:

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

    r18374 r18408  
    88
    99#include <sys/stat.h> //for file stats
     10#include <sys/statvfs.h> //for file statvfs
    1011
    1112#include "Dim.h"
     
    3334#include "HeadersDrive.h"
    3435#include "HeadersPower.h"
     36#include "HeadersPFmini.h"
    3537#include "HeadersAgilent.h"
    3638#include "HeadersFeedback.h"
     
    552554
    553555    float fFscControlHumidityAvg;
     556
     557    deque<float> fPfMiniHumidityHist;
     558    deque<float> fPfMiniTemperatureHist;
    554559
    555560    deque<float> fTemperatureControlHist;
     
    631636    DimDescribedState fDimFadControl;
    632637    DimDescribedState fDimFscControl;
     638    DimDescribedState fDimPfMiniControl;
    633639    DimDescribedState fDimGpsControl;
    634640    DimDescribedState fDimSqmControl;
     
    19031909
    19041910        fFscControlHumidityAvg = num>0 ? avg/num : 0;
     1911
     1912        return GetCurrentState();
     1913    }
     1914
     1915    int HandlePfMiniData(const EventImp &d)
     1916    {
     1917        if (!CheckDataSize(d, "PfMini:Data", sizeof(PFmini::Data)))
     1918            return GetCurrentState();
     1919
     1920        const PFmini::Data &data = d.Ref<PFmini::Data>();
     1921
     1922        ostringstream out;
     1923
     1924        out << fixed << setprecision(1);
     1925        out << d.GetJavaDate() << '\n';
     1926
     1927        out << HTML::kGreen << '\t' << data.temp << '\n';
     1928        out << HTML::kGreen << '\t' << data.hum  << '\n';
     1929
     1930        ofstream(fPath+"/pfmini.data") << out.str();
     1931
     1932        fPfMiniTemperatureHist.push_back(data.temp);
     1933        if (fPfMiniTemperatureHist.size()>60*4) // 1h
     1934            fPfMiniTemperatureHist.pop_front();
     1935
     1936        fPfMiniHumidityHist.push_back(data.hum);
     1937        if (fPfMiniHumidityHist.size()>60*4) // 1h
     1938            fPfMiniHumidityHist.pop_front();
     1939
     1940        WriteHist(d, "hist-pfmini-temp",
     1941                  fPfMiniTemperatureHist, 45, 0);
     1942
     1943        WriteHist(d, "hist-pfmini-hum",
     1944                  fPfMiniHumidityHist, 100, 0);
    19051945
    19061946        return GetCurrentState();
     
    25692609        // ==============================================================
    25702610
     2611        bool reqscript = false;
     2612
     2613#ifdef HAVE_SQL
     2614        try
     2615        {
     2616            const string query = Tools::Form("SELECT COUNT(*) FROM calendar.Data WHERE NOT u LIKE 'moon' AND y=%d AND m=%d AND d=%d",
     2617                                             now.NightAsInt()/10000, (now.NightAsInt()/100)%100-1, now.NightAsInt()%100);
     2618
     2619            const mysqlpp::StoreQueryResult res = Database(fDatabase).query(query).store();
     2620
     2621            const uint32_t cnt = res[0][0];
     2622
     2623            reqscript = cnt>0 && fSun.state>=2 && fSun.state<=6;
     2624        }
     2625        catch (const exception &e)
     2626        {
     2627            Out() << e.what() << endl;
     2628        }
     2629#endif
     2630        // ==============================================================
     2631
     2632        struct statvfs vfs;
     2633        statvfs("/daq", &vfs);
     2634
     2635        const uint64_t freedaq = vfs.f_bsize*vfs.f_bavail;
     2636
     2637        // ==============================================================
     2638
    25712639        const bool data_taking =
    25722640            fDimMcp.state()==MCP::State::kTriggerOn ||
     
    25962664                           "<b>datalogger not ready</b>");
    25972665
     2666        newerr |= SetError(fDimControl.state()!=3 && reqscript,
     2667                           "<b>No script running during datataking time.</b>");
     2668
    25982669        //newerr |= SetError(fDimDriveControl.state()==Drive::State::kLocked,
    25992670        //                   "<b><#darkred>Drive in LOCKED state, drive was automatically parked</#></b>");
     
    26222693                           "Average camera humidity exceed 60%");
    26232694
     2695        newerr |= SetError(!fPfMiniHumidityHist.empty() && fPfMiniHumidityHist.back()>40,
     2696                           "Camera humidity inside camera exceeds 40% (PFmini)");
     2697        newerr |= SetError(!fTemperatureControlHist.empty() && (fTemperatureControlHist.back()<26.5 || fTemperatureControlHist.back()>29),
     2698                           "Container temperature outside [26.5;29]&deg;C");
     2699
    26242700        newerr |= SetError(!fMagicWeatherHist[kHum].empty() && fMagicWeatherHist[kHum].back()>98 && fDimLidControl.state()==Lid::State::kOpen,
    26252701                           "Outside humidity exceeds 98% while lid is open");
     
    26502726
    26512727        newerr |= SetError(fFreeSpace<50000000000,
    2652                            "Less than 50GB disk space left.");
     2728                           "Less than 50GB disk space left on newdaq.");
     2729
     2730        newerr |= SetError(freedaq<80000000000,
     2731                           "Less than 80GB disk space left on daq.");
    26532732
    26542733        newerr |= SetError(fDimPwrControl.state()==Power::State::kCoolingFailure,
     
    30553134            out << GetStateHtml(fDimRateControl,    RateControl::State::kConnected);
    30563135            out << GetStateHtml(fDimFscControl,     FSC::State::kConnected);
     3136            out << GetStateHtml(fDimPfMiniControl,  PFmini::State::kConnected);
    30573137            out << GetStateHtml(fDimGpsControl,     GPS::State::kConnected);
    30583138            out << GetStateHtml(fDimSqmControl,     SQM::State::kConnected);
     
    30793159
    30803160            out << col << '\t' << Tools::Scientific(fFreeSpace) << "B\n";
     3161
     3162            col = HTML::kRed;
     3163            if (freedaq>uint64_t(199999999999))
     3164                col = HTML::kYellow;
     3165            if (freedaq>uint64_t(999999999999))
     3166                col = HTML::kGreen;
     3167            if (freedaq==UINT64_MAX)
     3168                col = HTML::kWhite;
     3169
     3170            out << col << '\t' << Tools::Scientific(freedaq) << "B\n";
    30813171
    30823172            out << HTML::kGreen << '\t' << dt.str().substr(0, dt.str().length()-7) << '\n';
     
    31303220        fDimFadControl    ("FAD_CONTROL"),
    31313221        fDimFscControl    ("FSC_CONTROL"),
     3222        fDimPfMiniControl ("PFMINI_CONTROL"),
    31323223        fDimGpsControl    ("GPS_CONTROL"),
    31333224        fDimSqmControl    ("SQM_CONTROL"),
     
    31573248        fDimFadControl.Subscribe(*this);
    31583249        fDimFscControl.Subscribe(*this);
     3250        fDimPfMiniControl.Subscribe(*this);
    31593251        fDimGpsControl.Subscribe(*this);
    31603252        fDimSqmControl.Subscribe(*this);
     
    31943286        Subscribe("FSC_CONTROL/BIAS_TEMP")
    31953287            (bind(&StateMachineSmartFACT::HandleFscBiasTemp,         this, placeholders::_1));
     3288
     3289        Subscribe("PFMINI_CONTROL/DATA")
     3290            (bind(&StateMachineSmartFACT::HandlePfMiniData,          this, placeholders::_1));
    31963291
    31973292        Subscribe("GPS_CONTROL/NEMA")
Note: See TracChangeset for help on using the changeset viewer.