rllib
1
Main Page
Classes
Files
File List
File Members
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
lib
rlstatemachine.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
* *
3
* This library is free software; you can redistribute it and/or modify *
4
* it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as *
5
* published by the Free Software Foundation *
6
* *
7
***************************************************************************/
8
#include "
rlstatemachine.h
"
9
10
rlStatemachine::rlStatemachine
(
int
numStates,
int
numProcessVariables,
rlPlcState
*state)
11
{
12
state = 0;
13
num_states
= 0;
14
var
= NULL;
15
num_states
= numStates;
16
num_process_variables
= numProcessVariables;
17
if
(numProcessVariables <= 0)
return
;
18
if
(state == NULL)
19
{
20
haveto_free_state
= 1;
21
var
=
new
rlPlcState
(numProcessVariables, numProcessVariables, numProcessVariables);
22
}
23
else
24
{
25
haveto_free_state
= 0;
26
var
=
state
;
27
}
28
}
29
30
rlStatemachine::~rlStatemachine
()
31
{
32
if
(
var
!= NULL &&
haveto_free_state
)
delete
var
;
33
}
34
35
int
rlStatemachine::setPlcStateInt
(
int
index,
int
val)
36
{
37
if
(index < 0)
return
0;
38
if
(index >=
num_process_variables
)
return
0;
39
if
(
var
== NULL)
return
0;
40
var
->
i_old
[index] =
var
->
i
[index];
41
var
->
i
[index] = val;
42
return
val;
43
}
44
45
float
rlStatemachine::setPlcStateFloat
(
int
index,
float
val)
46
{
47
if
(index < 0)
return
0;
48
if
(index >=
num_process_variables
)
return
0;
49
if
(
var
== NULL)
return
0;
50
var
->
f_old
[index] =
var
->
f
[index];
51
var
->
f
[index] = val;
52
return
val;
53
}
54
55
double
rlStatemachine::setPlcStateDouble
(
int
index,
double
val)
56
{
57
if
(index < 0)
return
0;
58
if
(index >=
num_process_variables
)
return
0;
59
if
(
var
== NULL)
return
0;
60
var
->
d_old
[index] =
var
->
d
[index];
61
var
->
d
[index] = val;
62
return
val;
63
}
64
65
void
rlStatemachine::doState
()
66
{
67
// implement in subclass
68
}
69
70
void
rlStatemachine::enterState
(
int
newState,
int
whichEntry)
71
{
72
// implement in subclass and call rlStatemachine::enterState(newState,whichEntry);
73
if
(newState < 0)
return
;
74
if
(newState >=
num_states
)
return
;
75
if
(whichEntry){}
76
state
= newState;
77
}
78
79
void
rlStatemachine::exitState
(
int
whichExit)
80
{
81
// implement in subclass
82
if
(whichExit){}
83
}
84
85
int
rlStatemachine::getPlcStateInt
(
int
index)
86
{
87
if
(index < 0)
return
0;
88
if
(index >=
num_process_variables
)
return
0;
89
if
(
var
== NULL)
return
0;
90
return
var
->
i
[index];
91
}
92
93
float
rlStatemachine::getPlcStateFloat
(
int
index)
94
{
95
if
(index < 0)
return
0;
96
if
(index >=
num_process_variables
)
return
0;
97
if
(
var
== NULL)
return
0;
98
return
var
->
f
[index];
99
}
100
101
double
rlStatemachine::getPlcStateDouble
(
int
index)
102
{
103
if
(index < 0)
return
0;
104
if
(index >=
num_process_variables
)
return
0;
105
if
(
var
== NULL)
return
0;
106
return
var
->
d
[index];
107
}
108
109
int
rlStatemachine::getState
()
110
{
111
return
state
;
112
}
113
114
rlPlcState
*
rlStatemachine::getVar
()
115
{
116
return
var
;
117
}
118
Generated by
1.8.2