svghmi/svghmi.c
branchsvghmi
changeset 2822 9101a72a1da0
parent 2820 d9b5303d43dc
child 2826 1e5abecc3cde
equal deleted inserted replaced
2821:d92d201d22e1 2822:9101a72a1da0
   255     setval = 0,
   255     setval = 0,
   256     reset = 1,
   256     reset = 1,
   257     subscribe = 2
   257     subscribe = 2
   258 } cmd_from_JS;
   258 } cmd_from_JS;
   259 
   259 
       
   260 // Returns :
       
   261 //   0 is OK, <0 is error, 1 is heartbeat
   260 int svghmi_recv_dispatch(uint32_t size, const uint8_t *ptr){
   262 int svghmi_recv_dispatch(uint32_t size, const uint8_t *ptr){
   261     const uint8_t* cursor = ptr + HMI_HASH_SIZE;
   263     const uint8_t* cursor = ptr + HMI_HASH_SIZE;
   262     const uint8_t* end = ptr + size;
   264     const uint8_t* end = ptr + size;
   263 
   265 
       
   266     int was_hearbeat = 0;
   264 
   267 
   265     /* match hmitree fingerprint */
   268     /* match hmitree fingerprint */
   266     if(size <= HMI_HASH_SIZE || memcmp(ptr, hmi_hash, HMI_HASH_SIZE) != 0)
   269     if(size <= HMI_HASH_SIZE || memcmp(ptr, hmi_hash, HMI_HASH_SIZE) != 0)
   267     {
   270     {
   268         printf("svghmi_recv_dispatch MISMATCH !!\n");
   271         printf("svghmi_recv_dispatch MISMATCH !!\n");
   269         return EINVAL;
   272         return -EINVAL;
   270     }
   273     }
   271 
   274 
   272     while(cursor < end)
   275     while(cursor < end)
   273     {
   276     {
   274         uint32_t progress;
   277         uint32_t progress;
   277         {
   280         {
   278             case setval:
   281             case setval:
   279             {
   282             {
   280                 uint32_t index = *(uint32_t*)(cursor);
   283                 uint32_t index = *(uint32_t*)(cursor);
   281                 uint8_t const *valptr = cursor + sizeof(uint32_t);
   284                 uint8_t const *valptr = cursor + sizeof(uint32_t);
       
   285                 
       
   286                 if(index == heartbeat_index)
       
   287                     was_hearbeat = 1;
   282 
   288 
   283                 if(index < HMI_ITEM_COUNT)
   289                 if(index < HMI_ITEM_COUNT)
   284                 {
   290                 {
   285                     hmi_tree_item_t *dsc = &hmi_tree_item[index];
   291                     hmi_tree_item_t *dsc = &hmi_tree_item[index];
   286                     void *real_value_p = NULL;
   292                     void *real_value_p = NULL;
   342                 printf("svghmi_recv_dispatch unknown %%d\n",cmd);
   348                 printf("svghmi_recv_dispatch unknown %%d\n",cmd);
   343 
   349 
   344         }
   350         }
   345         cursor += progress;
   351         cursor += progress;
   346     }
   352     }
   347     return 0;
   353     return was_hearbeat;
   348 }
   354 }
   349 
   355