Removed global variables.
This commit is contained in:
parent
98beafca60
commit
72ab96c4fb
3
TODO
3
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:
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.";
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 &);
|
||||
};
|
||||
|
||||
/****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 &);
|
||||
};
|
||||
|
||||
/****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ void CommandSiiWrite::execute(MasterDevice &m, const StringVector &args)
|
|||
file.close();
|
||||
}
|
||||
|
||||
if (!force) {
|
||||
if (!getForce()) {
|
||||
try {
|
||||
checkSiiData(&data);
|
||||
} catch (CommandException &e) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue