svghmi/svghmi.c
branchsvghmi
changeset 2777 cdf6584953a0
parent 2776 246ae685ab65
child 2779 75c6a31caca6
equal deleted inserted replaced
2776:246ae685ab65 2777:cdf6584953a0
   140 
   140 
   141 
   141 
   142     memcpy(visible_value_p, src_p, __get_type_enum_size(dsc->type));
   142     memcpy(visible_value_p, src_p, __get_type_enum_size(dsc->type));
   143 }
   143 }
   144 
   144 
   145 static pthread_cond_t UART_WakeCond = PTHREAD_COND_INITIALIZER;
   145 static pthread_cond_t svghmi_send_WakeCond = PTHREAD_COND_INITIALIZER;
   146 static pthread_mutex_t UART_WakeCondLock = PTHREAD_MUTEX_INITIALIZER;
   146 static pthread_mutex_t svghmi_send_WakeCondLock = PTHREAD_MUTEX_INITIALIZER;
   147 
   147 
   148 static int continue_collect;
   148 static int continue_collect;
   149 
   149 
   150 int __init_svghmi()
   150 int __init_svghmi()
   151 {
   151 {
   156     return 0;
   156     return 0;
   157 }
   157 }
   158 
   158 
   159 void __cleanup_svghmi()
   159 void __cleanup_svghmi()
   160 {
   160 {
   161     pthread_mutex_lock(&UART_WakeCondLock);
   161     pthread_mutex_lock(&svghmi_send_WakeCondLock);
   162     continue_collect = 0;
   162     continue_collect = 0;
   163     pthread_cond_signal(&UART_WakeCond);
   163     pthread_cond_signal(&svghmi_send_WakeCond);
   164     pthread_mutex_unlock(&UART_WakeCondLock);
   164     pthread_mutex_unlock(&svghmi_send_WakeCondLock);
   165 }
   165 }
   166 
   166 
   167 void __retrieve_svghmi()
   167 void __retrieve_svghmi()
   168 {
   168 {
   169     traverse_hmi_tree(read_iterator);
   169     traverse_hmi_tree(read_iterator);
   172 void __publish_svghmi()
   172 void __publish_svghmi()
   173 {
   173 {
   174     global_write_dirty = 0;
   174     global_write_dirty = 0;
   175     traverse_hmi_tree(write_iterator);
   175     traverse_hmi_tree(write_iterator);
   176     if(global_write_dirty) {
   176     if(global_write_dirty) {
   177         pthread_cond_signal(&UART_WakeCond);
   177         pthread_cond_signal(&svghmi_send_WakeCond);
   178     }
   178     }
   179 }
   179 }
   180 
   180 
   181 /* PYTHON CALLS */
   181 /* PYTHON CALLS */
   182 int svghmi_send_collect(uint32_t *size, void *ptr){
   182 int svghmi_send_collect(uint32_t *size, void *ptr){
   183 
   183 
   184     int do_collect;
   184     int do_collect;
   185     pthread_mutex_lock(&UART_WakeCondLock);
   185     pthread_mutex_lock(&svghmi_send_WakeCondLock);
   186     do_collect = continue_collect;
   186     do_collect = continue_collect;
   187     if(do_collect){
   187     if(do_collect){
   188         pthread_cond_wait(&UART_WakeCond, &UART_WakeCondLock);
   188         pthread_cond_wait(&svghmi_send_WakeCond, &svghmi_send_WakeCondLock);
   189         do_collect = continue_collect;
   189         do_collect = continue_collect;
   190     }
   190     }
   191     pthread_mutex_unlock(&UART_WakeCondLock);
   191     pthread_mutex_unlock(&svghmi_send_WakeCondLock);
   192 
   192 
   193 
   193 
   194     if(do_collect) {
   194     if(do_collect) {
   195         traverse_hmi_tree(send_iterator);
   195         traverse_hmi_tree(send_iterator);
   196         /* TODO set ptr and size to something  */
   196         /* TODO set ptr and size to something  */
   201         return EINTR;
   201         return EINTR;
   202     }
   202     }
   203 }
   203 }
   204 
   204 
   205 int svghmi_recv_dispatch(uint32_t size, void* ptr){
   205 int svghmi_recv_dispatch(uint32_t size, void* ptr){
       
   206     printf("%%*s",size,ptr);
   206     /* TODO something with ptr and size
   207     /* TODO something with ptr and size
   207         - subscribe
   208         - subscribe
   208          or
   209          or
   209         - spread values
   210         - spread values
   210     */
   211     */