63 typedef int(*hmi_tree_iterator)(uint32_t, hmi_tree_item_t*); |
63 typedef int(*hmi_tree_iterator)(uint32_t, hmi_tree_item_t*); |
64 static int traverse_hmi_tree(hmi_tree_iterator fp) |
64 static int traverse_hmi_tree(hmi_tree_iterator fp) |
65 { |
65 { |
66 unsigned int i; |
66 unsigned int i; |
67 for(i = 0; i < sizeof(hmi_tree_item)/sizeof(hmi_tree_item_t); i++){ |
67 for(i = 0; i < sizeof(hmi_tree_item)/sizeof(hmi_tree_item_t); i++){ |
68 int res; |
|
69 hmi_tree_item_t *dsc = &hmi_tree_item[i]; |
68 hmi_tree_item_t *dsc = &hmi_tree_item[i]; |
70 if(res = (*fp)(i, dsc)) |
69 int res = (*fp)(i, dsc); |
|
70 if(res != 0){ |
71 return res; |
71 return res; |
72 } |
72 } |
|
73 } |
|
74 return 0; |
73 } |
75 } |
74 |
76 |
75 #define __Unpack_desc_type hmi_tree_item_t |
77 #define __Unpack_desc_type hmi_tree_item_t |
76 |
78 |
77 %(var_access_code)s |
79 %(var_access_code)s |
114 return 0; |
116 return 0; |
115 } |
117 } |
116 |
118 |
117 static int send_iterator(uint32_t index, hmi_tree_item_t *dsc) |
119 static int send_iterator(uint32_t index, hmi_tree_item_t *dsc) |
118 { |
120 { |
119 int res = 0; |
|
120 while(AtomicCompareExchange(&dsc->wlock, 0, 1)) sched_yield(); |
121 while(AtomicCompareExchange(&dsc->wlock, 0, 1)) sched_yield(); |
121 |
122 |
122 if(dsc->wstate == buf_tosend) |
123 if(dsc->wstate == buf_tosend) |
123 { |
124 { |
124 uint32_t sz = __get_type_enum_size(dsc->type); |
125 uint32_t sz = __get_type_enum_size(dsc->type); |
125 if(sbufidx + sizeof(uint32_t) + sz < sizeof(sbuf)) |
126 if(sbufidx + sizeof(uint32_t) + sz <= sizeof(sbuf)) |
126 { |
127 { |
127 void *src_p = &wbuf[dsc->buf_index]; |
128 void *src_p = &wbuf[dsc->buf_index]; |
128 void *dst_p = &sbuf[sbufidx]; |
129 void *dst_p = &sbuf[sbufidx]; |
|
130 /* TODO : force into little endian */ |
129 memcpy(dst_p, &index, sizeof(uint32_t)); |
131 memcpy(dst_p, &index, sizeof(uint32_t)); |
130 memcpy(dst_p + sizeof(uint32_t), src_p, sz); |
132 memcpy(dst_p + sizeof(uint32_t), src_p, sz); |
131 dsc->wstate = buf_free; |
133 dsc->wstate = buf_free; |
132 sbufidx += sizeof(uint32_t) /* index */ + sz; |
134 sbufidx += sizeof(uint32_t) /* index */ + sz; |
133 } |
135 } |
134 else |
136 else |
135 { |
137 { |
136 res = EOVERFLOW; |
138 printf("BUG!!! %%d + %%ld + %%d > %%ld \n", sbufidx, sizeof(uint32_t), sz, sizeof(sbuf)); |
|
139 AtomicCompareExchange(&dsc->wlock, 1, 0); |
|
140 return EOVERFLOW; |
137 } |
141 } |
138 } |
142 } |
139 |
143 |
140 AtomicCompareExchange(&dsc->wlock, 1, 0); |
144 AtomicCompareExchange(&dsc->wlock, 1, 0); |
141 return res; |
145 return 0; |
142 } |
146 } |
143 |
147 |
144 static int read_iterator(uint32_t index, hmi_tree_item_t *dsc) |
148 static int read_iterator(uint32_t index, hmi_tree_item_t *dsc) |
145 { |
149 { |
146 if(AtomicCompareExchange(&dsc->rlock, 0, 1) == 0) |
150 if(AtomicCompareExchange(&dsc->rlock, 0, 1) == 0) |
222 } |
226 } |
223 pthread_mutex_unlock(&svghmi_send_WakeCondLock); |
227 pthread_mutex_unlock(&svghmi_send_WakeCondLock); |
224 |
228 |
225 if(do_collect) { |
229 if(do_collect) { |
226 int res; |
230 int res; |
227 memcpy(&sbuf[0], &hmi_hash[0], HMI_HASH_SIZE); |
|
228 sbufidx = HMI_HASH_SIZE; |
231 sbufidx = HMI_HASH_SIZE; |
229 if((res = traverse_hmi_tree(send_iterator)) == 0) |
232 if((res = traverse_hmi_tree(send_iterator)) == 0) |
230 { |
233 { |
231 *ptr = &sbuf[0]; |
234 if(sbufidx > HMI_HASH_SIZE){ |
232 *size = sbufidx; |
235 memcpy(&sbuf[0], &hmi_hash[0], HMI_HASH_SIZE); |
233 } |
236 *ptr = &sbuf[0]; |
|
237 *size = sbufidx; |
|
238 return 0; |
|
239 } |
|
240 return ENODATA; |
|
241 } |
|
242 // printf("collected BAD result %%d\n", res); |
234 return res; |
243 return res; |
235 } |
244 } |
236 else |
245 else |
237 { |
246 { |
238 return EINTR; |
247 return EINTR; |
247 |
256 |
248 int svghmi_recv_dispatch(uint32_t size, const uint8_t *ptr){ |
257 int svghmi_recv_dispatch(uint32_t size, const uint8_t *ptr){ |
249 const uint8_t* cursor = ptr + HMI_HASH_SIZE; |
258 const uint8_t* cursor = ptr + HMI_HASH_SIZE; |
250 const uint8_t* end = ptr + size; |
259 const uint8_t* end = ptr + size; |
251 |
260 |
252 printf("svghmi_recv_dispatch %%d\n",size); |
|
253 |
261 |
254 /* match hmitree fingerprint */ |
262 /* match hmitree fingerprint */ |
255 if(size <= HMI_HASH_SIZE || memcmp(ptr, hmi_hash, HMI_HASH_SIZE) != 0) |
263 if(size <= HMI_HASH_SIZE || memcmp(ptr, hmi_hash, HMI_HASH_SIZE) != 0) |
256 { |
264 { |
257 printf("svghmi_recv_dispatch MISMATCH !!\n"); |
265 printf("svghmi_recv_dispatch MISMATCH !!\n"); |
309 |
323 |
310 if(index < HMI_ITEM_COUNT) |
324 if(index < HMI_ITEM_COUNT) |
311 { |
325 { |
312 hmi_tree_item_t *dsc = &hmi_tree_item[index]; |
326 hmi_tree_item_t *dsc = &hmi_tree_item[index]; |
313 update_refresh_period(dsc, refresh_period_ms); |
327 update_refresh_period(dsc, refresh_period_ms); |
314 } |
328 printf("OK\n"); |
315 else return -EINVAL; |
329 } |
|
330 else |
|
331 { |
|
332 return -EINVAL; |
|
333 } |
316 |
334 |
317 progress = sizeof(uint32_t) /* index */ + |
335 progress = sizeof(uint32_t) /* index */ + |
318 sizeof(uint16_t) /* refresh period */; |
336 sizeof(uint16_t) /* refresh period */; |
319 } |
337 } |
320 break; |
338 break; |
|
339 default: |
|
340 printf("svghmi_recv_dispatch unknown %%d\n",cmd); |
321 |
341 |
322 } |
342 } |
323 cursor += progress; |
343 cursor += progress; |
324 } |
344 } |
325 return 0; |
345 return 0; |