-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpml_mo.hpp
More file actions
149 lines (132 loc) · 4.79 KB
/
Copy pathpml_mo.hpp
File metadata and controls
149 lines (132 loc) · 4.79 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#ifndef PMLMOS_HPP
#define PMLMOS_HPP value
#include<iostream>
enum pmlState {
NO_STATE=-1,
STOPPED,
STARTING,
IDLE,
SUSPENDING,
SUSPENDED,
UNSUSPENDING,
EXECUTE,
STOPPING,
ABORTING,
ABORTED,
HOLDING,
HELD,
UNHOLDING,
COMPLETING,
COMPLETE,
RESETTING,
CLEARING,
N_STATES
};
const char *pmlStateLabel[] =
{
"STOPPED",
"STARTING",
"IDLE",
"SUSPENDING",
"SUSPENDED",
"UNSUSPENDING",
"EXECUTE",
"STOPPING",
"ABORTING",
"ABORTED",
"HOLDING",
"HELD",
"UNHOLDING",
"COMPLETING",
"COMPLETE",
"RESETTING",
"CLEARING"
};
enum pmlCommand {
NO_COMMAND=-1,
START,
RESET,
HOLD,
UNHOLD,
SUSPEND,
UNSUSPEND,
CLEAR,
STOP,
ABORT,
N_COMMANDS
};
const char *pmlCommandLabel[] =
{
"START",
"RESET",
"HOLD",
"UNHOLD",
"SUSPEND",
"UNSUSPEND",
"CLEAR",
"STOP",
"ABORT"
};
const pmlState transition[pmlState (N_STATES)][pmlCommand (N_COMMANDS)] = {
// START RESET HOLD UNHOLD SUSPEND UNSUSPEND CLEAR STOP ABORT
/*STOPPED*/ {NO_STATE, RESETTING, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, ABORTING},
/*STARTING*/ {NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, STOPPING, ABORTING},
/*IDLE*/ {STARTING, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, STOPPING, ABORTING},
/*SUSPENDING*/ {NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, STOPPING, ABORTING},
/*SUSPENDED*/ {NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, UNSUSPENDING, NO_STATE, STOPPING, ABORTING},
/*UNSUSPENDING*/ {NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, STOPPING, ABORTING},
/*EXECUTE*/ {NO_STATE, NO_STATE, HOLDING, NO_STATE, SUSPENDING, NO_STATE, NO_STATE, STOPPING, ABORTING},
/*STOPPING*/ {NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, ABORTING},
/*ABORTING*/ {NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE},
/*ABORTED*/ {NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, CLEARING, NO_STATE, NO_STATE},
/*HOLDING*/ {NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, STOPPING, ABORTING},
/*HELD*/ {NO_STATE, NO_STATE, NO_STATE, UNHOLDING, NO_STATE, NO_STATE, NO_STATE, STOPPING, ABORTING},
/*UNHOLDING*/ {NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, STOPPING, ABORTING},
/*COMPLETING*/ {NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, STOPPING, ABORTING},
/*COMPLETE*/ {NO_STATE, RESETTING, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, STOPPING, ABORTING},
/*RESETTING*/ {NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, STOPPING, ABORTING},
/*CLEARING*/ {NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, NO_STATE, ABORTING}
};
class pmlMos
{
protected:
pmlState st_;
pmlState setState(pmlState _st) {return st_ = _st;};
public:
pmlMos(pmlState _st=ABORTED):st_(_st){};
pmlState state() {return st_;};
pmlState forceState(pmlState _st) {return st_ = _st;};
pmlState sendCommand(pmlCommand _cmd)
{
if(transition[st_][_cmd] >= 0)
st_ = transition[st_][_cmd];
return transition[st_][_cmd];
};
char ** print(char** floor, int nrows, int ncols) {return floor;};
};
#ifndef MAIN
#define MAIN
int main(int argc, char *argv[])
{
pmlMos mo;
for (mo.forceState(pmlState(0)); mo.state() < N_STATES; mo.forceState(pmlState(mo.state() + 1)))
{
std::cout << pmlStateLabel[mo.state()] << std::endl;
}
pmlState st;
pmlCommand cmd;
for (cmd=pmlCommand(0); cmd < N_COMMANDS; cmd=pmlCommand(cmd+1)) {
std::cout << pmlCommandLabel[cmd] << std::endl;
}
for (st = pmlState (0); st < N_STATES; st=pmlState(st+1))
{
for (cmd = pmlCommand(0); cmd < N_COMMANDS; cmd=pmlCommand(cmd+1))
{
if(transition[st][cmd] >= 0)
std::cout << "From: " << pmlStateLabel[st] << ", with a command of " << pmlCommandLabel[cmd] << " next state will be: " << pmlStateLabel[transition[st][cmd]] << std::endl;
}
}
return 0;
}
#endif /* ifndef MAIN */
#endif /* ifndef PMLMOS_HPP */