Skip to content
Snippets Groups Projects
Commit d08690dd authored by Florian Pose's avatar Florian Pose
Browse files

Implemented alias and position for configs.

parent ae546367
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,6 @@ Version 1.4.0: ...@@ -14,7 +14,6 @@ Version 1.4.0:
* Get original driver for r8169. * Get original driver for r8169.
* Race in jiffies frame timeout? * Race in jiffies frame timeout?
* ethercat tool: * ethercat tool:
- Implement Alias/Position selection for configs.
- Update help for --alias and --position. - Update help for --alias and --position.
- Show Pdos in 'ethercat slave -v'. - Show Pdos in 'ethercat slave -v'.
- Accept files from stdin. - Accept files from stdin.
......
...@@ -159,6 +159,69 @@ Command::SlaveList Command::selectedSlaves(MasterDevice &m) ...@@ -159,6 +159,69 @@ Command::SlaveList Command::selectedSlaves(MasterDevice &m)
return list; return list;
} }
/*****************************************************************************/
bool operator<(
const ec_ioctl_config_t &a,
const ec_ioctl_config_t &b
)
{
return a.alias < b.alias
|| (a.alias == b.alias && a.position < b.position);
}
/*****************************************************************************/
Command::ConfigList Command::selectedConfigs(MasterDevice &m)
{
unsigned int i;
int effAlias;
ec_ioctl_master_t master;
ec_ioctl_config_t config;
ConfigList list;
stringstream err;
m.getMaster(&master);
// Assume alias 0 if only position is given.
if (alias == -1 && position != -1) {
effAlias = 0;
} else {
effAlias = alias;
}
if (effAlias == -1) { // no alias given
if (position == -1) { // no alias and position given
// all items
for (i = 0; i < master.config_count; i++) {
m.getConfig(&config, i);
list.push_back(config);
}
}
} else { // alias given
if (position == -1) { // alias, but no position given
// take all items with a given alias
for (i = 0; i < master.config_count; i++) {
m.getConfig(&config, i);
if (config.alias == effAlias) {
list.push_back(config);
}
}
} else { // alias and position given
for (i = 0; i < master.config_count; i++) {
m.getConfig(&config, i);
if (config.alias == effAlias && config.position == position) {
list.push_back(config);
break; // there can be at most one matching
}
}
}
}
list.sort();
return list;
}
/****************************************************************************/ /****************************************************************************/
string Command::alStateString(uint8_t state) string Command::alStateString(uint8_t state)
......
...@@ -91,6 +91,8 @@ class Command ...@@ -91,6 +91,8 @@ class Command
typedef list<ec_ioctl_slave_t> SlaveList; typedef list<ec_ioctl_slave_t> SlaveList;
SlaveList selectedSlaves(MasterDevice &); SlaveList selectedSlaves(MasterDevice &);
typedef list<ec_ioctl_config_t> ConfigList;
ConfigList selectedConfigs(MasterDevice &);
static string alStateString(uint8_t); static string alStateString(uint8_t);
......
...@@ -58,40 +58,19 @@ string CommandConfig::helpString() const ...@@ -58,40 +58,19 @@ string CommandConfig::helpString() const
/*****************************************************************************/ /*****************************************************************************/
bool operator<(
const ec_ioctl_config_t &a,
const ec_ioctl_config_t &b
)
{
return a.alias < b.alias
|| (a.alias == b.alias && a.position < b.position);
}
/*****************************************************************************/
/** Lists the bus configuration. /** Lists the bus configuration.
*/ */
void CommandConfig::execute(MasterDevice &m, const StringVector &args) void CommandConfig::execute(MasterDevice &m, const StringVector &args)
{ {
ec_ioctl_master_t master; ConfigList configs;
unsigned int i;
ec_ioctl_config_t config;
ConfigList configList;
m.open(MasterDevice::Read); m.open(MasterDevice::Read);
m.getMaster(&master); configs = selectedConfigs(m);
for (i = 0; i < master.config_count; i++) {
m.getConfig(&config, i);
configList.push_back(config);
}
configList.sort();
if (getVerbosity() == Verbose) { if (getVerbosity() == Verbose) {
showDetailedConfigs(m, configList); showDetailedConfigs(m, configs);
} else { } else {
listConfigs(m, configList); listConfigs(m, configs);
} }
} }
......
...@@ -32,8 +32,6 @@ class CommandConfig: ...@@ -32,8 +32,6 @@ class CommandConfig:
string state; string state;
}; };
typedef list<ec_ioctl_config_t> ConfigList;
void showDetailedConfigs(MasterDevice &, const ConfigList &); void showDetailedConfigs(MasterDevice &, const ConfigList &);
void listConfigs(MasterDevice &m, const ConfigList &); void listConfigs(MasterDevice &m, const ConfigList &);
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment