SVGHMI: WIP for python<->C data exchange : message from browser hit the C side. svghmi
authorEdouard Tisserant
Mon, 16 Sep 2019 13:45:04 +0200
branchsvghmi
changeset 2777 cdf6584953a0
parent 2776 246ae685ab65
child 2778 cdf23b10b8f7
SVGHMI: WIP for python<->C data exchange : message from browser hit the C side.
svghmi/svghmi.c
svghmi/svghmi_server.py
--- a/svghmi/svghmi.c	Mon Sep 16 11:44:20 2019 +0200
+++ b/svghmi/svghmi.c	Mon Sep 16 13:45:04 2019 +0200
@@ -142,8 +142,8 @@
     memcpy(visible_value_p, src_p, __get_type_enum_size(dsc->type));
 }
 
-static pthread_cond_t UART_WakeCond = PTHREAD_COND_INITIALIZER;
-static pthread_mutex_t UART_WakeCondLock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t svghmi_send_WakeCond = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t svghmi_send_WakeCondLock = PTHREAD_MUTEX_INITIALIZER;
 
 static int continue_collect;
 
@@ -158,10 +158,10 @@
 
 void __cleanup_svghmi()
 {
-    pthread_mutex_lock(&UART_WakeCondLock);
+    pthread_mutex_lock(&svghmi_send_WakeCondLock);
     continue_collect = 0;
-    pthread_cond_signal(&UART_WakeCond);
-    pthread_mutex_unlock(&UART_WakeCondLock);
+    pthread_cond_signal(&svghmi_send_WakeCond);
+    pthread_mutex_unlock(&svghmi_send_WakeCondLock);
 }
 
 void __retrieve_svghmi()
@@ -174,7 +174,7 @@
     global_write_dirty = 0;
     traverse_hmi_tree(write_iterator);
     if(global_write_dirty) {
-        pthread_cond_signal(&UART_WakeCond);
+        pthread_cond_signal(&svghmi_send_WakeCond);
     }
 }
 
@@ -182,13 +182,13 @@
 int svghmi_send_collect(uint32_t *size, void *ptr){
 
     int do_collect;
-    pthread_mutex_lock(&UART_WakeCondLock);
+    pthread_mutex_lock(&svghmi_send_WakeCondLock);
     do_collect = continue_collect;
     if(do_collect){
-        pthread_cond_wait(&UART_WakeCond, &UART_WakeCondLock);
+        pthread_cond_wait(&svghmi_send_WakeCond, &svghmi_send_WakeCondLock);
         do_collect = continue_collect;
     }
-    pthread_mutex_unlock(&UART_WakeCondLock);
+    pthread_mutex_unlock(&svghmi_send_WakeCondLock);
 
 
     if(do_collect) {
@@ -203,6 +203,7 @@
 }
 
 int svghmi_recv_dispatch(uint32_t size, void* ptr){
+    printf("%%*s",size,ptr);
     /* TODO something with ptr and size
         - subscribe
          or
--- a/svghmi/svghmi_server.py	Mon Sep 16 11:44:20 2019 +0200
+++ b/svghmi/svghmi_server.py	Mon Sep 16 13:45:04 2019 +0200
@@ -65,7 +65,9 @@
         #        - refresh rates / subsriptions
 
         # TODO multiclient : pass client index as well
-        pass
+
+        #
+        svghmi_recv_dispatch(len(msg), ctypes.c_void_p.from_buffer_copy(msg))
 
     def sendMessage(self, msg):
         self.sendMessage(msg, True)