49 setvbuf ( fp , NULL , _IOFBF , 1024 );
79 timeinfo = localtime ( &rawtime );
81 sprintf(
err_out_buf,
"\nnew session startet: %s\n", asctime(timeinfo));
89 rlDebugPrintf(
"no board available or no board could be initialized correctly!\n");
106 for (
int boardid = 0;boardid<
boardcount;boardid++)
109 for(nodeid = 0; nodeid <=
MAX_NODES; nodeid++)
127 rlDebugPrintf(
"WARNING: no Mapping available on node %d.", nodeid);
128 rlDebugPrintf(
"Probably EDS file couldn't be found in EDS directory.\n");
145 for (
int j = 1;j<=pdomax;j++)
157 int currentboardcount=0;
159 BOARD_INFO tBoardInfo;
162 if ( (
sRet = DevOpenDriver(0)) == DRV_NO_ERROR)
164 if ( (
sRet = DevOpenDriver()) == DRV_NO_ERROR)
169 if ( (
sRet = DevGetBoardInfo( 0,
sizeof(tBoardInfo), &tBoardInfo)) != DRV_NO_ERROR)
171 if ( (
sRet = DevGetBoardInfo( &tBoardInfo)) != DRV_NO_ERROR)
180 for (
int usIdx = 0; usIdx < MAX_DEV_BOARDS; usIdx++)
182 if ( tBoardInfo.tBoard[usIdx].usAvailable == TRUE) {
186 tBoardInfo.tBoard[usIdx].usBoardNumber, NULL);
188 tBoardInfo.tBoard[usIdx].usBoard);
190 if (
sRet != DRV_NO_ERROR) {
203 if (currentboardcount!=0)
237 DevPutMessage(0, (MSG_STRUC *)&
message,5000L) ;
240 sRet = DevGetMessage ( 0,
252 sprintf(
err_out_buf,
"Board %d node %d is active. No problems found\n",
260 sprintf(
err_out_buf,
"Board %d node %d is active. \n",
264 rlDebugPrintf(
"Configuration data does not fit in one message,\n");
265 rlDebugPrintf(
"so the current node does not include the complete data\n");
266 rlDebugPrintf(
" - multiplex configration data is not yet implemented!!! -\n");
272 sprintf(
err_out_buf,
"---->message.a=%d, message.nr=%d unsere msg nr: %d\n",
276 sprintf(
err_out_buf,
"%s\n",
"Communication ERROR!!!");
288 if ( (
sRet = DevSetHostState( _boardnr, HOST_READY, 0L) == DRV_NO_ERROR) )
305 for(
unsigned int i = 0; i <
nodelist.size(); i++)
307 if ((
nodelist[i]->getNodeID() == _nodeid) &&
308 (
nodelist[i]->getBoardID() == _boardnr))
323 for(
unsigned int i = 0; i <
nodelist.size(); i++)
344 rlDebugPrintf(
"ERROR: specified node does not exist! SDO write failed!");
345 rlDebugPrintf(
"BoardId: %d NodeId: %d Objektindex: %d Subindex: %d\n",
346 _boardnr, _nodeid, _objectindex, _subindex);
366 message.data_adr = _objectindex;
372 if(DevPutMessage(0, (MSG_STRUC *)&
message,5000L) != DRV_NO_ERROR)
return 0;
381 unsigned char msgnrlocal;
389 canopentype=
getObjectType(_boardnr, _nodeid, _objectindex, _subindex);
400 for(
int i = 0; i < datalength; i++)
416 rlDebugPrintf(
"message.a = %d message.nr = %d vergleich mit: %d\n",
423 _boardnr, _nodeid, _objectindex, _subindex);
443 rlDebugPrintf(
"ERROR: specified node does not exist! SDO write failed!");
444 rlDebugPrintf(
"BoardId: %d NodeId: %d Objektindex: %d Subindex: %d\n",
445 _boardnr, _nodeid, _objectindex, _subindex);
452 int canopentype =
getObjectType(_boardnr, _nodeid, _objectindex, _subindex);
457 for(
int i = 0;i<length;i++)
473 message.data_adr = _objectindex;
479 if(DevPutMessage(0, (MSG_STRUC *)&
message,5000L) != DRV_NO_ERROR)
return 0;
484 sRet = DevGetMessage ( _boardnr,
489 unsigned char msgnrlocal =
messagenr - 1;
499 (
nodelist[nodeindex]->hasMapping()) )
501 rlDebugPrintf(
"Mapping has changed: boardid %d, nodeid %d, objectindex %x\n",
502 _boardnr, _nodeid, _objectindex);
509 (
nodelist[nodeindex]->hasMapping()) )
511 rlDebugPrintf(
"Mapping has changed: boardid %d, nodeid %d, objectindex %x\n",
512 _boardnr, _nodeid, _objectindex);
520 sprintf(
err_out_buf,
"message.f = %d message.f = %x Hex \n",
530 sprintf(
err_out_buf,
"message.a = %d message.nr = %d vergleich mit: %d\n",
537 _boardnr, _nodeid, _objectindex, _subindex);
552 unsigned char buffer[8];
556 rlDebugPrintf(
"ERROR: specified node does not exist! PDO receive failed!");
557 rlDebugPrintf(
"BoardId: %d NodeId: %d PDO ID: %d Mappingnr: %d\n",
558 _boardnr, _nodeid, _pdonr, _mappingnr);
564 rlDebugPrintf(
"ERROR: specified PDO ID does not exist! PDO receive failed!");
565 rlDebugPrintf(
"BoardId: %d NodeId: %d PDO ID: %d Mappingnr: %d\n",
566 _boardnr, _nodeid, _pdonr, _mappingnr);
572 < (
unsigned int) _mappingnr){
573 rlDebugPrintf(
"ERROR: specified Mappingnr does not exist! PDO receive failed!");
574 rlDebugPrintf(
"BoardId: %d NodeId: %d PDO ID: %d Mappingnr: %d\n",
575 _boardnr, _nodeid, _pdonr, _mappingnr);
587 if ( (
sRet = DevExchangeIO( _boardnr,
598 int length_in_byte =
nodelist[nodeindex]->
601 int position_in_byte =
nodelist[nodeindex]->
606 for(
int i = position_in_byte; i< length_in_byte+position_in_byte;i++)
608 _pdo_data.
set_buffer(i-position_in_byte,buffer[i]);
612 mappingList[_mappingnr-1]->etype);
620 mappingList[_mappingnr-1]->canopentype;
628 rlDebugPrintf(
"BoardId: %d NodeId: %d PDO ID: %d Mappingnr: %d\n",
629 _boardnr, _nodeid, _pdonr, _mappingnr);
646 sprintf(
err_out_buf,
"ERROR: specified node does not exist! PDO \ 647 receive failed! BoardId: %d NodeId: %d PDO \ 648 ID: %d\n", _boardnr, _nodeid, _pdonr);
657 sprintf(
err_out_buf,
"ERROR: specified PDO ID does not exist! \ 658 PDO receive failed! BoardId: %d NodeId: \ 659 %d PDO ID: %d\n", _boardnr, _nodeid, _pdonr);
669 int pdooffset =
nodelist[nodeindex]->
674 if ( (
sRet = DevExchangeIO( _boardnr,
691 BoardId: %d NodeId: %d PDO \ 692 ID: %d\n", _boardnr, _nodeid, _pdonr);
712 sprintf(
err_out_buf,
"ERROR: specified node does not exist! PDO transmit \ 713 failed! BoardId: %d NodeId: %d PDO ID: %d Mappingnr:\ 714 %d\n", _boardnr, _nodeid, _pdonr, _mappingnr);
720 sprintf(
err_out_buf,
"ERROR: specified PDO ID does not exist! PDO transmit\ 721 failed! BoardId: %d NodeId: %d PDO ID: %d Mappingnr:\ 722 %d\n", _boardnr, _nodeid, _pdonr, _mappingnr);
730 < (
unsigned int) _mappingnr){
731 sprintf(
err_out_buf,
"ERROR: specified mappingnr does not exist! PDO \ 732 transmit failed! BoardId: %d NodeId: %d PDO \ 733 ID: %d Mappingnr: %d\n",
734 _boardnr, _nodeid, _pdonr, _mappingnr);
747 mappingList[_mappingnr-1]->length/8;
750 mappingList[_mappingnr-1]->position/8;
756 sprintf(
err_out_buf,
"ERROR: invalid type! Expected type: %d Your Type:\ 757 %d! PDO transmit failed! BoardId: %d NodeId: %d \ 758 PDO ID: %d Mappingnr: %d\n",
760 mappingList[_mappingnr-1]->etype,
761 _pdo_data.
get_DaemonType(), _boardnr, _nodeid, _pdonr, _mappingnr);
774 pdooffset = pdooffset + position_in_byte;
775 pdosize = length_in_byte;
781 if ( (
sRet = DevExchangeIO( _boardnr,
795 sprintf(
err_out_buf,
"ERROR: PDO transmit failed! BoardId: %d NodeId: %d \ 796 PDO ID: %d Mappingnr: %d\n",
797 _boardnr, _nodeid, _pdonr, _mappingnr);
816 sprintf(
err_out_buf,
"ERROR: specified node does not exist! PDO transmit\ 817 failed! BoardId: %d NodeId: %d PDO ID: %d \n",
818 _boardnr, _nodeid, _pdonr);
825 sprintf(
err_out_buf,
"ERROR: specified PDO ID does not exist! PDO \ 826 transmit failed! BoardId: %d NodeId: %d PDO \ 827 ID: %d \n", _boardnr, _nodeid, _pdonr);
836 if ( (
sRet = DevExchangeIO( _boardnr,
849 sprintf(
err_out_buf,
"ERROR: PDO transmit failed! BoardId: %d NodeId: %d \ 850 PDO ID: %d \n", _boardnr, _nodeid, _pdonr);
884 for(
unsigned int i = 0; i <
nodelist.size(); i++)
886 if ((
nodelist[i]->getNodeID() == _nodeid) &&
887 (
nodelist[i]->getBoardID() == _boardnr))
904 if (
nodelist[nodeindex]->hasMapping())
905 return nodelist[nodeindex]->objecttype(_objectindex, _subindex);
928 pdoList[_pdoDirection][_pdoID -1]->mappingOvAdress;
932 sprintf(
err_out_buf,
"ERROR: specified node does not exist! refresh \ 933 mapping list failed! BoardId: %d NodeId: %d \ 934 PDO ID: %d \n", _boardnr, _nodeid, _pdoID);
940 if(
nodelist[nodeindex]->pdoList[_pdoDirection].size() < (
unsigned int) _pdoID)
942 sprintf(
err_out_buf,
"ERROR: PDO does not exist! refresh \ 943 mapping list failed! BoardId: %d NodeId: %d \ 944 PDO ID: %d \n", _boardnr, _nodeid, _pdoID);
955 if (
sdo_read(_boardnr,_nodeid,madress,0,sdobuffer) == 0){
956 sprintf(
err_out_buf,
"ERROR: read sdo data! refresh mapping list failed! \ 957 BoardId: %d NodeId: %d PDO ID: %d \n",
958 _boardnr, _nodeid, _pdoID);
964 sprintf(
err_out_buf,
"Current mappingcount: %d\n", mappingcount);
967 nodelist[nodeindex]->pdoList[_pdoDirection][_pdoID-1]->
968 mappingList.resize(mappingcount);
970 int currentposition = 0;
971 for (
int mcount = 1; mcount <= mappingcount;mcount++)
977 if (
sdo_read(_boardnr,_nodeid,madress,mcount,sdobuffer) == 0){
978 sprintf(
err_out_buf,
"ERROR: read sdo data! refresh mapping list failed! \ 979 BoardId: %d NodeId: %d PDO ID: %d \n",
980 _boardnr, _nodeid, _pdoID);
987 mappingobject->
length = mlength;
991 mappingobject->
position = currentposition;
994 currentposition+=mlength;
997 int mi = (int) (sdobuffer.
get_buffer(3)*pow(256,1)
1007 nodelist[nodeindex]->pdoList[_pdoDirection][_pdoID-1]->
1008 mappingList.insert(mcount-1,mappingobject);
1028 pdomax =
nodelist[nodeindex]->getReceivePdoCount();
1030 pdomax =
nodelist[nodeindex]->getTransmitPdoCount();
1034 for (
int j=1;j<=pdomax;j++)
1037 madress =
nodelist[nodeindex]->pdoList[_direction][j-1]->mappingOvAdress;
1038 if (madress == _objektindex)
1050 COM_ND_DIAGNOSTICS * diag;
1051 diag = (COM_ND_DIAGNOSTICS*) &
message.d[0];
1061 message.device_adr = _nodeid ;
1070 if ( (
sRet = DevPutMessage(_boardnr, (MSG_STRUC *)&
message, 5000L))
1073 while( (
sRet = DevGetMessage(_boardnr,
sizeof(
message),
1075 == DRV_DEV_GET_NO_MESSAGE )
1079 if (
sRet == DRV_NO_ERROR )
1087 rlDebugPrintf(
"\nDevGetMessage(%d, sizeof(message), &message, 500): %d\n",
1088 _boardnr, (
int)
sRet);
1099 diag->bNodeStatus_1.bEmcyBuffOverflow,
1100 diag->bNodeStatus_1.bPrmFault,
1101 diag->bNodeStatus_1.bGuardActive,
1102 diag->bNodeStatus_1.bDeactivated );
1120 if ( (
sRet = DevReset(_boardnr, _restarttype, 5000L) != DRV_NO_ERROR ))
1155 if ( (
sRet = DevPutMessage(_boardnr, (MSG_STRUC *)&
message, 5000L))
1158 while( (
sRet = DevGetMessage(_boardnr,
sizeof(
message),
1160 == DRV_DEV_GET_NO_MESSAGE )
1164 if (
sRet == DRV_NO_ERROR )
1172 rlDebugPrintf(
"\nDevGetMessage(%d, sizeof(message), &message, 500): %d\n",
1173 _boardnr, (
int)
sRet);
1180 rlDebugPrintf(
"\nDevPutMessage(NMT)(%d, &message, 5000): %d\n",_boardnr, (
int)
sRet);
1192 if (
ini.read(_filename)!=-1){
1196 buffer=QString(
ini.text(
"DIRECTORIES",
"EdsDir"));
1197 buffer.remove((
char) ACSII_CODE_CARRIAGE_RETURN);
1201 SetEnvironmentVariable(
"EdsDir", buffer.ascii());
1203 setenv(
"EdsDir", buffer.ascii(), 1);
1208 logFileName.remove((
char) ACSII_CODE_CARRIAGE_RETURN);
1212 buffer=QString(
ini.text(
"OPTIONS",
"enableLoggin"));
1213 if (buffer.contains(
"yes",
false)==1)
1228 switch (_canopentype){
1238 default :
return false;
unsigned short mappingId
the mapping ID determines the mapping object within the PDO (1 to n)
#define ERRCODE_INVALID_RLTYPE
#define CMDCODE_SDO_UPDOWNLOAD
int rlDebugPrintf(const char *format,...)
int activeboard
the currently active board
void set_CanOpenType(int _type)
recieves an CANopen typenumber and returns appropiate RL-Type
int getActiveBoard()
returns the number of currently active board
#define DIRECTION_RECEIVE
definition of CanOpen structs for CanOpen Deamon
#define TRANSMIT_PDO_MAPPING_MAXADRESS
void set_nodeerror(unsigned char _nodeerror)
void delmsg()
clear message struct by setting all elements to zero
int getBoardCount()
returns the number of available boards
int boardcount
the current count of CanOpenMaster cards
void set_DaemonType(rl_types _type)
alternative setter receives integer typenumber
#define DIRECTION_TRANSMIT
#define CAN_TASK
Hilscher device-communication constants.
short setBoardActive(int _boardnr)
sets a desired CanOpenMaster active, so that it can be used
QString logFileName
name of logfile stdout is redirected to
class to handle CANopen types
#define CMD_NMT_Module_Protocol
#define ERRCODE_INVALID_NODEID
int refreshMappingList(int _boardnr, int _nodeid, int _pdoID, int _pdoDirection)
int sdo_read(int _boardnr, int _nodeid, int _objectindex, int _subindex, rlCanOpenTypes &_sdo_data)
read a certain object from the object dictionary of a node
bool ini()
initialize nodes and create nodelist
static int canOpenType2DeamonType(int _canopentype)
Function for typenumber conversion.
void read_inifile(const char *_filename)
read properties of inifile
int getNodeIndex(int _boardnr, int _nodeid, int &_index)
this function returns the listindex of a desired node
#define ERRCODE_PDORCV_FAIL
int sendNMTCommand(int _boardnr, int _nodeid, unsigned char _cmd)
send a NMT Command to one or all nodes (of one board)
void pdobuf2buf()
exchange bytes 0-7 from pdobuffer to databuffer
int get_DaemonType()
returns current of data stored in databuffer
unsigned short position
its position in within the 8Byte
#define TRANSMIT_PDO_MAPPING_STARTADRESS
int pdo_transmit(int _boardnr, int _nodeid, int _pdonr, int _mappingnr, rlCanOpenTypes &_pdo_data)
transmit a mapped object within a PDO to a specific node
#define ERRCODE_INVALID_MAPID
int restartBoard(int _boardnr, int _restarttype)
using this function you are able to restart a CanOpenMaster board
unsigned char get_uchar()
returns databuffer-content as uchar type
void set_rlmsgerr(long _errnr)
sets the errornumber. refer private varibale rlmsgerr for details
bool showNodeConfiguration()
prints out the configuration off all available nodes from all boards
#define CMDCODE_GET_CONFIGURATION
int pdo_receive(int _boardnr, int _nodeid, int _pdonr, int _mappingnr, rlCanOpenTypes &_pdo_data)
using the pdo_receive function you can receive a mapped object within PDO
void buf2pdobuf()
exchange bytes 0-7 from databuffer to pdobuffer
char err_out_buf[255]
this string buffer is usually written with sprintf before sent to stdout
void clearBuffer()
sets all bytes in databuffer to zero
int sdo_write(int _boardnr, int _nodeid, int _objectindex, int _subindex, rlCanOpenTypes &_sdo_data)
write data into a certain object from the object dictionary of a node
#define ERRCODE_NOERROR
ERRCODES.
mapping object which is part of the mappinglist of a PDO
int getLength()
returns number of bytes used for current type
int getObjectType(int _boardnr, int _nodeid, int _objectindex, int _subindex)
returns daemontype number of a specific object
#define RECEIVE_PDO_MAPPING_MAXADRESS
int getPdoID(int _boardnr, int _nodeid, int _objektindex, int _direction)
return PdoId of mapped object.
int createMappingObjects(int _boardid, int _nodeid, int _pdoDirection)
this function writes the mapping objects for each pdo of a node
int get_CanOpenTypeLength(int _canopentype)
QPtrVector< rlCanNode > nodelist
this list contains all nodes from all boards
bool is_twisted_type(int _canopentype)
unsigned char messagenr
message counter
int etype
its current type (int32, float, char, ...)
unsigned char pdobuffer[8]
external buffer for pdotransfer
bool iniboards()
Read informations about installed devices.
#define RECEIVE_PDO_MAPPING_STARTADRESS
int createNodes()
Search for nodes in all boards and append it into the nodelist.
#define ERRCODE_INVALID_PDOID
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)
#define ERRCODE_PDOSND_FAIL
unsigned short length
length of mappend object in bits
short sRet
return value for hilscher specific message functions
int getNodeState(int _boardnr, int _nodeid, rlCanOpenTypes &_data)
use this function to get information about a specific node
class to manage one node of a CanOpenMaster board in a CanOpen network
void set_buffer(int _index, unsigned char _databyte)
transfer raw data into the databuffer
#define MAX_SDO_BUFFERSIZE
bool getNodeConfiguration(int _nodeID)
#define RESPONSE_CODE_GET_CONFIGURATION
#define CMDCODE_Node_Diag
RCS_MESSAGETELEGRAM_10 message
hilscher specific message structur which will be sent to the master card
void set_nodestate(unsigned char _nodestate)
sets current state of node.