tool/CommandDomains.cpp
changeset 1142 59be91dfcbe1
child 1144 7dbfdd61812c
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 "CommandDomains.h"
       
    12 
       
    13 /*****************************************************************************/
       
    14 
       
    15 CommandDomains::CommandDomains():
       
    16     Command("domains", "Show configured domains.")
       
    17 {
       
    18 }
       
    19 
       
    20 /*****************************************************************************/
       
    21 
       
    22 string CommandDomains::helpString() const
       
    23 {
       
    24     stringstream str;
       
    25 
       
    26 	str << getName() << " [OPTIONS]"
       
    27     	<< endl
       
    28     	<< getBriefDescription() << endl
       
    29         << endl
       
    30     	<< "Without the --verbose option, the domains are displayed" << endl
       
    31         << "one-per-line. Example:" << endl
       
    32     	<< endl
       
    33     	<< "Domain0: LogBaseAddr 0x00000000, Size   6, WorkingCounter 0/1"
       
    34 		<< endl << endl
       
    35     	<< "The domain's base address for the logical datagram" << endl
       
    36     	<< "(LRD/LWR/LRW) is displayed followed by the domain's" << endl
       
    37     	<< "process data size in byte. The last values are the current" << endl
       
    38     	<< "datagram working counter sum and the expected working" << endl
       
    39     	<< "counter sum. If the values are equal, all Pdos are exchanged."
       
    40 		<< endl << endl
       
    41     	<< "If the --verbose option is given, the participating slave" << endl
       
    42     	<< "configurations/FMMUs and the current process data are" << endl
       
    43     	<< "additionally displayed:" << endl
       
    44     	<< endl
       
    45     	<< "Domain1: LogBaseAddr 0x00000006, Size   6, WorkingCounter 0/1"
       
    46 		<< endl
       
    47     	<< "  SlaveConfig 1001:0, SM3 ( Input), LogAddr 0x00000006, Size 6"
       
    48 		<< endl
       
    49     	<< "    00 00 00 00 00 00" << endl
       
    50     	<< endl
       
    51     	<< "The process data are displayed as hexadecimal bytes." << endl
       
    52     	<< endl
       
    53     	<< "Command-specific options:" << endl
       
    54     	<< "  --domain  -d <index>  Positive numerical domain index," << endl
       
    55     	<< "                        or 'all' for all domains (default)."
       
    56 		<< endl
       
    57     	<< "  --verbose -v          Show FMMUs and process data" << endl
       
    58 		<< "                        additionally." << endl
       
    59     	<< endl
       
    60 		<< numericInfo();
       
    61 
       
    62 	return str.str();
       
    63 }
       
    64 
       
    65 /****************************************************************************/
       
    66 
       
    67 void CommandDomains::execute(MasterDevice &m, const StringVector &args)
       
    68 {
       
    69     m.open(MasterDevice::Read);
       
    70 
       
    71     if (domainIndex == -1) {
       
    72         unsigned int i;
       
    73         ec_ioctl_master_t master;
       
    74 
       
    75         m.getMaster(&master);
       
    76 
       
    77         for (i = 0; i < master.domain_count; i++) {
       
    78             showDomain(m, i);
       
    79         }
       
    80     } else {
       
    81         showDomain(m, domainIndex);
       
    82     }
       
    83 }
       
    84 
       
    85 /****************************************************************************/
       
    86 
       
    87 void CommandDomains::showDomain(MasterDevice &m, unsigned int domainIndex)
       
    88 {
       
    89     ec_ioctl_domain_t domain;
       
    90     unsigned char *processData;
       
    91     ec_ioctl_domain_data_t data;
       
    92     unsigned int i, j;
       
    93     ec_ioctl_domain_fmmu_t fmmu;
       
    94     unsigned int dataOffset;
       
    95     
       
    96     m.getDomain(&domain, domainIndex);
       
    97 
       
    98 	cout << "Domain" << dec << domainIndex << ":"
       
    99 		<< " LogBaseAddr 0x"
       
   100 		<< hex << setfill('0')
       
   101         << setw(8) << domain.logical_base_address
       
   102 		<< ", Size " << dec << setfill(' ')
       
   103         << setw(3) << domain.data_size
       
   104 		<< ", WorkingCounter "
       
   105 		<< domain.working_counter << "/"
       
   106         << domain.expected_working_counter << endl;
       
   107 
       
   108     if (!domain.data_size || getVerbosity() != Verbose)
       
   109         return;
       
   110 
       
   111     processData = new unsigned char[domain.data_size];
       
   112 
       
   113     try {
       
   114         m.getData(&data, domainIndex, domain.data_size, processData);
       
   115     } catch (MasterDeviceException &e) {
       
   116         delete [] processData;
       
   117         throw e;
       
   118     }
       
   119 
       
   120     for (i = 0; i < domain.fmmu_count; i++) {
       
   121         m.getFmmu(&fmmu, domainIndex, i);
       
   122 
       
   123         cout << "  SlaveConfig "
       
   124             << dec << fmmu.slave_config_alias
       
   125             << ":" << fmmu.slave_config_position
       
   126             << ", SM" << (unsigned int) fmmu.sync_index << " ("
       
   127             << setfill(' ') << setw(6)
       
   128             << (fmmu.dir == EC_DIR_INPUT ? "Input" : "Output")
       
   129             << "), LogAddr 0x"
       
   130             << hex << setfill('0')
       
   131             << setw(8) << fmmu.logical_address
       
   132             << ", Size " << dec << fmmu.data_size << endl;
       
   133 
       
   134         dataOffset = fmmu.logical_address - domain.logical_base_address;
       
   135         if (dataOffset + fmmu.data_size > domain.data_size) {
       
   136             stringstream err;
       
   137             delete [] processData;
       
   138             err << "Fmmu information corrupted!";
       
   139             throwCommandException(err);
       
   140         }
       
   141 
       
   142         cout << "    " << hex << setfill('0');
       
   143         for (j = 0; j < fmmu.data_size; j++) {
       
   144             if (j && !(j % BreakAfterBytes))
       
   145                 cout << endl << "    ";
       
   146             cout << setw(2)
       
   147                 << (unsigned int) *(processData + dataOffset + j) << " ";
       
   148         }
       
   149         cout << endl;
       
   150     }
       
   151 
       
   152     delete [] processData;
       
   153 }
       
   154 
       
   155 /*****************************************************************************/