tool/cmd_pdos.cpp
changeset 1142 59be91dfcbe1
parent 1141 7ffbca63fc72
child 1143 09ee878d7214
equal deleted inserted replaced
1141:7ffbca63fc72 1142:59be91dfcbe1
     1 /*****************************************************************************
       
     2  *
       
     3  * $Id$
       
     4  *
       
     5  ****************************************************************************/
       
     6 
       
     7 #include <iostream>
       
     8 #include <iomanip>
       
     9 using namespace std;
       
    10 
       
    11 #include "globals.h"
       
    12 
       
    13 /****************************************************************************/
       
    14 
       
    15 const char *help_pdos =
       
    16     "[OPTIONS]\n"
       
    17     "\n"
       
    18     "Displays sync managers, assigned Pdos and mapped Pdo entries.\n"
       
    19     "\n"
       
    20     "The information is displayed in three layers, which are indented\n"
       
    21     "accordingly:\n"
       
    22     "\n"
       
    23     "1) Sync managers - Contains the sync manager information from the\n"
       
    24     "   SII: Index, physical start address, default size (raw value from\n"
       
    25     "   the SII), control register and enable word. Example:\n"
       
    26     "\n"
       
    27     "   SM3: PhysAddr 0x1100, DefaultSize 0, ControlRegister 0x20, Enable 1\n"
       
    28     "\n"
       
    29     "2) Assigned Pdos - Pdo direction, hexadecimal index and -if available-\n"
       
    30     "   the Pdo name. Example:\n"
       
    31     "\n"
       
    32     "   TxPdo 0x1a00 \"Channel1\"\n"
       
    33     "\n"
       
    34     "3) Mapped Pdo entries - Pdo entry index and subindex (both\n"
       
    35     "   hexadecimal), the length in bit and -if available- the\n"
       
    36     "   description. Example:\n"
       
    37     "\n"
       
    38     "   Pdo entry 0x3101:01, 8 bit, \"Status\"\n"
       
    39     "\n"
       
    40     "Note, that the displayed Pdo assignment and Pdo mapping information\n"
       
    41     "can either originate from the SII or from the CoE communication area.\n"
       
    42     "\n"
       
    43     "Command-specific options:\n"
       
    44     "  --slave -s <index>  Positive numerical ring position, or 'all' for\n"
       
    45     "                      all slaves (default).\n"
       
    46     "\n"
       
    47     "Numerical values can be specified either with decimal (no prefix),\n"
       
    48     "octal (prefix '0') or hexadecimal (prefix '0x') base.\n";
       
    49 
       
    50 /****************************************************************************/
       
    51 	
       
    52 void listSlavePdos(uint16_t, bool);
       
    53 
       
    54 /****************************************************************************/
       
    55 
       
    56 void command_pdos(void)
       
    57 {
       
    58     masterDev.open(MasterDevice::Read);
       
    59 
       
    60     if (slavePosition == -1) {
       
    61         unsigned int numSlaves = masterDev.slaveCount(), i;
       
    62 
       
    63         for (i = 0; i < numSlaves; i++) {
       
    64             listSlavePdos(i, true);
       
    65         }
       
    66     } else {
       
    67         listSlavePdos(slavePosition, false);
       
    68     }
       
    69 }
       
    70 
       
    71 /****************************************************************************/
       
    72 
       
    73 void listSlavePdos(uint16_t slavePosition, bool withHeader)
       
    74 {
       
    75     ec_ioctl_slave_t slave;
       
    76     ec_ioctl_slave_sync_t sync;
       
    77     ec_ioctl_slave_sync_pdo_t pdo;
       
    78     ec_ioctl_slave_sync_pdo_entry_t entry;
       
    79     unsigned int i, j, k;
       
    80     
       
    81     masterDev.getSlave(&slave, slavePosition);
       
    82 
       
    83     if (withHeader)
       
    84         cout << "=== Slave " << slavePosition << " ===" << endl;
       
    85 
       
    86     for (i = 0; i < slave.sync_count; i++) {
       
    87         masterDev.getSync(&sync, slavePosition, i);
       
    88 
       
    89         cout << "SM" << i << ":"
       
    90             << " PhysAddr 0x"
       
    91             << hex << setfill('0')
       
    92             << setw(4) << sync.physical_start_address
       
    93             << ", DefaultSize "
       
    94             << dec << setfill(' ') << setw(4) << sync.default_size
       
    95             << ", ControlRegister 0x"
       
    96             << hex << setfill('0') << setw(2)
       
    97             << (unsigned int) sync.control_register
       
    98             << ", Enable " << dec << (unsigned int) sync.enable
       
    99             << endl;
       
   100 
       
   101         for (j = 0; j < sync.pdo_count; j++) {
       
   102             masterDev.getPdo(&pdo, slavePosition, i, j);
       
   103 
       
   104             cout << "  " << (sync.control_register & 0x04 ? "R" : "T")
       
   105                 << "xPdo 0x"
       
   106                 << hex << setfill('0')
       
   107                 << setw(4) << pdo.index
       
   108                 << " \"" << pdo.name << "\"" << endl;
       
   109 
       
   110             if (verbosity == Quiet)
       
   111                 continue;
       
   112 
       
   113             for (k = 0; k < pdo.entry_count; k++) {
       
   114                 masterDev.getPdoEntry(&entry, slavePosition, i, j, k);
       
   115 
       
   116                 cout << "    Pdo entry 0x"
       
   117                     << hex << setfill('0')
       
   118                     << setw(4) << entry.index
       
   119                     << ":" << setw(2) << (unsigned int) entry.subindex
       
   120                     << ", " << dec << (unsigned int) entry.bit_length
       
   121                     << " bit, \"" << entry.name << "\"" << endl;
       
   122             }
       
   123         }
       
   124     }
       
   125 }
       
   126 
       
   127 /*****************************************************************************/