Ignore:
Timestamp:
10/24/12 10:34:39 (12 years ago)
Author:
tbretz
Message:
Some adaptions of class names and other stuff.
File:
1 edited

Legend:

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

    r14451 r14514  
    2626using namespace std;
    2727
    28 class ConnectionLid : public Connection
     28class ConnectionInterlock : public Connection
    2929{
    3030protected:
    3131
    32     struct Lid
    33     {
    34         bool fc_ok;
    35         bool bp_on;
    36         bool il_on;
    37         bool fl_ok;
    38         bool fp_en;
    39         bool x_on;
    40         bool y_on;
    41         bool z_on;
    42 
    43         Lid() { }
     32    struct Status
     33    {
     34        bool fWaterFlowOk;
     35        bool fWaterLevelOk;
     36
     37        bool fPwrBiasOn;
     38        bool fPwr24VOn;
     39        bool fPwrPumpOn;
     40        bool fPwrDriveOn;
     41
     42        bool fDriveMainSwitchOn;
     43        bool fDriveFeedbackOn;
     44
     45        Status() { }
     46
     47        bool Set(bool &rc, const QString &value)
     48        {
     49            rc = value.toInt();
     50            return true;
     51        }
    4452
    4553        bool Set(const QDomNamedNodeMap &map)
    4654        {
    47             if (!map.contains("id") || !map.contains("value"))
     55            if (!map.contains("id") || !map.contains("title"))
    4856                return false;
    4957
    5058            QString item  = map.namedItem("id").nodeValue();
    51             QString value = map.namedItem("value").nodeValue();
    52 
    53             if (item==(QString("FC_OK")))
    54             {
    55                 fc_ok = value.toInt();
    56                 return true;
    57             }
    58 
    59             if (item==(QString("BP_ON")))
    60             {
    61                 bp_on = value.toInt();
    62                 return true;
    63             }
    64 
    65             if (item==(QString("IL_ON")))
    66             {
    67                 il_on = value.toInt();
    68                 return true;
    69             }
    70 
    71             if (item==(QString("FL_OK")))
    72             {
    73                 fl_ok = value.toInt();
    74                 return true;
    75             }
    76 
    77             if (item==(QString("FP_EN")))
    78             {
    79                 fp_en = value.toInt();
    80                 return true;
    81             }
    82 
    83             if (item==(QString("X_ON")))
    84             {
    85                 x_on = value.toInt();
    86                 return true;
    87             }
    88 
    89             if (item==(QString("Y_ON")))
    90             {
    91                 y_on = value.toInt();
    92                 return true;
    93             }
    94 
    95             if (item==(QString("Z_ON")))
    96             {
    97                 z_on = value.toInt();
    98                 return true;
    99             }
     59            QString value = map.namedItem("title").nodeValue();
     60
     61            if (item==(QString("flow_meter")))
     62                return Set(fWaterFlowOk, value);
     63
     64            if (item==(QString("level")))
     65                return Set(fWaterLevelOk, value);
     66
     67            if (item==(QString("bias_power")))
     68                return Set(fPwrBiasOn, value);
     69
     70            if (item==(QString("power_24v")))
     71                return Set(fPwr24VOn, value);
     72
     73            if (item==(QString("pump")))
     74                return Set(fPwrPumpOn, value);
     75
     76            if (item==(QString("drive_power")))
     77                return Set(fPwrDriveOn, value);
     78
     79            if (item==(QString("drive_on")))
     80                return Set(fDriveMainSwitchOn, value);
     81
     82            if (item==(QString("drive_enable")))
     83                return Set(fDriveFeedbackOn, value);
    10084
    10185            return false;
    10286        }
    10387
     88        void Print(ostream &out, const string &title, const bool &val, const string &t="enabled", const string &f="disabled")
     89        {
     90            out << setw(15) << (title+":");
     91            if (val)
     92                out << kGreen << t << endl;
     93            else
     94                out << kRed   << f << endl;
     95        }
     96
    10497        void Print(ostream &out)
    10598        {
    106             out << "FC_OK=" << fc_ok << endl;
    107             out << "BP_ON=" << bp_on << endl;
    108             out << "IL_ON=" << il_on << endl;
    109             out << "FL_OK=" << fl_ok << endl;
    110             out << "FP_EN=" << fp_en << endl;
    111             out << "X_ON =" << x_on  << endl;
    112             out << "Y_ON =" << y_on  << endl;
    113             out << "Z_ON =" << z_on  << endl;
     99            Print(out, "Water flow",     fWaterFlowOk,  "ok", "low");
     100            Print(out, "Water level",    fWaterLevelOk, "ok", "low");
     101            Print(out, "Power bias",     fPwrBiasOn);
     102            Print(out, "Power 24V",      fPwr24VOn);
     103            Print(out, "Power pump",     fPwrPumpOn);
     104            Print(out, "Power drive",    fPwrDriveOn);
     105            Print(out, "Drive main",     fDriveMainSwitchOn, "on", "off");
     106            Print(out, "Drive feedback", fDriveFeedbackOn,   "on", "off");
    114107        }
    115108
     
    130123    Time fLastReport;
    131124
    132     Lid fLid1;
    133 
    134     virtual void Update(const Lid &)
     125    Status fStatus;
     126
     127    virtual void Update(const Status &)
    135128    {
    136129    }
     
    224217            const QDomNamedNodeMap att = e.attributes();
    225218
    226             fLid1.Set(att);
     219            fStatus.Set(att);
    227220        }
    228221
    229222        if (fIsVerbose)
    230223        {
    231             fLid1.Print(Out());
     224            fStatus.Print(Out());
    232225            Out() << "------------------------------------------------------" << endl;
    233226        }
    234227
    235         Update(fLid1);
     228        Update(fStatus);
    236229
    237230        fRdfData = "";
     
    302295    {
    303296        async_read_some(ba::buffer(fArray),
    304                         boost::bind(&ConnectionLid::HandleRead, this,
     297                        boost::bind(&ConnectionInterlock::HandleRead, this,
    305298                                    dummy::error, dummy::bytes_transferred));
    306299    }
     
    374367
    375368public:
    376     ConnectionLid(ba::io_service& ioservice, MessageImp &imp) : Connection(ioservice, imp()),
     369    ConnectionInterlock(ba::io_service& ioservice, MessageImp &imp) : Connection(ioservice, imp()),
    377370        fIsVerbose(true), fLastReport(Time::none), fKeepAlive(ioservice)
    378371    {
     
    411404
    412405        fKeepAlive.expires_from_now(boost::posix_time::seconds(fInterval));
    413         fKeepAlive.async_wait(boost::bind(&ConnectionLid::HandleRequest,
     406        fKeepAlive.async_wait(boost::bind(&ConnectionInterlock::HandleRequest,
    414407                                          this, dummy::error));
    415408    }
     
    449442};
    450443
    451 const uint16_t ConnectionLid::kMaxAddr = 0xfff;
     444const uint16_t ConnectionInterlock::kMaxAddr = 0xfff;
    452445
    453446// ------------------------------------------------------------------------
     
    455448#include "DimDescriptionService.h"
    456449
    457 class ConnectionDimWeather : public ConnectionLid
     450class ConnectionDimWeather : public ConnectionInterlock
    458451{
    459452private:
     
    462455public:
    463456    ConnectionDimWeather(ba::io_service& ioservice, MessageImp &imp) :
    464         ConnectionLid(ioservice, imp)/*,
     457        ConnectionInterlock(ioservice, imp)/*,
    465458        fDim("PWR_CONTROL/DATA", "S:2;F:2;F:2",
    466459             "|status[bool]:Lid1/2 open or closed"
     
    470463    }
    471464
    472     void Update(const Lid &l1)
    473         {
     465    void Update(const Status &status)
     466    {
    474467            /*
    475468        struct DimData
     
    508501
    509502template <class T, class S>
    510 class StateMachineLidControl : public T, public ba::io_service, public ba::io_service::work
     503class StateMachinePowerControl : public T, public ba::io_service, public ba::io_service::work
    511504{
    512505private:
     
    594587
    595588public:
    596     StateMachineLidControl(ostream &out=cout) :
     589    StateMachinePowerControl(ostream &out=cout) :
    597590        T(out, "LID_CONTROL"), ba::io_service::work(static_cast<ba::io_service&>(*this)),
    598591        fLid(*this, *this)
     
    627620        // Verbosity commands
    628621        T::AddEvent("SET_VERBOSE", "B")
    629             (bind(&StateMachineLidControl::SetVerbosity, this, placeholders::_1))
     622            (bind(&StateMachinePowerControl::SetVerbosity, this, placeholders::_1))
    630623            ("set verbosity state"
    631624             "|verbosity[bool]:disable or enable verbosity for received data (yes/no), except dynamic data");
    632625
    633626        T::AddEvent("OPEN", Lid::State::kInconsistent, Lid::State::kClosed)
    634             (bind(&StateMachineLidControl::Open, this));
     627            (bind(&StateMachinePowerControl::Open, this));
    635628
    636629        T::AddEvent("CLOSE", Lid::State::kInconsistent, Lid::State::kOpen)
    637             (bind(&StateMachineLidControl::Close, this));
     630            (bind(&StateMachinePowerControl::Close, this));
    638631
    639632        T::AddEvent("POST", "C")
    640             (bind(&StateMachineLidControl::Post, this, placeholders::_1))
     633            (bind(&StateMachinePowerControl::Post, this, placeholders::_1))
    641634            ("set verbosity state"
    642635             "|verbosity[bool]:disable or enable verbosity for received data (yes/no), except dynamic data");
     
    664657int RunShell(Configuration &conf)
    665658{
    666     return Main::execute<T, StateMachineLidControl<S, R>>(conf);
     659    return Main::execute<T, StateMachinePowerControl<S, R>>(conf);
    667660}
    668661
     
    742735    {
    743736        if (conf.Get<bool>("no-dim"))
    744             return RunShell<LocalStream, StateMachine, ConnectionLid>(conf);
     737            return RunShell<LocalStream, StateMachine, ConnectionInterlock>(conf);
    745738        else
    746739            return RunShell<LocalStream, StateMachineDim, ConnectionDimWeather>(conf);
     
    750743    {
    751744        if (conf.Get<int>("console")==0)
    752             return RunShell<LocalShell, StateMachine, ConnectionLid>(conf);
     745            return RunShell<LocalShell, StateMachine, ConnectionInterlock>(conf);
    753746        else
    754             return RunShell<LocalConsole, StateMachine, ConnectionLid>(conf);
     747            return RunShell<LocalConsole, StateMachine, ConnectionInterlock>(conf);
    755748    }
    756749    else
Note: See TracChangeset for help on using the changeset viewer.