Class performs API rlcanopen functions remotely through tcp sockets. More...
#include <rlcanopenclient.h>


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 | |
| rlCanOpenClient (int _port, char *_remoteadress) | |
| initializes the client on given port and remove server adress | |
| ~rlCanOpenClient () | |
| destructor disconnects client | |
| int | connect () |
| opens a new connection to a running rlCanOpenDaemon | |
| int | disconnect () |
| disconnects from daemon | |
| 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. | |
| 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 | |
| int | pdo_receive (int _boardnr, int _nodeid, int _pdonr, int _mappingnr, rlCanOpenTypes &_pdo_data) |
| receives single mapped pdo object from daemon. | |
| int | pdo_receive (int _boardnr, int _nodeid, int _pdonr, rlCanOpenTypes &_pdo_data) |
| receives an 8 byte pdo from daemon. | |
| int | pdo_transmit (int _boardnr, int _nodeid, int _pdonr, int _mappingnr, rlCanOpenTypes &_pdo_data) |
| sends a single mapped pdo object to daemon. | |
| int | pdo_transmit (int _boardnr, int _nodeid, int _pdonr, rlCanOpenTypes &_pdo_data) |
| sends an 8 byte pdo to daemon. | |
| int | sendNMTCommand (int _boardnr, int _nodeid, unsigned char _cmd, bool &returnstate) |
| int | restartBoard (int _boardnr, int _restarttype, bool &returnstate) |
| int | getNodeState (int _boardnr, int _nodeid, rlCanOpenTypes &_data) |
| void | setPort (int _port) |
| setter for private port variable | |
| void | setAdr (char *_adr) |
| setter for private remoteadress variable | |
Private Attributes | |
| int | pid |
| variable contains process id | |
| bool | connected |
| flag indicates connection status | |
| int | port |
| variable contains port | |
| char | remoteadress [40] |
| string of remoteadress | |
| rlSocket * | socket |
| pointer to socket object | |
| int | client_timeout |
| timeout in ms | |
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.
| 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.
00038 { 00039 MSG_SEND = 0, 00040 MSG_RECEIVE = 1, 00041 MSG_SDO_READ = 0, 00042 MSG_SDO_WRITE = 1, 00043 MSG_PDO_RECEIVE = 3, 00044 MSG_CONNECT = 5, 00045 MSG_DISCONNECT = 6, 00046 MSG_PDO_TRANSMIT = 4, 00047 MSG_NMT_TRANSMIT = 7, 00048 MSG_RESTART_BOARD = 8, 00049 MSG_GET_NODE_STATE = 9 00050 };
| rlCanOpenClient::rlCanOpenClient | ( | ) |
initializes the client on localhost port 5000
initializes the client on port 5000
Definition at line 96 of file rlcanopenclient.cpp.
00097 { 00098 connected = false; 00099 //cout<<"rlCanOpenClient Konstrukter erfolgreich aufgerufen\n"; 00100 port=5000; 00101 strcpy(remoteadress, "localhost"); 00102 pid=getpid(); 00103 client_timeout=1000; 00104 socket = new rlSocket(remoteadress,port,1); 00105 }
| rlCanOpenClient::rlCanOpenClient | ( | int | _port, | |
| char * | _remoteadress | |||
| ) |
initializes the client on given port and remove server adress
Definition at line 108 of file rlcanopenclient.cpp.
00109 { 00110 connected = false; 00111 //cout<<"Konstrukter erfolgreich aufgerufen\n"; 00112 port=_port; 00113 pid=getpid(); 00114 client_timeout=1000; 00115 strcpy(remoteadress, _remoteadress); 00116 socket = new rlSocket(remoteadress,port,1); 00117 }
| rlCanOpenClient::~rlCanOpenClient | ( | ) |
destructor disconnects client
Definition at line 120 of file rlcanopenclient.cpp.
00121 { 00122 //printf("Destruktor rlCanOpenClient\n"); 00123 if (connected == true){ 00124 disconnect(); 00125 } 00126 if (socket!=0){ 00127 delete socket; 00128 } 00129 }
| int rlCanOpenClient::connect | ( | ) |
opens a new connection to a running rlCanOpenDaemon
Definition at line 132 of file rlcanopenclient.cpp.
00133 { 00134 00135 socket->setAdr(remoteadress); 00136 socket->setPort(port); 00137 socket->setActive(1); 00138 00139 socket->connect(); 00140 connected=socket->isConnected(); 00141 00142 if(socket->isConnected() == 0) { 00143 printf("no connection to server!\n"); 00144 return 0; 00145 } 00146 cout<<"connection established...\n"; 00147 return 1; 00148 }
| int rlCanOpenClient::disconnect | ( | ) |
disconnects from daemon
Definition at line 151 of file rlcanopenclient.cpp.
00152 { 00153 if (socket!=NULL){ 00154 printf("disconnection...\n"); 00155 socket->disconnect(); 00156 connected=false; 00157 } 00158 return 1; 00159 }
| int rlCanOpenClient::getNodeState | ( | int | _boardnr, | |
| int | _nodeid, | |||
| rlCanOpenTypes & | _data | |||
| ) |
receives node state data of particular node from daemon.
Definition at line 418 of file rlcanopenclient.cpp.
00420 { 00421 int ret; 00422 IPCMSGSTRUCT message; 00423 if (connected){ 00424 message = _data.createIpcMsg(); 00425 message.msgtype = MSG_GET_NODE_STATE; 00426 message.transfertype = MSG_SEND; 00427 message.processid = pid; 00428 message.boardid = _boardnr; 00429 message.nodeid=_nodeid; 00430 message.objectindex=0; 00431 message.subindex=0; 00432 message.pdoid=0; 00433 message.mappingid=0; 00434 00435 if(socket->isConnected() == 0) 00436 if ( connect() == 0 ) 00437 return 0; 00438 00439 socket->write((void*) &message, sizeof(message)); 00440 ret = socket->read((void*) &message,sizeof(message),client_timeout); 00441 if(ret <= 0) // timeout 00442 { 00443 return 0; 00444 } 00445 _data.getIpcMsg(message); 00446 } 00447 else 00448 { 00449 return 0; 00450 } 00451 return 1; 00452 }
| 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()
Reimplemented in rlCanClient.
Definition at line 281 of file rlcanopenclient.cpp.
00285 { 00286 int ret = pdo_receive(_boardnr, _nodeid, _pdonr, -1, _pdo_data); 00287 return ret; 00288 }
| 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.
00247 { 00248 int ret; 00249 IPCMSGSTRUCT message; 00250 if (connected){ 00251 message.msgtype = MSG_PDO_RECEIVE; 00252 message.transfertype = MSG_SEND; 00253 message.processid = pid; 00254 message.boardid = _boardnr; 00255 message.nodeid=_nodeid; 00256 message.objectindex=0; 00257 message.subindex=0; 00258 message.pdoid=_pdonr; 00259 message.mappingid=_mappingnr; 00260 00261 if(socket->isConnected() == 0) 00262 if ( connect() == 0 ) 00263 return 0; 00264 00265 socket->write((void*) &message, sizeof(message)); 00266 ret = socket->read((void*) &message,sizeof(message),client_timeout); 00267 if(ret <= 0) // timeout 00268 { 00269 return 0; 00270 } 00271 _pdo_data.getIpcMsg(message); 00272 } 00273 else 00274 { 00275 return 0; 00276 } 00277 return 1; 00278 }
| 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()
Reimplemented in rlCanClient.
Definition at line 333 of file rlcanopenclient.cpp.
00337 { 00338 return pdo_transmit(_boardnr, _nodeid, _pdonr, -1, _pdo_data); 00339 }
| 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.
00297 { 00298 int ret; 00299 IPCMSGSTRUCT message; 00300 if (connected){ 00301 message = _pdo_data.createIpcMsg(); 00302 message.msgtype = MSG_PDO_TRANSMIT; 00303 message.transfertype = MSG_SEND; 00304 message.processid = pid; 00305 message.boardid = _boardnr; 00306 message.nodeid=_nodeid; 00307 message.objectindex=0; 00308 message.subindex=0; 00309 message.pdoid=_pdonr; 00310 message.mappingid=_mappingnr; 00311 00312 if(socket->isConnected() == 0) 00313 if ( connect() == 0 ) 00314 return 0; 00315 00316 socket->write((void*) &message, sizeof(message)); 00317 ret = socket->read((void*) &message,sizeof(message),client_timeout); 00318 if(ret <= 0) // timeout 00319 { 00320 return 0; 00321 } 00322 _pdo_data.getIpcMsg(message); 00323 } 00324 else 00325 { 00326 return 0; 00327 } 00328 return 1; 00329 }
| int rlCanOpenClient::restartBoard | ( | int | _boardnr, | |
| int | _restarttype, | |||
| bool & | returnstate | |||
| ) |
forces daemon to restart canopen device.
Definition at line 381 of file rlcanopenclient.cpp.
00383 { 00384 int ret; 00385 IPCMSGSTRUCT message; 00386 if (connected){ 00387 message.mtext[0] = (char) _restarttype; 00388 message.msgtype = MSG_RESTART_BOARD; 00389 message.transfertype = MSG_SEND; 00390 message.processid = pid; 00391 message.boardid = _boardnr; 00392 message.nodeid=0; 00393 message.objectindex=0; 00394 message.subindex=0; 00395 message.pdoid=0; 00396 message.mappingid=0; 00397 00398 if(socket->isConnected() == 0) 00399 if ( connect() == 0 ) 00400 return 0; 00401 00402 socket->write((void*) &message, sizeof(message)); 00403 ret = socket->read((void*) &message,sizeof(message),client_timeout); 00404 if(ret <= 0) // timeout 00405 { 00406 return 0; 00407 } 00408 } 00409 else 00410 { 00411 return 0; 00412 } 00413 returnstate = (bool) message.transfertype; 00414 return 1; 00415 }
| 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.
00168 { 00169 int ret; 00170 IPCMSGSTRUCT message; 00171 if (connected){ 00172 message.msgtype = MSG_SDO_READ; 00173 message.transfertype = MSG_SEND; 00174 message.processid = pid; 00175 message.boardid = _boardnr; 00176 message.nodeid=_nodeid; 00177 message.objectindex=_objectindex; 00178 message.subindex=_subindex; 00179 00180 if(socket->isConnected() == 0) 00181 if ( connect() == 0 ) 00182 return 0; 00183 00184 socket->write((void*) &message, sizeof(message)); 00185 00186 ret = socket->read((void*) &message,sizeof(message),client_timeout); 00187 if(ret <= 0) // timeout 00188 { 00189 return 0; 00190 } 00191 _sdo_data.getIpcMsg(message); 00192 } 00193 else 00194 { 00195 return 0; 00196 } 00197 return 1; 00198 }
| 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.
00206 { 00207 int ret; 00208 IPCMSGSTRUCT message; 00209 if (connected){ 00210 message = _sdo_data.createIpcMsg(); 00211 message.msgtype = MSG_SDO_WRITE; 00212 message.transfertype = MSG_SEND; 00213 message.processid = pid; 00214 message.boardid = _boardnr; 00215 message.nodeid=_nodeid; 00216 message.objectindex=_objectindex; 00217 message.subindex=_subindex; 00218 00219 if(socket->isConnected() == 0) 00220 if ( connect() == 0 ) 00221 return 0; 00222 00223 00224 socket->write((void*) &message, sizeof(message)); 00225 00226 // recieve answer to check if write was successfull 00227 ret = socket->read((void*) &message,sizeof(message),client_timeout); 00228 if(ret <= 0) // timeout 00229 { 00230 return 0; 00231 } 00232 _sdo_data.getIpcMsg(message); 00233 } 00234 else 00235 { 00236 return 0; 00237 } 00238 return 1; 00239 }
| int rlCanOpenClient::sendNMTCommand | ( | int | _boardnr, | |
| int | _nodeid, | |||
| unsigned char | _cmd, | |||
| bool & | returnstate | |||
| ) |
sends a NMT command to daemon.
Definition at line 342 of file rlcanopenclient.cpp.
00345 { 00346 int ret; 00347 IPCMSGSTRUCT message; 00348 if (connected){ 00349 message.mtext[0] = _cmd; 00350 message.msgtype = MSG_NMT_TRANSMIT; 00351 message.transfertype = MSG_SEND; 00352 message.processid = pid; 00353 message.boardid = _boardnr; 00354 message.nodeid=_nodeid; 00355 message.objectindex=0; 00356 message.subindex=0; 00357 message.pdoid=0; 00358 message.mappingid=0; 00359 00360 if(socket->isConnected() == 0) 00361 if ( connect() == 0 ) 00362 return 0; 00363 00364 socket->write((void*) &message, sizeof(message)); 00365 ret = socket->read((void*) &message,sizeof(message),client_timeout); 00366 if(ret <= 0) // timeout 00367 { 00368 return 0; 00369 } 00370 } 00371 else 00372 { 00373 return 0; 00374 } 00375 returnstate = (bool) message.transfertype; 00376 return 1; 00377 }
| void rlCanOpenClient::setAdr | ( | char * | _adr | ) |
setter for private remoteadress variable
Definition at line 458 of file rlcanopenclient.cpp.
00458 { 00459 strcpy(remoteadress, _adr); 00460 }
| void rlCanOpenClient::setPort | ( | int | _port | ) |
setter for private port variable
Definition at line 454 of file rlcanopenclient.cpp.
00454 { 00455 port = _port; 00456 }
int rlCanOpenClient::client_timeout [private] |
timeout in ms
Definition at line 153 of file rlcanopenclient.h.
bool rlCanOpenClient::connected [private] |
flag indicates connection status
Definition at line 142 of file rlcanopenclient.h.
int rlCanOpenClient::pid [private] |
variable contains process id
Definition at line 139 of file rlcanopenclient.h.
int rlCanOpenClient::port [private] |
variable contains port
Definition at line 145 of file rlcanopenclient.h.
char rlCanOpenClient::remoteadress[40] [private] |
string of remoteadress
Definition at line 148 of file rlcanopenclient.h.
rlSocket* rlCanOpenClient::socket [private] |
pointer to socket object
Definition at line 151 of file rlcanopenclient.h.
1.6.3