EtherLab skin for 'ethercat pdos' command.
This commit is contained in:
parent
77d12c25ca
commit
4a52384661
|
|
@ -216,6 +216,13 @@ void Command::setOutputFile(const string &f)
|
||||||
outputFile = f;
|
outputFile = f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
void Command::setSkin(const string &s)
|
||||||
|
{
|
||||||
|
skin = s;
|
||||||
|
};
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|
||||||
bool Command::matchesSubstr(const string &cmd) const
|
bool Command::matchesSubstr(const string &cmd) const
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,9 @@ class Command
|
||||||
void setOutputFile(const string &);
|
void setOutputFile(const string &);
|
||||||
const string &getOutputFile() const;
|
const string &getOutputFile() const;
|
||||||
|
|
||||||
|
void setSkin(const string &);
|
||||||
|
const string &getSkin() const;
|
||||||
|
|
||||||
bool matchesSubstr(const string &) const;
|
bool matchesSubstr(const string &) const;
|
||||||
bool matchesAbbrev(const string &) const;
|
bool matchesAbbrev(const string &) const;
|
||||||
|
|
||||||
|
|
@ -151,6 +154,7 @@ class Command
|
||||||
string dataType;
|
string dataType;
|
||||||
bool force;
|
bool force;
|
||||||
string outputFile;
|
string outputFile;
|
||||||
|
string skin;
|
||||||
|
|
||||||
Command();
|
Command();
|
||||||
};
|
};
|
||||||
|
|
@ -199,4 +203,11 @@ inline const string &Command::getOutputFile() const
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|
||||||
|
inline const string &Command::getSkin() const
|
||||||
|
{
|
||||||
|
return skin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <cstring>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#include "CommandPdos.h"
|
#include "CommandPdos.h"
|
||||||
|
|
@ -51,7 +52,8 @@ string CommandPdos::helpString(const string &binaryBaseName) const
|
||||||
<< endl
|
<< endl
|
||||||
<< getBriefDescription() << endl
|
<< getBriefDescription() << endl
|
||||||
<< endl
|
<< endl
|
||||||
<< "The information is displayed in three layers, which are" << endl
|
<< "For the default skin (see --skin option) the information" << endl
|
||||||
|
<< "is displayed in three layers, which are" << endl
|
||||||
<< "indented accordingly:" << endl
|
<< "indented accordingly:" << endl
|
||||||
<< endl
|
<< endl
|
||||||
<< "1) Sync managers - Contains the sync manager information" << endl
|
<< "1) Sync managers - Contains the sync manager information" << endl
|
||||||
|
|
@ -77,10 +79,16 @@ string CommandPdos::helpString(const string &binaryBaseName) const
|
||||||
<< "information can either originate from the SII or from the" << endl
|
<< "information can either originate from the SII or from the" << endl
|
||||||
<< "CoE communication area." << endl
|
<< "CoE communication area." << endl
|
||||||
<< endl
|
<< endl
|
||||||
|
<< "The \"etherlab\" skin outputs a template configuration" << endl
|
||||||
|
<< "for EtherLab's generic EtherCAT slave block." << endl
|
||||||
|
<< endl
|
||||||
<< "Command-specific options:" << endl
|
<< "Command-specific options:" << endl
|
||||||
<< " --alias -a <alias>" << endl
|
<< " --alias -a <alias>" << endl
|
||||||
<< " --position -p <pos> Slave selection. See the help of" << endl
|
<< " --position -p <pos> Slave selection. See the help of" << endl
|
||||||
<< " the 'slaves' command." << endl
|
<< " the 'slaves' command." << endl
|
||||||
|
<< " --skin -s <skin> Choose output skin. Possible values are"
|
||||||
|
<< endl
|
||||||
|
<< " \"default\" and \"etherlab\"." << endl
|
||||||
<< endl
|
<< endl
|
||||||
<< numericInfo();
|
<< numericInfo();
|
||||||
|
|
||||||
|
|
@ -102,20 +110,41 @@ void CommandPdos::execute(const StringVector &args)
|
||||||
throwInvalidUsageException(err);
|
throwInvalidUsageException(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
masterIndices = getMasterIndices();
|
if (getSkin().empty() || getSkin() == "default") {
|
||||||
multiMaster = masterIndices.size() > 1;
|
masterIndices = getMasterIndices();
|
||||||
MasterIndexList::const_iterator mi;
|
multiMaster = masterIndices.size() > 1;
|
||||||
for (mi = masterIndices.begin();
|
MasterIndexList::const_iterator mi;
|
||||||
mi != masterIndices.end(); mi++) {
|
for (mi = masterIndices.begin();
|
||||||
MasterDevice m(*mi);
|
mi != masterIndices.end(); mi++) {
|
||||||
m.open(MasterDevice::Read);
|
MasterDevice m(*mi);
|
||||||
slaves = selectedSlaves(m);
|
m.open(MasterDevice::Read);
|
||||||
showHeader = multiMaster || slaves.size() > 1;
|
slaves = selectedSlaves(m);
|
||||||
|
showHeader = multiMaster || slaves.size() > 1;
|
||||||
|
|
||||||
for (si = slaves.begin(); si != slaves.end(); si++) {
|
for (si = slaves.begin(); si != slaves.end(); si++) {
|
||||||
listSlavePdos(m, *si, showHeader);
|
listSlavePdos(m, *si, showHeader);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (getSkin() == "etherlab") {
|
||||||
|
masterIndices = getMasterIndices();
|
||||||
|
MasterIndexList::const_iterator mi;
|
||||||
|
for (mi = masterIndices.begin();
|
||||||
|
mi != masterIndices.end(); mi++) {
|
||||||
|
MasterDevice m(*mi);
|
||||||
|
m.open(MasterDevice::Read);
|
||||||
|
slaves = selectedSlaves(m);
|
||||||
|
|
||||||
|
for (si = slaves.begin(); si != slaves.end(); si++) {
|
||||||
|
etherlabConfig(m, *si);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
stringstream err;
|
||||||
|
err << "Invalid skin '" << getSkin() << "'!";
|
||||||
|
throwInvalidUsageException(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|
@ -177,4 +206,111 @@ void CommandPdos::listSlavePdos(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************/
|
||||||
|
|
||||||
|
void CommandPdos::etherlabConfig(
|
||||||
|
MasterDevice &m,
|
||||||
|
const ec_ioctl_slave_t &slave
|
||||||
|
)
|
||||||
|
{
|
||||||
|
ec_ioctl_slave_sync_t sync;
|
||||||
|
ec_ioctl_slave_sync_pdo_t pdo;
|
||||||
|
ec_ioctl_slave_sync_pdo_entry_t entry;
|
||||||
|
unsigned int i, j, k;
|
||||||
|
|
||||||
|
cout << "%" << endl
|
||||||
|
<< "% Master " << m.getIndex() << ", Slave " << slave.position;
|
||||||
|
if (strlen(slave.order)) {
|
||||||
|
cout << ", \"" << slave.order << "\"";
|
||||||
|
}
|
||||||
|
cout << endl
|
||||||
|
<< "%" << endl
|
||||||
|
<< "function rv = slave" << slave.position << "()" << endl << endl;
|
||||||
|
|
||||||
|
cout << "% Slave configuration" << endl << endl;
|
||||||
|
|
||||||
|
cout << "rv.SlaveConfig.vendor = " << slave.vendor_id << ";" << endl
|
||||||
|
<< "rv.SlaveConfig.product = hex2dec('"
|
||||||
|
<< hex << setfill('0') << setw(8) << slave.product_code << "');"
|
||||||
|
<< endl
|
||||||
|
<< "rv.SlaveConfig.description = '" << slave.order << "';" << endl
|
||||||
|
<< "rv.SlaveConfig.sm = { ..." << endl;
|
||||||
|
|
||||||
|
/* slave configuration */
|
||||||
|
for (i = 0; i < slave.sync_count; i++) {
|
||||||
|
m.getSync(&sync, slave.position, i);
|
||||||
|
|
||||||
|
cout << " {" << dec << i << ", "
|
||||||
|
<< (sync.control_register & 0x04 ? 0 : 1) << ", {" << endl;
|
||||||
|
|
||||||
|
for (j = 0; j < sync.pdo_count; j++) {
|
||||||
|
m.getPdo(&pdo, slave.position, i, j);
|
||||||
|
|
||||||
|
cout << " {hex2dec('" <<
|
||||||
|
hex << setfill('0') << setw(4) << pdo.index << "'), ["
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
for (k = 0; k < pdo.entry_count; k++) {
|
||||||
|
m.getPdoEntry(&entry, slave.position, i, j, k);
|
||||||
|
|
||||||
|
cout << " hex2dec('"
|
||||||
|
<< hex << setfill('0') << setw(4) << entry.index
|
||||||
|
<< "'), hex2dec('"
|
||||||
|
<< setw(2) << (unsigned int) entry.subindex
|
||||||
|
<< "'), " << dec << setfill(' ') << setw(3)
|
||||||
|
<< (unsigned int) entry.bit_length
|
||||||
|
<< "; ..." << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << " ]}, ..." << endl;
|
||||||
|
}
|
||||||
|
cout << " }}, ..." << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << " };" << endl << endl;
|
||||||
|
|
||||||
|
cout << "% Port configuration" << endl << endl;
|
||||||
|
|
||||||
|
unsigned int input = 1, output = 1;
|
||||||
|
for (i = 0; i < slave.sync_count; i++) {
|
||||||
|
m.getSync(&sync, slave.position, i);
|
||||||
|
|
||||||
|
for (j = 0; j < sync.pdo_count; j++) {
|
||||||
|
m.getPdo(&pdo, slave.position, i, j);
|
||||||
|
|
||||||
|
for (k = 0; k < pdo.entry_count; k++) {
|
||||||
|
m.getPdoEntry(&entry, slave.position, i, j, k);
|
||||||
|
|
||||||
|
if (!entry.index) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
string dir;
|
||||||
|
unsigned int port;
|
||||||
|
|
||||||
|
if (sync.control_register & 0x04) {
|
||||||
|
dir = "input";
|
||||||
|
port = input++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dir = "output";
|
||||||
|
port = output++;
|
||||||
|
}
|
||||||
|
|
||||||
|
stringstream var;
|
||||||
|
var << "rv.PortConfig." << dir << "(" << dec << port
|
||||||
|
<< ")";
|
||||||
|
|
||||||
|
cout << var.str() << ".pdo = ["
|
||||||
|
<< i << ", " << j << ", " << k << ", 0];" << endl;
|
||||||
|
cout << var.str() << ".pdo_data_type = "
|
||||||
|
<< 1000 + (unsigned int) entry.bit_length
|
||||||
|
<< ";" << endl << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "end" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ class CommandPdos:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void listSlavePdos(MasterDevice &, const ec_ioctl_slave_t &, bool);
|
void listSlavePdos(MasterDevice &, const ec_ioctl_slave_t &, bool);
|
||||||
|
void etherlabConfig(MasterDevice &, const ec_ioctl_slave_t &);
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@ Command::Verbosity verbosity = Command::Normal;
|
||||||
bool force = false;
|
bool force = false;
|
||||||
bool helpRequested = false;
|
bool helpRequested = false;
|
||||||
string outputFile;
|
string outputFile;
|
||||||
|
string skin;
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
@ -147,6 +148,7 @@ void getOptions(int argc, char **argv)
|
||||||
{"domain", required_argument, NULL, 'd'},
|
{"domain", required_argument, NULL, 'd'},
|
||||||
{"type", required_argument, NULL, 't'},
|
{"type", required_argument, NULL, 't'},
|
||||||
{"output-file", required_argument, NULL, 'o'},
|
{"output-file", required_argument, NULL, 'o'},
|
||||||
|
{"skin", required_argument, NULL, 's'},
|
||||||
{"force", no_argument, NULL, 'f'},
|
{"force", no_argument, NULL, 'f'},
|
||||||
{"quiet", no_argument, NULL, 'q'},
|
{"quiet", no_argument, NULL, 'q'},
|
||||||
{"verbose", no_argument, NULL, 'v'},
|
{"verbose", no_argument, NULL, 'v'},
|
||||||
|
|
@ -155,7 +157,7 @@ void getOptions(int argc, char **argv)
|
||||||
};
|
};
|
||||||
|
|
||||||
do {
|
do {
|
||||||
c = getopt_long(argc, argv, "m:a:p:d:t:o:fqvh", longOptions, NULL);
|
c = getopt_long(argc, argv, "m:a:p:d:t:o:s:fqvh", longOptions, NULL);
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'm':
|
case 'm':
|
||||||
|
|
@ -182,6 +184,10 @@ void getOptions(int argc, char **argv)
|
||||||
outputFile = optarg;
|
outputFile = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
skin = optarg;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
force = true;
|
force = true;
|
||||||
break;
|
break;
|
||||||
|
|
@ -308,6 +314,7 @@ int main(int argc, char **argv)
|
||||||
cmd->setDomains(domains);
|
cmd->setDomains(domains);
|
||||||
cmd->setDataType(dataTypeStr);
|
cmd->setDataType(dataTypeStr);
|
||||||
cmd->setOutputFile(outputFile);
|
cmd->setOutputFile(outputFile);
|
||||||
|
cmd->setSkin(skin);
|
||||||
cmd->setForce(force);
|
cmd->setForce(force);
|
||||||
cmd->execute(commandArgs);
|
cmd->execute(commandArgs);
|
||||||
} catch (InvalidUsageException &e) {
|
} catch (InvalidUsageException &e) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue