source: uKadecot/trunk/kadecot/wamp_dealer.c@ 264

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

KadecotAPIの文字列確認の方法を変更

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