rllib  1
rlcannode.cpp
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�tigam, 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 #include "rlcutil.h"
17 #include "rlcannode.h"
18 
19 
20 //---------------------------------------------------------------------------
22 {
23  rlDebugPrintf("\n Constructer clear");
24 }
25 //---------------------------------------------------------------------------
28  (int boardnr, int nodeid, RCS_MESSAGETELEGRAM_10& _telegramm){
29  nodeID = nodeid;
30  boardID = boardnr;
31  readConfigurationMessage(_telegramm);
32  rlDebugPrintf("Initialising new node...\n BoardNr. %d NodeId %d Productstr %s ...",
33  boardnr, nodeid, abDeviceName.ascii());
34 
35  ini = getEDS(abDeviceName);
36 
37  if (ini!=0){
38  rlDebugPrintf(" SUCCESS! \n ");
39  rlDebugPrintf(" ProductName=%s \n ", ini->text("DeviceInfo","ProductName"));
40  rlDebugPrintf(" Filename=%s \n ", ini->text("FileInfo","FileName"));
41  rlDebugPrintf("Lege Objektverzeichnis an: ");
42  objdir = new ObjDir(ini);
43  }
44  else
45  {
46  rlDebugPrintf("ERROR!\n NO EDS FILE FOUND FOR \"%s\"!\n", abDeviceName.ascii());
47  objdir = 0;
48  }
49 
50  if (objdir){
51  // observe the adress for pdo mapping in OV
52  unsigned int i,adr;
54 
55  rlDebugPrintf(" PDO Gr�en:transmit PDOs: %d receive PDOs: %d\n",
56  pdoList[DIRECTION_TRANSMIT].size(),pdoList[DIRECTION_RECEIVE].size());
57 
58  for (i = 0; i< pdoList[DIRECTION_TRANSMIT].size();i++)
59  {
60  while(objdir->OVAdressExists(adr,0) == 0)
61  {
62  adr++;
63 
65  adr=0;
66  rlDebugPrintf("ERROR IN EDS FILE: errorous number of Mapping entries\n");
67  break;
68  }
69  }
70  pdoList[DIRECTION_TRANSMIT][i]->mappingOvAdress = adr;
71 
72  adr++;
73  }
74 
76  for (i = 0; i< pdoList[DIRECTION_RECEIVE].size();i++)
77  {
78  while(objdir->OVAdressExists(adr,0) == 0)
79  {
80  adr++;
81 
83  adr=0;
84  rlDebugPrintf("ERROR IN EDS FILE: errorous number of Mapping entries\n");
85  break;
86  }
87  }
88  pdoList[DIRECTION_RECEIVE][i]->mappingOvAdress = adr;
89  adr++;
90 
91  }
92  }
93 
94 }
95 //---------------------------------------------------------------------------
98  rlDebugPrintf("Destructor rlCanNode\n");
99  if (ini!=0){
100  delete ini;
101  }
102  if (objdir!=0){
103  delete objdir;
104  }
105 }
106 
107 //---------------------------------------------------------------------------
109 rlIniFile* rlCanNode::getEDS(const char* _productstr){
110  rlIniFile* _ini;
111  // get eds dir
112  QString dirname(getenv("EdsDir"));
113  if (dirname.isEmpty()){
114  dirname = "./";
115  }
116  QString productname(_productstr);
117  QDir edsdir(dirname);
118  edsdir.setNameFilter("*.EDS; *.eds");
119  QStringList::Iterator dirit;
120  QStringList dirlist;
121  dirlist = edsdir.entryList();
122  _ini = new rlIniFile();
123  for ( dirit = dirlist.begin(); dirit != dirlist.end(); ++dirit ) {
124  int searchval;
125 
126  QString exportname;
127 
128  edslocation = dirname + *dirit;
129  _ini->read(edslocation.ascii());
130  exportname =QString(_ini->text("DeviceInfo","ProductName"));
131  searchval = exportname.contains(productname, false);
132  if (searchval == 1){
133  return _ini;
134  }
135  }
136  delete _ini;
137  return 0;
138 }
139 
140 //---------------------------------------------------------------------------
142 void rlCanNode::readConfigurationMessage(RCS_MESSAGETELEGRAM_10& _message)
143 {
144 
145  int i;
146 
147  usIdentNumber = (unsigned short) (_message.d[2]+_message.d[1]*pow(256,1));
148  usVendorIdent = (unsigned short) (_message.d[4]+_message.d[3]*pow(256,1));
149 
150  for(i=0;i<32;i++)
151  {
152  abVendorName+=_message.d[5+i];
153  abDeviceName+=_message.d[37+i];
154  abDescription+=_message.d[69+i];
155  }
156 
157  bMasterAddress = _message.d[101];
158  bSettings = _message.d[102];
159  pdocount = _message.d[117];
160 
161  //transmit_pdoList.resize(pdocount);
162 
163  int startadress=118; // start index of pdos in buffer
164  int k = 0;
165  int tpdocounter = 0;
166  int rpdocounter = 0;
167 
168  for(i=1;i<=int(pdocount);i++)
169  {
170  rlCanPDO *tempPDO = new rlCanPDO;
171  tempPDO->bPDOSize = _message.d[startadress+k+1];
172  tempPDO->bDataPosition = _message.d[startadress+k+2];
173  tempPDO->usPDOAddress = (unsigned short)
174  (_message.d[startadress+k+3]*pow(256,0)
175  + _message.d[startadress+k+4]);
176 
177  if ((_message.d[startadress+k] & DATA_DIRECTION_MASK) == DIRECTION_INPUT)
178  {
179  rlDebugPrintf("\n tranceive pdo found ................\n");
180  tpdocounter++;
181  tempPDO->bPDODirection = DIRECTION_TRANSMIT; // => Tranceive PDO
183  pdoList[DIRECTION_TRANSMIT].insert(tpdocounter-1,tempPDO);
184  }
185  else if(
186  (_message.d[startadress+k] & DATA_DIRECTION_MASK) == DIRECTION_OUTPUT)
187  {
188  rlDebugPrintf("\n receive pdo found ................");
189  rpdocounter++;
190  tempPDO->bPDODirection = DIRECTION_RECEIVE; // => receive PDO
192  pdoList[DIRECTION_RECEIVE].insert(rpdocounter-1,tempPDO);
193  }
194  k=k+5;
195  }
196 
197 }
198 
201 {
202  cout<<"\n\n******** Configuration Board "
203  <<boardID<<" Node "<<nodeID <<" ********";
204 
205  cout<<"\n IdentNumber :" << usIdentNumber;
206  cout<<"\n VendorIdent :" <<usVendorIdent;
207  cout<<"\n Vendor Name :"<<abVendorName;
208  cout<<"\n Device Name :"<<abDeviceName;
209  cout<<"\n Description :"<<abDescription;
210  cout<<"\n PDO count :"<<int(pdocount);
211  cout<<"\n Master Adress :"<<int(bMasterAddress);
212  cout<<"\n Settings :"<<int(bSettings);
213 
214  cout<<"\n\n - - - - PDOs -> - - - - -";
215  unsigned int j;
216  for (j = 1;j<=pdoList[DIRECTION_TRANSMIT].size();j++)
217  {
218  cout<<"\n+ PDO No. "<<j;
219  cout<<"\nPDO Direction :Send PDO";
220  printf("\nPDO Size :%i",pdoList[DIRECTION_TRANSMIT][j-1]->bPDOSize);
221  printf("\nData Position :%i",pdoList[DIRECTION_TRANSMIT][j-1]->bDataPosition);
222  printf("\nPDO Adress :%i",pdoList[DIRECTION_TRANSMIT][j-1]->usPDOAddress);
223  }
224 
225  for (j = 1;j<=pdoList[DIRECTION_RECEIVE].size();j++)
226  {
227  cout<<"\n+ PDO No. "<<j;
228  cout<<"\nPDO Direction :Receive PDO";
229  printf("\nPDO Size :%i",pdoList[DIRECTION_RECEIVE][j-1]->bPDOSize);
230  printf("\nData Position :%i",pdoList[DIRECTION_RECEIVE][j-1]->bDataPosition);
231  printf("\nPDO Adress :%i",pdoList[DIRECTION_RECEIVE][j-1]->usPDOAddress);
232  }
233 
234  cout<<"\n **********************************************\n\n";
235 }
236 
237 //---------------------------------------------------------------------------
240 {
241  return nodeID;
242 }
243 //---------------------------------------------------------------------------
246 {
247  return boardID;
248 }
249 //---------------------------------------------------------------------------
250 int rlCanNode::objecttype(int objindex, int subindex)
251 {
252  QString edsbuffer;
253  bool ok;
254  int typenr;
255  if (objdir != 0) {
256  edsbuffer = objdir->get_objparameter(ObjDir::DATATYPE, objindex, subindex);
257  }
258  else
259  {
261  }
262 
263  if (edsbuffer == "ERROR"){
265  }
266  edsbuffer.remove("0x");
267  typenr = edsbuffer.toInt(&ok, 16);
268  if (!ok){
270  }
271  else
272  {
273  return typenr;
274 
275  }
276 }
277 
278 //---------------------------------------------------------------------------
281 {
282  return pdocount;
283 }
286 {
287  return pdoList[DIRECTION_RECEIVE].size();
288 }
291 {
292  return pdoList[DIRECTION_TRANSMIT].size();
293 }
296  if (objdir==0) return false;
297  else return true;
298 }
int rlDebugPrintf(const char *format,...)
Definition: rlcutil.cpp:61
#define DIRECTION_RECEIVE
definition of CanOpen structs for CanOpen Deamon
QString abDeviceName
Definition: rlcannode.h:128
int nodeID
current node ID (1-127)
Definition: rlcannode.h:98
#define TRANSMIT_PDO_MAPPING_MAXADRESS
const char * text(const char *section, const char *name)
Definition: rlinifile.cpp:208
#define DIRECTION_OUTPUT
int getBoardID()
returns the board ID the node is connected to.
Definition: rlcannode.cpp:245
#define DATA_DIRECTION_MASK
unsigned short usPDOAddress
fixes the PDO position in the card memory
#define DIRECTION_TRANSMIT
unsigned char pdocount
Definition: rlcannode.h:131
unsigned char bSettings
Definition: rlcannode.h:133
int objecttype(int objindex, int subindex)
returns the type of a specific entry in the object directory
Definition: rlcannode.cpp:250
int read(const char *filename)
Definition: rlinifile.cpp:116
unsigned char usVendorIdent
Unique vendor number if available.
Definition: rlcannode.h:124
short bPDODirection
1 = receive PDO / 2 = send PDO [indicate by PDO No]
#define TRANSMIT_PDO_MAPPING_STARTADRESS
QPtrVector< rlCanPDO > pdoList[2]
contains transmit PDOs
Definition: rlcannode.h:94
ObjDir * objdir
Definition: rlcannode.h:114
unsigned char bPDOSize
size of a PDO / max 8 Bytes
int boardID
curent board ID (0-3)
Definition: rlcannode.h:101
unsigned char bDataPosition
if only one bit is set in a PDO, this value shows its position
rlIniFile * ini
Definition: rlcannode.h:110
#define RECEIVE_PDO_MAPPING_MAXADRESS
#define DIRECTION_INPUT
QString abVendorName
specific node informations. extracted from message telegramm
Definition: rlcannode.h:127
int getNodeID()
returns the current node ID of the node
Definition: rlcannode.cpp:239
rlIniFile * getEDS(const char *_productstr)
finds the eds file matching the product string in [DeviceInfo] ProductName
Definition: rlcannode.cpp:109
unsigned char bMasterAddress
Definition: rlcannode.h:132
int getPdoCount()
returns the current number of all installed PDOs (Process Data Objects)
Definition: rlcannode.cpp:280
void readConfigurationMessage(RCS_MESSAGETELEGRAM_10 &_message)
reads out the configuration of a node from the CanOpenMaster board
Definition: rlcannode.cpp:142
QString edslocation
Definition: rlcannode.h:130
void showConfiguration()
prints out the configuration of the node
Definition: rlcannode.cpp:200
#define RECEIVE_PDO_MAPPING_STARTADRESS
int getTransmitPdoCount()
returns the current number of all installed transmit PDOs
Definition: rlcannode.cpp:290
int getReceivePdoCount()
returns the current number of all installed reiceive PDOs
Definition: rlcannode.cpp:285
unsigned short usIdentNumber
Unique device number if available.
Definition: rlcannode.h:121
PDO object which is part of one of the two pdo lists in the node class.
bool hasMapping()
indicates if a node available mapping
Definition: rlcannode.cpp:295
~rlCanNode()
calls destructors of rlinifile obj and objdir
Definition: rlcannode.cpp:97
QString abDescription
Definition: rlcannode.h:129