diff --git a/TODO b/TODO index d4f7dfe2..58111d5f 100644 --- a/TODO +++ b/TODO @@ -9,6 +9,15 @@ $Id$ Version 1.4.0: * Replace all Sysfs files via the new ethercat tool. + - Sdo info + - Sdo entry info + - Sdo entry value read + - Sdo entry value write + - Slave alias write + - Slave SII write + - Slave state write + - Slave info + - Config info * Remove the end state of the master state machine. * Supply new ec_master_state_t. * Implement ecrt_slave_config_state(). diff --git a/master/cdev.c b/master/cdev.c index ea469dfc..3d2f00a2 100644 --- a/master/cdev.c +++ b/master/cdev.c @@ -143,7 +143,30 @@ long eccdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) // FIXME lock switch (cmd) { - case EC_IOCTL_SLAVE_COUNT: + case EC_IOCTL_MASTER: + { + ec_ioctl_master_t data; + + data.slave_count = master->slave_count; + data.mode = (uint8_t) master->mode; + + memcpy(data.devices[0].address, master->main_mac, ETH_ALEN); + data.devices[0].attached = master->main_device.dev ? 1 : 0; + data.devices[0].tx_count = master->main_device.tx_count; + data.devices[0].rx_count = master->main_device.rx_count; + memcpy(data.devices[1].address, master->backup_mac, ETH_ALEN); + data.devices[1].attached = master->backup_device.dev ? 1 : 0; + data.devices[1].tx_count = master->backup_device.tx_count; + data.devices[1].rx_count = master->backup_device.rx_count; + + if (copy_to_user((void __user *) arg, &data, sizeof(data))) { + retval = -EFAULT; + break; + } + + break; + } + retval = master->slave_count; break; @@ -449,7 +472,7 @@ long eccdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) break; } - case EC_IOCTL_DEBUG_LEVEL: + case EC_IOCTL_SET_DEBUG: if (ec_master_debug_level(master, (unsigned int) arg)) { retval = -EINVAL; } diff --git a/master/ioctl.h b/master/ioctl.h index ca2818a8..8e574721 100644 --- a/master/ioctl.h +++ b/master/ioctl.h @@ -44,7 +44,7 @@ /*****************************************************************************/ enum { - EC_IOCTL_SLAVE_COUNT, + EC_IOCTL_MASTER, EC_IOCTL_SLAVE, EC_IOCTL_SYNC, EC_IOCTL_PDO, @@ -53,11 +53,24 @@ enum { EC_IOCTL_DOMAIN, EC_IOCTL_DOMAIN_FMMU, EC_IOCTL_DATA, - EC_IOCTL_DEBUG_LEVEL, + EC_IOCTL_SET_DEBUG, }; /*****************************************************************************/ +typedef struct { + unsigned int slave_count; + uint8_t mode; + struct { + uint8_t address[6]; + uint8_t attached; + unsigned int tx_count; + unsigned int rx_count; + } devices[2]; +} ec_ioctl_master_t; + +/*****************************************************************************/ + #define EC_IOCTL_SLAVE_NAME_SIZE 114 typedef struct { diff --git a/tools/Master.cpp b/tools/Master.cpp index 6ee44a4c..9b1130cb 100644 --- a/tools/Master.cpp +++ b/tools/Master.cpp @@ -97,7 +97,7 @@ void Master::setDebug(const vector &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; } /****************************************************************************/ diff --git a/tools/Master.h b/tools/Master.h index eef78cad..0938819d 100644 --- a/tools/Master.h +++ b/tools/Master.h @@ -46,6 +46,7 @@ class Master void setDebug(const vector &); 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); diff --git a/tools/main.cpp b/tools/main.cpp index e41183b1..4c5eed54 100644 --- a/tools/main.cpp +++ b/tools/main.cpp @@ -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") {