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


soem
Author(s): Arthur Ketels and M.J.G. van den Molengraft
autogenerated on Sat Jun 8 2019 18:02:17