rllib  1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
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  {
21  var = new rlPlcState(numProcessVariables, numProcessVariables, numProcessVariables);
22  }
23  else
24  {
26  var = state;
27  }
28 }
29 
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 
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 
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 
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 
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 
110 {
111  return state;
112 }
113 
115 {
116  return var;
117 }
118