mirror of
https://gitlab.com/etherlab.org/ethercat.git
synced 2026-09-23 10:33:49 +08:00
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
'ethercat master' command.
This commit is contained in:
+64
-6
@@ -97,7 +97,7 @@ void Master::setDebug(const vector<string> &commandArgs)
|
||||
throw MasterException(err.str());
|
||||
}
|
||||
|
||||
if (ioctl(fd, EC_IOCTL_DEBUG_LEVEL, debugLevel) < 0) {
|
||||
if (ioctl(fd, EC_IOCTL_SET_DEBUG, debugLevel) < 0) {
|
||||
stringstream err;
|
||||
err << "Failed to set debug level: " << strerror(errno);
|
||||
throw MasterException(err.str());
|
||||
@@ -156,6 +156,58 @@ void Master::listSlaves()
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void Master::showMaster()
|
||||
{
|
||||
ec_ioctl_master_t data;
|
||||
stringstream err;
|
||||
unsigned int i;
|
||||
|
||||
getMaster(&data);
|
||||
|
||||
cout
|
||||
<< "Master" << index << endl
|
||||
<< " State: ";
|
||||
|
||||
switch (data.mode) {
|
||||
case 0: cout << "Waiting for device..."; break;
|
||||
case 1: cout << "Idle"; break;
|
||||
case 2: cout << "Operation"; break;
|
||||
default:
|
||||
err << "Invalid master state " << data.mode;
|
||||
throw MasterException(err.str());
|
||||
}
|
||||
|
||||
cout << endl
|
||||
<< " Slaves: " << data.slave_count << endl;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
cout << " Device" << i << ": ";
|
||||
if (data.devices[i].address[0] == 0x00
|
||||
&& data.devices[i].address[1] == 0x00
|
||||
&& data.devices[i].address[2] == 0x00
|
||||
&& data.devices[i].address[3] == 0x00
|
||||
&& data.devices[i].address[4] == 0x00
|
||||
&& data.devices[i].address[5] == 0x00) {
|
||||
cout << "None.";
|
||||
} else {
|
||||
cout << hex << setfill('0')
|
||||
<< setw(2) << (unsigned int) data.devices[i].address[0] << ":"
|
||||
<< setw(2) << (unsigned int) data.devices[i].address[1] << ":"
|
||||
<< setw(2) << (unsigned int) data.devices[i].address[2] << ":"
|
||||
<< setw(2) << (unsigned int) data.devices[i].address[3] << ":"
|
||||
<< setw(2) << (unsigned int) data.devices[i].address[4] << ":"
|
||||
<< setw(2) << (unsigned int) data.devices[i].address[5] << " ("
|
||||
<< (data.devices[i].attached ? "attached" : "waiting...")
|
||||
<< ")" << endl << dec
|
||||
<< " Tx count: " << data.devices[i].tx_count << endl
|
||||
<< " Rx count: " << data.devices[i].rx_count;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void Master::listPdos(int slavePosition)
|
||||
{
|
||||
if (slavePosition == -1) {
|
||||
@@ -444,15 +496,21 @@ unsigned int Master::domainCount()
|
||||
|
||||
unsigned int Master::slaveCount()
|
||||
{
|
||||
int ret;
|
||||
ec_ioctl_master_t data;
|
||||
|
||||
if ((ret = ioctl(fd, EC_IOCTL_SLAVE_COUNT, 0)) < 0) {
|
||||
getMaster(&data);
|
||||
return data.slave_count;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
void Master::getMaster(ec_ioctl_master_t *data)
|
||||
{
|
||||
if (ioctl(fd, EC_IOCTL_MASTER, data) < 0) {
|
||||
stringstream err;
|
||||
err << "Failed to get number of slaves: " << strerror(errno);
|
||||
err << "Failed to get master information: " << strerror(errno);
|
||||
throw MasterException(err.str());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
@@ -46,6 +46,7 @@ class Master
|
||||
void setDebug(const vector<string> &);
|
||||
void showDomains(int);
|
||||
void listSlaves();
|
||||
void showMaster();
|
||||
void listPdos(int);
|
||||
void generateXml(int);
|
||||
|
||||
@@ -56,6 +57,7 @@ class Master
|
||||
void generateSlaveXml(uint16_t);
|
||||
unsigned int domainCount();
|
||||
unsigned int slaveCount();
|
||||
void getMaster(ec_ioctl_master_t *);
|
||||
void slaveSyncs(uint16_t);
|
||||
void getDomain(ec_ioctl_domain_t *, unsigned int);
|
||||
void getFmmu(ec_ioctl_domain_fmmu_t *, unsigned int, unsigned int);
|
||||
|
||||
@@ -37,6 +37,7 @@ void printUsage()
|
||||
<< " debug Set the master debug level." << endl
|
||||
<< " domain Show domain information." << endl
|
||||
<< " list (ls, slaves) List all slaves (former 'lsec')." << endl
|
||||
<< " master Show master information." << endl
|
||||
<< " pdos List Pdo mapping of given slaves." << endl
|
||||
<< " xml Generate slave information xml." << endl
|
||||
<< "Global options:" << endl
|
||||
@@ -157,6 +158,8 @@ int main(int argc, char **argv)
|
||||
master.showDomains(domainIndex);
|
||||
} else if (command == "list" || command == "ls" || command == "slaves") {
|
||||
master.listSlaves();
|
||||
} else if (command == "master") {
|
||||
master.showMaster();
|
||||
} else if (command == "pdos") {
|
||||
master.listPdos(slavePosition);
|
||||
} else if (command == "xml") {
|
||||
|
||||
Reference in New Issue
Block a user