Mark download data as const.
authorGavin Lambert <uecasm@users.sourceforge.net>
Sat, 31 May 2014 18:08:27 +1200
changeset 2622 1aee02c1e294
parent 2621 a26dee45c467
child 2623 ae24ede76e16
Mark download data as const.
Remove redundant code.
[07-sdo-up-download]
include/ecrt.h
lib/master.c
master/ioctl.c
master/ioctl.h
master/master.c
tool/CommandDownload.cpp
--- a/include/ecrt.h	Sat May 31 17:21:53 2014 +1200
+++ b/include/ecrt.h	Sat May 31 18:08:27 2014 +1200
@@ -815,7 +815,7 @@
         uint16_t slave_position, /**< Slave position. */
         uint16_t index, /**< Index of the SDO. */
         uint8_t subindex, /**< Subindex of the SDO. */
-        uint8_t *data, /**< Data buffer to download. */
+        const uint8_t *data, /**< Data buffer to download. */
         size_t data_size, /**< Size of the data buffer. */
         uint32_t *abort_code /**< Abort code of the SDO download. */
         );
@@ -834,7 +834,7 @@
         ec_master_t *master, /**< EtherCAT master. */
         uint16_t slave_position, /**< Slave position. */
         uint16_t index, /**< Index of the SDO. */
-        uint8_t *data, /**< Data buffer to download. */
+        const uint8_t *data, /**< Data buffer to download. */
         size_t data_size, /**< Size of the data buffer. */
         uint32_t *abort_code /**< Abort code of the SDO download. */
         );
--- a/lib/master.c	Sat May 31 17:21:53 2014 +1200
+++ b/lib/master.c	Sat May 31 18:08:27 2014 +1200
@@ -390,7 +390,7 @@
 /****************************************************************************/
 
 int ecrt_master_sdo_download(ec_master_t *master, uint16_t slave_position,
-        uint16_t index, uint8_t subindex, uint8_t *data,
+        uint16_t index, uint8_t subindex, const uint8_t *data,
         size_t data_size, uint32_t *abort_code)
 {
     ec_ioctl_slave_sdo_download_t download;
@@ -419,7 +419,7 @@
 /****************************************************************************/
 
 int ecrt_master_sdo_download_complete(ec_master_t *master,
-        uint16_t slave_position, uint16_t index, uint8_t *data,
+        uint16_t slave_position, uint16_t index, const uint8_t *data,
         size_t data_size, uint32_t *abort_code)
 {
     ec_ioctl_slave_sdo_download_t download;
--- a/master/ioctl.c	Sat May 31 17:21:53 2014 +1200
+++ b/master/ioctl.c	Sat May 31 18:08:27 2014 +1200
@@ -864,7 +864,7 @@
         return -ENOMEM;
     }
 
-    if (copy_from_user(sdo_data, (void __user *) data.data, data.data_size)) {
+    if (copy_from_user(sdo_data, (const void __user *) data.data, data.data_size)) {
         kfree(sdo_data);
         return -EFAULT;
     }
--- a/master/ioctl.h	Sat May 31 17:21:53 2014 +1200
+++ b/master/ioctl.h	Sat May 31 18:08:27 2014 +1200
@@ -400,7 +400,7 @@
     uint8_t sdo_entry_subindex;
     uint8_t complete_access;
     size_t data_size;
-    uint8_t *data;
+    const uint8_t *data;
 
     // outputs
     uint32_t abort_code;
--- a/master/master.c	Sat May 31 17:21:53 2014 +1200
+++ b/master/master.c	Sat May 31 18:08:27 2014 +1200
@@ -2849,7 +2849,7 @@
 /*****************************************************************************/
 
 int ecrt_master_sdo_download(ec_master_t *master, uint16_t slave_position,
-        uint16_t index, uint8_t subindex, uint8_t *data,
+        uint16_t index, uint8_t subindex, const uint8_t *data,
         size_t data_size, uint32_t *abort_code)
 {
     ec_sdo_request_t request;
@@ -2933,7 +2933,7 @@
 /*****************************************************************************/
 
 int ecrt_master_sdo_download_complete(ec_master_t *master,
-        uint16_t slave_position, uint16_t index, uint8_t *data,
+        uint16_t slave_position, uint16_t index, const uint8_t *data,
         size_t data_size, uint32_t *abort_code)
 {
     ec_sdo_request_t request;
--- a/tool/CommandDownload.cpp	Sat May 31 17:21:53 2014 +1200
+++ b/tool/CommandDownload.cpp	Sat May 31 18:08:27 2014 +1200
@@ -173,16 +173,17 @@
             throwCommandException(err);
         }
         data.data_size = contents.size();
-        data.data = new uint8_t[data.data_size + 1];
+        uint8_t *sdo_data = new uint8_t[data.data_size + 1];
+        data.data = sdo_data;
 
         try {
             data.data_size = interpretAsType(
-                    dataType, contents, data.data, data.data_size);
+                    dataType, contents, sdo_data, data.data_size);
         } catch (SizeException &e) {
-            delete [] data.data;
+            delete [] sdo_data;
             throwCommandException(e.what());
         } catch (ios::failure &e) {
-            delete [] data.data;
+            delete [] sdo_data;
             err << "Invalid value argument '" << args[2]
                 << "' for type '" << dataType->name << "'!";
             throwInvalidUsageException(err);
@@ -195,16 +196,17 @@
             data.data_size = DefaultBufferSize;
         }
 
-        data.data = new uint8_t[data.data_size + 1];
+        uint8_t *sdo_data = new uint8_t[data.data_size + 1];
+        data.data = sdo_data;
 
         try {
             data.data_size = interpretAsType(
-                    dataType, args[valueIndex], data.data, data.data_size);
+                    dataType, args[valueIndex], sdo_data, data.data_size);
         } catch (SizeException &e) {
-            delete [] data.data;
+            delete [] sdo_data;
             throwCommandException(e.what());
         } catch (ios::failure &e) {
-            delete [] data.data;
+            delete [] sdo_data;
             err << "Invalid value argument '" << args[2]
                 << "' for type '" << dataType->name << "'!";
             throwInvalidUsageException(err);
@@ -212,19 +214,6 @@
     }
 
     try {
-        data.data_size = interpretAsType(
-                dataType, args[valueIndex], data.data, data.data_size);
-    } catch (SizeException &e) {
-        delete [] data.data;
-        throwCommandException(e.what());
-    } catch (ios::failure &e) {
-        delete [] data.data;
-        err << "Invalid value argument '" << args[2]
-            << "' for type '" << dataType->name << "'!";
-        throwInvalidUsageException(err);
-    }
-
-    try {
         m.sdoDownload(&data);
     } catch (MasterDeviceSdoAbortException &e) {
         delete [] data.data;