Implemented 'data' command.
authorFlorian Pose <fp@igh-essen.com>
Wed, 04 Jun 2008 10:41:50 +0000
changeset 949 e424c0074c67
parent 948 1cfab7161491
child 950 8b00e63fff90
Implemented 'data' command.
master/cdev.c
master/ioctl.h
tools/Master.cpp
tools/Master.h
tools/main.cpp
--- a/master/cdev.c	Wed Jun 04 10:13:07 2008 +0000
+++ b/master/cdev.c	Wed Jun 04 10:41:50 2008 +0000
@@ -379,6 +379,37 @@
                 break;
             }
 
+        case EC_IOCTL_DATA:
+            {
+                ec_ioctl_data_t data;
+                const ec_domain_t *domain;
+
+                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+                    retval = -EFAULT;
+                    break;
+                }
+                
+                if (!(domain = ec_master_find_domain(master, data.domain_index))) {
+                    EC_ERR("Domain %u does not exist!\n", data.domain_index);
+                    retval = -EINVAL;
+                    break;
+                }
+
+                if (domain->data_size != data.data_size) {
+                    EC_ERR("Data size mismatch %u/%u!\n",
+                            data.data_size, domain->data_size);
+                    retval = -EFAULT;
+                    break;
+                }
+
+                if (copy_to_user((void __user *) data.target, domain->data,
+                            domain->data_size)) {
+                    retval = -EFAULT;
+                    break;
+                }
+                break;
+            }
+
         default:
             retval = -ENOIOCTLCMD;
     }
--- a/master/ioctl.h	Wed Jun 04 10:13:07 2008 +0000
+++ b/master/ioctl.h	Wed Jun 04 10:41:50 2008 +0000
@@ -50,7 +50,8 @@
     EC_IOCTL_PDO,
     EC_IOCTL_PDO_ENTRY,
 	EC_IOCTL_DOMAIN_COUNT,
-	EC_IOCTL_DOMAIN
+	EC_IOCTL_DOMAIN,
+	EC_IOCTL_DATA
 };
 
 /*****************************************************************************/
@@ -138,4 +139,13 @@
 
 /*****************************************************************************/
 
+typedef struct {
+    // inputs
+	unsigned int domain_index;
+    unsigned int data_size;
+    unsigned char *target;
+} ec_ioctl_data_t;
+
+/*****************************************************************************/
+
 #endif
--- a/tools/Master.cpp	Wed Jun 04 10:13:07 2008 +0000
+++ b/tools/Master.cpp	Wed Jun 04 10:41:50 2008 +0000
@@ -62,6 +62,21 @@
 
 /****************************************************************************/
 
+void Master::outputData(int domainIndex)
+{
+    if (domainIndex == -1) {
+        unsigned int numDomains = domainCount(), i;
+
+        for (i = 0; i < numDomains; i++) {
+            outputDomainData(i);
+        }
+    } else {
+        outputDomainData(domainIndex);
+    }
+}
+
+/****************************************************************************/
+
 void Master::showDomains(int domainIndex)
 {
     if (domainIndex == -1) {
@@ -142,17 +157,43 @@
 
 /****************************************************************************/
 
+void Master::outputDomainData(unsigned int domainIndex)
+{
+    ec_ioctl_domain_t domain;
+    ec_ioctl_data_t data;
+    unsigned char *processData;
+    unsigned int i;
+    
+    getDomain(&domain, domainIndex);
+
+    processData = new unsigned char[domain.data_size];
+
+    data.domain_index = domainIndex;
+    data.data_size = domain.data_size;
+    data.target = processData;
+
+    if (ioctl(fd, EC_IOCTL_DATA, &data) < 0) {
+        stringstream err;
+        err << "Failed to get domain data: " << strerror(errno);
+        delete [] processData;
+        throw MasterException(err.str());
+    }
+
+    for (i = 0; i < data.data_size; i++)
+        cout << processData[i];
+    cout.flush();
+
+    delete [] processData;
+}
+
+/****************************************************************************/
+
 void Master::showDomain(unsigned int domainIndex)
 {
     ec_ioctl_domain_t data;
     
     getDomain(&data, domainIndex);
 
-	unsigned int data_size;
-	uint32_t logical_base_address;
-	uint16_t working_counter;
-	uint16_t expected_working_counter;
-
 	cout << "Domain" << domainIndex << ":"
 		<< " LogBaseAddr 0x"
 		<< hex << setfill('0') << setw(8) << data.logical_base_address
--- a/tools/Master.h	Wed Jun 04 10:13:07 2008 +0000
+++ b/tools/Master.h	Wed Jun 04 10:41:50 2008 +0000
@@ -40,12 +40,14 @@
         void open(unsigned int);
         void close();
 
+        void outputData(int);
         void showDomains(int);
         void listSlaves();
         void listPdos(int);
         void generateXml(int);
 
     protected:
+        void outputDomainData(unsigned int);
         void showDomain(unsigned int);
         void listSlavePdos(uint16_t, bool = false);
         void generateSlaveXml(uint16_t);
--- a/tools/main.cpp	Wed Jun 04 10:13:07 2008 +0000
+++ b/tools/main.cpp	Wed Jun 04 10:41:50 2008 +0000
@@ -31,6 +31,7 @@
     cerr
         << "Usage: ethercat <COMMAND> [OPTIONS]" << endl
 		<< "Commands:" << endl
+        << "  data               Output binary domain process data." << endl
         << "  domain             Show domain information." << endl
         << "  list (ls, slaves)  List all slaves (former 'lsec')." << endl
         << "  pdos               List Pdo mapping of given slaves." << endl
@@ -143,7 +144,9 @@
     try {
         master.open(masterIndex);
 
-        if (command == "domain") {
+        if (command == "data") {
+            master.outputData(domainIndex);
+        } else if (command == "domain") {
             master.showDomains(domainIndex);
 		} else if (command == "list" || command == "ls" || command == "slaves") {
             master.listSlaves();