source: uKadecot/trunk/kadecot/wamp_dealer.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: 51.4 KB
Line 
1/*
2 * TOPPERS ECHONET Lite Communication Middleware
3 *
4 * Copyright (C) 2015 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: wamp_dealer.c 101 2015-06-02 15:37:23Z coas-nagasima $
40 */
41
42#include <string.h>
43#include "wamp.h"
44#include "wamp_dealer.h"
45#include "main.h"
46#include "fbs_string.h"
47#include "kadecot_names.h"
48#include "kernel_cfg.h"
49#include "echonet_agent.h"
50#include "arduino.h"
51#include "data_flash.h"
52#include "uip.h"
53#include "uip_adpt.h"
54
55#ifndef _MSC_VER
56#ifndef strcpy_s
57#define strcpy_s(s1, s1m, s2) strcpy(s1, s2)
58#endif
59
60#ifndef strncpy_s
61#define strncpy_s(dst, dsz, src, sz) strncpy(dst, src, sz)
62#endif
63
64size_t strnlen(const char *s, size_t maxlen);
65#endif
66
67static void wamp_dealer_call_dummy_param(wamp_dealer_t *dealer,
68 jsonsl_action_t action, struct jsonsl_state_st *state, const char *buf);
69static void wamp_dealer_call_kadecot_param(wamp_dealer_t *dealer,
70 jsonsl_action_t action, struct jsonsl_state_st *state, const char *buf);
71static void wamp_dealer_call_ecnl_param(wamp_dealer_t *dealer,
72 jsonsl_action_t action, struct jsonsl_state_st *state, const char *buf);
73static void wamp_dealer_call_arduino_param(wamp_dealer_t *dealer,
74 jsonsl_action_t action, struct jsonsl_state_st *state, const char *buf);
75static void wamp_dealer_call_init_params_param(wamp_dealer_t *dealer,
76 jsonsl_action_t action, struct jsonsl_state_st *state, const char *buf);
77
78static void wamp_dealer_none_close(struct wamp_dealer *dealer);
79static void wamp_dealer_get_devicelist_close(struct wamp_dealer *dealer);
80static void wamp_dealer_kadecot_get_close(struct wamp_dealer *dealer);
81static void wamp_dealer_kadecot_set_close(struct wamp_dealer *dealer);
82static void wamp_dealer_get_deviceinfo_close(struct wamp_dealer *dealer);
83static void wamp_dealer_ecnl_set_close(struct wamp_dealer *dealer);
84static void wamp_dealer_ecnl_get_close(struct wamp_dealer *dealer);
85static void wamp_dealer_ecnl_setget_close(struct wamp_dealer *dealer);
86static void wamp_dealer_pin_mode_close(struct wamp_dealer *dealer);
87static void wamp_dealer_digital_write_close(struct wamp_dealer *dealer);
88static void wamp_dealer_digital_read_close(struct wamp_dealer *dealer);
89static void wamp_dealer_analog_read_close(struct wamp_dealer *dealer);
90static void wamp_dealer_analog_write_close(struct wamp_dealer *dealer);
91static void wamp_dealer_set_init_params_close(struct wamp_dealer *dealer);
92static void wamp_dealer_get_init_params_close(struct wamp_dealer *dealer);
93
94static echonetlite_device_t *wamp_dealer_get_device(wamp_dealer_t *dealer, int deviceId);
95
96static bool_t wamp_dealer_get_epc(const char *propName, int nameLen,
97 uint16_t devType, uint8_t *epc, uint8_t *pdc);
98static void wamp_dealer_get_devicelist(struct wamp_dealer *dealer);
99
100int wamp_stob(const char *str, uint8_t *dst, int dstc);
101
102void wamp_dealer_register(wamp_dealer_t *dealer)
103{
104}
105
106void wamp_dealer_register_request_id(wamp_dealer_t *dealer, const char *value)
107{
108}
109
110void wamp_dealer_register_options(wamp_dealer_t *dealer, const char *value)
111{
112}
113
114void wamp_dealer_register_options_param(wamp_dealer_t *dealer, jsonsl_action_t action,
115 struct jsonsl_state_st *state, const char *buf)
116{
117}
118
119void wamp_dealer_register_procedure(wamp_dealer_t *dealer, const char *value)
120{
121}
122
123void wamp_dealer_register_close(struct wamp_state *s)
124{
125}
126
127void wamp_dealer_unregister(wamp_dealer_t *dealer)
128{
129}
130
131void wamp_dealer_unregister_request_id(wamp_dealer_t *dealer, const char *value)
132{
133}
134
135void wamp_dealer_unregister_registration_id(wamp_dealer_t *dealer, const char *value)
136{
137}
138
139void wamp_dealer_unregister_close(struct wamp_state *s)
140{
141}
142
143void wamp_dealer_call(wamp_dealer_t *dealer)
144{
145 dealer->args_parse = wamp_dealer_call_dummy_param;
146 dealer->call_close = wamp_dealer_none_close;
147
148 memset(&dealer->params, 0, sizeof(dealer->params));
149}
150
151void wamp_dealer_call_request_id(wamp_dealer_t *dealer, const char *value)
152{
153 dealer->requestId = atoi(value);
154}
155
156void wamp_dealer_call_options(wamp_dealer_t *dealer, const char *value)
157{
158}
159
160void wamp_dealer_call_options_param(wamp_dealer_t *dealer, jsonsl_action_t action,
161 struct jsonsl_state_st *state, const char *buf)
162{
163 static const char deviceId[] = "deviceId";
164
165 switch (state->level) {
166 case 3:
167 switch (action){
168 case JSONSL_ACTION_POP:
169 switch (state->type)
170 {
171 case JSONSL_T_HKEY:
172 if(strcmp(deviceId, dealer->s->jsn_buf) == 0){
173 dealer->state = WAMP_DEALER_STATE_DEVICE_ID;
174 }
175 break;
176 case JSONSL_T_SPECIAL:
177 dealer->current_device = wamp_dealer_get_device(dealer, atoi(dealer->s->jsn_buf));
178 break;
179 default:
180 break;
181 }
182 break;
183 }
184 break;
185 }
186}
187
188void wamp_dealer_call_procedure(wamp_dealer_t *dealer, const char *value)
189{
190 static const char getDeviceList[] = "com.sonycsl.kadecot.provider.procedure.getDeviceList";
191 static const char kadecotGet[] = "com.sonycsl.kadecot.echonetlite.procedure.get";
192 static const char kadecotSet[] = "com.sonycsl.kadecot.echonetlite.procedure.set";
193 static const char getDeviceInfo[] = "jp.toppers.ecnl.procedure.getDeviceInfo";
194 static const char ecnlSet[] = "jp.toppers.ecnl.procedure.set";
195 static const char ecnlGet[] = "jp.toppers.ecnl.procedure.get";
196 static const char ecnlSetGet[] = "jp.toppers.ecnl.procedure.setget";
197 static const char pinMode[] = "com.sonycsl.kadecot.arduino.pinMode";
198 static const char digitalWrite[] = "com.sonycsl.kadecot.arduino.digitalWrite";
199 static const char digitalRead[] = "com.sonycsl.kadecot.arduino.digitalRead";
200 static const char analogRead[] = "com.sonycsl.kadecot.arduino.analogRead";
201 static const char analogWrite[] = "com.sonycsl.kadecot.arduino.analogWrite";
202 static const char setInitParams[] = "jp.toppers.ecnl.procedure.setInitParams";
203 static const char getInitParams[] = "jp.toppers.ecnl.procedure.getInitParams";
204
205 if(strcmp(getDeviceList, value) == 0){
206 dealer->procedure = WAMP_DEALER_PROCEDURE_GET_DEVICELIST;
207 dealer->args_parse = wamp_dealer_call_dummy_param;
208 dealer->call_close = wamp_dealer_get_devicelist_close;
209 }
210 else if(strcmp(kadecotGet, value) == 0){
211 dealer->procedure = WAMP_DEALER_PROCEDURE_KADECOT_GET;
212 dealer->args_parse = wamp_dealer_call_kadecot_param;
213 dealer->call_close = wamp_dealer_kadecot_get_close;
214 }
215 else if(strcmp(kadecotSet, value) == 0){
216 dealer->procedure = WAMP_DEALER_PROCEDURE_KADECOT_SET;
217 dealer->args_parse = wamp_dealer_call_kadecot_param;
218 dealer->call_close = wamp_dealer_kadecot_set_close;
219 }
220 else if(strcmp(getDeviceInfo, value) == 0){
221 dealer->procedure = WAMP_DEALER_PROCEDURE_GET_DEVICEINFO;
222 dealer->args_parse = wamp_dealer_call_dummy_param;
223 dealer->call_close = wamp_dealer_get_deviceinfo_close;
224 }
225 else if(strcmp(ecnlSet, value) == 0){
226 dealer->procedure = WAMP_DEALER_PROCEDURE_ECNL_SET;
227 dealer->args_parse = wamp_dealer_call_ecnl_param;
228 dealer->call_close = wamp_dealer_ecnl_set_close;
229 }
230 else if(strcmp(ecnlGet, value) == 0){
231 dealer->procedure = WAMP_DEALER_PROCEDURE_ECNL_GET;
232 dealer->args_parse = wamp_dealer_call_ecnl_param;
233 dealer->call_close = wamp_dealer_ecnl_get_close;
234 }
235 else if(strcmp(ecnlSetGet, value) == 0){
236 dealer->procedure = WAMP_DEALER_PROCEDURE_ECNL_SETGET;
237 dealer->args_parse = wamp_dealer_call_ecnl_param;
238 dealer->call_close = wamp_dealer_ecnl_setget_close;
239 }
240 else if(strcmp(pinMode, value) == 0){
241 dealer->procedure = WAMP_DEALER_PROCEDURE_PIN_MODE;
242 dealer->args_parse = wamp_dealer_call_arduino_param;
243 dealer->call_close = wamp_dealer_pin_mode_close;
244 }
245 else if(strcmp(digitalWrite, value) == 0){
246 dealer->procedure = WAMP_DEALER_PROCEDURE_DIGITAL_WRITE;
247 dealer->args_parse = wamp_dealer_call_arduino_param;
248 dealer->call_close = wamp_dealer_digital_write_close;
249 }
250 else if(strcmp(digitalRead, value) == 0){
251 dealer->procedure = WAMP_DEALER_PROCEDURE_DIGITAL_READ;
252 dealer->args_parse = wamp_dealer_call_arduino_param;
253 dealer->call_close = wamp_dealer_digital_read_close;
254 }
255 else if(strcmp(analogRead, value) == 0){
256 dealer->procedure = WAMP_DEALER_PROCEDURE_ANALOG_READ;
257 dealer->args_parse = wamp_dealer_call_arduino_param;
258 dealer->call_close = wamp_dealer_analog_read_close;
259 }
260 else if(strcmp(analogWrite, value) == 0){
261 dealer->procedure = WAMP_DEALER_PROCEDURE_ANALOG_WRITE;
262 dealer->args_parse = wamp_dealer_call_arduino_param;
263 dealer->call_close = wamp_dealer_analog_write_close;
264 }
265 else if(strcmp(setInitParams, value) == 0){
266 dealer->procedure = WAMP_DEALER_PROCEDURE_SET_INIT_PARAMS;
267 dealer->args_parse = wamp_dealer_call_init_params_param;
268 dealer->call_close = wamp_dealer_set_init_params_close;
269 }
270 else if (strcmp(getInitParams, value) == 0) {
271 dealer->procedure = WAMP_DEALER_PROCEDURE_GET_INIT_PARAMS;
272 dealer->args_parse = wamp_dealer_call_init_params_param;
273 dealer->call_close = wamp_dealer_get_init_params_close;
274 }
275 else{
276 dealer->procedure = WAMP_DEALER_PROCEDURE_NONE;
277 dealer->args_parse = wamp_dealer_call_dummy_param;
278 dealer->call_close = wamp_dealer_none_close;
279 }
280}
281
282void wamp_dealer_call_arguments(wamp_dealer_t *dealer, const char *value)
283{
284}
285
286void wamp_dealer_call_arguments_param(wamp_dealer_t *dealer, jsonsl_action_t action,
287 struct jsonsl_state_st *state, const char *buf)
288{
289}
290
291void wamp_dealer_call_argumentskw(wamp_dealer_t *dealer, const char *value)
292{
293}
294
295void wamp_dealer_call_argumentskw_param(wamp_dealer_t *dealer, jsonsl_action_t action,
296 struct jsonsl_state_st *state, const char *buf)
297{
298 dealer->args_parse(dealer, action, state, buf);
299}
300
301static void wamp_dealer_call_dummy_param(wamp_dealer_t *dealer,
302 jsonsl_action_t action, struct jsonsl_state_st *state, const char *buf)
303{
304}
305
306static void wamp_dealer_call_kadecot_param(wamp_dealer_t *dealer,
307 jsonsl_action_t action, struct jsonsl_state_st *state, const char *buf)
308{
309 static const char propertyName[] = "propertyName";
310 static const char propertyValue[] = "propertyValue";
311
312 switch (state->level) {
313 case 3:
314 switch (action){
315 case JSONSL_ACTION_POP:
316 switch (state->type)
317 {
318 case JSONSL_T_HKEY:
319 if(strcmp(propertyName, dealer->s->jsn_buf) == 0){
320 dealer->state = WAMP_DEALER_STATE_PROPERTY_NAME;
321 }
322 else if(strcmp(propertyValue, dealer->s->jsn_buf) == 0){
323 dealer->state = WAMP_DEALER_STATE_PROPERTY_VALUE;
324 dealer->params.pdc = 0;
325 memset(dealer->params.edt, 0, sizeof(dealer->params.edt));
326 }
327 break;
328 case JSONSL_T_STRING:
329 switch(dealer->state){
330 case WAMP_DEALER_STATE_PROPERTY_NAME:
331 memcpy(dealer->params.prop_name, dealer->s->jsn_buf, sizeof(dealer->params.prop_name));
332 wamp_dealer_get_epc(dealer->params.prop_name, strnlen(dealer->params.prop_name,
333 sizeof(dealer->params.prop_name)),
334 dealer->current_device->deviceType,
335 &dealer->params.epc, &dealer->params.pdc);
336 break;
337 }
338 break;
339 default:
340 break;
341 }
342 break;
343 }
344 break;
345 case 4:
346 switch (action){
347 case JSONSL_ACTION_POP:
348 switch (state->type)
349 {
350 case JSONSL_T_SPECIAL:
351 switch(dealer->state){
352 case WAMP_DEALER_STATE_PROPERTY_VALUE:
353 dealer->params.edt[dealer->params.pdc++] = atoi(dealer->s->jsn_buf);
354 break;
355 }
356 break;
357 }
358 break;
359 }
360 break;
361 }
362}
363
364static void wamp_dealer_call_ecnl_param(wamp_dealer_t *dealer,
365 jsonsl_action_t action, struct jsonsl_state_st *state, const char *buf)
366{
367 static const char deojId[] = "deojid";
368 static const char properties[] = "properties";
369 static const char propertyCode[] = "epc";
370 static const char propertyValue[] = "edt";
371
372 switch (state->level) {
373 case 3:
374 switch (action){
375 case JSONSL_ACTION_POP:
376 switch (state->type)
377 {
378 case JSONSL_T_HKEY:
379 if(strcmp(deojId, dealer->s->jsn_buf) == 0){
380 dealer->state = WAMP_DEALER_STATE_DEOJID;
381 }
382 else if(strcmp(properties, dealer->s->jsn_buf) == 0){
383 dealer->state = WAMP_DEALER_STATE_PROPERTIES;
384 }
385 break;
386 case JSONSL_T_SPECIAL:
387 switch(dealer->state){
388 case WAMP_DEALER_STATE_DEOJID:
389 dealer->params.deojid = atoi(dealer->s->jsn_buf);
390 break;
391 }
392 break;
393 }
394 break;
395 case JSONSL_ACTION_PUSH:
396 switch (state->type)
397 {
398 case JSONSL_T_LIST:
399 switch(dealer->state){
400 case WAMP_DEALER_STATE_PROPERTIES:
401 dealer->state = WAMP_DEALER_STATE_PROPERTY_LIST;
402 break;
403 }
404 break;
405 default:
406 break;
407 }
408 break;
409 }
410 break;
411 case 4:
412 switch (action){
413 case JSONSL_ACTION_POP:
414 switch (state->type)
415 {
416 case JSONSL_T_SPECIAL:
417 switch(dealer->state){
418 }
419 break;
420 default:
421 break;
422 }
423 break;
424 }
425 break;
426 case 5:
427 switch (action){
428 case JSONSL_ACTION_POP:
429 switch (state->type)
430 {
431 case JSONSL_T_HKEY:
432 if(strcmp(propertyCode, dealer->s->jsn_buf) == 0){
433 dealer->state = WAMP_DEALER_STATE_PROPERTY_CODE;
434 }
435 else if(strcmp(propertyValue, dealer->s->jsn_buf) == 0){
436 dealer->state = WAMP_DEALER_STATE_PROPERTY_VALUE;
437 dealer->params.pdc = 0;
438 memset(dealer->params.edt, 0, sizeof(dealer->params.edt));
439 }
440 break;
441 case JSONSL_T_SPECIAL:
442 switch(dealer->state){
443 case WAMP_DEALER_STATE_PROPERTY_CODE:
444 dealer->params.epc = atoi(dealer->s->jsn_buf);
445 switch(dealer->procedure){
446 case WAMP_DEALER_PROCEDURE_ECNL_GET:
447 if (dealer->ecnl_mag == NULL){
448 ecn_esv_get(&dealer->ecnl_mag, dealer->params.deojid, dealer->params.epc);
449 }
450 else{
451 ecn_add_epc(dealer->ecnl_mag, dealer->params.epc);
452 }
453 break;
454 case WAMP_DEALER_PROCEDURE_ECNL_SETGET:
455 ecn_add_epc(dealer->ecnl_mag, dealer->params.epc);
456 break;
457 }
458 break;
459 }
460 break;
461 case JSONSL_T_STRING:
462 switch(dealer->state){
463 case WAMP_DEALER_STATE_PROPERTY_VALUE:
464 dealer->params.pdc = wamp_stob(dealer->s->jsn_buf, dealer->params.edt, sizeof(dealer->params.edt));
465 switch(dealer->procedure){
466 case WAMP_DEALER_PROCEDURE_ECNL_SET:
467 if (dealer->ecnl_mag == NULL){
468 ecn_esv_setc(&dealer->ecnl_mag, dealer->params.deojid, dealer->params.epc,
469 dealer->params.pdc, dealer->params.edt);
470 }
471 else{
472 ecn_add_edt(dealer->ecnl_mag, dealer->params.epc,
473 dealer->params.pdc, dealer->params.edt);
474 }
475 break;
476 case WAMP_DEALER_PROCEDURE_ECNL_SETGET:
477 if (dealer->ecnl_mag == NULL){
478 ecn_esv_set_get(&dealer->ecnl_mag, dealer->params.deojid, dealer->params.epc,
479 dealer->params.pdc, dealer->params.edt);
480 }
481 else{
482 ecn_add_edt(dealer->ecnl_mag, dealer->params.epc,
483 dealer->params.pdc, dealer->params.edt);
484 }
485 break;
486 }
487 break;
488 }
489 break;
490 }
491 break;
492 }
493 break;
494 }
495}
496
497static void wamp_dealer_call_arduino_param(wamp_dealer_t *dealer,
498 jsonsl_action_t action, struct jsonsl_state_st *state, const char *buf)
499{
500 static const char pin[] = "pin";
501 static const char mode[] = "mode";
502 static const char value[] = "value";
503 static const char INPUT[] = "INPUT";
504 static const char OUTPUT[] = "OUTPUT";
505 static const char INPUT_PULLUP[] = "INPUT_PULLUP";
506 static const char HIGH[] = "HIGH";
507 static const char LOW[] = "LOW";
508
509 switch (state->level) {
510 case 3:
511 switch (action){
512 case JSONSL_ACTION_POP:
513 switch (state->type)
514 {
515 case JSONSL_T_HKEY:
516 if(strcmp(pin, dealer->s->jsn_buf) == 0){
517 dealer->state = WAMP_DEALER_STATE_PIN;
518 }
519 else if(strcmp(mode, dealer->s->jsn_buf) == 0){
520 dealer->state = WAMP_DEALER_STATE_MODE;
521 }
522 else if(strcmp(value, dealer->s->jsn_buf) == 0){
523 if(dealer->procedure == WAMP_DEALER_PROCEDURE_DIGITAL_WRITE)
524 dealer->state = WAMP_DEALER_STATE_DIGITAL_VALUE;
525 else if(dealer->procedure == WAMP_DEALER_PROCEDURE_ANALOG_WRITE)
526 dealer->state = WAMP_DEALER_STATE_ANALOG_VALUE;
527 }
528 break;
529 case JSONSL_T_STRING:
530 switch(dealer->state){
531 case WAMP_DEALER_STATE_MODE:
532 if(strcmp(INPUT, dealer->s->jsn_buf) == 0){
533 dealer->arduino_params.mode = WAMP_DEALER_PIN_MODE_INPUT;
534 }
535 else if(strcmp(OUTPUT, dealer->s->jsn_buf) == 0){
536 dealer->arduino_params.mode = WAMP_DEALER_PIN_MODE_OUTPUT;
537 }
538 else if(strcmp(INPUT_PULLUP, dealer->s->jsn_buf) == 0){
539 dealer->arduino_params.mode = WAMP_DEALER_PIN_MODE_INPUT_PULLUP;
540 }
541 break;
542 case WAMP_DEALER_STATE_DIGITAL_VALUE:
543 if(strcmp(HIGH, dealer->s->jsn_buf) == 0){
544 dealer->arduino_params.digval = WAMP_DEALER_DIGITAL_VALUE_HIGH;
545 }
546 else if(strcmp(LOW, dealer->s->jsn_buf) == 0){
547 dealer->arduino_params.digval = WAMP_DEALER_DIGITAL_VALUE_LOW;
548 }
549 break;
550 }
551 break;
552 case JSONSL_T_SPECIAL:
553 switch(dealer->state){
554 case WAMP_DEALER_STATE_PIN:
555 dealer->arduino_params.pin = atoi(dealer->s->jsn_buf);
556 break;
557 case WAMP_DEALER_STATE_ANALOG_VALUE:
558 dealer->arduino_params.anaval = atoi(dealer->s->jsn_buf);
559 break;
560 }
561 break;
562 default:
563 break;
564 }
565 break;
566 }
567 break;
568 }
569}
570
571static void wamp_dealer_call_init_params_param(wamp_dealer_t *dealer,
572 jsonsl_action_t action, struct jsonsl_state_st *state, const char *buf)
573{
574 static const char macAddr[] = "macAddr";
575
576 switch (state->level) {
577 case 3:
578 switch (action){
579 case JSONSL_ACTION_POP:
580 switch (state->type)
581 {
582 case JSONSL_T_HKEY:
583 if(strcmp(macAddr, dealer->s->jsn_buf) == 0){
584 dealer->state = WAMP_DEALER_STATE_MAC_ADDR_VALUE;
585 memset(&dealer->init_params, 0, sizeof(dealer->init_params));
586 }
587 break;
588 default:
589 break;
590 }
591 break;
592 }
593 break;
594 case 4:
595 switch (action){
596 case JSONSL_ACTION_POP:
597 switch (state->type)
598 {
599 case JSONSL_T_SPECIAL:
600 switch(dealer->state){
601 case WAMP_DEALER_STATE_MAC_ADDR_VALUE:
602 dealer->init_params.mac_addr[dealer->init_params.pos++] = atoi(dealer->s->jsn_buf);
603 break;
604 }
605 break;
606 }
607 break;
608 }
609 break;
610 }
611}
612
613void wamp_dealer_call_close(struct wamp_state *s)
614{
615 wamp_dealer_t *dealer = &s->dealer;
616 ER ret;
617
618 dealer->error = internal_error;
619
620 // send RESULT
621 dealer->call_close(dealer);
622
623 if (dealer->error != NULL){
624 ret = wamp_send_error_res(s, WAMP_CODE_CALL, dealer->requestId, dealer->error);
625 if (ret != E_OK) {
626 syslog(LOG_WARNING, "wamp_dealer_call_close() : wamp_send_error_res() result = %d", ret);
627 }
628 dealer->error = NULL;
629 }
630}
631
632static void wamp_dealer_none_close(struct wamp_dealer *dealer)
633{
634 wamp_state_t *s = dealer->s;
635 ER ret;
636
637 dealer->error = NULL;
638 ret = wamp_send_error_res(s, WAMP_CODE_CALL, dealer->requestId, invalid_request);
639 if (ret != E_OK) {
640 syslog(LOG_WARNING, "wamp_dealer_none_close() : wamp_send_error_res() result = %d", ret);
641 }
642}
643
644static void wamp_dealer_get_devicelist_close(struct wamp_dealer *dealer)
645{
646 dealer->error = NULL;
647 main_get_device_list(dealer->requestId, dealer);
648}
649
650void wamp_dealer_set_devicelist(struct wamp_dealer *dealer, ECN_FBS_ID msg)
651{
652 wamp_state_t *s = dealer->s;
653 ecn_inm_get_device_item_t device;
654 ECN_FBS_SSIZE_T rlen;
655 echonetlite_device_t *dev, *end = &dealer->devices[sizeof(dealer->devices) / sizeof(dealer->devices[0])];
656 ER ret;
657
658 /* ‹@Šíî•ñ‚ðƒNƒŠƒA */
659 for(dev = dealer->devices; dev < end; dev++){
660 dev->deviceId = 0;
661 }
662
663 /* ƒƒbƒZ[ƒW‚©‚ç‹@Šíî•ñ‚ðì¬ */
664 for(dev = dealer->devices; dev < end; ){
665 ret = _ecn_fbs_get_data(msg, &device, sizeof(device), &rlen);
666 if ((ret != E_OK) || (rlen != sizeof(device)))
667 break;
668
669 if (device.enodid == 0)
670 continue;
671
672 dev->deviceId = device.eobjid;
673 dev->nodeId = device.enodid;
674 dev->addrId = device.addrid;
675 dev->deviceType = (device.eojx1 << 8) | device.eojx2;
676 dev->x3 = device.eojx3;
677 dev->status = device.state != 0;
678
679 dev++;
680 }
681
682 dealer->current_device = &dealer->devices[0];
683 dealer->devices_pos = 0;
684 main_get_device_ipaddr(dealer->requestId, dealer, dealer->current_device->addrId);
685}
686
687void wamp_dealer_get_devicelist_timeout(struct wamp_dealer *dealer)
688{
689 wamp_state_t *s = dealer->s;
690 ER ret;
691
692 ret = wamp_send_error_res(s, WAMP_CODE_CALL, dealer->requestId, internal_error);
693 if (ret != E_OK) {
694 syslog(LOG_WARNING, "wamp_dealer_get_devicelist_timeout() : wamp_send_error_res() result = %d", ret);
695 }
696}
697
698void wamp_dealer_set_ipaddr(struct wamp_dealer *dealer, char *ipaddr)
699{
700 echonetlite_device_t *dev, *end = &dealer->devices[sizeof(dealer->devices) / sizeof(dealer->devices[0])];
701 int i, devicePos;
702
703 dev = dealer->current_device;
704 if ((dev != NULL) && (ipaddr != NULL)){
705 strcpy_s(dev->ip_addr, sizeof(dev->ip_addr), ipaddr);
706
707 kadecot_names_get_device_type_name(dev->deviceType, dev->deviceTypeStr, sizeof(dev->deviceTypeStr));
708 strcpy_s(dev->description, sizeof(dev->description), dev->deviceTypeStr);
709 strcpy_s(dev->nickname, sizeof(dev->nickname), dev->deviceTypeStr);
710 }
711
712 devicePos = sizeof(dealer->devices) / sizeof(dealer->devices[0]);
713 for(i = dealer->devices_pos + 1, dev = &dealer->devices[i]; dev < end; i++, dev++){
714 if(dev->deviceId == 0)
715 continue;
716
717 devicePos = i;
718 break;
719 }
720
721 if (devicePos == sizeof(dealer->devices) / sizeof(dealer->devices[0])){
722 dealer->current_device = NULL;
723 dealer->devices_pos = 0;
724 wamp_dealer_get_devicelist(dealer);
725 }
726 else{
727 dealer->current_device = &dealer->devices[devicePos];
728 dealer->devices_pos = devicePos;
729 main_get_device_ipaddr(dealer->requestId, dealer, dealer->current_device->addrId);
730 }
731}
732
733void wamp_dealer_get_ipaddr_timeout(struct wamp_dealer *dealer)
734{
735 wamp_state_t *s = dealer->s;
736 ER ret;
737
738 ret = wamp_send_error_res(s, WAMP_CODE_CALL, dealer->requestId, internal_error);
739 if (ret != E_OK) {
740 syslog(LOG_WARNING, "wamp_dealer_get_ipaddr_timeout() : wamp_send_error_res() result = %d", ret);
741 }
742}
743
744static void wamp_dealer_get_devicelist(struct wamp_dealer *dealer)
745{
746 wamp_state_t *s = dealer->s;
747 echonetlite_device_t *dev, *end = &dealer->devices[sizeof(dealer->devices) / sizeof(dealer->devices[0])];
748 ECN_FBS_ID buf;
749 ECN_FBS_SSIZE_T pos = 0, start;
750 char ip_addr[16];
751 ER ret;
752
753 ret = _ecn_fbs_cre(1, &buf);
754 if (ret != E_OK) {
755 syslog(LOG_WARNING, "_ecn_fbs_cre() result = %d", ret);
756 return;
757 }
758
759 ret = fbs_printf(buf, &pos, "[50,%d,{},[],", dealer->requestId);
760 if (ret != E_OK) {
761 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
762 _ecn_fbs_del(buf);
763 return;
764 }
765
766 ret = fbs_printf(buf, &pos, "{\"deviceList\":["
767 "{\"description\":\"GR-SAKURA\",\"deviceId\":1,\"deviceType\":\"GrSakura\",\"ip_addr\":\"%s\",\"nickname\":\"GR-SAKURA\",\"protocol\":\"arduino\",\"status\":true},",
768 ip2str(ip_addr, uip_hostaddr));
769 if (ret != E_OK) {
770 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
771 _ecn_fbs_del(buf);
772 return;
773 }
774
775 start = pos;
776 for(dev = dealer->devices; dev < end; dev++){
777 if(dev->deviceId == 0)
778 continue;
779
780 ret = fbs_printf(buf, &pos, "{\"description\":\"%s\",\"deviceId\":%d,\"deviceType\":\"%s\",\"ip_addr\":\"%s\",\"nickname\":\"%s\",\"protocol\":\"echonetlite\",\"status\":%s},",
781 dev->description, dev->deviceId, dev->deviceTypeStr, dev->ip_addr, dev->nickname, dev->status ? "true" : "false");
782 if (ret != E_OK) {
783 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
784 _ecn_fbs_del(buf);
785 return;
786 }
787 }
788
789 /* ÅŒã‚Ì","‚ðÁ‚· */
790 if(start != pos)
791 pos--;
792
793 ret = fbs_printf(buf, &pos, "]}]");
794 if (ret != E_OK) {
795 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
796 _ecn_fbs_del(buf);
797 return;
798 }
799
800 ret = main_send_message(buf, s->wbsid);
801 if (ret != E_OK) {
802 syslog(LOG_WARNING, "wamp_dealer_get_devicelist() : main_send_message() result = %d", ret);
803 }
804}
805
806static void wamp_dealer_kadecot_get_close(struct wamp_dealer *dealer)
807{
808 echonetlite_device_t *device = dealer->current_device;
809 uint16_t devType;
810
811 if(device == NULL)
812 return;
813
814 devType = device->deviceType;
815 if(devType == 0)
816 return;
817
818 if (dealer->params.epc == 0) {
819 dealer->error = method_not_found;
820 syslog(7, method_not_found);
821 return;
822 }
823
824 dealer->error = NULL;
825 main_kadecot_get(dealer->requestId, dealer, device->deviceId, dealer->params.epc);
826}
827
828void wamp_dealer_kadecot_get(struct wamp_dealer *dealer, int deviceId, uint8_t epc,
829 uint8_t pdc, uint8_t *edt)
830{
831 wamp_state_t *s = dealer->s;
832 ECN_FBS_ID buf;
833 ECN_FBS_SSIZE_T pos = 0, start;
834 int i;
835 const char *propName;
836 ER ret;
837
838 ret = _ecn_fbs_cre(1, &buf);
839 if (ret != E_OK) {
840 syslog(LOG_WARNING, "_ecn_fbs_cre() result = %d", ret);
841 return;
842 }
843
844 ret = fbs_printf(buf, &pos, "[50,%d,{\"deviceId\":%d},[],",
845 dealer->requestId, deviceId);
846 if (ret != E_OK) {
847 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
848 _ecn_fbs_del(buf);
849 return;
850 }
851
852 propName = dealer->params.prop_name;
853 if(propName[0] != '\0'){
854 ret = fbs_printf(buf, &pos, "{\"propertyName\":\"%s\",\"propertyValue\":[",
855 propName);
856 if (ret != E_OK) {
857 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
858 _ecn_fbs_del(buf);
859 return;
860 }
861 }
862 else{
863 ret = fbs_printf(buf, &pos, "{\"propertyName\":\"0x%02x\",\"propertyValue\":[",
864 epc);
865 if (ret != E_OK) {
866 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
867 _ecn_fbs_del(buf);
868 return;
869 }
870 }
871
872 start = pos;
873 for(i = 0; i < pdc; i++){
874 ret = fbs_printf(buf, &pos, "%d,", edt[i]);
875 if (ret != E_OK) {
876 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
877 _ecn_fbs_del(buf);
878 return;
879 }
880 }
881
882 /* ÅŒã‚Ì","‚ðÁ‚· */
883 if(start != pos)
884 pos--;
885
886 ret = fbs_printf(buf, &pos, "]}]");
887 if (ret != E_OK) {
888 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
889 _ecn_fbs_del(buf);
890 return;
891 }
892
893 ret = main_send_message(buf, s->wbsid);
894 if (ret != E_OK) {
895 syslog(LOG_WARNING, "wamp_dealer_kadecot_get() : main_send_message() result = %d", ret);
896 }
897}
898
899void wamp_dealer_kadecot_set_timeout(struct wamp_dealer *dealer)
900{
901 wamp_state_t *s = dealer->s;
902 ER ret;
903
904 ret = wamp_send_error_res(s, WAMP_CODE_CALL, dealer->requestId, internal_error);
905 if (ret != E_OK) {
906 syslog(LOG_WARNING, "wamp_dealer_kadecot_set_timeout() : wamp_send_error_res() result = %d", ret);
907 }
908}
909
910static void wamp_dealer_kadecot_set_close(struct wamp_dealer *dealer)
911{
912 echonetlite_device_t *device = dealer->current_device;
913 uint16_t devType;
914
915 if(device == NULL)
916 return;
917
918 devType = device->deviceType;
919 if(devType == 0)
920 return;
921
922 if(dealer->params.epc == 0){
923 dealer->error = method_not_found;
924 return;
925 }
926
927 dealer->error = NULL;
928 main_kadecot_set(dealer->requestId, dealer, device->deviceId, dealer->params.epc,
929 dealer->params.pdc, dealer->params.edt);
930}
931
932void wamp_dealer_kadecot_set(struct wamp_dealer *dealer, int deviceId, uint8_t epc)
933{
934 wamp_state_t *s = dealer->s;
935 ECN_FBS_ID buf;
936 ECN_FBS_SSIZE_T pos = 0, start;
937 int i;
938 const char *propName;
939 ER ret;
940
941 ret = _ecn_fbs_cre(1, &buf);
942 if (ret != E_OK) {
943 syslog(LOG_WARNING, "_ecn_fbs_cre() result = %d", ret);
944 return;
945 }
946
947 ret = fbs_printf(buf, &pos, "[50,%d,{\"deviceId\":%d},[],",
948 dealer->requestId, deviceId);
949 if (ret != E_OK) {
950 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
951 _ecn_fbs_del(buf);
952 return;
953 }
954
955 propName = dealer->params.prop_name;
956 if(propName[0] != '\0'){
957 ret = fbs_printf(buf, &pos, "{\"propertyName\":\"%s\",\"propertyValue\":[",
958 propName);
959 if (ret != E_OK) {
960 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
961 _ecn_fbs_del(buf);
962 return;
963 }
964 }
965 else{
966 ret = fbs_printf(buf, &pos, "{\"propertyName\":\"0x%02x\",\"propertyValue\":[",
967 epc);
968 if (ret != E_OK) {
969 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
970 _ecn_fbs_del(buf);
971 return;
972 }
973 }
974
975 start = pos;
976 for(i = 0; i < dealer->params.pdc; i++){
977 ret = fbs_printf(buf, &pos, "%d,", dealer->params.edt[i]);
978 if (ret != E_OK) {
979 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
980 _ecn_fbs_del(buf);
981 return;
982 }
983 }
984
985 /* ÅŒã‚Ì","‚ðÁ‚· */
986 if(start != pos)
987 pos--;
988
989 ret = fbs_printf(buf, &pos, "]}]");
990 if (ret != E_OK) {
991 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
992 _ecn_fbs_del(buf);
993 return;
994 }
995
996 ret = main_send_message(buf, s->wbsid);
997 if (ret != E_OK) {
998 syslog(LOG_WARNING, "wamp_dealer_kadecot_set() : main_send_message() result = %d", ret);
999 }
1000}
1001
1002void wamp_dealer_kadecot_get_timeout(struct wamp_dealer *dealer)
1003{
1004 wamp_state_t *s = dealer->s;
1005 ER ret;
1006
1007 ret = wamp_send_error_res(s, WAMP_CODE_CALL, dealer->requestId, internal_error);
1008 if (ret != E_OK) {
1009 syslog(LOG_WARNING, "wamp_dealer_kadecot_get_timeout() : wamp_send_error_res() result = %d", ret);
1010 }
1011}
1012
1013static void wamp_dealer_get_deviceinfo_close(struct wamp_dealer *dealer)
1014{
1015 echonetlite_device_t *device = dealer->current_device;
1016 if(device == NULL)
1017 return;
1018
1019 dealer->error = NULL;
1020 main_get_device_info(dealer->requestId, dealer, device->deviceId);
1021}
1022
1023void wamp_dealer_set_deviceinfo(struct wamp_dealer *dealer, int deviceId, uint8_t *pmset,
1024 uint8_t *pmget, uint8_t *pmanno)
1025{
1026 wamp_state_t *s = dealer->s;
1027 echonetlite_device_t *device = dealer->current_device;
1028 ECN_FBS_ID buf;
1029 ECN_FBS_SSIZE_T pos = 0;
1030 int i, j, m, prop;
1031 ER ret;
1032
1033 if(device == NULL)
1034 return;
1035
1036 ret = _ecn_fbs_cre(1, &buf);
1037 if (ret != E_OK) {
1038 syslog(LOG_WARNING, "_ecn_fbs_cre() result = %d", ret);
1039 return;
1040 }
1041
1042 ret = fbs_printf(buf, &pos, "[50,%d,{\"deviceId\":%d},[],",
1043 dealer->requestId, deviceId);
1044 if (ret != E_OK) {
1045 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1046 _ecn_fbs_del(buf);
1047 return;
1048 }
1049
1050 ret = fbs_printf(buf, &pos, "{\"x1\":%d,\"x2\":%d,\"x3\":%d,\"enodid\":%d,\"properties\":[",
1051 device->deviceType >> 8, device->deviceType & 0xFF, device->x3, device->nodeId);
1052 if (ret != E_OK) {
1053 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1054 _ecn_fbs_del(buf);
1055 return;
1056 }
1057
1058 prop = pos;
1059 for(i = 0; i < 16; i++){
1060 uint8_t pms = pmset[i], pmg = pmget[i], pma = pmanno[i], exs = pms | pmg | pma;
1061
1062 for(j = 0; j < 8; j++){
1063 m = 1 << j;
1064 if(!(exs & m))
1065 continue;
1066
1067 ret = fbs_printf(buf, &pos, "{\"epc\":%d,\"flag\":\"", 0x80 | (j << 4) | i);
1068 if (ret != E_OK) {
1069 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1070 _ecn_fbs_del(buf);
1071 return;
1072 }
1073 if (pms & m) {
1074 ret = fbs_printf(buf, &pos, "RULE_SET,");
1075 if (ret != E_OK) {
1076 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1077 _ecn_fbs_del(buf);
1078 return;
1079 }
1080 }
1081 if (pmg & m) {
1082 ret = fbs_printf(buf, &pos, "RULE_GET,");
1083 if (ret != E_OK) {
1084 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1085 _ecn_fbs_del(buf);
1086 return;
1087 }
1088 }
1089 if (pma & m) {
1090 ret = fbs_printf(buf, &pos, "ANNOUNCE,");
1091 if (ret != E_OK) {
1092 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1093 _ecn_fbs_del(buf);
1094 return;
1095 }
1096 }
1097 /* ÅŒã‚Ì","‚ðÁ‚· */
1098 pos--;
1099
1100 ret = fbs_printf(buf, &pos, "\"},");
1101 if (ret != E_OK) {
1102 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1103 _ecn_fbs_del(buf);
1104 return;
1105 }
1106 }
1107 }
1108
1109 /* ÅŒã‚Ì","‚ðÁ‚· */
1110 if(prop != pos)
1111 pos--;
1112
1113 ret = fbs_printf(buf, &pos, "]}]");
1114 if (ret != E_OK) {
1115 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1116 _ecn_fbs_del(buf);
1117 return;
1118 }
1119
1120 ret = main_send_message(buf, s->wbsid);
1121 if (ret != E_OK) {
1122 syslog(LOG_WARNING, "wamp_dealer_set_deviceinfo() : main_send_message() result = %d", ret);
1123 }
1124}
1125
1126void wamp_dealer_get_deviceinfo_timeout(struct wamp_dealer *dealer)
1127{
1128 wamp_state_t *s = dealer->s;
1129 ER ret;
1130
1131 ret = wamp_send_error_res(s, WAMP_CODE_CALL, dealer->requestId, internal_error);
1132 if (ret != E_OK) {
1133 syslog(LOG_WARNING, "wamp_dealer_get_deviceinfo_timeout() : wamp_send_error_res() result = %d", ret);
1134 }
1135}
1136
1137static void wamp_dealer_ecnl_set_close(struct wamp_dealer *dealer)
1138{
1139 ER ret;
1140 echonetlite_device_t *device = dealer->current_device;
1141 ECN_FBS_ID buf = { (T_ECN_FST_BLK *)dealer->ecnl_mag };
1142
1143 if (dealer->ecnl_mag == NULL)
1144 return;
1145
1146 if(device == NULL){
1147 _ecn_fbs_del(buf);
1148 return;
1149 }
1150
1151 ret = main_ecnl_set(dealer->requestId, dealer, device->deviceId, dealer->ecnl_mag);
1152 if (ret == E_OK) {
1153 dealer->error = NULL;
1154 }
1155 else {
1156 _ecn_fbs_del(buf);
1157 }
1158
1159 dealer->ecnl_mag = NULL;
1160}
1161
1162void wamp_dealer_ecnl_set_res(struct wamp_dealer *dealer, T_EDATA *esv)
1163{
1164 wamp_state_t *s = dealer->s;
1165 echonetlite_device_t *device = dealer->current_device;
1166 ECN_FBS_ID buf;
1167 ECN_FBS_SSIZE_T pos = 0, start;
1168 uint8_t epc;
1169 uint8_t pdc;
1170 uint8_t p_edt[256];
1171 T_ENUM_EPC enm;
1172 int j;
1173 ER ret;
1174
1175 if(device == NULL)
1176 return;
1177
1178 ret = _ecn_fbs_cre(1, &buf);
1179 if (ret != E_OK) {
1180 syslog(LOG_WARNING, "_ecn_fbs_cre() result = %d", ret);
1181 return;
1182 }
1183
1184 ret = fbs_printf(buf, &pos, "[50,%d,{\"deviceId\":%d},[],",
1185 dealer->requestId, device->deviceId);
1186 if (ret != E_OK) {
1187 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1188 _ecn_fbs_del(buf);
1189 return;
1190 }
1191
1192 /* ƒvƒƒpƒeƒB’l‘‚«ž‚݉ž“š 0x71 */
1193 ret = fbs_printf(buf, &pos, "{\"esv\":113,\"sender\":%d,\"seoj\":\"%02x%02x%02x\",\"deoj\":\"%02x%02x%02x\",\"properties\":[",
1194 ecn_get_enod(esv), esv->hdr.edata.seoj.eojx1, esv->hdr.edata.seoj.eojx2, esv->hdr.edata.seoj.eojx3,
1195 esv->hdr.edata.deoj.eojx1, esv->hdr.edata.deoj.eojx2, esv->hdr.edata.deoj.eojx3);
1196 if (ret != E_OK) {
1197 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1198 _ecn_fbs_del(buf);
1199 return;
1200 }
1201
1202 ret = ecn_itr_ini(&enm, esv);
1203 if (ret != E_OK){
1204 syslog(LOG_ERROR, "ecn_itr_ini");
1205 return;
1206 }
1207
1208 start = pos;
1209 for(;;) {
1210 while ((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
1211 if (pdc == 0) {
1212 ret = fbs_printf(buf, &pos, "{\"epc\":%d},", epc);
1213 if (ret != E_OK) {
1214 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1215 _ecn_fbs_del(buf);
1216 return;
1217 }
1218 }
1219 else {
1220 ret = fbs_printf(buf, &pos, "{\"epc\":%d,\"edt\":\"", epc);
1221 if (ret != E_OK) {
1222 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1223 _ecn_fbs_del(buf);
1224 return;
1225 }
1226 for(j = 0; j < pdc; j++){
1227 ret = fbs_printf(buf, &pos, "%02x", p_edt[j]);
1228 if (ret != E_OK) {
1229 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1230 _ecn_fbs_del(buf);
1231 return;
1232 }
1233 }
1234 ret = fbs_printf(buf, &pos, "\"},");
1235 if (ret != E_OK) {
1236 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1237 _ecn_fbs_del(buf);
1238 return;
1239 }
1240 }
1241 }
1242 if(ret != E_BOVR){
1243 syslog(LOG_ERROR, "ecn_itr_nxt");
1244 break;
1245 }
1246 if(enm.is_eof)
1247 break;
1248 }
1249
1250 /* ÅŒã‚Ì","‚ðÁ‚· */
1251 if(start != pos)
1252 pos--;
1253
1254 ret = fbs_printf(buf, &pos, "]}]");
1255 if (ret != E_OK) {
1256 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1257 _ecn_fbs_del(buf);
1258 return;
1259 }
1260
1261 ret = main_send_message(buf, s->wbsid);
1262 if (ret != E_OK) {
1263 syslog(LOG_WARNING, "wamp_dealer_ecnl_set_res() : main_send_message() result = %d", ret);
1264 }
1265}
1266
1267void wamp_dealer_ecnl_set_timeout(struct wamp_dealer *dealer)
1268{
1269 wamp_state_t *s = dealer->s;
1270 ER ret;
1271
1272 ret = wamp_send_error_res(s, WAMP_CODE_CALL, dealer->requestId, internal_error);
1273 if (ret != E_OK) {
1274 syslog(LOG_WARNING, "wamp_dealer_ecnl_set_timeout() : wamp_send_error_res() result = %d", ret);
1275 }
1276}
1277
1278static void wamp_dealer_ecnl_get_close(struct wamp_dealer *dealer)
1279{
1280 ER ret;
1281 echonetlite_device_t *device = dealer->current_device;
1282 ECN_FBS_ID buf = { (T_ECN_FST_BLK *)dealer->ecnl_mag };
1283
1284 if (dealer->ecnl_mag == NULL)
1285 return;
1286
1287 if(device == NULL){
1288 _ecn_fbs_del(buf);
1289 return;
1290 }
1291
1292 ret = main_ecnl_get(dealer->requestId, dealer, device->deviceId, dealer->ecnl_mag);
1293 if (ret == E_OK) {
1294 dealer->error = NULL;
1295 }
1296 else {
1297 _ecn_fbs_del(buf);
1298 }
1299
1300 dealer->ecnl_mag = NULL;
1301}
1302
1303void wamp_dealer_ecnl_get_res(struct wamp_dealer *dealer, T_EDATA *esv)
1304{
1305 wamp_state_t *s = dealer->s;
1306 echonetlite_device_t *device = dealer->current_device;
1307 ECN_FBS_ID buf;
1308 ECN_FBS_SSIZE_T pos = 0, start;
1309 uint8_t epc;
1310 uint8_t pdc;
1311 uint8_t p_edt[256];
1312 T_ENUM_EPC enm;
1313 int j;
1314 ER ret;
1315
1316 if(device == NULL)
1317 return;
1318
1319 ret = _ecn_fbs_cre(1, &buf);
1320 if (ret != E_OK) {
1321 syslog(LOG_WARNING, "_ecn_fbs_cre() result = %d", ret);
1322 return;
1323 }
1324
1325 ret = fbs_printf(buf, &pos, "[50,%d,{\"deviceId\":%d},[],",
1326 dealer->requestId, device->deviceId);
1327 if (ret != E_OK) {
1328 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1329 _ecn_fbs_del(buf);
1330 return;
1331 }
1332
1333 /* ƒvƒƒpƒeƒB’l“ǂݍž‚݉ž“š 0x72 */
1334 ret = fbs_printf(buf, &pos, "{\"esv\":114,\"sender\":%d,\"seoj\":\"%02x%02x%02x\",\"deoj\":\"%02x%02x%02x\",\"properties\":[",
1335 ecn_get_enod(esv), esv->hdr.edata.seoj.eojx1, esv->hdr.edata.seoj.eojx2, esv->hdr.edata.seoj.eojx3,
1336 esv->hdr.edata.deoj.eojx1, esv->hdr.edata.deoj.eojx2, esv->hdr.edata.deoj.eojx3);
1337 if (ret != E_OK) {
1338 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1339 _ecn_fbs_del(buf);
1340 return;
1341 }
1342
1343 ret = ecn_itr_ini(&enm, esv);
1344 if (ret != E_OK){
1345 syslog(LOG_ERROR, "ecn_itr_ini");
1346 return;
1347 }
1348
1349 start = pos;
1350 for(;;) {
1351 while ((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
1352 if (pdc == 0) {
1353 ret = fbs_printf(buf, &pos, "{\"epc\":%d},", epc);
1354 if (ret != E_OK) {
1355 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1356 _ecn_fbs_del(buf);
1357 return;
1358 }
1359 }
1360 else {
1361 ret = fbs_printf(buf, &pos, "{\"epc\":%d,\"edt\":\"", epc);
1362 if (ret != E_OK) {
1363 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1364 _ecn_fbs_del(buf);
1365 return;
1366 }
1367 for(j = 0; j < pdc; j++){
1368 ret = fbs_printf(buf, &pos, "%02x", p_edt[j]);
1369 if (ret != E_OK) {
1370 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1371 _ecn_fbs_del(buf);
1372 return;
1373 }
1374 }
1375 ret = fbs_printf(buf, &pos, "\"},");
1376 if (ret != E_OK) {
1377 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1378 _ecn_fbs_del(buf);
1379 return;
1380 }
1381 }
1382 }
1383 if(ret != E_BOVR){
1384 syslog(LOG_ERROR, "ecn_itr_nxt");
1385 break;
1386 }
1387 if(enm.is_eof)
1388 break;
1389 }
1390
1391 /* ÅŒã‚Ì","‚ðÁ‚· */
1392 if(start != pos)
1393 pos--;
1394
1395 ret = fbs_printf(buf, &pos, "]}]");
1396 if (ret != E_OK) {
1397 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1398 _ecn_fbs_del(buf);
1399 return;
1400 }
1401
1402 ret = main_send_message(buf, s->wbsid);
1403 if (ret != E_OK) {
1404 syslog(LOG_WARNING, "wamp_dealer_ecnl_get_res() : main_send_message() result = %d", ret);
1405 }
1406}
1407
1408void wamp_dealer_ecnl_get_timeout(struct wamp_dealer *dealer)
1409{
1410 wamp_state_t *s = dealer->s;
1411 ER ret;
1412
1413 ret = wamp_send_error_res(s, WAMP_CODE_CALL, dealer->requestId, internal_error);
1414 if (ret != E_OK) {
1415 syslog(LOG_WARNING, "wamp_dealer_ecnl_get_timeout() : wamp_send_error_res() result = %d", ret);
1416 }
1417}
1418
1419static void wamp_dealer_ecnl_setget_close(struct wamp_dealer *dealer)
1420{
1421 ER ret;
1422 echonetlite_device_t *device = dealer->current_device;
1423 ECN_FBS_ID buf = { (T_ECN_FST_BLK *)dealer->ecnl_mag };
1424
1425 if (dealer->ecnl_mag == NULL)
1426 return;
1427
1428 if(device == NULL){
1429 _ecn_fbs_del(buf);
1430 return;
1431 }
1432
1433 ret = main_ecnl_setget(dealer->requestId, dealer, device->deviceId, dealer->ecnl_mag);
1434 if (ret == E_OK) {
1435 dealer->error = NULL;
1436 }
1437 else {
1438 _ecn_fbs_del(buf);
1439 }
1440
1441 dealer->ecnl_mag = NULL;
1442}
1443
1444void wamp_dealer_ecnl_setget_res(struct wamp_dealer *dealer, T_EDATA *esv)
1445{
1446 wamp_state_t *s = dealer->s;
1447 echonetlite_device_t *device = dealer->current_device;
1448 ECN_FBS_ID buf;
1449 ECN_FBS_SSIZE_T pos = 0, start;
1450 uint8_t epc;
1451 uint8_t pdc;
1452 uint8_t p_edt[256];
1453 T_ENUM_EPC enm;
1454 int j;
1455 ER ret;
1456
1457 if(device == NULL)
1458 return;
1459
1460 ret = _ecn_fbs_cre(1, &buf);
1461 if (ret != E_OK) {
1462 syslog(LOG_WARNING, "_ecn_fbs_cre() result = %d", ret);
1463 return;
1464 }
1465
1466 ret = fbs_printf(buf, &pos, "[50,%d,{\"deviceId\":%d},[],",
1467 dealer->requestId, device->deviceId);
1468 if (ret != E_OK) {
1469 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1470 _ecn_fbs_del(buf);
1471 return;
1472 }
1473
1474 /* ƒvƒƒpƒeƒB’l‘‚«ž‚݁E“ǂݍž‚݉ž“š 0x7E */
1475 ret = fbs_printf(buf, &pos, "{\"esv\":126,\"sender\":%d,\"seoj\":\"%02x%02x%02x\",\"deoj\":\"%02x%02x%02x\",\"properties\":[",
1476 ecn_get_enod(esv), esv->hdr.edata.seoj.eojx1, esv->hdr.edata.seoj.eojx2, esv->hdr.edata.seoj.eojx3,
1477 esv->hdr.edata.deoj.eojx1, esv->hdr.edata.deoj.eojx2, esv->hdr.edata.deoj.eojx3);
1478 if (ret != E_OK) {
1479 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1480 _ecn_fbs_del(buf);
1481 return;
1482 }
1483
1484 ret = ecn_itr_ini(&enm, esv);
1485 if (ret != E_OK){
1486 syslog(LOG_ERROR, "ecn_itr_ini");
1487 return;
1488 }
1489
1490 start = pos;
1491 for(;;) {
1492 while ((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
1493 if (pdc == 0) {
1494 ret = fbs_printf(buf, &pos, "{\"epc\":%d},", epc);
1495 if (ret != E_OK) {
1496 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1497 _ecn_fbs_del(buf);
1498 return;
1499 }
1500 }
1501 else {
1502 ret = fbs_printf(buf, &pos, "{\"epc\":%d,\"edt\":\"", epc);
1503 if (ret != E_OK) {
1504 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1505 _ecn_fbs_del(buf);
1506 return;
1507 }
1508 for(j = 0; j < pdc; j++){
1509 ret = fbs_printf(buf, &pos, "%02x", p_edt[j]);
1510 if (ret != E_OK) {
1511 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1512 _ecn_fbs_del(buf);
1513 return;
1514 }
1515 }
1516 ret = fbs_printf(buf, &pos, "\"},");
1517 if (ret != E_OK) {
1518 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1519 _ecn_fbs_del(buf);
1520 return;
1521 }
1522 }
1523 }
1524 if(ret != E_BOVR){
1525 syslog(LOG_ERROR, "ecn_itr_nxt");
1526 break;
1527 }
1528 if(enm.is_eof)
1529 break;
1530 }
1531
1532 /* ÅŒã‚Ì","‚ðÁ‚· */
1533 if(start != pos)
1534 pos--;
1535
1536 ret = fbs_printf(buf, &pos, "]}]");
1537 if (ret != E_OK) {
1538 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1539 _ecn_fbs_del(buf);
1540 return;
1541 }
1542
1543 ret = main_send_message(buf, s->wbsid);
1544 if (ret != E_OK) {
1545 syslog(LOG_WARNING, "wamp_dealer_ecnl_setget_res() : main_send_message() result = %d", ret);
1546 }
1547}
1548
1549void wamp_dealer_ecnl_setget_timeout(struct wamp_dealer *dealer)
1550{
1551 wamp_state_t *s = dealer->s;
1552 ER ret;
1553
1554 ret = wamp_send_error_res(s, WAMP_CODE_CALL, dealer->requestId, internal_error);
1555 if (ret != E_OK) {
1556 syslog(LOG_WARNING, "wamp_dealer_ecnl_setget_timeout() : wamp_send_error_res() result = %d", ret);
1557 }
1558}
1559
1560static void wamp_dealer_pin_mode_close(struct wamp_dealer *dealer)
1561{
1562 wamp_state_t *s = dealer->s;
1563 ECN_FBS_ID buf;
1564 ECN_FBS_SSIZE_T pos = 0;
1565 ER ret = E_PAR;
1566
1567 switch(dealer->arduino_params.mode){
1568 case WAMP_DEALER_PIN_MODE_INPUT:
1569 ret = arduino_pinMode(dealer->arduino_params.pin, ARDUINO_PIN_MODE_INPUT);
1570 break;
1571 case WAMP_DEALER_PIN_MODE_OUTPUT:
1572 ret = arduino_pinMode(dealer->arduino_params.pin, ARDUINO_PIN_MODE_OUTPUT);
1573 break;
1574 case WAMP_DEALER_PIN_MODE_INPUT_PULLUP:
1575 ret = arduino_pinMode(dealer->arduino_params.pin, ARDUINO_PIN_MODE_INPUT_PULLUP);
1576 break;
1577 }
1578
1579 if (ret != E_OK)
1580 return;
1581
1582 ret = _ecn_fbs_cre(1, &buf);
1583 if (ret != E_OK) {
1584 syslog(LOG_WARNING, "_ecn_fbs_cre() result = %d", ret);
1585 return;
1586 }
1587
1588 ret = fbs_printf(buf, &pos, "[50,%d,{\"deviceId\":1},[],{}]", dealer->requestId);
1589 if (ret != E_OK) {
1590 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1591 _ecn_fbs_del(buf);
1592 return;
1593 }
1594
1595 ret = main_send_message(buf, s->wbsid);
1596 if (ret != E_OK) {
1597 syslog(LOG_WARNING, "main_send_message() result = %d", ret);
1598 return;
1599 }
1600
1601 dealer->error = NULL;
1602}
1603
1604static void wamp_dealer_digital_write_close(struct wamp_dealer *dealer)
1605{
1606 wamp_state_t *s = dealer->s;
1607 ECN_FBS_ID buf;
1608 ECN_FBS_SSIZE_T pos = 0;
1609 ER ret = E_PAR;
1610
1611 switch(dealer->arduino_params.digval){
1612 case WAMP_DEALER_DIGITAL_VALUE_HIGH:
1613 ret = arduino_digitalWrite(dealer->arduino_params.pin, ARDUINO_DIGITAL_VALUE_HIGH);
1614 break;
1615 case WAMP_DEALER_DIGITAL_VALUE_LOW:
1616 ret = arduino_digitalWrite(dealer->arduino_params.pin, ARDUINO_DIGITAL_VALUE_LOW);
1617 break;
1618 }
1619
1620 if (ret != E_OK)
1621 return;
1622
1623 ret = _ecn_fbs_cre(1, &buf);
1624 if (ret != E_OK) {
1625 syslog(LOG_WARNING, "_ecn_fbs_cre() result = %d", ret);
1626 return;
1627 }
1628
1629 ret = fbs_printf(buf, &pos, "[50,%d,{\"deviceId\":1},[],{}]", dealer->requestId);
1630 if (ret != E_OK) {
1631 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1632 _ecn_fbs_del(buf);
1633 return;
1634 }
1635
1636 ret = main_send_message(buf, s->wbsid);
1637 if (ret != E_OK) {
1638 syslog(LOG_WARNING, "main_send_message() result = %d", ret);
1639 return;
1640 }
1641
1642 dealer->error = NULL;
1643}
1644
1645static void wamp_dealer_digital_read_close(struct wamp_dealer *dealer)
1646{
1647 const static char *values[] = { "", "HIGH", "LOW" };
1648 wamp_state_t *s = dealer->s;
1649 ECN_FBS_ID buf;
1650 ECN_FBS_SSIZE_T pos = 0;
1651 arduino_digital_value_t value;
1652 ER ret;
1653
1654 ret = arduino_digitalRead(dealer->arduino_params.pin, &value);
1655 if (ret != E_OK)
1656 return;
1657
1658 ret = _ecn_fbs_cre(1, &buf);
1659 if (ret != E_OK) {
1660 syslog(LOG_WARNING, "_ecn_fbs_cre() result = %d", ret);
1661 return;
1662 }
1663
1664 ret = fbs_printf(buf, &pos, "[50,%d,{\"deviceId\":1},[],{", dealer->requestId);
1665 if (ret != E_OK) {
1666 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1667 _ecn_fbs_del(buf);
1668 return;
1669 }
1670
1671 ret = fbs_printf(buf, &pos, "\"pin\":%d,\"value\":\"%s\"",
1672 dealer->arduino_params.pin, values[value]);
1673 if (ret != E_OK) {
1674 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1675 _ecn_fbs_del(buf);
1676 return;
1677 }
1678
1679 ret = fbs_printf(buf, &pos, "}]");
1680 if (ret != E_OK) {
1681 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1682 _ecn_fbs_del(buf);
1683 return;
1684 }
1685
1686 ret = main_send_message(buf, s->wbsid);
1687 if (ret != E_OK) {
1688 syslog(LOG_WARNING, "main_send_message() result = %d", ret);
1689 return;
1690 }
1691
1692 dealer->error = NULL;
1693}
1694
1695static void wamp_dealer_analog_read_close(struct wamp_dealer *dealer)
1696{
1697 wamp_state_t *s = dealer->s;
1698 ECN_FBS_ID buf;
1699 ECN_FBS_SSIZE_T pos = 0;
1700 int value;
1701 ER ret;
1702
1703 ret = arduino_analogRead(dealer->arduino_params.pin, &value);
1704 if (ret != E_OK)
1705 return;
1706
1707 ret = _ecn_fbs_cre(1, &buf);
1708 if (ret != E_OK) {
1709 syslog(LOG_WARNING, "_ecn_fbs_cre() result = %d", ret);
1710 return;
1711 }
1712
1713 ret = fbs_printf(buf, &pos, "[50,%d,{\"deviceId\":1},[],{", dealer->requestId);
1714 if (ret != E_OK) {
1715 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1716 _ecn_fbs_del(buf);
1717 return;
1718 }
1719
1720 ret = fbs_printf(buf, &pos, "\"pin\":%d,\"value\":%d",
1721 dealer->arduino_params.pin, value);
1722 if (ret != E_OK) {
1723 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1724 _ecn_fbs_del(buf);
1725 return;
1726 }
1727
1728 ret = fbs_printf(buf, &pos, "}]");
1729 if (ret != E_OK) {
1730 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1731 _ecn_fbs_del(buf);
1732 return;
1733 }
1734
1735 ret = main_send_message(buf, s->wbsid);
1736 if (ret != E_OK) {
1737 syslog(LOG_WARNING, "main_send_message() result = %d", ret);
1738 return;
1739 }
1740
1741 dealer->error = NULL;
1742}
1743
1744static void wamp_dealer_analog_write_close(struct wamp_dealer *dealer)
1745{
1746 wamp_state_t *s = dealer->s;
1747 ECN_FBS_ID buf;
1748 ECN_FBS_SSIZE_T pos = 0;
1749 ER ret;
1750
1751 ret = arduino_analogWrite(dealer->arduino_params.pin, dealer->arduino_params.anaval);
1752 if (ret != E_OK)
1753 return;
1754
1755 ret = _ecn_fbs_cre(1, &buf);
1756 if (ret != E_OK) {
1757 syslog(LOG_WARNING, "_ecn_fbs_cre() result = %d", ret);
1758 return;
1759 }
1760
1761 ret = fbs_printf(buf, &pos, "[50,%d,{\"deviceId\":1},[],{}]", dealer->requestId);
1762 if (ret != E_OK) {
1763 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1764 _ecn_fbs_del(buf);
1765 return;
1766 }
1767
1768 ret = main_send_message(buf, s->wbsid);
1769 if (ret != E_OK) {
1770 syslog(LOG_WARNING, "main_send_message() result = %d", ret);
1771 return;
1772 }
1773
1774 dealer->error = NULL;
1775}
1776
1777static void wamp_dealer_set_init_params_close(struct wamp_dealer *dealer)
1778{
1779 wamp_state_t *s = dealer->s;
1780 ECN_FBS_ID buf;
1781 ECN_FBS_SSIZE_T pos = 0;
1782 ER ret;
1783
1784 ret = data_flash_write(0, dealer->init_params.mac_addr);
1785 if (ret != E_OK) {
1786 syslog(LOG_WARNING, "data_flash_write() result = %d", ret);
1787 return;
1788 }
1789
1790 ret = _ecn_fbs_cre(1, &buf);
1791 if (ret != E_OK) {
1792 syslog(LOG_WARNING, "_ecn_fbs_cre() result = %d", ret);
1793 return;
1794 }
1795
1796 ret = fbs_printf(buf, &pos, "[50,%d,{\"deviceId\":1},[],{}]", dealer->requestId);
1797 if (ret != E_OK) {
1798 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1799 _ecn_fbs_del(buf);
1800 return;
1801 }
1802
1803 ret = main_send_message(buf, s->wbsid);
1804 if (ret != E_OK) {
1805 syslog(LOG_WARNING, "main_send_message() result = %d", ret);
1806 return;
1807 }
1808
1809 dealer->error = NULL;
1810}
1811
1812static void wamp_dealer_get_init_params_close(struct wamp_dealer *dealer)
1813{
1814 wamp_state_t *s = dealer->s;
1815 ECN_FBS_ID buf;
1816 ECN_FBS_SSIZE_T pos = 0;
1817 ER ret;
1818 int i;
1819
1820 ret = data_flash_read(0, dealer->init_params.mac_addr);
1821 if (ret != E_OK) {
1822 syslog(LOG_WARNING, "data_flash_read() result = %d", ret);
1823 return;
1824 }
1825
1826 ret = _ecn_fbs_cre(1, &buf);
1827 if (ret != E_OK) {
1828 syslog(LOG_WARNING, "_ecn_fbs_cre() result = %d", ret);
1829 return;
1830 }
1831
1832 ret = fbs_printf(buf, &pos, "[50,%d,{},[],{\"macAddr\":[", dealer->requestId);
1833 if (ret != E_OK) {
1834 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1835 _ecn_fbs_del(buf);
1836 return;
1837 }
1838
1839 for (i = 0; i < 6; i++) {
1840 ret = fbs_printf(buf, &pos, "%d,", dealer->init_params.mac_addr[i]);
1841 if (ret != E_OK) {
1842 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1843 _ecn_fbs_del(buf);
1844 return;
1845 }
1846 }
1847
1848 /* ÅŒã‚Ì","‚ðÁ‚· */
1849 pos--;
1850
1851 ret = fbs_printf(buf, &pos, "]}]");
1852 if (ret != E_OK) {
1853 syslog(LOG_WARNING, "fbs_printf() result = %d", ret);
1854 _ecn_fbs_del(buf);
1855 return;
1856 }
1857
1858 ret = main_send_message(buf, s->wbsid);
1859 if (ret != E_OK) {
1860 syslog(LOG_WARNING, "main_send_message() result = %d", ret);
1861 return;
1862 }
1863
1864 dealer->error = NULL;
1865}
1866
1867void wamp_dealer_yield(wamp_dealer_t *dealer)
1868{
1869}
1870
1871void wamp_dealer_yield_request_id(wamp_dealer_t *dealer, const char *value)
1872{
1873}
1874
1875void wamp_dealer_yield_options(wamp_dealer_t *dealer, const char *value)
1876{
1877}
1878
1879void wamp_dealer_yield_options_param(wamp_dealer_t *dealer, jsonsl_action_t action,
1880 struct jsonsl_state_st *state, const char *buf)
1881{
1882}
1883
1884void wamp_dealer_yield_arguments(wamp_dealer_t *dealer, const char *value)
1885{
1886}
1887
1888void wamp_dealer_yield_arguments_param(wamp_dealer_t *dealer, jsonsl_action_t action,
1889 struct jsonsl_state_st *state, const char *buf)
1890{
1891}
1892
1893void wamp_dealer_yield_argumentskw(wamp_dealer_t *dealer, const char *value)
1894{
1895}
1896
1897void wamp_dealer_yield_argumentskw_param(wamp_dealer_t *dealer, jsonsl_action_t action,
1898 struct jsonsl_state_st *state, const char *buf)
1899{
1900}
1901
1902void wamp_dealer_yield_close(struct wamp_state *s)
1903{
1904}
1905
1906void wamp_dealer_cansel(wamp_dealer_t *dealer)
1907{
1908}
1909
1910void wamp_dealer_cansel_request_id(wamp_dealer_t *dealer, const char *value)
1911{
1912}
1913
1914void wamp_dealer_cansel_options(wamp_dealer_t *dealer, const char *value)
1915{
1916}
1917
1918void wamp_dealer_cansel_options_param(wamp_dealer_t *dealer, jsonsl_action_t action,
1919 struct jsonsl_state_st *state, const char *buf)
1920{
1921}
1922
1923void wamp_dealer_cansel_close(struct wamp_state *s)
1924{
1925}
1926
1927static bool_t wamp_dealer_get_epc(const char *propName, int nameLen,
1928 uint16_t devType, uint8_t *epc, uint8_t *pdc)
1929{
1930 if(propName[0] == '0' && propName[1] == 'x'){
1931 if((wamp_stob(&propName[2], epc, sizeof(*epc)) != 1)
1932 || (propName[4] != '\0')){
1933 *epc = 0;
1934 *pdc = 0;
1935 return false;
1936 }
1937
1938 *pdc = 1;
1939 return true;
1940 }
1941
1942 *epc = kadecot_names_get_property_code(propName, nameLen, devType);
1943 if(*epc == 0){
1944 *pdc = 0;
1945 return false;
1946 }
1947 *pdc = 1;
1948
1949 return true;
1950}
1951
1952static echonetlite_device_t *wamp_dealer_get_device(wamp_dealer_t *dealer, int deviceId)
1953{
1954 echonetlite_device_t *pos, *end = &dealer->devices[sizeof(dealer->devices) / sizeof(dealer->devices[0])];
1955
1956 if(deviceId <= 0)
1957 return NULL;
1958
1959 for(pos = dealer->devices; pos < end; pos++){
1960 if(pos->deviceId != deviceId)
1961 continue;
1962
1963 return pos;
1964 }
1965
1966 return NULL;
1967}
1968
1969int wamp_stob(const char *str, uint8_t *dst, int dstc)
1970{
1971 uint8_t *start = dst, *end = &dst[dstc];
1972 int size = 0, i;
1973 char c;
1974 uint8_t data;
1975
1976 for(i = 0; dst < end; dst++){
1977 c = str[i];
1978 if(c == '\0')
1979 break;
1980
1981 data = 0;
1982
1983 if(c >= '0' && c <= '9'){
1984 data |= (c - '0');
1985 }
1986 else if(c >= 'A' && c <= 'F'){
1987 data |= (0xA + c - 'A');
1988 }
1989 else if(c >= 'a' && c <= 'f'){
1990 data |= (0xA + c - 'a');
1991 }
1992 else
1993 break;
1994
1995 i++;
1996 c = str[i];
1997 data <<= 4;
1998
1999 if(c >= '0' && c <= '9'){
2000 data |= (c - '0');
2001 }
2002 else if(c >= 'A' && c <= 'F'){
2003 data |= (0xA + c - 'A');
2004 }
2005 else if(c >= 'a' && c <= 'f'){
2006 data |= (0xA + c - 'a');
2007 }
2008 else
2009 break;
2010
2011 i++;
2012 *dst = data;
2013 }
2014
2015 return dst - start;
2016}
2017
2018void wamp_dealer_init(wamp_dealer_t *dealer)
2019{
2020}
Note: See TracBrowser for help on using the repository browser.