svghmi/svghmi.c
branchsvghmi
changeset 2765 887aba5ef178
parent 2764 b75cc2cf4e50
child 2766 3f3b1b8ccba4
--- a/svghmi/svghmi.c	Thu Aug 22 14:58:53 2019 +0200
+++ b/svghmi/svghmi.c	Fri Aug 23 13:01:37 2019 +0200
@@ -1,23 +1,57 @@
+#include <pthread.h>
 #include "iec_types_all.h"
 #include "POUS.h"
 #include "config.h"
 #include "beremiz.h"
 
+#define HMI_BUFFER_SIZE %(buffer_size)d
+
+/* PLC reads from that buffer */
+static char rbuf[HMI_BUFFER_SIZE];
+
+/* PLC writes to that buffer */
+static char wbuf[HMI_BUFFER_SIZE];
+
+static pthread_mutex_t wbuf_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t rbuf_mutex = PTHREAD_MUTEX_INITIALIZER;
+
 %(extern_variables_declarations)s
 
 typedef const struct {
     void *ptr;
     __IEC_types_enum type;
-    /* TODO : w/r buffer, flags, locks */
+    uint32_t buf_index;
+    uint32_t flags;
 } hmi_tree_item_t;
 
 static hmi_tree_item_t hmi_tree_item[] = {
 %(variable_decl_array)s
 };
 
+typedef void(*hmi_tree_iterator)(hmi_tree_item_t*);
+void traverse_hmi_tree(hmi_tree_iterator fp)
+{
+    unsigned int i;
+    for(i = 0; i < sizeof(hmi_tree_item)/sizeof(hmi_tree_item_t); i++){
+        hmi_tree_item_t *dsc = &hmi_tree_item[i];
+        if(dsc->type != UNKNOWN_ENUM) 
+            (*fp)(dsc);
+    }
+}
+
+void read_iterator(hmi_tree_item_t *dsc){
+    /* todo */
+}
+
+void write_iterator(hmi_tree_item_t *dsc){
+    /* todo */
+}
+
 int __init_svghmi()
 {
-    %(varinit)s
+    bzero(rbuf,sizeof(rbuf));
+    bzero(wbuf,sizeof(wbuf));
+
     return 0;
 }
 
@@ -27,11 +61,15 @@
 
 void __retrieve_svghmi()
 {
-%(varret)s
+    if(!pthread_mutex_lock(&rbuf_mutex)){
+        pthread_mutex_unlock(&rbuf_mutex);
+    }
 }
 
 void __publish_svghmi()
 {
-%(varpub)s
+    if(!pthread_mutex_lock(&wbuf_mutex)){
+        pthread_mutex_unlock(&wbuf_mutex);
+    }
 }