Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
authorFlorian Pose <fp@igh-essen.com>
Thu, 05 Jun 2008 15:39:15 +0000 (2008-06-05)
changeset 957 ed5ac2e83495
parent 956 d9b9bc794d10
child 958 02a789e9f1c5
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
'ethercat master' command.
TODO
master/cdev.c
master/ioctl.h
tools/Master.cpp
tools/Master.h
tools/main.cpp
--- a/TODO	Thu Jun 05 14:33:36 2008 +0000
+++ b/TODO	Thu Jun 05 15:39:15 2008 +0000
@@ -9,6 +9,15 @@
 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().
--- a/master/cdev.c	Thu Jun 05 14:33:36 2008 +0000
+++ b/master/cdev.c	Thu Jun 05 15:39:15 2008 +0000
@@ -143,7 +143,30 @@
     // 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 @@
                 break;
             }
 
-        case EC_IOCTL_DEBUG_LEVEL:
+        case EC_IOCTL_SET_DEBUG:
             if (ec_master_debug_level(master, (unsigned int) arg)) {
                 retval = -EINVAL;
             }
--- a/master/ioctl.h	Thu Jun 05 14:33:36 2008 +0000
+++ b/master/ioctl.h	Thu Jun 05 15:39:15 2008 +0000
@@ -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 @@
 	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 {
--- a/tools/Master.cpp	Thu Jun 05 14:33:36 2008 +0000
+++ b/tools/Master.cpp	Thu Jun 05 15:39:15 2008 +0000
@@ -97,7 +97,7 @@
         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::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::slaveCount()
 {
-    int ret;
-
-    if ((ret = ioctl(fd, EC_IOCTL_SLAVE_COUNT, 0)) < 0) {
-        stringstream err;
-        err << "Failed to get number of slaves: " << strerror(errno);
-        throw MasterException(err.str());
-    }
-
-    return ret;
+    ec_ioctl_master_t data;
+
+    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 master information: " << strerror(errno);
+        throw MasterException(err.str());
+    }
 }
 
 /****************************************************************************/
--- a/tools/Master.h	Thu Jun 05 14:33:36 2008 +0000
+++ b/tools/Master.h	Thu Jun 05 15:39:15 2008 +0000
@@ -46,6 +46,7 @@
         void setDebug(const vector<string> &);
         void showDomains(int);
         void listSlaves();
+        void showMaster();
         void listPdos(int);
         void generateXml(int);
 
@@ -56,6 +57,7 @@
         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);
--- a/tools/main.cpp	Thu Jun 05 14:33:36 2008 +0000
+++ b/tools/main.cpp	Thu Jun 05 15:39:15 2008 +0000
@@ -37,6 +37,7 @@
         << "  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 @@
             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") {