source: UsbWattMeter/trunk/ecnl_lwip/echonet_task.c@ 164

Last change on this file since 164 was 164, checked in by coas-nagasima, 6 years ago

TOPPERS/ECNLサンプルアプリ「USB充電器電力計」を追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 55.5 KB
RevLine 
[164]1/*
2 * TOPPERS ECHONET Lite Communication Middleware
3 *
4 * Copyright (C) 2014-2016 Cores Co., Ltd. Japan
5 *
6 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
7 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
8 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
9 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
10 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
11 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
12 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
13 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
14ƒƒ“ƒgi—˜—p
15 * ŽÒƒ}ƒjƒ…
16ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
17 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
18 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
19 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
20 * ‚ƁD
21 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
22ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
23ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
24 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
25 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
26 * •ñ‚·‚邱‚ƁD
27 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
28 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
29 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
30 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
31 * –Ɛӂ·‚邱‚ƁD
32 *
33 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
34 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
35 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
36 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
37 * ‚̐ӔC‚𕉂í‚È‚¢D
38 *
39 * @(#) $Id: echonet_task.c 164 2016-03-07 11:33:50Z coas-nagasima $
40 */
41
42/*
43 * ECHONET Lite ƒ^ƒXƒN
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 <t_stdlib.h>
53
54#include "syssvc/serial.h"
55#include "syssvc/syslog.h"
56
57#include "echonet.h"
58#include "echonet_fbs.h"
59#include "echonet_task.h"
60#include "echonet_dbg.h"
61#ifdef ECHONET_CONTROLLER_EXTENTION
62#include "echonet_agent.h"
63#endif
64
65#ifndef ECHONET_TASK_GET_TIMER
66#define ECHONET_TASK_GET_TIMER TMO_FEVR
67#endif /* ECHONET_TASK_GET_TIMER */
68
69#ifndef ECHONET_TASK_PROGRESS
70#define ECHONET_TASK_PROGRESS(timer)
71#endif /* ECHONET_TASK_PROGRESS */
72
73#ifndef ECHONET_TASK_TIMEOUT
74#define ECHONET_TASK_TIMEOUT
75#endif /* ECHONET_TASK_TIMEOUT */
76
77/* ƒAƒvƒŠƒP[ƒVƒ‡ƒ“‚ª—v‹‚µ‚½“d•¶‚̃V[ƒPƒ“ƒX”ԍ† */
78static uint16_t g_api_tid;
79
80/* ŽóMƒƒbƒZ[ƒW‚ðŠJ•ú‚·‚é‚©”Û‚© */
81static bool_t g_release_esv;
82
83ER _ecn_tsk_ntf_inl(intptr_t fa_exinf);
84
85ER _ecn_tsk_snd_mbx(ECN_FBS_ID fa_rsp_fbs, bool_t from_app)
86{
87 ER a_ret;
88 T_MSG *msg = (T_MSG *)fa_rsp_fbs.ptr;
89 ID mbxid = ecn_udp_mailboxid;
90 int i;
91#ifdef ECN_DBG_PUT_ENA
92 intptr_t a_fbs_sub1 = (intptr_t)fa_rsp_fbs.ptr->lnk.p_sub[0];
93#endif
94 if (from_app && (((T_EDATA *)fa_rsp_fbs.ptr)->hdr.edata.esv == ESV_INFC)) {
95 g_api_tid = ((T_EDATA *)fa_rsp_fbs.ptr)->hdr.ecn_hdr.tid;
96 mbxid = ecn_svc_mailboxid;
97 }
98 else {
99 switch (fa_rsp_fbs.ptr->hdr.target.id) {
100 case ENOD_MULTICAST_ID:
101 if (from_app)
102 g_api_tid = ((T_EDATA *)fa_rsp_fbs.ptr)->hdr.ecn_hdr.tid;
103
104 mbxid = ecn_udp_mailboxid;
105 break;
106 case ENOD_LOCAL_ID:
107 if (from_app)
108 mbxid = ecn_svc_mailboxid;
109 else
110 mbxid = ecn_api_mailboxid;
111 break;
112 case ENOD_API_ID:
113 mbxid = ecn_api_mailboxid;
114 break;
115 default:
116 if (from_app)
117 g_api_tid = ((T_EDATA *)fa_rsp_fbs.ptr)->hdr.ecn_hdr.tid;
118
119 i = fa_rsp_fbs.ptr->hdr.target.id;
120 if (i < ENOD_REMOTE_ID || tnum_enodadr <= i)
121 return E_NOEXS;
122 i += - ENOD_REMOTE_ID + 1;
123 if (from_app && (i < tnum_enodid)) {
124 /* ”ñ“¯Šú‚̃Šƒ‚[ƒgƒm[ƒh‚̓T[ƒrƒXˆ—ƒ^ƒXƒN‚ŏˆ—‚·‚é */
125 switch (eobjcb_table[i].profile->eobjatr) {
126 case EOBJ_SYNC_REMOTE_NODE:
127 mbxid = ecn_udp_mailboxid;
128 break;
129 case EOBJ_ASYNC_REMOTE_NODE:
130 mbxid = ecn_svc_mailboxid;
131 break;
132 default:
133 return E_SYS;
134 }
135 }
136 else {
137 mbxid = ecn_udp_mailboxid;
138 }
139 break;
140 }
141 }
142#ifdef ECN_DBG_PUT_ENA
143 ECN_DBG_PUT( "snd_mbx(%d, 0x%08X-0x%08X)", mbxid, (intptr_t)msg, a_fbs_sub1 );
144 _ecn_dbg_bindmp(msg, 256);
145#endif
146 a_ret = snd_mbx(mbxid, msg);
147#ifdef ECN_DBG_PUT_ENA
148 ECN_DBG_PUT( "snd_mbx(%d, 0x%08X-0x%08X) result = %d:%s", mbxid, (intptr_t)msg, a_fbs_sub1, a_ret, itron_strerror(a_ret) );
149#endif
150 return a_ret;
151}
152
153static void _ecn_tsk_int_module_init(intptr_t fa_exinf);
154static void _ecn_tsk_int_startup(intptr_t fa_exinf);
155static uint16_t _ecn_tsk_new_tid(void);
156static void _ecn_tsk_int_msg(intptr_t fa_exinf, ECN_FBS_ID fa_fbs_id);
157static void _ecn_tsk_ecn_msg(intptr_t fa_exinf, ECN_FBS_ID fa_fbs_id);
158
159static void _ecn_tsk_eoj_set(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_fromapp, bool_t fa_update,
160 ECN_FBS_ID fa_fbs_id, ECN_SRV_CODE fa_res_esv, ECN_SRV_CODE fa_sna_esv,
161 ECN_FBS_ID *fa_fbs_anno);
162static void _ecn_tsk_eoj_get(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_forward, ATR fa_access,
163 ECN_FBS_ID fa_fbs_id, ECN_SRV_CODE fa_res_esv, ECN_SRV_CODE fa_sna_esv);
164static void _ecn_tsk_eoj_res(ECN_FBS_ID fa_fbs_id, ECN_SRV_CODE fa_res_esv,
165 ECN_SRV_CODE fa_sna_esv);
166static void _ecn_tsk_eoj_set_get(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_fromapp,
167 ECN_FBS_ID fa_fbs_id, ECN_SRV_CODE fa_res_esv, ECN_SRV_CODE fa_sna_esv,
168 ECN_FBS_ID *fa_fbs_anno);
169static void _ecn_tsk_eoj_set_get_res(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_fromapp,
170 ECN_FBS_ID fa_fbs_id, ECN_FBS_ID *fa_fbs_anno);
171
172/* ƒ‚ƒWƒ…
173[ƒ‹‰Šú‰»ƒtƒ‰ƒO */
174static uint8_t m_eobjlist_need_init = 1;
175
176/* ƒV[ƒPƒ“ƒX”ԍ† */
177static uint16_t g_current_tid = 1;
178
179/*
180 * ECHONET Lite ƒ^ƒXƒN‚̏‰Šú‰»iƒRƒ“ƒXƒgƒ‰ƒNƒ^‘Š“–j
181 */
182void echonet_task_init(intptr_t exinf)
183{
184 if (m_eobjlist_need_init)
185 _ecn_tsk_int_module_init(exinf);
186}
187
188/*
189 * ƒ‚ƒWƒ…
190[ƒ‹‰Šú‰»
191 */
192static void _ecn_tsk_int_module_init(intptr_t exinf)
193{
194 ID tskid;
195
196 if (!m_eobjlist_need_init)
197 return;
198
199 get_tid(&tskid);
200 /* ECN_DBG_PUT( "[ECHONET MainTask:%d] started", tskid ); */
201 syslog(LOG_NOTICE, "[ECHONET MainTask:%d] started", tskid);
202
203 m_eobjlist_need_init = 0;
204
205#ifdef ECHONET_CONTROLLER_EXTENTION
206 ecn_agent_init();
207#endif
208}
209
210/*
211 * ECHONET Lite ƒ^ƒXƒN‚Ì–{‘Ì
212 */
213void echonet_task(intptr_t fa_exinf)
214{
215 ER a_ret, a_ret2;
216 union
217 {
218 T_MSG *p_msg;
219 ECN_FBS_ID fbs_id;
220 } a_mdt;
221 SYSTIM a_prev, a_now;
222 TMO a_timer;
223#ifdef ECHONET_CONTROLLER_EXTENTION
224 TMO a_timera;
225#endif
226
227 _ecn_tsk_int_startup(fa_exinf);
228
229 a_ret2 = get_tim(&a_now);
230 if (a_ret2 != E_OK) {
231 ECN_DBG_PUT( "get_tim() result = %d:%s", a_ret2, itron_strerror(a_ret2) );
232 return;
233 }
234
235 /* ƒƒbƒZ[ƒWƒ‹[ƒv */
236 for (;;) {
237 a_prev = a_now;
238
239 a_timer = ECHONET_TASK_GET_TIMER;
240#ifdef ECHONET_CONTROLLER_EXTENTION
241 a_timera = ecn_agent_get_timer();
242 if(a_timer == TMO_FEVR){
243 a_timer =a_timera;
244 }
245 else if((a_timera != TMO_FEVR) && (a_timera < a_timer)){
246 a_timer = a_timera;
247 }
248#endif
249
250 a_ret = trcv_mbx(ecn_svc_mailboxid, &a_mdt.p_msg, a_timer);
251 if ((a_ret != E_OK) && (a_ret != E_TMOUT)) {
252 ECN_DBG_PUT( "trcv_mbx() result = %d:%s", a_ret, itron_strerror(a_ret) );
253 break;
254 }
255
256 a_ret2 = get_tim(&a_now);
257 if (a_ret2 != E_OK) {
258 ECN_DBG_PUT( "get_tim() result = %d:%s", a_ret2, itron_strerror(a_ret2) );
259 break;
260 }
261
262 a_timer = a_now - a_prev;
263 ECHONET_TASK_PROGRESS(a_timer);
264#ifdef ECHONET_CONTROLLER_EXTENTION
265 ecn_agent_progress(a_timer);
266#endif
267
268 if (a_ret == E_OK) {
269 ECN_DBG_PUT( "trcv_mbx() mbx recv (%d byte)", _ecn_fbs_get_datalen(a_mdt.fbs_id) );
270 g_release_esv = true;
271
272 switch (a_mdt.fbs_id.ptr->hdr.type) {
273 /* “à•”Žg—pƒƒbƒZ[ƒW */
274 case ECN_MSG_INTERNAL:
275 _ecn_tsk_int_msg(fa_exinf, a_mdt.fbs_id);
276 break;
277
278 /* ECHONET—pƒƒbƒZ[ƒW */
279 case ECN_MSG_ECHONET:
280 _ecn_tsk_ecn_msg(fa_exinf, a_mdt.fbs_id);
281 break;
282
283 default:
284 syslog(LOG_WARNING, "echonet_task() a_fbs_id.ptr->k.hdr.k.t_edt.type:0x%02X undefined.", a_mdt.fbs_id.ptr->hdr.type);
285 }
286
287 /* —̈æ‰ð•ú */
288 if (g_release_esv)
289 _ecn_fbs_del(a_mdt.fbs_id);
290 }
291
292 ECHONET_TASK_TIMEOUT;
293#ifdef ECHONET_CONTROLLER_EXTENTION
294 ecn_agent_timeout();
295#endif
296 }
297}
298
299/*
300 * ƒV[ƒPƒ“ƒX”ԍ†¶¬
301 */
302static uint16_t _ecn_tsk_new_tid(void)
303{
304 return g_current_tid++;
305}
306
307/*
308 * —v‹“d•¶ì¬
309 * ˆø”
310 * ECN_FBS_ID *fp_fbs_id Žæ“¾‚µ‚½FBS_ID‚ÌŠi”[æ
311 * ID fa_seoj ‘—MŒ³‚ÌECHONETƒIƒuƒWƒFƒNƒgID
312 * ID fa_deoj ˆ¶æ‚ÌECHONETƒIƒuƒWƒFƒNƒgID
313 * uint8_t fa_epc ƒvƒƒpƒeƒBƒR[ƒh
314 * uint8_t fa_pdc ƒvƒƒpƒeƒB’lƒf[ƒ^ƒTƒCƒY
315 * const void *p_edt ƒvƒƒpƒeƒB’lƒf[ƒ^
316 * ECN_SRV_CODE fa_esv ECHONET Light ƒT[ƒrƒXƒR[ƒh
317 */
318ER _ecn_tsk_mk_esv(ECN_FBS_ID *fp_fbs_id, ID fa_seoj, ID fa_deoj,
319 uint8_t fa_epc, uint8_t fa_pdc, const void *p_edt, ECN_SRV_CODE fa_esv)
320{
321 ER a_ret;
322 int a_size, i;
323 ECN_FBS_ID a_fbs_id = { 0 }; /* —v‹“d•¶—pƒƒ‚ƒŠ */
324 T_ECN_EDT_HDR a_ecn_hdp; /* ecn_hdr+edata+ecn_prp 14byte */
325 ID a_enodid;
326 const EOBJINIB *a_eobj;
327 const EOBJINIB *a_enod;
328
329 if (!fp_fbs_id)
330 return E_PAR; /* Žæ“¾‚µ‚½FBS_ID‚ÌŠi”[æ‚ªNULL */
331 if (ECHONET_MEMPOOL_BLOCK_SIZE <= fa_pdc)
332 return E_PAR; /* ƒvƒƒpƒeƒB’lƒTƒCƒY‚ª‘å‚«‚·‚¬‚é */
333 if (!p_edt && 0 < fa_pdc)
334 return E_PAR; /* ƒvƒƒpƒeƒB’lƒTƒCƒY‚ª1ˆÈã‚Ȃ̂Ƀf[ƒ^ƒ|ƒCƒ“ƒ^‚ªNULL */
335
336 if (fa_seoj <= EOBJ_NULL || tmax_eobjid < fa_seoj)
337 return E_NOEXS; /* ECHONETƒIƒuƒWƒFƒNƒgID‚ª–¢’è‹` */
338#ifndef ECHONET_CONTROLLER_EXTENTION
339 if (fa_deoj < EOBJ_NULL || tmax_eobjid < fa_deoj)
340 return E_NOEXS; /* ECHONETƒIƒuƒWƒFƒNƒgID‚ª–¢’è‹` */
341#else
342 if (fa_deoj < EOBJ_NULL || (tmax_eobjid + TNUM_AEOBJID) < fa_deoj)
343 return E_NOEXS; /* ECHONETƒIƒuƒWƒFƒNƒgID‚ª–¢’è‹` */
344#endif
345 if (fa_deoj == EOBJ_NULL && fa_esv == ESV_INFC)
346 return E_NOEXS; /* ECHONETƒIƒuƒWƒFƒNƒgID‚ª–¢’è‹` */
347
348 /* —v‹Å¬ƒTƒCƒY‚̎擾 */
349 a_size = sizeof(T_ECN_HDR) + sizeof(T_ECN_EDATA_BODY) + sizeof(T_ECN_PRP);
350
351 /* —v‹“d•¶—pƒƒ‚ƒŠ‚̎擾 */
352 a_ret = _ecn_fbs_cre(a_size, &a_fbs_id);
353 if (a_ret != E_OK || !a_fbs_id.ptr) { /* Šm•ÛŽ¸”s */
354 ECN_DBG_PUT( "_ecn_fbs_cre(%d) result = %d:%s",
355 a_size,
356 a_ret, itron_strerror(a_ret) );
357 return E_NOMEM;
358 }
359
360 /* —v‹“d•¶Ý’è */
361 memset(&a_ecn_hdp, 0, sizeof(a_ecn_hdp));
362 a_ecn_hdp.ecn_hdr.ehd1 = ECN_EDH1_ECHONET_LITE;
363 a_ecn_hdp.ecn_hdr.ehd2 = ECN_EDH2_FORMAT_1;
364 a_ecn_hdp.ecn_hdr.tid = _ecn_tsk_new_tid();
365 memcpy(&a_ecn_hdp.edata.seoj, &eobjinib_table[fa_seoj - 1].eojx1, sizeof(a_ecn_hdp.edata.seoj));
366 a_ecn_hdp.edata.esv = fa_esv;
367 a_ecn_hdp.edata.opc = 1; /* ˆ—ƒvƒƒpƒeƒB” */
368 a_ecn_hdp.ecn_prp.epc = fa_epc; /* ƒvƒƒpƒeƒBƒR[ƒh */
369 a_ecn_hdp.ecn_prp.pdc = fa_pdc; /* •tƒf[ƒ^ƒTƒCƒY */
370
371 /* —v‹“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ */
372 a_ret = _ecn_fbs_add_data_ex(a_fbs_id, &a_ecn_hdp, a_size);
373 if (a_ret) {
374 ECN_DBG_PUT( "_ecn_fbs_add_data_ex(*, ecn_hdp{esv:0x%02X,epc:0x%02X}, %d) result = %d:%s",
375 a_ecn_hdp.edata.esv, a_ecn_hdp.ecn_prp.epc, a_size,
376 a_ret, itron_strerror(a_ret) );
377 goto lb_except;
378 }
379 if (0 < fa_pdc) {
380 /* •tƒf[ƒ^’ljÁ */
381 a_ret = _ecn_fbs_add_data_ex(a_fbs_id, p_edt, fa_pdc);
382 if (a_ret) {
383 ECN_DBG_PUT( "_ecn_fbs_add_data_ex(*, ecn_hdp{esv:0x%02X,epc:0x%02X} edt, %d) result = %d:%s",
384 a_ecn_hdp.edata.esv, a_ecn_hdp.ecn_prp.epc, fa_pdc,
385 a_ret, itron_strerror(a_ret) );
386 goto lb_except;
387 }
388 }
389 if (fa_deoj == 0) {
390 ECN_DBG_PUT( "%s", "ƒ}ƒ‹ƒ`ƒLƒƒƒXƒg" );
391 /* fa_deoj == 0 : ƒ}ƒ‹ƒ`ƒLƒƒƒXƒg */
392 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx1 = EOJ_X1_PROFILE;
393 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx2 = EOJ_X2_NODE_PROFILE;
394 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx3 = 0x01;
395 a_fbs_id.ptr->hdr.target.id = ENOD_MULTICAST_ID;
396 }
397 else if (fa_deoj <= tmax_eobjid) {
398 ECN_DBG_PUT( "fa_deoj = %d", fa_deoj );
399 /* if (fa_deoj < 1 || tmax_eobjid < fa_deoj) c‚ُ̈íŒn‚͊֐”–`“ª‚ŏœŠOÏ‚Ý‚Æ‚·‚é */
400 a_eobj = &eobjinib_table[fa_deoj - 1];
401 memcpy(&((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj, &a_eobj->eojx1,
402 sizeof(((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj));
403
404 /* ƒe[ƒuƒ‹‚©‚猟õ */
405 a_fbs_id.ptr->hdr.target.id = ENOD_NOT_MATCH_ID;
406 a_enodid = (a_eobj->enodid == 0) ? fa_deoj : a_eobj->enodid;
407 a_enod = &eobjinib_table[a_enodid - 1];
408 if ((a_enod->eobjatr == EOBJ_LOCAL_NODE)
409 || ((a_enod->eobjatr == EOBJ_ASYNC_REMOTE_NODE) && (fa_esv == ESV_GET))) {
410 a_fbs_id.ptr->hdr.target.id = ENOD_LOCAL_ID;
411 }
412 else{
413 for (i = 1; i < tnum_enodid; i++) {
414 const EOBJCB *temp = &eobjcb_table[i];
415 if (a_enod != temp->profile)
416 continue;
417
418 a_fbs_id.ptr->hdr.target.id = (ECN_ENOD_ID)(i + ENOD_REMOTE_ID - 1);
419 break;
420 }
421 }
422 if (a_fbs_id.ptr->hdr.target.id == ENOD_NOT_MATCH_ID) {
423 goto lb_except;
424 ECN_DBG_PUT( "deoj = %02X %02X %02x : enod not match",
425 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx1,
426 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx2,
427 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx3 );
428 }
429#ifdef ECN_DBG_PUT_ENA
430 else {
431 ECN_DBG_PUT( "deoj = %02X %02X %02x : %s",
432 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx1,
433 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx2,
434 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx3,
435 _ecn_dbg_enod2str(a_fbs_id.ptr->hdr.target.id) );
436 }
437#endif
438 }
439#ifdef ECHONET_CONTROLLER_EXTENTION
440 else{
441 T_ECN_EOJ eoj;
442 ECN_ENOD_ID enodid;
443 ECN_DBG_PUT( "fa_deoj = %d", fa_deoj );
444 /* ƒIƒuƒWƒFƒNƒgID‚©‚çEOJ‚ƃm[ƒhID‚ðŽæ“¾ */
445 if(ecn_agent_get_eoj_enodid(fa_deoj, &eoj, &enodid)){
446 memcpy(&((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj, &eoj,
447 sizeof(((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj));
448 a_fbs_id.ptr->hdr.target.id = enodid;
449 }
450 else {
451 goto lb_except;
452 ECN_DBG_PUT( "deoj = %02X %02X %02x : enod not match",
453 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx1,
454 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx2,
455 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx3 );
456 }
457#ifdef ECN_DBG_PUT_ENA
458 else {
459 ECN_DBG_PUT( "deoj = %02X %02X %02x : %s",
460 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx1,
461 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx2,
462 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.deoj.eojx3,
463 _ecn_dbg_enod2str(a_fbs_id.ptr->hdr.target) );
464 }
465#endif
466 }
467#endif
468 a_fbs_id.ptr->hdr.type = ECN_MSG_ECHONET;
469 a_fbs_id.ptr->hdr.sender.id = ENOD_API_ID;
470 if (fa_esv == ESV_INFC)
471 a_fbs_id.ptr->hdr.reply.id = a_fbs_id.ptr->hdr.target.id;
472 else if (fa_esv == ESV_INF_REQ)
473 a_fbs_id.ptr->hdr.reply.id = ENOD_MULTICAST_ID;
474 else
475 a_fbs_id.ptr->hdr.reply.id = ENOD_API_ID;
476
477 /* ³íI—¹ */
478 *fp_fbs_id = a_fbs_id;
479 return E_OK;
480
481lb_except:
482 /* ƒf[ƒ^ì¬Ž¸”s‚µ‚½‚ç—̈æ‰ð•ú */
483 if (a_fbs_id.ptr)
484 _ecn_fbs_del(a_fbs_id);
485
486 return a_ret;
487}
488
489/*
490 * “à•”Žg—pƒƒbƒZ[ƒW
491 */
492static void _ecn_tsk_int_msg(intptr_t fa_exinf, ECN_FBS_ID fa_fbs_id)
493{
494 T_ECN_INTERNAL_MSG a_im;
495 ECN_FBS_SSIZE_T a_len;
496 int a_ans;
497
498 a_im.command = 0;
499 a_len = 0;
500 a_ans = _ecn_fbs_get_data(fa_fbs_id, &a_im.command, sizeof(a_im.command), &a_len);
501 if (a_ans || !a_len) {
502 return; /* NG */
503 }
504
505 switch (a_im.command) {
506 case ECN_INM_NOTIFY_INSTANCELIST:
507 ECN_DBG_PUT( "do _ecn_tsk_int_startup()" );
508 _ecn_tsk_int_startup(fa_exinf);
509 break;
510 default:
511#ifdef ECHONET_CONTROLLER_EXTENTION
512 if(ecn_agent_proc_int_msg(fa_fbs_id, a_im.command))
513 break;
514#endif
515 ECN_DBG_PUT( "recv: unefined internal-msg: %d", a_im.command );
516 break;
517 }
518}
519
520/*
521 * ƒ^ƒXƒN‰Šú‰»
522 */
523static void _ecn_tsk_int_startup(intptr_t fa_exinf)
524{
525 ER a_ret;
526
527 if (m_eobjlist_need_init)
528 _ecn_tsk_int_module_init(fa_exinf);
529
530 /* ƒCƒ“ƒXƒ^ƒ“ƒXƒŠƒXƒg’Ê’m‚Ì‘—M */
531 a_ret = _ecn_tsk_ntf_inl(fa_exinf);
532 if (a_ret) {
533 syslog(LOG_WARNING, "_ecn_tsk_ntf_inl() result = %d:%s", a_ret, itron_strerror(a_ret));
534 }
535}
536
537/*
538 * ƒCƒ“ƒXƒ^ƒ“ƒXƒŠƒXƒg’Ê’m‚Ì‘—M
539 * ECHONET-Lite_Ver.1.10_02.pdf p.43 }4-1-4
540 */
541ER _ecn_tsk_ntf_inl(intptr_t fa_exinf)
542{
543 const T_ECN_EOJ a_seoj = /* 0x01 : ˆê”ʃm[ƒhA0x02F‘—Mê—pƒm[ƒh */
544 { EOJ_X1_PROFILE, EOJ_X2_NODE_PROFILE, 0x01 };
545 const T_ECN_EOJ a_deoj =
546 { EOJ_X1_PROFILE, EOJ_X2_NODE_PROFILE, 0x01 };
547 T_ECN_EDT_HDR a_hdr;
548 ER a_ret = E_OK;
549 ECN_FBS_ID a_fbs = { 0 };
550 int a_eoj_ct = 0;
551 int i;
552 uint8_t a_count;
553 const EOBJCB *enod = &eobjcb_table[0]; /* ƒ[ƒJƒ‹ƒm[ƒh */
554 const EOBJINIB *eobj;
555
556 ECN_DBG_PUT( "do _ecn_tsk_ntf_inl()" );
557
558 memset(&a_hdr, 0, sizeof(a_hdr));
559 a_hdr.ecn_hdr.ehd1 = ECN_EDH1_ECHONET_LITE;
560 a_hdr.ecn_hdr.ehd2 = ECN_EDH2_FORMAT_1;
561 a_hdr.edata.seoj = a_seoj;
562 a_hdr.edata.deoj = a_deoj;
563 a_hdr.edata.esv = ESV_INF;
564 a_hdr.edata.opc = 1;
565 a_hdr.ecn_prp.epc = ECN_EPC_INL_BCS;
566
567 for (i = 0; i < enod->eobjcnt; i++) {
568 eobj = enod->eobjs[i];
569
570 if (!a_eoj_ct) {
571 /* ƒƒ‚ƒŠŠm•ÛEƒwƒbƒ_Ši”[ */
572 a_hdr.ecn_hdr.tid = (uint8_t)_ecn_tsk_new_tid(); /* ƒV[ƒPƒ“ƒX”ԍ†¶¬ */
573 a_ret = _ecn_fbs_cre(sizeof(a_hdr), &a_fbs);
574 if (a_ret != E_OK) /* Šm•ÛŽ¸”s */
575 goto lb_except;
576 a_ret = _ecn_fbs_add_data(a_fbs, &a_hdr, sizeof(a_hdr));
577 if (a_ret != E_OK) /* ƒf[ƒ^’ljÁŽ¸”s */
578 goto lb_except;
579
580 a_fbs.ptr->hdr.type = ECN_MSG_ECHONET;
581 a_fbs.ptr->hdr.sender.id = ENOD_LOCAL_ID;
582 a_fbs.ptr->hdr.target.id = ENOD_MULTICAST_ID;
583 a_fbs.ptr->hdr.reply.id = ENOD_LOCAL_ID;
584 ((T_EDATA *)a_fbs.ptr)->hdr.ecn_prp.pdc = 1; /* Œ” */
585 /* Œ”‚ðŠi”[ */
586 a_count = (uint8_t)(enod->eobjcnt - i);
587 if (a_count >= ECN_IST_LST_EOJ_MAX_CT)
588 a_count = ECN_IST_LST_EOJ_MAX_CT;
589 a_ret = _ecn_fbs_add_data_ex(a_fbs, &a_count, sizeof(a_count));
590 if (a_ret != E_OK) /* ƒf[ƒ^’ljÁŽ¸”s */
591 goto lb_except;
592 }
593 /* ECHONETƒIƒuƒWƒFƒNƒgID(3byte)‚ðŠi”[ */
594 a_ret = _ecn_fbs_add_data_ex(a_fbs, &eobj->eojx1, sizeof(T_ECN_EOJ));
595 if (a_ret != E_OK) /* ƒf[ƒ^’ljÁŽ¸”s */
596 goto lb_except;
597
598 /* Œ”EedtƒTƒCƒY‰ÁŽZ */
599 ((T_EDATA *)a_fbs.ptr)->hdr.ecn_prp.pdc += sizeof(T_ECN_EOJ);
600 if (++a_eoj_ct < ECN_IST_LST_EOJ_MAX_CT)
601 continue;
602
603 /* 1ƒAƒiƒEƒ“ƒX‚ł̏ãŒÀ‚É’B‚µ‚½‚çAˆê’U‘—M */
604 a_ret = _ecn_tsk_snd_mbx(a_fbs, false);
605 if (a_ret != E_OK) /* ƒf[ƒ^‘—MŽ¸”s */
606 goto lb_except;
607 a_eoj_ct = 0;
608 a_fbs.ptr = 0;
609 }
610 if (a_eoj_ct) {
611 /* –¢‘—Mƒf[ƒ^‚ª‚ ‚Á‚½‚çA‘—M */
612 a_ret = _ecn_tsk_snd_mbx(a_fbs, false);
613 if (a_ret != E_OK) /* ƒf[ƒ^‘—MŽ¸”s */
614 goto lb_except;
615 a_fbs.ptr = 0;
616 }
617 goto lb_finally;
618
619lb_except:
620 if (a_fbs.ptr)
621 _ecn_fbs_del(a_fbs);
622
623lb_finally:
624 return a_ret;
625}
626
627const EOBJCB *_ecn_eno_fnd(ECN_ENOD_ID enodid)
628{
629 const EOBJCB *enod = NULL;
630 int i;
631
632 switch (enodid) {
633 case ENOD_MULTICAST_ID:
634 case ENOD_LOCAL_ID:
635 case ENOD_API_ID:
636 enod = &eobjcb_table[0];
637 break;
638 default:
639 i = enodid - ENOD_REMOTE_ID + 1;
640 if ((i >= 1) && (i < tnum_enodid))
641 enod = &eobjcb_table[i];
642#ifdef ECHONET_CONTROLLER_EXTENTION
643 else{
644 ecn_node_t *p_tmp = ecn_agent_find_node(enodid);
645 if (p_tmp == NULL)
646 return NULL;
647 return &p_tmp->eobj;
648 }
649#endif
650 break;
651 }
652
653 return enod;
654}
655
656/*
657 * 3byte‚Ìeobjid‚Å”z—ñ’†‚ðŒŸõ‚·‚é
658 */
659const EOBJINIB *_ecn_eoj_fnd(const EOBJCB *fp_nod, const T_ECN_EOJ *fp_eoj)
660{
661 const EOBJINIB *p_obj;
662 int i, count = fp_nod->eobjcnt;
663
664#ifdef ECHONET_CONTROLLER_EXTENTION
665 if (fp_nod->eobjs == NULL) {
666 ecn_obj_t *p_tmp = ecn_agent_find_eobj(fp_nod, *fp_eoj);
667 if(p_tmp == NULL)
668 return NULL;
669 return &p_tmp->inib;
670 }
671#endif
672
673 for (i = 0; i < count; i++) {
674 p_obj = fp_nod->eobjs[i];
675
676 if (p_obj->eojx1 != fp_eoj->eojx1)
677 continue;
678 if (p_obj->eojx2 != fp_eoj->eojx2)
679 continue;
680 if (p_obj->eojx3 != fp_eoj->eojx3)
681 continue;
682
683 return p_obj;
684 }
685
686 return 0;
687}
688
689static int _ecn_tsk_ecn_msg_main(ECN_FBS_ID fa_fbs_id, const EOBJINIB *p_obj, ATR eobjatr,
690 const EOBJINIB *p_sobj, ATR sobjatr);
691
692/*
693 * ECHONET—pƒƒbƒZ[ƒW
694 */
695static void _ecn_tsk_ecn_msg(intptr_t fa_exinf, ECN_FBS_ID fa_fbs_id)
696{
697 const EOBJCB *p_nod, *p_snod;
698 const EOBJINIB *p_obj, *p_sobj = NULL;
699 ATR eobjatr, sobjatr = EPC_NONE;
700 T_ECN_EDT_HDR *p_esv;
701 ER a_ret;
702 int i, count;
703 T_ECN_EOJ *p_eoj;
704 bool_t a_prc;
705 bool_t a_fwd;
706
707#ifdef ECN_DBG_PUT_ENA
708 syslog(LOG_NOTICE, "mbx recv:");
709 _ecn_dbg_bindmp(fa_fbs_id.ptr, fa_fbs_id.ptr->hdr.length);
710#endif
711
712 p_esv = &((T_EDATA *)fa_fbs_id.ptr)->hdr;
713
714 if (p_esv->ecn_hdr.ehd1 != ECN_EDH1_ECHONET_LITE
715 || p_esv->ecn_hdr.ehd2 != ECN_EDH2_FORMAT_1) {
716 syslog(LOG_WARNING, "_ecn_tsk_ecn_msg() format fault: 0x%02X,0x%02X", p_esv->ecn_hdr.ehd1, p_esv->ecn_hdr.ehd2);
717 return;
718 }
719
720 /* ‘—Mˆ¶‚©‚çƒm[ƒh‚ðŒŸõ */
721 p_nod = _ecn_eno_fnd(fa_fbs_id.ptr->hdr.target.id);
722 /* ‘—MŒ³‚©‚çƒm[ƒh‚ðŒŸõ */
723 p_snod = _ecn_eno_fnd(fa_fbs_id.ptr->hdr.sender.id);
724 if (p_snod != NULL) {
725 sobjatr = p_snod->profile->eobjatr;
726 /* ƒm[ƒhƒvƒƒtƒ@ƒCƒ‹‚̏ꍇ */
727 if ((p_esv->edata.seoj.eojx1 == EOJ_X1_PROFILE)
728 && (p_esv->edata.seoj.eojx2 == EOJ_X2_NODE_PROFILE)) {
729 p_sobj = p_snod->profile;
730 }
731 /* ‹@ŠíƒIƒuƒWƒFƒNƒg‚̏ꍇ */
732 else {
733 p_sobj = _ecn_eoj_fnd(p_snod, &p_esv->edata.seoj);
734 }
735 }
736
737#ifdef ECHONET_CONTROLLER_EXTENTION
738 ecn_agent_proc_ecn_msg(&p_snod, &p_sobj, (T_EDATA *)fa_fbs_id.ptr);
739#endif
740
741 /* ƒm[ƒh“à‚Ì‹@ŠíƒIƒuƒWƒFƒNƒg‚ðŒŸõ */
742 a_prc = false;
743 a_fwd = false;
744 if (p_nod != NULL) {
745 eobjatr = p_nod->profile->eobjatr;
746 p_eoj = &p_esv->edata.deoj;
747 /* ƒm[ƒhƒvƒƒtƒ@ƒCƒ‹‚̏ꍇ */
748 if ((p_eoj->eojx1 == EOJ_X1_PROFILE)
749 && (p_eoj->eojx2 == EOJ_X2_NODE_PROFILE)) {
750 if ((p_eoj->eojx3 == p_nod->profile->eojx3)
751 || (p_eoj->eojx3 == 0)) {
752 /* “d•¶ˆ—ŽÀs */
753 if (_ecn_tsk_ecn_msg_main(fa_fbs_id, p_nod->profile, eobjatr, p_sobj, sobjatr) == 1)
754 a_fwd = true;
755 a_prc = true;
756 }
757 /* 0x74 ƒvƒƒpƒeƒB’l’Ê’mi‰ž“š—vj‚̏ꍇˆ—‚µ‚½‚±‚Æ‚É‚·‚é */
758 else if (p_esv->edata.esv == ESV_INFC) {
759 a_prc = true;
760 }
761 }
762 /* ‹@ŠíƒIƒuƒWƒFƒNƒg‚̏ꍇ */
763 else {
764 count = p_nod->eobjcnt;
765#ifdef ECHONET_CONTROLLER_EXTENTION
766 p_obj = NULL;
767#endif
768 for (i = 0; i < count; i++) {
769#ifdef ECHONET_CONTROLLER_EXTENTION
770 if(p_nod->eobjs == NULL)
771 p_obj = ecn_agent_next_eobj(p_nod, p_obj);
772 else
773 p_obj = p_nod->eobjs[i];
774#else
775 p_obj = p_nod->eobjs[i];
776#endif
777 if (p_obj->eojx1 != p_eoj->eojx1)
778 continue;
779 if (p_obj->eojx2 != p_eoj->eojx2)
780 continue;
781 /* ƒCƒ“ƒXƒ^ƒ“ƒXƒR[ƒh‚ª‚O‚̏ꍇA“¯‚¶ƒNƒ‰ƒX‚Ì‘S‚ẴCƒ“ƒXƒ^ƒ“ƒXˆ¶ */
782 if ((p_obj->eojx3 != p_eoj->eojx3) && (p_eoj->eojx3 != 0))
783 continue;
784
785 /* “d•¶ˆ—ŽÀs */
786 if (_ecn_tsk_ecn_msg_main(fa_fbs_id, p_obj, eobjatr, p_sobj, sobjatr) == 1)
787 a_fwd = true;
788 a_prc = true;
789 }
790 }
791 }
792 /* ‹@ŠíƒIƒuƒWƒFƒNƒg‚ªŒ©‚‚©‚ç‚È‚¢ê‡‚Å‚à */
793 if (!a_prc) {
794 /* “d•¶ˆ—ŽÀsi‰ž“šŽóM—pj */
795 if (_ecn_tsk_ecn_msg_main(fa_fbs_id, NULL, EPC_NONE, p_sobj, sobjatr) == 1)
796 a_fwd = true;
797 }
798
799 /* ‰ž“š‚̏ꍇƒAƒvƒŠƒP[ƒVƒ‡ƒ“‚É“]‘—‚·‚é */
800 if (a_fwd && (p_esv->ecn_hdr.tid == g_api_tid)) {
801 g_release_esv = false;
802
803 ECN_CAP_PUT( "redirect ecn_svc_mailboxid ¨ ecn_api_mailboxid (esv:0x%02X)",
804 p_esv->edata.esv );
805 fa_fbs_id.ptr->hdr.target.id = ENOD_API_ID;
806 a_ret = snd_mbx(ecn_api_mailboxid, (T_MSG *)fa_fbs_id.ptr);
807 if (a_ret != E_OK) {
808 syslog(LOG_WARNING, "_ecn_tsk_ecn_msg() : snd_mbx() result = %d:%s", a_ret, itron_strerror(a_ret));
809 _ecn_fbs_del(fa_fbs_id);
810 }
811 }
812#ifdef ECHONET_CONTROLLER_EXTENTION
813 ecn_agent_proc_ecn_msg_end();
814#endif
815}
816
817static int _ecn_tsk_ecn_msg_main(ECN_FBS_ID fa_fbs_id, const EOBJINIB *p_obj, ATR eobjatr,
818 const EOBJINIB *p_sobj, ATR sobjatr)
819{
820 int result;
821 T_ECN_EDT_HDR *p_esv;
822 ECN_FBS_ID a_fbs_anno = { NULL };
823 bool_t fromapp = sobjatr == EOBJ_LOCAL_NODE;
824
825 p_esv = &((T_EDATA *)fa_fbs_id.ptr)->hdr;
826
827 switch (p_esv->edata.esv) {
828 /* 0x60 ƒvƒƒpƒeƒB’l‘‚«ž‚Ý—v‹i‰ž“š•s—vj */
829 case ESV_SET_I:
830 if (!p_obj) {
831 ECN_DBG_PUT( "_ecn_tsk_ecn_msg_main() eoj %06X not found.",
832 p_esv->edata.deoj.eojx1 << 16 | p_esv->edata.deoj.eojx2 << 8 | p_esv->edata.deoj.eojx3 );
833 result = -1;
834 break;
835 }
836 _ecn_tsk_eoj_set(p_obj, eobjatr, fromapp, false, fa_fbs_id, ESV_NOP, ESV_SET_I_SNA, &a_fbs_anno); /* 0; 0x50 */
837 result = 0;
838 break;
839
840 /* 0x61 ƒvƒƒpƒeƒB’l‘‚«ž‚Ý—v‹i‰ž“š—vj */
841 case ESV_SET_C:
842 if (!p_obj) {
843 ECN_DBG_PUT( "_ecn_tsk_ecn_msg_main() eoj %06X not found.",
844 p_esv->edata.deoj.eojx1 << 16 | p_esv->edata.deoj.eojx2 << 8 | p_esv->edata.deoj.eojx3 );
845 result = -1;
846 break;
847 }
848 _ecn_tsk_eoj_set(p_obj, eobjatr, fromapp, false, fa_fbs_id, ESV_SET_RES, ESV_SET_C_SNA, &a_fbs_anno); /* 0x71; 0x51 */
849 result = 0;
850 break;
851
852 /* 0x62 ƒvƒƒpƒeƒB’l“ǂݏo‚µ—v‹ */
853 case ESV_GET:
854 if (!p_obj) {
855 ECN_DBG_PUT( "_ecn_tsk_ecn_msg_main() eoj %06X not found.",
856 p_esv->edata.deoj.eojx1 << 16 | p_esv->edata.deoj.eojx2 << 8 | p_esv->edata.deoj.eojx3 );
857 result = -1;
858 break;
859 }
860 _ecn_tsk_eoj_get(p_obj, eobjatr, false, EPC_RULE_GET, fa_fbs_id, ESV_GET_RES, ESV_GET_SNA); /* 0x72; 0x52 */
861 result = 0;
862 break;
863
864 /* 0x63 ƒvƒƒpƒeƒB’l’Ê’m—v‹ */
865 case ESV_INF_REQ:
866 if (!p_obj) {
867 ECN_DBG_PUT( "_ecn_tsk_ecn_msg_main() eoj %06X not found.",
868 p_esv->edata.deoj.eojx1 << 16 | p_esv->edata.deoj.eojx2 << 8 | p_esv->edata.deoj.eojx3 );
869 result = -1;
870 break;
871 }
872 fa_fbs_id.ptr->hdr.reply.id = ENOD_MULTICAST_ID;
873 _ecn_tsk_eoj_get(p_obj, eobjatr, false, (EPC_RULE_GET|EPC_RULE_ANNO), fa_fbs_id, ESV_INF, ESV_INF_SNA); /* 0x73; 0x53 */
874 result = 0;
875 break;
876
877 /* 0x6E ƒvƒƒpƒeƒB’l‘‚«ž‚݁E“ǂݏo‚µ—v‹ */
878 case ESV_SET_GET:
879 if (!p_obj) {
880 ECN_DBG_PUT( "_ecn_tsk_ecn_msg_main() eoj %06X not found.",
881 p_esv->edata.deoj.eojx1 << 16 | p_esv->edata.deoj.eojx2 << 8 | p_esv->edata.deoj.eojx3 );
882 result = -1;
883 break;
884 }
885 _ecn_tsk_eoj_set_get(p_obj, eobjatr, fromapp, fa_fbs_id, ESV_SET_GET_RES, ESV_SET_GET_SNA, &a_fbs_anno); /* 0x7E; 0x5E */
886 result = 0;
887 break;
888
889 /* 0x74 ƒvƒƒpƒeƒB’l’Ê’mi‰ž“š—vj */
890 case ESV_INFC:
891 if (!p_sobj)
892 _ecn_tsk_eoj_res(fa_fbs_id, ESV_INFC_RES, ESV_INFC_RES); /* 0x74; 0 */
893 else if (fromapp)
894 _ecn_tsk_eoj_get(p_sobj, sobjatr, true, (EPC_RULE_GET|EPC_RULE_ANNO), fa_fbs_id, ESV_INFC, ESV_NOP); /* 0x74; 0 */
895 else
896 _ecn_tsk_eoj_set(p_sobj, sobjatr, fromapp, true, fa_fbs_id, ESV_INFC_RES, ESV_INFC_RES, &a_fbs_anno); /* 0x7A; 0 */
897 result = 0;
898 break;
899
900 /* 0x60 ƒvƒƒpƒeƒB’l‘‚«ž‚Ý—v‹i‰ž“š•s—vj */
901 case ESV_SET_I_SNA: /* 0x50 ƒvƒƒpƒeƒB’l‘‚«ž‚Ý—v‹•s‰Â‰ž“š */
902 result = 1;
903 break;
904
905 /* 0x61 ƒvƒƒpƒeƒB’l‘‚«ž‚Ý—v‹i‰ž“š—vj */
906 case ESV_SET_RES: /* 0x71 ƒvƒƒpƒeƒB’l‘‚«ž‚݉ž“š */
907 case ESV_SET_C_SNA: /* 0x51 ƒvƒƒpƒeƒB’l‘‚«ž‚Ý—v‹•s‰Â‰ž“š */
908 result = 1;
909 break;
910
911 /* 0x62 ƒvƒƒpƒeƒB’l“ǂݏo‚µ—v‹ */
912 case ESV_GET_RES: /* 0x72 ƒvƒƒpƒeƒB’l“ǂݏo‚µ‰ž“š */
913 case ESV_GET_SNA: /* 0x52 ƒvƒƒpƒeƒB’l“ǂݏo‚µ•s‰Â‰ž“š */
914 if (!p_sobj) {
915 ECN_DBG_PUT( "_ecn_tsk_ecn_msg_main() eoj %06X not found.",
916 p_esv->edata.seoj.eojx1 << 16 | p_esv->edata.seoj.eojx2 << 8 | p_esv->edata.seoj.eojx3 );
917 result = -1;
918 break;
919 }
920 _ecn_tsk_eoj_set(p_sobj, sobjatr, fromapp, true, fa_fbs_id, ESV_NOP, ESV_NOP, &a_fbs_anno); /* 0; 0 */
921 result = 1;
922 break;
923
924 /* 0x63 ƒvƒƒpƒeƒB’l’Ê’m—v‹ */
925 case ESV_INF: /* 0x73 ƒvƒƒpƒeƒB’l’Ê’m */
926 case ESV_INF_SNA: /* 0x53 ƒvƒƒpƒeƒB’l’Ê’m•s‰Â‰ž“š */
927 if (!p_sobj) {
928 ECN_DBG_PUT( "_ecn_tsk_ecn_msg_main() eoj %06X not found.",
929 p_esv->edata.seoj.eojx1 << 16 | p_esv->edata.seoj.eojx2 << 8 | p_esv->edata.seoj.eojx3 );
930 result = -1;
931 break;
932 }
933 _ecn_tsk_eoj_set(p_sobj, sobjatr, fromapp, true, fa_fbs_id, ESV_NOP, ESV_NOP, &a_fbs_anno); /* 0; 0 */
934 result = 1;
935 break;
936
937 /* 0x6E ƒvƒƒpƒeƒB’l‘‚«ž‚݁E“ǂݏo‚µ—v‹ */
938 case ESV_SET_GET_RES: /* 0x7E ƒvƒƒpƒeƒB’l‘‚«ž‚݁E“ǂݏo‚µ‰ž“š */
939 case ESV_SET_GET_SNA: /* 0x5E ƒvƒƒpƒeƒB’l‘‚«ž‚݁E“ǂݏo‚µ•s‰Â‰ž“š */
940 if (!p_sobj) {
941 ECN_DBG_PUT( "_ecn_tsk_ecn_msg_main() eoj %06X not found.",
942 p_esv->edata.seoj.eojx1 << 16 | p_esv->edata.seoj.eojx2 << 8 | p_esv->edata.seoj.eojx3 );
943 result = -1;
944 break;
945 }
946 _ecn_tsk_eoj_set_get_res(p_sobj, sobjatr, fromapp, fa_fbs_id, &a_fbs_anno); /* 0x7A; 0 */
947 result = 1;
948 break;
949
950 /* 0x74 ƒvƒƒpƒeƒB’l’Ê’mi‰ž“š—vj */
951 case ESV_INFC_RES: /* 0x7A ƒvƒƒpƒeƒB’l’Ê’m‰ž“š */
952 result = 1;
953 break;
954
955 default:
956 syslog(LOG_WARNING, "_ecn_tsk_ecn_msg_main() esv 0x%02X undefined.", p_esv->edata.esv);
957 result = -1;
958 break;
959 }
960
961 /* ƒvƒƒpƒeƒB’Ê’m—v‹‚𑗐M */
962 if (a_fbs_anno.ptr != NULL) {
963 ER a_ret = _ecn_tsk_snd_mbx(a_fbs_anno, true);
964 if (a_ret != E_OK)
965 _ecn_fbs_del(a_fbs_anno);
966 }
967
968 return result;
969}
970
971#ifdef ECN_DBG_PUT_ENA
972static void f_put_fbs_eoj(const char *fp_fncnm, const char *fp_varnm,
973 ECN_FBS_ID fa_fbs_id);
974static void f_put_fbs_eoj(const char *fp_fncnm, const char *fp_varnm,
975 ECN_FBS_ID fa_fbs_id)
976{
977 ECN_DBG_PUT( "%s() %s eoj src:%06X dest:%06X",
978 fp_fncnm, fp_varnm,
979 ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.seoj.eojx1 << 16 | ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.seoj.eojx2 << 8 | ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.seoj.eojx3,
980 ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.deoj.eojx1 << 16 | ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.deoj.eojx2 << 8 | ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.deoj.eojx3 );
981}
982#else
983#define f_put_fbs_eoj(f,v,r)
984#endif /* #ifdef ECN_DBG_PUT_ENA */
985
986static const EPRPINIB *_ecn_tsk_eoj_get_property(const EOBJINIB *fp_obj, uint8_t fa_epc);
987static const EPRPINIB *_ecn_tsk_eoj_get_property(const EOBJINIB *fp_obj, uint8_t fa_epc)
988{
989 const EPRPINIB *p = fp_obj->eprp;
990 uint_t i;
991#ifdef ECHONET_CONTROLLER_EXTENTION
992 if (fp_obj->eprpcnt == 0) {
993 return ecn_agent_get_property(fp_obj, fa_epc, p);
994 }
995#endif
996 for (i = 0; i < fp_obj->eprpcnt; i++, p++) {
997 if (p->eprpcd != fa_epc)
998 continue;
999
1000 return p;
1001 }
1002 ECN_DBG_PUT( "_ecn_tsk_eoj_get_property(0x%02X-0x%02X-0x%02X, epc:0x%02X) not found.",
1003 fp_obj->eojx1, fp_obj->eojx2, fp_obj->eojx3,
1004 fa_epc );
1005
1006 return NULL;
1007}
1008
1009static int _ecn_tsk_eoj_set_edt(const EPRPINIB *fp_prp, void *fp_src, int fa_srcsz,
1010 bool_t *fa_anno);
1011static int _ecn_tsk_eoj_set_edt(const EPRPINIB *fp_prp, void *fp_src, int fa_srcsz,
1012 bool_t *fa_anno)
1013{
1014 if (!fp_prp->eprpset)
1015 return -1;
1016
1017 ECN_DBG_PUT( "_ecn_tsk_eoj_set_edt(epc:0x%02X) call eprpset()",
1018 fp_prp->eprpcd );
1019
1020 return fp_prp->eprpset(fp_prp, fp_src, fa_srcsz, fa_anno);
1021}
1022
1023static int _ecn_tsk_eoj_get_edt(const EPRPINIB *fp_prp, void *fp_dst, int fa_dstsz);
1024static int _ecn_tsk_eoj_get_edt(const EPRPINIB *fp_prp, void *fp_dst, int fa_dstsz)
1025{
1026 if (fa_dstsz < fp_prp->eprpsz)
1027 return -1;
1028 if (!fp_prp->eprpget)
1029 return -1;
1030
1031 ECN_DBG_PUT( "_ecn_tsk_eoj_get_edt(epc:0x%02X) call eprpget()",
1032 fp_prp->eprpcd );
1033
1034 return fp_prp->eprpget(fp_prp, fp_dst, fp_prp->eprpsz);
1035}
1036
1037static ID _ecn_tsk_get_prp_pce(ECN_FBS_ID fa_fbs_id, T_ECN_PRP *fp_prp,
1038 uint8_t *fp_blk);
1039
1040/*
1041 * ECN_FBS_ID‚©‚çT_ECN_PRP1Œ‚Æ‚»‚Ì•tƒf[ƒ^(edt)‚𒊏o‚µAedt‚̃|ƒCƒ“ƒ^‚ð•Ô‚·
1042 * ˆø”
1043 * ECN_FBS_ID fa_fbs_id “Ç‚ÝŽæ‚éFBS
1044 * T_ECN_PRP *fp_prp epc+pdc‚ÌŠi”[æ
1045 * uint8_t *fp_blk ì‹Æ—pƒƒ‚ƒŠ‚̃|ƒCƒ“ƒ^
1046 * ³íFƒ|ƒCƒ“ƒ^ NG:0
1047 */
1048static ID _ecn_tsk_get_prp_pce(ECN_FBS_ID fa_fbs_id, T_ECN_PRP *fp_prp,
1049 uint8_t *fp_blk)
1050{
1051 int a_size;
1052 ER a_ret;
1053
1054 memset(fp_blk, 0, sizeof(T_ECN_SUB_BLK));
1055
1056 /* T_ECN_PRP•”•ª(epc,pdc)‚ð“Ç‚ÝŽæ‚é */
1057 a_size = 0;
1058 a_ret = _ecn_fbs_get_data(fa_fbs_id, fp_prp, sizeof(*fp_prp), &a_size);
1059 if ((a_ret != 0) || a_size < (int)sizeof(*fp_prp)) {
1060 ECN_DBG_PUT( "_ecn_fbs_get_data() result = %d:%s", a_ret, itron_strerror(a_ret) );
1061 return E_OBJ;
1062 }
1063
1064 if (0 < fp_prp->pdc) {
1065 /* •tƒf[ƒ^•”•ª(edt)‚ð“Ç‚ÝŽæ‚é */
1066 a_size = 0;
1067 a_ret = _ecn_fbs_get_data(fa_fbs_id, fp_blk, fp_prp->pdc, &a_size);
1068 if ((a_ret != 0) || a_size < (int)fp_prp->pdc) {
1069 ECN_DBG_PUT( "_ecn_fbs_get_data() result = %d:%s", a_ret, itron_strerror(a_ret) );
1070 return E_OBJ;
1071 }
1072 }
1073
1074 return E_OK;
1075}
1076
1077static ER _ecn_tsk_eoj_set_main(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_fromapp, bool_t fa_update,
1078 ECN_FBS_ID fa_fbs_id, ECN_FBS_ID a_fbs_res, ECN_FBS_ID *fa_fbs_anno, int a_count,
1079 int *p_sw_ok);
1080/* ƒvƒƒpƒeƒB’l‘‚«ž‚ÝŽÀs */
1081static ER _ecn_tsk_eoj_set_main(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_fromapp, bool_t fa_update,
1082 ECN_FBS_ID fa_fbs_id, ECN_FBS_ID a_fbs_res, ECN_FBS_ID *fa_fbs_anno, int a_count,
1083 int *p_sw_ok)
1084{
1085 uint8_t p_edt[256];
1086 T_ECN_PRP a_prp; /* epc+pdc */
1087 const EPRPINIB *a_eprp;
1088 int i, a_ans;
1089 ER a_ret;
1090 uint8_t a_size;
1091 bool_t a_anno = false, a_update;
1092
1093 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc = 0;
1094
1095 for (i = 0; i < a_count; i++) {
1096 /* ECN_FBS_ID‚©‚çT_ECN_PRP1Œ‚Æ‚»‚Ì•tƒf[ƒ^‚𒊏o‚µA‚»‚̃|ƒCƒ“ƒ^‚ð•Ô‚· */
1097 a_ret = _ecn_tsk_get_prp_pce(fa_fbs_id, &a_prp, p_edt);
1098 if (a_ret != E_OK) {
1099 ECN_DBG_PUT( "_ecn_tsk_eoj_set_main(): _ecn_tsk_get_prp_pce() fault." );
1100 goto lb_except;
1101 }
1102
1103 /* ƒvƒƒpƒeƒB‚̐ݒè set_prp(obj, reqp, resp) */
1104 a_size = a_prp.pdc;
1105 /* obj,epc‚ɑΉž‚·‚ésetŠÖ”‚ðŒÄ‚Ô */
1106 a_eprp = _ecn_tsk_eoj_get_property(fp_obj, a_prp.epc);
1107 if ((a_eprp != NULL)
1108 && (fa_update || (((a_eprp->eprpatr & EPC_RULE_SET) != 0) || fa_fromapp))) {
1109 a_anno = (fa_eobjatr == EOBJ_LOCAL_NODE) && ((a_eprp->eprpatr & EPC_ANNOUNCE) != 0);
1110 a_update = a_anno;
1111 a_ans = _ecn_tsk_eoj_set_edt(a_eprp, p_edt, a_size, &a_update);
1112 if (a_anno && (a_ans > 0))
1113 a_anno = a_update;
1114 }
1115 else {
1116 a_ans = -1;
1117 }
1118 if (a_ans == a_size) {
1119 ECN_DBG_PUT( "_ecn_tsk_eoj_set_edt(0x%06X, 0x%02x, 0x%02X..., %u) ok.",
1120 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1121 a_prp.epc, p_edt[0], a_size );
1122 a_prp.pdc = 0;
1123 } else {
1124 ECN_DBG_PUT( "_ecn_tsk_eoj_set_edt(0x%06X, 0x%02x, 0x%02X..., %u) fault.",
1125 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1126 a_prp.epc, p_edt[0], a_size );
1127 *p_sw_ok = 0; /* ƒvƒƒpƒeƒBÝ’莸”s */
1128 /* ‰ž“šˆ—‚̏ꍇEDT‚͐ݒ肵‚È‚¢ */
1129 if (fa_update)
1130 a_prp.pdc = 0;
1131 }
1132
1133 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ(epc,pdc‚Ì2byte) */
1134 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, &a_prp, sizeof(a_prp));
1135 if (a_ret) {
1136 ECN_DBG_PUT( "_ecn_fbs_add_data_ex() result = %d:%s", a_ret, itron_strerror(a_ret) );
1137 goto lb_except;
1138 }
1139
1140 if (0 < a_prp.pdc) {
1141 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ(edt n-byte) */
1142 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, p_edt, a_prp.pdc);
1143 if (a_ret) {
1144 ECN_DBG_PUT( "_ecn_fbs_add_data_ex() result = %d:%s", a_ret, itron_strerror(a_ret) );
1145 goto lb_except;
1146 }
1147 }
1148 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc ++;
1149
1150 /* ƒvƒƒpƒeƒB’Ê’m‚ ‚è‚̏ꍇ */
1151 if (a_anno && (a_ans == a_size)) {
1152 if (fa_fbs_anno->ptr == NULL) {
1153 _ecn_tsk_mk_esv(fa_fbs_anno, (ID)1, (((intptr_t)fp_obj - (intptr_t)eobjinib_table) / sizeof(EPRPINIB)) + 1,
1154 a_prp.epc, 0, NULL, ESV_INF_REQ);
1155 }
1156 else{
1157 ecn_add_edt((T_EDATA *)fa_fbs_anno->ptr, a_prp.epc, 0, 0);
1158 }
1159 }
1160 }
1161 a_ret = E_OK; /* ok */
1162 goto lb_finally;
1163
1164lb_except:
1165 a_ret = E_SYS;
1166
1167lb_finally:
1168 return a_ret;
1169}
1170
1171static ER _ecn_tsk_eoj_get_main(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_forward, ATR fa_access,
1172 ECN_FBS_ID fa_fbs_id, ECN_FBS_ID a_fbs_res, int a_count, int *p_sw_ok);
1173/* ƒvƒƒpƒeƒB’l“ǂݏo‚µŽÀs */
1174static ER _ecn_tsk_eoj_get_main(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_forward, ATR fa_access,
1175 ECN_FBS_ID fa_fbs_id, ECN_FBS_ID a_fbs_res, int a_count, int *p_sw_ok)
1176{
1177 uint8_t p_edt[256]; /* ì‹Æ—̈æ */
1178 const EPRPINIB *a_eprp;
1179 ER a_ret = E_SYS;
1180 T_ECN_PRP a_prp; /* epc+pdc */
1181 int i, a_ans;
1182
1183 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc = 0;
1184
1185 for (i = 0; i < a_count; i++) {
1186 /* ECN_FBS_ID‚©‚çT_ECN_PRP1Œ‚Æ‚»‚Ì•tƒf[ƒ^‚𒊏o */
1187 a_ret = _ecn_tsk_get_prp_pce(fa_fbs_id, &a_prp, p_edt);
1188 if (a_ret != E_OK) {
1189 ECN_DBG_PUT( "_ecn_tsk_eoj_get_main(): _ecn_tsk_get_prp_pce() fault." );
1190 goto lb_except;
1191 }
1192
1193 /* ƒvƒƒpƒeƒB‚̎擾 get_eprp(obj, reqp, resp, size) */
1194 memset(p_edt, 0, sizeof(p_edt));
1195 /* obj,epc‚ɑΉž‚·‚égetŠÖ”‚ðŒÄ‚Ô */
1196 a_eprp = _ecn_tsk_eoj_get_property(fp_obj, a_prp.epc);
1197 if ((a_eprp != NULL) && (((a_eprp->eprpatr & fa_access) != 0) && (fa_eobjatr == EOBJ_LOCAL_NODE) || fa_forward)) {
1198 a_ans = _ecn_tsk_eoj_get_edt(a_eprp, p_edt, sizeof(p_edt));
1199 }
1200 else {
1201 a_ans = -1;
1202 }
1203 if (0 < a_ans && a_ans <= (int)UINT8_MAX) {
1204 a_prp.pdc = (uint8_t)a_ans;
1205 } else {
1206 *p_sw_ok = 0; /* ƒvƒƒpƒeƒBŽæ“¾Ž¸”s */
1207 a_ans = 0;
1208 a_prp.pdc = 0;
1209 }
1210
1211 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ(epc,pdc‚Ì2byte) */
1212 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, &a_prp, sizeof(a_prp));
1213 if (a_ret) {
1214 ECN_DBG_PUT( "_ecn_fbs_add_data_ex() result = %d:%s", a_ret, itron_strerror(a_ret) );
1215 goto lb_except;
1216 }
1217 if (0 < a_ans) {
1218 /* •tƒf[ƒ^’ljÁ */
1219 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, p_edt, a_ans);
1220 if (a_ret) {
1221 ECN_DBG_PUT( "_ecn_fbs_add_data_ex() result = %d:%s", a_ret, itron_strerror(a_ret) );
1222 goto lb_except;
1223 }
1224 }
1225 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc ++;
1226 }
1227 a_ret = E_OK; /* ok */
1228 goto lb_finally;
1229
1230lb_except:
1231 a_ret = E_SYS;
1232
1233lb_finally:
1234 return a_ret;
1235}
1236
1237static ER _ecn_tsk_eoj_res_main(ECN_FBS_ID fa_fbs_id, ECN_FBS_ID a_fbs_res, int a_count, int *p_sw_ok);
1238/* ƒvƒƒpƒeƒB’l“ǂݏo‚µŽÀs */
1239static ER _ecn_tsk_eoj_res_main(ECN_FBS_ID fa_fbs_id, ECN_FBS_ID a_fbs_res, int a_count, int *p_sw_ok)
1240{
1241 uint8_t p_edt[256];
1242 ER a_ret = E_SYS;
1243 T_ECN_PRP a_prp; /* epc+pdc */
1244 int i;
1245
1246 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc = 0;
1247
1248 for (i = 0; i < a_count; i++) {
1249 /* ECN_FBS_ID‚©‚çT_ECN_PRP1Œ‚Æ‚»‚Ì•tƒf[ƒ^‚𒊏o */
1250 a_ret = _ecn_tsk_get_prp_pce(fa_fbs_id, &a_prp, p_edt);
1251 if (a_ret != E_OK) {
1252 ECN_DBG_PUT( "_ecn_tsk_eoj_get_main(): _ecn_tsk_get_prp_pce() fault." );
1253 goto lb_except;
1254 }
1255
1256 a_prp.pdc = 0;
1257
1258 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ(epc,pdc‚Ì2byte) */
1259 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, &a_prp, sizeof(a_prp));
1260 if (a_ret) {
1261 ECN_DBG_PUT( "_ecn_fbs_add_data_ex() result = %d:%s", a_ret, itron_strerror(a_ret) );
1262 goto lb_except;
1263 }
1264 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc++;
1265 }
1266 a_ret = E_OK; /* ok */
1267 goto lb_finally;
1268
1269lb_except:
1270 a_ret = E_SYS;
1271
1272lb_finally:
1273 return a_ret;
1274}
1275
1276/* ƒvƒƒpƒeƒB’l“Ç‚Ý”ò‚΂µŽÀs */
1277static ER _ecn_tsk_eoj_skip_main(const EOBJINIB *fp_obj, ECN_FBS_ID fa_fbs_id,
1278 int a_count);
1279static ER _ecn_tsk_eoj_skip_main(const EOBJINIB *fp_obj, ECN_FBS_ID fa_fbs_id,
1280 int a_count)
1281{
1282 T_ECN_PRP a_prp; /* epc+pdc */
1283 int i, a_size;
1284 ER a_ret;
1285
1286 for (i = 0; i < a_count; i++) {
1287 /* T_ECN_PRP•”•ª(epc,pdc)‚ð“Ç‚ÝŽæ‚é */
1288 a_size = 0;
1289 a_ret = _ecn_fbs_get_data(fa_fbs_id, &a_prp, sizeof(a_prp), &a_size);
1290 if (a_ret || a_size < (int)sizeof(a_prp)) {
1291 ECN_DBG_PUT( "_ecn_fbs_get_data() result = %d:%s", a_ret, itron_strerror(a_ret) );
1292 goto lb_except;
1293 }
1294
1295 /* pdc•ª“Ç‚Ý”ò‚΂µ */
1296 a_ret = _ecn_fbs_seek_rpos(fa_fbs_id, a_prp.pdc);
1297 if (a_ret) {
1298 ECN_DBG_PUT( "_ecn_fbs_seek_rpos() result = %d:%s", a_ret, itron_strerror(a_ret) );
1299 goto lb_except;
1300 }
1301 }
1302 a_ret = E_OK; /* ok */
1303 goto lb_finally;
1304
1305lb_except:
1306 a_ret = E_SYS;
1307
1308lb_finally:
1309 return a_ret;
1310}
1311
1312static void _ecn_tsk_mk_rsp_hdr(const EOBJINIB *fp_obj, T_ECN_EDT_HDR *fp_rsp_esv,
1313 T_ECN_EDT_HDR const *fp_req_esv);
1314/* ‰ž“š“d•¶Ý’è */
1315static void _ecn_tsk_mk_rsp_hdr(const EOBJINIB *fp_obj, T_ECN_EDT_HDR *fp_rsp_esv,
1316 T_ECN_EDT_HDR const *fp_req_esv)
1317{
1318 fp_rsp_esv->ecn_hdr.ehd1 = ECN_EDH1_ECHONET_LITE;
1319 fp_rsp_esv->ecn_hdr.ehd2 = ECN_EDH2_FORMAT_1;
1320 fp_rsp_esv->ecn_hdr.tid = fp_req_esv->ecn_hdr.tid;
1321 fp_rsp_esv->edata.seoj.eojx1 = fp_obj->eojx1;
1322 fp_rsp_esv->edata.seoj.eojx2 = fp_obj->eojx2;
1323 fp_rsp_esv->edata.seoj.eojx3 = fp_obj->eojx3;
1324 fp_rsp_esv->edata.deoj = fp_req_esv->edata.seoj;
1325}
1326
1327static void _ecn_tsk_mk_rsp_hdr_res(T_ECN_EDT_HDR *fp_rsp_esv,
1328 T_ECN_EDT_HDR const *fp_req_esv);
1329static void _ecn_tsk_mk_rsp_hdr_res(T_ECN_EDT_HDR *fp_rsp_esv,
1330 T_ECN_EDT_HDR const *fp_req_esv)
1331{
1332 fp_rsp_esv->ecn_hdr.ehd1 = ECN_EDH1_ECHONET_LITE;
1333 fp_rsp_esv->ecn_hdr.ehd2 = ECN_EDH2_FORMAT_1;
1334 fp_rsp_esv->ecn_hdr.tid = fp_req_esv->ecn_hdr.tid;
1335 fp_rsp_esv->edata.seoj = fp_req_esv->edata.deoj;
1336 fp_rsp_esv->edata.deoj = fp_req_esv->edata.seoj;
1337}
1338
1339/* ‰ž“š“d•¶—pfbsÝ’è */
1340static void _ecn_tsk_set_rsp_fbs(ECN_FBS_ID fa_rsp_fbs, T_ECN_FST_BLK const *fp_req_ptr);
1341/* ‰ž“š“d•¶—pfbsÝ’è(sender/target‚̐ݒè) */
1342static void _ecn_tsk_set_rsp_fbs(ECN_FBS_ID fa_rsp_fbs, T_ECN_FST_BLK const *fp_req_ptr)
1343{
1344 fa_rsp_fbs.ptr->hdr.type = ECN_MSG_ECHONET;
1345 fa_rsp_fbs.ptr->hdr.sender.id = ENOD_LOCAL_ID;
1346 fa_rsp_fbs.ptr->hdr.target.id = fp_req_ptr->hdr.reply.id;
1347 fa_rsp_fbs.ptr->hdr.reply.id = ENOD_LOCAL_ID;
1348}
1349
1350/* ƒvƒƒpƒeƒB’l‘‚«ž‚Ý—v‹ */
1351static void _ecn_tsk_eoj_set(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_fromapp, bool_t fa_update,
1352 ECN_FBS_ID fa_fbs_id, ECN_SRV_CODE fa_res_esv, ECN_SRV_CODE fa_sna_esv,
1353 ECN_FBS_ID *fa_fbs_anno)
1354{
1355 T_ECN_EDT_HDR const *p_req_esv = &((T_EDATA *)fa_fbs_id.ptr)->hdr;
1356 T_ECN_EDT_HDR a_ecn_hdp;
1357 ECN_FBS_ID a_fbs_res = { 0 };
1358 ER a_ret;
1359 int a_size;
1360 int a_sw_ok = 1;
1361 T_ECN_EOJ eoj;
1362
1363 memset(&a_ecn_hdp, 0, sizeof(a_ecn_hdp));
1364
1365 /* ‰ž“šÅ‘åƒTƒCƒY‚̎擾 */
1366 a_size = sizeof(T_ECN_HDR) + sizeof(T_ECN_EDATA_BODY) + sizeof(T_ECN_PRP);
1367
1368 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚̎擾 */
1369 a_ret = _ecn_fbs_cre(a_size, &a_fbs_res);
1370 if (a_ret != E_OK || !a_fbs_res.ptr) /* Šm•ÛŽ¸”s */
1371 return;
1372
1373 /* ‰ž“š“d•¶Ý’è */
1374 if(p_req_esv->edata.deoj.eojx3 != 0)
1375 _ecn_tsk_mk_rsp_hdr_res(&a_ecn_hdp, p_req_esv);
1376 else
1377 _ecn_tsk_mk_rsp_hdr(fp_obj, &a_ecn_hdp, p_req_esv);
1378
1379 /* ³íŽž‚̉ž“š“d•¶‚ªƒvƒƒpƒeƒB’l’Ê’m‰ž“š‚̏ꍇ */
1380 if (fa_res_esv == ESV_INFC_RES) {
1381 /* ‘—MŒ³‚ƈ¶æ‚ð“ü‚ê‘Ö‚¦ */
1382 eoj = a_ecn_hdp.edata.seoj;
1383 a_ecn_hdp.edata.seoj = a_ecn_hdp.edata.deoj;
1384 a_ecn_hdp.edata.deoj = eoj;
1385 }
1386
1387 f_put_fbs_eoj("_ecn_tsk_eoj_set", "fa_fbs_id", fa_fbs_id); /* s/deoj ƒfƒoƒbƒOo—Í */
1388
1389 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ */
1390 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, &a_ecn_hdp,
1391 sizeof(a_ecn_hdp.ecn_hdr) + sizeof(a_ecn_hdp.edata));
1392 if (a_ret)
1393 goto lb_except;
1394
1395 /* payloadæ“ª‚ÌT_ECN_HDR(ecn_hdr), T_ECN_EDATA_BODY(edata)‚ð“Ç‚Ý”ò‚΂· */
1396 a_ret = _ecn_fbs_set_rpos(fa_fbs_id, offsetof(T_ECN_EDT_HDR, ecn_prp));
1397 if (a_ret)
1398 goto lb_except;
1399
1400 /* ‰ž“š“d•¶—pfbsÝ’è */
1401 _ecn_tsk_set_rsp_fbs(a_fbs_res, fa_fbs_id.ptr);
1402
1403 /* ƒvƒƒpƒeƒB’l‘‚«ž‚ÝŽÀs */
1404 a_ret = _ecn_tsk_eoj_set_main(fp_obj, fa_eobjatr, fa_fromapp, fa_update, fa_fbs_id, a_fbs_res,
1405 fa_fbs_anno, p_req_esv->edata.opc, &a_sw_ok);
1406 if (a_ret)
1407 goto lb_except;
1408
1409 /* ‰ž“š—v‚̏ꍇ */
1410 if (a_sw_ok) {
1411 if (!fa_res_esv) {
1412 /* ‰ž“š•s—v‚̏ꍇ */
1413 _ecn_fbs_del(a_fbs_res);
1414 goto lb_finally;
1415 }
1416 /* Ý’菈—¬Œ÷ */
1417 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.esv = fa_res_esv;
1418 } else {
1419 if (!fa_sna_esv) {
1420 /* ‰ž“š•s—v‚̏ꍇ */
1421 _ecn_fbs_del(a_fbs_res);
1422 goto lb_finally;
1423 }
1424 /* Ý’菈—Ž¸”s */
1425 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.esv = fa_sna_esv;
1426 }
1427 /* ‰ž“š‘—M */
1428 a_ret = _ecn_tsk_snd_mbx(a_fbs_res, false);
1429 if (a_ret == E_OK)
1430 goto lb_finally;
1431
1432lb_except:
1433 /* ƒf[ƒ^‘—MŽ¸”s‚µ‚½‚ç—̈æ‰ð•ú */
1434 if (a_fbs_res.ptr)
1435 _ecn_fbs_del(a_fbs_res);
1436
1437lb_finally:
1438 return;
1439}
1440
1441/* ƒvƒƒpƒeƒB’l“ǂݏo‚µ—v‹ */
1442static void _ecn_tsk_eoj_get(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_forward, ATR fa_access,
1443 ECN_FBS_ID fa_fbs_id, ECN_SRV_CODE fa_res_esv, ECN_SRV_CODE fa_sna_esv)
1444{
1445 T_ECN_EDT_HDR const *p_req_esv = &((T_EDATA *)fa_fbs_id.ptr)->hdr;
1446 T_ECN_EDT_HDR a_ecn_hdp;
1447 ECN_FBS_ID a_fbs_res = { 0 };
1448 ER a_ret;
1449 int a_size;
1450 int a_sw_ok = 1;
1451
1452 memset(&a_ecn_hdp, 0, sizeof(a_ecn_hdp));
1453
1454 /* ‰ŠúŽæ“¾ƒTƒCƒY */
1455 a_size = sizeof(T_ECN_HDR) + sizeof(T_ECN_EDATA_BODY) + sizeof(T_ECN_PRP);
1456
1457 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚̎擾 */
1458 a_ret = _ecn_fbs_cre(a_size, &a_fbs_res);
1459 if (a_ret != E_OK || !a_fbs_res.ptr) { /* Šm•ÛŽ¸”s */
1460 ECN_DBG_PUT( "_ecn_fbs_cre() result = %d:%s", a_ret, itron_strerror(a_ret) );
1461 goto lb_finally;
1462 }
1463
1464 /* ‰ž“š“d•¶Ý’è */
1465 if(p_req_esv->edata.deoj.eojx3 != 0)
1466 _ecn_tsk_mk_rsp_hdr_res(&a_ecn_hdp, p_req_esv);
1467 else
1468 _ecn_tsk_mk_rsp_hdr(fp_obj, &a_ecn_hdp, p_req_esv);
1469
1470 f_put_fbs_eoj("_ecn_tsk_eoj_get", "fa_fbs_id", fa_fbs_id); /* s/deoj ƒfƒoƒbƒOo—Í */
1471
1472 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ */
1473 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, &a_ecn_hdp,
1474 sizeof(a_ecn_hdp.ecn_hdr) + sizeof(a_ecn_hdp.edata));
1475 if (a_ret) {
1476 ECN_DBG_PUT( "_ecn_fbs_add_data_ex() result = %d:%s", a_ret, itron_strerror(a_ret) );
1477 goto lb_except;
1478 }
1479
1480 /* payloadæ“ª‚ÌT_ECN_HDR(ecn_hdr), T_ECN_EDATA_BODY(edata)‚ð“Ç‚Ý”ò‚΂· */
1481 a_ret = _ecn_fbs_set_rpos(fa_fbs_id, offsetof(T_ECN_EDT_HDR, ecn_prp));
1482 if (a_ret) {
1483 ECN_DBG_PUT( "_ecn_fbs_set_rpos() result = %d:%s", a_ret, itron_strerror(a_ret) );
1484 goto lb_except;
1485 }
1486
1487 /* ‰ž“š“d•¶—pfbsÝ’è */
1488 _ecn_tsk_set_rsp_fbs(a_fbs_res, fa_fbs_id.ptr);
1489
1490 /* ƒvƒƒpƒeƒB’l“ǂݍž‚ÝŽÀs */
1491 a_ret = _ecn_tsk_eoj_get_main(fp_obj, fa_eobjatr, fa_forward, fa_access, fa_fbs_id, a_fbs_res,
1492 ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.opc, &a_sw_ok);
1493 if (a_ret) {
1494 ECN_DBG_PUT( "_ecn_tsk_eoj_get_main() result = %d:%s", a_ret, itron_strerror(a_ret) );
1495 goto lb_except;
1496 }
1497
1498 if (a_sw_ok) {
1499 if (!fa_res_esv) {
1500 /* ‰ž“š•s—v‚̏ꍇ */
1501 _ecn_fbs_del(a_fbs_res);
1502 goto lb_finally;
1503 }
1504 /* Ý’菈—¬Œ÷ */
1505 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.esv = fa_res_esv;
1506 } else {
1507 if (!fa_sna_esv) {
1508 /* ‰ž“š•s—v‚̏ꍇ */
1509 _ecn_fbs_del(a_fbs_res);
1510 goto lb_finally;
1511 }
1512 /* Ý’菈—Ž¸”s */
1513 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.esv = fa_sna_esv;
1514 }
1515 /* ‰ž“š‘—M */
1516 a_ret = _ecn_tsk_snd_mbx(a_fbs_res, false);
1517 if (a_ret != E_OK) {
1518 ECN_DBG_PUT( "_ecn_tsk_snd_mbx() result = %d:%s", a_ret, itron_strerror(a_ret) );
1519 goto lb_except;
1520 }
1521 goto lb_finally;
1522
1523lb_except:
1524 /* ƒf[ƒ^‘—MŽ¸”s‚µ‚½‚ç—̈æ‰ð•ú */
1525 if (a_fbs_res.ptr)
1526 _ecn_fbs_del(a_fbs_res);
1527
1528lb_finally:
1529 return;
1530}
1531
1532/* ƒvƒƒpƒeƒB’l“ǂݏo‚µ—v‹ */
1533static void _ecn_tsk_eoj_res(ECN_FBS_ID fa_fbs_id, ECN_SRV_CODE fa_res_esv,
1534 ECN_SRV_CODE fa_sna_esv)
1535{
1536 T_ECN_EDT_HDR const *p_req_esv = &((T_EDATA *)fa_fbs_id.ptr)->hdr;
1537 T_ECN_EDT_HDR a_ecn_hdp;
1538 ECN_FBS_ID a_fbs_res = { 0 };
1539 ER a_ret;
1540 int a_size;
1541 int a_sw_ok = 1;
1542
1543 memset(&a_ecn_hdp, 0, sizeof(a_ecn_hdp));
1544
1545 /* ‰ŠúŽæ“¾ƒTƒCƒY */
1546 a_size = sizeof(T_ECN_HDR) + sizeof(T_ECN_EDATA_BODY) + sizeof(T_ECN_PRP);
1547
1548 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚̎擾 */
1549 a_ret = _ecn_fbs_cre(a_size, &a_fbs_res);
1550 if (a_ret != E_OK || !a_fbs_res.ptr) { /* Šm•ÛŽ¸”s */
1551 ECN_DBG_PUT( "_ecn_fbs_cre() result = %d:%s", a_ret, itron_strerror(a_ret) );
1552 goto lb_finally;
1553 }
1554
1555 /* ‰ž“š“d•¶Ý’è */
1556 _ecn_tsk_mk_rsp_hdr_res(&a_ecn_hdp, p_req_esv);
1557
1558 f_put_fbs_eoj("_ecn_tsk_eoj_res", "fa_fbs_id", fa_fbs_id); /* s/deoj ƒfƒoƒbƒOo—Í */
1559
1560 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ */
1561 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, &a_ecn_hdp,
1562 sizeof(a_ecn_hdp.ecn_hdr) + sizeof(a_ecn_hdp.edata));
1563 if (a_ret) {
1564 ECN_DBG_PUT( "_ecn_fbs_add_data_ex() result = %d:%s", a_ret, itron_strerror(a_ret) );
1565 goto lb_except;
1566 }
1567
1568 /* payloadæ“ª‚ÌT_ECN_HDR(ecn_hdr), T_ECN_EDATA_BODY(edata)‚ð“Ç‚Ý”ò‚΂· */
1569 a_ret = _ecn_fbs_set_rpos(fa_fbs_id, offsetof(T_ECN_EDT_HDR, ecn_prp));
1570 if (a_ret) {
1571 ECN_DBG_PUT( "_ecn_fbs_set_rpos() result = %d:%s", a_ret, itron_strerror(a_ret) );
1572 goto lb_except;
1573 }
1574
1575 /* ‰ž“š“d•¶—pfbsÝ’è */
1576 _ecn_tsk_set_rsp_fbs(a_fbs_res, fa_fbs_id.ptr);
1577
1578 /* ƒvƒƒpƒeƒB’l“ǂݍž‚ÝŽÀs */
1579 a_ret = _ecn_tsk_eoj_res_main(fa_fbs_id, a_fbs_res,
1580 ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.opc, &a_sw_ok);
1581 if (a_ret) {
1582 ECN_DBG_PUT( "_ecn_tsk_eoj_res_main() result = %d:%s", a_ret, itron_strerror(a_ret) );
1583 goto lb_except;
1584 }
1585
1586 if (a_sw_ok) {
1587 if (!fa_res_esv) {
1588 /* ‰ž“š•s—v‚̏ꍇ */
1589 _ecn_fbs_del(a_fbs_res);
1590 goto lb_finally;
1591 }
1592 /* Ý’菈—¬Œ÷ */
1593 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.esv = fa_res_esv;
1594 } else {
1595 if (!fa_sna_esv) {
1596 /* ‰ž“š•s—v‚̏ꍇ */
1597 _ecn_fbs_del(a_fbs_res);
1598 goto lb_finally;
1599 }
1600 /* Ý’菈—Ž¸”s */
1601 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.esv = fa_sna_esv;
1602 }
1603 /* ‰ž“š‘—M */
1604 a_ret = _ecn_tsk_snd_mbx(a_fbs_res, false);
1605 if (a_ret != E_OK) {
1606 ECN_DBG_PUT( "_ecn_tsk_snd_mbx() result = %d:%s", a_ret, itron_strerror(a_ret) );
1607 goto lb_except;
1608 }
1609 goto lb_finally;
1610
1611lb_except:
1612 /* ƒf[ƒ^‘—MŽ¸”s‚µ‚½‚ç—̈æ‰ð•ú */
1613 if (a_fbs_res.ptr)
1614 _ecn_fbs_del(a_fbs_res);
1615
1616lb_finally:
1617 return;
1618}
1619
1620static void _ecn_tsk_eoj_set_get(const EOBJINIB *fp_obj, ATR fa_eobjatr, bool_t fa_fromapp,
1621 ECN_FBS_ID fa_fbs_id, ECN_SRV_CODE fa_res_esv, ECN_SRV_CODE fa_sna_esv,
1622 ECN_FBS_ID *fa_fbs_anno)
1623{
1624 T_ECN_EDT_HDR const *p_req_esv = &((T_EDATA *)fa_fbs_id.ptr)->hdr;
1625 T_ECN_EDT_HDR a_ecn_hdp;
1626 ECN_FBS_ID a_fbs_res = { 0 };
1627 int a_rdprp_wrpos; /* ƒvƒƒpƒeƒB“ǂݍž‚ÝŒ”‘‚«ž‚ÝŽž‚̃wƒbƒhˆÊ’u */
1628 ER a_ret;
1629 int i, a_size, a_rdlen;
1630 int a_sw_ok = 1;
1631 int a_count = ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.opc; /* ˆ—ƒvƒƒpƒeƒB” */
1632
1633 memset(&a_ecn_hdp, 0, sizeof(a_ecn_hdp));
1634
1635 ECN_DBG_PUT( "_ecn_tsk_eoj_set_get() eoj:%06X",
1636 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3 );
1637
1638 /* ‰ŠúŽæ“¾ƒTƒCƒY */
1639 a_size = sizeof(T_ECN_HDR) + sizeof(T_ECN_EDATA_BODY) + sizeof(T_ECN_PRP);
1640
1641 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚̎擾 */
1642 a_ret = _ecn_fbs_cre(a_size, &a_fbs_res);
1643 if (a_ret != E_OK || !a_fbs_res.ptr) /* Šm•ÛŽ¸”s */
1644 goto lb_finally;
1645
1646 /* ‰ž“š“d•¶Ý’è */
1647 if(p_req_esv->edata.deoj.eojx3 != 0)
1648 _ecn_tsk_mk_rsp_hdr_res(&a_ecn_hdp, p_req_esv);
1649 else
1650 _ecn_tsk_mk_rsp_hdr(fp_obj, &a_ecn_hdp, p_req_esv);
1651 a_size -= sizeof(T_ECN_HDR) + sizeof(T_ECN_EDATA_BODY);
1652
1653 f_put_fbs_eoj("_ecn_tsk_eoj_set_get", "fa_fbs_id", fa_fbs_id); /* s/deoj ƒfƒoƒbƒOo—Í */
1654
1655 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ */
1656 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, &a_ecn_hdp,
1657 sizeof(a_ecn_hdp.ecn_hdr) + sizeof(a_ecn_hdp.edata));
1658 if (a_ret)
1659 goto lb_except;
1660
1661 /* payloadæ“ª‚ÌT_ECN_HDR(ecn_hdr), T_ECN_EDATA_BODY(edata)‚ð“Ç‚Ý”ò‚΂· */
1662 a_ret = _ecn_fbs_set_rpos(fa_fbs_id, offsetof(T_ECN_EDT_HDR, ecn_prp));
1663 if (a_ret)
1664 goto lb_except;
1665
1666 /* ‰ž“š“d•¶—pfbsÝ’è */
1667 _ecn_tsk_set_rsp_fbs(a_fbs_res, fa_fbs_id.ptr);
1668
1669 /* ƒvƒƒpƒeƒB’l‘‚«ž‚ÝŽÀs */
1670 a_ret = _ecn_tsk_eoj_set_main(fp_obj, fa_eobjatr, fa_fromapp, false, fa_fbs_id, a_fbs_res,
1671 fa_fbs_anno, a_count, &a_sw_ok);
1672 if (a_ret) {
1673 syslog(LOG_WARNING, "_ecn_tsk_eoj_set_get() eoj:%06X _ecn_tsk_eoj_set_main() fault. result = %d",
1674 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1675 a_ret);
1676 goto lb_except;
1677 }
1678 ECN_DBG_PUT( "_ecn_tsk_eoj_set_get() eoj:%06X _ecn_tsk_eoj_set_main() ok sw_ok:%s",
1679 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1680 (a_sw_ok ? "true" : "false") );
1681
1682 /* ŽŸ‚ÌŒ”‚ð“Ç‚ÝŽæ‚é(1byte) */
1683 /* ¨ ECHONET-Lite_Ver.1.10_02.pdf p.40 [OPCGet] */
1684 a_rdlen = i = 0;
1685 a_ret = _ecn_fbs_get_data(fa_fbs_id, &i, 1, &a_rdlen);
1686 if (a_ret < 0 || a_rdlen < 1)
1687 goto lb_except; /* NG */
1688 a_count = *(uint8_t *)&i;
1689
1690 /* ƒvƒƒpƒeƒB“ǂݍž‚ÝŒ”‘‚«ž‚ÝŽž‚̃wƒbƒhî•ñ‚ð‹L˜^ */
1691 a_rdprp_wrpos = _ecn_fbs_get_datalen(a_fbs_res);
1692
1693 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ (OPCGet 1byte) */
1694 a_ret = _ecn_fbs_add_data_ex(a_fbs_res, &i, 1);
1695 if (a_ret)
1696 goto lb_except;
1697
1698 /* ‚±‚ÌŽž“_‚ł̉ž“š“d•¶’†ƒvƒƒpƒeƒBŒ”‚ð‹L˜^ */
1699 i = ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc;
1700 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc = 0;
1701
1702 /* ƒvƒƒpƒeƒB’l“ǂݍž‚ÝŽÀs */
1703 a_ret = _ecn_tsk_eoj_get_main(fp_obj, fa_eobjatr, false, EPC_RULE_GET, fa_fbs_id, a_fbs_res,
1704 a_count, &a_sw_ok);
1705 if (a_ret) {
1706 syslog(LOG_WARNING, "%s _ecn_tsk_eoj_set_get() eoj:%06X _ecn_tsk_eoj_get_main() fault. result = %d",
1707 ECN_SRC_LOC,
1708 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1709 a_ret);
1710 goto lb_except;
1711 }
1712 ECN_DBG_PUT( "_ecn_tsk_eoj_set_get() eoj:%06X _ecn_tsk_eoj_get_main() ok sw_ok:%s",
1713 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1714 (a_sw_ok ? "true" : "false") );
1715
1716 /* ƒvƒƒpƒeƒB“ǂݍž‚ÝŒ”‘‚«ž‚ÝŽž‚̃wƒbƒhî•ñ‚ŁA“ǂݏo‚µŒ”‚ð‹L˜^ */
1717 _ecn_fbs_poke(a_fbs_res, a_rdprp_wrpos, ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc);
1718
1719 /* ‹L˜^‚µ‚Ä‚¨‚¢‚½ƒvƒƒpƒeƒBŒ”i‘‚«ž‚ÝŒ”j‚ð‘‚«–ß‚· */
1720 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.opc = (uint8_t)i;
1721
1722 /* ‰ž“š—v‚̏ꍇ */
1723 if (a_sw_ok) {
1724 /* Ý’菈—¬Œ÷ */
1725 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.esv = fa_res_esv;
1726 } else {
1727 /* Ý’菈—Ž¸”s */
1728 ((T_EDATA *)a_fbs_res.ptr)->hdr.edata.esv = fa_sna_esv;
1729 }
1730 /* ‰ž“š‘—M */
1731 a_ret = _ecn_tsk_snd_mbx(a_fbs_res, false);
1732 if (a_ret == E_OK)
1733 goto lb_finally;
1734
1735lb_except:
1736 /* ƒf[ƒ^‘—MŽ¸”s‚µ‚½‚ç—̈æ‰ð•ú */
1737 if (a_fbs_res.ptr)
1738 _ecn_fbs_del(a_fbs_res);
1739
1740lb_finally:
1741 return;
1742}
1743
1744static void _ecn_tsk_eoj_set_get_res(const EOBJINIB *fp_obj, ATR fa_eobjatr,
1745 bool_t fa_fromapp, ECN_FBS_ID fa_fbs_id, ECN_FBS_ID *fa_fbs_anno)
1746{
1747 T_ECN_EDT_HDR const *p_req_esv = &((T_EDATA *)fa_fbs_id.ptr)->hdr;
1748 T_ECN_EDT_HDR a_ecn_hdp;
1749 ECN_FBS_ID a_fbs_dmy = { 0 };
1750 ER a_ret;
1751 int i, a_size, a_rdlen;
1752 int a_sw_ok = 1;
1753 int a_count = ((T_EDATA *)fa_fbs_id.ptr)->hdr.edata.opc; /* ˆ—ƒvƒƒpƒeƒB” */
1754
1755 memset(&a_ecn_hdp, 0, sizeof(a_ecn_hdp));
1756
1757 ECN_DBG_PUT( "_ecn_tsk_eoj_set_get_res() eoj:%06X",
1758 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3 );
1759
1760 /* ‰ŠúŽæ“¾ƒTƒCƒY */
1761 a_size = sizeof(T_ECN_HDR) + sizeof(T_ECN_EDATA_BODY) + sizeof(T_ECN_PRP);
1762
1763 /* ‰ž“š“d•¶—pƒƒ‚ƒŠiƒ_ƒ~[j‚̎擾 */
1764 a_ret = _ecn_fbs_cre(a_size, &a_fbs_dmy);
1765 if (a_ret != E_OK || !a_fbs_dmy.ptr) /* Šm•ÛŽ¸”s */
1766 goto lb_finally;
1767
1768 /* ‰ž“š“d•¶Ý’è */
1769 _ecn_tsk_mk_rsp_hdr_res(&a_ecn_hdp, p_req_esv);
1770 a_size -= sizeof(T_ECN_HDR) + sizeof(T_ECN_EDATA_BODY);
1771
1772 /* payloadæ“ª‚ÌT_ECN_HDR(ecn_hdr), T_ECN_EDATA_BODY(edata)‚ð“Ç‚Ý”ò‚΂· */
1773 a_ret = _ecn_fbs_set_rpos(fa_fbs_id, offsetof(T_ECN_EDT_HDR, ecn_prp));
1774 if (a_ret)
1775 goto lb_except;
1776
1777 /* ƒvƒƒpƒeƒB’l‘‚«ž‚݉ž“š“Ç‚Ý”ò‚΂µŽÀs */
1778 a_ret = _ecn_tsk_eoj_skip_main(fp_obj, fa_fbs_id, a_count);
1779 if (a_ret) {
1780 syslog(LOG_WARNING, "_ecn_tsk_eoj_set_get_res() eoj:%06X _ecn_tsk_eoj_set_main() fault. result = %d",
1781 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1782 a_ret);
1783 goto lb_except;
1784 }
1785 ECN_DBG_PUT( "_ecn_tsk_eoj_set_get_res() eoj:%06X _ecn_tsk_eoj_set_main() ok sw_ok:%s",
1786 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1787 (a_sw_ok ? "true" : "false") );
1788
1789 /* ŽŸ‚ÌŒ”‚ð“Ç‚ÝŽæ‚é(1byte) */
1790 /* ¨ ECHONET-Lite_Ver.1.10_02.pdf p.40 [OPCGet] */
1791 a_rdlen = i = 0;
1792 a_ret = _ecn_fbs_get_data(fa_fbs_id, &i, 1, &a_rdlen);
1793 if (a_ret < 0 || a_rdlen < 1)
1794 goto lb_except; /* NG */
1795 a_count = *(uint8_t *)&i;
1796
1797 /* ƒvƒƒpƒeƒB’l“ǂݏo‚µ‰ž“š‚̏‘‚«ž‚ÝŽÀs */
1798 a_ret = _ecn_tsk_eoj_set_main(fp_obj, fa_eobjatr, fa_fromapp, true, fa_fbs_id, a_fbs_dmy,
1799 fa_fbs_anno, a_count, &a_sw_ok);
1800 if (a_ret) {
1801 syslog(LOG_WARNING, "%s _ecn_tsk_eoj_set_get_res() eoj:%06X _ecn_tsk_eoj_get_main() fault. result = %d",
1802 ECN_SRC_LOC,
1803 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1804 a_ret);
1805 goto lb_except;
1806 }
1807 ECN_DBG_PUT( "_ecn_tsk_eoj_set_get_res() eoj:%06X _ecn_tsk_eoj_get_main() ok sw_ok:%s",
1808 fp_obj->eojx1 << 16 | fp_obj->eojx2 << 8 | fp_obj->eojx3,
1809 (a_sw_ok ? "true" : "false") );
1810
1811 goto lb_finally;
1812
1813lb_except:
1814 /* ƒf[ƒ^‘—MŽ¸”s‚µ‚½‚ç—̈æ‰ð•ú */
1815 if (a_fbs_dmy.ptr)
1816 _ecn_fbs_del(a_fbs_dmy);
1817
1818lb_finally:
1819 return;
1820}
1821
1822/*
1823 * ‰ž“š“d•¶‘Ò‚¿‚ÌŠ„‚荞‚Ý“d•¶ì¬
1824 */
1825ER _ecn_mk_brk_wai(ECN_FBS_ID *pk_fbs_id, const void *p_dat, size_t fa_size)
1826{
1827 ER a_ret;
1828 ECN_FBS_ID a_fbs_id = { 0 }; /* —v‹“d•¶—pƒƒ‚ƒŠ */
1829
1830 if (!pk_fbs_id)
1831 return E_PAR;
1832 *pk_fbs_id = a_fbs_id;
1833 if (sizeof(a_fbs_id.ptr->payload) <= fa_size)
1834 return E_PAR; /* •tƒf[ƒ^‚ª‘å‚«‚·‚¬‚é */
1835 if (!p_dat && 0 < fa_size)
1836 return E_PAR; /* •tƒf[ƒ^ƒTƒCƒY‚ª1ˆÈã‚Ȃ̂Ƀf[ƒ^ƒ|ƒCƒ“ƒ^‚ªNULL */
1837
1838 /* —v‹“d•¶—pƒƒ‚ƒŠ‚̎擾 */
1839 a_ret = _ecn_fbs_cre((0 < fa_size ? fa_size : 1), &a_fbs_id);
1840 if (a_ret != E_OK || !a_fbs_id.ptr) { /* Šm•ÛŽ¸”s */
1841 syslog(LOG_WARNING, "_ecn_fbs_cre(%d) result = %d:%s", fa_size, a_ret, itron_strerror(a_ret));
1842 return a_ret;
1843 }
1844
1845 /* —v‹“d•¶Ý’è */
1846 a_fbs_id.ptr->hdr.type = ECN_MSG_USER_BREAK;
1847 a_fbs_id.ptr->hdr.sender.id = ENOD_API_ID;
1848 a_fbs_id.ptr->hdr.target.id = ENOD_API_ID;
1849 a_fbs_id.ptr->hdr.reply.id = ENOD_API_ID;
1850
1851 if (0 < fa_size && p_dat) {
1852 /* •tƒf[ƒ^’ljÁ */
1853 a_ret = _ecn_fbs_add_data_ex(a_fbs_id, p_dat, fa_size);
1854 if (a_ret) {
1855 syslog(LOG_WARNING, "_ecn_fbs_add_data_ex(*, dat, %lu) result = %d:%s",
1856 fa_size,
1857 a_ret, itron_strerror(a_ret));
1858 goto lb_except;
1859 }
1860 }
1861
1862 *pk_fbs_id = a_fbs_id;
1863
1864 /* ³íI—¹ */
1865 return a_ret;
1866
1867lb_except:
1868 /* ƒf[ƒ^ì¬Ž¸”s‚µ‚½‚ç—̈æ‰ð•ú */
1869 if (a_fbs_id.ptr)
1870 _ecn_fbs_del(a_fbs_id);
1871
1872 return a_ret;
1873}
1874
1875/* ‰ž“š“d•¶—pfbsÝ’è(sender/target‚̐ݒè) */
1876ER _ecn_tsk_cre_req_fbs(ID sender, uint8_t cmd, ECN_FBS_ID *pk_req)
1877{
1878 ER ret;
1879 ECN_FBS_ID req;
1880
1881 ret = _ecn_fbs_cre(1, &req);
1882 if (ret != E_OK) {
1883 ECN_DBG_PUT( "_ecn_tsk_cre_req_fbs() : _ecn_fbs_cre() result = %d:%s", ret, itron_strerror(ret) );
1884 return ret;
1885 }
1886
1887 ret = _ecn_fbs_add_data(req, &cmd, sizeof(cmd));
1888 if (ret != E_OK) {
1889 _ecn_fbs_del(req);
1890 ECN_DBG_PUT( "_ecn_tsk_cre_req_fbs() : _ecn_fbs_add_data() result = %d:%s", ret, itron_strerror(ret) );
1891 return ret;
1892 }
1893
1894 req.ptr->hdr.type = ECN_MSG_INTERNAL;
1895 req.ptr->hdr.sender.mbxid = sender;
1896 req.ptr->hdr.target.mbxid = ecn_svc_mailboxid;
1897 req.ptr->hdr.reply.mbxid = sender;
1898
1899 *pk_req = req;
1900
1901 return E_OK;
1902}
1903
1904/* ‰ž“š“d•¶—pfbsÝ’è(sender/target‚̐ݒè) */
1905ER _ecn_tsk_cre_res_fbs(ECN_FBS_ID req, uint8_t cmd, ECN_FBS_ID *pk_res)
1906{
1907 ER ret;
1908 ECN_FBS_ID res;
1909
1910 ret = _ecn_fbs_cre(1, &res);
1911 if (ret != E_OK) {
1912 ECN_DBG_PUT( "_ecn_tsk_cre_res_fbs() : _ecn_fbs_cre() result = %d:%s", ret, itron_strerror(ret) );
1913 return ret;
1914 }
1915
1916 ret = _ecn_fbs_add_data(res, &cmd, sizeof(cmd));
1917 if (ret != E_OK) {
1918 _ecn_fbs_del(res);
1919 ECN_DBG_PUT( "_ecn_tsk_cre_res_fbs() : _ecn_fbs_add_data() result = %d:%s", ret, itron_strerror(ret) );
1920 return ret;
1921 }
1922
1923 res.ptr->hdr.type = ECN_MSG_INTERNAL;
1924 res.ptr->hdr.sender.mbxid = ecn_svc_mailboxid;
1925 res.ptr->hdr.target.mbxid = req.ptr->hdr.reply.mbxid;
1926 res.ptr->hdr.reply.mbxid = ecn_svc_mailboxid;
1927
1928 *pk_res = res;
1929
1930 return E_OK;
1931}
Note: See TracBrowser for help on using the repository browser.