linux/slaveinfo/slaveinfo.c
Go to the documentation of this file.
1 
14 #include <stdio.h>
15 #include <string.h>
16 #include <inttypes.h>
17 
18 #include "ethercat.h"
19 
20 char IOmap[4096];
23 boolean printSDO = FALSE;
24 boolean printMAP = FALSE;
25 char usdo[128];
26 char hstr[1024];
27 
28 char* dtype2string(uint16 dtype)
29 {
30  switch(dtype)
31  {
32  case ECT_BOOLEAN:
33  sprintf(hstr, "BOOLEAN");
34  break;
35  case ECT_INTEGER8:
36  sprintf(hstr, "INTEGER8");
37  break;
38  case ECT_INTEGER16:
39  sprintf(hstr, "INTEGER16");
40  break;
41  case ECT_INTEGER32:
42  sprintf(hstr, "INTEGER32");
43  break;
44  case ECT_INTEGER24:
45  sprintf(hstr, "INTEGER24");
46  break;
47  case ECT_INTEGER64:
48  sprintf(hstr, "INTEGER64");
49  break;
50  case ECT_UNSIGNED8:
51  sprintf(hstr, "UNSIGNED8");
52  break;
53  case ECT_UNSIGNED16:
54  sprintf(hstr, "UNSIGNED16");
55  break;
56  case ECT_UNSIGNED32:
57  sprintf(hstr, "UNSIGNED32");
58  break;
59  case ECT_UNSIGNED24:
60  sprintf(hstr, "UNSIGNED24");
61  break;
62  case ECT_UNSIGNED64:
63  sprintf(hstr, "UNSIGNED64");
64  break;
65  case ECT_REAL32:
66  sprintf(hstr, "REAL32");
67  break;
68  case ECT_REAL64:
69  sprintf(hstr, "REAL64");
70  break;
71  case ECT_BIT1:
72  sprintf(hstr, "BIT1");
73  break;
74  case ECT_BIT2:
75  sprintf(hstr, "BIT2");
76  break;
77  case ECT_BIT3:
78  sprintf(hstr, "BIT3");
79  break;
80  case ECT_BIT4:
81  sprintf(hstr, "BIT4");
82  break;
83  case ECT_BIT5:
84  sprintf(hstr, "BIT5");
85  break;
86  case ECT_BIT6:
87  sprintf(hstr, "BIT6");
88  break;
89  case ECT_BIT7:
90  sprintf(hstr, "BIT7");
91  break;
92  case ECT_BIT8:
93  sprintf(hstr, "BIT8");
94  break;
95  case ECT_VISIBLE_STRING:
96  sprintf(hstr, "VISIBLE_STRING");
97  break;
98  case ECT_OCTET_STRING:
99  sprintf(hstr, "OCTET_STRING");
100  break;
101  default:
102  sprintf(hstr, "Type 0x%4.4X", dtype);
103  }
104  return hstr;
105 }
106 
107 char* SDO2string(uint16 slave, uint16 index, uint8 subidx, uint16 dtype)
108 {
109  int l = sizeof(usdo) - 1, i;
110  uint8 *u8;
111  int8 *i8;
112  uint16 *u16;
113  int16 *i16;
114  uint32 *u32;
115  int32 *i32;
116  uint64 *u64;
117  int64 *i64;
118  float *sr;
119  double *dr;
120  char es[32];
121 
122  memset(&usdo, 0, 128);
123  ec_SDOread(slave, index, subidx, FALSE, &l, &usdo, EC_TIMEOUTRXM);
124  if (EcatError)
125  {
126  return ec_elist2string();
127  }
128  else
129  {
130  switch(dtype)
131  {
132  case ECT_BOOLEAN:
133  u8 = (uint8*) &usdo[0];
134  if (*u8) sprintf(hstr, "TRUE");
135  else sprintf(hstr, "FALSE");
136  break;
137  case ECT_INTEGER8:
138  i8 = (int8*) &usdo[0];
139  sprintf(hstr, "0x%2.2x %d", *i8, *i8);
140  break;
141  case ECT_INTEGER16:
142  i16 = (int16*) &usdo[0];
143  sprintf(hstr, "0x%4.4x %d", *i16, *i16);
144  break;
145  case ECT_INTEGER32:
146  case ECT_INTEGER24:
147  i32 = (int32*) &usdo[0];
148  sprintf(hstr, "0x%8.8x %d", *i32, *i32);
149  break;
150  case ECT_INTEGER64:
151  i64 = (int64*) &usdo[0];
152  sprintf(hstr, "0x%16.16"PRIx64" %"PRId64, *i64, *i64);
153  break;
154  case ECT_UNSIGNED8:
155  u8 = (uint8*) &usdo[0];
156  sprintf(hstr, "0x%2.2x %u", *u8, *u8);
157  break;
158  case ECT_UNSIGNED16:
159  u16 = (uint16*) &usdo[0];
160  sprintf(hstr, "0x%4.4x %u", *u16, *u16);
161  break;
162  case ECT_UNSIGNED32:
163  case ECT_UNSIGNED24:
164  u32 = (uint32*) &usdo[0];
165  sprintf(hstr, "0x%8.8x %u", *u32, *u32);
166  break;
167  case ECT_UNSIGNED64:
168  u64 = (uint64*) &usdo[0];
169  sprintf(hstr, "0x%16.16"PRIx64" %"PRIu64, *u64, *u64);
170  break;
171  case ECT_REAL32:
172  sr = (float*) &usdo[0];
173  sprintf(hstr, "%f", *sr);
174  break;
175  case ECT_REAL64:
176  dr = (double*) &usdo[0];
177  sprintf(hstr, "%f", *dr);
178  break;
179  case ECT_BIT1:
180  case ECT_BIT2:
181  case ECT_BIT3:
182  case ECT_BIT4:
183  case ECT_BIT5:
184  case ECT_BIT6:
185  case ECT_BIT7:
186  case ECT_BIT8:
187  u8 = (uint8*) &usdo[0];
188  sprintf(hstr, "0x%x", *u8);
189  break;
190  case ECT_VISIBLE_STRING:
191  strcpy(hstr, usdo);
192  break;
193  case ECT_OCTET_STRING:
194  hstr[0] = 0x00;
195  for (i = 0 ; i < l ; i++)
196  {
197  sprintf(es, "0x%2.2x ", usdo[i]);
198  strcat( hstr, es);
199  }
200  break;
201  default:
202  sprintf(hstr, "Unknown type");
203  }
204  return hstr;
205  }
206 }
207 
209 int si_PDOassign(uint16 slave, uint16 PDOassign, int mapoffset, int bitoffset)
210 {
211  uint16 idxloop, nidx, subidxloop, rdat, idx, subidx;
212  uint8 subcnt;
213  int wkc, bsize = 0, rdl;
214  int32 rdat2;
215  uint8 bitlen, obj_subidx;
216  uint16 obj_idx;
217  int abs_offset, abs_bit;
218 
219  rdl = sizeof(rdat); rdat = 0;
220  /* read PDO assign subindex 0 ( = number of PDO's) */
221  wkc = ec_SDOread(slave, PDOassign, 0x00, FALSE, &rdl, &rdat, EC_TIMEOUTRXM);
222  rdat = etohs(rdat);
223  /* positive result from slave ? */
224  if ((wkc > 0) && (rdat > 0))
225  {
226  /* number of available sub indexes */
227  nidx = rdat;
228  bsize = 0;
229  /* read all PDO's */
230  for (idxloop = 1; idxloop <= nidx; idxloop++)
231  {
232  rdl = sizeof(rdat); rdat = 0;
233  /* read PDO assign */
234  wkc = ec_SDOread(slave, PDOassign, (uint8)idxloop, FALSE, &rdl, &rdat, EC_TIMEOUTRXM);
235  /* result is index of PDO */
236  idx = etohs(rdat);
237  if (idx > 0)
238  {
239  rdl = sizeof(subcnt); subcnt = 0;
240  /* read number of subindexes of PDO */
241  wkc = ec_SDOread(slave,idx, 0x00, FALSE, &rdl, &subcnt, EC_TIMEOUTRXM);
242  subidx = subcnt;
243  /* for each subindex */
244  for (subidxloop = 1; subidxloop <= subidx; subidxloop++)
245  {
246  rdl = sizeof(rdat2); rdat2 = 0;
247  /* read SDO that is mapped in PDO */
248  wkc = ec_SDOread(slave, idx, (uint8)subidxloop, FALSE, &rdl, &rdat2, EC_TIMEOUTRXM);
249  rdat2 = etohl(rdat2);
250  /* extract bitlength of SDO */
251  bitlen = LO_BYTE(rdat2);
252  bsize += bitlen;
253  obj_idx = (uint16)(rdat2 >> 16);
254  obj_subidx = (uint8)((rdat2 >> 8) & 0x000000ff);
255  abs_offset = mapoffset + (bitoffset / 8);
256  abs_bit = bitoffset % 8;
257  ODlist.Slave = slave;
258  ODlist.Index[0] = obj_idx;
259  OElist.Entries = 0;
260  wkc = 0;
261  /* read object entry from dictionary if not a filler (0x0000:0x00) */
262  if(obj_idx || obj_subidx)
263  wkc = ec_readOEsingle(0, obj_subidx, &ODlist, &OElist);
264  printf(" [0x%4.4X.%1d] 0x%4.4X:0x%2.2X 0x%2.2X", abs_offset, abs_bit, obj_idx, obj_subidx, bitlen);
265  if((wkc > 0) && OElist.Entries)
266  {
267  printf(" %-12s %s\n", dtype2string(OElist.DataType[obj_subidx]), OElist.Name[obj_subidx]);
268  }
269  else
270  printf("\n");
271  bitoffset += bitlen;
272  };
273  };
274  };
275  };
276  /* return total found bitlength (PDO) */
277  return bsize;
278 }
279 
281 {
282  int wkc, rdl;
283  int retVal = 0;
284  uint8 nSM, iSM, tSM;
285  int Tsize, outputs_bo, inputs_bo;
286  uint8 SMt_bug_add;
287 
288  printf("PDO mapping according to CoE :\n");
289  SMt_bug_add = 0;
290  outputs_bo = 0;
291  inputs_bo = 0;
292  rdl = sizeof(nSM); nSM = 0;
293  /* read SyncManager Communication Type object count */
294  wkc = ec_SDOread(slave, ECT_SDO_SMCOMMTYPE, 0x00, FALSE, &rdl, &nSM, EC_TIMEOUTRXM);
295  /* positive result from slave ? */
296  if ((wkc > 0) && (nSM > 2))
297  {
298  /* make nSM equal to number of defined SM */
299  nSM--;
300  /* limit to maximum number of SM defined, if true the slave can't be configured */
301  if (nSM > EC_MAXSM)
302  nSM = EC_MAXSM;
303  /* iterate for every SM type defined */
304  for (iSM = 2 ; iSM <= nSM ; iSM++)
305  {
306  rdl = sizeof(tSM); tSM = 0;
307  /* read SyncManager Communication Type */
308  wkc = ec_SDOread(slave, ECT_SDO_SMCOMMTYPE, iSM + 1, FALSE, &rdl, &tSM, EC_TIMEOUTRXM);
309  if (wkc > 0)
310  {
311  if((iSM == 2) && (tSM == 2)) // SM2 has type 2 == mailbox out, this is a bug in the slave!
312  {
313  SMt_bug_add = 1; // try to correct, this works if the types are 0 1 2 3 and should be 1 2 3 4
314  printf("Activated SM type workaround, possible incorrect mapping.\n");
315  }
316  if(tSM)
317  tSM += SMt_bug_add; // only add if SMt > 0
318 
319  if (tSM == 3) // outputs
320  {
321  /* read the assign RXPDO */
322  printf(" SM%1d outputs\n addr b index: sub bitl data_type name\n", iSM);
323  Tsize = si_PDOassign(slave, ECT_SDO_PDOASSIGN + iSM, (int)(ec_slave[slave].outputs - (uint8 *)&IOmap[0]), outputs_bo );
324  outputs_bo += Tsize;
325  }
326  if (tSM == 4) // inputs
327  {
328  /* read the assign TXPDO */
329  printf(" SM%1d inputs\n addr b index: sub bitl data_type name\n", iSM);
330  Tsize = si_PDOassign(slave, ECT_SDO_PDOASSIGN + iSM, (int)(ec_slave[slave].inputs - (uint8 *)&IOmap[0]), inputs_bo );
331  inputs_bo += Tsize;
332  }
333  }
334  }
335  }
336 
337  /* found some I/O bits ? */
338  if ((outputs_bo > 0) || (inputs_bo > 0))
339  retVal = 1;
340  return retVal;
341 }
342 
343 int si_siiPDO(uint16 slave, uint8 t, int mapoffset, int bitoffset)
344 {
345  uint16 a , w, c, e, er, Size;
346  uint8 eectl;
347  uint16 obj_idx;
348  uint8 obj_subidx;
349  uint8 obj_name;
350  uint8 obj_datatype;
351  uint8 bitlen;
352  int totalsize;
353  ec_eepromPDOt eepPDO;
354  ec_eepromPDOt *PDO;
355  int abs_offset, abs_bit;
356  char str_name[EC_MAXNAME + 1];
357 
358  eectl = ec_slave[slave].eep_pdi;
359  Size = 0;
360  totalsize = 0;
361  PDO = &eepPDO;
362  PDO->nPDO = 0;
363  PDO->Length = 0;
364  PDO->Index[1] = 0;
365  for (c = 0 ; c < EC_MAXSM ; c++) PDO->SMbitsize[c] = 0;
366  if (t > 1)
367  t = 1;
368  PDO->Startpos = ec_siifind(slave, ECT_SII_PDO + t);
369  if (PDO->Startpos > 0)
370  {
371  a = PDO->Startpos;
372  w = ec_siigetbyte(slave, a++);
373  w += (ec_siigetbyte(slave, a++) << 8);
374  PDO->Length = w;
375  c = 1;
376  /* traverse through all PDOs */
377  do
378  {
379  PDO->nPDO++;
380  PDO->Index[PDO->nPDO] = ec_siigetbyte(slave, a++);
381  PDO->Index[PDO->nPDO] += (ec_siigetbyte(slave, a++) << 8);
382  PDO->BitSize[PDO->nPDO] = 0;
383  c++;
384  /* number of entries in PDO */
385  e = ec_siigetbyte(slave, a++);
386  PDO->SyncM[PDO->nPDO] = ec_siigetbyte(slave, a++);
387  a++;
388  obj_name = ec_siigetbyte(slave, a++);
389  a += 2;
390  c += 2;
391  if (PDO->SyncM[PDO->nPDO] < EC_MAXSM) /* active and in range SM? */
392  {
393  str_name[0] = 0;
394  if(obj_name)
395  ec_siistring(str_name, slave, obj_name);
396  if (t)
397  printf(" SM%1d RXPDO 0x%4.4X %s\n", PDO->SyncM[PDO->nPDO], PDO->Index[PDO->nPDO], str_name);
398  else
399  printf(" SM%1d TXPDO 0x%4.4X %s\n", PDO->SyncM[PDO->nPDO], PDO->Index[PDO->nPDO], str_name);
400  printf(" addr b index: sub bitl data_type name\n");
401  /* read all entries defined in PDO */
402  for (er = 1; er <= e; er++)
403  {
404  c += 4;
405  obj_idx = ec_siigetbyte(slave, a++);
406  obj_idx += (ec_siigetbyte(slave, a++) << 8);
407  obj_subidx = ec_siigetbyte(slave, a++);
408  obj_name = ec_siigetbyte(slave, a++);
409  obj_datatype = ec_siigetbyte(slave, a++);
410  bitlen = ec_siigetbyte(slave, a++);
411  abs_offset = mapoffset + (bitoffset / 8);
412  abs_bit = bitoffset % 8;
413 
414  PDO->BitSize[PDO->nPDO] += bitlen;
415  a += 2;
416 
417  /* skip entry if filler (0x0000:0x00) */
418  if(obj_idx || obj_subidx)
419  {
420  str_name[0] = 0;
421  if(obj_name)
422  ec_siistring(str_name, slave, obj_name);
423 
424  printf(" [0x%4.4X.%1d] 0x%4.4X:0x%2.2X 0x%2.2X", abs_offset, abs_bit, obj_idx, obj_subidx, bitlen);
425  printf(" %-12s %s\n", dtype2string(obj_datatype), str_name);
426  }
427  bitoffset += bitlen;
428  totalsize += bitlen;
429  }
430  PDO->SMbitsize[ PDO->SyncM[PDO->nPDO] ] += PDO->BitSize[PDO->nPDO];
431  Size += PDO->BitSize[PDO->nPDO];
432  c++;
433  }
434  else /* PDO deactivated because SM is 0xff or > EC_MAXSM */
435  {
436  c += 4 * e;
437  a += 8 * e;
438  c++;
439  }
440  if (PDO->nPDO >= (EC_MAXEEPDO - 1)) c = PDO->Length; /* limit number of PDO entries in buffer */
441  }
442  while (c < PDO->Length);
443  }
444  if (eectl) ec_eeprom2pdi(slave); /* if eeprom control was previously pdi then restore */
445  return totalsize;
446 }
447 
448 
450 {
451  int retVal = 0;
452  int Tsize, outputs_bo, inputs_bo;
453 
454  printf("PDO mapping according to SII :\n");
455 
456  outputs_bo = 0;
457  inputs_bo = 0;
458  /* read the assign RXPDOs */
459  Tsize = si_siiPDO(slave, 1, (int)(ec_slave[slave].outputs - (uint8*)&IOmap), outputs_bo );
460  outputs_bo += Tsize;
461  /* read the assign TXPDOs */
462  Tsize = si_siiPDO(slave, 0, (int)(ec_slave[slave].inputs - (uint8*)&IOmap), inputs_bo );
463  inputs_bo += Tsize;
464  /* found some I/O bits ? */
465  if ((outputs_bo > 0) || (inputs_bo > 0))
466  retVal = 1;
467  return retVal;
468 }
469 
470 void si_sdo(int cnt)
471 {
472  int i, j;
473 
474  ODlist.Entries = 0;
475  memset(&ODlist, 0, sizeof(ODlist));
476  if( ec_readODlist(cnt, &ODlist))
477  {
478  printf(" CoE Object Description found, %d entries.\n",ODlist.Entries);
479  for( i = 0 ; i < ODlist.Entries ; i++)
480  {
481  ec_readODdescription(i, &ODlist);
482  while(EcatError) printf("%s", ec_elist2string());
483  printf(" Index: %4.4x Datatype: %4.4x Objectcode: %2.2x Name: %s\n",
484  ODlist.Index[i], ODlist.DataType[i], ODlist.ObjectCode[i], ODlist.Name[i]);
485  memset(&OElist, 0, sizeof(OElist));
486  ec_readOE(i, &ODlist, &OElist);
487  while(EcatError) printf("%s", ec_elist2string());
488  for( j = 0 ; j < ODlist.MaxSub[i]+1 ; j++)
489  {
490  if ((OElist.DataType[j] > 0) && (OElist.BitLength[j] > 0))
491  {
492  printf(" Sub: %2.2x Datatype: %4.4x Bitlength: %4.4x Obj.access: %4.4x Name: %s\n",
493  j, OElist.DataType[j], OElist.BitLength[j], OElist.ObjAccess[j], OElist.Name[j]);
494  if ((OElist.ObjAccess[j] & 0x0007))
495  {
496  printf(" Value :%s\n", SDO2string(cnt, ODlist.Index[i], j, OElist.DataType[j]));
497  }
498  }
499  }
500  }
501  }
502  else
503  {
504  while(EcatError) printf("%s", ec_elist2string());
505  }
506 }
507 
508 void slaveinfo(char *ifname)
509 {
510  int cnt, i, j, nSM;
511  uint16 ssigen;
512  int expectedWKC;
513 
514  printf("Starting slaveinfo\n");
515 
516  /* initialise SOEM, bind socket to ifname */
517  if (ec_init(ifname))
518  {
519  printf("ec_init on %s succeeded.\n",ifname);
520  /* find and auto-config slaves */
521  if ( ec_config(FALSE, &IOmap) > 0 )
522  {
523  ec_configdc();
524  while(EcatError) printf("%s", ec_elist2string());
525  printf("%d slaves found and configured.\n",ec_slavecount);
526  expectedWKC = (ec_group[0].outputsWKC * 2) + ec_group[0].inputsWKC;
527  printf("Calculated workcounter %d\n", expectedWKC);
528  /* wait for all slaves to reach SAFE_OP state */
530  if (ec_slave[0].state != EC_STATE_SAFE_OP )
531  {
532  printf("Not all slaves reached safe operational state.\n");
533  ec_readstate();
534  for(i = 1; i<=ec_slavecount ; i++)
535  {
536  if(ec_slave[i].state != EC_STATE_SAFE_OP)
537  {
538  printf("Slave %d State=%2x StatusCode=%4x : %s\n",
539  i, ec_slave[i].state, ec_slave[i].ALstatuscode, ec_ALstatuscode2string(ec_slave[i].ALstatuscode));
540  }
541  }
542  }
543 
544 
545  ec_readstate();
546  for( cnt = 1 ; cnt <= ec_slavecount ; cnt++)
547  {
548  printf("\nSlave:%d\n Name:%s\n Output size: %dbits\n Input size: %dbits\n State: %d\n Delay: %d[ns]\n Has DC: %d\n",
549  cnt, ec_slave[cnt].name, ec_slave[cnt].Obits, ec_slave[cnt].Ibits,
550  ec_slave[cnt].state, ec_slave[cnt].pdelay, ec_slave[cnt].hasdc);
551  if (ec_slave[cnt].hasdc) printf(" DCParentport:%d\n", ec_slave[cnt].parentport);
552  printf(" Activeports:%d.%d.%d.%d\n", (ec_slave[cnt].activeports & 0x01) > 0 ,
553  (ec_slave[cnt].activeports & 0x02) > 0 ,
554  (ec_slave[cnt].activeports & 0x04) > 0 ,
555  (ec_slave[cnt].activeports & 0x08) > 0 );
556  printf(" Configured address: %4.4x\n", ec_slave[cnt].configadr);
557  printf(" Man: %8.8x ID: %8.8x Rev: %8.8x\n", (int)ec_slave[cnt].eep_man, (int)ec_slave[cnt].eep_id, (int)ec_slave[cnt].eep_rev);
558  for(nSM = 0 ; nSM < EC_MAXSM ; nSM++)
559  {
560  if(ec_slave[cnt].SM[nSM].StartAddr > 0)
561  printf(" SM%1d A:%4.4x L:%4d F:%8.8x Type:%d\n",nSM, etohs(ec_slave[cnt].SM[nSM].StartAddr), etohs(ec_slave[cnt].SM[nSM].SMlength),
562  etohl(ec_slave[cnt].SM[nSM].SMflags), ec_slave[cnt].SMtype[nSM]);
563  }
564  for(j = 0 ; j < ec_slave[cnt].FMMUunused ; j++)
565  {
566  printf(" FMMU%1d Ls:%8.8x Ll:%4d Lsb:%d Leb:%d Ps:%4.4x Psb:%d Ty:%2.2x Act:%2.2x\n", j,
567  etohl(ec_slave[cnt].FMMU[j].LogStart), etohs(ec_slave[cnt].FMMU[j].LogLength), ec_slave[cnt].FMMU[j].LogStartbit,
568  ec_slave[cnt].FMMU[j].LogEndbit, etohs(ec_slave[cnt].FMMU[j].PhysStart), ec_slave[cnt].FMMU[j].PhysStartBit,
569  ec_slave[cnt].FMMU[j].FMMUtype, ec_slave[cnt].FMMU[j].FMMUactive);
570  }
571  printf(" FMMUfunc 0:%d 1:%d 2:%d 3:%d\n",
572  ec_slave[cnt].FMMU0func, ec_slave[cnt].FMMU1func, ec_slave[cnt].FMMU2func, ec_slave[cnt].FMMU3func);
573  printf(" MBX length wr: %d rd: %d MBX protocols : %2.2x\n", ec_slave[cnt].mbx_l, ec_slave[cnt].mbx_rl, ec_slave[cnt].mbx_proto);
574  ssigen = ec_siifind(cnt, ECT_SII_GENERAL);
575  /* SII general section */
576  if (ssigen)
577  {
578  ec_slave[cnt].CoEdetails = ec_siigetbyte(cnt, ssigen + 0x07);
579  ec_slave[cnt].FoEdetails = ec_siigetbyte(cnt, ssigen + 0x08);
580  ec_slave[cnt].EoEdetails = ec_siigetbyte(cnt, ssigen + 0x09);
581  ec_slave[cnt].SoEdetails = ec_siigetbyte(cnt, ssigen + 0x0a);
582  if((ec_siigetbyte(cnt, ssigen + 0x0d) & 0x02) > 0)
583  {
584  ec_slave[cnt].blockLRW = 1;
585  ec_slave[0].blockLRW++;
586  }
587  ec_slave[cnt].Ebuscurrent = ec_siigetbyte(cnt, ssigen + 0x0e);
588  ec_slave[cnt].Ebuscurrent += ec_siigetbyte(cnt, ssigen + 0x0f) << 8;
590  }
591  printf(" CoE details: %2.2x FoE details: %2.2x EoE details: %2.2x SoE details: %2.2x\n",
592  ec_slave[cnt].CoEdetails, ec_slave[cnt].FoEdetails, ec_slave[cnt].EoEdetails, ec_slave[cnt].SoEdetails);
593  printf(" Ebus current: %d[mA]\n only LRD/LWR:%d\n",
594  ec_slave[cnt].Ebuscurrent, ec_slave[cnt].blockLRW);
595  if ((ec_slave[cnt].mbx_proto & ECT_MBXPROT_COE) && printSDO)
596  si_sdo(cnt);
597  if(printMAP)
598  {
599  if (ec_slave[cnt].mbx_proto & ECT_MBXPROT_COE)
600  si_map_sdo(cnt);
601  else
602  si_map_sii(cnt);
603  }
604  }
605  }
606  else
607  {
608  printf("No slaves found!\n");
609  }
610  printf("End slaveinfo, close socket\n");
611  /* stop SOEM, close socket */
612  ec_close();
613  }
614  else
615  {
616  printf("No socket connection on %s\nExcecute as root\n",ifname);
617  }
618 }
619 
620 char ifbuf[1024];
621 
622 int main(int argc, char *argv[])
623 {
624  ec_adaptert * adapter = NULL;
625  printf("SOEM (Simple Open EtherCAT Master)\nSlaveinfo\n");
626 
627  if (argc > 1)
628  {
629  if ((argc > 2) && (strncmp(argv[2], "-sdo", sizeof("-sdo")) == 0)) printSDO = TRUE;
630  if ((argc > 2) && (strncmp(argv[2], "-map", sizeof("-map")) == 0)) printMAP = TRUE;
631  /* start slaveinfo */
632  strcpy(ifbuf, argv[1]);
633  slaveinfo(ifbuf);
634  }
635  else
636  {
637  printf("Usage: slaveinfo ifname [options]\nifname = eth0 for example\nOptions :\n -sdo : print SDO info\n -map : print mapping\n");
638 
639  printf ("Available adapters\n");
640  adapter = ec_find_adapters ();
641  while (adapter != NULL)
642  {
643  printf ("Description : %s, Device to use for wpcap: %s\n", adapter->desc,adapter->name);
644  adapter = adapter->next;
645  }
646  }
647 
648  printf("End program\n");
649  return (0);
650 }
int expectedWKC
Definition: eoe_test.c:33
uint16 ObjAccess[EC_MAXOELIST]
Definition: ethercatcoe.h:56
char * ec_ALstatuscode2string(uint16 ALstatuscode)
char usdo[128]
int ec_readstate(void)
uint8 ec_siigetbyte(uint16 slave, uint16 address)
uint16 outputsWKC
Definition: ethercatmain.h:266
#define EC_TIMEOUTSTATE
Definition: ethercattype.h:76
char name[EC_MAXLEN_ADAPTERNAME]
Definition: ethercatmain.h:46
uint8 MaxSub[EC_MAXODLIST]
Definition: ethercatcoe.h:39
uint8_t uint8
Definition: osal.h:28
char hstr[1024]
#define ECT_SDO_PDOASSIGN
Definition: ethercattype.h:452
uint8 FoEdetails
Definition: ethercatmain.h:215
int16 Ebuscurrent
Definition: ethercatmain.h:221
int si_siiPDO(uint16 slave, uint8 t, int mapoffset, int bitoffset)
Headerfile for all ethercat headers.
ec_adaptert * next
Definition: ethercatmain.h:48
uint8 eep_pdi
Definition: ethercatmain.h:211
int ec_init(const char *ifname)
uint16_t uint16
Definition: osal.h:29
uint16 Index[EC_MAXEEPDO]
Definition: ethercatmain.h:305
char * ec_elist2string(void)
#define EC_TIMEOUTRXM
Definition: ethercattype.h:74
#define EC_MAXEEPDO
Definition: ethercatmain.h:33
#define etohs(A)
Definition: ethercattype.h:536
#define TRUE
Definition: osal.h:19
void ec_siistring(char *str, uint16 slave, uint16 Sn)
int ec_readODlist(uint16 Slave, ec_ODlistt *pODlist)
Definition: ethercatcoe.c:1471
uint8 CoEdetails
Definition: ethercatmain.h:213
#define EC_MAXSM
Definition: ethercatmain.h:35
char desc[EC_MAXLEN_ADAPTERNAME]
Definition: ethercatmain.h:47
int ec_eeprom2pdi(uint16 slave)
int ec_readOE(uint16 Item, ec_ODlistt *pODlist, ec_OElistt *pOElist)
Definition: ethercatcoe.c:1501
#define PRIx64
Definition: inttypes.h:133
#define ECT_SDO_SMCOMMTYPE
Definition: ethercattype.h:450
#define ECT_MBXPROT_COE
Definition: ethercatmain.h:89
char * dtype2string(uint16 dtype)
int ec_readODdescription(uint16 Item, ec_ODlistt *pODlist)
Definition: ethercatcoe.c:1483
uint16 Slave
Definition: ethercatcoe.h:29
ec_OElistt OElist
boolean printSDO
uint16 Index[EC_MAXODLIST]
Definition: ethercatcoe.h:33
uint16 SMbitsize[EC_MAXSM]
Definition: ethercatmain.h:308
int ec_slavecount
Definition: ethercatmain.c:69
uint8 blockLRW
Definition: ethercatmain.h:223
int slave
Definition: aliastool.c:44
int64_t int64
Definition: osal.h:31
#define FALSE
Definition: osal.h:22
int32_t int32
Definition: osal.h:27
char * SDO2string(uint16 slave, uint16 index, uint8 subidx, uint16 dtype)
#define LO_BYTE(w)
Definition: ethercattype.h:514
int si_PDOassign(uint16 slave, uint16 PDOassign, int mapoffset, int bitoffset)
int8_t int8
Definition: osal.h:25
int16 ec_siifind(uint16 slave, uint16 cat)
char ifbuf[1024]
boolean EcatError
Definition: ethercatmain.c:93
uint16 BitLength[EC_MAXOELIST]
Definition: ethercatcoe.h:54
uint64_t uint64
Definition: osal.h:32
char Name[EC_MAXOELIST][EC_MAXNAME+1]
Definition: ethercatcoe.h:58
void slaveinfo(char *ifname)
uint8 EoEdetails
Definition: ethercatmain.h:217
uint16 DataType[EC_MAXODLIST]
Definition: ethercatcoe.h:35
int wkc
Definition: aliastool.c:47
#define EC_MAXNAME
Definition: ethercatmain.h:23
int ec_config(uint8 usetable, void *pIOmap)
#define PRIu64
Definition: inttypes.h:132
boolean ec_configdc(void)
Definition: ethercatdc.c:444
#define etohl(A)
Definition: ethercattype.h:537
int si_map_sii(int slave)
uint8 ObjectCode[EC_MAXODLIST]
Definition: ethercatcoe.h:37
uint32_t uint32
Definition: osal.h:30
boolean printMAP
uint16 Entries
Definition: ethercatcoe.h:31
ec_adaptert * ec_find_adapters(void)
Definition: ethercatmain.c:131
uint16 Entries
Definition: ethercatcoe.h:48
int main(int argc, char *argv[])
uint8 SoEdetails
Definition: ethercatmain.h:219
int16_t int16
Definition: osal.h:26
#define PRId64
Definition: inttypes.h:78
int si_map_sdo(int slave)
void ec_close(void)
uint8 FMMUunused
Definition: ethercatmain.h:227
char Name[EC_MAXODLIST][EC_MAXNAME+1]
Definition: ethercatcoe.h:41
int ec_SDOread(uint16 slave, uint16 index, uint8 subindex, boolean CA, int *psize, void *p, int timeout)
Definition: ethercatcoe.c:1344
uint16 ec_statecheck(uint16 slave, uint16 reqstate, int timeout)
int ec_readOEsingle(uint16 Item, uint8 SubI, ec_ODlistt *pODlist, ec_OElistt *pOElist)
Definition: ethercatcoe.c:1488
uint16 SyncM[EC_MAXEEPDO]
Definition: ethercatmain.h:306
uint16 Startpos
Definition: ethercatmain.h:302
uint16 BitSize[EC_MAXEEPDO]
Definition: ethercatmain.h:307
ec_ODlistt ODlist
void si_sdo(int cnt)
uint16 DataType[EC_MAXOELIST]
Definition: ethercatcoe.h:52
char IOmap[4096]


soem
Author(s): Arthur Ketels and M.J.G. van den Molengraft
autogenerated on Sat Jun 27 2020 03:48:21