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

Class performs API rlcanopen functions remotely through tcp sockets. More...

#include <rlcanopenclient.h>

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

Public Types

enum  rl_msg {
  MSG_SEND = 0, MSG_RECEIVE = 1, MSG_SDO_READ = 0, MSG_SDO_WRITE = 1,
  MSG_PDO_RECEIVE = 3, MSG_CONNECT = 5, MSG_DISCONNECT = 6, MSG_PDO_TRANSMIT = 4,
  MSG_NMT_TRANSMIT = 7, MSG_RESTART_BOARD = 8, MSG_GET_NODE_STATE = 9
}
 

Public Member Functions

 rlCanOpenClient ()
 initializes the client on localhost port 5000 More...
 
 rlCanOpenClient (int _port, char *_remoteadress)
 initializes the client on given port and remove server adress More...
 
 ~rlCanOpenClient ()
 destructor disconnects client More...
 
int connect ()
 opens a new connection to a running rlCanOpenDaemon More...
 
int disconnect ()
 disconnects from daemon More...
 
int sdo_read (int _boardnr, int _nodeid, int _objectindex, int _subindex, rlCanOpenTypes &_sdo_data)
 remotely reads a certain object from the object dictionary of a node. More...
 
int sdo_write (int _boardnr, int _nodeid, int _objectindex, int _subindex, rlCanOpenTypes &_sdo_data)
 remotely writes data into a certain object from the object dictionary of a node More...
 
int pdo_receive (int _boardnr, int _nodeid, int _pdonr, int _mappingnr, rlCanOpenTypes &_pdo_data)
 receives single mapped pdo object from daemon. More...
 
int pdo_receive (int _boardnr, int _nodeid, int _pdonr, rlCanOpenTypes &_pdo_data)
 receives an 8 byte pdo from daemon. More...
 
int pdo_transmit (int _boardnr, int _nodeid, int _pdonr, int _mappingnr, rlCanOpenTypes &_pdo_data)
 sends a single mapped pdo object to daemon. More...
 
int pdo_transmit (int _boardnr, int _nodeid, int _pdonr, rlCanOpenTypes &_pdo_data)
 sends an 8 byte pdo to daemon. More...
 
int sendNMTCommand (int _boardnr, int _nodeid, unsigned char _cmd, bool &returnstate)
 sends a NMT command to daemon. More...
 
int restartBoard (int _boardnr, int _restarttype, bool &returnstate)
 forces daemon to restart canopen device. More...
 
int getNodeState (int _boardnr, int _nodeid, rlCanOpenTypes &_data)
 receives node state data of particular node from daemon. More...
 
void setPort (int _port)
 setter for private port variable More...
 
void setAdr (char *_adr)
 setter for private remoteadress variable More...
 

Private Attributes

int pid
 variable contains process id More...
 
bool connected
 flag indicates connection status More...
 
int port
 variable contains port More...
 
char remoteadress [40]
 string of remoteadress More...
 
rlSocketsocket
 pointer to socket object More...
 
int client_timeout
 timeout in ms More...
 

Detailed Description

Class performs API rlcanopen functions remotely through tcp sockets.

this class provides the client API funcions which should be similar to the rlcanopen API. Main difference is that underlying code does not communicate with the canopen device itself but with a rlcanopendaemon, which should run in backbround or on an remote computer.

Definition at line 34 of file rlcanopenclient.h.

Member Enumeration Documentation

◆ rl_msg

Enumerator
MSG_SEND 
MSG_RECEIVE 
MSG_SDO_READ 
MSG_SDO_WRITE 
MSG_PDO_RECEIVE 
MSG_CONNECT 
MSG_DISCONNECT 
MSG_PDO_TRANSMIT 
MSG_NMT_TRANSMIT 
MSG_RESTART_BOARD 
MSG_GET_NODE_STATE 

Definition at line 38 of file rlcanopenclient.h.

Constructor & Destructor Documentation

◆ rlCanOpenClient() [1/2]

rlCanOpenClient::rlCanOpenClient ( )

initializes the client on localhost port 5000

initializes the client on port 5000

Definition at line 96 of file rlcanopenclient.cpp.

97 {
98  connected = false;
99  //cout<<"rlCanOpenClient Konstrukter erfolgreich aufgerufen\n";
100  port=5000;
101  strcpy(remoteadress, "localhost");
102  pid=getpid();
103  client_timeout=1000;
104  socket = new rlSocket(remoteadress,port,1);
105 }
char remoteadress[40]
string of remoteadress
rlSocket * socket
pointer to socket object
int pid
variable contains process id
bool connected
flag indicates connection status
int port
variable contains port
int client_timeout
timeout in ms

◆ rlCanOpenClient() [2/2]

rlCanOpenClient::rlCanOpenClient ( int  _port,
char *  _remoteadress 
)

initializes the client on given port and remove server adress

Definition at line 108 of file rlcanopenclient.cpp.

109 {
110  connected = false;
111  //cout<<"Konstrukter erfolgreich aufgerufen\n";
112  port=_port;
113  pid=getpid();
114  client_timeout=1000;
115  strcpy(remoteadress, _remoteadress);
116  socket = new rlSocket(remoteadress,port,1);
117 }
char remoteadress[40]
string of remoteadress
rlSocket * socket
pointer to socket object
int pid
variable contains process id
bool connected
flag indicates connection status
int port
variable contains port
int client_timeout
timeout in ms

◆ ~rlCanOpenClient()

rlCanOpenClient::~rlCanOpenClient ( )

destructor disconnects client

Definition at line 120 of file rlcanopenclient.cpp.

121 {
122  //printf("Destruktor rlCanOpenClient\n");
123  if (connected == true){
124  disconnect();
125  }
126  if (socket!=0){
127  delete socket;
128  }
129 }
int disconnect()
disconnects from daemon
rlSocket * socket
pointer to socket object
bool connected
flag indicates connection status

Member Function Documentation

◆ connect()

int rlCanOpenClient::connect ( )

opens a new connection to a running rlCanOpenDaemon

Definition at line 132 of file rlcanopenclient.cpp.

133 {
134 
136  socket->setPort(port);
137  socket->setActive(1);
138 
139  socket->connect();
141 
142  if(socket->isConnected() == 0) {
143  printf("no connection to server!\n");
144  return 0;
145  }
146  cout<<"connection established...\n";
147  return 1;
148 }
void setActive(int active)
Definition: rlsocket.cpp:186
char remoteadress[40]
string of remoteadress
void setPort(int port)
Definition: rlsocket.cpp:176
rlSocket * socket
pointer to socket object
bool connected
flag indicates connection status
int port
variable contains port
int connect()
Definition: rlsocket.cpp:321
int isConnected()
Definition: rlsocket.cpp:559
void setAdr(const char *adr)
Definition: rlsocket.cpp:168

◆ disconnect()

int rlCanOpenClient::disconnect ( )

disconnects from daemon

Definition at line 151 of file rlcanopenclient.cpp.

152 {
153  if (socket!=NULL){
154  printf("disconnection...\n");
155  socket->disconnect();
156  connected=false;
157  }
158  return 1;
159 }
rlSocket * socket
pointer to socket object
bool connected
flag indicates connection status
int disconnect()
Definition: rlsocket.cpp:545

◆ getNodeState()

int rlCanOpenClient::getNodeState ( int  _boardnr,
int  _nodeid,
rlCanOpenTypes _data 
)

receives node state data of particular node from daemon.

receives node state data of particular node from daemon.

Definition at line 418 of file rlcanopenclient.cpp.

420  {
421  int ret;
422  IPCMSGSTRUCT message;
423  if (connected){
424  message = _data.createIpcMsg();
425  message.msgtype = MSG_GET_NODE_STATE;
426  message.transfertype = MSG_SEND;
427  message.processid = pid;
428  message.boardid = _boardnr;
429  message.nodeid=_nodeid;
430  message.objectindex=0;
431  message.subindex=0;
432  message.pdoid=0;
433  message.mappingid=0;
434 
435  if(socket->isConnected() == 0)
436  if ( connect() == 0 )
437  return 0;
438 
439  socket->write((void*) &message, sizeof(message));
440  ret = socket->read((void*) &message,sizeof(message),client_timeout);
441  if(ret <= 0) // timeout
442  {
443  return 0;
444  }
445  _data.getIpcMsg(message);
446  }
447  else
448  {
449  return 0;
450  }
451  return 1;
452 }
int write(const void *buf, int len)
Definition: rlsocket.cpp:292
the IPCMSGSTRUCT is the transfer buffer which is send trough TCP sockets
void getIpcMsg(IPCMSGSTRUCT _myIpcMsg)
overwrites all data with IPCMSGSTRUCT data
int read(void *buf, int len, int timeout=0)
Definition: rlsocket.cpp:191
rlSocket * socket
pointer to socket object
int pid
variable contains process id
int connect()
opens a new connection to a running rlCanOpenDaemon
bool connected
flag indicates connection status
IPCMSGSTRUCT createIpcMsg()
returns a IPCMSGSTRUCT filled with current object data
int isConnected()
Definition: rlsocket.cpp:559
int client_timeout
timeout in ms

◆ pdo_receive() [1/2]

int rlCanOpenClient::pdo_receive ( int  _boardnr,
int  _nodeid,
int  _pdonr,
int  _mappingnr,
rlCanOpenTypes _pdo_data 
)

receives single mapped pdo object from daemon.

receives single mapped pdo object from daemon. Function will return NULL if connection to daemon broke down. CanOpen interface related errors are accessable in _sdo_data.get_rlmsgerr()

Definition at line 242 of file rlcanopenclient.cpp.

247 {
248  int ret;
249  IPCMSGSTRUCT message;
250  if (connected){
251  message.msgtype = MSG_PDO_RECEIVE;
252  message.transfertype = MSG_SEND;
253  message.processid = pid;
254  message.boardid = _boardnr;
255  message.nodeid=_nodeid;
256  message.objectindex=0;
257  message.subindex=0;
258  message.pdoid=_pdonr;
259  message.mappingid=_mappingnr;
260 
261  if(socket->isConnected() == 0)
262  if ( connect() == 0 )
263  return 0;
264 
265  socket->write((void*) &message, sizeof(message));
266  ret = socket->read((void*) &message,sizeof(message),client_timeout);
267  if(ret <= 0) // timeout
268  {
269  return 0;
270  }
271  _pdo_data.getIpcMsg(message);
272  }
273  else
274  {
275  return 0;
276  }
277  return 1;
278 }
int write(const void *buf, int len)
Definition: rlsocket.cpp:292
the IPCMSGSTRUCT is the transfer buffer which is send trough TCP sockets
void getIpcMsg(IPCMSGSTRUCT _myIpcMsg)
overwrites all data with IPCMSGSTRUCT data
int read(void *buf, int len, int timeout=0)
Definition: rlsocket.cpp:191
rlSocket * socket
pointer to socket object
int pid
variable contains process id
int connect()
opens a new connection to a running rlCanOpenDaemon
bool connected
flag indicates connection status
int isConnected()
Definition: rlsocket.cpp:559
int client_timeout
timeout in ms

◆ pdo_receive() [2/2]

int rlCanOpenClient::pdo_receive ( int  _boardnr,
int  _nodeid,
int  _pdonr,
rlCanOpenTypes _pdo_data 
)

receives an 8 byte pdo from daemon.

receives an 8 byte pdo from daemon.
Function will return NULL if connection to daemon broke down. CanOpen interface related errors are accessable in _sdo_data.get_rlmsgerr()

Definition at line 281 of file rlcanopenclient.cpp.

285 {
286  int ret = pdo_receive(_boardnr, _nodeid, _pdonr, -1, _pdo_data);
287  return ret;
288 }
int pdo_receive(int _boardnr, int _nodeid, int _pdonr, int _mappingnr, rlCanOpenTypes &_pdo_data)
receives single mapped pdo object from daemon.

◆ pdo_transmit() [1/2]

int rlCanOpenClient::pdo_transmit ( int  _boardnr,
int  _nodeid,
int  _pdonr,
int  _mappingnr,
rlCanOpenTypes _pdo_data 
)

sends a single mapped pdo object to daemon.

sends a single mapped pdo object to daemon.
Function will return NULL if connection to daemon broke down. CanOpen interface related errors are accessable in _pdo_data.get_rlmsgerr()

Definition at line 292 of file rlcanopenclient.cpp.

297 {
298  int ret;
299  IPCMSGSTRUCT message;
300  if (connected){
301  message = _pdo_data.createIpcMsg();
302  message.msgtype = MSG_PDO_TRANSMIT;
303  message.transfertype = MSG_SEND;
304  message.processid = pid;
305  message.boardid = _boardnr;
306  message.nodeid=_nodeid;
307  message.objectindex=0;
308  message.subindex=0;
309  message.pdoid=_pdonr;
310  message.mappingid=_mappingnr;
311 
312  if(socket->isConnected() == 0)
313  if ( connect() == 0 )
314  return 0;
315 
316  socket->write((void*) &message, sizeof(message));
317  ret = socket->read((void*) &message,sizeof(message),client_timeout);
318  if(ret <= 0) // timeout
319  {
320  return 0;
321  }
322  _pdo_data.getIpcMsg(message);
323  }
324  else
325  {
326  return 0;
327  }
328  return 1;
329 }
int write(const void *buf, int len)
Definition: rlsocket.cpp:292
the IPCMSGSTRUCT is the transfer buffer which is send trough TCP sockets
void getIpcMsg(IPCMSGSTRUCT _myIpcMsg)
overwrites all data with IPCMSGSTRUCT data
int read(void *buf, int len, int timeout=0)
Definition: rlsocket.cpp:191
rlSocket * socket
pointer to socket object
int pid
variable contains process id
int connect()
opens a new connection to a running rlCanOpenDaemon
bool connected
flag indicates connection status
IPCMSGSTRUCT createIpcMsg()
returns a IPCMSGSTRUCT filled with current object data
int isConnected()
Definition: rlsocket.cpp:559
int client_timeout
timeout in ms

◆ pdo_transmit() [2/2]

int rlCanOpenClient::pdo_transmit ( int  _boardnr,
int  _nodeid,
int  _pdonr,
rlCanOpenTypes _pdo_data 
)

sends an 8 byte pdo to daemon.

sends an 8 byte pdo to daemon.
Function will return NULL if connection to daemon broke down. CanOpen interface related errors are accessable in _pdo_data.get_rlmsgerr()

Definition at line 333 of file rlcanopenclient.cpp.

337 {
338  return pdo_transmit(_boardnr, _nodeid, _pdonr, -1, _pdo_data);
339 }
int pdo_transmit(int _boardnr, int _nodeid, int _pdonr, int _mappingnr, rlCanOpenTypes &_pdo_data)
sends a single mapped pdo object to daemon.

◆ restartBoard()

int rlCanOpenClient::restartBoard ( int  _boardnr,
int  _restarttype,
bool &  returnstate 
)

forces daemon to restart canopen device.

forces daemon to restart canopen device.

Definition at line 381 of file rlcanopenclient.cpp.

383  {
384  int ret;
385  IPCMSGSTRUCT message;
386  if (connected){
387  message.mtext[0] = (char) _restarttype;
388  message.msgtype = MSG_RESTART_BOARD;
389  message.transfertype = MSG_SEND;
390  message.processid = pid;
391  message.boardid = _boardnr;
392  message.nodeid=0;
393  message.objectindex=0;
394  message.subindex=0;
395  message.pdoid=0;
396  message.mappingid=0;
397 
398  if(socket->isConnected() == 0)
399  if ( connect() == 0 )
400  return 0;
401 
402  socket->write((void*) &message, sizeof(message));
403  ret = socket->read((void*) &message,sizeof(message),client_timeout);
404  if(ret <= 0) // timeout
405  {
406  return 0;
407  }
408  }
409  else
410  {
411  return 0;
412  }
413  returnstate = (bool) message.transfertype;
414  return 1;
415 }
int write(const void *buf, int len)
Definition: rlsocket.cpp:292
the IPCMSGSTRUCT is the transfer buffer which is send trough TCP sockets
char mtext[247]
int read(void *buf, int len, int timeout=0)
Definition: rlsocket.cpp:191
rlSocket * socket
pointer to socket object
int pid
variable contains process id
int connect()
opens a new connection to a running rlCanOpenDaemon
bool connected
flag indicates connection status
int isConnected()
Definition: rlsocket.cpp:559
int client_timeout
timeout in ms

◆ sdo_read()

int rlCanOpenClient::sdo_read ( int  _boardnr,
int  _nodeid,
int  _objectindex,
int  _subindex,
rlCanOpenTypes _sdo_data 
)

remotely reads a certain object from the object dictionary of a node.

using the sdo_read function you can read a certain object from the object dictionary of a node. Function will return NULL if connection to daemon broke down. CanOpen interface related errors are accessable in _sdo_data.get_rlmsgerr()

Definition at line 163 of file rlcanopenclient.cpp.

168 {
169  int ret;
170  IPCMSGSTRUCT message;
171  if (connected){
172  message.msgtype = MSG_SDO_READ;
173  message.transfertype = MSG_SEND;
174  message.processid = pid;
175  message.boardid = _boardnr;
176  message.nodeid=_nodeid;
177  message.objectindex=_objectindex;
178  message.subindex=_subindex;
179 
180  if(socket->isConnected() == 0)
181  if ( connect() == 0 )
182  return 0;
183 
184  socket->write((void*) &message, sizeof(message));
185 
186  ret = socket->read((void*) &message,sizeof(message),client_timeout);
187  if(ret <= 0) // timeout
188  {
189  return 0;
190  }
191  _sdo_data.getIpcMsg(message);
192  }
193  else
194  {
195  return 0;
196  }
197  return 1;
198 }
int write(const void *buf, int len)
Definition: rlsocket.cpp:292
the IPCMSGSTRUCT is the transfer buffer which is send trough TCP sockets
void getIpcMsg(IPCMSGSTRUCT _myIpcMsg)
overwrites all data with IPCMSGSTRUCT data
int read(void *buf, int len, int timeout=0)
Definition: rlsocket.cpp:191
rlSocket * socket
pointer to socket object
int pid
variable contains process id
int connect()
opens a new connection to a running rlCanOpenDaemon
bool connected
flag indicates connection status
int isConnected()
Definition: rlsocket.cpp:559
int client_timeout
timeout in ms

◆ sdo_write()

int rlCanOpenClient::sdo_write ( int  _boardnr,
int  _nodeid,
int  _objectindex,
int  _subindex,
rlCanOpenTypes _sdo_data 
)

remotely writes data into a certain object from the object dictionary of a node

using the sdo_write function you can write to a certain object from the object dictionary of a node Function will return NULL if connection to daemon broke down. CanOpen interface related errors are accessable in _sdo_data.get_rlmsgerr()

Definition at line 201 of file rlcanopenclient.cpp.

206 {
207  int ret;
208  IPCMSGSTRUCT message;
209  if (connected){
210  message = _sdo_data.createIpcMsg();
211  message.msgtype = MSG_SDO_WRITE;
212  message.transfertype = MSG_SEND;
213  message.processid = pid;
214  message.boardid = _boardnr;
215  message.nodeid=_nodeid;
216  message.objectindex=_objectindex;
217  message.subindex=_subindex;
218 
219  if(socket->isConnected() == 0)
220  if ( connect() == 0 )
221  return 0;
222 
223 
224  socket->write((void*) &message, sizeof(message));
225 
226  // recieve answer to check if write was successfull
227  ret = socket->read((void*) &message,sizeof(message),client_timeout);
228  if(ret <= 0) // timeout
229  {
230  return 0;
231  }
232  _sdo_data.getIpcMsg(message);
233  }
234  else
235  {
236  return 0;
237  }
238  return 1;
239 }
int write(const void *buf, int len)
Definition: rlsocket.cpp:292
the IPCMSGSTRUCT is the transfer buffer which is send trough TCP sockets
void getIpcMsg(IPCMSGSTRUCT _myIpcMsg)
overwrites all data with IPCMSGSTRUCT data
int read(void *buf, int len, int timeout=0)
Definition: rlsocket.cpp:191
rlSocket * socket
pointer to socket object
int pid
variable contains process id
int connect()
opens a new connection to a running rlCanOpenDaemon
bool connected
flag indicates connection status
IPCMSGSTRUCT createIpcMsg()
returns a IPCMSGSTRUCT filled with current object data
int isConnected()
Definition: rlsocket.cpp:559
int client_timeout
timeout in ms

◆ sendNMTCommand()

int rlCanOpenClient::sendNMTCommand ( int  _boardnr,
int  _nodeid,
unsigned char  _cmd,
bool &  returnstate 
)

sends a NMT command to daemon.

sends a NMT command to daemon.

Definition at line 342 of file rlcanopenclient.cpp.

345  {
346  int ret;
347  IPCMSGSTRUCT message;
348  if (connected){
349  message.mtext[0] = _cmd;
350  message.msgtype = MSG_NMT_TRANSMIT;
351  message.transfertype = MSG_SEND;
352  message.processid = pid;
353  message.boardid = _boardnr;
354  message.nodeid=_nodeid;
355  message.objectindex=0;
356  message.subindex=0;
357  message.pdoid=0;
358  message.mappingid=0;
359 
360  if(socket->isConnected() == 0)
361  if ( connect() == 0 )
362  return 0;
363 
364  socket->write((void*) &message, sizeof(message));
365  ret = socket->read((void*) &message,sizeof(message),client_timeout);
366  if(ret <= 0) // timeout
367  {
368  return 0;
369  }
370  }
371  else
372  {
373  return 0;
374  }
375  returnstate = (bool) message.transfertype;
376  return 1;
377 }
int write(const void *buf, int len)
Definition: rlsocket.cpp:292
the IPCMSGSTRUCT is the transfer buffer which is send trough TCP sockets
char mtext[247]
int read(void *buf, int len, int timeout=0)
Definition: rlsocket.cpp:191
rlSocket * socket
pointer to socket object
int pid
variable contains process id
int connect()
opens a new connection to a running rlCanOpenDaemon
bool connected
flag indicates connection status
int isConnected()
Definition: rlsocket.cpp:559
int client_timeout
timeout in ms

◆ setAdr()

void rlCanOpenClient::setAdr ( char *  _adr)

setter for private remoteadress variable

Definition at line 458 of file rlcanopenclient.cpp.

458  {
459  strcpy(remoteadress, _adr);
460 }
char remoteadress[40]
string of remoteadress

◆ setPort()

void rlCanOpenClient::setPort ( int  _port)

setter for private port variable

Definition at line 454 of file rlcanopenclient.cpp.

454  {
455  port = _port;
456 }
int port
variable contains port

Member Data Documentation

◆ client_timeout

int rlCanOpenClient::client_timeout
private

timeout in ms

Definition at line 153 of file rlcanopenclient.h.

◆ connected

bool rlCanOpenClient::connected
private

flag indicates connection status

Definition at line 142 of file rlcanopenclient.h.

◆ pid

int rlCanOpenClient::pid
private

variable contains process id

Definition at line 139 of file rlcanopenclient.h.

◆ port

int rlCanOpenClient::port
private

variable contains port

Definition at line 145 of file rlcanopenclient.h.

◆ remoteadress

char rlCanOpenClient::remoteadress[40]
private

string of remoteadress

Definition at line 148 of file rlcanopenclient.h.

◆ socket

rlSocket* rlCanOpenClient::socket
private

pointer to socket object

Definition at line 151 of file rlcanopenclient.h.


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