Ignore:
Timestamp:
03/30/17 13:06:59 (8 years ago)
Author:
(none)
Message:
lidctrl for 2017 version of lid-arduino firmware
Location:
branches/FACT++_lidctrl_new_eth/src
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/FACT++_lidctrl_new_eth/src/HeadersLid.h

    r18125 r18796  
    44namespace Lid
    55{
     6    enum motor_stop_reason_t{
     7        M_NO_REASON,
     8        M_OVERCURRENT,
     9        M_ZEROCURRENT,
     10        M_TIMEOUT,
     11        M_POSITION_REACHED,
     12        M_USER_INTERUPT,
     13    };
     14
     15    struct MotorReport
     16    {
     17        int8_t motor_id;
     18        int32_t duration_in_ms;
     19        motor_stop_reason_t stop_reason;
     20        std::vector<int> current;
     21        std::vector<int> position;
     22    };
     23
     24    void to_json(nlohmann::json& j, const MotorReport& r) {
     25        j = nlohmann::json{
     26            {"motor_id", r.motor_id},
     27            {"duration[ms]", r.duration_in_ms},
     28            {"motor_stop_reason", {
     29                {"motor_stop_id", r.stop_reason}
     30            }},
     31            {"current", r.current},
     32            {"position", r.position}
     33        };
     34    }
     35
     36    void from_json(const nlohmann::json& j, MotorReport& r) {
     37        r.motor_id = j.at("motor_id");
     38        r.duration_in_ms = j.at("duration[ms]");
     39        r.stop_reason = j.at("motor_stop_reason").at("motor_stop_id");
     40        r.current = j.at("current").get<std::vector<int> >();
     41        r.position = j.at("position").get<std::vector<int> >();
     42    }
     43
     44    struct DimMotorReport
     45    {
     46        int32_t motor_id;
     47        int32_t duration_in_ms;
     48        int32_t stop_reason;
     49        int32_t current[100];
     50        int32_t position[100];
     51
     52        DimMotorReport(const MotorReport& mr){
     53            motor_id = mr.motor_id;
     54            duration_in_ms = mr.duration_in_ms;
     55            stop_reason = mr.stop_reason;
     56            // init with -1
     57            for (size_t i=0; i<100; i++){
     58                current[i] = -1;
     59                position[i] = -1;
     60            }
     61            for (size_t i=0; i<mr.current.size(); i++){
     62                current[i] = mr.current[i];
     63            }
     64            for (size_t i=0; i<mr.position.size(); i++){
     65                position[i] = mr.position[i];
     66            }
     67        }
     68    }__attribute__((__packed__));
     69
    670    namespace State
    771    {
    872        enum states_t
    973        {
    10             kDisconnected = 1,
    11             kConnected,
    12             kUnidentified,
    13             kInconsistent,
     74            kClosed,
     75            kClosing,
     76            kFailClose,
     77            kOpen,
     78            kOpening,
     79            kFailOpen,
    1480            kUnknown,
    15             kPowerProblem,
    16             kOvercurrent,
    17             kClosed,
    18             kOpen,
    19             kMoving,
    20             kLocked
     81            kDisconnected,
     82            kConnected
    2183        };
    22     };
    23 };
     84    }
     85}
     86
    2487#endif
  • branches/FACT++_lidctrl_new_eth/src/lidctrl.cc

    r18125 r18796  
    1818
    1919#include "tools.h"
    20 
     20#include "json.hpp"
     21using json = nlohmann::json;
    2122#include "HeadersLid.h"
    2223
     
    2930class ConnectionLid : public Connection
    3031{
    31 protected:
    32 
    33     struct Lid
    34     {
    35         int id;
    36 
    37         float position;
    38         float current;
    39         string status;
    40 
    41         Lid(int i) : id(i) { }
    42 
    43         bool Set(const QDomNamedNodeMap &map)
    44         {
    45             if (!map.contains("id") || !map.contains("value"))
    46                 return false;
    47 
    48             QString item  = map.namedItem("id").nodeValue();
    49             QString value = map.namedItem("value").nodeValue();
    50 
    51             const char c = '0'+id;
    52 
    53             if (item==(QString("cur")+c))
    54             {
    55                 current = value.toFloat();
    56                 return true;
    57             }
    58 
    59             if (item==(QString("pos")+c))
    60             {
    61                 position = value.toFloat();
    62                 return true;
    63             }
    64 
    65             if (item==(QString("lid")+c))
    66             {
    67                 status = value.toStdString();
    68                 return true;
    69             }
    70 
    71             return false;
    72         }
    73 
    74         void Print(ostream &out)
    75         {
    76             out << "Lid" << id << " @ " << position << " / " << current << "A [" << status << "]" << endl;
    77         }
    78 
    79     };
    80 
    8132private:
    8233    uint16_t fInterval;
    83 
    8434    bool fIsVerbose;
    85 
    86     string fSite;
    87     string fRdfData;
    88 
    89     boost::array<char, 4096> fArray;
    90 
    91     string fNextCommand;
    92 
     35    boost::asio::streambuf fBuffer;
    9336    Time fLastReport;
    9437
    95     Lid fLid1;
    96     Lid fLid2;
    97 
    98     virtual void Update(const Lid &, const Lid &)
    99     {
    100     }
    101 
    102 
    103     void ProcessAnswer()
    104     {
    105         if (fIsVerbose)
    106         {
    107             Out() << "------------------------------------------------------" << endl;
    108             Out() << fRdfData << endl;
    109             Out() << "------------------------------------------------------" << endl;
    110         }
    111 
    112         fRdfData.insert(0, "<?xml version=\"1.0\"?>\n");
    113 
    114         QDomDocument doc;
    115         if (!doc.setContent(QString(fRdfData.c_str()), false))
    116         {
    117             Warn("Parsing of html failed.");
    118             return;
    119         }
    120 
    121         if (fIsVerbose)
    122         {
    123             Out() << "Parsed:\n-------\n" << doc.toString().toStdString() << endl;
    124             Out() << "------------------------------------------------------" << endl;
    125         }
    126 
    127         const QDomNodeList imageElems = doc.elementsByTagName("span"); // "input"
    128 
    129         /*
    130         // elementById
    131         for (unsigned int i=0; i<imageElems.length(); i++)
    132         {
    133             QDomElement e = imageElems.item(i).toElement();
    134             Out() << "<" << e.tagName().toStdString() << " ";
    135 
    136             QDomNamedNodeMap att = e.attributes();
    137 
    138             for (int j=0; j<att.size(); j++)
    139             {
    140                 Out() << att.item(j).nodeName().toStdString() << "=";
    141                 Out() << att.item(j).nodeValue().toStdString() << " ";
    142             }
    143             Out() << "> " << e.text().toStdString() << endl;
    144         }*/
    145 
    146         for (unsigned int i=0; i<imageElems.length(); i++)
    147         {
    148             const QDomElement e = imageElems.item(i).toElement();
    149 
    150             const QDomNamedNodeMap att = e.attributes();
    151 
    152             fLid1.Set(att);
    153             fLid2.Set(att);
    154         }
    155 
    156         if (fIsVerbose)
    157         {
    158             fLid1.Print(Out());
    159             fLid2.Print(Out());
    160             Out() << "------------------------------------------------------" << endl;
    161         }
    162 
    163         Update(fLid1, fLid2);
    164 
    165         fRdfData = "";
    166 
    167         if ((fLid1.status!="Open" && fLid1.status!="Closed" && fLid1.status!="Power Problem" && fLid1.status!="Unknown" && fLid1.status!="Overcurrent") ||
    168             (fLid2.status!="Open" && fLid2.status!="Closed" && fLid2.status!="Power Problem" && fLid2.status!="Unknown" && fLid1.status!="Overcurrent"))
    169             Warn("Lid reported status unknown by lidctrl ("+fLid1.status+"/"+fLid2.status+")");
    170 
    171         fLastReport = Time();
    172     }
     38    Lid::State::states_t fArduinoState;
     39
     40    virtual void UpdateControllerState(){}
     41    virtual void UpdateMotorReport(Lid::MotorReport& report){}
    17342
    17443    void HandleRead(const boost::system::error_code& err, size_t bytes_received)
     
    17948            if (err==ba::error::eof)
    18049            {
    181                 //Warn("Connection closed by remote host.");
    182                 ProcessAnswer();
    183                 PostClose(false);
     50                Warn("Connection closed by remote host.");
     51                PostClose(true);
    18452                return;
    18553            }
     
    19765            PostClose(err!=ba::error::basic_errors::operation_aborted);
    19866
    199             fRdfData = "";
    20067            return;
    20168        }
    20269
    203         fRdfData += string(fArray.data(), bytes_received);
    204 
    205         //cout << "." << flush;
    206 
    207         // Does the message contain a header?
    208         const size_t p1 = fRdfData.find("\r\n\r\n");
    209         if (p1!=string::npos)
    210         {
    211             // Does the answer also contain the body?
    212             const size_t p2 = fRdfData.find("\r\n\r\n", p1+4);
    213             if (p2!=string::npos)
    214             {
    215                 ProcessAnswer();
    216             }
    217         }
    218 
    219         // Go on reading until the web-server closes the connection
     70        std::string fRdfData((std::istreambuf_iterator<char>(&fBuffer)),
     71               std::istreambuf_iterator<char>());
     72
     73        json j;
     74        try
     75        {
     76            j = json::parse(fRdfData);
     77            if (fIsVerbose) Out() << j << endl;
     78        }
     79        catch(std::invalid_argument)
     80        {
     81            if (fIsVerbose) Out() << "invalid JSON found" << endl;
     82            if (fIsVerbose) Out() << fRdfData << endl;
     83            j = json::parse("{}");
     84        }
     85
     86        try
     87        {
     88            fArduinoState = static_cast<Lid::State::states_t>(
     89                j["state"]["state_id"].get<int>()
     90            );
     91            UpdateControllerState();
     92        }
     93        catch(std::domain_error){
     94            if (fIsVerbose) Out() << "j is not ControllerState:" << j << endl;
     95        }
     96
     97        try
     98        {
     99            Lid::MotorReport motor_report = j;
     100            UpdateMotorReport(motor_report);
     101        }
     102        catch(std::domain_error){
     103            if (fIsVerbose) Out() << "j is not MotorReport:" << j << endl;
     104        }
     105
     106        //Update();
     107        fLastReport = Time();
    220108        StartReadReport();
    221109    }
    222110
    223     boost::asio::streambuf fBuffer;
    224 
    225111    void StartReadReport()
    226112    {
    227         async_read_some(ba::buffer(fArray),
    228                         boost::bind(&ConnectionLid::HandleRead, this,
    229                                     dummy::error, dummy::bytes_transferred));
    230     }
    231 
    232     boost::asio::deadline_timer fKeepAlive;
    233 
    234     void PostRequest(string cmd, const string &args="")
    235     {
    236         cmd += " "+fSite+" HTTP/1.1\r\n"
    237             //"Connection: Keep-Alive\r\n"
    238             ;
    239 
    240         ostringstream msg;
    241         msg << args.length();
    242 
    243         cmd += "Content-Length: ";
    244         cmd += msg.str();
    245         cmd +="\r\n";
    246 
    247         if (args.length()>0)
    248             cmd += "\r\n"+args + "\r\n";
    249 
    250         cmd += "\r\n";
    251 
    252         //cout << "Post: " << cmd << endl;
    253         PostMessage(cmd);
    254     }
    255 
    256     void HandleRequest(const bs::error_code &error)
    257     {
    258         // 125: Operation canceled (bs::error_code(125, bs::system_category))
    259         if (error && error!=ba::error::basic_errors::operation_aborted)
    260         {
    261             ostringstream str;
    262             str << "Write timeout of " << URL() << ": " << error.message() << " (" << error << ")";// << endl;
    263             Error(str);
    264 
    265             PostClose(false);
    266             return;
    267         }
    268 
    269         if (!is_open())
    270         {
    271             // For example: Here we could schedule a new accept if we
    272             // would not want to allow two connections at the same time.
    273             PostClose(true);
    274             return;
    275         }
    276 
    277         // Check whether the deadline has passed. We compare the deadline
    278         // against the current time since a new asynchronous operation
    279         // may have moved the deadline before this actor had a chance
    280         // to run.
    281         if (fKeepAlive.expires_at() > ba::deadline_timer::traits_type::now())
    282             return;
    283 
    284         Request();
    285     }
    286 
    287 
    288 private:
     113        ba::async_read_until(
     114            *this,
     115            fBuffer,
     116            '\n',
     117            boost::bind(
     118                &ConnectionLid::HandleRead,
     119                this,
     120                dummy::error,
     121                dummy::bytes_transferred
     122            )
     123        );
     124    }
     125
    289126    // This is called when a connection was established
    290127    void ConnectionEstablished()
    291128    {
    292         Request();
    293129        StartReadReport();
    294     }
    295 
    296     void ConnectionFailed()
    297     {
    298         StartConnect();
     130        PostMessage("s", 1);
    299131    }
    300132
    301133public:
    302     static const uint16_t kMaxAddr;
    303 
    304 public:
    305     ConnectionLid(ba::io_service& ioservice, MessageImp &imp) : Connection(ioservice, imp()),
    306         fIsVerbose(true), fLastReport(Time::none),
    307         fLid1(1), fLid2(2), fKeepAlive(ioservice)
     134    ConnectionLid(ba::io_service& ioservice, MessageImp &imp) :
     135        Connection(ioservice, imp()),
     136        fIsVerbose(true),
     137        fLastReport(Time::none),
     138        fArduinoState(Lid::State::states_t::kUnknown)
    308139    {
    309140        SetLogStream(&imp);
     
    321152    }
    322153
    323     void SetSite(const string &site)
    324     {
    325         fSite = site;
    326     }
    327 
    328     void Post(const string &post)
    329     {
    330         fNextCommand = post;
    331 
    332         fLid1.status = "";
    333         fLid2.status = "";
    334         //PostRequest("POST", post);
    335     }
    336 
    337     void Request()
    338     {
    339         PostRequest("POST", fNextCommand);
    340         fNextCommand = "";
    341 
    342         fKeepAlive.expires_from_now(boost::posix_time::seconds(fInterval));
    343         fKeepAlive.async_wait(boost::bind(&ConnectionLid::HandleRequest,
    344                                           this, dummy::error));
    345     }
    346 
    347154    int GetInterval() const
    348155    {
     
    350157    }
    351158
    352     int GetState() const
    353     {
    354         using namespace Lid;
    355 
    356         // Timeout
    357         if (fLastReport.IsValid() && fLastReport+boost::posix_time::seconds(fInterval*2)<Time())
    358             return State::kDisconnected;
    359 
    360         // Unidentified state detected
    361         if ((!fLid1.status.empty() && fLid1.status!="Open" && fLid1.status!="Closed" && fLid1.status!="Power Problem" && fLid1.status!="Unknown" && fLid1.status!="Overcurrent") ||
    362             (!fLid2.status.empty() && fLid2.status!="Open" && fLid2.status!="Closed" && fLid2.status!="Power Problem" && fLid2.status!="Unknown" && fLid2.status!="Overcurrent"))
    363             return State::kUnidentified;
    364 
    365         // This is an assumption, but the best we have...
    366         if (fLid1.status=="Closed" && fLid2.status=="Power Problem")
    367             return State::kClosed;
    368         if (fLid2.status=="Closed" && fLid1.status=="Power Problem")
    369             return State::kClosed;
    370         if (fLid1.status=="Open" && fLid2.status=="Power Problem")
    371             return State::kOpen;
    372         if (fLid2.status=="Open" && fLid1.status=="Power Problem")
    373             return State::kOpen;
    374 
    375         // Inconsistency
    376         if (fLid1.status!=fLid2.status)
    377             return State::kInconsistent;
    378 
    379         // Unknown
    380         if (fLid1.status=="Unknown")
    381             return State::kUnknown;
    382 
    383         // Power Problem
    384         if (fLid1.status=="Power Problem")
    385             return State::kPowerProblem;
    386 
    387         // Overcurrent
    388         if (fLid1.status=="Overcurrent")
    389             return State::kOvercurrent;
    390 
    391         // Closed
    392         if (fLid1.status=="Closed")
    393             return State::kClosed;
    394 
    395         // Open
    396         if (fLid1.status=="Open")
    397             return State::kOpen;
    398 
    399         return State::kConnected;
     159    Lid::State::states_t GetState()
     160    {
     161        return fArduinoState;
    400162    }
    401163};
    402164
    403 const uint16_t ConnectionLid::kMaxAddr = 0xfff;
    404 
    405165// ------------------------------------------------------------------------
    406166
    407167#include "DimDescriptionService.h"
    408168
    409 class ConnectionDimWeather : public ConnectionLid
     169class ConnectionDimLid : public ConnectionLid
    410170{
    411171private:
    412     DimDescribedService fDim;
     172    DimDescribedService fDimControllerState;
     173    DimDescribedService fDimMotorReport;
    413174
    414175public:
    415     ConnectionDimWeather(ba::io_service& ioservice, MessageImp &imp) :
     176    ConnectionDimLid(ba::io_service& ioservice, MessageImp &imp) :
    416177        ConnectionLid(ioservice, imp),
    417         fDim("LID_CONTROL/DATA", "S:2;F:2;F:2",
    418              "|status[bool]:Lid1/2 open or closed"
    419              "|I[A]:Lid1/2 current"
    420              "|P[dac]:Lid1/2 hall sensor position in averaged dac counts")
    421     {
    422     }
    423 
    424     void Update(const Lid &l1, const Lid &l2)
    425     {
    426         struct DimData
    427         {
    428             int16_t status[2];
    429             float   current[2];
    430             float   position[2];
    431 
    432             DimData() { status[0] = status[1] = -1; }
    433 
     178        fDimControllerState(
     179            "LID_CONTROL/CONTROLLER_STATE",
     180            "S",
     181            "|state[int]: arduino state id"
     182            ),
     183        fDimMotorReport(
     184            "LID_CONTROL/MOTOR",
     185            "I:1;I:1;I:1;I:100;I:100",
     186            "|id[byte]: motor id"
     187            "|duration[int32]: movement time in [ms]"
     188            "|stop_reason[byte]: Lid::motor_stop_reason_t"
     189            "|current[int32]: power drawn by motor [3.4mA]"
     190            "|position[int32]: position measured by hall sensor"
     191            )
     192
     193    {
     194    }
     195
     196    void UpdateControllerState()
     197    {
     198        struct DimControllerState
     199        {
     200            int16_t state;
    434201        } __attribute__((__packed__));
    435202
    436         DimData data;
    437 
    438         if (l1.status=="Unknown")
    439             data.status[0] = 3;
    440         if (l1.status=="Power Problem")
    441             data.status[0] = 2;
    442         if (l1.status=="Open")
    443             data.status[0] = 1;
    444         if (l1.status=="Closed")
    445             data.status[0] = 0;
    446 
    447         if (l2.status=="Unknown")
    448             data.status[1] = 3;
    449         if (l2.status=="Power Problem")
    450             data.status[1] = 2;
    451         if (l2.status=="Open")
    452             data.status[1] = 1;
    453         if (l2.status=="Closed")
    454             data.status[1] = 0;
    455 
    456         data.current[0]  = l1.current;
    457         data.current[1]  = l2.current;
    458 
    459         data.position[0] = l1.position;
    460         data.position[1] = l2.position;
    461 
    462         fDim.setQuality(GetState());
    463         fDim.Update(data);
     203        DimControllerState s;
     204        s.state = GetState();
     205        fDimControllerState.setQuality(GetState());
     206        fDimControllerState.Update(s);
     207    }
     208
     209    void UpdateMotorReport(Lid::MotorReport& report)
     210    {
     211        Lid::DimMotorReport dim_report(report);
     212        fDimMotorReport.setQuality(GetState());
     213        fDimMotorReport.Update(dim_report);
    464214    }
    465215};
     
    472222private:
    473223    S fLid;
    474     Time fLastCommand;
    475     Time fSunRise;
    476 
    477     uint16_t fTimeToMove;
    478224
    479225    bool CheckEventSize(size_t has, const char *name, size_t size)
     
    498244    }
    499245
    500     int Post(const EventImp &evt)
    501     {
    502         fLid.Post(evt.GetText());
     246    int Open()
     247    {
     248        fLid.PostMessage("o", 1);
    503249        return T::GetCurrentState();
    504250    }
    505251
    506     int Open()
    507     {
    508         fLastCommand = Time();
    509         fLid.Post("Button5=");
    510         return Lid::State::kMoving;
    511     }
     252    int RequestStatus()
     253    {
     254        fLid.PostMessage("s", 1);
     255        return T::GetCurrentState();
     256    }
     257
    512258    int Close()
    513259    {
    514         fLastCommand = Time();
    515         fLid.Post("Button6=");
    516         return Lid::State::kMoving;
    517 
    518     }
    519     /*
    520     int MoveMotor(const EventImp &evt, int mid)
    521     {
    522         if (!CheckEventSize(evt.GetSize(), "MoveMotor", 2))
    523             return T::kSM_FatalError;
    524 
    525         if (evt.GetUShort()>0xfff)
    526         {
    527             ostringstream msg;
    528             msg << "Position " << evt.GetUShort() << " for motor " << mid+1 << " out of range [0,1023].";
    529             T::Error(msg);
    530             return T::GetCurrentState();
    531         }
    532 
    533         fLid.MoveMotor(mid, evt.GetUShort());
    534 
     260        fLid.PostMessage("c", 1);
    535261        return T::GetCurrentState();
    536     }*/
    537 
    538     int Unlock()
     262    }
     263
     264    int Execute()
    539265    {
    540266        return fLid.GetState();
    541267    }
    542 
    543     int Execute()
    544     {
    545         const int rc = fLid.GetState();
    546         const int state = T::GetCurrentState();
    547 
    548         if (state==Lid::State::kMoving &&
    549             (rc==Lid::State::kConnected || rc==Lid::State::kDisconnected) &&
    550             fLastCommand+boost::posix_time::seconds(fTimeToMove+fLid.GetInterval()) > Time())
    551         {
    552             return Lid::State::kMoving;
    553         }
    554 
    555         const Time now;
    556         if (now>fSunRise)
    557         {
    558             if (state!=Lid::State::kClosed && state!=Lid::State::kLocked && state>Lid::State::kDisconnected)
    559             {
    560                 T::Error("Lidctrl not in 'Closed' at end of nautical twilight!");
    561                 Close();
    562             }
    563 
    564             fSunRise = now.GetNextSunRise(-6);
    565 
    566             ostringstream msg;
    567             msg << "During next sun-rise nautical twilight will end at " << fSunRise;
    568             T::Info(msg);
    569 
    570             return Lid::State::kLocked;
    571         }
    572 
    573         return rc==Lid::State::kConnected ? state : rc;
    574     }
    575 
    576268
    577269public:
    578270    StateMachineLidControl(ostream &out=cout) :
    579         StateMachineAsio<T>(out, "LID_CONTROL"), fLid(*this, *this),
    580         fSunRise(Time().GetNextSunRise(-6))
     271        StateMachineAsio<T>(out, "LID_CONTROL"), fLid(*this, *this)
    581272    {
    582273        // State names
     
    587278                     "Connection established, but status still not known");
    588279
    589         T::AddStateName(Lid::State::kUnidentified, "Unidentified",
    590                      "At least one lid reported a state which could not be identified by lidctrl");
    591 
    592         T::AddStateName(Lid::State::kInconsistent, "Inconsistent",
    593                      "Both lids show different states");
    594 
    595280        T::AddStateName(Lid::State::kUnknown, "Unknown",
    596                      "Arduino reports at least one lids in an unknown status");
    597 
    598         T::AddStateName(Lid::State::kPowerProblem, "PowerProblem",
    599                      "Arduino reports both lids to have a power problem (might also be that both are at the end switches)");
    600 
    601         T::AddStateName(Lid::State::kOvercurrent, "Overcurrent",
    602                      "Arduino reports both lids to have a overcurrent (might also be that both are at the end switches)");
     281                     "Arduino just restarted");
    603282
    604283        T::AddStateName(Lid::State::kClosed, "Closed",
     
    608287                     "Both lids are open");
    609288
    610         T::AddStateName(Lid::State::kMoving, "Moving",
    611                      "Lids are supposed to move, waiting for next status");
    612 
    613         T::AddStateName(Lid::State::kLocked, "Locked",
    614                         "Locked, no commands accepted except UNLOCK.");
    615 
     289        T::AddStateName(Lid::State::kClosing, "Closing",
     290                     "Lids are Closing");
     291
     292        T::AddStateName(Lid::State::kFailClose, "FailClose",
     293                     "Closing failed: timeout?|user_interrupt?");
     294
     295        T::AddStateName(Lid::State::kOpening, "Opening",
     296                     "Lids are Opening");
     297
     298        T::AddStateName(Lid::State::kFailOpen, "FailOpen",
     299                     "Opening failed: timeout?|user_interrupt?|overcurrent?");
    616300
    617301        // Verbosity commands
     
    621305             "|verbosity[bool]:disable or enable verbosity for received data (yes/no), except dynamic data");
    622306
    623         T::AddEvent("OPEN", Lid::State::kUnidentified, Lid::State::kInconsistent, Lid::State::kUnknown, Lid::State::kPowerProblem, Lid::State::kClosed)
     307        T::AddEvent("OPEN")
    624308            (bind(&StateMachineLidControl::Open, this))
    625309            ("Open the lids");
    626310
    627         T::AddEvent("CLOSE")(Lid::State::kUnidentified)(Lid::State::kInconsistent)(Lid::State::kUnknown)(Lid::State::kOvercurrent)(Lid::State::kPowerProblem)(Lid::State::kOpen)
     311        T::AddEvent("CLOSE")
    628312            (bind(&StateMachineLidControl::Close, this))
    629313            ("Close the lids");
    630314
    631         T::AddEvent("POST", "C")(Lid::State::kUnidentified)(Lid::State::kInconsistent)(Lid::State::kUnknown)(Lid::State::kOvercurrent)(Lid::State::kPowerProblem)(Lid::State::kOpen)(Lid::State::kClosed)(Lid::State::kMoving)
    632             (bind(&StateMachineLidControl::Post, this, placeholders::_1))
    633             ("set verbosity state"
    634              "|verbosity[bool]:disable or enable verbosity for received data (yes/no), except dynamic data");
    635 
    636         T::AddEvent("UNLOCK", Lid::State::kLocked)
    637             (bind(&StateMachineLidControl::Unlock, this))
    638             ("Unlock if in locked state.");
     315        T::AddEvent("STATUS")
     316            (bind(&StateMachineLidControl::RequestStatus, this))
     317            ("Request Arduino Status");
    639318    }
    640319
     
    644323        fLid.SetInterval(conf.Get<uint16_t>("interval"));
    645324        fLid.SetDebugTx(conf.Get<bool>("debug-tx"));
    646         fLid.SetSite(conf.Get<string>("url"));
    647325        fLid.SetEndpoint(conf.Get<string>("addr"));
    648326        fLid.StartConnect();
    649 
    650         fTimeToMove = conf.Get<uint16_t>("time-to-move");
    651 
    652327        return -1;
    653328    }
     
    707382void PrintHelp()
    708383{
    709 //    Main::PrintHelp<StateMachineFTM<StateMachine, ConnectionFTM>>();
    710 
    711     /* Additional help text which is printed after the configuration
    712      options goes here */
    713 
    714     /*
    715      cout << "bla bla bla" << endl << endl;
    716      cout << endl;
    717      cout << "Environment:" << endl;
    718      cout << "environment" << endl;
    719      cout << endl;
    720      cout << "Examples:" << endl;
    721      cout << "test exam" << endl;
    722      cout << endl;
    723      cout << "Files:" << endl;
    724      cout << "files" << endl;
    725      cout << endl;
    726      */
    727384}
    728385
     
    743400            return RunShell<LocalStream, StateMachine, ConnectionLid>(conf);
    744401        else
    745             return RunShell<LocalStream, StateMachineDim, ConnectionDimWeather>(conf);
     402            return RunShell<LocalStream, StateMachineDim, ConnectionDimLid>(conf);
    746403    }
    747404    // Cosole access w/ and w/o Dim
     
    756413    {
    757414        if (conf.Get<int>("console")==0)
    758             return RunShell<LocalShell, StateMachineDim, ConnectionDimWeather>(conf);
     415            return RunShell<LocalShell, StateMachineDim, ConnectionDimLid>(conf);
    759416        else
    760             return RunShell<LocalConsole, StateMachineDim, ConnectionDimWeather>(conf);
     417            return RunShell<LocalConsole, StateMachineDim, ConnectionDimLid>(conf);
    761418    }
    762419
Note: See TracChangeset for help on using the changeset viewer.