tools/Master.cpp
changeset 957 ed5ac2e83495
parent 956 d9b9bc794d10
child 960 36e460ffbb5e
--- 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());
+    }
 }
 
 /****************************************************************************/