source: uKadecot/trunk/ecnl_ssp/echonet.c@ 101

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

TOPPERS/uKadecotのソースコードを追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/plain
File size: 18.7 KB
Line 
1/*
2 * TOPPERS ECHONET Lite Communication Middleware
3 *
4 * Copyright (C) 2014 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.c 101 2015-06-02 15:37:23Z coas-nagasima $
40 */
41
42#include <kernel.h>
43#include <stdio.h>
44#include <string.h>
45
46#include "echonet.h"
47#include "echonet_fbs.h"
48#include "echonet_task.h"
49#include "echonet_dbg.h"
50#include "echonet_agent.h"
51
52/*
53 * ECHONET LiteƒT[ƒrƒXˆ—ŠJŽn
54 */
55ER ecn_sta_svc()
56{
57 return act_tsk(ecn_udp_taskid);
58}
59
60/*
61 * ECHONETƒIƒuƒWƒFƒNƒgŽQÆ
62 * ˆø”
63 * ID fa_eobjid ECHONETƒIƒuƒWƒFƒNƒgID
64 * T_REOBJ *fp_eobj ECHONETƒIƒuƒWƒFƒNƒg‚̐ݒè“à—eƒRƒs[æ
65 *
66 * eobjid‚ÅŽw’肵‚½ECHONETƒIƒuƒWƒFƒNƒg‚̐ݒè“à—e‚ðŽQÆ‚·‚éB
67 * ŽQÆ‚µ‚½Ý’è“à—e‚Ípk_eobj‚ÉŽw’肵‚½ƒƒ‚ƒŠ‚É•Ô‚³‚ê‚éB
68 */
69ER ecn_ref_eobj(ID fa_eobjid, T_REOBJ *fp_eobj)
70{
71 const EOBJINIB *p_obj;
72
73 if (!fp_eobj)
74 return E_PAR; /* ƒpƒ‰ƒ[ƒ^ƒGƒ‰[ */
75
76 if ((fa_eobjid <= 0) || (fa_eobjid > tmax_eobjid))
77 return E_OBJ; /* ƒIƒuƒWƒFƒNƒg–¢“o˜^ */
78
79 p_obj = &eobjinib_table[fa_eobjid - 1];
80
81 *fp_eobj = *p_obj;
82
83 return E_OK;
84}
85
86/*
87 * ECHONETƒvƒƒpƒeƒBŽQÆ
88 * ˆø”
89 * ID fa_eobjid ECHONETƒIƒuƒWƒFƒNƒgID
90 * uint8_t fa_epc ƒvƒƒpƒeƒBƒR[ƒh
91 * T_RPRP *fp_eprp ECHONETƒIƒuƒWƒFƒNƒg‚̃vƒƒpƒeƒBÝ’è“à—eƒRƒs[æ
92 *
93 * eobjid‚ÅŽw’肵‚½ECHONETƒIƒuƒWƒFƒNƒg‚́Aepc‚ÅŽw’肵‚½ƒvƒƒpƒeƒB‚̐ݒè“à—e‚ðŽQÆ‚·‚éB
94 * ŽQÆ‚µ‚½Ý’è“à—e‚Ípk_eprp‚ÉŽw’肵‚½ƒƒ‚ƒŠ‚É•Ô‚³‚ê‚éB
95 */
96ER ecn_ref_eprp(ID fa_eobjid, uint8_t fa_epc, T_RPRP *fp_eprp)
97{
98 const EOBJINIB *p_obj;
99 const EPRPINIB *p;
100 uint_t i;
101
102 if (!fp_eprp)
103 return E_PAR; /* ƒpƒ‰ƒ[ƒ^ƒGƒ‰[ */
104
105 if ((fa_eobjid <= 0) || (fa_eobjid > tmax_eobjid))
106 return E_OBJ; /* ƒIƒuƒWƒFƒNƒg–¢“o˜^ */
107
108 p_obj = &eobjinib_table[fa_eobjid - 1];
109
110 /* eoj‚ÌŽ‚ƒvƒƒpƒeƒB‰Šú‰»’è‹`”z—ñ‚©‚猟õ */
111 p = p_obj->eprp;
112 for (i = 0; i < p_obj->eprpcnt; i++, p++) {
113 if (p->eprpcd != fa_epc)
114 continue;
115 *fp_eprp = *p;
116 return E_OK;
117 }
118
119 return E_PAR; /* ƒpƒ‰ƒ[ƒ^ƒGƒ‰[ */
120}
121
122/*
123 * ƒvƒƒpƒeƒB’l‘‚«ž‚Ý—v‹i‰ž“š•s—vj“d•¶ì¬
124 * ˆø”
125 * T_EDATA **ppk_esv Žæ“¾‚µ‚½“d•¶‚ÌŠi”[æ
126 * ID fa_deoj ˆ¶æ‚ÌECHONETƒIƒuƒWƒFƒNƒgID
127 * uint8_t fa_epc ƒvƒƒpƒeƒBƒR[ƒh
128 * uint8_t fa_pdc ƒvƒƒpƒeƒB’lƒf[ƒ^ƒTƒCƒY
129 * const void *p_edt ƒvƒƒpƒeƒB’lƒf[ƒ^
130 *
131 * ƒvƒƒpƒeƒB’l‘‚«ž‚Ý—v‹i‰ž“š•s—vj“d•¶‚ðì¬‚·‚éB
132 * “d•¶‚Ídeoj‚ÅŽw’肵‚½ECHONETƒIƒuƒWƒFƒNƒg‚ðˆ¶æ‚Æ‚µA
133 * “d•¶‚̏‰‚߂̃vƒƒpƒeƒB’l‚Æ‚µ‚āAepc‚ÆpdcAp_edt‚ÅŽw’肳‚ꂽ
134 * ƒvƒƒpƒeƒBƒR[ƒhAƒf[ƒ^ƒTƒCƒYAƒf[ƒ^‚ð“d•¶‚ɐݒ肷‚éB
135 * ì¬‚µ‚½“d•¶‚̐擪ƒAƒhƒŒƒX‚̓|ƒCƒ“ƒ^Œo—R‚Å•Ô‚³‚ê‚éB
136 */
137ER ecn_esv_seti(T_EDATA **ppk_esv, ID fa_deoj, uint8_t fa_epc, uint8_t fa_pdc,
138 const void *p_edt)
139{
140 return _ecn_tsk_mk_esv((ECN_FBS_ID *)ppk_esv, (ID)1, fa_deoj, fa_epc, fa_pdc, p_edt, ESV_SET_I);
141}
142
143/*
144 * ƒvƒƒpƒeƒB’l‘‚«ž‚Ý—v‹i‰ž“š—vj“d•¶ì¬
145 * ˆø”
146 * T_EDATA **ppk_esv Žæ“¾‚µ‚½“d•¶‚ÌŠi”[æ
147 * ID fa_deoj ˆ¶æ‚ÌECHONETƒIƒuƒWƒFƒNƒgID
148 * uint8_t fa_epc ƒvƒƒpƒeƒBƒR[ƒh
149 * uint8_t fa_pdc ƒvƒƒpƒeƒB’lƒf[ƒ^ƒTƒCƒY
150 * const void *p_edt ƒvƒƒpƒeƒB’lƒf[ƒ^
151 *
152 * ƒvƒƒpƒeƒB’l‘‚«ž‚Ý—v‹i‰ž“š—vj“d•¶‚ðì¬‚·‚éB
153 * “d•¶‚Ídeoj‚ÅŽw’肵‚½ECHONETƒIƒuƒWƒFƒNƒg‚ðˆ¶æ‚Æ‚µA
154 * “d•¶‚̏‰‚߂̃vƒƒpƒeƒB’l‚Æ‚µ‚āAepc‚ÆpdcAp_edt‚ÅŽw’肳‚ꂽ
155 * ƒvƒƒpƒeƒBƒR[ƒhAƒf[ƒ^ƒTƒCƒYAƒf[ƒ^‚ð“d•¶‚ɐݒ肷‚éB
156 * ì¬‚µ‚½“d•¶‚̐擪ƒAƒhƒŒƒX‚̓|ƒCƒ“ƒ^Œo—R‚Å•Ô‚³‚ê‚éB
157 */
158ER ecn_esv_setc(T_EDATA **ppk_esv, ID fa_deoj, uint8_t fa_epc, uint8_t fa_pdc,
159 const void *p_edt)
160{
161 return _ecn_tsk_mk_esv((ECN_FBS_ID *)ppk_esv, (ID)1, fa_deoj, fa_epc, fa_pdc, p_edt, ESV_SET_C);
162}
163
164/*
165 * ƒvƒƒpƒeƒB’l“ǂݏo‚µ—v‹“d•¶ì¬
166 * ˆø”
167 * T_EDATA **ppk_esv Žæ“¾‚µ‚½“d•¶‚ÌŠi”[æ
168 * ID fa_deoj ˆ¶æ‚ÌECHONETƒIƒuƒWƒFƒNƒgID
169 * uint8_t fa_epc ƒvƒƒpƒeƒBƒR[ƒh
170 *
171 * ƒvƒƒpƒeƒB’l“ǂݏo‚µ—v‹“d•¶‚ðì¬‚·‚éB
172 * “d•¶‚Ídeoj‚ÅŽw’肵‚½ECHONETƒIƒuƒWƒFƒNƒg‚ðˆ¶æ‚Æ‚µA
173 * “d•¶‚̏‰‚߂̃vƒƒpƒeƒB’l‚Æ‚µ‚āAepc‚ÅŽw’肳‚ꂽ
174 * ƒvƒƒpƒeƒBƒR[ƒh‚ð“d•¶‚ɐݒ肷‚éB
175 * ì¬‚µ‚½“d•¶‚̐擪ƒAƒhƒŒƒX‚̓|ƒCƒ“ƒ^Œo—R‚Å•Ô‚³‚ê‚éB
176 */
177ER ecn_esv_get(T_EDATA **ppk_esv, ID fa_deoj, uint8_t fa_epc)
178{
179 return _ecn_tsk_mk_esv((ECN_FBS_ID *)ppk_esv, (ID)1, fa_deoj, fa_epc, 0, NULL, ESV_GET);
180}
181
182/*
183 * ƒvƒƒpƒeƒB’l’Ê’m—v‹“d•¶ì¬
184 * ˆø”
185 * T_EDATA **ppk_esv Žæ“¾‚µ‚½“d•¶‚ÌŠi”[æ
186 * ID fa_deoj ˆ¶æ‚ÌECHONETƒIƒuƒWƒFƒNƒgID
187 * uint8_t fa_epc ƒvƒƒpƒeƒBƒR[ƒh
188 *
189 * ƒvƒƒpƒeƒB’l’Ê’m—v‹“d•¶‚ðì¬‚·‚éB
190 * “d•¶‚Ídeoj‚ÅŽw’肵‚½ECHONETƒIƒuƒWƒFƒNƒg‚ðˆ¶æ‚Æ‚µA
191 * “d•¶‚̏‰‚߂̃vƒƒpƒeƒB’l‚Æ‚µ‚āAepc‚ÅŽw’肳‚ꂽ
192 * ƒvƒƒpƒeƒBƒR[ƒh‚ð“d•¶‚ɐݒ肷‚éB
193 * ì¬‚µ‚½“d•¶‚̐擪ƒAƒhƒŒƒX‚̓|ƒCƒ“ƒ^Œo—R‚Å•Ô‚³‚ê‚éB
194 */
195ER ecn_esv_inf_req(T_EDATA **ppk_esv, ID fa_deoj, uint8_t fa_epc)
196{
197 return _ecn_tsk_mk_esv((ECN_FBS_ID *)ppk_esv, (ID)1, fa_deoj, fa_epc, 0, NULL, ESV_INF_REQ);
198}
199
200/*
201 * ƒvƒƒpƒeƒB’l‘‚«ž‚݁E“ǂݏo‚µ—v‹“d•¶ì¬
202 * ˆø”
203 * T_EDATA **ppk_esv Žæ“¾‚µ‚½“d•¶‚ÌŠi”[æ
204 * ID fa_deoj ˆ¶æ‚ÌECHONETƒIƒuƒWƒFƒNƒgID
205 * uint8_t fa_epc ƒvƒƒpƒeƒBƒR[ƒh
206 * uint8_t fa_pdc ƒvƒƒpƒeƒB’lƒf[ƒ^ƒTƒCƒY
207 * const void *p_edt ƒvƒƒpƒeƒB’lƒf[ƒ^
208 *
209 * ƒvƒƒpƒeƒB’l‘‚«ž‚݁E“ǂݏo‚µ—v‹“d•¶‚ðì¬‚·‚éB
210 * “d•¶‚Ídeoj‚ÅŽw’肵‚½ECHONETƒIƒuƒWƒFƒNƒg‚ðˆ¶æ‚Æ‚µA
211 * “d•¶‚̏‰‚߂̃vƒƒpƒeƒB’l‚Æ‚µ‚āAepc‚ÆpdcAp_edt‚ÅŽw’肳‚ꂽ
212 * ƒvƒƒpƒeƒBƒR[ƒhAƒf[ƒ^ƒTƒCƒYAƒf[ƒ^‚ð“d•¶‚ɐݒ肷‚éB
213 * ì¬‚µ‚½“d•¶‚̐擪ƒAƒhƒŒƒX‚̓|ƒCƒ“ƒ^Œo—R‚Å•Ô‚³‚ê‚éB
214 */
215ER ecn_esv_set_get(T_EDATA **ppk_esv, ID fa_deoj, uint8_t fa_epc, uint8_t fa_pdc,
216 const void *p_edt)
217{
218 return _ecn_tsk_mk_esv((ECN_FBS_ID *)ppk_esv, (ID)1, fa_deoj, fa_epc, fa_pdc, p_edt, ESV_SET_GET);
219}
220
221/*
222 * ƒvƒƒpƒeƒB’l‘‚«ž‚݁E“ǂݏo‚µ—v‹“d•¶ì¬FÜ‚è•Ô‚µŽw’è
223 * ƒvƒƒpƒeƒB’l‘‚«ž‚݁E“ǂݏo‚µ—v‹“d•¶ì¬’†‚́A‘‚«ž‚݃vƒƒpƒeƒB”z—ñ‚ðI‚¦‚Ä
224 * “ǂݏo‚µƒvƒƒpƒeƒB”z—ñ‚Ɉڂ鎞‚É—p‚¢‚éB
225 */
226ER ecn_trn_set_get(T_EDATA *ppk_esv, int *p_trn_pos)
227{
228 ER a_ret;
229
230 if (!ppk_esv)
231 return E_PAR;
232 if (!p_trn_pos)
233 return E_PAR;
234
235 /* ƒvƒƒpƒeƒB“ǂݍž‚ÝŒ”‘‚«ž‚ÝŽž‚̃wƒbƒhî•ñ‚ð‹L˜^ */
236 *p_trn_pos = _ecn_fbs_get_datalen(*(ECN_FBS_ID *)&ppk_esv);
237
238 /* ‰ž“š“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁE‚±‚ÌŽž“_‚ł̉ž“š“d•¶’†ƒvƒƒpƒeƒBŒ”‚ð‹L˜^ */
239 a_ret = _ecn_fbs_add_data_ex(*(ECN_FBS_ID *)&ppk_esv, &ppk_esv->hdr.edata.opc, 1);
240 if (a_ret) {
241 ECN_DBG_PUT "ecn_trn_set_get(): _ecn_fbs_add_data_ex() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
242 return a_ret;
243 }
244
245 /* ‰ž“š“d•¶’†ƒvƒƒpƒeƒBŒ”‚ð 0 ‚É–ß‚·i¡ŒãAI—¹Žw’è‚·‚é‚܂ł͓ǂݏo‚µƒvƒƒpƒeƒBŒ”‚É‚È‚éj */
246 ppk_esv->hdr.edata.opc = 0;
247
248 return E_OK;
249}
250
251/*
252 * ƒvƒƒpƒeƒB’l‘‚«ž‚݁E“ǂݏo‚µ—v‹“d•¶ì¬FI—¹Žw’è
253 * ƒvƒƒpƒeƒB’l‘‚«ž‚݁E“ǂݏo‚µ—v‹“d•¶ì¬’†‚́A“ǂݏo‚µƒvƒƒpƒeƒB”z—ñ‚ðI‚¦‚鎞‚É—p‚¢‚éB
254 */
255ER ecn_end_set_get(T_EDATA *ppk_esv, int fa_trn_pos)
256{
257 ER a_ret;
258 int a_wr_opc;
259 uint8_t a_rd_opc;
260
261 if (!ppk_esv)
262 return E_PAR;
263
264 /* ‚±‚ÌŽž“_‚ł̉ž“š“d•¶’†ƒvƒƒpƒeƒBŒ”(“ǂݏo‚µƒvƒƒpƒeƒBŒ”)‚ð•ÛŽ */
265 a_rd_opc = ppk_esv->hdr.edata.opc;
266
267 /* ‰ž“š“d•¶’†ƒvƒƒpƒeƒBŒ”(‘‚«ž‚݃vƒƒpƒeƒBŒ”)‚ð•Û‘¶ˆÊ’u‚©‚ç“Ç‚ÝŽæ‚è */
268 a_wr_opc = _ecn_fbs_peek(*(ECN_FBS_ID *)&ppk_esv, fa_trn_pos);
269 if (a_wr_opc < 0) {
270 ECN_DBG_PUT "ecn_end_set_get(): _ecn_fbs_peek() result = %d:%s", a_wr_opc, itron_strerror(a_wr_opc) ECN_DBG_END;
271 return a_wr_opc;
272 }
273
274 /* ‰ž“š“d•¶’†ƒvƒƒpƒeƒBŒ”(‘‚«ž‚݃vƒƒpƒeƒBŒ”)‚𕜌³ */
275 ppk_esv->hdr.edata.opc = (uint8_t)a_wr_opc;
276
277 /* ‰ž“š“d•¶’†ƒvƒƒpƒeƒBŒ”(“ǂݏo‚µƒvƒƒpƒeƒBŒ”)‚ð•Û‘¶ˆÊ’u‚ɏ‘‚«ž‚Ý */
278 a_ret = _ecn_fbs_poke(*(ECN_FBS_ID *)&ppk_esv, fa_trn_pos, a_rd_opc);
279 if (a_ret) {
280 ECN_DBG_PUT "ecn_end_set_get(): _ecn_fbs_poke() result = %d:%s", a_ret, itron_strerror(a_ret) ECN_DBG_END;
281 return a_ret;
282 }
283
284 return E_OK;
285}
286
287/*
288 * ƒvƒƒpƒeƒB’l’Ê’mi‰ž“š—vj“d•¶ì¬
289 * ˆø”
290 * T_EDATA **ppk_esv Žæ“¾‚µ‚½“d•¶‚ÌŠi”[æ
291 * ID fa_deoj ˆ¶æ‚ÌECHONETƒIƒuƒWƒFƒNƒgID
292 * ID fa_seoj ‘—MŒ³‚ÌECHONETƒIƒuƒWƒFƒNƒgID
293 * uint8_t fa_sepc ‘—MŒ³‚̃vƒƒpƒeƒBƒR[ƒh
294 */
295ER ecn_esv_infc(T_EDATA **ppk_esv, ID fa_deoj, ID fa_seoj, uint8_t fa_sepc)
296{
297 return _ecn_tsk_mk_esv((ECN_FBS_ID *)ppk_esv, fa_seoj, fa_deoj, fa_sepc, 0, NULL, ESV_INFC);
298}
299
300/*
301 * —v‹“d•¶‚ւ̃vƒƒpƒeƒBŽw’è’ljÁ (ƒvƒƒpƒeƒBƒf[ƒ^‚ª•t‚µ‚È‚¢ê‡‚É—p‚¢‚é)
302 */
303ER ecn_add_epc(T_EDATA *pk_esv, uint8_t epc)
304{
305 return ecn_add_edt(pk_esv, epc, 0, 0);
306}
307
308/*
309 * —v‹“d•¶‚ւ̃vƒƒpƒeƒBƒf[ƒ^’ljÁ (ƒvƒƒpƒeƒB‚¨‚æ‚Ñ•tƒf[ƒ^‚ð’ljÁ‚·‚é)
310 */
311ER ecn_add_edt(T_EDATA *pk_esv, uint8_t fa_epc, uint8_t fa_pdc, const void *p_edt)
312{
313 ECN_FBS_ID a_fbs_id;
314 ER a_ret;
315 T_ECN_PRP a_ecn_prp;
316
317 if (!pk_esv)
318 return E_PAR; /* Žæ“¾‚µ‚½FBS_ID‚ÌŠi”[æ‚ªNULL */
319 if (ECHONET_MEMPOOL_BLOCK_SIZE <= fa_pdc)
320 return E_PAR; /* ƒvƒƒpƒeƒB’lƒTƒCƒY‚ª‘å‚«‚·‚¬‚é */
321 if (!p_edt && 0 < fa_pdc)
322 return E_PAR; /* ƒvƒƒpƒeƒB’lƒTƒCƒY‚ª1ˆÈã‚Ȃ̂Ƀf[ƒ^ƒ|ƒCƒ“ƒ^‚ªNULL */
323
324 a_fbs_id.ptr = (T_ECN_FST_BLK *)pk_esv;
325 if (((T_EDATA *)a_fbs_id.ptr)->hdr.edata.opc == 0xFF)
326 return E_PAR; /* ƒvƒƒpƒeƒB‚ª‘½‚·‚¬‚é */
327
328 /* —v‹“d•¶—pƒƒ‚ƒŠ‚Ƀf[ƒ^’ljÁ */
329 memset(&a_ecn_prp, 0, sizeof(a_ecn_prp));
330 a_ecn_prp.epc = fa_epc;
331 a_ecn_prp.pdc = fa_pdc;
332 a_ret = _ecn_fbs_add_data_ex(a_fbs_id, &a_ecn_prp, sizeof(a_ecn_prp));
333 if (a_ret) {
334 ECN_DBG_PUT "ecn_add_edt(): _ecn_fbs_add_data_ex(*, ecn_prp{epc:0x%02X}, %u) result = %d:%s",
335 a_ecn_prp.epc, sizeof(a_ecn_prp),
336 a_ret, itron_strerror(a_ret) ECN_DBG_END;
337 goto lb_except;
338 }
339 if (0 < fa_pdc) {
340 /* •tƒf[ƒ^’ljÁ */
341 a_ret = _ecn_fbs_add_data_ex(a_fbs_id, p_edt, fa_pdc);
342 if (a_ret) {
343 ECN_DBG_PUT "ecn_add_edt(): _ecn_fbs_add_data_ex(*, ecn_prp{epc:0x%02X} edt, %u) result = %d:%s",
344 a_ecn_prp.epc, fa_pdc,
345 a_ret, itron_strerror(a_ret) ECN_DBG_END;
346 goto lb_except;
347 }
348 }
349 /* ƒvƒƒpƒeƒB”ƒCƒ“ƒNƒŠƒƒ“ƒg */
350 ((T_EDATA *)a_fbs_id.ptr)->hdr.edata.opc++;
351
352lb_except:
353 return a_ret;
354}
355
356/*
357 * —v‹“d•¶‚Ì‘—M
358 * esv‚ÅŽw’肳‚ꂽ—v‹“d•¶‚𑗐M‚·‚éB
359 * “d•¶‚ÉŽw’肳‚ꂽˆ¶æ‚©‚çIPƒAƒhƒŒƒX‚ð“Á’肵AUDPƒpƒPƒbƒg‚Æ‚µ‚Ä‘—M‚·‚éB
360 */
361ER ecn_snd_esv(T_EDATA *pk_esv)
362{
363 ECN_FBS_ID a_rsp_fbs;
364 a_rsp_fbs.ptr = (T_ECN_FST_BLK *)pk_esv;
365 return _ecn_tsk_snd_mbx(a_rsp_fbs, true);
366}
367
368/*
369 * ‰ž“š“d•¶‚ÌŽóMƒ|[ƒŠƒ“ƒO
370 * ‰ž“š“d•¶‚ðŽóM‚·‚é‚Ì‚ð‘҂B
371 * ŽóM‚µ‚½‰ž“š“d•¶‚Íppk_esv‚ÅŽw’肵‚½ƒ|ƒCƒ“ƒ^[‚ɐ擪ƒAƒhƒŒƒX‚ª•Ô‚³‚ê‚éB
372 * ‰ž“š“d•¶‚ÌŽóM‚Ì—L–³‚É‚©‚©‚í‚炸A‘Ò‚½‚¸‚Ɋ֐”‚𔲂¯‚éB
373 */
374ER ecn_prcv_esv(T_EDATA **ppk_esv)
375{
376 intptr_t p_msg = 0;
377 ER a_ret;
378
379 if (!ppk_esv)
380 return E_PAR;
381
382 a_ret = prcv_dtq(ecn_api_mailboxid, &p_msg);
383 if (a_ret != E_OK) {
384 *ppk_esv = NULL;
385 return a_ret;
386 }
387
388 *ppk_esv = (T_EDATA *)p_msg;
389 return (((T_ECN_FST_BLK *)p_msg)->hdr.type == ECN_MSG_ECHONET) ? E_OK : E_BRK;
390}
391
392/*
393 * ‰ž“š“d•¶‚Ì”jŠü
394 */
395ER ecn_rel_esv(T_EDATA *pk_esv)
396{
397 ECN_FBS_ID a_fbs;
398 ER a_ret;
399
400 a_fbs.ptr = (T_ECN_FST_BLK *)pk_esv;
401 a_ret = _ecn_fbs_del(a_fbs);
402 return a_ret;
403}
404
405/*
406 * ‰ž“š“d•¶‚Ì‘—MŒ³ƒm[ƒh‚ðŽæ“¾‚·‚é
407 */
408ID ecn_get_enod(T_EDATA *pk_esv)
409{
410 const EOBJCB *p_snod;
411 const EOBJINIB *p_sobj = NULL;
412 T_ECN_EDT_HDR *p_esv;
413
414 p_esv = &pk_esv->hdr;
415 p_snod = _ecn_eno_fnd(((T_ECN_FST_BLK *)pk_esv)->hdr.sender);
416 if (p_snod != NULL) {
417 p_sobj = p_snod->profile;
418 }
419
420 if (p_sobj == NULL)
421 return EOBJ_NULL;
422#ifdef ECHONET_CONTROLLER_EXTENTION
423 if (p_sobj->eprpcnt == 0)
424 return ecn_agent_get_eobj(p_sobj);
425#endif
426 return 1 + (((intptr_t)p_sobj - (intptr_t)eobjinib_table) / sizeof(EOBJINIB));
427}
428
429/*
430 * ‰ž“š“d•¶‚Ì‘—MŒ³‹@ŠíƒIƒuƒWƒFƒNƒg‚ðŽæ“¾‚·‚é
431 */
432ID ecn_get_eobj(T_EDATA *pk_esv)
433{
434 const EOBJCB *p_snod;
435 const EOBJINIB *p_sobj = NULL;
436 T_ECN_EDT_HDR *p_esv;
437
438 p_esv = &pk_esv->hdr;
439 p_snod = _ecn_eno_fnd(((T_ECN_FST_BLK *)pk_esv)->hdr.sender);
440 if (p_snod != NULL) {
441 /* ƒm[ƒhƒvƒƒtƒ@ƒCƒ‹‚̏ꍇ */
442 if ((p_esv->edata.seoj.eojx1 == EOJ_X1_PROFILE)
443 && (p_esv->edata.seoj.eojx2 == EOJ_X2_NODE_PROFILE)) {
444 p_sobj = p_snod->profile;
445 }
446 /* ‹@ŠíƒIƒuƒWƒFƒNƒg‚̏ꍇ */
447 else {
448 p_sobj = _ecn_eoj_fnd(p_snod, &p_esv->edata.seoj);
449 }
450 }
451
452 if (p_sobj == NULL)
453 return EOBJ_NULL;
454#ifdef ECHONET_CONTROLLER_EXTENTION
455 if (p_sobj->eprpcnt == 0)
456 return ecn_agent_get_eobj(p_sobj);
457#endif
458 return 1 + (((intptr_t)p_sobj - (intptr_t)eobjinib_table) / sizeof(EOBJINIB));
459}
460
461/*
462 * ‰ž“š“d•¶‰ðÍƒCƒeƒŒ[ƒ^[‰Šú‰»
463 */
464ER ecn_itr_ini(T_ENUM_EPC *pk_itr, T_EDATA *pk_esv)
465{
466 if (!pk_itr)
467 return E_PAR;
468 if (!pk_esv)
469 return E_PAR;
470
471 memset(pk_itr, 0, sizeof(*pk_itr));
472 pk_itr->pk_esv = pk_esv;
473 pk_itr->count = pk_esv->hdr.edata.opc;
474 /* ¡‚̃uƒƒbƒN‚ł̃vƒƒpƒeƒB‘” */
475 pk_itr->got_ct = 0; /* ¡‚̃uƒƒbƒN‚ŁA“Ç‚ÝŽæ‚Á‚½” */
476 pk_itr->next_blk_ct = 0; /* Œã‘±ƒuƒƒbƒN” */
477 pk_itr->is_eof = 0; /* I’[‚É’B‚µ‚½ŽžA”ñ0 */
478 pk_itr->cur = offsetof(T_ECN_EDT_HDR, ecn_prp);
479
480 switch (pk_esv->hdr.edata.esv) {
481 case ESV_SET_GET: /* 0x6E ƒvƒƒpƒeƒB’l‘‚«ž‚݁E“ǂݏo‚µ—v‹ */
482 case ESV_SET_GET_RES: /* 0x7E ƒvƒƒpƒeƒB’l‘‚«ž‚݁E“ǂݏo‚µ‰ž“š */
483 case ESV_SET_GET_SNA: /* 0x5E ƒvƒƒpƒeƒB’l‘‚«ž‚݁E“ǂݏo‚µ•s‰Â‰ž“š */
484 pk_itr->next_blk_ct ++;
485 default:
486 break;
487 }
488
489 return E_OK;
490}
491
492/*
493 * ‰ž“š“d•¶‰ðÍƒCƒeƒŒ[ƒ^[ƒCƒ“ƒNƒŠƒƒ“ƒg
494 */
495ER ecn_itr_nxt(T_ENUM_EPC *pk_itr, uint8_t *p_epc, uint8_t *p_pdc, void *p_edt)
496{
497 ECN_FBS_ID a_fbs_id;
498 int a_rd_bak;
499 ER a_ret;
500 ECN_FBS_SSIZE_T a_rd_len;
501 T_ECN_PRP a_ecn_prp;
502
503 if (!pk_itr)
504 return E_PAR;
505 if (!p_epc)
506 return E_PAR;
507 if (!p_pdc)
508 return E_PAR;
509 if (!p_edt)
510 return E_PAR;
511 if (!pk_itr->pk_esv)
512 return E_PAR;
513
514 if (pk_itr->is_eof)
515 return E_BOVR; /* ƒf[ƒ^I—¹ */
516 if ( pk_itr->count <= pk_itr->got_ct
517 && pk_itr->next_blk_ct < 1) {
518 pk_itr->is_eof = 1; /* I’[‚É’B‚µ‚½ŽžA”ñ0 */
519 return E_BOVR; /* ƒf[ƒ^I—¹ */
520 }
521
522 a_fbs_id.ptr = (T_ECN_FST_BLK *)pk_itr->pk_esv;
523
524 /* Œ³‚̃J[ƒ\ƒ‹ˆÊ’u‚ð•Û‘¶‚µAƒCƒeƒŒ[ƒ^‚̃J[ƒ\ƒ‹ˆÊ’u‚É‚·‚é */
525 a_rd_bak = a_fbs_id.ptr->hdr.rd;
526 a_fbs_id.ptr->hdr.rd = pk_itr->cur;
527
528#ifdef ECN_ENA_ITR_NXT_CARP
529 ECN_CAP_PUT "ecn_itr_nxt() rd.cur=b%dp%d", pk_itr->cur.blk, pk_itr->cur.pos ECN_CAP_PUT;
530#endif
531 if (pk_itr->count <= pk_itr->got_ct && 0 < pk_itr->next_blk_ct) {
532 /* ŽŸƒuƒƒbƒN‚Ɉړ® */
533 pk_itr->next_blk_ct --;
534 pk_itr->count = 0; /* ¡‚̃uƒƒbƒN‚ł̃vƒƒpƒeƒB‘” */
535 pk_itr->got_ct = 0; /* ¡‚̃uƒƒbƒN‚ŁA“Ç‚ÝŽæ‚Á‚½” */
536
537 /* ŽŸƒuƒƒbƒN‚̃vƒƒpƒeƒB”‚ð“Ç‚ÝŽæ‚é */
538 a_rd_len = 0;
539 a_ret = _ecn_fbs_get_data(a_fbs_id, &a_ecn_prp.pdc, 1, &a_rd_len);
540 if (a_ret != E_OK)
541 goto lb_except;
542 if (0 < a_rd_len) {
543 pk_itr->count = a_ecn_prp.pdc; /* ¡‚̃uƒƒbƒN‚ł̃vƒƒpƒeƒB‘” */
544 }
545 a_ret = E_BOVR; /* ƒf[ƒ^I—¹ */
546 goto lb_finally;
547 }
548
549 /* ƒvƒƒpƒeƒBƒR[ƒh‚ƃf[ƒ^ƒTƒCƒY‚ð“Ç‚ÝŽæ‚é */
550 memset(&a_ecn_prp, 0, sizeof(a_ecn_prp));
551 a_rd_len = 0;
552 a_ret = _ecn_fbs_get_data(a_fbs_id, &a_ecn_prp, sizeof(a_ecn_prp), &a_rd_len);
553 if (a_ret != E_OK)
554 goto lb_except;
555 if (a_rd_len < sizeof(a_ecn_prp)) {
556 ECN_DBG_PUT "ecn_itr_nxt() ecn_prp read fault."
557 " rd.cur=%d", pk_itr->cur ECN_DBG_END;
558 pk_itr->is_eof = 1; /* I’[‚É’B‚µ‚½ŽžA”ñ0 */
559 a_ret = E_BOVR; /* ƒf[ƒ^I—¹ */
560 goto lb_finally;
561 }
562 *p_epc = a_ecn_prp.epc;
563 *p_pdc = a_ecn_prp.pdc;
564
565 if (0 < a_ecn_prp.pdc) {
566 /* •tƒf[ƒ^‚ð“Ç‚ÝŽæ‚é */
567 a_rd_len = 0;
568 a_ret = _ecn_fbs_get_data(a_fbs_id, p_edt, a_ecn_prp.pdc, &a_rd_len);
569 if (a_ret != E_OK)
570 goto lb_except;
571 if (a_rd_len < (ECN_FBS_SSIZE_T)a_ecn_prp.pdc) {
572 ECN_DBG_PUT "ecn_itr_nxt() edt read fault."
573 " rd.cur=%d,epc=0x%02X,pdc=%u", pk_itr->cur, a_ecn_prp.epc , a_ecn_prp.pdc ECN_DBG_END;
574 pk_itr->is_eof = 1; /* I’[‚É’B‚µ‚½ŽžA”ñ0 */
575 a_ret = E_BOVR; /* ƒf[ƒ^I—¹ */
576 goto lb_finally;
577 }
578 }
579 pk_itr->got_ct++;
580
581#ifdef ECN_ENA_ITR_NXT_CARP
582 ECN_CAP_PUT "ecn_itr_nxt() read: ct=%d/%d", pk_itr->got_ct, pk_itr->count ECN_CAP_PUT;
583#endif
584
585lb_finally:
586 /* ƒCƒeƒŒ[ƒ^‚̃J[ƒ\ƒ‹ˆÊ’u‚ðXV */
587 pk_itr->cur = a_fbs_id.ptr->hdr.rd;
588
589lb_except:
590 /* Œ³‚̃J[ƒ\ƒ‹ˆÊ’u‚É–ß‚· */
591 a_fbs_id.ptr->hdr.rd = a_rd_bak;
592 return a_ret;
593}
594
595/*
596 * ‰ž“š“d•¶‘Ò‚¿‚ÌŠ„‚荞‚Ý‘—M
597 */
598ER ecn_brk_wai(const void *p_dat, int fa_datsz)
599{
600 ER a_ret;
601 ECN_FBS_ID a_fbs_id = { 0 }; /* —v‹“d•¶—pƒƒ‚ƒŠ */
602
603 /* ‰ž“š“d•¶‘Ò‚¿‚ÌŠ„‚荞‚Ý“d•¶ì¬ */
604 a_ret = _ecn_mk_brk_wai(&a_fbs_id, p_dat, fa_datsz);
605 if (a_ret)
606 return a_ret;
607
608 /* Š„‚荞‚Ý‘—M */
609 a_ret = _ecn_tsk_snd_mbx(a_fbs_id, true);
610 if (a_ret) {
611 ECN_DBG_PUT "_ecn_tsk_snd_mbx() result = %d:%s",
612 a_ret, itron_strerror(a_ret) ECN_DBG_END;
613 goto lb_except;
614 }
615
616 /* ³íI—¹ */
617 return a_ret;
618
619lb_except:
620 /* ƒf[ƒ^ì¬Ž¸”s‚µ‚½‚ç—̈æ‰ð•ú */
621 if (a_fbs_id.ptr)
622 _ecn_fbs_del(a_fbs_id);
623
624 return a_ret;
625}
626
627/*
628 * Š„‚荞‚݃f[ƒ^‚̎擾
629 */
630ER ecn_get_brk_dat(T_EDATA *pk_esv, void *p_buf, int fa_bufsz, int *p_datsz)
631{
632 ECN_FBS_ID a_fbs;
633 ER a_ret;
634 ECN_FBS_SSIZE_T a_len;
635
636 if (p_datsz)
637 *p_datsz = 0;
638 if (!pk_esv)
639 return E_PAR;
640
641 a_fbs.ptr = (T_ECN_FST_BLK *)pk_esv;
642 if (a_fbs.ptr->hdr.type != ECN_MSG_USER_BREAK) {
643 ECN_DBG_PUT "ecn_get_brk_dat: fbs-type:%d != ECN_MSG_USER_BREAK",
644 a_fbs.ptr->hdr.type ECN_DBG_END;
645 return E_PAR;
646 }
647
648 /* “Ç‚ÝŽæ‚èˆÊ’u‚ðæ“ª‚É–ß‚· */
649 a_ret = _ecn_fbs_set_rpos(a_fbs, 0);
650 if (a_ret) {
651 ECN_DBG_PUT "_ecn_fbs_set_rpos(*, 0) result = %d:%s",
652 a_ret, itron_strerror(a_ret) ECN_DBG_END;
653 return a_ret;
654 }
655
656 /* •tƒf[ƒ^‚ð“ǂݍž‚Þ */
657 if (p_buf && 0 < fa_bufsz) {
658 a_len = 0;
659 a_ret = _ecn_fbs_get_data(a_fbs, p_buf, fa_bufsz, &a_len);
660 if (a_ret || !a_len) {
661 ECN_DBG_PUT "_ecn_fbs_get_data(*, p_buf, fa_bufsz) result = %d:%s",
662 a_ret, itron_strerror(a_ret) ECN_DBG_END;
663 return E_PAR;
664 }
665 *p_datsz = a_len;
666 }
667
668 return E_OK;
669}
670
671#ifndef ECN_USER_DATA_PROP_SET
672/*
673 * ƒf[ƒ^Ý’èŠÖ”
674 */
675int ecn_data_prop_set(const EPRPINIB *item, const void *src, int size, bool_t *anno)
676{
677 if (size > item->eprpsz)
678 size = item->eprpsz;
679
680 if (*anno)
681 *anno = memcmp((uint8_t *)item->exinf, src, size) != 0;
682
683 memcpy((uint8_t *)item->exinf, src, size);
684
685 return size;
686}
687#endif
688
689#ifndef ECN_USER_DATA_PROP_GET
690/*
691 * ƒf[ƒ^Žæ“¾ŠÖ”
692 */
693int ecn_data_prop_get(const EPRPINIB *item, void *dst, int size)
694{
695 if (size > item->eprpsz)
696 size = item->eprpsz;
697
698 memcpy(dst, (uint8_t *)item->exinf, size);
699
700 return size;
701}
702#endif
Note: See TracBrowser for help on using the repository browser.