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

#include <rlppiclient.h>

Inheritance diagram for rlPPIClient:
Inheritance graph
[legend]
Collaboration diagram for rlPPIClient:
Collaboration graph
[legend]

Public Types

enum  PPI_area {
  daveSD = 0x3, daveInputs = 0x81, daveOutputs = 0x82, daveFlags = 0x83,
  daveDB = 0x84, daveDI = 0x85, daveLocal = 0x86, daveV = 0x87,
  daveCounter = 28, daveTimer = 29
}
 
- Public Types inherited from rlMailbox
enum  MailboxEnum {
  MAILBOX_ERROR = -1, MAILBOX_FULL = -2, WAIT = 1, NOWAIT = 0,
  MAX_MAILBOX = 256*256, OK = 2, COULD_NOT_CREATE_MAILBOX = 3, COULD_NOT_GET_KEY = 4,
  COULD_NOT_GET_CHAN_ID = 5
}
 

Public Member Functions

 rlPPIClient (const char *mbxname, const char *shmname, int shmsize, int have_to_swap=1)
 
virtual ~rlPPIClient ()
 
int write (int slave, int area, int dbnum, int start, int len, const unsigned char *data)
 
int writeFloat (int slave, int area, int dbnum, int start, int len, const float *val)
 
int writeDword (int slave, int area, int dbnum, int start, int len, const int *val)
 
int writeShort (int slave, int area, int dbnum, int start, int len, const short *val)
 
int writeUDword (int slave, int area, int dbnum, int start, int len, const unsigned int *val)
 
int writeUShort (int slave, int area, int dbnum, int start, int len, const unsigned short *val)
 
int read (int offset, int len)
 
float Float (int index)
 
int Dword (int index)
 
int Short (int index)
 
unsigned int UDword (int index)
 
unsigned int UShort (int index)
 
- Public Member Functions inherited from rlMailbox
 rlMailbox (const char *name)
 
virtual ~rlMailbox ()
 
int write (const void *buf, int len)
 
int printf (const char *format,...)
 
int read (void *buf, int maxlen, int wait=WAIT)
 
int setReadBufferSize (int size)
 
const char * read (int wait=WAIT)
 
int write (const char *message)
 
void clear ()
 

Public Attributes

unsigned char buf [512]
 
- Public Attributes inherited from rlMailbox
int status
 
char * name
 

Private Attributes

int have_to_swap
 
- Private Attributes inherited from rlSharedMemory
int status
 
char * name
 

Additional Inherited Members

- Private Types inherited from rlSharedMemory
enum  SharedMemoryEnum {
  OK = 0, ERROR_FILE, ERROR_SHMGET, ERROR_SHMAT,
  ERROR_SHMCTL
}
 
- Private Member Functions inherited from rlSharedMemory
 rlSharedMemory (const char *name, unsigned long size, int rwmode=0600)
 
virtual ~rlSharedMemory ()
 
int deleteSharedMemory ()
 
int write (unsigned long offset, const void *buf, int len)
 
int read (unsigned long offset, void *buf, int len)
 
int readInt (unsigned long offset, int index)
 
int readShort (unsigned long offset, int index)
 
int readByte (unsigned long offset, int index)
 
float readFloat (unsigned long offset, int index)
 
int writeInt (unsigned long offset, int index, int val)
 
int writeShort (unsigned long offset, int index, int val)
 
int writeByte (unsigned long offset, int index, unsigned char val)
 
int writeFloat (unsigned long offset, int index, float val)
 
void * getUserAdr ()
 
int shmKey ()
 
int shmId ()
 
unsigned long size ()
 

Detailed Description

This class is for data acquisition from pvserver according to the pvbrowser principle.
The according daemon is generated by pvdevelop.
It communicates by the means of a shared memory and a mailbox.

Definition at line 28 of file rlppiclient.h.

Member Enumeration Documentation

◆ PPI_area

Enumerator
daveSD 
daveInputs 
daveOutputs 
daveFlags 
daveDB 
daveDI 
daveLocal 
daveV 
daveCounter 
daveTimer 

Definition at line 31 of file rlppiclient.h.

32  {
33  daveSD = 0x3,
34  daveInputs = 0x81,
35  daveOutputs = 0x82,
36  daveFlags = 0x83,
37  daveDB = 0x84, //data blocks
38  daveDI = 0x85, //not tested
39  daveLocal = 0x86, //not tested
40  daveV = 0x87, // don't know what it is
41  daveCounter = 28, //not tested
42  daveTimer = 29 //not tested
43  };

Constructor & Destructor Documentation

◆ rlPPIClient()

rlPPIClient::rlPPIClient ( const char *  mbxname,
const char *  shmname,
int  shmsize,
int  have_to_swap = 1 
)

Definition at line 31 of file rlppiclient.cpp.

32  :rlMailbox(mbxname), rlSharedMemory(shmname, shmsize)
33 {
34  have_to_swap = _have_to_swap;
35 }
rlSharedMemory(const char *name, unsigned long size, int rwmode=0600)
rlMailbox(const char *name)
Definition: rlmailbox.cpp:55
int have_to_swap
Definition: rlppiclient.h:60

◆ ~rlPPIClient()

rlPPIClient::~rlPPIClient ( )
virtual

Definition at line 37 of file rlppiclient.cpp.

38 {
39 }

Member Function Documentation

◆ Dword()

int rlPPIClient::Dword ( int  index)

Definition at line 256 of file rlppiclient.cpp.

257 {
258  SWAP swap;
259  if(index*4+4 > (int) BUFSIZE) return 0;
260  if(have_to_swap == 1)
261  {
262  swap.b[0] = buf[4*index+3];
263  swap.b[1] = buf[4*index+2];
264  swap.b[2] = buf[4*index+1];
265  swap.b[3] = buf[4*index];
266  }
267  else
268  {
269  swap.b[0] = buf[4*index];
270  swap.b[1] = buf[4*index+1];
271  swap.b[2] = buf[4*index+2];
272  swap.b[3] = buf[4*index+3];
273  }
274  return swap.i;
275 }
#define BUFSIZE
Definition: rlppiclient.cpp:19
unsigned char buf[512]
Definition: rlppiclient.h:58
int i
Definition: rlppiclient.cpp:27
int have_to_swap
Definition: rlppiclient.h:60
unsigned char b[4]
Definition: rlppiclient.cpp:23

◆ Float()

float rlPPIClient::Float ( int  index)

Definition at line 235 of file rlppiclient.cpp.

236 {
237  SWAP swap;
238  if(index*4+4 > (int) BUFSIZE) return 0.0f;
239  if(have_to_swap == 1)
240  {
241  swap.b[0] = buf[4*index+3];
242  swap.b[1] = buf[4*index+2];
243  swap.b[2] = buf[4*index+1];
244  swap.b[3] = buf[4*index];
245  }
246  else
247  {
248  swap.b[0] = buf[4*index];
249  swap.b[1] = buf[4*index+1];
250  swap.b[2] = buf[4*index+2];
251  swap.b[3] = buf[4*index+3];
252  }
253  return swap.f;
254 }
float f
Definition: rlppiclient.cpp:28
#define BUFSIZE
Definition: rlppiclient.cpp:19
unsigned char buf[512]
Definition: rlppiclient.h:58
int have_to_swap
Definition: rlppiclient.h:60
unsigned char b[4]
Definition: rlppiclient.cpp:23

◆ read()

int rlPPIClient::read ( int  offset,
int  len 
)

Definition at line 230 of file rlppiclient.cpp.

231 {
232  return rlSharedMemory::read(offset,buf,len);
233 }
int read(unsigned long offset, void *buf, int len)
unsigned char buf[512]
Definition: rlppiclient.h:58

◆ Short()

int rlPPIClient::Short ( int  index)

Definition at line 277 of file rlppiclient.cpp.

278 {
279  SWAP swap;
280  if(index*2+2 > (int) BUFSIZE) return 0;
281  if(have_to_swap == 1)
282  {
283  swap.b[0] = buf[2*index+1];
284  swap.b[1] = buf[2*index];
285  }
286  else
287  {
288  swap.b[0] = buf[4*index];
289  swap.b[1] = buf[4*index+1];
290  }
291  return swap.s[0];
292 }
#define BUFSIZE
Definition: rlppiclient.cpp:19
short s[2]
Definition: rlppiclient.cpp:25
unsigned char buf[512]
Definition: rlppiclient.h:58
int have_to_swap
Definition: rlppiclient.h:60
unsigned char b[4]
Definition: rlppiclient.cpp:23

◆ UDword()

unsigned int rlPPIClient::UDword ( int  index)

Definition at line 294 of file rlppiclient.cpp.

295 {
296  SWAP swap;
297  if(index*4+4 > (int) BUFSIZE) return 0;
298  if(have_to_swap == 1)
299  {
300  swap.b[0] = buf[4*index+3];
301  swap.b[1] = buf[4*index+2];
302  swap.b[2] = buf[4*index+1];
303  swap.b[3] = buf[4*index];
304  }
305  else
306  {
307  swap.b[0] = buf[4*index];
308  swap.b[1] = buf[4*index+1];
309  swap.b[2] = buf[4*index+2];
310  swap.b[3] = buf[4*index+3];
311  }
312  return swap.ui;
313 }
unsigned int ui
Definition: rlppiclient.cpp:26
#define BUFSIZE
Definition: rlppiclient.cpp:19
unsigned char buf[512]
Definition: rlppiclient.h:58
int have_to_swap
Definition: rlppiclient.h:60
unsigned char b[4]
Definition: rlppiclient.cpp:23

◆ UShort()

unsigned int rlPPIClient::UShort ( int  index)

Definition at line 315 of file rlppiclient.cpp.

316 {
317  SWAP swap;
318  if(index*2+4 > (int) BUFSIZE) return 0;
319  if(have_to_swap == 1)
320  {
321  swap.b[0] = buf[2*index+1];
322  swap.b[1] = buf[2*index];
323  }
324  else
325  {
326  swap.b[0] = buf[4*index];
327  swap.b[1] = buf[4*index+1];
328  }
329  return swap.us[0];
330 }
#define BUFSIZE
Definition: rlppiclient.cpp:19
unsigned short us[2]
Definition: rlppiclient.cpp:24
unsigned char buf[512]
Definition: rlppiclient.h:58
int have_to_swap
Definition: rlppiclient.h:60
unsigned char b[4]
Definition: rlppiclient.cpp:23

◆ write()

int rlPPIClient::write ( int  slave,
int  area,
int  dbnum,
int  start,
int  len,
const unsigned char *  data 
)

Definition at line 41 of file rlppiclient.cpp.

42 {
43  unsigned char buf[BUFSIZE+8];
44 
45  if(len < 0) return -1;
46  if(len > BUFSIZE) return -1;
47  if(slave < 0) return -1;
48  if(slave > 31) return -1;
49 
50  buf[0] = slave;
51  buf[1] = area;
52  buf[2] = dbnum / 256;
53  buf[3] = dbnum & 0x0ff;
54  buf[4] = start / 256;
55  buf[5] = start & 0x0ff;
56  buf[6] = len / 256;
57  buf[7] = len & 0x0ff;
58  memcpy(&buf[8],data,len);
59  rlMailbox::write((void *) buf,len+8);
60  return 0;
61 }
#define BUFSIZE
Definition: rlppiclient.cpp:19
unsigned char buf[512]
Definition: rlppiclient.h:58
int write(const void *buf, int len)
Definition: rlmailbox.cpp:149

◆ writeDword()

int rlPPIClient::writeDword ( int  slave,
int  area,
int  dbnum,
int  start,
int  len,
const int *  val 
)

Definition at line 98 of file rlppiclient.cpp.

99 {
100  SWAP swap;
101  int i;
102  unsigned char buf[BUFSIZE];
103 
104  if(len < 0) return -1;
105  if(len > BUFSIZE) return -1;
106  if(slave < 0) return -1;
107  if(slave > 31) return -1;
108  if(have_to_swap == 1)
109  {
110  for(i=0; i<len; i+=4)
111  {
112  swap.i = val[i/4];
113  buf[i+3] = swap.b[0];
114  buf[i+2] = swap.b[1];
115  buf[i+1] = swap.b[2];
116  buf[i] = swap.b[3];
117  }
118  }
119  else
120  {
121  for(i=0; i<len; i+=4)
122  {
123  swap.i = val[i/4];
124  buf[i] = swap.b[0];
125  buf[i+1] = swap.b[1];
126  buf[i+2] = swap.b[2];
127  buf[i+3] = swap.b[3];
128  }
129  }
130  return write(slave,area,dbnum,start,len,buf);
131 }
#define BUFSIZE
Definition: rlppiclient.cpp:19
unsigned char buf[512]
Definition: rlppiclient.h:58
int write(int slave, int area, int dbnum, int start, int len, const unsigned char *data)
Definition: rlppiclient.cpp:41
int i
Definition: rlppiclient.cpp:27
int have_to_swap
Definition: rlppiclient.h:60
unsigned char b[4]
Definition: rlppiclient.cpp:23

◆ writeFloat()

int rlPPIClient::writeFloat ( int  slave,
int  area,
int  dbnum,
int  start,
int  len,
const float *  val 
)

Definition at line 63 of file rlppiclient.cpp.

64 {
65  SWAP swap;
66  int i;
67  unsigned char buf[BUFSIZE];
68 
69  if(len < 0) return -1;
70  if(len > BUFSIZE) return -1;
71  if(slave < 0) return -1;
72  if(slave > 31) return -1;
73  if(have_to_swap == 1)
74  {
75  for(i=0; i<len; i+=4)
76  {
77  swap.f = val[i/4];
78  buf[i+3] = swap.b[0];
79  buf[i+2] = swap.b[1];
80  buf[i+1] = swap.b[2];
81  buf[i] = swap.b[3];
82  }
83  }
84  else
85  {
86  for(i=0; i<len; i+=4)
87  {
88  swap.f = val[i/4];
89  buf[i] = swap.b[0];
90  buf[i+1] = swap.b[1];
91  buf[i+2] = swap.b[2];
92  buf[i+3] = swap.b[3];
93  }
94  }
95  return write(slave,area,dbnum,start,len,buf);
96 }
float f
Definition: rlppiclient.cpp:28
#define BUFSIZE
Definition: rlppiclient.cpp:19
unsigned char buf[512]
Definition: rlppiclient.h:58
int write(int slave, int area, int dbnum, int start, int len, const unsigned char *data)
Definition: rlppiclient.cpp:41
int have_to_swap
Definition: rlppiclient.h:60
unsigned char b[4]
Definition: rlppiclient.cpp:23

◆ writeShort()

int rlPPIClient::writeShort ( int  slave,
int  area,
int  dbnum,
int  start,
int  len,
const short *  val 
)

Definition at line 133 of file rlppiclient.cpp.

134 {
135  SWAP swap;
136  int i;
137  unsigned char buf[BUFSIZE];
138 
139  if(len < 0) return -1;
140  if(len > BUFSIZE) return -1;
141  if(slave < 0) return -1;
142  if(slave > 31) return -1;
143  if(have_to_swap == 1)
144  {
145  for(i=0; i<len; i+=2)
146  {
147  swap.s[0] = val[i/2];
148  buf[i+1] = swap.b[0];
149  buf[i] = swap.b[1];
150  }
151  }
152  else
153  {
154  for(i=0; i<len; i+=2)
155  {
156  swap.s[0] = val[i/2];
157  buf[i] = swap.b[0];
158  buf[i+1] = swap.b[1];
159  }
160  }
161  return write(slave,area,dbnum,start,len,buf);
162 }
#define BUFSIZE
Definition: rlppiclient.cpp:19
short s[2]
Definition: rlppiclient.cpp:25
unsigned char buf[512]
Definition: rlppiclient.h:58
int write(int slave, int area, int dbnum, int start, int len, const unsigned char *data)
Definition: rlppiclient.cpp:41
int have_to_swap
Definition: rlppiclient.h:60
unsigned char b[4]
Definition: rlppiclient.cpp:23

◆ writeUDword()

int rlPPIClient::writeUDword ( int  slave,
int  area,
int  dbnum,
int  start,
int  len,
const unsigned int *  val 
)

Definition at line 164 of file rlppiclient.cpp.

165 {
166  SWAP swap;
167  int i;
168  unsigned char buf[BUFSIZE];
169 
170  if(len < 0) return -1;
171  if(len > BUFSIZE) return -1;
172  if(slave < 0) return -1;
173  if(slave > 31) return -1;
174  if(have_to_swap == 1)
175  {
176  for(i=0; i<len; i+=4)
177  {
178  swap.ui = val[i/4];
179  buf[i+3] = swap.b[0];
180  buf[i+2] = swap.b[1];
181  buf[i+1] = swap.b[2];
182  buf[i] = swap.b[3];
183  }
184  }
185  else
186  {
187  for(i=0; i<len; i+=4)
188  {
189  swap.ui = val[i/4];
190  buf[i] = swap.b[0];
191  buf[i+1] = swap.b[1];
192  buf[i+2] = swap.b[2];
193  buf[i+3] = swap.b[3];
194  }
195  }
196  return write(slave,area,dbnum,start,len,buf);
197 }
unsigned int ui
Definition: rlppiclient.cpp:26
#define BUFSIZE
Definition: rlppiclient.cpp:19
unsigned char buf[512]
Definition: rlppiclient.h:58
int write(int slave, int area, int dbnum, int start, int len, const unsigned char *data)
Definition: rlppiclient.cpp:41
int have_to_swap
Definition: rlppiclient.h:60
unsigned char b[4]
Definition: rlppiclient.cpp:23

◆ writeUShort()

int rlPPIClient::writeUShort ( int  slave,
int  area,
int  dbnum,
int  start,
int  len,
const unsigned short *  val 
)

Definition at line 199 of file rlppiclient.cpp.

200 {
201  SWAP swap;
202  int i;
203  unsigned char buf[BUFSIZE];
204 
205  if(len < 0) return -1;
206  if(len > BUFSIZE) return -1;
207  if(slave < 0) return -1;
208  if(slave > 31) return -1;
209  if(have_to_swap == 1)
210  {
211  for(i=0; i<len; i+=2)
212  {
213  swap.us[0] = val[i/2];
214  buf[i+1] = swap.b[0];
215  buf[i] = swap.b[1];
216  }
217  }
218  else
219  {
220  for(i=0; i<len; i+=2)
221  {
222  swap.us[0] = val[i/2];
223  buf[i] = swap.b[0];
224  buf[i+1] = swap.b[1];
225  }
226  }
227  return write(slave,area,dbnum,start,len,buf);
228 }
#define BUFSIZE
Definition: rlppiclient.cpp:19
unsigned short us[2]
Definition: rlppiclient.cpp:24
unsigned char buf[512]
Definition: rlppiclient.h:58
int write(int slave, int area, int dbnum, int start, int len, const unsigned char *data)
Definition: rlppiclient.cpp:41
int have_to_swap
Definition: rlppiclient.h:60
unsigned char b[4]
Definition: rlppiclient.cpp:23

Member Data Documentation

◆ buf

unsigned char rlPPIClient::buf[512]

Definition at line 58 of file rlppiclient.h.

◆ have_to_swap

int rlPPIClient::have_to_swap
private

Definition at line 60 of file rlppiclient.h.


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