diff --git a/TODO b/TODO index c3db2d152946dbd15a4f9054a56f036248270e06..a74d603bef9c64632ae729bbcb6ca372e2aa788a 100644 --- a/TODO +++ b/TODO @@ -13,8 +13,6 @@ Version 1.4.0: * Update documentation. * Get original driver for r8169. * Race in jiffies frame timeout? -* ethercat tool: - - Check for options, remove global variables. Future issues: @@ -36,6 +34,7 @@ Future issues: * ethercat tool: - Data type abbreviations. - Add a -n (numeric) switch. + - Check for unwanted options. Smaller issues: diff --git a/tool/Command.cpp b/tool/Command.cpp index 51f2d5d68ee2cfc096e4f386b131e84770729b52..7ce5a196bdefb947d12989247a4127c670043dff 100644 --- a/tool/Command.cpp +++ b/tool/Command.cpp @@ -42,6 +42,27 @@ void Command::setPosition(int p) position = p; }; +/*****************************************************************************/ + +void Command::setDomain(int d) +{ + domain = d; +}; + +/*****************************************************************************/ + +void Command::setDataType(const string &t) +{ + dataType = t; +}; + +/*****************************************************************************/ + +void Command::setForce(bool f) +{ + force = f; +}; + /****************************************************************************/ bool Command::matchesSubstr(const string &cmd) const @@ -226,6 +247,31 @@ Command::ConfigList Command::selectedConfigs(MasterDevice &m) /****************************************************************************/ +Command::DomainList Command::selectedDomains(MasterDevice &m) +{ + ec_ioctl_domain_t d; + DomainList list; + + if (domain == -1) { + ec_ioctl_master_t master; + unsigned int i; + + m.getMaster(&master); + + for (i = 0; i < master.domain_count; i++) { + m.getDomain(&d, i); + list.push_back(d); + } + } else { + m.getDomain(&d, domain); + list.push_back(d); + } + + return list; +} + +/****************************************************************************/ + string Command::alStateString(uint8_t state) { switch (state) { diff --git a/tool/Command.h b/tool/Command.h index a998a0157e348ae9419b22469e25a01b5f21f7f5..92d60d1d5e1e31f0ac39a5a2672908357b1e92e9 100644 --- a/tool/Command.h +++ b/tool/Command.h @@ -14,13 +14,6 @@ using namespace std; #include "MasterDevice.h" -/*****************************************************************************/ - -extern unsigned int masterIndex; -extern int domainIndex; -extern string dataTypeStr; -extern bool force; - /****************************************************************************/ class InvalidUsageException: @@ -71,6 +64,12 @@ class Command int getAlias() const; void setPosition(int); int getPosition() const; + void setDomain(int); + int getDomain() const; + void setDataType(const string &); + const string &getDataType() const; + void setForce(bool); + bool getForce() const; bool matchesSubstr(const string &) const; bool matchesAbbrev(const string &) const; @@ -93,6 +92,8 @@ class Command SlaveList selectedSlaves(MasterDevice &); typedef list<ec_ioctl_config_t> ConfigList; ConfigList selectedConfigs(MasterDevice &); + typedef list<ec_ioctl_domain_t> DomainList; + DomainList selectedDomains(MasterDevice &); static string alStateString(uint8_t); @@ -102,6 +103,9 @@ class Command Verbosity verbosity; int alias; int position; + int domain; + string dataType; + bool force; Command(); }; @@ -143,4 +147,25 @@ inline int Command::getPosition() const /****************************************************************************/ +inline int Command::getDomain() const +{ + return domain; +} + +/****************************************************************************/ + +inline const string &Command::getDataType() const +{ + return dataType; +} + +/****************************************************************************/ + +inline bool Command::getForce() const +{ + return force; +} + +/****************************************************************************/ + #endif diff --git a/tool/CommandAlias.cpp b/tool/CommandAlias.cpp index bcacc8284e9b73300423dfb0adbb39b9a0520845..2c0de921c3b74fdfc259d5d189d8ee4c4c7a9471 100644 --- a/tool/CommandAlias.cpp +++ b/tool/CommandAlias.cpp @@ -79,7 +79,7 @@ void CommandAlias::execute(MasterDevice &m, const StringVector &args) m.open(MasterDevice::ReadWrite); slaves = selectedSlaves(m); - if (slaves.size() > 1 && !force) { + if (slaves.size() > 1 && !getForce()) { err << "This will write the alias addresses of " << slaves.size() << " slaves to " << alias << "! Please specify --force to proceed."; diff --git a/tool/CommandData.cpp b/tool/CommandData.cpp index f7d80542c4abb13314c6dc82c233b98fbe053a61..9a04be648a1a6e662daaa1c4c8f2c95000939ef8 100644 --- a/tool/CommandData.cpp +++ b/tool/CommandData.cpp @@ -41,40 +41,35 @@ string CommandData::helpString() const void CommandData::execute(MasterDevice &m, const StringVector &args) { + DomainList domains; + DomainList::const_iterator di; + m.open(MasterDevice::Read); + domains = selectedDomains(m); - if (domainIndex == -1) { - unsigned int i; - ec_ioctl_master_t master; - - m.getMaster(&master); - - for (i = 0; i < master.domain_count; i++) { - outputDomainData(m, i); - } - } else { - outputDomainData(m, domainIndex); - } + for (di = domains.begin(); di != domains.end(); di++) { + outputDomainData(m, *di); + } } /****************************************************************************/ -void CommandData::outputDomainData(MasterDevice &m, unsigned int domainIndex) +void CommandData::outputDomainData( + MasterDevice &m, + const ec_ioctl_domain_t &domain + ) { - ec_ioctl_domain_t domain; ec_ioctl_domain_data_t data; unsigned char *processData; unsigned int i; - m.getDomain(&domain, domainIndex); - if (!domain.data_size) return; processData = new unsigned char[domain.data_size]; try { - m.getData(&data, domainIndex, domain.data_size, processData); + m.getData(&data, domain.index, domain.data_size, processData); } catch (MasterDeviceException &e) { delete [] processData; throw e; diff --git a/tool/CommandData.h b/tool/CommandData.h index 4e8c83aaa631de5934090d6238087ed9a6497c5e..8cd4f90d85777d8da6076b8976319866ae57f3e8 100644 --- a/tool/CommandData.h +++ b/tool/CommandData.h @@ -21,7 +21,7 @@ class CommandData: void execute(MasterDevice &, const StringVector &); protected: - void outputDomainData(MasterDevice &, unsigned int); + void outputDomainData(MasterDevice &, const ec_ioctl_domain_t &); }; /****************************************************************************/ diff --git a/tool/CommandDomains.cpp b/tool/CommandDomains.cpp index ac6b63111098c3937d1574c040965b645e149a54..f248574fcb2e59a9728e6823f77b98b3d46243e5 100644 --- a/tool/CommandDomains.cpp +++ b/tool/CommandDomains.cpp @@ -66,36 +66,31 @@ string CommandDomains::helpString() const void CommandDomains::execute(MasterDevice &m, const StringVector &args) { + DomainList domains; + DomainList::const_iterator di; + m.open(MasterDevice::Read); + domains = selectedDomains(m); - if (domainIndex == -1) { - unsigned int i; - ec_ioctl_master_t master; - - m.getMaster(&master); - - for (i = 0; i < master.domain_count; i++) { - showDomain(m, i); - } - } else { - showDomain(m, domainIndex); - } + for (di = domains.begin(); di != domains.end(); di++) { + showDomain(m, *di); + } } /****************************************************************************/ -void CommandDomains::showDomain(MasterDevice &m, unsigned int domainIndex) +void CommandDomains::showDomain( + MasterDevice &m, + const ec_ioctl_domain_t &domain + ) { - ec_ioctl_domain_t domain; unsigned char *processData; ec_ioctl_domain_data_t data; unsigned int i, j; ec_ioctl_domain_fmmu_t fmmu; unsigned int dataOffset; - m.getDomain(&domain, domainIndex); - - cout << "Domain" << dec << domainIndex << ":" + cout << "Domain" << dec << domain.index << ":" << " LogBaseAddr 0x" << hex << setfill('0') << setw(8) << domain.logical_base_address @@ -111,14 +106,14 @@ void CommandDomains::showDomain(MasterDevice &m, unsigned int domainIndex) processData = new unsigned char[domain.data_size]; try { - m.getData(&data, domainIndex, domain.data_size, processData); + m.getData(&data, domain.index, domain.data_size, processData); } catch (MasterDeviceException &e) { delete [] processData; throw e; } for (i = 0; i < domain.fmmu_count; i++) { - m.getFmmu(&fmmu, domainIndex, i); + m.getFmmu(&fmmu, domain.index, i); cout << " SlaveConfig " << dec << fmmu.slave_config_alias diff --git a/tool/CommandDomains.h b/tool/CommandDomains.h index bffe03b8dc6695dd6ac1e65f01049ea7abefb861..0b6f9606b558bfe06d2dcdf8b893511cfe4f360b 100644 --- a/tool/CommandDomains.h +++ b/tool/CommandDomains.h @@ -21,7 +21,7 @@ class CommandDomains: void execute(MasterDevice &, const StringVector &); protected: - void showDomain(MasterDevice &, unsigned int); + void showDomain(MasterDevice &, const ec_ioctl_domain_t &); }; /****************************************************************************/ diff --git a/tool/CommandDownload.cpp b/tool/CommandDownload.cpp index 1dab9649abe7aa863b742913a8ceb2783bb68387..80eee2169f2dbcc3bac348cb9c03e791cf4bebcf 100644 --- a/tool/CommandDownload.cpp +++ b/tool/CommandDownload.cpp @@ -100,9 +100,9 @@ void CommandDownload::execute(MasterDevice &m, const StringVector &args) } data.slave_position = slaves.front().position; - if (dataTypeStr != "") { // data type specified - if (!(dataType = findDataType(dataTypeStr))) { - err << "Invalid data type '" << dataTypeStr << "'!"; + if (!getDataType().empty()) { // data type specified + if (!(dataType = findDataType(getDataType()))) { + err << "Invalid data type '" << getDataType() << "'!"; throwInvalidUsageException(err); } } else { // no data type specified: fetch from dictionary diff --git a/tool/CommandMaster.cpp b/tool/CommandMaster.cpp index c8f8ba37ef6b52d071fb90646950cd42f19561ba..b693eef749a44b8b97cc202cd77cb876bbc58d05 100644 --- a/tool/CommandMaster.cpp +++ b/tool/CommandMaster.cpp @@ -47,7 +47,7 @@ void CommandMaster::execute(MasterDevice &m, const StringVector &args) m.getMaster(&data); cout - << "Master" << masterIndex << endl + << "Master" << m.getIndex() << endl << " Phase: "; switch (data.phase) { diff --git a/tool/CommandSiiWrite.cpp b/tool/CommandSiiWrite.cpp index 27a1199752f46c39445723b956630a8c7e38bf31..fc34d8d6771ee8391fa77a5002e8ffd0346de821 100644 --- a/tool/CommandSiiWrite.cpp +++ b/tool/CommandSiiWrite.cpp @@ -77,7 +77,7 @@ void CommandSiiWrite::execute(MasterDevice &m, const StringVector &args) file.close(); } - if (!force) { + if (!getForce()) { try { checkSiiData(&data); } catch (CommandException &e) { diff --git a/tool/CommandUpload.cpp b/tool/CommandUpload.cpp index a6e1bd3dd245cc1d6bb93341c65491de66ebd6a6..d2b03d690a87101cc560ffc6aa2db7d6db96b97b 100644 --- a/tool/CommandUpload.cpp +++ b/tool/CommandUpload.cpp @@ -99,9 +99,9 @@ void CommandUpload::execute(MasterDevice &m, const StringVector &args) } data.slave_position = slaves.front().position; - if (dataTypeStr != "") { // data type specified - if (!(dataType = findDataType(dataTypeStr))) { - err << "Invalid data type '" << dataTypeStr << "'!"; + if (!getDataType().empty()) { // data type specified + if (!(dataType = findDataType(getDataType()))) { + err << "Invalid data type '" << getDataType() << "'!"; throwInvalidUsageException(err); } } else { // no data type specified: fetch from dictionary diff --git a/tool/MasterDevice.h b/tool/MasterDevice.h index 7575daacda668d7f7d6e1e15ec2edb7e21a1210a..d5fac7a069c512bafdffa9e18ad2a63377b337c9 100644 --- a/tool/MasterDevice.h +++ b/tool/MasterDevice.h @@ -37,6 +37,7 @@ class MasterDevice ~MasterDevice(); void setIndex(unsigned int); + unsigned int getIndex() const; enum Permissions {Read, ReadWrite}; void open(Permissions); @@ -74,4 +75,11 @@ class MasterDevice /****************************************************************************/ +inline unsigned int MasterDevice::getIndex() const +{ + return index; +} + +/****************************************************************************/ + #endif diff --git a/tool/main.cpp b/tool/main.cpp index b43e17dec989acebfd5907954f3aee7232ded722..23095037f2cdb0484f2a9035a76773099d7fe758 100644 --- a/tool/main.cpp +++ b/tool/main.cpp @@ -285,6 +285,9 @@ int main(int argc, char **argv) cmd->setVerbosity(verbosity); cmd->setAlias(slaveAlias); cmd->setPosition(slavePosition); + cmd->setDomain(domainIndex); + cmd->setDataType(dataTypeStr); + cmd->setForce(force); cmd->execute(masterDev, commandArgs); } catch (InvalidUsageException &e) { cerr << e.what() << endl << endl;