Edouard@2765: #include Edouard@2764: #include "iec_types_all.h" Edouard@2764: #include "POUS.h" Edouard@2764: #include "config.h" Edouard@2764: #include "beremiz.h" Edouard@2750: Edouard@2765: #define HMI_BUFFER_SIZE %(buffer_size)d Edouard@2765: Edouard@2765: /* PLC reads from that buffer */ Edouard@2765: static char rbuf[HMI_BUFFER_SIZE]; Edouard@2765: Edouard@2765: /* PLC writes to that buffer */ Edouard@2765: static char wbuf[HMI_BUFFER_SIZE]; Edouard@2765: Edouard@2765: static pthread_mutex_t wbuf_mutex = PTHREAD_MUTEX_INITIALIZER; Edouard@2765: static pthread_mutex_t rbuf_mutex = PTHREAD_MUTEX_INITIALIZER; Edouard@2765: Edouard@2764: %(extern_variables_declarations)s Edouard@2764: Edouard@2764: typedef const struct { Edouard@2764: void *ptr; Edouard@2764: __IEC_types_enum type; Edouard@2765: uint32_t buf_index; Edouard@2765: uint32_t flags; Edouard@2764: } hmi_tree_item_t; Edouard@2764: Edouard@2764: static hmi_tree_item_t hmi_tree_item[] = { Edouard@2764: %(variable_decl_array)s Edouard@2764: }; Edouard@2764: Edouard@2765: typedef void(*hmi_tree_iterator)(hmi_tree_item_t*); Edouard@2765: void traverse_hmi_tree(hmi_tree_iterator fp) Edouard@2765: { Edouard@2765: unsigned int i; Edouard@2765: for(i = 0; i < sizeof(hmi_tree_item)/sizeof(hmi_tree_item_t); i++){ Edouard@2765: hmi_tree_item_t *dsc = &hmi_tree_item[i]; Edouard@2765: if(dsc->type != UNKNOWN_ENUM) Edouard@2765: (*fp)(dsc); Edouard@2765: } Edouard@2765: } Edouard@2765: Edouard@2766: /* TODO : deduplicate that code with plc_debug.c */ Edouard@2766: Edouard@2766: #define __Unpack_case_t(TYPENAME) \ Edouard@2766: case TYPENAME##_ENUM :\ Edouard@2766: *flags = ((__IEC_##TYPENAME##_t *)varp)->flags;\ Edouard@2766: forced_value_p = *real_value_p = &((__IEC_##TYPENAME##_t *)varp)->value;\ Edouard@2766: break; Edouard@2766: Edouard@2766: #define __Unpack_case_p(TYPENAME)\ Edouard@2766: case TYPENAME##_O_ENUM :\ Edouard@2766: *flags = __IEC_OUTPUT_FLAG;\ Edouard@2766: case TYPENAME##_P_ENUM :\ Edouard@2766: *flags |= ((__IEC_##TYPENAME##_p *)varp)->flags;\ Edouard@2766: *real_value_p = ((__IEC_##TYPENAME##_p *)varp)->value;\ Edouard@2766: forced_value_p = &((__IEC_##TYPENAME##_p *)varp)->fvalue;\ Edouard@2766: break; Edouard@2766: Edouard@2766: static void* UnpackVar(hmi_tree_item_t *dsc, void **real_value_p, char *flags) Edouard@2766: { Edouard@2766: void *varp = dsc->ptr; Edouard@2766: void *forced_value_p = NULL; Edouard@2766: *flags = 0; Edouard@2766: /* find data to copy*/ Edouard@2766: switch(dsc->type){ Edouard@2766: __ANY(__Unpack_case_t) Edouard@2766: __ANY(__Unpack_case_p) Edouard@2766: default: Edouard@2766: break; Edouard@2766: } Edouard@2766: if (*flags & __IEC_FORCE_FLAG) Edouard@2766: return forced_value_p; Edouard@2766: return *real_value_p; Edouard@2765: } Edouard@2765: Edouard@2766: void write_iterator(hmi_tree_item_t *dsc) Edouard@2766: { Edouard@2766: void *dest_p = &wbuf[dsc->buf_index]; Edouard@2766: void *real_value_p = NULL; Edouard@2766: char flags = 0; Edouard@2766: Edouard@2766: void *visible_value_p = UnpackVar(dsc, &real_value_p, &flags); Edouard@2766: Edouard@2766: memcpy(dest_p, visible_value_p, __get_type_enum_size(dsc->type)); Edouard@2766: } Edouard@2766: Edouard@2766: void read_iterator(hmi_tree_item_t *dsc) Edouard@2766: { Edouard@2766: void *src_p = &rbuf[dsc->buf_index]; Edouard@2766: void *real_value_p = NULL; Edouard@2766: char flags = 0; Edouard@2766: Edouard@2766: void *visible_value_p = UnpackVar(dsc, &real_value_p, &flags); Edouard@2766: Edouard@2766: memcpy(visible_value_p, src_p, __get_type_enum_size(dsc->type)); Edouard@2765: } Edouard@2765: Edouard@2764: int __init_svghmi() Edouard@2764: { Edouard@2765: bzero(rbuf,sizeof(rbuf)); Edouard@2765: bzero(wbuf,sizeof(wbuf)); Edouard@2765: Edouard@2764: return 0; Edouard@2750: } Edouard@2764: Edouard@2764: void __cleanup_svghmi() Edouard@2764: { Edouard@2764: } Edouard@2764: Edouard@2764: void __retrieve_svghmi() Edouard@2764: { Edouard@2765: if(!pthread_mutex_lock(&rbuf_mutex)){ Edouard@2766: traverse_hmi_tree(read_iterator); Edouard@2765: pthread_mutex_unlock(&rbuf_mutex); Edouard@2765: } Edouard@2764: } Edouard@2764: Edouard@2764: void __publish_svghmi() Edouard@2764: { Edouard@2765: if(!pthread_mutex_lock(&wbuf_mutex)){ Edouard@2765: pthread_mutex_unlock(&wbuf_mutex); Edouard@2765: } Edouard@2764: } Edouard@2764: