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

#include <rlsiemenstcpclient.h>

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

Public Types

enum  ORG {
  ORG_DB = 1, ORG_M = 2, ORG_E = 3, ORG_A = 4,
  ORG_PEPA = 5, ORG_Z = 6, ORG_T = 7
}
 
- 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

 rlSiemensTCPClient (const char *mbxname, const char *shmname, int shmsize, int have_to_swap=1)
 
virtual ~rlSiemensTCPClient ()
 
int write (int slave, int org, int dbnum, int start, int len, const unsigned char *buf, int function)
 
int writeBit (int slave, int org, int dbnum, int start, int offset, int len, const unsigned char *buf)
 
int writeByte (int slave, int org, int dbnum, int start, int len, const unsigned char *val)
 
int writeFloat (int slave, int org, int dbnum, int start, int len, const float *val)
 
int writeDword (int slave, int org, int dbnum, int start, int len, const int *val)
 
int writeShort (int slave, int org, int dbnum, int start, int len, const short *val)
 
int writeUDword (int slave, int org, int dbnum, int start, int len, const unsigned int *val)
 
int writeUShort (int slave, int org, 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 [2048]
 
- 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 within pvserver according to the pvbrowser principle.
The corresponding daemon is generated by pvdevelop.
It communicates by the means of a shared memory and a mailbox.

Definition at line 33 of file rlsiemenstcpclient.h.

Member Enumeration Documentation

◆ ORG

Enumerator
ORG_DB 
ORG_M 
ORG_E 
ORG_A 
ORG_PEPA 
ORG_Z 
ORG_T 

Definition at line 36 of file rlsiemenstcpclient.h.

Constructor & Destructor Documentation

◆ rlSiemensTCPClient()

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

Definition at line 35 of file rlsiemenstcpclient.cpp.

36  :rlMailbox(mbxname), rlSharedMemory(shmname, shmsize)
37 {
38  have_to_swap = _have_to_swap;
39 }
rlSharedMemory(const char *name, unsigned long size, int rwmode=0600)
rlMailbox(const char *name)
Definition: rlmailbox.cpp:55

◆ ~rlSiemensTCPClient()

rlSiemensTCPClient::~rlSiemensTCPClient ( )
virtual

Definition at line 41 of file rlsiemenstcpclient.cpp.

42 {
43 }

Member Function Documentation

◆ Dword()

int rlSiemensTCPClient::Dword ( int  index)

Definition at line 285 of file rlsiemenstcpclient.cpp.

286 {
287  SWAP swap;
288  if(index*4+4 > (int) BUFSIZE) return 0;
289  if(have_to_swap == 1)
290  {
291  swap.b[0] = buf[4*index+3];
292  swap.b[1] = buf[4*index+2];
293  swap.b[2] = buf[4*index+1];
294  swap.b[3] = buf[4*index];
295  }
296  else
297  {
298  swap.b[0] = buf[4*index];
299  swap.b[1] = buf[4*index+1];
300  swap.b[2] = buf[4*index+2];
301  swap.b[3] = buf[4*index+3];
302  }
303  return swap.i;
304 }
#define BUFSIZE
unsigned char buf[2048]
int i
Definition: rlppiclient.cpp:27
unsigned char b[4]
Definition: rlppiclient.cpp:23

◆ Float()

float rlSiemensTCPClient::Float ( int  index)

Definition at line 264 of file rlsiemenstcpclient.cpp.

265 {
266  SWAP swap;
267  if(index*4+4 > (int) BUFSIZE) return 0.0f;
268  if(have_to_swap == 1)
269  {
270  swap.b[0] = buf[4*index+3];
271  swap.b[1] = buf[4*index+2];
272  swap.b[2] = buf[4*index+1];
273  swap.b[3] = buf[4*index];
274  }
275  else
276  {
277  swap.b[0] = buf[4*index];
278  swap.b[1] = buf[4*index+1];
279  swap.b[2] = buf[4*index+2];
280  swap.b[3] = buf[4*index+3];
281  }
282  return swap.f;
283 }
float f
Definition: rlppiclient.cpp:28
#define BUFSIZE
unsigned char buf[2048]
unsigned char b[4]
Definition: rlppiclient.cpp:23

◆ read()

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

Definition at line 259 of file rlsiemenstcpclient.cpp.

260 {
261  return rlSharedMemory::read(offset,buf,len);
262 }
int read(unsigned long offset, void *buf, int len)
unsigned char buf[2048]

◆ Short()

int rlSiemensTCPClient::Short ( int  index)

Definition at line 306 of file rlsiemenstcpclient.cpp.

307 {
308  SWAP swap;
309  if(index*2+2 > (int) BUFSIZE) return 0;
310  if(have_to_swap == 1)
311  {
312  swap.b[0] = buf[2*index+1];
313  swap.b[1] = buf[2*index];
314  }
315  else
316  {
317  swap.b[0] = buf[2*index];
318  swap.b[1] = buf[2*index+1];
319  }
320  return swap.s[0];
321 }
#define BUFSIZE
unsigned char buf[2048]
short s[2]
Definition: rlppiclient.cpp:25
unsigned char b[4]
Definition: rlppiclient.cpp:23

◆ UDword()

unsigned int rlSiemensTCPClient::UDword ( int  index)

Definition at line 323 of file rlsiemenstcpclient.cpp.

324 {
325  SWAP swap;
326  if(index*4+4 > (int) BUFSIZE) return 0;
327  if(have_to_swap == 1)
328  {
329  swap.b[0] = buf[4*index+3];
330  swap.b[1] = buf[4*index+2];
331  swap.b[2] = buf[4*index+1];
332  swap.b[3] = buf[4*index];
333  }
334  else
335  {
336  swap.b[0] = buf[4*index];
337  swap.b[1] = buf[4*index+1];
338  swap.b[2] = buf[4*index+2];
339  swap.b[3] = buf[4*index+3];
340  }
341  return swap.ui;
342 }
unsigned int ui
Definition: rlppiclient.cpp:26
#define BUFSIZE
unsigned char buf[2048]
unsigned char b[4]
Definition: rlppiclient.cpp:23

◆ UShort()

unsigned int rlSiemensTCPClient::UShort ( int  index)

Definition at line 344 of file rlsiemenstcpclient.cpp.

345 {
346  SWAP swap;
347  if(index*2+4 > (int) BUFSIZE) return 0;
348  if(have_to_swap == 1)
349  {
350  swap.b[0] = buf[2*index+1];
351  swap.b[1] = buf[2*index];
352  }
353  else
354  {
355  swap.b[0] = buf[2*index];
356  swap.b[1] = buf[2*index+1];
357  }
358  return swap.us[0];
359 }
#define BUFSIZE
unsigned short us[2]
Definition: rlppiclient.cpp:24
unsigned char buf[2048]
unsigned char b[4]
Definition: rlppiclient.cpp:23

◆ write()

int rlSiemensTCPClient::write ( int  slave,
int  org,
int  dbnum,
int  start,
int  len,
const unsigned char *  buf,
int  function = rlSiemensTCP::WriteByte 
)

Definition at line 45 of file rlsiemenstcpclient.cpp.

46 {
47  unsigned char buf[BUFSIZE+8];
48  int len_byte;
49 
50  if(len <= 0) return -1;
51  if(slave < 0) return -1;
52  if(slave >= 256) return -1;
53  len_byte = len;
54  buf[0] = slave;
55  buf[1] = org;
56  buf[2] = dbnr / 256;
57  buf[3] = dbnr & 0x0ff;
58  buf[4] = start_adr / 256;
59  buf[5] = start_adr & 0x0ff;
60  buf[6] = len / 256;
61  buf[7] = len & 0x0ff;
62  buf[8] = function;
63  memcpy(&buf[9],inbuf,len_byte);
64  rlMailbox::write((void *) buf, len_byte + 9);
65  return 0;
66 }
#define BUFSIZE
unsigned char buf[2048]
int write(const void *buf, int len)
Definition: rlmailbox.cpp:149

◆ writeBit()

int rlSiemensTCPClient::writeBit ( int  slave,
int  org,
int  dbnum,
int  start,
int  offset,
int  len,
const unsigned char *  buf 
)

Definition at line 68 of file rlsiemenstcpclient.cpp.

69 {
70  if(len < 0) return -1;
71  if(len > BUFSIZE) return -1;
72  if(slave < 0) return -1;
73  if(slave > 255) return -1;
74  int start_adr = start * 8 + offset;
75  return write(slave,org,dbnum,start_adr,len,val,rlSiemensTCP::WriteBit);
76 }
int write(int slave, int org, int dbnum, int start, int len, const unsigned char *buf, int function)
#define BUFSIZE

◆ writeByte()

int rlSiemensTCPClient::writeByte ( int  slave,
int  org,
int  dbnum,
int  start,
int  len,
const unsigned char *  val 
)

Definition at line 78 of file rlsiemenstcpclient.cpp.

79 {
80  if(len < 0) return -1;
81  if(len > BUFSIZE) return -1;
82  if(slave < 0) return -1;
83  if(slave > 255) return -1;
84  return write(slave,org,dbnum,start,len,val,rlSiemensTCP::WriteByte);
85 }
int write(int slave, int org, int dbnum, int start, int len, const unsigned char *buf, int function)
#define BUFSIZE

◆ writeDword()

int rlSiemensTCPClient::writeDword ( int  slave,
int  org,
int  dbnum,
int  start,
int  len,
const int *  val 
)

Definition at line 123 of file rlsiemenstcpclient.cpp.

124 {
125  SWAP swap;
126  int i,len_byte;
127  unsigned char buf[BUFSIZE];
128 
129  len_byte = len * 4;
130  if(len_byte < 0) return -1;
131  if(len_byte > BUFSIZE) return -1;
132  if(slave < 0) return -1;
133  if(slave > 255) return -1;
134  if(have_to_swap == 1)
135  {
136  for(i=0; i<len_byte; i+=4)
137  {
138  swap.i = val[i/4];
139  buf[i+3] = swap.b[0];
140  buf[i+2] = swap.b[1];
141  buf[i+1] = swap.b[2];
142  buf[i] = swap.b[3];
143  }
144  }
145  else
146  {
147  for(i=0; i<len_byte; i+=4)
148  {
149  swap.i = val[i/4];
150  buf[i] = swap.b[0];
151  buf[i+1] = swap.b[1];
152  buf[i+2] = swap.b[2];
153  buf[i+3] = swap.b[3];
154  }
155  }
156  return write(slave,org,dbnum,start,len_byte,buf,rlSiemensTCP::WriteByte);
157 }
int write(int slave, int org, int dbnum, int start, int len, const unsigned char *buf, int function)
#define BUFSIZE
unsigned char buf[2048]
int i
Definition: rlppiclient.cpp:27
unsigned char b[4]
Definition: rlppiclient.cpp:23

◆ writeFloat()

int rlSiemensTCPClient::writeFloat ( int  slave,
int  org,
int  dbnum,
int  start,
int  len,
const float *  val 
)

Definition at line 87 of file rlsiemenstcpclient.cpp.

88 {
89  SWAP swap;
90  int i,len_byte;
91  unsigned char buf[BUFSIZE];
92 
93  len_byte = len * 4;
94  if(len_byte < 0) return -1;
95  if(len_byte > BUFSIZE) return -1;
96  if(slave < 0) return -1;
97  if(slave > 255) return -1;
98  if(have_to_swap == 1)
99  {
100  for(i=0; i<len_byte; i+=4)
101  {
102  swap.f = val[i/4];
103  buf[i+3] = swap.b[0];
104  buf[i+2] = swap.b[1];
105  buf[i+1] = swap.b[2];
106  buf[i] = swap.b[3];
107  }
108  }
109  else
110  {
111  for(i=0; i<len_byte; i+=4)
112  {
113  swap.f = val[i/4];
114  buf[i] = swap.b[0];
115  buf[i+1] = swap.b[1];
116  buf[i+2] = swap.b[2];
117  buf[i+3] = swap.b[3];
118  }
119  }
120  return write(slave,org,dbnum,start,len_byte,buf,rlSiemensTCP::WriteByte);
121 }
float f
Definition: rlppiclient.cpp:28
int write(int slave, int org, int dbnum, int start, int len, const unsigned char *buf, int function)
#define BUFSIZE
unsigned char buf[2048]
unsigned char b[4]
Definition: rlppiclient.cpp:23

◆ writeShort()

int rlSiemensTCPClient::writeShort ( int  slave,
int  org,
int  dbnum,
int  start,
int  len,
const short *  val 
)

Definition at line 159 of file rlsiemenstcpclient.cpp.

160 {
161  SWAP swap;
162  int i,len_byte;
163  unsigned char buf[BUFSIZE];
164 
165  len_byte = len * 2;
166  if(len_byte < 0) return -1;
167  if(len_byte > BUFSIZE) return -1;
168  if(slave < 0) return -1;
169  if(slave > 255) return -1;
170  if(have_to_swap == 1)
171  {
172  for(i=0; i<len_byte; i+=2)
173  {
174  swap.s[0] = val[i/2];
175  buf[i+1] = swap.b[0];
176  buf[i] = swap.b[1];
177  }
178  }
179  else
180  {
181  for(i=0; i<len_byte; i+=2)
182  {
183  swap.s[0] = val[i/2];
184  buf[i] = swap.b[0];
185  buf[i+1] = swap.b[1];
186  }
187  }
188  return write(slave,org,dbnum,start,len_byte,buf,rlSiemensTCP::WriteByte);
189 }
int write(int slave, int org, int dbnum, int start, int len, const unsigned char *buf, int function)
#define BUFSIZE
unsigned char buf[2048]
short s[2]
Definition: rlppiclient.cpp:25
unsigned char b[4]
Definition: rlppiclient.cpp:23

◆ writeUDword()

int rlSiemensTCPClient::writeUDword ( int  slave,
int  org,
int  dbnum,
int  start,
int  len,
const unsigned int *  val 
)

Definition at line 191 of file rlsiemenstcpclient.cpp.

192 {
193  SWAP swap;
194  int i,len_byte;
195  unsigned char buf[BUFSIZE];
196 
197  len_byte = len * 4;
198  if(len_byte < 0) return -1;
199  if(len_byte > BUFSIZE) return -1;
200  if(slave < 0) return -1;
201  if(slave > 255) return -1;
202  if(have_to_swap == 1)
203  {
204  for(i=0; i<len_byte; i+=4)
205  {
206  swap.ui = val[i/4];
207  buf[i+3] = swap.b[0];
208  buf[i+2] = swap.b[1];
209  buf[i+1] = swap.b[2];
210  buf[i] = swap.b[3];
211  }
212  }
213  else
214  {
215  for(i=0; i<len_byte; i+=4)
216  {
217  swap.ui = val[i/4];
218  buf[i] = swap.b[0];
219  buf[i+1] = swap.b[1];
220  buf[i+2] = swap.b[2];
221  buf[i+3] = swap.b[3];
222  }
223  }
224  return write(slave,org,dbnum,start,len_byte,buf,rlSiemensTCP::WriteByte);
225 }
unsigned int ui
Definition: rlppiclient.cpp:26
int write(int slave, int org, int dbnum, int start, int len, const unsigned char *buf, int function)
#define BUFSIZE
unsigned char buf[2048]
unsigned char b[4]
Definition: rlppiclient.cpp:23

◆ writeUShort()

int rlSiemensTCPClient::writeUShort ( int  slave,
int  org,
int  dbnum,
int  start,
int  len,
const unsigned short *  val 
)

Definition at line 227 of file rlsiemenstcpclient.cpp.

228 {
229  SWAP swap;
230  int i,len_byte;
231  unsigned char buf[BUFSIZE];
232 
233  len_byte = len * 2;
234  if(len_byte < 0) return -1;
235  if(len_byte > BUFSIZE) return -1;
236  if(slave < 0) return -1;
237  if(slave > 255) return -1;
238  if(have_to_swap == 1)
239  {
240  for(i=0; i<len_byte; i+=2)
241  {
242  swap.us[0] = val[i/2];
243  buf[i+1] = swap.b[0];
244  buf[i] = swap.b[1];
245  }
246  }
247  else
248  {
249  for(i=0; i<len_byte; i+=2)
250  {
251  swap.us[0] = val[i/2];
252  buf[i] = swap.b[0];
253  buf[i+1] = swap.b[1];
254  }
255  }
256  return write(slave,org,dbnum,start,len_byte,buf,rlSiemensTCP::WriteByte);
257 }
int write(int slave, int org, int dbnum, int start, int len, const unsigned char *buf, int function)
#define BUFSIZE
unsigned short us[2]
Definition: rlppiclient.cpp:24
unsigned char buf[2048]
unsigned char b[4]
Definition: rlppiclient.cpp:23

Member Data Documentation

◆ buf

unsigned char rlSiemensTCPClient::buf[2048]

Definition at line 62 of file rlsiemenstcpclient.h.

◆ have_to_swap

int rlSiemensTCPClient::have_to_swap
private

Definition at line 64 of file rlsiemenstcpclient.h.


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