Deleted.
Diff: ped.cpp
- Revision:
- 2:27716f570c3d
- Parent:
- 1:3fe0c7f27d97
diff -r 3fe0c7f27d97 -r 27716f570c3d ped.cpp --- a/ped.cpp Sun Sep 25 18:31:45 2011 +0000 +++ b/ped.cpp Mon Sep 26 02:20:21 2011 +0000 @@ -1,117 +1,116 @@ -////////////////////////////////////////////////////////////////////////////// -// Model: pelican.qm -// File: ./ped.cpp -// -// This file has been generated automatically by QP Modeler (QM). -// DO NOT EDIT THIS FILE MANUALLY. -// -// Please visit www.state-machine.com/qm for more information. -////////////////////////////////////////////////////////////////////////////// -#include "qp_port.h" -#include "bsp.h" -#include "pelican.h" - -Q_DEFINE_THIS_FILE - -enum PedTimeouts { // various timeouts in ticks - N_ATTEMPTS = 10, // number of PED_WAITING attempts - WAIT_TOUT = BSP_TICKS_PER_SEC * 3, // wait between posting PED_WAITING - OFF_TOUT = BSP_TICKS_PER_SEC * 8 // wait time after posting OFF_SIG -}; - -// Ped class ----------------------------------------------------------------- -// $(components::Ped) ........................................................ -/// Ped (Pedestrian) active object. -/// -/// NOTE: The mbed borad does not provide a push button (at least not out of the box) to provide the PEDS_WAITING event to the system. Instead, to be able to run this example on a bare-bones mbed board, the Pedestrian is *simulated* as the Ped active object. -class Ped : public QActive { -private: - QTimeEvt m_timeout; - uint8_t m_retryCtr; - -public: - Ped(); - -protected: - static QState initial(Ped *me, QEvent const *e); - static QState wait(Ped *me, QEvent const *e); - static QState off(Ped *me, QEvent const *e); -}; - -// Local objects ------------------------------------------------------------- -static Ped l_Ped; // the single instance of Ped active object - -// Global objects ------------------------------------------------------------ -QActive * const AO_Ped = &l_Ped; // the opaque pointer - -// Ped class definition ------------------------------------------------------ -// $(components::Ped) ........................................................ -// $(components::Ped::Ped) ................................................... -Ped::Ped() : QActive((QStateHandler)&Ped::initial), m_timeout(TIMEOUT_SIG) { -} -// $(components::Ped::Statechart) ............................................ -// @(/1/1/3/0) -QState Ped::initial(Ped *me, QEvent const *e) { - QS_OBJ_DICTIONARY(&l_Ped); - QS_OBJ_DICTIONARY(&l_Ped.m_timeout); - - QS_FUN_DICTIONARY(&Ped::initial); - QS_FUN_DICTIONARY(&Ped::wait); - QS_FUN_DICTIONARY(&Ped::off); - - QS_SIG_DICTIONARY(TIMEOUT_SIG, &l_Ped); // just for Ped - return Q_TRAN(&Ped::wait); -} -// $(components::Ped::Statechart::wait) ...................................... -QState Ped::wait(Ped *me, QEvent const *e) { - switch (e->sig) { - // @(/1/1/3/1) - case Q_ENTRY_SIG: { - me->m_retryCtr = N_ATTEMPTS; - me->m_timeout.postEvery(me, WAIT_TOUT); - return Q_HANDLED(); - } - // @(/1/1/3/1) - case Q_EXIT_SIG: { - me->m_timeout.disarm(); - return Q_HANDLED(); - } - // @(/1/1/3/1/0) - case TIMEOUT_SIG: { - --me->m_retryCtr; - // @(/1/1/3/1/0/1) - if (me->m_retryCtr != 0) { - QF::publish(Q_NEW(QEvent, PEDS_WAITING_SIG)); - return Q_HANDLED(); - } - // @(/1/1/3/1/0/0) - else { - return Q_TRAN(&Ped::off); - } - } - } - return Q_SUPER(&QHsm::top); -} -// $(components::Ped::Statechart::off) ....................................... -QState Ped::off(Ped *me, QEvent const *e) { - switch (e->sig) { - // @(/1/1/3/2) - case Q_ENTRY_SIG: { - me->m_timeout.postEvery(me, OFF_TOUT); - AO_Pelican->postFIFO(Q_NEW(QEvent, OFF_SIG)); - return Q_HANDLED(); - } - // @(/1/1/3/2) - case Q_EXIT_SIG: { - me->m_timeout.disarm(); - return Q_HANDLED(); - } - // @(/1/1/3/2/0) - case TIMEOUT_SIG: { - AO_Pelican->postFIFO(Q_NEW(QEvent, ON_SIG)); - - return Q_TRAN(&Ped::wait); - } - } - return Q_SUPER(&QHsm::top); -} +////////////////////////////////////////////////////////////////////////////// +// Model: pelican.qm +// File: ./ped.cpp +// +// This file has been generated automatically by QP Modeler (QM). +// DO NOT EDIT THIS FILE MANUALLY. +// +// Please visit www.state-machine.com/qm for more information. +////////////////////////////////////////////////////////////////////////////// +#include "qp_port.h" +#include "bsp.h" +#include "pelican.h" + +Q_DEFINE_THIS_FILE + +enum PedTimeouts { // various timeouts in ticks + N_ATTEMPTS = 10, // number of PED_WAITING attempts + WAIT_TOUT = BSP_TICKS_PER_SEC * 3, // wait between posting PED_WAITING + OFF_TOUT = BSP_TICKS_PER_SEC * 8 // wait time after posting OFF_SIG +}; + +// Ped class ----------------------------------------------------------------- +// $(components::Ped) ........................................................ +/// Ped (Pedestrian) active object. +/// +/// NOTE: The mbed borad does not provide a push button (at least not out of the box) to provide the PEDS_WAITING event to the system. Instead, to be able to run this example on a bare-bones mbed board, the Pedestrian is *simulated* as the Ped active object. +class Ped : public QActive { +private: + QTimeEvt m_timeout; + uint8_t m_retryCtr; + +public: + Ped(); + +protected: + static QState initial(Ped *me, QEvent const *e); + static QState wait(Ped *me, QEvent const *e); + static QState off(Ped *me, QEvent const *e); +}; + +// Local objects ------------------------------------------------------------- +static Ped l_Ped; // the single instance of Ped active object + +// Global objects ------------------------------------------------------------ +QActive * const AO_Ped = &l_Ped; // the opaque pointer + +// Ped class definition ------------------------------------------------------ +// $(components::Ped) ........................................................ +// $(components::Ped::Ped) ................................................... +Ped::Ped() : QActive((QStateHandler)&Ped::initial), m_timeout(TIMEOUT_SIG) { +} +// $(components::Ped::Statechart) ............................................ +// @(/1/1/3/0) +QState Ped::initial(Ped *me, QEvent const *e) { + QS_OBJ_DICTIONARY(&l_Ped); + QS_OBJ_DICTIONARY(&l_Ped.m_timeout); + + QS_FUN_DICTIONARY(&Ped::initial); + QS_FUN_DICTIONARY(&Ped::wait); + QS_FUN_DICTIONARY(&Ped::off); + + QS_SIG_DICTIONARY(TIMEOUT_SIG, &l_Ped); // just for Ped + return Q_TRAN(&Ped::wait); +} +// $(components::Ped::Statechart::wait) ...................................... +QState Ped::wait(Ped *me, QEvent const *e) { + switch (e->sig) { + // @(/1/1/3/1) + case Q_ENTRY_SIG: { + me->m_retryCtr = N_ATTEMPTS; + me->m_timeout.postEvery(me, WAIT_TOUT); + return Q_HANDLED(); + } + // @(/1/1/3/1) + case Q_EXIT_SIG: { + me->m_timeout.disarm(); + return Q_HANDLED(); + } + // @(/1/1/3/1/0) + case TIMEOUT_SIG: { + --me->m_retryCtr; + // @(/1/1/3/1/0/1) + if (me->m_retryCtr != 0) { + QF::PUBLISH(Q_NEW(QEvent, PEDS_WAITING_SIG), me); + return Q_HANDLED(); + } + // @(/1/1/3/1/0/0) + else { + return Q_TRAN(&Ped::off); + } + } + } + return Q_SUPER(&QHsm::top); +} +// $(components::Ped::Statechart::off) ....................................... +QState Ped::off(Ped *me, QEvent const *e) { + switch (e->sig) { + // @(/1/1/3/2) + case Q_ENTRY_SIG: { + me->m_timeout.postEvery(me, OFF_TOUT); + AO_Pelican->POST(Q_NEW(QEvent, OFF_SIG), me); + return Q_HANDLED(); + } + // @(/1/1/3/2) + case Q_EXIT_SIG: { + me->m_timeout.disarm(); + return Q_HANDLED(); + } + // @(/1/1/3/2/0) + case TIMEOUT_SIG: { + AO_Pelican->POST(Q_NEW(QEvent, ON_SIG), me); + return Q_TRAN(&Ped::wait); + } + } + return Q_SUPER(&QHsm::top); +}