Changeset 18125 for trunk/FACT++


Ignore:
Timestamp:
02/13/15 09:24:07 (10 years ago)
Author:
tbretz
Message:
Implemeneted a locked state which is initiated by an automatic lid close at nautical twilight.
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/HeadersLid.h

    r16837 r18125  
    1717            kClosed,
    1818            kOpen,
    19             kMoving
     19            kMoving,
     20            kLocked
    2021        };
    2122    };
  • trunk/FACT++/src/lidctrl.cc

    r17916 r18125  
    473473    S fLid;
    474474    Time fLastCommand;
     475    Time fSunRise;
    475476
    476477    uint16_t fTimeToMove;
     
    535536    }*/
    536537
     538    int Unlock()
     539    {
     540        return fLid.GetState();
     541    }
     542
    537543    int Execute()
    538544    {
    539545        const int rc = fLid.GetState();
    540 
    541         if (T::GetCurrentState()==Lid::State::kMoving &&
     546        const int state = T::GetCurrentState();
     547
     548        if (state==Lid::State::kMoving &&
    542549            (rc==Lid::State::kConnected || rc==Lid::State::kDisconnected) &&
    543550            fLastCommand+boost::posix_time::seconds(fTimeToMove+fLid.GetInterval()) > Time())
     
    546553        }
    547554
    548         return rc==Lid::State::kConnected ? T::GetCurrentState() : rc;
     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;
    549574    }
    550575
     
    552577public:
    553578    StateMachineLidControl(ostream &out=cout) :
    554         StateMachineAsio<T>(out, "LID_CONTROL"), fLid(*this, *this)
     579        StateMachineAsio<T>(out, "LID_CONTROL"), fLid(*this, *this),
     580        fSunRise(Time().GetNextSunRise(-6))
    555581    {
    556582        // State names
     
    584610        T::AddStateName(Lid::State::kMoving, "Moving",
    585611                     "Lids are supposed to move, waiting for next status");
     612
     613        T::AddStateName(Lid::State::kLocked, "Locked",
     614                        "Locked, no commands accepted except UNLOCK.");
    586615
    587616
     
    600629            ("Close the lids");
    601630
    602         T::AddEvent("POST", "C")
     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)
    603632            (bind(&StateMachineLidControl::Post, this, placeholders::_1))
    604633            ("set verbosity state"
    605634             "|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.");
    606639    }
    607640
Note: See TracChangeset for help on using the changeset viewer.