rllib  1
rlcanopentypes.h
Go to the documentation of this file.
1 /***************************************************************************
2  rlcanopen.cpp - description
3  -------------------
4  begin : Tue March 03 2004
5  copyright : (C) 2004 by Marc Bräutigam, Christian Wilmes, R. Lehrig
6  email : lehrig@t-online.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This library is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as *
13  * published by the Free Software Foundation *
14  * *
15  ***************************************************************************/
16 
17 #include <iostream>
18  using std::cin;
19  using std::cout;
20 
21 #include "rlinifile.h"
22 #include <stdlib.h>
23 #include <string.h>
24 
25 struct IPCMSGSTRUCT;
26 
28 
39  public:
40  enum rl_types{
45  RL_INT ,
54  RL_PDO = 13,
56  RL_NOTYPE = 0xFF
57  };
58 
59 
61 
62  c_BOOLEAN = 0x0001,
63  INTEGER8_t = 0x0002,
64  INTEGER16_t = 0x0003,
65  INTEGER32_t = 0x0004,
66  UNSIGNED8_t = 0x0005,
67  UNSIGNED16_t = 0x0006,
68  UNSIGNED32_t = 0x0007,
69  REAL32_t = 0x0008,
70  VISIBLE_STRING = 0x0009,
71  OCTET_STRING_t = 0x000A,
72  UNICODE_STRING = 0x000B,
73  TIME_OF_DAY_t = 0x000C,
74  TIME_DIFFERENC = 0x000D,
75  BIT_STRING_t = 0x000E,
76  DOMAIN_t = 0x000F,
77  INTEGER24_t = 0x0010,
78  REAL64_t = 0x0011,
79  INTEGER40_t = 0x0012,
80  INTEGER48_t = 0x0013,
81  INTEGER56_t = 0x0014,
82  INTEGER64_t = 0x0015,
83  UNSIGNED24_t = 0x0016,
84  RESERVED1_t = 0x0017,
85  UNSIGNED40_t = 0x0018,
86  UNSIGNED48_t = 0x0019,
87  UNSIGNED56_t = 0x001A,
88  UNSIGNED64_t = 0x001B
89 };
90 
93 
95  int getLength();
96 
98  void clearBuffer();
99 
104  void set_DaemonType(rl_types _type);
105 
107  void set_DaemonType(int _type);
108 
110  int get_DaemonType();
111 
116  void set_CanOpenType(int _type);
117 
119  int get_CanOpenType();
120 
126  static int canOpenType2DeamonType(int _canopentype);
127 
129  static int deamonType2CanOpenType(int _deamontype);
130 
132  void set_int(int _value);
133 
136  int get_int();
137 
139  void set_float(float _value);
140 
143  float get_float();
144 
146  void set_double(double _value);
147 
150  double get_double();
151 
153  void set_short(short _value);
154 
157  short get_short();
158 
160  void set_ushort(unsigned short _value);
161 
164  unsigned short get_ushort();
165 
167  void set_longlong(long int _value);
168 
171  long int get_longlong();
172 
175  void set_string(const char* _value);
176 
181  char* get_string();
182 
188  void set_buffer(int _index, unsigned char _databyte);
189 
191  unsigned char get_buffer(int _index);
192 
194  void set_uchar(unsigned char _value);
195 
198  unsigned char get_uchar();
199 
201  void set_bool(bool _value);
202 
205  bool get_bool();
206 
208  void set_long(long _value);
209 
212  long get_long();
213 
215  void set_ulong(unsigned long _value);
216 
219  unsigned long get_ulong();
220 
222  void set_ulonglong(unsigned long int _value);
223  unsigned long int get_ulonglong();
224 
226  void set_rlmsgerr(long _errnr);
228  long get_rlmsgerr();
229 
232  void set_nodestateFlags( unsigned char _bNodeNoResponse,
233  unsigned char _bEmcyBuffOverflow,
234  unsigned char _bPrmFault,
235  unsigned char _bGuardActive ,
236  unsigned char _bDeactivated);
237 
240  bool get_nodestateFlags( bool &_bNodeNoResponse,
241  bool &_bEmcyBuffOverflow,
242  bool &_bPrmFault,
243  bool &_bGuardActive,
244  bool &_bDeactivated);
245 
252 
261  void set_nodestate(unsigned char _nodestate);
262 
264  unsigned char get_nodestate();
265 
268  void set_nodeerror(unsigned char _nodeerror);
269 
271  unsigned char get_nodeerror();
272 
274  unsigned char pdobuffer[8];
275 
277  void buf2pdobuf();
278 
280  void pdobuf2buf();
281 
284 
287 
289  void getIpcMsg(IPCMSGSTRUCT _myIpcMsg);
290 
292  void rlMsgErrOut();
293 
294 
299  char* rlMsgErrStr();
300 
305  char* type2str(int _typenr);
306 
307 
308  bool translate_CanOpenType(int _canopentype);
309  int get_CanOpenTypeLength(int _canopentype);
310 
311  private:
312 
315  void invalidTypeError(int _typenr);
316 
317 
321 
332  long rlmsgerr;
333 
334 
335  //all different types are stored together in the same data area
336  union {
337  int t_int; // 4 Bytes 0x00
338  float t_float; // 4 Bytes 0x01
339  double t_double; // 8 Bytes 0x02
340  short t_short; // 2 Bytes 0x03
341  unsigned short t_ushort; // 2 Bytes 0x04
342  long int t_longlong; // 8 Bytes 0x05
343  char t_string[247]; // 246 Bytes 0x06
344  unsigned char t_databytes[247]; // 246 Bytes 0x07
345  unsigned char t_databyte; // 1 Byte 0x08
346  bool t_bool; // 1 Byte 0x09
347  long t_long; // 4 Bytes 0x0A
348  unsigned long t_ulong; // 4 Bytes 0x0B
349  unsigned long int t_ulonglong; // 8 Bytes 0x0C
350  // Error => 0xFF
351  struct
352  {
353  unsigned char bNodeNoResponse : 1; /* no response */
354  unsigned char bEmcyBuffOverflow : 1; /* emcy.buffer overflow */
355  unsigned char bPrmFault : 1; /* parameters faulty */
356  unsigned char bGuardActive : 1; /* node guarding active */
357  unsigned char bDeactivated : 1; /* not configured */
358  unsigned char bNodeState;
359  #define DISCONNECTED 1
360  #define CONNECTING 2
361  #define PREPARING 3
362  #define PREPARED 4
363  #define OPERATIONAL 5
364  #define PRE_OPERATIONAL 127
365  unsigned char bActualError;
366  } bNodeFlagState;
367  };
368 
369 };
370 
371 
372 
374 /*
375  MSG_SEND 0
376  MSG_RECEIVE 1
377 
378 #define MSG_SDO_READ 0
379 #define MSG_SDO_WRITE 1
380 #define MSG_PDO_RECEIVE 3
381 #define MSG_CONNECT 5
382 #define MSG_DISCONNECT 6
383 #define MSG_PDO_TRANSMIT 4
384 #define MSG_NMT_TRANSMIT 7
385 #define MSG_RESTART_BOARD 8
386 #define MSG_GET_NODE_STATE 9
387 */
388 
390 {
392  /* msgtype can be one of this values
393  MSG_SDO_READ 0
394  MSG_SDO_WRITE 1
395  MSG_PDO_RECEIVE 3
396  MSG_CONNECT 5
397  MSG_DISCONNECT 6
398  MSG_PDO_TRANSMIT 4
399  MSG_NMT_TRANSMIT 7
400  MSG_RESTART_BOARD 8
401  MSG_GET_NODE_STATE 9 */
402  long msgtype;
403 
404  /* transfer type can be one of this values
405  MSG_SEND 0
406  MSG_RECEIVE 1 */
408 
409  long processid;
410  long boardid;
411  long nodeid;
413  long subindex;
414  long pdoid;
415  long mappingid;
416  long rlmsgerr;
417  char mtext[247];
418 };
419 
unsigned char bEmcyBuffOverflow
void set_bool(bool _value)
sets type to RL_BOOL and stores passed parameter data in databuffer
void set_CanOpenType(int _type)
recieves an CANopen typenumber and returns appropiate RL-Type
float get_float()
returns databuffer-content as float type.
void set_int(int _value)
sets type to RL_INT and stores passed parameter data in databuffer
void set_longlong(long int _value)
sets type to RL_LONGLONG and stores passed parameter data in databuffer
the IPCMSGSTRUCT is the transfer buffer which is send trough TCP sockets
void set_nodeerror(unsigned char _nodeerror)
double get_double()
returns databuffer-content as double type.
unsigned long int t_ulonglong
unsigned char bPrmFault
unsigned char bGuardActive
void set_DaemonType(rl_types _type)
alternative setter receives integer typenumber
unsigned char get_nodeerror()
returns actual node error
void set_uchar(unsigned char _value)
sets type to RL_UCHAR and stores passed parameter data in databuffer
char mtext[247]
void getIpcMsg(IPCMSGSTRUCT _myIpcMsg)
overwrites all data with IPCMSGSTRUCT data
class to handle CANopen types
unsigned char t_databyte
bool get_nodestateFlags(bool &_bNodeNoResponse, bool &_bEmcyBuffOverflow, bool &_bPrmFault, bool &_bGuardActive, bool &_bDeactivated)
long int t_longlong
unsigned short t_ushort
void set_ulonglong(unsigned long int _value)
sets type to RL_ULONGLONG and stores passed parameter data in databuffer
unsigned char bNodeState
static int canOpenType2DeamonType(int _canopentype)
Function for typenumber conversion.
long get_rlmsgerr()
returns current errnumber
unsigned long int get_ulonglong()
returns databuffer-content as unsigned long long type
bool get_nodestateFlag_GuardActive()
void pdobuf2buf()
exchange bytes 0-7 from pdobuffer to databuffer
int get_DaemonType()
returns current of data stored in databuffer
bool get_nodestateFlag_PrmFault()
bool get_bool()
returns databuffer-content as bool type
long int get_longlong()
returns databuffer-content as long long type
void set_ushort(unsigned short _value)
sets type to RL_USHORT and stores passed parameter data in databuffer
unsigned long get_ulong()
returns databuffer-content as unsigned long type
char * type2str(int _typenr)
returns a pointer to a new 12 character string containing the name of the type
char t_string[247]
unsigned char get_uchar()
returns databuffer-content as uchar type
int get_CanOpenType()
returns the current type converted to CANopen typenumber
unsigned char t_databytes[247]
void set_rlmsgerr(long _errnr)
sets the errornumber. refer private varibale rlmsgerr for details
void buf2pdobuf()
exchange bytes 0-7 from databuffer to pdobuffer
void clearBuffer()
sets all bytes in databuffer to zero
int getLength()
returns number of bytes used for current type
void rlMsgErrOut()
prints MsgErrStr to StdOut
int get_int()
returns databuffer-content as integer type.
int get_CanOpenTypeLength(int _canopentype)
bool get_nodestateFlag_EmcyBuffOverflow()
unsigned char get_nodestate()
returns the nodestate. refer code numbers above
unsigned short get_ushort()
returns databuffer-content as short type
void set_ulong(unsigned long _value)
sets type to RL_ULONG and stores passed parameter data in databuffer
unsigned long t_ulong
unsigned char pdobuffer[8]
external buffer for pdotransfer
void set_double(double _value)
sets type to RL_DOUBLE and stores passed parameter data in databuffer
unsigned char bActualError
void set_string(const char *_value)
IPCMSGSTRUCT createIpcMsg()
returns a IPCMSGSTRUCT filled with current object data
rlCanOpenTypes()
Constructor initializes with RL_NOTYPE.
char * get_string()
creates string filled with databuffer-content and returns a pointer
unsigned char get_buffer(int _index)
returns 1 byte from databuffer
void set_nodestateFlags(unsigned char _bNodeNoResponse, unsigned char _bEmcyBuffOverflow, unsigned char _bPrmFault, unsigned char _bGuardActive, unsigned char _bDeactivated)
sets type to RL_NODESTATE. Stores flag-data received from the device.
bool translate_CanOpenType(int _canopentype)
static int deamonType2CanOpenType(int _deamontype)
Function for typenumber conversion.
void set_float(float _value)
sets type to RL_FLOAT and stores passed parameter data in databuffer
void set_buffer(int _index, unsigned char _databyte)
transfer raw data into the databuffer
unsigned char bDeactivated
long get_long()
returns databuffer-content as long type
short get_short()
returns databuffer-content as short type
bool get_nodestateFlag_Deactivated()
rlCanOpenTypes & operator=(rlCanOpenTypes &cp)
copies all data from right object into left object
bool get_nodestateFlag_NoResponse()
read particular nodestade with the following functions
struct rlCanOpenTypes::@0::@2 bNodeFlagState
void invalidTypeError(int _typenr)
produce an invalid-type-warning to stdout. used by nearly all getter functions
void set_short(short _value)
sets type to RL_SHORT and stores passed parameter data in databuffer
void set_long(long _value)
sets type to RL_LONG and stores passed parameter data in databuffer
unsigned char bNodeNoResponse
void set_nodestate(unsigned char _nodestate)
sets current state of node.