1 | /*
|
---|
2 | * TOPPERS ECHONET Lite Communication Middleware
|
---|
3 | *
|
---|
4 | * Copyright (C) 2015 Cores Co., Ltd. Japan
|
---|
5 | *
|
---|
6 | * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
|
---|
7 | * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü
|
---|
8 | * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
9 | * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
10 | * \¦C±Ìpð¨æÑºLÌ³ÛØKèªC»ÌÜÜÌ`Å\[
|
---|
11 | * XR[hÉÜÜêĢ鱯D
|
---|
12 | * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg
|
---|
13 | * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
14 | gip
|
---|
15 | * Ò}j
|
---|
16 | AÈÇjÉCãLÌì \¦C±Ìpð¨æÑºL
|
---|
17 | * Ì³ÛØKèðfÚ·é±ÆD
|
---|
18 | * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg
|
---|
19 | * pūȢ`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
|
---|
20 | * ÆD
|
---|
21 | * (a) Äzzɺ¤hL
|
---|
22 | gipÒ}j
|
---|
23 | AÈÇjÉCãLÌ
|
---|
24 | * ì \¦C±Ìpð¨æÑºLÌ³ÛØKèðfÚ·é±ÆD
|
---|
25 | * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
|
---|
26 | * ñ·é±ÆD
|
---|
27 | * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹
|
---|
28 | * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
29 | * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé
|
---|
30 | * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð
|
---|
31 | * ÆÓ·é±ÆD
|
---|
32 | *
|
---|
33 | * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
|
---|
34 | * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
|
---|
35 | * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF
|
---|
36 | * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC»
|
---|
37 | * ÌÓCðíÈ¢D
|
---|
38 | *
|
---|
39 | * @(#) $Id: echonet_agent.c 101 2015-06-02 15:37:23Z coas-nagasima $
|
---|
40 | */
|
---|
41 |
|
---|
42 | /*
|
---|
43 | * ECHONET Lite ®I¶¬m[h
|
---|
44 | */
|
---|
45 |
|
---|
46 | #include <kernel.h>
|
---|
47 | #include <stdio.h>
|
---|
48 | #include <stdlib.h>
|
---|
49 | #include <stdarg.h>
|
---|
50 | #include <string.h>
|
---|
51 | #include <t_syslog.h>
|
---|
52 | #include "echonet.h"
|
---|
53 | #include "echonet_fbs.h"
|
---|
54 | #include "echonet_agent.h"
|
---|
55 | #include "echonet_task.h"
|
---|
56 | #include "echonet_lcl_task.h"
|
---|
57 |
|
---|
58 | extern bool_t g_forward_esv;
|
---|
59 |
|
---|
60 | typedef struct ecn_agent_buffer
|
---|
61 | {
|
---|
62 | union{
|
---|
63 | struct ecn_agent_buffer *free;
|
---|
64 | ecn_agent_queue_t queue;
|
---|
65 | };
|
---|
66 | union{
|
---|
67 | ecn_obj_t obj;
|
---|
68 | ecn_node_t node;
|
---|
69 | ecn_device_t device;
|
---|
70 | };
|
---|
71 | } ecn_agent_buffer_t;
|
---|
72 |
|
---|
73 | typedef struct ecn_agent
|
---|
74 | {
|
---|
75 | EPRPINIB eprpinib;
|
---|
76 | ecn_agent_queue_t nodes;
|
---|
77 | ecn_node_t *current_node;
|
---|
78 | bool_t msg_proced;
|
---|
79 | int blkpos;
|
---|
80 | ecn_agent_buffer_t *free;
|
---|
81 | ecn_agent_buffer_t blockes[TNUM_AEOBJID];
|
---|
82 | int requestid;
|
---|
83 | } ecn_agent_t;
|
---|
84 |
|
---|
85 | static ER ecn_agent_proc_get_device_list(ecn_agent_t *agent, ECN_FBS_ID req);
|
---|
86 | static ER ecn_agent_proc_get_device_info(ecn_agent_t *agent, ECN_FBS_ID req);
|
---|
87 | static void ecn_node_send_set_prop_map(ecn_node_t *node);
|
---|
88 | static void ecn_node_send_get_prop_map(ecn_node_t *node);
|
---|
89 | static void ecn_node_send_anno_prop_map(ecn_node_t *node);
|
---|
90 | static void ecn_node_timeout_on_start(ecn_node_t *node);
|
---|
91 | static void ecn_node_next_proc_on_set_prpmap_wait(ecn_node_t *node, ecn_obj_t *sobj);
|
---|
92 | static void ecn_node_timeout_on_set_prpmap_wait(ecn_node_t *node);
|
---|
93 | static void ecn_node_next_proc_on_get_prpmap_wait(ecn_node_t *node, ecn_obj_t *sobj);
|
---|
94 | static void ecn_node_timeout_on_get_prpmap_wait(ecn_node_t *node);
|
---|
95 | static void ecn_node_next_proc_on_anno_prpmap_wait(ecn_node_t *node, ecn_obj_t *sobj);
|
---|
96 | static void ecn_node_timeout_on_anno_prpmap_wait(ecn_node_t *node);
|
---|
97 |
|
---|
98 | int ecn_agent_eprpset(const EPRPINIB *item, const void *src, int size, bool_t *anno);
|
---|
99 | int ecn_agent_eprpget(const EPRPINIB *item, void *dst, int size);
|
---|
100 |
|
---|
101 | static ecn_agent_queue_t *cast_queue(ecn_obj_t *obj)
|
---|
102 | {
|
---|
103 | return (ecn_agent_queue_t *)((intptr_t)obj - offsetof(ecn_agent_buffer_t, obj));
|
---|
104 | }
|
---|
105 |
|
---|
106 | static ecn_obj_t *cast_obj(ecn_agent_queue_t *queue)
|
---|
107 | {
|
---|
108 | return (ecn_obj_t *)((intptr_t)queue + offsetof(ecn_agent_buffer_t, obj));
|
---|
109 | }
|
---|
110 |
|
---|
111 | static ecn_node_t *cast_node(const EOBJCB *eobj)
|
---|
112 | {
|
---|
113 | return (ecn_node_t *)((intptr_t)eobj - offsetof(ecn_node_t, eobj));
|
---|
114 | }
|
---|
115 |
|
---|
116 | static ecn_obj_t *cast_obj2(const EOBJINIB *inib)
|
---|
117 | {
|
---|
118 | return (ecn_obj_t *)((intptr_t)inib - offsetof(ecn_obj_t, inib));
|
---|
119 | }
|
---|
120 |
|
---|
121 | static ecn_agent_t *cast_agent(const EPRPINIB *inib)
|
---|
122 | {
|
---|
123 | return (ecn_agent_t *)((intptr_t)inib - offsetof(ecn_agent_t, eprpinib));
|
---|
124 | }
|
---|
125 |
|
---|
126 | ecn_agent_t g_ecn_agent = {
|
---|
127 | /*eprpinib*/{
|
---|
128 | 0x00,
|
---|
129 | EPC_RULE_SET | EPC_RULE_GET,
|
---|
130 | 255,
|
---|
131 | (intptr_t)&g_ecn_agent,
|
---|
132 | ecn_agent_eprpset,
|
---|
133 | ecn_agent_eprpget
|
---|
134 | },
|
---|
135 | };
|
---|
136 |
|
---|
137 | ER get_buf(ecn_agent_t *agent, ecn_agent_buffer_t **buf)
|
---|
138 | {
|
---|
139 | ER ret = E_OK;
|
---|
140 |
|
---|
141 | loc_cpu();
|
---|
142 |
|
---|
143 | if (agent->blkpos < TNUM_AEOBJID) {
|
---|
144 | *buf = &agent->blockes[agent->blkpos++];
|
---|
145 | }
|
---|
146 | else if (agent->free == NULL) {
|
---|
147 | ret = E_TMOUT;
|
---|
148 | }
|
---|
149 | else{
|
---|
150 | *buf = agent->free;
|
---|
151 | agent->free = agent->free->free;
|
---|
152 | }
|
---|
153 |
|
---|
154 | unl_cpu();
|
---|
155 |
|
---|
156 | return ret;
|
---|
157 | }
|
---|
158 |
|
---|
159 | ER rel_buf(ecn_agent_t *agent, ecn_agent_buffer_t *buf)
|
---|
160 | {
|
---|
161 | if ((buf < &agent->blockes[0]) || (buf >= &agent->blockes[TNUM_AEOBJID]))
|
---|
162 | return E_PAR;
|
---|
163 |
|
---|
164 | if ((((intptr_t)buf - (intptr_t)&agent->blockes[0]) % sizeof(ecn_agent_buffer_t)) != 0)
|
---|
165 | return E_PAR;
|
---|
166 |
|
---|
167 | loc_cpu();
|
---|
168 |
|
---|
169 | if (agent->free == NULL) {
|
---|
170 | agent->free = buf;
|
---|
171 | agent->free->free = NULL;
|
---|
172 | }
|
---|
173 | else {
|
---|
174 | ecn_agent_buffer_t *next = agent->free;
|
---|
175 | agent->free = buf;
|
---|
176 | agent->free->free = next;
|
---|
177 | }
|
---|
178 |
|
---|
179 | unl_cpu();
|
---|
180 |
|
---|
181 | return E_OK;
|
---|
182 | }
|
---|
183 |
|
---|
184 | /*
|
---|
185 | * L
|
---|
186 | [Ìú»
|
---|
187 | *
|
---|
188 | * p_queueÉÍL
|
---|
189 | [wb_ðwè·éD
|
---|
190 | */
|
---|
191 | Inline void
|
---|
192 | ecn_agent_queue_init(ecn_agent_queue_t *p_queue)
|
---|
193 | {
|
---|
194 | #ifdef _DEBUG
|
---|
195 | p_queue->p_parent = p_queue;
|
---|
196 | #endif
|
---|
197 | p_queue->p_prev = p_queue;
|
---|
198 | p_queue->p_next = p_queue;
|
---|
199 | }
|
---|
200 |
|
---|
201 | /*
|
---|
202 | * L
|
---|
203 | [ÌOGgÖÌ}ü
|
---|
204 | *
|
---|
205 | * p_queueÌOÉp_entryð}ü·éDp_queueÉL
|
---|
206 | [wb_ðwèµ½ê
|
---|
207 | * ÉÍCL
|
---|
208 | [ÌöÉp_entryð}ü·é±ÆÉÈéD
|
---|
209 | */
|
---|
210 | Inline void
|
---|
211 | ecn_agent_queue_add(ecn_agent_queue_t *p_queue, ecn_agent_queue_t *p_entry)
|
---|
212 | {
|
---|
213 | #ifdef _DEBUG
|
---|
214 | assert((p_queue->p_parent == p_queue) && (p_entry->p_parent == NULL));
|
---|
215 | p_entry->p_parent = p_queue;
|
---|
216 | #endif
|
---|
217 | p_entry->p_prev = p_queue->p_prev;
|
---|
218 | p_entry->p_next = p_queue;
|
---|
219 | p_queue->p_prev->p_next = p_entry;
|
---|
220 | p_queue->p_prev = p_entry;
|
---|
221 | }
|
---|
222 |
|
---|
223 | /*
|
---|
224 | * GgÌí
|
---|
225 | *
|
---|
226 | * p_entryðL
|
---|
227 | [©çí·éD
|
---|
228 | */
|
---|
229 | Inline void
|
---|
230 | ecn_agent_queue_remove(ecn_agent_queue_t *p_queue, ecn_agent_queue_t *p_entry)
|
---|
231 | {
|
---|
232 | #ifdef _DEBUG
|
---|
233 | assert((p_queue->p_parent == p_queue) && (p_entry->p_parent == p_queue));
|
---|
234 | p_entry->p_parent = NULL;
|
---|
235 | #endif
|
---|
236 | p_entry->p_prev->p_next = p_entry->p_next;
|
---|
237 | p_entry->p_next->p_prev = p_entry->p_prev;
|
---|
238 | }
|
---|
239 |
|
---|
240 | ecn_node_t *ecn_agent_find_node(ECN_ENOD_ID enodid)
|
---|
241 | {
|
---|
242 | ecn_agent_t *agent = &g_ecn_agent;
|
---|
243 | ecn_agent_queue_t *queue = agent->nodes.p_next;
|
---|
244 | #ifdef _DEBUG
|
---|
245 | assert(queue->p_parent == &agent->nodes);
|
---|
246 | #endif
|
---|
247 | for (; queue != &agent->nodes; queue = queue->p_next) {
|
---|
248 | ecn_node_t *node = (ecn_node_t *)cast_obj(queue);
|
---|
249 | if(node->enodId == enodid)
|
---|
250 | return node;
|
---|
251 | }
|
---|
252 |
|
---|
253 | return NULL;
|
---|
254 | }
|
---|
255 |
|
---|
256 | ecn_node_t *ecn_agent_find_node2(const EOBJCB *pk_eobj)
|
---|
257 | {
|
---|
258 | ecn_agent_t *agent = &g_ecn_agent;
|
---|
259 | ecn_agent_queue_t *queue;
|
---|
260 |
|
---|
261 | if(pk_eobj == NULL)
|
---|
262 | return NULL;
|
---|
263 |
|
---|
264 | queue = agent->nodes.p_next;
|
---|
265 | #ifdef _DEBUG
|
---|
266 | assert(queue->p_parent == &agent->nodes);
|
---|
267 | #endif
|
---|
268 | for (; queue != &agent->nodes; queue = queue->p_next) {
|
---|
269 | ecn_node_t *node = (ecn_node_t *)cast_obj(queue);
|
---|
270 | if(&node->eobj == pk_eobj)
|
---|
271 | return node;
|
---|
272 | }
|
---|
273 |
|
---|
274 | return NULL;
|
---|
275 | }
|
---|
276 |
|
---|
277 | ecn_obj_t *ecn_agent_find_eobj(const EOBJCB *pk_nod, T_ECN_EOJ eoj)
|
---|
278 | {
|
---|
279 | ecn_agent_queue_t *devices = &cast_node(pk_nod)->devices;
|
---|
280 | ecn_agent_queue_t *queue = devices->p_next;
|
---|
281 | #ifdef _DEBUG
|
---|
282 | assert(queue->p_parent == devices);
|
---|
283 | #endif
|
---|
284 | for (; queue != devices; queue = queue->p_next) {
|
---|
285 | ecn_obj_t *obj = cast_obj(queue);
|
---|
286 | if (obj->inib.eojx1 != eoj.eojx1)
|
---|
287 | continue;
|
---|
288 | if (obj->inib.eojx2 != eoj.eojx2)
|
---|
289 | continue;
|
---|
290 | if (obj->inib.eojx3 != eoj.eojx3)
|
---|
291 | continue;
|
---|
292 |
|
---|
293 | return obj;
|
---|
294 | }
|
---|
295 |
|
---|
296 | return NULL;
|
---|
297 | }
|
---|
298 |
|
---|
299 | ecn_obj_t *ecn_agent_find_obj2(ecn_node_t *pk_nod, const EOBJINIB *pk_obj)
|
---|
300 | {
|
---|
301 | ecn_agent_queue_t *devices = &pk_nod->devices;
|
---|
302 | ecn_agent_queue_t *queue = devices->p_next;
|
---|
303 | #ifdef _DEBUG
|
---|
304 | assert(queue->p_parent == devices);
|
---|
305 | #endif
|
---|
306 | for (; queue != devices; queue = queue->p_next) {
|
---|
307 | ecn_obj_t *obj = cast_obj(queue);
|
---|
308 | if (&obj->inib == pk_obj)
|
---|
309 | return obj;
|
---|
310 | }
|
---|
311 |
|
---|
312 | return NULL;
|
---|
313 | }
|
---|
314 |
|
---|
315 | ID ecn_agent_get_eobj(const EOBJINIB *pk_obj)
|
---|
316 | {
|
---|
317 | return cast_obj2(pk_obj)->eobjId;
|
---|
318 | }
|
---|
319 |
|
---|
320 | const EOBJINIB *ecn_agent_next_eobj(const EOBJCB *pk_nod, const EOBJINIB *pk_obj)
|
---|
321 | {
|
---|
322 | ecn_agent_queue_t *devices = &cast_node(pk_nod)->devices;
|
---|
323 | ecn_obj_t *device = (ecn_obj_t *)pk_obj->exinf;
|
---|
324 | ecn_agent_queue_t *queue = cast_queue(device);
|
---|
325 | #ifdef _DEBUG
|
---|
326 | assert(queue->p_parent == devices);
|
---|
327 | #endif
|
---|
328 | if (queue == devices)
|
---|
329 | return NULL;
|
---|
330 |
|
---|
331 | return &cast_obj(queue->p_next)->inib;
|
---|
332 | }
|
---|
333 |
|
---|
334 | bool_t ecn_agent_get_eoj_enodid(ID eobjid, T_ECN_EOJ *eoj, ECN_ENOD_ID *enodid)
|
---|
335 | {
|
---|
336 | ecn_agent_t *agent = &g_ecn_agent;
|
---|
337 | ecn_agent_buffer_t *buf;
|
---|
338 | int i = eobjid;
|
---|
339 |
|
---|
340 | /* IuWFNgID©çÀÌðæ¾ */
|
---|
341 | i -= (tmax_eobjid + 1);
|
---|
342 | if ((i < 0)
|
---|
343 | || (i >= (sizeof(agent->blockes) / sizeof(agent->blockes[0])))){
|
---|
344 | return false;
|
---|
345 | }
|
---|
346 |
|
---|
347 | buf = &agent->blockes[i];
|
---|
348 | if(buf->obj.eobjId != eobjid)
|
---|
349 | return false;
|
---|
350 |
|
---|
351 | /* IuWFNgÌEOJðRs[ */
|
---|
352 | memcpy(eoj, &buf->obj.inib.eojx1, sizeof(*eoj));
|
---|
353 |
|
---|
354 | /* ®·ém[hÌIuWFNgIDðæ¾ */
|
---|
355 | if(buf->obj.inib.enodid == 0)
|
---|
356 | i = buf->obj.eobjId;
|
---|
357 | else
|
---|
358 | i = buf->obj.inib.enodid;
|
---|
359 |
|
---|
360 | i -= (tmax_eobjid + 1);
|
---|
361 | if ((i < 0)
|
---|
362 | || (i >= (sizeof(agent->blockes) / sizeof(agent->blockes[0])))){
|
---|
363 | return false;
|
---|
364 | }
|
---|
365 |
|
---|
366 | /* m[hIDðæ¾ */
|
---|
367 | buf = &agent->blockes[i];
|
---|
368 | *enodid = buf->node.enodId;
|
---|
369 |
|
---|
370 | return true;
|
---|
371 | }
|
---|
372 |
|
---|
373 | void ecn_agent_set_epc_to_prop_map(uint8_t epc, uint8_t *propMap)
|
---|
374 | {
|
---|
375 | int i, j;
|
---|
376 | assert((epc & 0x80) != 0);
|
---|
377 | i = epc & 0xF;
|
---|
378 | j = (epc >> 4) - 8;
|
---|
379 | propMap[i] |= (1 << j);
|
---|
380 | }
|
---|
381 |
|
---|
382 | bool_t ecn_agent_contains_epc_in_prop_map(uint8_t epc, uint8_t *propMap)
|
---|
383 | {
|
---|
384 | int i, j;
|
---|
385 | assert((epc & 0x80) != 0);
|
---|
386 | i = epc & 0xF;
|
---|
387 | j = (epc >> 4) - 8;
|
---|
388 | return (propMap[i] & (1 << j)) != 0;
|
---|
389 | }
|
---|
390 |
|
---|
391 | void ecn_agent_init(void)
|
---|
392 | {
|
---|
393 | ecn_agent_queue_init(&g_ecn_agent.nodes);
|
---|
394 | }
|
---|
395 |
|
---|
396 | ecn_node_t *ecn_agent_create_node(ecn_agent_t *agent, T_EDATA *esv)
|
---|
397 | {
|
---|
398 | ecn_agent_buffer_t *result = NULL;
|
---|
399 | ecn_node_t *node;
|
---|
400 | uint8_t epc;
|
---|
401 | uint8_t pdc;
|
---|
402 | uint8_t edt[256];
|
---|
403 | T_ENUM_EPC enm;
|
---|
404 | ER ret;
|
---|
405 | T_ECN_EOJ *eoj, *end;
|
---|
406 |
|
---|
407 | // vpeBÊm©æ¾ÅA
|
---|
408 | switch (esv->hdr.edata.esv) {
|
---|
409 | case ESV_GET_RES:
|
---|
410 | case ESV_GET_SNA:
|
---|
411 | case ESV_INF:
|
---|
412 | break;
|
---|
413 | default:
|
---|
414 | return NULL;
|
---|
415 | }
|
---|
416 |
|
---|
417 | // m[hvt@C¶Ìê
|
---|
418 | eoj = &esv->hdr.edata.seoj;
|
---|
419 | if ((eoj->eojx1 != EOJ_X1_PROFILE) || (eoj->eojx2 != EOJ_X2_NODE_PROFILE)
|
---|
420 | || (eoj->eojx3 != 0x01))
|
---|
421 | return NULL;
|
---|
422 |
|
---|
423 | ret = ecn_itr_ini(&enm, esv);
|
---|
424 | if(ret != E_OK){
|
---|
425 | syslog(LOG_WARNING, "ecn_itr_ini");
|
---|
426 | }
|
---|
427 |
|
---|
428 | while (ecn_itr_nxt(&enm, &epc, &pdc, &edt) == E_OK) {
|
---|
429 | switch (epc) {
|
---|
430 | // CX^XXgÊmÌê
|
---|
431 | case 0xD5:
|
---|
432 | // ©m[hCX^XXgrÊmÌê
|
---|
433 | case 0xD6:
|
---|
434 | // TCYªíÈ¢ê
|
---|
435 | if (pdc != (1 + edt[0] * sizeof(T_ECN_EOJ)))
|
---|
436 | return NULL;
|
---|
437 |
|
---|
438 | ret = get_buf(agent, &result);
|
---|
439 | if(ret != E_OK){
|
---|
440 | syslog(LOG_WARNING, "get_buf");
|
---|
441 | return NULL;
|
---|
442 | }
|
---|
443 |
|
---|
444 | memset(result, 0, sizeof(*result));
|
---|
445 | node = &result->node;
|
---|
446 | node->enodId = ((T_ECN_FST_BLK *)esv)->hdr.sender;
|
---|
447 | node->base.eobjId = tmax_eobjid + 1 + (((intptr_t)result - (intptr_t)agent->blockes) / sizeof(agent->blockes[0]));
|
---|
448 | node->base.inib.enodid = 0;
|
---|
449 | node->base.inib.eobjatr = EOBJ_SYNC_REMOTE_NODE;
|
---|
450 | node->base.inib.exinf = (intptr_t)node;
|
---|
451 | node->base.inib.eojx1 = eoj->eojx1;
|
---|
452 | node->base.inib.eojx2 = eoj->eojx2;
|
---|
453 | node->base.inib.eojx3 = eoj->eojx3;
|
---|
454 | node->base.inib.eprp = &agent->eprpinib;
|
---|
455 | node->base.inib.eprpcnt = 0;
|
---|
456 | ecn_agent_set_epc_to_prop_map(0xD5, node->base.pmapGet);
|
---|
457 | ecn_agent_set_epc_to_prop_map(0xD6, node->base.pmapGet);
|
---|
458 | ecn_agent_set_epc_to_prop_map(0x9D, node->base.pmapGet);
|
---|
459 | ecn_agent_set_epc_to_prop_map(0x9E, node->base.pmapGet);
|
---|
460 | ecn_agent_set_epc_to_prop_map(0x9F, node->base.pmapGet);
|
---|
461 | ecn_agent_queue_init(&node->devices);
|
---|
462 | node->eobj.profile = &node->base.inib;
|
---|
463 | node->eobj.eobjs = NULL;
|
---|
464 | node->eobj.eobjcnt = pdc / 3;
|
---|
465 | node->state = ecn_node_state_idle;
|
---|
466 | node->timer = TMO_FEVR;
|
---|
467 |
|
---|
468 | end = (T_ECN_EOJ *)&edt[pdc];
|
---|
469 | for (eoj = (T_ECN_EOJ *)&edt[1]; eoj < end; eoj++) {
|
---|
470 | ecn_device_t *device;
|
---|
471 | ecn_agent_buffer_t *obj;
|
---|
472 |
|
---|
473 | ret = get_buf(agent, &obj);
|
---|
474 | if(ret != E_OK){
|
---|
475 | syslog(LOG_WARNING, "get_buf");
|
---|
476 | return NULL;
|
---|
477 | }
|
---|
478 |
|
---|
479 | memset(obj, 0, sizeof(*obj));
|
---|
480 | device = &obj->device;
|
---|
481 | device->node = node;
|
---|
482 | device->base.eobjId = tmax_eobjid + 1 + (((intptr_t)obj - (intptr_t)agent->blockes) / sizeof(agent->blockes[0]));
|
---|
483 | device->base.inib.eobjatr = EOBJ_DEVICE;
|
---|
484 | device->base.inib.enodid = node->base.eobjId;
|
---|
485 | device->base.inib.exinf = (intptr_t)device;
|
---|
486 | device->base.inib.eojx1 = eoj->eojx1;
|
---|
487 | device->base.inib.eojx2 = eoj->eojx2;
|
---|
488 | device->base.inib.eojx3 = eoj->eojx3;
|
---|
489 | device->base.inib.eprp = &agent->eprpinib;
|
---|
490 | device->base.inib.eprpcnt = 0;
|
---|
491 | ecn_agent_set_epc_to_prop_map(0x9D, device->base.pmapGet);
|
---|
492 | ecn_agent_set_epc_to_prop_map(0x9E, device->base.pmapGet);
|
---|
493 | ecn_agent_set_epc_to_prop_map(0x9F, device->base.pmapGet);
|
---|
494 |
|
---|
495 | ecn_agent_queue_add(&node->devices, &obj->queue);
|
---|
496 | }
|
---|
497 | break;
|
---|
498 | default:
|
---|
499 | continue;
|
---|
500 | }
|
---|
501 | break;
|
---|
502 | }
|
---|
503 |
|
---|
504 | if (result == NULL)
|
---|
505 | return NULL;
|
---|
506 |
|
---|
507 | ecn_agent_queue_add(&agent->nodes, &result->queue);
|
---|
508 |
|
---|
509 | return node;
|
---|
510 | }
|
---|
511 |
|
---|
512 | static ER ecn_agent_proc_get_device_list(ecn_agent_t *agent, ECN_FBS_ID req)
|
---|
513 | {
|
---|
514 | ER ret;
|
---|
515 | ECN_FBS_ID res;
|
---|
516 | ecn_inm_get_device_list_req_t msg;
|
---|
517 | ECN_FBS_SSIZE_T len;
|
---|
518 | ecn_agent_buffer_t *pos, *end = &agent->blockes[TNUM_AEOBJID];
|
---|
519 | ecn_inm_get_device_item_t item;
|
---|
520 | int i, j;
|
---|
521 |
|
---|
522 | ret = _ecn_fbs_get_data(req, &msg, sizeof(msg), &len);
|
---|
523 | if (ret != E_OK) {
|
---|
524 | return ret;
|
---|
525 | }
|
---|
526 |
|
---|
527 | ret = _ecn_tsk_cre_res_fbs(req, ECN_INM_GET_DEVICE_LIST_RES, &res);
|
---|
528 | if (ret != E_OK) {
|
---|
529 | return ret;
|
---|
530 | }
|
---|
531 |
|
---|
532 | ret = _ecn_fbs_add_data_ex(res, &msg.requestid, sizeof(((ecn_inm_get_device_list_res_t *)0)->requestid));
|
---|
533 | if (ret != E_OK) {
|
---|
534 | _ecn_fbs_del(res);
|
---|
535 | return ret;
|
---|
536 | }
|
---|
537 |
|
---|
538 | for (i = 0; i < tnum_enodid; i++) {
|
---|
539 | const EOBJCB *enod = &eobjcb_table[i];
|
---|
540 | for (j = 0; j < enod->eobjcnt; j++) {
|
---|
541 | const EOBJINIB *eobj = enod->eobjs[i];
|
---|
542 | item.eobjid = 1 + (((intptr_t)eobj - (intptr_t)eobjinib_table) / sizeof(EOBJINIB));
|
---|
543 | item.enodid = eobj->enodid;
|
---|
544 | item.state = true;
|
---|
545 | item.eojx1 = eobj->eojx1;
|
---|
546 | item.eojx2 = eobj->eojx2;
|
---|
547 | item.eojx3 = eobj->eojx3;
|
---|
548 | item.addrid = (i == 0) ? ENOD_LOCAL_ID : (ENOD_REMOTE_ID + i);
|
---|
549 |
|
---|
550 | ret = _ecn_fbs_add_data_ex(res, &item, sizeof(item));
|
---|
551 | if (ret != E_OK) {
|
---|
552 | _ecn_fbs_del(res);
|
---|
553 | return ret;
|
---|
554 | }
|
---|
555 | }
|
---|
556 | }
|
---|
557 |
|
---|
558 | for (pos = &agent->blockes[0]; pos < end; pos++){
|
---|
559 | if(pos->obj.eobjId == 0)
|
---|
560 | continue;
|
---|
561 |
|
---|
562 | item.eobjid = pos->obj.eobjId;
|
---|
563 | item.enodid = pos->obj.inib.enodid;
|
---|
564 | item.state = (pos->obj.pmapFlag & (PMAP_FLAG_SET | PMAP_FLAG_GET | PMAP_FLAG_ANNO))
|
---|
565 | == (PMAP_FLAG_SET | PMAP_FLAG_GET | PMAP_FLAG_ANNO);
|
---|
566 | item.eojx1 = pos->obj.inib.eojx1;
|
---|
567 | item.eojx2 = pos->obj.inib.eojx2;
|
---|
568 | item.eojx3 = pos->obj.inib.eojx3;
|
---|
569 |
|
---|
570 | if(pos->device.node != NULL)
|
---|
571 | item.addrid = pos->device.node->enodId;
|
---|
572 | else
|
---|
573 | item.addrid = pos->node.enodId;
|
---|
574 |
|
---|
575 | ret = _ecn_fbs_add_data_ex(res, &item, sizeof(item));
|
---|
576 | if (ret != E_OK) {
|
---|
577 | _ecn_fbs_del(res);
|
---|
578 | return ret;
|
---|
579 | }
|
---|
580 | }
|
---|
581 |
|
---|
582 | ret = psnd_dtq(res.ptr->hdr.target_mbxid, (intptr_t)res.ptr);
|
---|
583 | if (ret != E_OK) {
|
---|
584 | _ecn_fbs_del(res);
|
---|
585 | return ret;
|
---|
586 | }
|
---|
587 |
|
---|
588 | return E_OK;
|
---|
589 | }
|
---|
590 |
|
---|
591 | static ER ecn_agent_proc_get_device_info(ecn_agent_t *agent, ECN_FBS_ID req)
|
---|
592 | {
|
---|
593 | ER ret;
|
---|
594 | ECN_FBS_ID res;
|
---|
595 | ecn_inm_get_device_info_req_t msg;
|
---|
596 | ecn_inm_get_device_info_res_t rmsg;
|
---|
597 | ECN_FBS_SSIZE_T len;
|
---|
598 |
|
---|
599 | ret = _ecn_fbs_get_data(req, &msg, sizeof(msg), &len);
|
---|
600 | if (ret != E_OK) {
|
---|
601 | return ret;
|
---|
602 | }
|
---|
603 |
|
---|
604 | memset(&rmsg, 0, sizeof(rmsg));
|
---|
605 |
|
---|
606 | if (msg.eobjid <= tmax_eobjid) {
|
---|
607 | const EOBJINIB *eobj = &eobjinib_table[msg.eobjid - 1];
|
---|
608 | int i;
|
---|
609 |
|
---|
610 | rmsg.requestid = msg.requestid;
|
---|
611 | rmsg.eobjid = msg.eobjid;
|
---|
612 | for (i = 0; i < eobj->eprpcnt; i++) {
|
---|
613 | uint8_t epc = eobj->eprp[i].eprpcd;
|
---|
614 | ecn_agent_set_epc_to_prop_map(epc, rmsg.pmapSet);
|
---|
615 | ecn_agent_set_epc_to_prop_map(epc, rmsg.pmapGet);
|
---|
616 | ecn_agent_set_epc_to_prop_map(epc, rmsg.pmapAnno);
|
---|
617 | }
|
---|
618 | rmsg.eprpcnt = eobj->eprpcnt;
|
---|
619 | }
|
---|
620 | else {
|
---|
621 | int eobjId;
|
---|
622 | ecn_agent_buffer_t *pos;
|
---|
623 |
|
---|
624 | eobjId = msg.eobjid - tmax_eobjid - 1;
|
---|
625 | pos = &agent->blockes[eobjId];
|
---|
626 |
|
---|
627 | rmsg.requestid = msg.requestid;
|
---|
628 | rmsg.eobjid = pos->obj.eobjId;
|
---|
629 | memcpy(rmsg.pmapSet, pos->obj.pmapSet, sizeof(rmsg.pmapSet));
|
---|
630 | memcpy(rmsg.pmapGet, pos->obj.pmapGet, sizeof(rmsg.pmapGet));
|
---|
631 | memcpy(rmsg.pmapAnno, pos->obj.pmapAnno, sizeof(rmsg.pmapAnno));
|
---|
632 | rmsg.eprpcnt = pos->obj.eprpcnt;
|
---|
633 | }
|
---|
634 |
|
---|
635 | ret = _ecn_tsk_cre_res_fbs(req, ECN_INM_GET_DEVICE_INFO_RES, &res);
|
---|
636 | if (ret != E_OK) {
|
---|
637 | return ret;
|
---|
638 | }
|
---|
639 |
|
---|
640 | ret = _ecn_fbs_add_data_ex(res, &rmsg, sizeof(rmsg));
|
---|
641 | if (ret != E_OK) {
|
---|
642 | _ecn_fbs_del(res);
|
---|
643 | return ret;
|
---|
644 | }
|
---|
645 |
|
---|
646 | ret = psnd_dtq(res.ptr->hdr.target_mbxid, (intptr_t)res.ptr);
|
---|
647 | if (ret != E_OK) {
|
---|
648 | _ecn_fbs_del(res);
|
---|
649 | return ret;
|
---|
650 | }
|
---|
651 |
|
---|
652 | return E_OK;
|
---|
653 | }
|
---|
654 |
|
---|
655 | TMO ecn_agent_get_timer()
|
---|
656 | {
|
---|
657 | TMO timer = TMO_FEVR, temp;
|
---|
658 | ecn_agent_t *agent = &g_ecn_agent;
|
---|
659 | ecn_node_t *node;
|
---|
660 | ecn_agent_queue_t *queue;
|
---|
661 |
|
---|
662 | queue = &agent->nodes;
|
---|
663 | for (;;) {
|
---|
664 | queue = queue->p_next;
|
---|
665 | #ifdef _DEBUG
|
---|
666 | assert(queue->p_parent == &agent->nodes);
|
---|
667 | #endif
|
---|
668 | if(&agent->nodes == queue)
|
---|
669 | break;
|
---|
670 |
|
---|
671 | node = (ecn_node_t *)cast_obj(queue);
|
---|
672 | temp = node->timer;
|
---|
673 | if (temp != TMO_FEVR) {
|
---|
674 | if ((timer == TMO_FEVR) || (temp < timer)) {
|
---|
675 | timer = temp;
|
---|
676 | }
|
---|
677 | }
|
---|
678 | }
|
---|
679 |
|
---|
680 | return timer;
|
---|
681 | }
|
---|
682 |
|
---|
683 | void ecn_agent_progress(TMO interval)
|
---|
684 | {
|
---|
685 | ecn_agent_t *agent = &g_ecn_agent;
|
---|
686 | ecn_node_t *node;
|
---|
687 | ecn_agent_queue_t *queue;
|
---|
688 |
|
---|
689 | queue = &agent->nodes;
|
---|
690 | for (;;) {
|
---|
691 | queue = queue->p_next;
|
---|
692 | #ifdef _DEBUG
|
---|
693 | assert(queue->p_parent == &agent->nodes);
|
---|
694 | #endif
|
---|
695 | if(&agent->nodes == queue)
|
---|
696 | break;
|
---|
697 |
|
---|
698 | node = (ecn_node_t *)cast_obj(queue);
|
---|
699 | if (node->timer == TMO_FEVR)
|
---|
700 | continue;
|
---|
701 |
|
---|
702 | node->timer -= interval;
|
---|
703 | if (node->timer <= 0) {
|
---|
704 | node->timer = 0;
|
---|
705 | }
|
---|
706 | }
|
---|
707 | }
|
---|
708 |
|
---|
709 | void ecn_agent_timeout()
|
---|
710 | {
|
---|
711 | ecn_agent_t *agent = &g_ecn_agent;
|
---|
712 | ecn_node_t *node;
|
---|
713 | ecn_agent_queue_t *queue;
|
---|
714 |
|
---|
715 | queue = &agent->nodes;
|
---|
716 | for (;;) {
|
---|
717 | queue = queue->p_next;
|
---|
718 | #ifdef _DEBUG
|
---|
719 | assert(queue->p_parent == &agent->nodes);
|
---|
720 | #endif
|
---|
721 | if(&agent->nodes == queue)
|
---|
722 | break;
|
---|
723 |
|
---|
724 | node = (ecn_node_t *)cast_obj(queue);
|
---|
725 | if (node->timer != 0)
|
---|
726 | continue;
|
---|
727 |
|
---|
728 | switch (node->state) {
|
---|
729 | case ecn_node_state_start:
|
---|
730 | ecn_node_timeout_on_start(node);
|
---|
731 | break;
|
---|
732 | case ecn_node_state_set_prpmap_wait:
|
---|
733 | ecn_node_timeout_on_set_prpmap_wait(node);
|
---|
734 | break;
|
---|
735 | case ecn_node_state_get_prpmap_wait:
|
---|
736 | ecn_node_timeout_on_get_prpmap_wait(node);
|
---|
737 | break;
|
---|
738 | case ecn_node_state_anno_prpmap_wait:
|
---|
739 | ecn_node_timeout_on_anno_prpmap_wait(node);
|
---|
740 | break;
|
---|
741 | case ecn_node_state_fault:
|
---|
742 | ecn_node_timeout_on_start(node);
|
---|
743 | break;
|
---|
744 | default:
|
---|
745 | assert(0);
|
---|
746 | }
|
---|
747 | }
|
---|
748 | }
|
---|
749 |
|
---|
750 | bool_t ecn_agent_proc_int_msg(ECN_FBS_ID fbs, uint8_t cmd)
|
---|
751 | {
|
---|
752 | ecn_agent_t *agent = &g_ecn_agent;
|
---|
753 |
|
---|
754 | switch(cmd)
|
---|
755 | {
|
---|
756 | case ECN_INM_GET_DEVICE_LIST_REQ:
|
---|
757 | ecn_agent_proc_get_device_list(agent, fbs);
|
---|
758 | break;
|
---|
759 | case ECN_INM_GET_DEVICE_INFO_REQ:
|
---|
760 | ecn_agent_proc_get_device_info(agent, fbs);
|
---|
761 | break;
|
---|
762 | default:
|
---|
763 | return false;
|
---|
764 | }
|
---|
765 |
|
---|
766 | return true;
|
---|
767 | }
|
---|
768 |
|
---|
769 | void ecn_agent_proc_ecn_msg(const EOBJCB **ppk_snod, const EOBJINIB **ppk_sobj, T_EDATA *esv)
|
---|
770 | {
|
---|
771 | ecn_agent_t *agent = &g_ecn_agent;
|
---|
772 | ecn_node_t *snod;
|
---|
773 | ecn_obj_t *sobj;
|
---|
774 |
|
---|
775 | /* ÃIÉè`³ê½M³Ìê */
|
---|
776 | if ((*ppk_snod != NULL) && (*ppk_snod)->eobjs != NULL) {
|
---|
777 | /* µÈ¢ */
|
---|
778 | return;
|
---|
779 | }
|
---|
780 |
|
---|
781 | snod = ecn_agent_find_node2(*ppk_snod);
|
---|
782 |
|
---|
783 | /* M³ðmçÈ©Á½ç */
|
---|
784 | if (snod == NULL) {
|
---|
785 | /* M³Ìm[hîñðVKÉì¬ */
|
---|
786 | snod = ecn_agent_create_node(agent, esv);
|
---|
787 | if (snod == NULL)
|
---|
788 | return;
|
---|
789 | }
|
---|
790 |
|
---|
791 | sobj = ecn_agent_find_obj2(snod, *ppk_sobj);
|
---|
792 |
|
---|
793 | /* m[hvt@CÌê */
|
---|
794 | if ((esv->hdr.edata.seoj.eojx1 == EOJ_X1_PROFILE)
|
---|
795 | && (esv->hdr.edata.seoj.eojx2 == EOJ_X2_NODE_PROFILE)) {
|
---|
796 | sobj = &snod->base;
|
---|
797 | }
|
---|
798 | /* @íIuWFNgÌê */
|
---|
799 | else {
|
---|
800 | sobj = ecn_agent_find_eobj(&snod->eobj, esv->hdr.edata.seoj);
|
---|
801 | }
|
---|
802 |
|
---|
803 | *ppk_snod = &snod->eobj;
|
---|
804 | *ppk_sobj = &sobj->inib;
|
---|
805 |
|
---|
806 | agent->current_node = snod;
|
---|
807 | agent->msg_proced = false;
|
---|
808 | }
|
---|
809 |
|
---|
810 | void ecn_agent_proc_ecn_msg_end()
|
---|
811 | {
|
---|
812 | ecn_agent_t *agent = &g_ecn_agent;
|
---|
813 | ecn_node_t *node = agent->current_node;
|
---|
814 | ecn_obj_t *sobj;
|
---|
815 |
|
---|
816 | if(node == NULL)
|
---|
817 | return;
|
---|
818 |
|
---|
819 | sobj = node->current;
|
---|
820 | if(sobj == NULL)
|
---|
821 | return;
|
---|
822 |
|
---|
823 | if (agent->msg_proced) {
|
---|
824 | switch (node->state) {
|
---|
825 | case ecn_node_state_set_prpmap_wait:
|
---|
826 | ecn_node_next_proc_on_set_prpmap_wait(node, sobj);
|
---|
827 | break;
|
---|
828 | case ecn_node_state_get_prpmap_wait:
|
---|
829 | ecn_node_next_proc_on_get_prpmap_wait(node, sobj);
|
---|
830 | break;
|
---|
831 | case ecn_node_state_anno_prpmap_wait:
|
---|
832 | ecn_node_next_proc_on_anno_prpmap_wait(node, sobj);
|
---|
833 | break;
|
---|
834 | }
|
---|
835 | }
|
---|
836 | }
|
---|
837 |
|
---|
838 | static void ecn_node_send_set_prop_map(ecn_node_t *node)
|
---|
839 | {
|
---|
840 | T_EDATA *esv;
|
---|
841 | ecn_obj_t *obj = node->current;
|
---|
842 |
|
---|
843 | // vpeBlÇÝoµv
|
---|
844 | ecn_esv_get(&esv, obj->eobjId, 0x9E);
|
---|
845 | ecn_snd_esv(esv);
|
---|
846 |
|
---|
847 | node->state = ecn_node_state_set_prpmap_wait;
|
---|
848 | node->timer = (TMO)5000;
|
---|
849 | }
|
---|
850 |
|
---|
851 | static void ecn_node_send_get_prop_map(ecn_node_t *node)
|
---|
852 | {
|
---|
853 | T_EDATA *esv;
|
---|
854 | ecn_obj_t *obj = node->current;
|
---|
855 |
|
---|
856 | // vpeBlÇÝoµv
|
---|
857 | ecn_esv_get(&esv, obj->eobjId, 0x9F);
|
---|
858 | ecn_snd_esv(esv);
|
---|
859 |
|
---|
860 | node->state = ecn_node_state_get_prpmap_wait;
|
---|
861 | node->timer = (TMO)5000;
|
---|
862 | }
|
---|
863 |
|
---|
864 | static void ecn_node_send_anno_prop_map(ecn_node_t *node)
|
---|
865 | {
|
---|
866 | T_EDATA *esv;
|
---|
867 | ecn_obj_t *obj = node->current;
|
---|
868 |
|
---|
869 | // vpeBlÇÝoµv
|
---|
870 | ecn_esv_get(&esv, obj->eobjId, 0x9D);
|
---|
871 | ecn_snd_esv(esv);
|
---|
872 |
|
---|
873 | node->state = ecn_node_state_anno_prpmap_wait;
|
---|
874 | node->timer = (TMO)5000;
|
---|
875 | }
|
---|
876 |
|
---|
877 | static void ecn_node_next_obj(ecn_node_t *node)
|
---|
878 | {
|
---|
879 | ecn_obj_t *obj = node->current;
|
---|
880 | ecn_agent_queue_t *queue;
|
---|
881 | ecn_device_t *device;
|
---|
882 |
|
---|
883 | /* objªwè³êĢȢê */
|
---|
884 | if(obj == NULL){
|
---|
885 | /* ±Ìm[hðÔ· */
|
---|
886 | node->current = &node->base;
|
---|
887 | return;
|
---|
888 | }
|
---|
889 | /* m[hÌê */
|
---|
890 | else if((obj->inib.eojx1 == EOJ_X1_PROFILE) && (obj->inib.eojx2 == EOJ_X2_NODE_PROFILE)){
|
---|
891 | node = (ecn_node_t *)obj;
|
---|
892 |
|
---|
893 | /* zºÌ@íðÔ· */
|
---|
894 | queue = node->devices.p_next;
|
---|
895 | device = (ecn_device_t *)cast_obj(queue);
|
---|
896 | }
|
---|
897 | /* @íÌê */
|
---|
898 | else{
|
---|
899 | /* Ì@íðÔ· */
|
---|
900 | node = ((ecn_device_t *)obj)->node;
|
---|
901 | queue = cast_queue(obj)->p_next;
|
---|
902 | device = (ecn_device_t *)cast_obj(queue);
|
---|
903 | }
|
---|
904 |
|
---|
905 | /* »Ì@íªö¾Á½ê */
|
---|
906 | if(&node->devices == queue){
|
---|
907 | node->current = NULL;
|
---|
908 | }
|
---|
909 | else {
|
---|
910 | node->current = &device->base;
|
---|
911 | }
|
---|
912 | }
|
---|
913 |
|
---|
914 | static void ecn_node_timeout_on_start(ecn_node_t *node)
|
---|
915 | {
|
---|
916 | for (;;) {
|
---|
917 | ecn_obj_t *obj = node->current;
|
---|
918 | if (obj == NULL) {
|
---|
919 | node->state = ecn_node_state_idle;
|
---|
920 | node->timer = TMO_FEVR;
|
---|
921 | return;
|
---|
922 | }
|
---|
923 |
|
---|
924 | if((obj->pmapFlag & PMAP_FLAG_SET) == 0){
|
---|
925 | ecn_node_send_set_prop_map(node);
|
---|
926 | break;
|
---|
927 | }
|
---|
928 | else if((obj->pmapFlag & PMAP_FLAG_GET) == 0){
|
---|
929 | ecn_node_send_get_prop_map(node);
|
---|
930 | break;
|
---|
931 | }
|
---|
932 | else if((obj->pmapFlag & PMAP_FLAG_ANNO) == 0){
|
---|
933 | ecn_node_send_anno_prop_map(node);
|
---|
934 | break;
|
---|
935 | }
|
---|
936 | else{
|
---|
937 | ecn_node_next_obj(node);
|
---|
938 | }
|
---|
939 | }
|
---|
940 | }
|
---|
941 |
|
---|
942 | static void ecn_node_next_proc_on_set_prpmap_wait(ecn_node_t *node, ecn_obj_t *sobj)
|
---|
943 | {
|
---|
944 | if((sobj->pmapFlag & PMAP_FLAG_GET) == 0){
|
---|
945 | ecn_node_send_get_prop_map(node);
|
---|
946 | }
|
---|
947 | else if((sobj->pmapFlag & PMAP_FLAG_ANNO) == 0){
|
---|
948 | ecn_node_send_anno_prop_map(node);
|
---|
949 | }
|
---|
950 | else if((sobj->pmapFlag & PMAP_FLAG_SET) == 0){
|
---|
951 | ecn_node_send_set_prop_map(node);
|
---|
952 | }
|
---|
953 | else{
|
---|
954 | ecn_node_next_obj(node);
|
---|
955 | ecn_node_timeout_on_start(node);
|
---|
956 | }
|
---|
957 | }
|
---|
958 |
|
---|
959 | static void ecn_node_timeout_on_set_prpmap_wait(ecn_node_t *node)
|
---|
960 | {
|
---|
961 | ecn_obj_t *obj = node->current;
|
---|
962 | if(obj == NULL){
|
---|
963 | node->state = ecn_node_state_idle;
|
---|
964 | node->timer = TMO_FEVR;
|
---|
965 | return;
|
---|
966 | }
|
---|
967 |
|
---|
968 | node->retry++;
|
---|
969 | if(node->retry < 3){
|
---|
970 | ecn_node_next_proc_on_set_prpmap_wait(node, obj);
|
---|
971 | }
|
---|
972 | else{
|
---|
973 | node->retry = 0;
|
---|
974 | node->state = ecn_node_state_fault;
|
---|
975 | node->timer = TMO_FEVR;
|
---|
976 | }
|
---|
977 | }
|
---|
978 |
|
---|
979 | static void ecn_node_next_proc_on_get_prpmap_wait(ecn_node_t *node, ecn_obj_t *sobj)
|
---|
980 | {
|
---|
981 | if((sobj->pmapFlag & PMAP_FLAG_ANNO) == 0){
|
---|
982 | ecn_node_send_anno_prop_map(node);
|
---|
983 | }
|
---|
984 | else if((sobj->pmapFlag & PMAP_FLAG_SET) == 0){
|
---|
985 | ecn_node_send_set_prop_map(node);
|
---|
986 | }
|
---|
987 | else if((sobj->pmapFlag & PMAP_FLAG_GET) == 0){
|
---|
988 | ecn_node_send_get_prop_map(node);
|
---|
989 | }
|
---|
990 | else{
|
---|
991 | ecn_node_next_obj(node);
|
---|
992 | ecn_node_timeout_on_start(node);
|
---|
993 | }
|
---|
994 | }
|
---|
995 |
|
---|
996 | static void ecn_node_timeout_on_get_prpmap_wait(ecn_node_t *node)
|
---|
997 | {
|
---|
998 | ecn_obj_t *obj = node->current;
|
---|
999 | if(obj == NULL){
|
---|
1000 | node->state = ecn_node_state_idle;
|
---|
1001 | node->timer = TMO_FEVR;
|
---|
1002 | return;
|
---|
1003 | }
|
---|
1004 |
|
---|
1005 | ecn_node_next_proc_on_get_prpmap_wait(node, obj);
|
---|
1006 | }
|
---|
1007 |
|
---|
1008 | static void ecn_node_next_proc_on_anno_prpmap_wait(ecn_node_t *node, ecn_obj_t *sobj)
|
---|
1009 | {
|
---|
1010 | if((sobj->pmapFlag & PMAP_FLAG_SET) == 0){
|
---|
1011 | ecn_node_send_set_prop_map(node);
|
---|
1012 | }
|
---|
1013 | else if((sobj->pmapFlag & PMAP_FLAG_GET) == 0){
|
---|
1014 | ecn_node_send_get_prop_map(node);
|
---|
1015 | }
|
---|
1016 | else if((sobj->pmapFlag & PMAP_FLAG_ANNO) == 0){
|
---|
1017 | ecn_node_send_anno_prop_map(node);
|
---|
1018 | }
|
---|
1019 | else{
|
---|
1020 | ecn_node_next_obj(node);
|
---|
1021 | ecn_node_timeout_on_start(node);
|
---|
1022 | }
|
---|
1023 | }
|
---|
1024 |
|
---|
1025 | static void ecn_node_timeout_on_anno_prpmap_wait(ecn_node_t *node)
|
---|
1026 | {
|
---|
1027 | ecn_obj_t *obj = node->current;
|
---|
1028 | if(obj == NULL){
|
---|
1029 | node->state = ecn_node_state_idle;
|
---|
1030 | node->timer = TMO_FEVR;
|
---|
1031 | return;
|
---|
1032 | }
|
---|
1033 |
|
---|
1034 | ecn_node_next_proc_on_anno_prpmap_wait(node, obj);
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 | const EPRPINIB *ecn_agent_get_property(const EOBJINIB *fp_obj, uint8_t fa_epc, const EPRPINIB *item)
|
---|
1038 | {
|
---|
1039 | ecn_obj_t *obj = cast_obj2(fp_obj);
|
---|
1040 | bool_t has = false;
|
---|
1041 |
|
---|
1042 | /* m[hÌêÍCX^XXgÊmÆ©m[hCX^XXgrÊmðK{Åó¯æé */
|
---|
1043 | if ((fp_obj->enodid == 0) && ((fa_epc == 0xD5) || (fa_epc == 0xD6)))
|
---|
1044 | has = true;
|
---|
1045 | else if (ecn_agent_contains_epc_in_prop_map(fa_epc, obj->pmapGet))
|
---|
1046 | has = true;
|
---|
1047 | else if (ecn_agent_contains_epc_in_prop_map(fa_epc, obj->pmapSet))
|
---|
1048 | has = true;
|
---|
1049 | else if (ecn_agent_contains_epc_in_prop_map(fa_epc, obj->pmapAnno))
|
---|
1050 | has = true;
|
---|
1051 |
|
---|
1052 | if(!has)
|
---|
1053 | return NULL;
|
---|
1054 |
|
---|
1055 | ((EPRPINIB *)item)->eprpcd = fa_epc;
|
---|
1056 | ((EPRPINIB *)item)->exinf = (intptr_t)fp_obj;
|
---|
1057 |
|
---|
1058 | return item;
|
---|
1059 | }
|
---|
1060 |
|
---|
1061 | int ecn_agent_eprpget(const EPRPINIB *item, void *dst, int size)
|
---|
1062 | {
|
---|
1063 | return 0;
|
---|
1064 | }
|
---|
1065 |
|
---|
1066 | int ecn_agent_eprpset(const EPRPINIB *item, const void *src, int size, bool_t *anno)
|
---|
1067 | {
|
---|
1068 | ecn_agent_t *agent = cast_agent(item);
|
---|
1069 | ecn_node_t *node = agent->current_node;
|
---|
1070 | const uint8_t *edt = (const uint8_t *)src;
|
---|
1071 | ecn_obj_t *sobj = cast_obj2((const EOBJINIB *)item->exinf);
|
---|
1072 | uint8_t eprpcnt;
|
---|
1073 | int i;
|
---|
1074 |
|
---|
1075 | switch (item->eprpcd) {
|
---|
1076 | /* CX^XXgÊmÌê */
|
---|
1077 | case 0xD5:
|
---|
1078 | /* ©m[hCX^XXgrÊmÌê */
|
---|
1079 | case 0xD6:
|
---|
1080 | if ((node != NULL) && (node->state == ecn_node_state_idle)) {
|
---|
1081 | ecn_agent_queue_t *devices = &node->devices;
|
---|
1082 | ecn_agent_queue_t *queue = devices->p_next;
|
---|
1083 | #ifdef _DEBUG
|
---|
1084 | assert(queue->p_parent == devices);
|
---|
1085 | #endif
|
---|
1086 | for (; queue != devices; queue = queue->p_next) {
|
---|
1087 | ecn_obj_t *obj = cast_obj(queue);
|
---|
1088 | obj->pmapFlag = 0;
|
---|
1089 | }
|
---|
1090 | node->base.pmapFlag = 0;
|
---|
1091 | node->state = ecn_node_state_start;
|
---|
1092 | node->timer = (TMO)1000;
|
---|
1093 | node->current = sobj;
|
---|
1094 | }
|
---|
1095 | break;
|
---|
1096 | /* ÊmvpeB}bvÌê */
|
---|
1097 | case 0x9D:
|
---|
1098 | eprpcnt = edt[0];
|
---|
1099 |
|
---|
1100 | if (eprpcnt < 16) {
|
---|
1101 | /* TCY`FbN */
|
---|
1102 | if (eprpcnt + 1 != size)
|
---|
1103 | return 0;
|
---|
1104 |
|
---|
1105 | for (i = 1; i < size; i++)
|
---|
1106 | ecn_agent_set_epc_to_prop_map(edt[i], sobj->pmapAnno);
|
---|
1107 | }
|
---|
1108 | else {
|
---|
1109 | /* TCY`FbN */
|
---|
1110 | if (size != 17)
|
---|
1111 | return 0;
|
---|
1112 |
|
---|
1113 | memcpy(sobj->pmapAnno, &edt[1], 16);
|
---|
1114 | }
|
---|
1115 | sobj->eprpcnt = eprpcnt;
|
---|
1116 | sobj->pmapFlag |= PMAP_FLAG_ANNO;
|
---|
1117 | break;
|
---|
1118 | /* SETvpeB}bvÌê */
|
---|
1119 | case 0x9E:
|
---|
1120 | eprpcnt = edt[0];
|
---|
1121 |
|
---|
1122 | if (eprpcnt < 16) {
|
---|
1123 | /* TCY`FbN */
|
---|
1124 | if (eprpcnt + 1 != size)
|
---|
1125 | return 0;
|
---|
1126 |
|
---|
1127 | for (i = 1; i < size; i++)
|
---|
1128 | ecn_agent_set_epc_to_prop_map(edt[i], sobj->pmapSet);
|
---|
1129 | }
|
---|
1130 | else {
|
---|
1131 | /* TCY`FbN */
|
---|
1132 | if (size != 17)
|
---|
1133 | return 0;
|
---|
1134 |
|
---|
1135 | memcpy(sobj->pmapSet, &edt[1], 16);
|
---|
1136 | }
|
---|
1137 | sobj->eprpcnt = eprpcnt;
|
---|
1138 | sobj->pmapFlag |= PMAP_FLAG_SET;
|
---|
1139 | break;
|
---|
1140 | /* GETvpeB}bvÌê */
|
---|
1141 | case 0x9F:
|
---|
1142 | eprpcnt = edt[0];
|
---|
1143 |
|
---|
1144 | if (eprpcnt < 16) {
|
---|
1145 | /* TCY`FbN */
|
---|
1146 | if (eprpcnt + 1 != size)
|
---|
1147 | return 0;
|
---|
1148 |
|
---|
1149 | for (i = 1; i < size; i++)
|
---|
1150 | ecn_agent_set_epc_to_prop_map(edt[i], sobj->pmapGet);
|
---|
1151 | }
|
---|
1152 | else {
|
---|
1153 | /* TCY`FbN */
|
---|
1154 | if (size != 17)
|
---|
1155 | return 0;
|
---|
1156 |
|
---|
1157 | memcpy(sobj->pmapGet, &edt[1], 16);
|
---|
1158 | }
|
---|
1159 | sobj->eprpcnt = eprpcnt;
|
---|
1160 | sobj->pmapFlag |= PMAP_FLAG_GET;
|
---|
1161 | break;
|
---|
1162 | default:
|
---|
1163 | g_forward_esv = true;
|
---|
1164 | return 0;
|
---|
1165 | }
|
---|
1166 |
|
---|
1167 | agent->msg_proced = true;
|
---|
1168 |
|
---|
1169 | return size;
|
---|
1170 | }
|
---|
1171 |
|
---|
1172 | ER ecn_agent_get_device_list(ID sender, int requestid, ECN_FBS_ID *pk_req)
|
---|
1173 | {
|
---|
1174 | ER a_ret;
|
---|
1175 | ECN_FBS_ID req;
|
---|
1176 |
|
---|
1177 | a_ret = _ecn_tsk_cre_req_fbs(sender, ECN_INM_GET_DEVICE_LIST_REQ, &req);
|
---|
1178 | if (a_ret != E_OK) {
|
---|
1179 | return a_ret;
|
---|
1180 | }
|
---|
1181 |
|
---|
1182 | a_ret = _ecn_fbs_add_data_ex(req, &requestid, sizeof(((ecn_inm_get_device_list_req_t *)0)->requestid));
|
---|
1183 | if (a_ret != E_OK) {
|
---|
1184 | _ecn_fbs_del(req);
|
---|
1185 | return a_ret;
|
---|
1186 | }
|
---|
1187 |
|
---|
1188 | *pk_req = req;
|
---|
1189 |
|
---|
1190 | return E_OK;
|
---|
1191 | }
|
---|
1192 |
|
---|
1193 | ER ecn_agent_get_device_info(ID sender, int requestid, ID eobjid, ECN_FBS_ID *pk_req)
|
---|
1194 | {
|
---|
1195 | ER a_ret;
|
---|
1196 | ECN_FBS_ID req;
|
---|
1197 |
|
---|
1198 | a_ret = _ecn_tsk_cre_req_fbs(sender, ECN_INM_GET_DEVICE_INFO_REQ, &req);
|
---|
1199 | if (a_ret != E_OK) {
|
---|
1200 | return a_ret;
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 | a_ret = _ecn_fbs_add_data_ex(req, &requestid, sizeof(((ecn_inm_get_device_info_req_t *)0)->requestid));
|
---|
1204 | if (a_ret != E_OK) {
|
---|
1205 | _ecn_fbs_del(req);
|
---|
1206 | return a_ret;
|
---|
1207 | }
|
---|
1208 |
|
---|
1209 | a_ret = _ecn_fbs_add_data_ex(req, &eobjid, sizeof(((ecn_inm_get_device_info_req_t *)0)->eobjid));
|
---|
1210 | if (a_ret != E_OK) {
|
---|
1211 | _ecn_fbs_del(req);
|
---|
1212 | return a_ret;
|
---|
1213 | }
|
---|
1214 |
|
---|
1215 | *pk_req = req;
|
---|
1216 |
|
---|
1217 | return E_OK;
|
---|
1218 | }
|
---|