-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlManagerSM.cpp
More file actions
80 lines (58 loc) · 2.51 KB
/
Copy pathControlManagerSM.cpp
File metadata and controls
80 lines (58 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "qp_port.h"
#include "bsp.h"
#include "ControlManager.h"
//Q_DEFINE_THIS_FILE
using namespace QP;
// local objects -------------------------------------------------------------
class ControlManagerSM : public QActive // extend the QActive class
{
// Variables
ControlManager manager;
public:
ControlManagerSM() :
QActive((QStateHandler)&ControlManagerSM::initial)
{ }
private:
// Member functions
// QStates
static QState initial (ControlManagerSM *me, QEvt const *e);
static QState active (ControlManagerSM *me, QEvt const *e);
};
static ControlManagerSM l_ControlManagerSM; // the sole instance of the ControlManager active object
// global objects ------------------------------------------------------------
QActive * AO_ControlManagerSM = &l_ControlManagerSM; // opaque pointer to ControlManager AO
// HSM definition ------------------------------------------------------------
//............................................................................
QState ControlManagerSM::initial(ControlManagerSM *me, QEvt const *) {
me->subscribe(TIME_TICK_SIG); // subscribe for time event
QS_OBJ_DICTIONARY(&l_ControlManagerSM); // object dictionary for ControlManager object
QS_FUN_DICTIONARY(&ControlManagerSM::initial); // function dictionaries for ControlManager HSM
QS_FUN_DICTIONARY(&ControlManagerSM::active);
QS_SIG_DICTIONARY(TIME_TICK_SIG, &l_ControlManagerSM);
QS_SIG_DICTIONARY(Q_CONFIG_SIG, &l_ControlManagerSM); // local signals
return Q_TRAN(&ControlManagerSM::active); // top-most initial transition
}
//............................................................................
QState ControlManagerSM::active(ControlManagerSM *me, QEvt const *e) {
switch (e->sig) {
case Q_ENTRY_SIG:
{
me->manager.initialize();
return Q_SUPER(&QHsm::top);
break;
}
case Q_CONFIG_SIG:
{
//configure(e->cfg);// configure functions tbd
return Q_HANDLED();
}
case TIME_TICK_SIG:
{
me->manager.readSensor();
me->manager.computeControl();
me->manager.sendControl();
return Q_HANDLED();
}
}
return Q_SUPER(&QHsm::top);
}