With info from size list every item of halui_str is initialized or
copied in one for loop.

Based on discussion with micges and SWPadnos.

Signed-off-by: Pavel Shramov <shra...@mexmat.net>
---
 src/emc/usr_intf/halui.cc |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/src/emc/usr_intf/halui.cc b/src/emc/usr_intf/halui.cc
index 2d7e1e0..9133eff 100644
--- a/src/emc/usr_intf/halui.cc
+++ b/src/emc/usr_intf/halui.cc
@@ -35,6 +35,8 @@
 #include "nml_oi.hh"
 #include "timer.hh"
 
+#include "halui_size.h"
+
 /*
   Using halui:
 
@@ -338,6 +340,28 @@ struct halui_str {
     hal_bit_t *mdi_commands[MDI_MAX];
 } * halui_data; 
 
+struct halui_str halui_local0, *halui_old = &halui_local0;
+struct halui_str halui_local1, *halui_new = &halui_local1;
+hal_float_t halui_buffer0[sizeof(halui_data_size)]; // Buffer for local0
+hal_float_t halui_buffer1[sizeof(halui_data_size)]; // Buffer for local1
+
+void halui_str_init(struct halui_str * s, hal_float_t * buffer) {
+    for (size_t i = 0; i < sizeof(halui_data_size); i++)
+       ((void **) s)[i] = (void *) (buffer + i);
+}
+
+void halui_str_copy(struct halui_str * dest, const struct halui_str * src) {
+    for (size_t i = 0; i < sizeof(halui_data_size); i++) {
+       const void * s = *((const void **) src + i);
+       void ** d = ((void **) dest + i);
+
+       if (s)
+           memcpy(*d, s, halui_data_size[i]);
+       else
+           *d = 0;
+    }
+}
+
 struct local_halui_str {
     hal_bit_t machine_on;         //pin for setting machine On
     hal_bit_t machine_off;        //pin for setting machine Off
@@ -1652,6 +1676,13 @@ static void check_hal_changes()
     int select_changed, joint;
     hal_bit_t bit, js;
     hal_float_t floatt;
+
+    {
+       halui_str * tmp = halui_old;
+       halui_old = halui_new;
+       halui_new = tmp;
+       halui_str_copy(halui_new, halui_data);
+    }
     
     //check if machine_on pin has changed (the rest work exactly the same)
     if (check_bit_changed(halui_data->machine_on, 
&(old_halui_data.machine_on)) != 0)
@@ -2077,6 +2108,9 @@ int main(int argc, char *argv[])
     }
 
     //initialize safe values
+    halui_str_init(&halui_local0, halui_buffer0);
+    halui_str_init(&halui_local1, halui_buffer1);
+
     hal_init_pins();
 
     // init NML
-- 
1.7.1

------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
Emc-developers mailing list
Emc-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to