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

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