diff --git a/TODO b/TODO index 93788af5b1ef66083c55be23ad5714005f76642c..519a182e2f55292ef7a1234c4e40b14abde667c9 100644 --- a/TODO +++ b/TODO @@ -16,7 +16,6 @@ Version 1.4.0: * ethercat tool: - Replace --slave by --position. - Add --alias option. - - Show attached slave position. - Show Pdos in 'ethercat slave -v'. - Accept files from stdin. - Display attached device's MAC address instead of ff's. diff --git a/master/cdev.c b/master/cdev.c index 5c97a2e535448da241de2f80384890f9fc6fd0fc..b2f2bc399f9b55358c8b788f4c12baaf20034bd2 100644 --- a/master/cdev.c +++ b/master/cdev.c @@ -994,9 +994,7 @@ int ec_cdev_ioctl_config( ec_pdo_list_count(&sc->sync_configs[i].pdos); } data.sdo_count = ec_slave_config_sdo_count(sc); - data.attached = sc->slave != NULL; - data.operational = sc->slave && - sc->slave->current_state == EC_SLAVE_STATE_OP; + data.slave_position = sc->slave ? sc->slave->ring_position : -1; up(&master->master_sem); diff --git a/master/ioctl.h b/master/ioctl.h index f5be8be10294e8775ef057f65b40bf6f0568478e..067181cbac7b0ac2a77d126253e8713465182b2b 100644 --- a/master/ioctl.h +++ b/master/ioctl.h @@ -301,8 +301,7 @@ typedef struct { uint32_t pdo_count; } syncs[EC_MAX_SYNC_MANAGERS]; uint32_t sdo_count; - uint8_t attached : 1, - operational : 1; + int32_t slave_position; } ec_ioctl_config_t; /*****************************************************************************/ diff --git a/tool/CommandConfig.cpp b/tool/CommandConfig.cpp index 0e9025ee6aa7c2ad15f55668d529cb53bb78459c..bbadde821b6daf2d05ccb8616c81a1e6d5817047 100644 --- a/tool/CommandConfig.cpp +++ b/tool/CommandConfig.cpp @@ -33,11 +33,16 @@ string CommandConfig::helpString() const << "Without the --verbose option, slave configurations are" << endl << "output one-per-line. Example:" << endl << endl - << "1001:0 0x0000003b/0x02010000 - -" << endl + << "1001:0 0x0000003b/0x02010000 3 OP" << endl << "| | | |" << endl - << "| | | \\- Slave is operational." - << endl - << "| | \\- Slave has been found." << endl + << "| | | \\- Application-layer" << endl + << "| | | state of the attached" << endl + << "| | | slave, or '-', if no" << endl + << "| | | slave is attached." << endl + << "| | \\- Absolute decimal ring" << endl + << "| | position of the attached" << endl + << "| | slave, or '-' if none" << endl + << "| | attached." << endl << "| \\- Vendor ID and product code (both" << endl << "| hexadecimal)." << endl << "\\- Alias and relative position (both decimal)." << endl @@ -86,7 +91,7 @@ void CommandConfig::execute(MasterDevice &m, const StringVector &args) if (getVerbosity() == Verbose) { showDetailedConfigs(m, configList); } else { - listConfigs(configList); + listConfigs(m, configList); } } @@ -101,6 +106,7 @@ void CommandConfig::showDetailedConfigs( { ConfigList::const_iterator configIter; unsigned int j, k, l; + ec_ioctl_slave_t slave; ec_ioctl_config_pdo_t pdo; ec_ioctl_config_pdo_entry_t entry; ec_ioctl_config_sdo_t sdo; @@ -117,8 +123,15 @@ void CommandConfig::showDetailedConfigs( << setw(8) << configIter->vendor_id << endl << "Product code: 0x" << setw(8) << configIter->product_code << endl - << "Attached: " << (configIter->attached ? "yes" : "no") << endl - << "Operational: " << (configIter->operational ? "yes" : "no") << endl; + << "Attached slave: "; + + if (configIter->slave_position != -1) { + m.getSlave(&slave, configIter->slave_position); + cout << configIter->slave_position + << " (" << alStateString(slave.state) << ")" << endl; + } else { + cout << "none" << endl; + } for (j = 0; j < EC_MAX_SYNC_MANAGERS; j++) { if (configIter->syncs[j].pdo_count) { @@ -188,7 +201,10 @@ void CommandConfig::showDetailedConfigs( /** Lists the bus configuration. */ -void CommandConfig::listConfigs(const ConfigList &configList) +void CommandConfig::listConfigs( + MasterDevice &m, + const ConfigList &configList + ) { ConfigList::const_iterator configIter; stringstream str; @@ -197,7 +213,8 @@ void CommandConfig::listConfigs(const ConfigList &configList) InfoList list; InfoList::const_iterator iter; unsigned int maxAliasWidth = 0, maxPosWidth = 0, - maxAttWidth = 0, maxOpWidth = 0; + maxSlavePosWidth = 0, maxStateWidth = 0; + ec_ioctl_slave_t slave; for (configIter = configList.begin(); configIter != configList.end(); @@ -220,15 +237,29 @@ void CommandConfig::listConfigs(const ConfigList &configList) str.clear(); str.str(""); - str << (configIter->attached ? "attached" : "-"); - info.att = str.str(); - str.clear(); - str.str(""); + if (configIter->slave_position != -1) { + m.getSlave(&slave, configIter->slave_position); - str << (configIter->operational ? "operational" : "-"); - info.op = str.str(); - str.clear(); - str.str(""); + str << configIter->slave_position; + info.slavePos = str.str(); + str.clear(); + str.str(""); + + str << alStateString(slave.state); + info.state = str.str(); + str.clear(); + str.str(""); + } else { + str << "-"; + info.slavePos = str.str(); + str.clear(); + str.str(""); + + str << "-"; + info.state = str.str(); + str.clear(); + str.str(""); + } list.push_back(info); @@ -236,10 +267,10 @@ void CommandConfig::listConfigs(const ConfigList &configList) maxAliasWidth = info.alias.length(); if (info.pos.length() > maxPosWidth) maxPosWidth = info.pos.length(); - if (info.att.length() > maxAttWidth) - maxAttWidth = info.att.length(); - if (info.op.length() > maxOpWidth) - maxOpWidth = info.op.length(); + if (info.slavePos.length() > maxSlavePosWidth) + maxSlavePosWidth = info.slavePos.length(); + if (info.state.length() > maxStateWidth) + maxStateWidth = info.state.length(); } for (iter = list.begin(); iter != list.end(); iter++) { @@ -250,8 +281,8 @@ void CommandConfig::listConfigs(const ConfigList &configList) << " " << iter->ident << " " - << setw(maxAttWidth) << iter->att << " " - << setw(maxOpWidth) << iter->op << " " + << setw(maxSlavePosWidth) << iter->slavePos << " " + << setw(maxStateWidth) << iter->state << " " << endl; } } diff --git a/tool/CommandConfig.h b/tool/CommandConfig.h index 25a8ab3893c6ab0ef6f3295988d7daaff20f9ab1..beb56a1b03d232d71f788fc1de0ddbb7d960ff6f 100644 --- a/tool/CommandConfig.h +++ b/tool/CommandConfig.h @@ -28,14 +28,14 @@ class CommandConfig: string alias; string pos; string ident; - string att; - string op; + string slavePos; + string state; }; typedef list<ec_ioctl_config_t> ConfigList; void showDetailedConfigs(MasterDevice &, const ConfigList &); - void listConfigs(const ConfigList &); + void listConfigs(MasterDevice &m, const ConfigList &); }; /****************************************************************************/