source: uKadecot/trunk/src/ukadecot/main.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: 30.0 KB
Line 
1/*
2 * TOPPERS ECHONET Lite Communication Middleware
3 *
4 * Copyright (C) 2014 Cores Co., Ltd. Japan
5 *
6 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
7 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
8 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
9 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
10 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
11 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
12 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
13 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
14ƒƒ“ƒgi—˜—p
15 * ŽÒƒ}ƒjƒ…
16ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
17 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
18 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
19 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
20 * ‚ƁD
21 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
22ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
23ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
24 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
25 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
26 * •ñ‚·‚邱‚ƁD
27 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
28 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
29 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
30 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
31 * –Ɛӂ·‚邱‚ƁD
32 *
33 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
34 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
35 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
36 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
37 * ‚̐ӔC‚𕉂í‚È‚¢D
38 *
39 * @(#) $Id: main.c 101 2015-06-02 15:37:23Z coas-nagasima $
40 */
41
42/*
43 * ƒTƒ“ƒvƒ‹ƒvƒƒOƒ‰ƒ€(1)‚Ì–{‘Ì
44 */
45
46#include <kernel.h>
47#include <t_syslog.h>
48#include <sil.h>
49#include "syssvc/serial.h"
50#include "syssvc/syslog.h"
51#include "kernel_cfg.h"
52#include "main.h"
53#include "echonet_cfg.h"
54#ifdef __RX
55#include "rx630_ccrx/rx630.h"
56#else
57#include "rx630_msvc/rx630.h"
58#endif
59#include <uip.h>
60#include <pt.h>
61#include "uip_adpt.h"
62#include "wamp.h"
63// TODO:ƒRƒ“ƒgƒ[ƒ‰Œü‚¯ƒwƒbƒ_[ƒtƒ@ƒCƒ‹‚ðì¬‚·‚é
64#include "echonet_task.h"
65#include "echonet_agent.h"
66#include "echonet_lcl_task.h"
67#include "arduino.h"
68#include "data_flash.h"
69
70uint8_t mac_addr[6] = { 0x00, 0x30, 0x13, 0x06, 0x62, 0xC0 };
71
72#define MAKER_CODE 0x00, 0x00, 0xB3 /* TOPPERSƒvƒƒWƒFƒNƒg */
73
74/* ƒm[ƒhƒvƒƒtƒ@ƒCƒ‹ƒIƒuƒWƒFƒNƒg */
75struct node_profile_object_t local_node_data = {
76 0x30, /* “®ìó‘Ô */
77 { 0x01, 0x0A, 0x01, 0x00 }, /* ‚u‚…
78‚’‚“‚‰‚‚Žî•ñ */
79 {
80 0xFE, /* ‰ºˆÊ’ʐM‘wIDƒtƒB[ƒ‹ƒh */
81 { MAKER_CODE }, /* ƒ[ƒJ[ƒR[ƒh */
82 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }, /* ƒ†ƒj[ƒNID•”(ƒ[ƒJ[“ÆŽ©) */
83 },
84 0x0000, /* ˆÙí“à—e */
85 { MAKER_CODE }, /* ƒ[ƒJ[ƒR[ƒh */
86};
87
88/* ƒRƒ“ƒgƒ[ƒ‰[ƒNƒ‰ƒX */
89struct controller_t controller_class_data = {
90 0x30, /* “®ìó‘Ô */
91 0x00, /* Ý’uêŠ */
92 { 0x00, 0x00, 'C', 0x00 }, /* ‹KŠi‚u‚…
93‚’‚“‚‰‚‚Žî•ñ */
94 0x41, /* ˆÙí”­¶ó‘Ô */
95 { MAKER_CODE }, /* ƒ[ƒJ[ƒR[ƒh */
96};
97
98/*
99 * “®ìó‘ÔON/OFFÝ’èŠÖ”i0x30, 0x31‚̂ݎ󂯕t‚¯j
100 */
101int onoff_prop_set(const EPRPINIB *item, const void *src, int size, bool_t *anno)
102{
103 /* ƒTƒCƒY‚ª‚PˆÈŠO‚͎󂯕t‚¯‚È‚¢ */
104 if(size != 1)
105 return 0;
106
107 *anno = *((uint8_t*)item->exinf) != *((uint8_t*)src);
108
109 switch(*(uint8_t *)src){
110 /* ON‚̏ꍇ */
111 case 0x30:
112 *((uint8_t *)item->exinf) = *((uint8_t *)src);
113 /* LED‚Ì"."‚ðON */
114 sil_wrb_mem((uint8_t *)0x0008C02A, sil_reb_mem((uint8_t *)0x0008C02A) | 0x40);
115 break;
116 /* OFF‚̏ꍇ */
117 case 0x31:
118 *((uint8_t *)item->exinf) = *((uint8_t *)src);
119 /* LED‚Ì"."‚ðOFF */
120 sil_wrb_mem((uint8_t *)0x0008C02A, sil_reb_mem((uint8_t *)0x0008C02A) & ~0x40);
121 break;
122 /* 0x30‚©0x31ˆÈŠO‚͎󂯕t‚¯‚È‚¢ */
123 default:
124 return 0;
125 }
126
127 return 1;
128}
129
130/*
131 * ˆÙí“à—eÝ’èŠÖ”
132 */
133int node_profile_object_fault_content_set(const EPRPINIB *item, const void *src, int size, bool_t *anno)
134{
135 /* ƒTƒCƒY‚ª2ˆÈŠO‚͎󂯕t‚¯‚È‚¢ */
136 if(size != 2)
137 return 0;
138
139 if((*(uint16_t *)src >= 0x0) && (*(uint16_t *)src <= 0x3ec)){
140 *((uint16_t *)item->exinf) = *((uint16_t *)src);
141 /* TODO: ‚±‚̂̏ꍇ‚̏ˆ—*/
142 }
143 /* ã‹LˆÈŠO‚͎󂯕t‚¯‚È‚¢ */
144 else{
145 return 0;
146 }
147
148 return 2;
149}
150
151/*
152 * ˆÙí”­¶ó‘ԐݒèŠÖ”i0x41, 0x42‚̂ݎ󂯕t‚¯j
153 */
154int alarm_prop_set(const EPRPINIB *item, const void *src, int size, bool_t *anno)
155{
156 /* ƒTƒCƒY‚ª‚PˆÈŠO‚͎󂯕t‚¯‚È‚¢ */
157 if(size != 1)
158 return 0;
159
160 *anno = *((uint8_t *)item->exinf) != *((uint8_t *)src);
161
162 switch(*(uint8_t *)src){
163 /* ˆÙí”­¶‚ ‚è‚̏ꍇ */
164 case 0x41:
165 /* ˆÙí”­¶‚È‚µ‚̏ꍇ */
166 case 0x42:
167 *((uint8_t *)item->exinf) = *((uint8_t *)src);
168 break;
169 /* 0x41‚©0x42ˆÈŠO‚͎󂯕t‚¯‚È‚¢ */
170 default:
171 return 0;
172 }
173
174 return 1;
175}
176
177/*
178 * Œ»ÝŽžÝ’èŠÖ”
179 */
180int time_prop_set(const EPRPINIB *item, const void *src, int size, bool_t *anno)
181{
182 uint8_t *p_src;
183
184 if(size != 2)
185 return 0;
186
187 /* ŽžÝ’è */
188 p_src = (uint8_t *)src;
189 sil_wrb_mem((uint8_t *)RTC_RHRCNT_ADDR, *p_src++);
190 sil_wrb_mem((uint8_t *)RTC_RMINCNT_ADDR, *p_src++);
191 sil_wrb_mem((uint8_t *)RTC_RSECCNT_ADDR, 0x00);
192
193 return (intptr_t)p_src - (intptr_t)src;
194}
195
196/*
197 * Œ»ÝŽžŽæ“¾ŠÖ”
198 */
199int time_prop_get(const EPRPINIB *item, void *dst, int size)
200{
201 uint8_t *p_dst;
202
203 if(size != 2)
204 return 0;
205
206 /* ŽžÝ’è */
207 p_dst = (uint8_t *)dst;
208 *p_dst++ = sil_reb_mem((uint8_t *)RTC_RHRCNT_ADDR);
209 *p_dst++ = sil_reb_mem((uint8_t *)RTC_RMINCNT_ADDR);
210
211 return (intptr_t)p_dst - (intptr_t)dst;
212}
213
214/*
215 * Œ»Ý”NŒŽ“úÝ’èŠÖ”
216 */
217int date_prop_set(const EPRPINIB *item, const void *src, int size, bool_t *anno)
218{
219 uint8_t *p_src;
220
221 if(size != 4)
222 return 0;
223
224 /* ”NŒŽ“úÝ’è */
225 p_src = (uint8_t *)src;
226 p_src++; /* 20XX */
227 sil_wrb_mem((uint8_t *)RTC_RYRCNT_ADDR, *p_src++);
228 sil_wrb_mem((uint8_t *)RTC_RMONCNT_ADDR, *p_src++);
229 sil_wrb_mem((uint8_t *)RTC_RDAYCNT_ADDR, *p_src++);
230
231 return (intptr_t)p_src - (intptr_t)src;
232}
233
234/*
235 * Œ»Ý”NŒŽ“úŽæ“¾ŠÖ”
236 */
237int date_prop_get(const EPRPINIB *item, void *dst, int size)
238{
239 uint8_t *p_dst;
240
241 if(size != 4)
242 return 0;
243
244 p_dst = (uint8_t *)dst;
245 *p_dst++ = 0x20;
246 *p_dst++ = sil_reb_mem((uint8_t *)RTC_RYRCNT_ADDR);
247 *p_dst++ = sil_reb_mem((uint8_t *)RTC_RMONCNT_ADDR);
248 *p_dst++ = sil_reb_mem((uint8_t *)RTC_RDAYCNT_ADDR);
249
250 return (intptr_t)p_dst - (intptr_t)dst;
251}
252
253/*
254 * uIP ƒ^ƒXƒN‰Šú‰»ˆ—
255 */
256void uip_task_init(intptr_t exinf)
257{
258 httpd_init();
259}
260
261static void main_initialize();
262static TMO main_get_timer();
263static void main_progress(TMO interval);
264static void main_recv_esv(T_EDATA *esv);
265static bool_t main_wbs_msg(ECN_FBS_ID msg);
266static bool_t main_wbs_que_msg();
267static void main_int_msg(ECN_FBS_ID msg);
268static void main_break_wait(uint8_t *brkdat, int32_t len);
269static void main_timeout();
270static void main_start_service();
271static void main_get_device_list_res(ECN_FBS_ID msg);
272static void main_get_ipaddr_res(ECN_FBS_ID msg);
273static void main_get_device_info_res(ECN_FBS_ID msg);
274static void main_kadecot_set_res(T_EDATA *esv);
275static void main_kadecot_get_res(T_EDATA *esv);
276static void main_ecnl_set_res(T_EDATA *esv);
277static void main_ecnl_get_res(T_EDATA *esv);
278static void main_ecnl_setget_res(T_EDATA *esv);
279static void main_publish(T_EDATA *esv);
280
281struct pt main_pt;
282struct uip_timer main_pt_timer;
283T_ECN_FBS_QUEUE wbs_queue;
284
285/*
286 * ƒƒCƒ“ƒ^ƒXƒN
287 */
288static
289PT_THREAD(main_task_pt(void))
290{
291 ER ret, ret2;
292 static SYSTIM prev, now;
293 TMO timer;
294 T_EDATA *esv;
295 uint8_t brkdat[64];
296 int32_t len;
297
298 PT_BEGIN(&main_pt);
299
300 /* ‰Šú‰» */
301 main_initialize();
302
303 ret2 = get_tim(&now);
304 if (ret2 != E_OK){
305 syslog(LOG_ERROR, "get_tim");
306 PT_EXIT(&main_pt);
307 }
308
309 for(;;){
310 prev = now;
311
312 /* ƒ^ƒCƒ}[Žæ“¾ */
313 timer = main_get_timer();
314 timer_set(&main_pt_timer, timer);
315
316 /* ‰ž“š“d•¶‘Ò‚¿ */
317 PT_WAIT_UNTIL(&main_pt, (((ret = ecn_prcv_esv(&esv)) == E_OK) || (ret == E_BRK)
318 || ((ret = timer_expired(&main_pt_timer) ? E_TMOUT : E_WBLK) == E_TMOUT)));
319 if ((ret != E_OK) && (ret != E_BRK) && (ret != E_TMOUT)){
320 syslog(LOG_ERROR, "ecn_trcv_esv");
321 PT_EXIT(&main_pt);
322 }
323
324 ret2 = get_tim(&now);
325 if (ret2 != E_OK){
326 syslog(LOG_ERROR, "get_tim");
327 PT_EXIT(&main_pt);
328 }
329
330 /* ŽžŠÔŒo‰ß */
331 main_progress(now - prev);
332
333 /* Echonet“d•¶ŽóM‚̏ꍇ */
334 if (ret == E_OK) {
335 /* Echonet“d•¶ŽóMˆ— */
336 main_recv_esv(esv);
337
338 /* —̈æ‰ð•ú */
339 ret = ecn_rel_esv(esv);
340 if (ret != E_OK){
341 syslog(LOG_ERROR, "ecn_rel_esv");
342 PT_EXIT(&main_pt);
343 }
344 }
345 /* ‰ž“š“d•¶‘Ò‚¿‚ÌŠ„‚荞‚݂̏ꍇ */
346 else if (ret == E_BRK) {
347 ECN_FBS_ID msg = { (T_ECN_FST_BLK *)esv };
348 bool_t rel_msg = true;
349 switch (msg.ptr->hdr.type) {
350 case 0:
351 rel_msg = main_wbs_msg(msg);
352 break;
353 case 1/*ECN_MSG_INTERNAL*/:
354 main_int_msg(msg);
355 break;
356 case 3/*ECN_MSG_USER_BREAK*/:
357 /* ‰ž“š“d•¶‘Ò‚¿‚ÌŠ„‚荞‚݃f[ƒ^Žæ“¾ */
358 ret = ecn_get_brk_dat(esv, brkdat, sizeof(brkdat), &len);
359 if (ret != E_OK){
360 syslog(LOG_ERROR, "ecn_get_brk_dat");
361 PT_EXIT(&main_pt);
362 }
363
364 /* ‰ž“š“d•¶‘Ò‚¿‚ÌŠ„‚荞‚ݏˆ— */
365 main_break_wait(brkdat, len);
366 break;
367 }
368
369 /* —̈æ‰ð•ú */
370 if (rel_msg) {
371 ret = ecn_rel_esv(esv);
372 if (ret != E_OK){
373 syslog(LOG_ERROR, "ecn_rel_esv");
374 PT_EXIT(&main_pt);
375 }
376 }
377 }
378
379 /* ƒ^ƒCƒ€ƒAƒEƒgˆ— */
380 main_timeout();
381
382 /* ƒLƒ…
383[‚É—­‚Ü‚Á‚½ƒƒbƒZ[ƒW‚ðˆ— */
384 while(main_wbs_que_msg());
385 }
386
387 PT_END(&main_pt);
388}
389
390void main_task(intptr_t exinf)
391{
392 main_task_pt();
393}
394
395void main_task_cychdr(intptr_t exinf)
396{
397 (void)iact_tsk((ID)exinf);
398}
399
400enum main_state_t {
401 main_state_start,
402 main_state_idle,
403};
404
405TMO main_timer = TMO_FEVR;
406enum main_state_t main_state = main_state_start;
407bool_t main_btn1_state;
408int main_btn1_count = 0;
409bool_t main_btn2_state;
410int main_btn2_count = 0;
411
412enum request_info_state_t {
413 request_info_state_idle,
414 request_info_state_search_device,
415 request_info_state_get_device_list,
416 request_info_state_get_ipaddr,
417 request_info_state_get_device_info,
418 request_info_state_kadecot_set,
419 request_info_state_kadecot_get,
420 request_info_state_ecnl_set,
421 request_info_state_ecnl_get,
422 request_info_state_ecnl_setget,
423};
424
425typedef struct request_info {
426 enum request_info_state_t state;
427 TMO timer;
428 unsigned int requestId;
429 struct wamp_dealer *dealer;
430 ID eobjid;
431 uint8_t epc;
432} request_info_t;
433
434request_info_t request_infos[1];
435wamp_state_t wamp;
436
437/*
438 * ‰Šú‰»
439 */
440static void main_initialize()
441{
442 uint8_t btn1, btn2;
443 uint8_t data[32], c;
444 int i, j;
445 bool_t dflt_addr = true;
446 ER ret;
447
448 /* LED‚ð"000"‚Æ•\Ž¦ */
449 sil_wrb_mem((uint8_t *)0x0008C02A, 0x00);
450
451 ret = data_flash_init();
452
453 while(ret == E_OK){
454 ret = data_flash_read(0, data);
455 if(ret != E_OK){
456 break;
457 }
458
459 dflt_addr = false;
460 memcpy(mac_addr, data, sizeof(mac_addr));
461 break;
462 }
463
464 for(i = 0, j = 0; i < sizeof(mac_addr); i++){
465 c = mac_addr[i] >> 4;
466 data[j++] = (c < 10) ? ('0' + c) : ('A' - 10 + c);
467 c = mac_addr[i] & 0xF;
468 data[j++] = (c < 10) ? ('0' + c) : ('A' - 10 + c);
469 data[j++] = ':';
470 }
471 data[--j] = '\0';
472
473 syslog(LOG_INFO, "mac_addr %s %s", data, dflt_addr ? "default" : "flash-rom");
474
475 /* uIP‚ðŠJŽn */
476 uip_start();
477
478 wamp_init(&wamp);
479
480 /* 10msŒã‚Ƀ{ƒ^ƒ“ó‘Ô‚ðŠm”F */
481 main_state = main_state_start;
482 main_timer = TMO_FEVR;
483
484 /* ArduinoŒÝŠ·‹@”\‰Šú‰» */
485 arduino_init();
486
487 /* ƒ{ƒ^ƒ“ó‘ԓǂݍž‚Ý */
488 btn1 = sil_reb_mem((uint8_t *)0x0008C04A);
489 /*btn1 = sil_reb_mem((uint8_t *)0x0008C040);*/
490 btn2 = sil_reb_mem((uint8_t *) 0x0008C040);
491 main_btn1_state = (btn1 & 0x80/*0x0x20*/) != 0;
492 main_btn2_state = (btn2 & 0x80) != 0;
493
494 for (i = 0; i< sizeof(request_infos) / sizeof(request_infos[0]); i++) {
495 request_infos[i].timer = TMO_FEVR;
496 }
497}
498
499/*
500 * ƒ^ƒCƒ}[Žæ“¾
501 */
502static TMO main_get_timer()
503{
504 int i;
505 TMO timer = main_timer, temp;
506
507 for (i = 0; i< sizeof(request_infos) / sizeof(request_infos[0]); i++) {
508 temp = request_infos[i].timer;
509 if (temp != TMO_FEVR) {
510 if ((timer == TMO_FEVR) || (temp < timer)) {
511 timer = temp;
512 }
513 }
514 }
515
516 return timer;
517}
518
519/*
520 * ŽžŠÔŒo‰ß
521 */
522static void main_progress(TMO interval)
523{
524 int i;
525 TMO temp;
526
527 if (main_timer != TMO_FEVR) {
528 main_timer -= interval;
529 if(main_timer < 0){
530 main_timer = 0;
531 }
532 }
533
534 for (i = 0; i< sizeof(request_infos) / sizeof(request_infos[0]); i++) {
535 temp = request_infos[i].timer;
536 if (temp != TMO_FEVR) {
537 temp -= interval;
538 if(temp < 0){
539 temp = 0;
540 }
541 request_infos[i].timer = temp;
542 }
543 }
544}
545
546static void main_self_msg(T_EDATA *esv);
547
548/*
549 * Echonet“d•¶ŽóMˆ—
550 */
551static void main_recv_esv(T_EDATA *esv)
552{
553 request_info_t *request_info = &request_infos[0];
554
555 switch(esv->hdr.edata.esv){
556 case ESV_SET_RES:
557 case ESV_SET_C_SNA:
558 if (request_info->eobjid != ecn_get_eobj(esv)) {
559 main_self_msg(esv);
560 break;
561 }
562
563 switch(request_info->state){
564 case request_info_state_kadecot_set:
565 main_kadecot_set_res(esv);
566 break;
567 case request_info_state_ecnl_set:
568 main_ecnl_set_res(esv);
569 break;
570 }
571 break;
572 case ESV_GET_RES:
573 case ESV_GET_SNA:
574 if (request_info->eobjid != ecn_get_eobj(esv)) {
575 main_self_msg(esv);
576 break;
577 }
578
579 switch(request_info->state){
580 case request_info_state_kadecot_get:
581 main_kadecot_get_res(esv);
582 break;
583 case request_info_state_ecnl_get:
584 main_ecnl_get_res(esv);
585 break;
586 }
587 break;
588 case ESV_SET_GET_RES:
589 case ESV_SET_GET_SNA:
590 if (request_info->eobjid != ecn_get_eobj(esv)) {
591 main_self_msg(esv);
592 break;
593 }
594
595 switch(request_info->state){
596 case request_info_state_ecnl_setget:
597 main_ecnl_setget_res(esv);
598 break;
599 }
600 break;
601 case ESV_INF:
602 main_self_msg(esv);
603 main_publish(esv);
604 break;
605 default:
606 main_self_msg(esv);
607 break;
608 }
609}
610
611/*
612 * WebSocketƒƒbƒZ[ƒWŽóMˆ—
613 */
614static bool_t main_wbs_msg(ECN_FBS_ID msg)
615{
616 request_info_t *request_info = &request_infos[0];
617
618 if (request_info->state != request_info_state_idle) {
619 ecn_fbs_enqueue(&wbs_queue, msg.ptr);
620 return false;
621 }
622
623 wamp_put_msg(&wamp, msg, ((ID *)msg.ptr->_gap)[0]);
624 return true;
625}
626
627static bool_t main_wbs_que_msg()
628{
629 request_info_t *request_info = &request_infos[0];
630 ECN_FBS_ID msg;
631 ER ret;
632
633 if (request_info->state != request_info_state_idle)
634 return false;
635
636 ret = ecn_fbs_dequeue(&wbs_queue, &msg.ptr);
637 if (ret == E_TMOUT)
638 return false;
639
640 wamp_put_msg(&wamp, msg, ((ID *)msg.ptr->_gap)[0]);
641
642 _ecn_fbs_del(msg);
643
644 return true;
645}
646
647/*
648 * Š„‚荞‚݃ƒbƒZ[ƒWŽóMˆ—
649 */
650static void main_int_msg(ECN_FBS_ID msg)
651{
652 ER ret;
653 uint8_t cmd;
654 ECN_FBS_SSIZE_T len;
655
656 ret = _ecn_fbs_get_data(msg, &cmd, 1, &len);
657 if (ret != E_OK) {
658 return;
659 }
660
661 switch(cmd){
662 case ECN_INM_GET_DEVICE_LIST_RES:
663 main_get_device_list_res(msg);
664 break;
665 case ECN_INM_GET_DEVICE_INFO_RES:
666 main_get_device_info_res(msg);
667 break;
668 case ECN_UDP_MSG_GET_IPADDR_RES:
669 main_get_ipaddr_res(msg);
670 break;
671 }
672}
673
674/*
675 * ‰ž“š“d•¶‘Ò‚¿‚ÌŠ„‚荞‚ݏˆ—
676 */
677static void main_break_wait(uint8_t *brkdat, int32_t len)
678{
679 switch(main_state){
680 case main_state_start:
681 main_start_service();
682 main_state = main_state_idle;
683 main_timer = 10;
684 break;
685 case main_state_idle:
686 break;
687 }
688}
689
690/*
691 * ‰ž“š“d•¶‘Ò‚¿‚ÌŠ„‚荞‚ݏˆ—
692 */
693void main_set_addr_callback()
694{
695 ER ret;
696 uint8_t data[1];
697
698 /* ƒƒCƒ“ƒ^ƒXƒN‚É’Ê’m */
699 data[0] = 0x01;
700 ret = ecn_brk_wai(data, sizeof(data));
701 if(ret != E_OK){
702 syslog(LOG_ERROR, "ecn_brk_wai");
703 }
704}
705
706/*
707 * ‰ž“š“d•¶‘Ò‚¿‚ÌŠ„‚荞‚ݏˆ—
708 */
709static void main_start_service()
710{
711 char ip_addr[16], netmask[16], gateway[16];
712 ER ret;
713
714 ip2str(ip_addr, uip_hostaddr);
715 ip2str(netmask, uip_netmask);
716 ip2str(gateway, uip_draddr);
717 syslog(LOG_INFO, "ip_addr %s, netmask %s, gateway %s", ip_addr, netmask, gateway);
718
719 /* ECHONETƒ~ƒhƒ‹ƒEƒFƒA‚ð‹N“® */
720 ret = ecn_sta_svc();
721 if(ret != E_OK)
722 return;
723}
724
725static void main_btn_timeout();
726static void main_request_info_timeout(request_info_t *request_info);
727
728/*
729 * ƒ^ƒCƒ€ƒAƒEƒgˆ—
730 */
731static void main_timeout()
732{
733 int i;
734 TMO temp;
735
736 if (main_timer == 0) {
737 main_btn_timeout();
738 }
739
740 for (i = 0; i< sizeof(request_infos) / sizeof(request_infos[0]); i++) {
741 temp = request_infos[i].timer;
742 if (temp != 0)
743 continue;
744
745 main_request_info_timeout(&request_infos[i]);;
746 }
747}
748
749static void main_btn1_change(bool_t push);
750static void main_btn2_change(bool_t push);
751static ER main_search_device();
752
753static void main_btn_timeout()
754{
755 uint8_t btn1, btn2;
756
757 if(main_timer != 0)
758 return;
759
760 switch(main_state){
761 case main_state_idle:
762 /* 10msŒã‚Ƀ{ƒ^ƒ“ó‘Ô‚ðŠm”F */
763 main_timer = 10;
764
765 arduino_tick();
766
767 /* ƒ{ƒ^ƒ“ó‘ԓǂݍž‚Ý */
768 btn1 = sil_reb_mem((uint8_t *)0x0008C04A);
769 /*btn1 = sil_reb_mem((uint8_t *)0x0008C040);*/
770 btn2 = sil_reb_mem((uint8_t *) 0x0008C040);
771
772 /* ƒ{ƒ^ƒ“‚P‚̏ˆ— */
773 if(((btn1 & 0x80/*0x20*/) != 0) && !main_btn1_state){
774 main_btn1_count++;
775 if(main_btn1_count > 10){
776 main_btn1_count = 0;
777 main_btn1_state = true;
778
779 main_btn1_change(true);
780 }
781 }
782 else if(((btn1 & 0x80/*0x20*/) == 0) && main_btn1_state){
783 main_btn1_count++;
784 if(main_btn1_count > 10){
785 main_btn1_count = 0;
786 main_btn1_state = false;
787
788 main_btn1_change(false);
789 }
790 }
791 else{
792 main_btn1_count = 0;
793 }
794
795 /* ƒ{ƒ^ƒ“‚Q‚̏ˆ— */
796 if(((btn2 & 0x80) != 0) && !main_btn2_state){
797 main_btn2_count++;
798 if(main_btn2_count > 10){
799 main_btn2_count = 0;
800 main_btn2_state = true;
801
802 main_btn2_change(true);
803 }
804 }
805 else if(((btn2 & 0x80) == 0) && main_btn2_state){
806 main_btn2_count++;
807 if(main_btn2_count > 10){
808 main_btn2_count = 0;
809 main_btn2_state = false;
810
811 main_btn2_change(false);
812 }
813 }
814 else{
815 main_btn2_count = 0;
816 }
817 break;
818 }
819}
820
821static void main_self_msg(T_EDATA *esv)
822{
823 ER ret;
824 uint8_t epc;
825 uint8_t pdc;
826 uint8_t p_edt[256];
827 T_ENUM_EPC enm;
828
829 ret = ecn_itr_ini(&enm, esv);
830 if(ret != E_OK){
831 syslog(LOG_ERROR, "ecn_itr_ini");
832 return;
833 }
834
835 for(;;) {
836 while((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
837 switch (epc) {
838 case 0x80:
839 break;
840 case 0x81:
841 break;
842 }
843 }
844 if(ret != E_BOVR){
845 syslog(LOG_ERROR, "ecn_itr_nxt");
846 break;
847 }
848 if(enm.is_eof)
849 break;
850 }
851}
852
853/*
854 * ƒ{ƒ^ƒ“‚Pó‘ԕω»ˆ—
855 */
856static void main_btn1_change(bool_t push)
857{
858 /* ‰Ÿ‚³‚ê‚Ä–ß‚Á‚½Žž‚ɏˆ—‚·‚é */
859 if(push)
860 return;
861
862 /* ‹@Ší‚ÌŒŸõ */
863 main_search_device();
864}
865
866/*
867 * ƒ{ƒ^ƒ“‚Qó‘ԕω»ˆ—
868 */
869static void main_btn2_change(bool_t push)
870{
871}
872
873/*
874 * ‹@Ší‚ÌŒŸõ
875 */
876static ER main_search_device()
877{
878 ER ret;
879 T_EDATA *esv;
880
881 /* ‹@Ší‚ÌŒŸõ */
882 ret = ecn_esv_inf_req(&esv, EOBJ_NULL, 0xD6);
883 if(ret != E_OK){
884 syslog(LOG_ERROR, "ecn_esv_inf_req");
885 return ret;
886 }
887
888 /* “d•¶‘—M */
889 ret = ecn_snd_esv(esv);
890 if(ret != E_OK){
891 syslog(LOG_ERROR, "ecn_snd_esv");
892 return ret;
893 }
894
895 return E_OK;
896}
897
898extern int ws_out_req;
899
900ER main_send_message(ECN_FBS_ID msg, ID wbsid)
901{
902 ER ret;
903
904 ((ID *)msg.ptr->_gap)[0] = wbsid;
905
906 ret = psnd_dtq(WEBSOCKET_MBXID, (intptr_t)msg.ptr);
907 if(ret != E_OK){
908 syslog(LOG_ERROR, "psnd_dtq(WEBSOCKET_MBXID) : result=%d", ret);
909 _ecn_fbs_del(msg);
910 return ret;
911 }
912
913 ws_out_req++;
914 act_tsk(UIP_TASK);
915
916 return ret;
917}
918
919ER main_get_device_list(unsigned int requestId, struct wamp_dealer *dealer)
920{
921 request_info_t *request_info = &request_infos[0];
922 ER ret;
923
924 if(request_info->requestId != 0)
925 return E_QOVR;
926
927 /* ‹@Ší‚ÌŒŸõ */
928 ret = main_search_device();
929 if(ret != E_OK){
930 return ret;
931 }
932
933 request_info->state = request_info_state_search_device;
934 request_info->timer = (TMO)5000;
935 request_info->requestId = requestId;
936 request_info->dealer = dealer;
937
938 return E_OK;
939}
940
941static void main_search_device_timeout()
942{
943 request_info_t *request_info = &request_infos[0];
944 ER ret;
945 ECN_FBS_ID req;
946
947 for (;;) {
948 ret = ecn_agent_get_device_list(ECHONET_API_MAILBOX, request_info->requestId, &req);
949 if(ret != E_OK){
950 syslog(LOG_ERROR, "ecn_agent_get_device_list");
951 break;
952 }
953
954 ret = psnd_dtq(req.ptr->hdr.target_mbxid, (intptr_t)req.ptr);
955 if (ret != E_OK) {
956 syslog(LOG_ERROR, "psnd_dtq");
957 _ecn_fbs_del(req);
958 break;
959 }
960
961 request_info->state = request_info_state_get_device_list;
962 request_info->timer = (TMO)1000;
963 return;
964 }
965
966 wamp_dealer_get_devicelist_timeout(request_info->dealer);
967
968 request_info->state = request_info_state_idle;
969 request_info->timer = TMO_FEVR;
970 request_info->requestId = 0;
971 request_info->dealer = NULL;
972}
973
974static void main_get_device_list_res(ECN_FBS_ID msg)
975{
976 request_info_t *request_info = &request_infos[0];
977 ER ret;
978 unsigned int requestId;
979 struct wamp_dealer *dealer;
980 ECN_FBS_SSIZE_T len;
981
982 ret = _ecn_fbs_get_data(msg, &requestId, sizeof(requestId), &len);
983 if (ret != E_OK) {
984 syslog(LOG_ERROR, "_ecn_fbs_get_data");
985 return;
986 }
987
988 if (request_info->requestId != requestId)
989 return;
990
991 dealer = request_info->dealer;
992 request_info->state = request_info_state_idle;
993 request_info->timer = TMO_FEVR;
994 request_info->requestId = 0;
995 request_info->dealer = NULL;
996
997 wamp_dealer_set_devicelist(dealer, msg);
998}
999
1000ER main_get_device_ipaddr(unsigned int requestId, struct wamp_dealer *dealer, ECN_ENOD_ID addrid)
1001{
1002 request_info_t *request_info = &request_infos[0];
1003 ER ret;
1004 ECN_FBS_ID req;
1005
1006 if(request_info->requestId != 0)
1007 return E_QOVR;
1008
1009 ret = ecn_udp_get_ipaddr(ECHONET_API_MAILBOX, requestId, addrid, &req);
1010 if(ret != E_OK){
1011 return ret;
1012 }
1013
1014 ret = psnd_dtq(req.ptr->hdr.target_mbxid, (intptr_t)req.ptr);
1015 if (ret != E_OK) {
1016 syslog(LOG_ERROR, "psnd_dtq");
1017 _ecn_fbs_del(req);
1018 return ret;
1019 }
1020
1021 request_info->state = request_info_state_get_ipaddr;
1022 request_info->timer = (TMO)1000;
1023 request_info->requestId = requestId;
1024 request_info->dealer = dealer;
1025
1026 return E_OK;
1027}
1028
1029static void main_get_ipaddr_res(ECN_FBS_ID msg)
1030{
1031 request_info_t *request_info = &request_infos[0];
1032 ER ret;
1033 struct wamp_dealer *dealer;
1034 ECN_FBS_SSIZE_T len;
1035 ecn_udp_msg_get_ipaddr_res_t ipaddr;
1036 char str[16];
1037
1038 ret = _ecn_fbs_get_data(msg, &ipaddr, sizeof(ipaddr), &len);
1039 if (ret || (len != sizeof(ipaddr))) {
1040 syslog(LOG_ERROR, "_ecn_fbs_get_data");
1041 return;
1042 }
1043
1044 if (request_info->requestId != ipaddr.requestid)
1045 return;
1046
1047 dealer = request_info->dealer;
1048 request_info->state = request_info_state_idle;
1049 request_info->timer = TMO_FEVR;
1050 request_info->requestId = 0;
1051 request_info->dealer = NULL;
1052
1053 ipaddr2str(str, sizeof(str), ipaddr.enodadrb.ipaddr);
1054
1055 wamp_dealer_set_ipaddr(dealer, str);
1056}
1057
1058ER main_get_device_info(unsigned int requestId, struct wamp_dealer *dealer, ID eobjid)
1059{
1060 request_info_t *request_info = &request_infos[0];
1061 ER ret;
1062 ECN_FBS_ID req;
1063
1064 if(request_info->requestId != 0)
1065 return E_QOVR;
1066
1067 ret = ecn_agent_get_device_info(ECHONET_API_MAILBOX, requestId, eobjid, &req);
1068 if(ret != E_OK){
1069 return ret;
1070 }
1071
1072 ret = psnd_dtq(req.ptr->hdr.target_mbxid, (intptr_t)req.ptr);
1073 if (ret != E_OK) {
1074 syslog(LOG_ERROR, "psnd_dtq");
1075 _ecn_fbs_del(req);
1076 return ret;
1077 }
1078
1079 request_info->state = request_info_state_get_device_info;
1080 request_info->timer = (TMO)1000;
1081 request_info->requestId = requestId;
1082 request_info->dealer = dealer;
1083
1084 return E_OK;
1085}
1086
1087static void main_get_device_info_res(ECN_FBS_ID msg)
1088{
1089 request_info_t *request_info = &request_infos[0];
1090 ER ret;
1091 struct wamp_dealer *dealer;
1092 ecn_inm_get_device_info_res_t rmsg;
1093 ECN_FBS_SSIZE_T len;
1094
1095 ret = _ecn_fbs_get_data(msg, &rmsg, sizeof(rmsg), &len);
1096 if (ret != E_OK) {
1097 syslog(LOG_ERROR, "_ecn_fbs_get_data");
1098 return;
1099 }
1100
1101 if (request_info->requestId != rmsg.requestid)
1102 return;
1103
1104 dealer = request_info->dealer;
1105 request_info->state = request_info_state_idle;
1106 request_info->timer = TMO_FEVR;
1107 request_info->requestId = 0;
1108 request_info->dealer = NULL;
1109
1110 wamp_dealer_set_deviceinfo(dealer, rmsg.eobjid, rmsg.pmapSet, rmsg.pmapGet, rmsg.pmapAnno);
1111}
1112
1113ER main_kadecot_get(unsigned int requestId, struct wamp_dealer *dealer, ID eobjid, uint8_t epc)
1114{
1115 request_info_t *request_info = &request_infos[0];
1116 ER ret;
1117 T_EDATA *esv;
1118
1119 if(request_info->requestId != 0)
1120 return E_QOVR;
1121
1122 /* ƒvƒƒpƒeƒBŽæ“¾“d•¶ì¬ */
1123 ret = ecn_esv_get(&esv, eobjid, epc);
1124 if(ret != E_OK){
1125 syslog(LOG_ERROR, "ecn_esv_get");
1126 return ret;
1127 }
1128
1129 /* “d•¶‘—M */
1130 ret = ecn_snd_esv(esv);
1131 if(ret != E_OK){
1132 syslog(LOG_ERROR, "ecn_snd_esv");
1133 return ret;
1134 }
1135
1136 request_info->state = request_info_state_kadecot_get;
1137 request_info->timer = (TMO)5000;
1138 request_info->requestId = requestId;
1139 request_info->dealer = dealer;
1140 request_info->eobjid = eobjid;
1141 request_info->epc = epc;
1142
1143 return E_OK;
1144}
1145
1146static void main_kadecot_get_res(T_EDATA *esv)
1147{
1148 request_info_t *request_info = &request_infos[0];
1149 ER ret;
1150 ID eobjid = ecn_get_eobj(esv);
1151 struct wamp_dealer *dealer = request_info->dealer;
1152 uint8_t epc;
1153 uint8_t pdc;
1154 uint8_t p_edt[256];
1155 T_ENUM_EPC enm;
1156
1157 if(request_info->eobjid != eobjid)
1158 return;
1159
1160 dealer = request_info->dealer;
1161 request_info->state = request_info_state_idle;
1162 request_info->timer = TMO_FEVR;
1163 request_info->requestId = 0;
1164 request_info->dealer = NULL;
1165
1166 ret = ecn_itr_ini(&enm, esv);
1167 if(ret != E_OK){
1168 syslog(LOG_ERROR, "ecn_itr_ini");
1169 return;
1170 }
1171
1172 for(;;) {
1173 while((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
1174 if (request_info->epc == epc) {
1175 wamp_dealer_kadecot_get(dealer, eobjid, epc, pdc, p_edt);
1176 }
1177 }
1178 if(ret != E_BOVR){
1179 syslog(LOG_ERROR, "ecn_itr_nxt");
1180 break;
1181 }
1182 if(enm.is_eof)
1183 break;
1184 }
1185}
1186
1187ER main_kadecot_set(unsigned int requestId, struct wamp_dealer *dealer, ID eobjid, uint8_t epc,
1188 uint8_t pdc, uint8_t *edt)
1189{
1190 request_info_t *request_info = &request_infos[0];
1191 ER ret;
1192 T_EDATA *esv;
1193
1194 if(request_info->requestId != 0)
1195 return E_QOVR;
1196
1197 /* ƒvƒƒpƒeƒBŽæ“¾“d•¶ì¬ */
1198 ret = ecn_esv_setc(&esv, eobjid, epc, pdc, edt);
1199 if(ret != E_OK){
1200 syslog(LOG_ERROR, "ecn_esv_setc");
1201 return ret;
1202 }
1203
1204 /* “d•¶‘—M */
1205 ret = ecn_snd_esv(esv);
1206 if(ret != E_OK){
1207 syslog(LOG_ERROR, "ecn_snd_esv");
1208 return ret;
1209 }
1210
1211 request_info->state = request_info_state_kadecot_set;
1212 request_info->timer = (TMO)5000;
1213 request_info->requestId = requestId;
1214 request_info->dealer = dealer;
1215 request_info->eobjid = eobjid;
1216 request_info->epc = epc;
1217
1218 return E_OK;
1219}
1220
1221static void main_kadecot_set_res(T_EDATA *esv)
1222{
1223 request_info_t *request_info = &request_infos[0];
1224 ER ret;
1225 ID eobjid = ecn_get_eobj(esv);
1226 struct wamp_dealer *dealer = request_info->dealer;
1227 uint8_t epc;
1228 uint8_t pdc;
1229 uint8_t p_edt[256];
1230 T_ENUM_EPC enm;
1231
1232 if (dealer == NULL)
1233 return;
1234
1235 if(request_info->eobjid != eobjid)
1236 return;
1237
1238 request_info->state = request_info_state_idle;
1239 request_info->timer = TMO_FEVR;
1240 request_info->requestId = 0;
1241 request_info->dealer = NULL;
1242
1243 ret = ecn_itr_ini(&enm, esv);
1244 if(ret != E_OK){
1245 syslog(LOG_ERROR, "ecn_itr_ini");
1246 return;
1247 }
1248
1249 for(;;) {
1250 while((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
1251 if (request_info->epc == epc) {
1252 wamp_dealer_kadecot_set(dealer, eobjid, epc);
1253 }
1254 }
1255 if(ret != E_BOVR){
1256 syslog(LOG_ERROR, "ecn_itr_nxt");
1257 break;
1258 }
1259 if(enm.is_eof)
1260 break;
1261 }
1262}
1263
1264ER main_ecnl_get(unsigned int requestId, struct wamp_dealer *dealer, ID eobjid, T_EDATA *esv)
1265{
1266 request_info_t *request_info = &request_infos[0];
1267 ER ret;
1268
1269 if(request_info->requestId != 0)
1270 return E_QOVR;
1271
1272 /* “d•¶‘—M */
1273 ret = ecn_snd_esv(esv);
1274 if(ret != E_OK){
1275 syslog(LOG_ERROR, "ecn_snd_esv");
1276 return ret;
1277 }
1278
1279 request_info->state = request_info_state_ecnl_get;
1280 request_info->timer = (TMO)5000;
1281 request_info->requestId = requestId;
1282 request_info->dealer = dealer;
1283 request_info->eobjid = eobjid;
1284
1285 return E_OK;
1286}
1287
1288static void main_ecnl_get_res(T_EDATA *esv)
1289{
1290 request_info_t *request_info = &request_infos[0];
1291
1292 wamp_dealer_ecnl_get_res(request_info->dealer, esv);
1293
1294 request_info->state = request_info_state_idle;
1295 request_info->timer = TMO_FEVR;
1296 request_info->requestId = 0;
1297 request_info->dealer = NULL;
1298}
1299
1300ER main_ecnl_set(unsigned int requestId, struct wamp_dealer *dealer, ID eobjid, T_EDATA *esv)
1301{
1302 request_info_t *request_info = &request_infos[0];
1303 ER ret;
1304
1305 if(request_info->requestId != 0)
1306 return E_QOVR;
1307
1308 /* “d•¶‘—M */
1309 ret = ecn_snd_esv(esv);
1310 if(ret != E_OK){
1311 syslog(LOG_ERROR, "ecn_snd_esv");
1312 return ret;
1313 }
1314
1315 request_info->state = request_info_state_ecnl_set;
1316 request_info->timer = (TMO)5000;
1317 request_info->requestId = requestId;
1318 request_info->dealer = dealer;
1319 request_info->eobjid = eobjid;
1320
1321 return E_OK;
1322}
1323
1324static void main_ecnl_set_res(T_EDATA *esv)
1325{
1326 request_info_t *request_info = &request_infos[0];
1327
1328 wamp_dealer_ecnl_set_res(request_info->dealer, esv);
1329
1330 request_info->state = request_info_state_idle;
1331 request_info->timer = TMO_FEVR;
1332 request_info->requestId = 0;
1333 request_info->dealer = NULL;
1334}
1335
1336ER main_ecnl_setget(unsigned int requestId, struct wamp_dealer *dealer, ID eobjid, T_EDATA *esv)
1337{
1338 request_info_t *request_info = &request_infos[0];
1339 ER ret;
1340
1341 if(request_info->requestId != 0)
1342 return E_QOVR;
1343
1344 /* “d•¶‘—M */
1345 ret = ecn_snd_esv(esv);
1346 if(ret != E_OK){
1347 syslog(LOG_ERROR, "ecn_snd_esv");
1348 return ret;
1349 }
1350
1351 request_info->state = request_info_state_ecnl_setget;
1352 request_info->timer = (TMO)5000;
1353 request_info->requestId = requestId;
1354 request_info->dealer = dealer;
1355 request_info->eobjid = eobjid;
1356
1357 return E_OK;
1358}
1359
1360static void main_ecnl_setget_res(T_EDATA *esv)
1361{
1362 request_info_t *request_info = &request_infos[0];
1363
1364 wamp_dealer_ecnl_setget_res(request_info->dealer, esv);
1365
1366 request_info->state = request_info_state_idle;
1367 request_info->timer = TMO_FEVR;
1368 request_info->requestId = 0;
1369 request_info->dealer = NULL;
1370}
1371
1372static void main_request_info_timeout(request_info_t *request_info)
1373{
1374 struct wamp_dealer *dealer = request_info->dealer;
1375
1376 switch(request_info->state) {
1377 case request_info_state_search_device:
1378 main_search_device_timeout();
1379 return;
1380 case request_info_state_get_device_list:
1381 wamp_dealer_get_devicelist_timeout(dealer);
1382 break;
1383 case request_info_state_get_ipaddr:
1384 wamp_dealer_get_ipaddr_timeout(dealer);
1385 break;
1386 case request_info_state_get_device_info:
1387 wamp_dealer_get_deviceinfo_timeout(dealer);
1388 break;
1389 case request_info_state_kadecot_set:
1390 wamp_dealer_kadecot_set_timeout(dealer);
1391 break;
1392 case request_info_state_kadecot_get:
1393 wamp_dealer_kadecot_get_timeout(dealer);
1394 break;
1395 case request_info_state_ecnl_set:
1396 wamp_dealer_ecnl_set_timeout(dealer);
1397 break;
1398 case request_info_state_ecnl_get:
1399 wamp_dealer_ecnl_get_timeout(dealer);
1400 break;
1401 case request_info_state_ecnl_setget:
1402 wamp_dealer_ecnl_setget_timeout(dealer);
1403 break;
1404 }
1405
1406 request_info->state = request_info_state_idle;
1407 request_info->timer = TMO_FEVR;
1408 request_info->requestId = 0;
1409 request_info->dealer = NULL;
1410}
1411
1412static void main_publish(T_EDATA *esv)
1413{
1414 ID eobjid = ecn_get_eobj(esv);
1415 uint16_t devType = (esv->hdr.edata.seoj.eojx1 << 8) | esv->hdr.edata.seoj.eojx2;
1416 uint8_t epc;
1417 uint8_t pdc;
1418 uint8_t p_edt[256];
1419 T_ENUM_EPC enm;
1420 ER ret;
1421
1422 ret = ecn_itr_ini(&enm, esv);
1423 if(ret != E_OK){
1424 syslog(LOG_ERROR, "ecn_itr_ini");
1425 return;
1426 }
1427
1428 for(;;) {
1429 while((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
1430 wamp_broker_publish_inf(&wamp.broker, esv->hdr.ecn_hdr.tid, eobjid,
1431 devType, epc, pdc, p_edt);
1432 }
1433 if(ret != E_BOVR){
1434 syslog(LOG_ERROR, "ecn_itr_nxt");
1435 break;
1436 }
1437 if(enm.is_eof)
1438 break;
1439 }
1440}
Note: See TracBrowser for help on using the repository browser.