equal
deleted
inserted
replaced
1 #include <pthread.h> |
1 #include <pthread.h> |
|
2 #include <errno.h> |
2 #include "iec_types_all.h" |
3 #include "iec_types_all.h" |
3 #include "POUS.h" |
4 #include "POUS.h" |
4 #include "config.h" |
5 #include "config.h" |
5 #include "beremiz.h" |
6 #include "beremiz.h" |
6 |
7 |
7 #define DEFAULT_REFRESH_PERIOD_MS 100 |
8 #define DEFAULT_REFRESH_PERIOD_MS 100 |
8 #define HMI_BUFFER_SIZE %(buffer_size)d |
9 #define HMI_BUFFER_SIZE %(buffer_size)d |
|
10 #define HMI_ITEM_COUNT %(item_count)d |
9 |
11 |
10 /* PLC reads from that buffer */ |
12 /* PLC reads from that buffer */ |
11 static char rbuf[HMI_BUFFER_SIZE]; |
13 static char rbuf[HMI_BUFFER_SIZE]; |
12 |
14 |
13 /* PLC writes to that buffer */ |
15 /* PLC writes to that buffer */ |
48 } hmi_tree_item_t; |
50 } hmi_tree_item_t; |
49 |
51 |
50 static hmi_tree_item_t hmi_tree_item[] = { |
52 static hmi_tree_item_t hmi_tree_item[] = { |
51 %(variable_decl_array)s |
53 %(variable_decl_array)s |
52 }; |
54 }; |
|
55 |
|
56 static char sendbuf[HMI_BUFFER_SIZE]; |
53 |
57 |
54 typedef void(*hmi_tree_iterator)(hmi_tree_item_t*); |
58 typedef void(*hmi_tree_iterator)(hmi_tree_item_t*); |
55 void traverse_hmi_tree(hmi_tree_iterator fp) |
59 void traverse_hmi_tree(hmi_tree_iterator fp) |
56 { |
60 { |
57 unsigned int i; |
61 unsigned int i; |
90 }else{ |
94 }else{ |
91 dsc->wstate = buf_tosend; |
95 dsc->wstate = buf_tosend; |
92 } |
96 } |
93 } |
97 } |
94 } |
98 } |
95 |
99 |
96 /* if new value differs from previous one */ |
100 /* if new value differs from previous one */ |
97 if(memcmp(dest_p, visible_value_p, __get_type_enum_size(dsc->type)) != 0){ |
101 if(memcmp(dest_p, visible_value_p, __get_type_enum_size(dsc->type)) != 0){ |
98 /* copy and flag as set */ |
102 /* copy and flag as set */ |
99 memcpy(dest_p, visible_value_p, __get_type_enum_size(dsc->type)); |
103 memcpy(dest_p, visible_value_p, __get_type_enum_size(dsc->type)); |
100 if(dsc->wstate == buf_free) { |
104 if(dsc->wstate == buf_free) { |
139 } |
143 } |
140 |
144 |
141 static pthread_cond_t UART_WakeCond = PTHREAD_COND_INITIALIZER; |
145 static pthread_cond_t UART_WakeCond = PTHREAD_COND_INITIALIZER; |
142 static pthread_mutex_t UART_WakeCondLock = PTHREAD_MUTEX_INITIALIZER; |
146 static pthread_mutex_t UART_WakeCondLock = PTHREAD_MUTEX_INITIALIZER; |
143 |
147 |
|
148 static int continue_collect; |
|
149 |
144 int __init_svghmi() |
150 int __init_svghmi() |
145 { |
151 { |
146 bzero(rbuf,sizeof(rbuf)); |
152 bzero(rbuf,sizeof(rbuf)); |
147 bzero(wbuf,sizeof(wbuf)); |
153 bzero(wbuf,sizeof(wbuf)); |
148 continue_collect = 1; |
154 continue_collect = 1; |
173 } |
179 } |
174 |
180 |
175 /* PYTHON CALLS */ |
181 /* PYTHON CALLS */ |
176 int svghmi_send_collect(uint32_t *size, void *ptr){ |
182 int svghmi_send_collect(uint32_t *size, void *ptr){ |
177 |
183 |
|
184 int do_collect; |
178 pthread_mutex_lock(&UART_WakeCondLock); |
185 pthread_mutex_lock(&UART_WakeCondLock); |
179 do_collect = continue_collect; |
186 do_collect = continue_collect; |
180 if do_collect; |
187 if(do_collect){ |
181 pthread_cond_wait(&UART_WakeCond, &UART_WakeCondLock); |
188 pthread_cond_wait(&UART_WakeCond, &UART_WakeCondLock); |
182 do_collect = continue_collect; |
189 do_collect = continue_collect; |
|
190 } |
183 pthread_mutex_unlock(&UART_WakeCondLock); |
191 pthread_mutex_unlock(&UART_WakeCondLock); |
184 |
192 |
185 |
193 |
186 if(do_collect) { |
194 if(do_collect) { |
187 traverse_hmi_tree(send_iterator); |
195 traverse_hmi_tree(send_iterator); |