rllib  1
Public Member Functions | Public Attributes | Private Attributes | List of all members
rlPlcState Class Reference

#include <rlplc.h>

Collaboration diagram for rlPlcState:
Collaboration graph
[legend]

Public Member Functions

 rlPlcState (int numInt=100, int numFloat=100, int numDouble=0, const char *shared_memory=NULL)
 
virtual ~rlPlcState ()
 
void clear ()
 
void rememberState ()
 
int intChanged (int index)
 
int floatChanged (int index)
 
int doubleChanged (int index)
 
int intHasIncreased (int index)
 
int floatHasIncreased (int index)
 
int doubleHasIncreased (int index)
 
int intHasDecreased (int index)
 
int floatHasDecreased (int index)
 
int doubleHasDecreased (int index)
 
int deltaInt (int index)
 
float deltaFloat (int index)
 
double deltaDouble (int index)
 
void set (int index, int bit)
 
void clear (int index, int bit)
 
int isSet (int index, int bit)
 
int isClear (int index, int bit)
 
int hasBeenSet (int index, int bit)
 
int hasBeenCleared (int index, int bit)
 
int maxInt ()
 
int maxFloat ()
 
int maxDouble ()
 
int getInt (int index)
 
float getFloat (int index)
 
double getDouble (int index)
 
int getOldInt (int index)
 
float getOldFloat (int index)
 
double getOldDouble (int index)
 

Public Attributes

int * i
 
int * i_old
 
float * f
 
float * f_old
 
double * d
 
double * d_old
 
rlSharedMemoryshm
 

Private Attributes

int max_int
 
int max_float
 
int max_double
 

Detailed Description

Definition at line 22 of file rlplc.h.

Constructor & Destructor Documentation

◆ rlPlcState()

rlPlcState::rlPlcState ( int  numInt = 100,
int  numFloat = 100,
int  numDouble = 0,
const char *  shared_memory = NULL 
)

Definition at line 19 of file rlplc.cpp.

20 {
21  max_int = numInt;
22  if(max_int <= 0) max_int = 1;
23  max_float = numFloat;
24  if(max_float <= 0) max_float = 1;
25  max_double = numDouble;
26  if(max_double <= 0) max_double = 1;
27  if(shared_memory == NULL)
28  { // use local memory
29  i = new int[max_int];
30  i_old = new int[max_int];
31  f = new float[max_float];
32  f_old = new float[max_float];
33  d = new double[max_double];
34  d_old = new double[max_double];
35  memset(i ,0,sizeof(int)*max_int);
36  memset(i_old,0,sizeof(int)*max_int);
37  memset(f ,0,sizeof(float)*max_float);
38  memset(f_old,0,sizeof(float)*max_float);
39  memset(d ,0,sizeof(double)*max_double);
40  memset(d_old,0,sizeof(double)*max_double);
41  }
42  else
43  { // map memory to shared memory
44  shm = new rlSharedMemory(shared_memory, sizeof(int)*max_int*2 + sizeof(float)*max_float*2 + sizeof(double)*max_double*2 );
46  {
47  void *ptr = shm->getUserAdr();
48  i = (int *) ptr;
49  i_old = (int *) ptr + sizeof(int)*max_int;
50  f = (float *) ptr + sizeof(int)*max_int*2;
51  f_old = (float *) ptr + sizeof(int)*max_int*2 + sizeof(float)*max_float;
52  d = (double *) ptr + sizeof(int)*max_int*2 + sizeof(float)*max_float*2;
53  d_old = (double *) ptr + sizeof(int)*max_int*2 + sizeof(float)*max_float*2 + sizeof(double)*max_double;
54  }
55  else
56  {
57  printf("ERROR: rlPlcState sharedMemoryStatus(%s) is not OK\n", shared_memory);
58  }
59  }
60 }
double * d
Definition: rlplc.h:29
float * f
Definition: rlplc.h:28
int max_int
Definition: rlplc.h:62
int * i
Definition: rlplc.h:27
rlSharedMemory * shm
Definition: rlplc.h:59
int max_double
Definition: rlplc.h:62
int max_float
Definition: rlplc.h:62
int * i_old
Definition: rlplc.h:27
double * d_old
Definition: rlplc.h:29
float * f_old
Definition: rlplc.h:28

◆ ~rlPlcState()

rlPlcState::~rlPlcState ( )
virtual

Definition at line 62 of file rlplc.cpp.

63 {
64  if(shm == NULL)
65  {
66  delete [] i;
67  delete [] i_old;
68  delete [] f;
69  delete [] f_old;
70  delete [] d;
71  delete [] d_old;
72  }
73  else
74  {
75  delete shm;
76  }
77 }
double * d
Definition: rlplc.h:29
float * f
Definition: rlplc.h:28
int * i
Definition: rlplc.h:27
rlSharedMemory * shm
Definition: rlplc.h:59
int * i_old
Definition: rlplc.h:27
double * d_old
Definition: rlplc.h:29
float * f_old
Definition: rlplc.h:28

Member Function Documentation

◆ clear() [1/2]

void rlPlcState::clear ( )

Definition at line 79 of file rlplc.cpp.

80 {
81  if(i != NULL) memset(i ,0,sizeof(int)*max_int);
82  if(i_old != NULL) memset(i_old,0,sizeof(int)*max_int);
83  if(f != NULL) memset(f ,0,sizeof(float)*max_float);
84  if(f_old != NULL) memset(f_old,0,sizeof(float)*max_float);
85  if(d != NULL) memset(d ,0,sizeof(double)*max_double);
86  if(d_old != NULL) memset(d_old,0,sizeof(double)*max_double);
87 }
double * d
Definition: rlplc.h:29
float * f
Definition: rlplc.h:28
int max_int
Definition: rlplc.h:62
int * i
Definition: rlplc.h:27
int max_double
Definition: rlplc.h:62
int max_float
Definition: rlplc.h:62
int * i_old
Definition: rlplc.h:27
double * d_old
Definition: rlplc.h:29
float * f_old
Definition: rlplc.h:28

◆ clear() [2/2]

void rlPlcState::clear ( int  index,
int  bit 
)

Definition at line 183 of file rlplc.cpp.

184 {
185  if(index<0 || index >= max_int) return;
186  i[index] = i[index] & ~bit;
187 }
int max_int
Definition: rlplc.h:62
int * i
Definition: rlplc.h:27

◆ deltaDouble()

double rlPlcState::deltaDouble ( int  index)

Definition at line 171 of file rlplc.cpp.

172 {
173  if(index<0 || index >= max_double) return 0;
174  return d[index] - d_old[index];
175 }
double * d
Definition: rlplc.h:29
int max_double
Definition: rlplc.h:62
double * d_old
Definition: rlplc.h:29

◆ deltaFloat()

float rlPlcState::deltaFloat ( int  index)

Definition at line 165 of file rlplc.cpp.

166 {
167  if(index<0 || index >= max_float) return 0;
168  return f[index] - f_old[index];
169 }
float * f
Definition: rlplc.h:28
int max_float
Definition: rlplc.h:62
float * f_old
Definition: rlplc.h:28

◆ deltaInt()

int rlPlcState::deltaInt ( int  index)

Definition at line 159 of file rlplc.cpp.

160 {
161  if(index<0 || index >= max_int) return 0;
162  return i[index] - i_old[index];
163 }
int max_int
Definition: rlplc.h:62
int * i
Definition: rlplc.h:27
int * i_old
Definition: rlplc.h:27

◆ doubleChanged()

int rlPlcState::doubleChanged ( int  index)

Definition at line 110 of file rlplc.cpp.

111 {
112  if(index<0 || index >= max_double) return 0;
113  if(d[index] == d_old[index]) return 0;
114  else return 1;
115 }
double * d
Definition: rlplc.h:29
int max_double
Definition: rlplc.h:62
double * d_old
Definition: rlplc.h:29

◆ doubleHasDecreased()

int rlPlcState::doubleHasDecreased ( int  index)

Definition at line 152 of file rlplc.cpp.

153 {
154  if(index<0 || index >= max_double) return 0;
155  if(d[index] < d_old[index]) return 1;
156  else return 0;
157 }
double * d
Definition: rlplc.h:29
int max_double
Definition: rlplc.h:62
double * d_old
Definition: rlplc.h:29

◆ doubleHasIncreased()

int rlPlcState::doubleHasIncreased ( int  index)

Definition at line 131 of file rlplc.cpp.

132 {
133  if(index<0 || index >= max_double) return 0;
134  if(d[index] > d_old[index]) return 1;
135  else return 0;
136 }
double * d
Definition: rlplc.h:29
int max_double
Definition: rlplc.h:62
double * d_old
Definition: rlplc.h:29

◆ floatChanged()

int rlPlcState::floatChanged ( int  index)

Definition at line 103 of file rlplc.cpp.

104 {
105  if(index<0 || index >= max_float) return 0;
106  if(f[index] == f_old[index]) return 0;
107  else return 1;
108 }
float * f
Definition: rlplc.h:28
int max_float
Definition: rlplc.h:62
float * f_old
Definition: rlplc.h:28

◆ floatHasDecreased()

int rlPlcState::floatHasDecreased ( int  index)

Definition at line 145 of file rlplc.cpp.

146 {
147  if(index<0 || index >= max_float) return 0;
148  if(f[index] < f_old[index]) return 1;
149  else return 0;
150 }
float * f
Definition: rlplc.h:28
int max_float
Definition: rlplc.h:62
float * f_old
Definition: rlplc.h:28

◆ floatHasIncreased()

int rlPlcState::floatHasIncreased ( int  index)

Definition at line 124 of file rlplc.cpp.

125 {
126  if(index<0 || index >= max_float) return 0;
127  if(f[index] > f_old[index]) return 1;
128  else return 0;
129 }
float * f
Definition: rlplc.h:28
int max_float
Definition: rlplc.h:62
float * f_old
Definition: rlplc.h:28

◆ getDouble()

double rlPlcState::getDouble ( int  index)

Definition at line 252 of file rlplc.cpp.

253 {
254  if(index<0 || index >= max_double) return 0;
255  return d[index];
256 }
double * d
Definition: rlplc.h:29
int max_double
Definition: rlplc.h:62

◆ getFloat()

float rlPlcState::getFloat ( int  index)

Definition at line 246 of file rlplc.cpp.

247 {
248  if(index<0 || index >= max_float) return 0;
249  return f[index];
250 }
float * f
Definition: rlplc.h:28
int max_float
Definition: rlplc.h:62

◆ getInt()

int rlPlcState::getInt ( int  index)

Definition at line 240 of file rlplc.cpp.

241 {
242  if(index<0 || index >= max_int) return 0;
243  return i[index];
244 }
int max_int
Definition: rlplc.h:62
int * i
Definition: rlplc.h:27

◆ getOldDouble()

double rlPlcState::getOldDouble ( int  index)

Definition at line 270 of file rlplc.cpp.

271 {
272  if(index<0 || index >= max_double) return 0;
273  return d_old[index];
274 }
int max_double
Definition: rlplc.h:62
double * d_old
Definition: rlplc.h:29

◆ getOldFloat()

float rlPlcState::getOldFloat ( int  index)

Definition at line 264 of file rlplc.cpp.

265 {
266  if(index<0 || index >= max_float) return 0;
267  return f_old[index];
268 }
int max_float
Definition: rlplc.h:62
float * f_old
Definition: rlplc.h:28

◆ getOldInt()

int rlPlcState::getOldInt ( int  index)

Definition at line 258 of file rlplc.cpp.

259 {
260  if(index<0 || index >= max_int) return 0;
261  return i_old[index];
262 }
int max_int
Definition: rlplc.h:62
int * i_old
Definition: rlplc.h:27

◆ hasBeenCleared()

int rlPlcState::hasBeenCleared ( int  index,
int  bit 
)

Definition at line 214 of file rlplc.cpp.

215 {
216  if(index<0 || index >= max_int) return 0;
217  if((i[index] & bit) == 0) // is bit clear ?
218  {
219  if((i_old[index] & bit) == 0) return 0; // both are clear
220  else return 1; // old one was set
221  }
222  return 0;
223 }
int max_int
Definition: rlplc.h:62
int * i
Definition: rlplc.h:27
int * i_old
Definition: rlplc.h:27

◆ hasBeenSet()

int rlPlcState::hasBeenSet ( int  index,
int  bit 
)

Definition at line 203 of file rlplc.cpp.

204 {
205  if(index<0 || index >= max_int) return 0;
206  if(i[index] & bit) // is bit set ?
207  {
208  if(i_old[index] & bit) return 0; // both are set
209  else return 1; // old one was not set
210  }
211  return 0;
212 }
int max_int
Definition: rlplc.h:62
int * i
Definition: rlplc.h:27
int * i_old
Definition: rlplc.h:27

◆ intChanged()

int rlPlcState::intChanged ( int  index)

Definition at line 96 of file rlplc.cpp.

97 {
98  if(index<0 || index >= max_int) return 0;
99  if(i[index] == i_old[index]) return 0;
100  else return 1;
101 }
int max_int
Definition: rlplc.h:62
int * i
Definition: rlplc.h:27
int * i_old
Definition: rlplc.h:27

◆ intHasDecreased()

int rlPlcState::intHasDecreased ( int  index)

Definition at line 138 of file rlplc.cpp.

139 {
140  if(index<0 || index >= max_int) return 0;
141  if(i[index] < i_old[index]) return 1;
142  else return 0;
143 }
int max_int
Definition: rlplc.h:62
int * i
Definition: rlplc.h:27
int * i_old
Definition: rlplc.h:27

◆ intHasIncreased()

int rlPlcState::intHasIncreased ( int  index)

Definition at line 117 of file rlplc.cpp.

118 {
119  if(index<0 || index >= max_int) return 0;
120  if(i[index] > i_old[index]) return 1;
121  else return 0;
122 }
int max_int
Definition: rlplc.h:62
int * i
Definition: rlplc.h:27
int * i_old
Definition: rlplc.h:27

◆ isClear()

int rlPlcState::isClear ( int  index,
int  bit 
)

Definition at line 196 of file rlplc.cpp.

197 {
198  if(index<0 || index >= max_int) return 0;
199  if(i[index] & bit) return 0;
200  else return 1;
201 }
int max_int
Definition: rlplc.h:62
int * i
Definition: rlplc.h:27

◆ isSet()

int rlPlcState::isSet ( int  index,
int  bit 
)

Definition at line 189 of file rlplc.cpp.

190 {
191  if(index<0 || index >= max_int) return 0;
192  if(i[index] & bit) return 1;
193  else return 0;
194 }
int max_int
Definition: rlplc.h:62
int * i
Definition: rlplc.h:27

◆ maxDouble()

int rlPlcState::maxDouble ( )

Definition at line 235 of file rlplc.cpp.

236 {
237  return max_float - 1;
238 }
int max_float
Definition: rlplc.h:62

◆ maxFloat()

int rlPlcState::maxFloat ( )

Definition at line 230 of file rlplc.cpp.

231 {
232  return max_float - 1;
233 }
int max_float
Definition: rlplc.h:62

◆ maxInt()

int rlPlcState::maxInt ( )

Definition at line 225 of file rlplc.cpp.

226 {
227  return max_int - 1;
228 }
int max_int
Definition: rlplc.h:62

◆ rememberState()

void rlPlcState::rememberState ( )

Definition at line 89 of file rlplc.cpp.

90 {
91  memcpy(i_old,i,sizeof(int)*max_int);
92  memcpy(f_old,f,sizeof(float)*max_float);
93  memcpy(d_old,d,sizeof(double)*max_double);
94 }
double * d
Definition: rlplc.h:29
float * f
Definition: rlplc.h:28
int max_int
Definition: rlplc.h:62
int * i
Definition: rlplc.h:27
int max_double
Definition: rlplc.h:62
int max_float
Definition: rlplc.h:62
int * i_old
Definition: rlplc.h:27
double * d_old
Definition: rlplc.h:29
float * f_old
Definition: rlplc.h:28

◆ set()

void rlPlcState::set ( int  index,
int  bit 
)

Definition at line 177 of file rlplc.cpp.

178 {
179  if(index<0 || index >= max_int) return;
180  i[index] = i[index] | bit;
181 }
int max_int
Definition: rlplc.h:62
int * i
Definition: rlplc.h:27

Member Data Documentation

◆ d

double* rlPlcState::d

Definition at line 29 of file rlplc.h.

◆ d_old

double * rlPlcState::d_old

Definition at line 29 of file rlplc.h.

◆ f

float* rlPlcState::f

Definition at line 28 of file rlplc.h.

◆ f_old

float * rlPlcState::f_old

Definition at line 28 of file rlplc.h.

◆ i

int* rlPlcState::i

Definition at line 27 of file rlplc.h.

◆ i_old

int * rlPlcState::i_old

Definition at line 27 of file rlplc.h.

◆ max_double

int rlPlcState::max_double
private

Definition at line 62 of file rlplc.h.

◆ max_float

int rlPlcState::max_float
private

Definition at line 62 of file rlplc.h.

◆ max_int

int rlPlcState::max_int
private

Definition at line 62 of file rlplc.h.

◆ shm

rlSharedMemory* rlPlcState::shm

Definition at line 59 of file rlplc.h.


The documentation for this class was generated from the following files: