|
rllib
1
|
00001 /*************************************************************************** 00002 rlcanopen.cpp - description 00003 ------------------- 00004 begin : Tue March 03 2004 00005 copyright : (C) 2004 by Marc Bräutigam, Christian Wilmes, Rainer Lehrig 00006 email : lehrig@t-online.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This library is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as * 00013 * published by the Free Software Foundation * 00014 * * 00015 ***************************************************************************/ 00016 00017 #include <iostream> 00018 using std::cin; 00019 using std::cout; 00020 00021 #include "rlinifile.h" 00022 #include <stdlib.h> 00023 #include <string.h> 00024 00025 struct IPCMSGSTRUCT; 00026 00028 00038 class rlCanOpenTypes { 00039 public: 00040 enum rl_types{ 00041 RL_BOOL=0, 00042 RL_UCHAR, 00043 RL_SHORT, 00044 RL_USHORT, 00045 RL_INT , 00046 RL_LONG, 00047 RL_FLOAT, 00048 RL_DOUBLE, 00049 RL_LONGLONG, 00050 RL_STRING, 00051 RL_BUFFER, 00052 RL_ULONG, 00053 RL_ULONGLONG, 00054 RL_PDO = 13, 00055 RL_NODESTATE, 00056 RL_NOTYPE = 0xFF 00057 }; 00058 00059 00060 enum canopen_types{ 00061 00062 c_BOOLEAN = 0x0001, 00063 INTEGER8_t = 0x0002, 00064 INTEGER16_t = 0x0003, 00065 INTEGER32_t = 0x0004, 00066 UNSIGNED8_t = 0x0005, 00067 UNSIGNED16_t = 0x0006, 00068 UNSIGNED32_t = 0x0007, 00069 REAL32_t = 0x0008, 00070 VISIBLE_STRING = 0x0009, 00071 OCTET_STRING_t = 0x000A, 00072 UNICODE_STRING = 0x000B, 00073 TIME_OF_DAY_t = 0x000C, 00074 TIME_DIFFERENC = 0x000D, 00075 BIT_STRING_t = 0x000E, 00076 DOMAIN_t = 0x000F, 00077 INTEGER24_t = 0x0010, 00078 REAL64_t = 0x0011, 00079 INTEGER40_t = 0x0012, 00080 INTEGER48_t = 0x0013, 00081 INTEGER56_t = 0x0014, 00082 INTEGER64_t = 0x0015, 00083 UNSIGNED24_t = 0x0016, 00084 RESERVED1_t = 0x0017, 00085 UNSIGNED40_t = 0x0018, 00086 UNSIGNED48_t = 0x0019, 00087 UNSIGNED56_t = 0x001A, 00088 UNSIGNED64_t = 0x001B 00089 }; 00090 00092 rlCanOpenTypes(); 00093 00095 int getLength(); 00096 00098 void clearBuffer(); 00099 00104 void set_DaemonType(rl_types _type); 00105 00107 void set_DaemonType(int _type); 00108 00110 int get_DaemonType(); 00111 00116 void set_CanOpenType(int _type); 00117 00119 int get_CanOpenType(); 00120 00126 static int canOpenType2DeamonType(int _canopentype); 00127 00129 static int deamonType2CanOpenType(int _deamontype); 00130 00132 void set_int(int _value); 00133 00136 int get_int(); 00137 00139 void set_float(float _value); 00140 00143 float get_float(); 00144 00146 void set_double(double _value); 00147 00150 double get_double(); 00151 00153 void set_short(short _value); 00154 00157 short get_short(); 00158 00160 void set_ushort(unsigned short _value); 00161 00164 unsigned short get_ushort(); 00165 00167 void set_longlong(long int _value); 00168 00171 long int get_longlong(); 00172 00175 void set_string(const char* _value); 00176 00181 char* get_string(); 00182 00188 void set_buffer(int _index, unsigned char _databyte); 00189 00191 unsigned char get_buffer(int _index); 00192 00194 void set_uchar(unsigned char _value); 00195 00198 unsigned char get_uchar(); 00199 00201 void set_bool(bool _value); 00202 00205 bool get_bool(); 00206 00208 void set_long(long _value); 00209 00212 long get_long(); 00213 00215 void set_ulong(unsigned long _value); 00216 00219 unsigned long get_ulong(); 00220 00222 void set_ulonglong(unsigned long int _value); 00223 unsigned long int get_ulonglong(); 00224 00226 void set_rlmsgerr(long _errnr); 00228 long get_rlmsgerr(); 00229 00232 void set_nodestateFlags( unsigned char _bNodeNoResponse, 00233 unsigned char _bEmcyBuffOverflow, 00234 unsigned char _bPrmFault, 00235 unsigned char _bGuardActive , 00236 unsigned char _bDeactivated); 00237 00240 bool get_nodestateFlags( bool &_bNodeNoResponse, 00241 bool &_bEmcyBuffOverflow, 00242 bool &_bPrmFault, 00243 bool &_bGuardActive, 00244 bool &_bDeactivated); 00245 00247 bool get_nodestateFlag_NoResponse(); 00248 bool get_nodestateFlag_EmcyBuffOverflow(); 00249 bool get_nodestateFlag_PrmFault(); 00250 bool get_nodestateFlag_GuardActive(); 00251 bool get_nodestateFlag_Deactivated(); 00252 00261 void set_nodestate(unsigned char _nodestate); 00262 00264 unsigned char get_nodestate(); 00265 00268 void set_nodeerror(unsigned char _nodeerror); 00269 00271 unsigned char get_nodeerror(); 00272 00274 unsigned char pdobuffer[8]; 00275 00277 void buf2pdobuf(); 00278 00280 void pdobuf2buf(); 00281 00283 rlCanOpenTypes& operator = (rlCanOpenTypes &cp); 00284 00286 IPCMSGSTRUCT createIpcMsg(); 00287 00289 void getIpcMsg(IPCMSGSTRUCT _myIpcMsg); 00290 00292 void rlMsgErrOut(); 00293 00294 00299 char* rlMsgErrStr(); 00300 00305 char* type2str(int _typenr); 00306 00307 00308 bool translate_CanOpenType(int _canopentype); 00309 int get_CanOpenTypeLength(int _canopentype); 00310 00311 private: 00312 00315 void invalidTypeError(int _typenr); 00316 00317 00320 int typenumber; 00321 00332 long rlmsgerr; 00333 00334 00335 //all different types are stored together in the same data area 00336 union { 00337 int t_int; // 4 Bytes 0x00 00338 float t_float; // 4 Bytes 0x01 00339 double t_double; // 8 Bytes 0x02 00340 short t_short; // 2 Bytes 0x03 00341 unsigned short t_ushort; // 2 Bytes 0x04 00342 long int t_longlong; // 8 Bytes 0x05 00343 char t_string[247]; // 246 Bytes 0x06 00344 unsigned char t_databytes[247]; // 246 Bytes 0x07 00345 unsigned char t_databyte; // 1 Byte 0x08 00346 bool t_bool; // 1 Byte 0x09 00347 long t_long; // 4 Bytes 0x0A 00348 unsigned long t_ulong; // 4 Bytes 0x0B 00349 unsigned long int t_ulonglong; // 8 Bytes 0x0C 00350 // Error => 0xFF 00351 struct 00352 { 00353 unsigned char bNodeNoResponse : 1; /* no response */ 00354 unsigned char bEmcyBuffOverflow : 1; /* emcy.buffer overflow */ 00355 unsigned char bPrmFault : 1; /* parameters faulty */ 00356 unsigned char bGuardActive : 1; /* node guarding active */ 00357 unsigned char bDeactivated : 1; /* not configured */ 00358 unsigned char bNodeState; 00359 #define DISCONNECTED 1 00360 #define CONNECTING 2 00361 #define PREPARING 3 00362 #define PREPARED 4 00363 #define OPERATIONAL 5 00364 #define PRE_OPERATIONAL 127 00365 unsigned char bActualError; 00366 } bNodeFlagState; 00367 }; 00368 00369 }; 00370 00371 00372 00374 /* 00375 MSG_SEND 0 00376 MSG_RECEIVE 1 00377 00378 #define MSG_SDO_READ 0 00379 #define MSG_SDO_WRITE 1 00380 #define MSG_PDO_RECEIVE 3 00381 #define MSG_CONNECT 5 00382 #define MSG_DISCONNECT 6 00383 #define MSG_PDO_TRANSMIT 4 00384 #define MSG_NMT_TRANSMIT 7 00385 #define MSG_RESTART_BOARD 8 00386 #define MSG_GET_NODE_STATE 9 00387 */ 00388 00389 struct IPCMSGSTRUCT 00390 { 00391 long typenumber; 00392 /* msgtype can be one of this values 00393 MSG_SDO_READ 0 00394 MSG_SDO_WRITE 1 00395 MSG_PDO_RECEIVE 3 00396 MSG_CONNECT 5 00397 MSG_DISCONNECT 6 00398 MSG_PDO_TRANSMIT 4 00399 MSG_NMT_TRANSMIT 7 00400 MSG_RESTART_BOARD 8 00401 MSG_GET_NODE_STATE 9 */ 00402 long msgtype; 00403 00404 /* transfer type can be one of this values 00405 MSG_SEND 0 00406 MSG_RECEIVE 1 */ 00407 long transfertype; 00408 00409 long processid; 00410 long boardid; 00411 long nodeid; 00412 long objectindex; 00413 long subindex; 00414 long pdoid; 00415 long mappingid; 00416 long rlmsgerr; 00417 char mtext[247]; 00418 }; 00419
1.7.5.1