svghmi/svghmi.c
branchsvghmi
changeset 2765 887aba5ef178
parent 2764 b75cc2cf4e50
child 2766 3f3b1b8ccba4
equal deleted inserted replaced
2764:b75cc2cf4e50 2765:887aba5ef178
       
     1 #include <pthread.h>
     1 #include "iec_types_all.h"
     2 #include "iec_types_all.h"
     2 #include "POUS.h"
     3 #include "POUS.h"
     3 #include "config.h"
     4 #include "config.h"
     4 #include "beremiz.h"
     5 #include "beremiz.h"
       
     6 
       
     7 #define HMI_BUFFER_SIZE %(buffer_size)d
       
     8 
       
     9 /* PLC reads from that buffer */
       
    10 static char rbuf[HMI_BUFFER_SIZE];
       
    11 
       
    12 /* PLC writes to that buffer */
       
    13 static char wbuf[HMI_BUFFER_SIZE];
       
    14 
       
    15 static pthread_mutex_t wbuf_mutex = PTHREAD_MUTEX_INITIALIZER;
       
    16 static pthread_mutex_t rbuf_mutex = PTHREAD_MUTEX_INITIALIZER;
     5 
    17 
     6 %(extern_variables_declarations)s
    18 %(extern_variables_declarations)s
     7 
    19 
     8 typedef const struct {
    20 typedef const struct {
     9     void *ptr;
    21     void *ptr;
    10     __IEC_types_enum type;
    22     __IEC_types_enum type;
    11     /* TODO : w/r buffer, flags, locks */
    23     uint32_t buf_index;
       
    24     uint32_t flags;
    12 } hmi_tree_item_t;
    25 } hmi_tree_item_t;
    13 
    26 
    14 static hmi_tree_item_t hmi_tree_item[] = {
    27 static hmi_tree_item_t hmi_tree_item[] = {
    15 %(variable_decl_array)s
    28 %(variable_decl_array)s
    16 };
    29 };
    17 
    30 
       
    31 typedef void(*hmi_tree_iterator)(hmi_tree_item_t*);
       
    32 void traverse_hmi_tree(hmi_tree_iterator fp)
       
    33 {
       
    34     unsigned int i;
       
    35     for(i = 0; i < sizeof(hmi_tree_item)/sizeof(hmi_tree_item_t); i++){
       
    36         hmi_tree_item_t *dsc = &hmi_tree_item[i];
       
    37         if(dsc->type != UNKNOWN_ENUM) 
       
    38             (*fp)(dsc);
       
    39     }
       
    40 }
       
    41 
       
    42 void read_iterator(hmi_tree_item_t *dsc){
       
    43     /* todo */
       
    44 }
       
    45 
       
    46 void write_iterator(hmi_tree_item_t *dsc){
       
    47     /* todo */
       
    48 }
       
    49 
    18 int __init_svghmi()
    50 int __init_svghmi()
    19 {
    51 {
    20     %(varinit)s
    52     bzero(rbuf,sizeof(rbuf));
       
    53     bzero(wbuf,sizeof(wbuf));
       
    54 
    21     return 0;
    55     return 0;
    22 }
    56 }
    23 
    57 
    24 void __cleanup_svghmi()
    58 void __cleanup_svghmi()
    25 {
    59 {
    26 }
    60 }
    27 
    61 
    28 void __retrieve_svghmi()
    62 void __retrieve_svghmi()
    29 {
    63 {
    30 %(varret)s
    64     if(!pthread_mutex_lock(&rbuf_mutex)){
       
    65         pthread_mutex_unlock(&rbuf_mutex);
       
    66     }
    31 }
    67 }
    32 
    68 
    33 void __publish_svghmi()
    69 void __publish_svghmi()
    34 {
    70 {
    35 %(varpub)s
    71     if(!pthread_mutex_lock(&wbuf_mutex)){
       
    72         pthread_mutex_unlock(&wbuf_mutex);
       
    73     }
    36 }
    74 }
    37 
    75