svghmi/svghmi.c
branchRuntimeLists
changeset 3397 75920c99ffc9
parent 3374 9a82918e063c
child 3399 95e0b926a8c3
equal deleted inserted replaced
3396:8c8cb5c9ff38 3397:75920c99ffc9
    85 {
    85 {
    86     {
    86     {
    87         uint32_t session_index = 0;
    87         uint32_t session_index = 0;
    88         int value_changed = 0;
    88         int value_changed = 0;
    89         void *dest_p = NULL;
    89         void *dest_p = NULL;
    90         void *real_value_p = NULL;
    90         void *value_p = NULL;
    91         void *visible_value_p = NULL;
    91         size_t sz = 0;
    92         USINT sz = 0;
       
    93         while(session_index < MAX_CONNECTIONS) {
    92         while(session_index < MAX_CONNECTIONS) {
    94             if(dsc->wstate[session_index] == buf_set){
    93             if(dsc->wstate[session_index] == buf_set){
    95                 /* if being subscribed */
    94                 /* if being subscribed */
    96                 if(dsc->refresh_period_ms[session_index]){
    95                 if(dsc->refresh_period_ms[session_index]){
    97                     if(dsc->age_ms[session_index] + ticktime_ms < dsc->refresh_period_ms[session_index]){
    96                     if(dsc->age_ms[session_index] + ticktime_ms < dsc->refresh_period_ms[session_index]){
   109             int just_subscribed = dsc->wstate[session_index] == buf_new;
   108             int just_subscribed = dsc->wstate[session_index] == buf_new;
   110             if(!just_subscribed){
   109             if(!just_subscribed){
   111                 int already_subscribed = dsc->refresh_period_ms[session_index] > 0;
   110                 int already_subscribed = dsc->refresh_period_ms[session_index] > 0;
   112                 if(already_subscribed){
   111                 if(already_subscribed){
   113                     if(!value_changed){
   112                     if(!value_changed){
   114                         if(!visible_value_p){
   113                         if(!value_p){
   115                             char flags = 0;
   114                             UnpackVar(dsc, &value_p, NULL, &sz);
   116                             visible_value_p = UnpackVar(dsc, &real_value_p, &flags);
       
   117                             if(__Is_a_string(dsc)){
   115                             if(__Is_a_string(dsc)){
   118                                 sz = ((STRING*)visible_value_p)->len + 1;
   116                                 sz = ((STRING*)value_p)->len + 1;
   119                             } else {
   117                             } 
   120                                 sz = __get_type_enum_size(dsc->type);
       
   121                             }
       
   122                             dest_p = &wbuf[dsc->buf_index];
   118                             dest_p = &wbuf[dsc->buf_index];
   123                         }
   119                         }
   124                         value_changed = memcmp(dest_p, visible_value_p, sz) != 0;
   120                         value_changed = memcmp(dest_p, value_p, sz) != 0;
   125                         do_sample = value_changed;
   121                         do_sample = value_changed;
   126                     }else{
   122                     }else{
   127                         do_sample = 1;
   123                         do_sample = 1;
   128                     }
   124                     }
   129                 }
   125                 }
   147 
   143 
   148             session_index++;
   144             session_index++;
   149         }
   145         }
   150         /* copy value if changed (and subscribed) */
   146         /* copy value if changed (and subscribed) */
   151         if(value_changed)
   147         if(value_changed)
   152             memcpy(dest_p, visible_value_p, sz);
   148             memcpy(dest_p, value_p, sz);
   153     }
   149     }
   154     // else ... : PLC can't wait, variable will be updated next turn
   150     // else ... : PLC can't wait, variable will be updated next turn
   155     return 0;
   151     return 0;
   156 }
   152 }
   157 
   153 
   187 static int read_iterator(uint32_t index, hmi_tree_item_t *dsc)
   183 static int read_iterator(uint32_t index, hmi_tree_item_t *dsc)
   188 {
   184 {
   189     if(dsc->rstate == buf_set)
   185     if(dsc->rstate == buf_set)
   190     {
   186     {
   191         void *src_p = &rbuf[dsc->buf_index];
   187         void *src_p = &rbuf[dsc->buf_index];
   192         void *real_value_p = NULL;
   188         void *value_p = NULL;
   193         char flags = 0;
   189         size_t sz = 0;
   194         void *visible_value_p = UnpackVar(dsc, &real_value_p, &flags);
   190         UnpackVar(dsc, &value_p, NULL, &sz);
   195         memcpy(real_value_p, src_p, __get_type_enum_size(dsc->type));
   191         memcpy(value_p, src_p, sz);
   196         dsc->rstate = buf_free;
   192         dsc->rstate = buf_free;
   197     }
   193     }
   198     return 0;
   194     return 0;
   199 }
   195 }
   200 
   196 
   376                     was_hearbeat = 1;
   372                     was_hearbeat = 1;
   377 
   373 
   378                 if(index < HMI_ITEM_COUNT)
   374                 if(index < HMI_ITEM_COUNT)
   379                 {
   375                 {
   380                     hmi_tree_item_t *dsc = &hmi_tree_item[index];
   376                     hmi_tree_item_t *dsc = &hmi_tree_item[index];
   381                     void *real_value_p = NULL;
   377                     void *value_p = NULL;
   382                     char flags = 0;
   378                     size_t sz = 0;
   383                     void *visible_value_p = UnpackVar(dsc, &real_value_p, &flags);
   379                     UnpackVar(dsc, &value_p, NULL, &sz);
   384                     void *dst_p = &rbuf[dsc->buf_index];
   380                     void *dst_p = &rbuf[dsc->buf_index];
   385                     uint32_t sz = __get_type_enum_size(dsc->type);
       
   386 
   381 
   387                     if(__Is_a_string(dsc)){
   382                     if(__Is_a_string(dsc)){
   388                         sz = ((STRING*)valptr)->len + 1;
   383                         sz = ((STRING*)valptr)->len + 1;
   389                     }
   384                     }
   390 
   385