tool/cmd_sdos.cpp
changeset 1126 b09fd81894cb
child 1130 bb1c11adb2db
equal deleted inserted replaced
1125:9976f7b9fe66 1126:b09fd81894cb
       
     1 /*****************************************************************************
       
     2  *
       
     3  * $Id$
       
     4  *
       
     5  ****************************************************************************/
       
     6 
       
     7 #include <iostream>
       
     8 #include <iomanip>
       
     9 using namespace std;
       
    10 
       
    11 #include "globals.h"
       
    12 #include "coe_datatypes.h"
       
    13 
       
    14 /****************************************************************************/
       
    15 
       
    16 const char *help_sdos =
       
    17     "[OPTIONS]\n"
       
    18     "\n"
       
    19     "\n"
       
    20     "Command-specific options:\n";
       
    21 
       
    22 /****************************************************************************/
       
    23 
       
    24 void listSlaveSdos(uint16_t, bool);
       
    25 
       
    26 /****************************************************************************/
       
    27 
       
    28 void command_sdos(void)
       
    29 {
       
    30     masterDev.open(MasterDevice::Read);
       
    31 
       
    32     if (slavePosition == -1) {
       
    33         unsigned int numSlaves = masterDev.slaveCount(), i;
       
    34 
       
    35         for (i = 0; i < numSlaves; i++) {
       
    36             listSlaveSdos(i, true);
       
    37         }
       
    38     } else {
       
    39         listSlaveSdos(slavePosition, false);
       
    40     }
       
    41 }
       
    42 
       
    43 /****************************************************************************/
       
    44 
       
    45 void listSlaveSdos(
       
    46 		uint16_t slavePosition,
       
    47 		bool withHeader
       
    48 		)
       
    49 {
       
    50     ec_ioctl_slave_t slave;
       
    51     ec_ioctl_slave_sdo_t sdo;
       
    52     ec_ioctl_slave_sdo_entry_t entry;
       
    53     unsigned int i, j;
       
    54     const CoEDataType *d;
       
    55     
       
    56     masterDev.getSlave(&slave, slavePosition);
       
    57 
       
    58     if (withHeader)
       
    59         cout << "=== Slave " << slavePosition << " ===" << endl;
       
    60 
       
    61     for (i = 0; i < slave.sdo_count; i++) {
       
    62         masterDev.getSdo(&sdo, slavePosition, i);
       
    63 
       
    64         cout << "Sdo 0x"
       
    65             << hex << setfill('0')
       
    66             << setw(4) << sdo.sdo_index
       
    67             << ", \"" << sdo.name << "\"" << endl;
       
    68 
       
    69         if (verbosity == Quiet)
       
    70             continue;
       
    71 
       
    72         for (j = 0; j <= sdo.max_subindex; j++) {
       
    73             masterDev.getSdoEntry(&entry, slavePosition, -i, j);
       
    74 
       
    75             cout << "  0x" << hex << setfill('0')
       
    76                 << setw(4) << sdo.sdo_index << ":"
       
    77                 << setw(2) << (unsigned int) entry.sdo_entry_subindex
       
    78                 << ", ";
       
    79 
       
    80             if ((d = findDataType(entry.data_type))) {
       
    81                 cout << d->name;
       
    82             } else {
       
    83                 cout << "type " << setw(4) << entry.data_type;
       
    84             }
       
    85 
       
    86             cout << ", " << dec << entry.bit_length << " bit, \""
       
    87                 << entry.description << "\"" << endl;
       
    88         }
       
    89     }
       
    90 }
       
    91 
       
    92 /*****************************************************************************/