Fixed bug in copying sync managers. Now making a deep copy.
authorFlorian Pose <fp@igh-essen.com>
Mon, 17 Mar 2008 14:16:16 +0000
changeset 873 ec01ba291896
parent 872 d4e0380d63b3
child 874 022f869ea40f
Fixed bug in copying sync managers. Now making a deep copy.
master/slave.c
master/sync.c
master/sync.h
--- a/master/slave.c	Mon Mar 17 09:38:48 2008 +0000
+++ b/master/slave.c	Mon Mar 17 14:16:16 2008 +0000
@@ -502,9 +502,8 @@
             return -1;
         }
 
-        // copy existing sync managers
-        memcpy(syncs, slave->sii.syncs,
-                slave->sii.sync_count * sizeof(ec_sync_t));
+        for (i = 0; i < slave->sii.sync_count; i++)
+            ec_sync_init_copy(syncs + i, slave->sii.syncs + i);
 
         // initialize new sync managers
         for (i = 0; i < count; i++, data += 8) {
--- a/master/sync.c	Mon Mar 17 09:38:48 2008 +0000
+++ b/master/sync.c	Mon Mar 17 14:16:16 2008 +0000
@@ -62,6 +62,28 @@
 
 /*****************************************************************************/
 
+/** Copy constructor.
+ */
+void ec_sync_init_copy(
+        ec_sync_t *sync, /**< EtherCAT sync manager. */
+        const ec_sync_t *other /**< Sync manager to copy from. */
+        )
+{
+   sync->slave = other->slave;
+   sync->index = other->index;
+   sync->physical_start_address = other->physical_start_address;
+   sync->length = other->length;
+   sync->control_register = other->control_register;
+   sync->enable = other->enable;
+   
+   ec_pdo_mapping_init(&sync->mapping);
+   ec_pdo_mapping_copy(&sync->mapping, &other->mapping);
+
+   sync->mapping_source = other->mapping_source;
+}
+
+/*****************************************************************************/
+
 /** Destructor.
  */
 void ec_sync_clear(
--- a/master/sync.h	Mon Mar 17 09:38:48 2008 +0000
+++ b/master/sync.h	Mon Mar 17 14:16:16 2008 +0000
@@ -76,6 +76,7 @@
 /*****************************************************************************/
 
 void ec_sync_init(ec_sync_t *, ec_slave_t *, unsigned int);
+void ec_sync_init_copy(ec_sync_t *, const ec_sync_t *);
 void ec_sync_clear(ec_sync_t *);
 
 void ec_sync_config(const ec_sync_t *, uint16_t, uint8_t *);