Index: uKadecot/trunk/src/ukadecot/main.c
===================================================================
--- uKadecot/trunk/src/ukadecot/main.c	(revision 148)
+++ uKadecot/trunk/src/ukadecot/main.c	(revision 152)
@@ -1,7 +1,7 @@
 /*
  *  TOPPERS ECHONET Lite Communication Middleware
- * 
+ *
  *  Copyright (C) 2014 Cores Co., Ltd. Japan
- * 
+ *
  *  上記著作権者は，以下の(1)〜(4)の条件を満たす場合に限り，本ソフトウェ
  *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
@@ -26,5 +26,5 @@
  *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
  *      免責すること．
- * 
+ *
  *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
  *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
@@ -32,9 +32,9 @@
  *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
  *  の責任を負わない．
- * 
+ *
  *  @(#) $Id$
  */
 
-/* 
+/*
  *  サンプルプログラム(1)の本体
  */
@@ -64,5 +64,5 @@
 #include "data_flash.h"
 
-uint8_t mac_addr[6] = { 0x12, 0x34, 0x56, 0x78, 0x9A, 0xB8 };
+uint8_t mac_addr[6] = {0x12, 0x34, 0x56, 0x78, 0x9A, 0xB8};
 bool_t dhcp_enable = true;
 
@@ -97,10 +97,10 @@
 {
 	/* サイズが１以外は受け付けない */
-	if(size != 1)
+	if (size != 1)
 		return 0;
 
 	*anno = *((uint8_t*)item->exinf) != *((uint8_t*)src);
 
-	switch(*(uint8_t *)src){
+	switch (*(uint8_t *)src) {
 	/* ONの場合 */
 	case 0x30:
@@ -129,13 +129,13 @@
 {
 	/* サイズが2以外は受け付けない */
-	if(size != 2)
+	if (size != 2)
 		return 0;
 
-	if((*(uint16_t *)src >= 0x0) && (*(uint16_t *)src <= 0x3ec)){
+	if ((*(uint16_t *)src >= 0x0) && (*(uint16_t *)src <= 0x3ec)) {
 		*((uint16_t *)item->exinf) = *((uint16_t *)src);
 		/* TODO: このの場合の処理*/
 	}
 	/* 上記以外は受け付けない */
-	else{
+	else {
 		return 0;
 	}
@@ -150,10 +150,10 @@
 {
 	/* サイズが１以外は受け付けない */
-	if(size != 1)
+	if (size != 1)
 		return 0;
 
 	*anno = *((uint8_t *)item->exinf) != *((uint8_t *)src);
 
-	switch(*(uint8_t *)src){
+	switch (*(uint8_t *)src) {
 	/* 異常発生ありの場合 */
 	case 0x41:
@@ -177,5 +177,5 @@
 	uint8_t *p_src;
 
-	if(size != 2)
+	if (size != 2)
 		return 0;
 
@@ -196,5 +196,5 @@
 	uint8_t *p_dst;
 
-	if(size != 2)
+	if (size != 2)
 		return 0;
 
@@ -214,5 +214,5 @@
 	uint8_t *p_src;
 
-	if(size != 4)
+	if (size != 4)
 		return 0;
 
@@ -234,5 +234,5 @@
 	uint8_t *p_dst;
 
-	if(size != 4)
+	if (size != 4)
 		return 0;
 
@@ -305,10 +305,10 @@
 
 	ret2 = get_tim(&now);
-	if (ret2 != E_OK){
+	if (ret2 != E_OK) {
 		syslog(LOG_ERROR, "get_tim");
 		PT_EXIT(&main_pt);
 	}
 
-	for(;;){
+	for (;;) {
 		prev = now;
 
@@ -320,5 +320,5 @@
 		PT_WAIT_UNTIL(&main_pt, (((ret = ecn_prcv_esv(&esv)) == E_OK) || (ret == E_BRK)
 			|| ((ret = timer_expired(&main_pt_timer) ? E_TMOUT : E_WBLK) == E_TMOUT)));
-		if ((ret != E_OK) && (ret != E_BRK) && (ret != E_TMOUT)){
+		if ((ret != E_OK) && (ret != E_BRK) && (ret != E_TMOUT)) {
 			syslog(LOG_ERROR, "ecn_trcv_esv");
 			PT_EXIT(&main_pt);
@@ -326,5 +326,5 @@
 
 		ret2 = get_tim(&now);
-		if (ret2 != E_OK){
+		if (ret2 != E_OK) {
 			syslog(LOG_ERROR, "get_tim");
 			PT_EXIT(&main_pt);
@@ -341,5 +341,5 @@
 			/* 領域解放 */
 			ret = ecn_rel_esv(esv);
-			if (ret != E_OK){
+			if (ret != E_OK) {
 				syslog(LOG_ERROR, "ECNL ecn_rel_esv result = %d", ret);
 				PT_EXIT(&main_pt);
@@ -348,8 +348,8 @@
 		/* 応答電文待ちの割り込みの場合 */
 		else if (ret == E_BRK) {
-			ECN_FBS_ID msg = { (T_ECN_FST_BLK *)esv };
+			ECN_FBS_ID msg = {(T_ECN_FST_BLK *)esv};
 			bool_t rel_msg = true;
 			switch (msg.ptr->hdr.type) {
-			case 0: 
+			case 0:
 				rel_msg = main_wbs_msg(msg);
 				break;
@@ -360,5 +360,5 @@
 				/* 応答電文待ちの割り込みデータ取得 */
 				ret = ecn_get_brk_dat(esv, brkdat, sizeof(brkdat), &len);
-				if (ret != E_OK){
+				if (ret != E_OK) {
 					syslog(LOG_ERROR, "ecn_get_brk_dat");
 					PT_EXIT(&main_pt);
@@ -373,5 +373,5 @@
 			if (rel_msg) {
 				ret = ecn_rel_esv(esv);
-				if (ret != E_OK){
+				if (ret != E_OK) {
 					syslog(LOG_ERROR, "BRK ecn_rel_esv msg = %p, type = %d, result = %d", esv, msg.ptr->hdr.type, ret);
 					PT_EXIT(&main_pt);
@@ -384,5 +384,5 @@
 
 		/* キューに溜まったメッセージを処理 */
-		while(main_wbs_que_msg());
+		while (main_wbs_que_msg());
 	}
 
@@ -400,8 +400,29 @@
 }
 
-bool_t main_btn1_state;
-int main_btn1_count = 0;
-bool_t main_btn2_state;
-int main_btn2_count = 0;
+typedef struct gpio_state {
+	bool_t state;
+	int count;
+} gpio_state_t;
+
+gpio_state_t main_gpio[2/*btn1, btn2*/ + 14/*arduino pin*/];
+
+#define MAIN_GPIO_BTN1 0
+#define MAIN_GPIO_BTN2 1
+#define MAIN_GPIO_ARDUINO_PIN0 2
+#define MAIN_GPIO_COUNT (sizeof(main_gpio) / sizeof(main_gpio[0]))
+
+typedef struct analog_state {
+	int subscriptionId;
+	int pinno;
+	bool_t state;
+	int count;
+	uint16_t threshold;
+} analog_state_t;
+
+analog_state_t main_analog[16];
+
+#define MAIN_ANALOG_COUNT (sizeof(main_analog) / sizeof(main_analog[0]))
+
+int main_gpio_pubid;
 
 enum request_info_state_t {
@@ -430,4 +451,6 @@
 wamp_state_t wamp;
 
+#define MAIN_REQUEST_INFOS_COUNT (sizeof(request_infos) / sizeof(request_infos[0]))
+
 /*
  * 初期化
@@ -448,7 +471,7 @@
 
 	ret = data_flash_init();
-	while(ret == E_OK){
+	while (ret == E_OK) {
 		ret = data_flash_read(0, data);
-		if(ret != E_OK){
+		if (ret != E_OK) {
 			break;
 		}
@@ -463,5 +486,5 @@
 	}
 
-	for(i = 0, j = 0; i < sizeof(mac_addr); i++){
+	for (i = 0, j = 0; i < sizeof(mac_addr); i++) {
 		c = mac_addr[i] >> 4;
 		data[j++] = (c < 10) ? ('0' + c) : ('A' - 10 + c);
@@ -489,9 +512,18 @@
 	btn1 = sil_reb_mem((uint8_t *)0x0008C04A);
 	/*btn1 = sil_reb_mem((uint8_t *)0x0008C040);*/
-	btn2 = sil_reb_mem((uint8_t *) 0x0008C040);
-	main_btn1_state = (btn1 & 0x80/*0x0x20*/) != 0;
-	main_btn2_state = (btn2 & 0x80) != 0;
-
-	for (i = 0; i< sizeof(request_infos) / sizeof(request_infos[0]); i++) {
+	btn2 = sil_reb_mem((uint8_t *)0x0008C040);
+	main_gpio[MAIN_GPIO_BTN1].state = (btn1 & 0x80/*0x0x20*/) != 0;
+	main_gpio[MAIN_GPIO_BTN2].state = (btn2 & 0x80) != 0;
+	for (i = MAIN_GPIO_ARDUINO_PIN0; i < MAIN_GPIO_COUNT; i++) {
+		arduino_digital_value_t dval;
+		arduino_digitalRead(i - MAIN_GPIO_ARDUINO_PIN0, &dval);
+		main_gpio[i].state = dval == ARDUINO_DIGITAL_VALUE_HIGH;
+	}
+
+	for (i = 0; i < MAIN_ANALOG_COUNT; i++) {
+		main_analog[i].state = true; /* たぶんプルアップされている */
+	}
+
+	for (i = 0; i < MAIN_REQUEST_INFOS_COUNT; i++) {
 		request_infos[i].timer = TMO_FEVR;
 	}
@@ -506,5 +538,5 @@
 	TMO timer = main_timer, temp;
 
-	for (i = 0; i< sizeof(request_infos) / sizeof(request_infos[0]); i++) {
+	for (i = 0; i < sizeof(request_infos) / sizeof(request_infos[0]); i++) {
 		temp = request_infos[i].timer;
 		if (temp != TMO_FEVR) {
@@ -528,14 +560,14 @@
 	if (main_timer != TMO_FEVR) {
 		main_timer -= interval;
-		if(main_timer < 0){
+		if (main_timer < 0) {
 			main_timer = 0;
 		}
 	}
 
-	for (i = 0; i< sizeof(request_infos) / sizeof(request_infos[0]); i++) {
+	for (i = 0; i < sizeof(request_infos) / sizeof(request_infos[0]); i++) {
 		temp = request_infos[i].timer;
 		if (temp != TMO_FEVR) {
 			temp -= interval;
-			if(temp < 0){
+			if (temp < 0) {
 				temp = 0;
 			}
@@ -554,5 +586,5 @@
 	request_info_t *request_info = &request_infos[0];
 
-	switch(esv->hdr.edata.esv){
+	switch (esv->hdr.edata.esv) {
 	case ESV_SET_RES:
 	case ESV_SET_C_SNA:
@@ -562,5 +594,5 @@
 		}
 
-		switch(request_info->state){
+		switch (request_info->state) {
 		case request_info_state_kadecot_set:
 			main_kadecot_set_res(esv);
@@ -578,5 +610,5 @@
 		}
 
-		switch(request_info->state){
+		switch (request_info->state) {
 		case request_info_state_kadecot_get:
 			main_kadecot_get_res(esv);
@@ -594,5 +626,5 @@
 		}
 
-		switch(request_info->state){
+		switch (request_info->state) {
 		case request_info_state_ecnl_setget:
 			main_ecnl_setget_res(esv);
@@ -621,5 +653,5 @@
 		return false;
 	}
-	
+
 	wamp_put_msg(&wamp, msg, ((ID *)msg.ptr->_gap)[0]);
 	return true;
@@ -660,5 +692,5 @@
 	}
 
-	switch(cmd){
+	switch (cmd) {
 	case ECN_INM_GET_DEVICE_LIST_RES:
 		main_get_device_list_res(msg);
@@ -678,5 +710,5 @@
 static void main_break_wait(uint8_t *brkdat, int32_t len)
 {
-	switch(main_state){
+	switch (main_state) {
 	case main_state_start:
 		main_start_service();
@@ -700,5 +732,5 @@
 	data[0] = 0x01;
 	ret = ecn_brk_wai(data, sizeof(data));
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_brk_wai");
 	}
@@ -720,5 +752,5 @@
 	/* ECHONETミドルウェアを起動 */
 	ret = ecn_sta_svc();
-	if(ret != E_OK)
+	if (ret != E_OK)
 		return;
 }
@@ -739,5 +771,5 @@
 	}
 
-	for (i = 0; i< sizeof(request_infos) / sizeof(request_infos[0]); i++) {
+	for (i = 0; i < sizeof(request_infos) / sizeof(request_infos[0]); i++) {
 		temp = request_infos[i].timer;
 		if (temp != 0)
@@ -750,14 +782,20 @@
 static void main_btn1_change(bool_t push);
 static void main_btn2_change(bool_t push);
+static void main_gpio_change(int pinno, uint16_t high);
 static ER main_search_device();
 
 static void main_btn_timeout()
 {
-	uint8_t btn1, btn2;
-
-	if(main_timer != 0)
-		return;
-
-	switch(main_state){
+	gpio_state_t *gpio;
+	analog_state_t *analog;
+	arduino_digital_value_t dval;
+	int aval;
+	bool_t val;
+	int i;
+
+	if (main_timer != 0)
+		return;
+
+	switch (main_state) {
 	case main_state_idle:
 		/* 10ms後にボタン状態を確認 */
@@ -766,56 +804,149 @@
 		arduino_tick();
 
-		/* ボタン状態読み込み */
-		btn1 = sil_reb_mem((uint8_t *)0x0008C04A);
-		/*btn1 = sil_reb_mem((uint8_t *)0x0008C040);*/
-		btn2 = sil_reb_mem((uint8_t *) 0x0008C040);
-
-		/* ボタン１の処理 */
-		if(((btn1 & 0x80/*0x20*/) != 0) && !main_btn1_state){
-			main_btn1_count++;
-			if(main_btn1_count > 10){
-				main_btn1_count = 0;
-				main_btn1_state = true;
-
-				main_btn1_change(true);
+		for (i = 0; i < MAIN_GPIO_COUNT; i++) {
+			gpio = &main_gpio[i];
+
+			/* GPIO状態読み込み */
+			switch (i) {
+			case MAIN_GPIO_BTN1:
+				val = (sil_reb_mem((uint8_t *)0x0008C04A) & 0x80) != 0;
+				/*val = (sil_reb_mem((uint8_t *)0x0008C040) & 0x20) != 0;*/
+				break;
+			case MAIN_GPIO_BTN2:
+				val = (sil_reb_mem((uint8_t *)0x0008C040) & 0x80) != 0;
+				break;
+			default:
+				arduino_digitalRead(i - MAIN_GPIO_ARDUINO_PIN0, &dval);
+				val = dval == ARDUINO_DIGITAL_VALUE_HIGH;
+				break;
 			}
-		}
-		else if(((btn1 & 0x80/*0x20*/) == 0) && main_btn1_state){
-			main_btn1_count++;
-			if(main_btn1_count > 10){
-				main_btn1_count = 0;
-				main_btn1_state = false;
-
-				main_btn1_change(false);
+
+			if (val && !gpio->state) {
+				gpio->count++;
+				if (gpio->count > 10) {
+					gpio->count = 0;
+					gpio->state = true;
+
+					switch (i) {
+					case MAIN_GPIO_BTN1:
+						main_btn1_change(true);
+						break;
+					case MAIN_GPIO_BTN2:
+						main_btn2_change(true);
+						break;
+					default:
+						main_gpio_change(i - MAIN_GPIO_ARDUINO_PIN0, 1);
+						break;
+					}
+				}
 			}
-		}
-		else{
-			main_btn1_count = 0;
-		}
-
-		/* ボタン２の処理 */
-		if(((btn2 & 0x80) != 0) && !main_btn2_state){
-			main_btn2_count++;
-			if(main_btn2_count > 10){
-				main_btn2_count = 0;
-				main_btn2_state = true;
-
-				main_btn2_change(true);
+			else if (!val && gpio->state) {
+				gpio->count++;
+				if (gpio->count > 10) {
+					gpio->count = 0;
+					gpio->state = false;
+
+					switch (i) {
+					case MAIN_GPIO_BTN1:
+						main_btn1_change(false);
+						break;
+					case MAIN_GPIO_BTN2:
+						main_btn2_change(false);
+						break;
+					default:
+						main_gpio_change(i - MAIN_GPIO_ARDUINO_PIN0, 0);
+						break;
+					}
+				}
 			}
-		}
-		else if(((btn2 & 0x80) == 0) && main_btn2_state){
-			main_btn2_count++;
-			if(main_btn2_count > 10){
-				main_btn2_count = 0;
-				main_btn2_state = false;
-
-				main_btn2_change(false);
+			else {
+				gpio->count = 0;
 			}
 		}
-		else{
-			main_btn2_count = 0;
-		}
-		break;
-	}
+
+		for (i = 0; i < MAIN_ANALOG_COUNT; i++) {
+			analog = &main_analog[i];
+
+			if (analog->subscriptionId == 0)
+				continue;
+
+			/* GPIO状態読み込み */
+			arduino_analogRead(analog->pinno, &aval);
+
+			if (analog->state)
+				val = aval < analog->threshold;
+			else
+				val = aval > analog->threshold;
+
+			if (val && !analog->state) {
+				analog->count++;
+				if (analog->count > 10) {
+					analog->count = 0;
+					analog->state = true;
+
+					main_gpio_change(analog->pinno, aval);
+				}
+			}
+			else if (val && analog->state) {
+				analog->count++;
+				if (analog->count > 10) {
+					analog->count = 0;
+					analog->state = false;
+
+					main_gpio_change(analog->pinno, aval);
+				}
+			}
+			else {
+				analog->count = 0;
+			}
+		}
+		break;
+	}
+}
+
+ER main_add_threshold(int subscriptionId, int pinno, uint16_t threshold)
+{
+	int i, aval;
+	analog_state_t *analog;
+
+	if ((pinno < 14) || (pinno > 19))
+		return E_PAR;
+
+	for (i = 0; i < MAIN_ANALOG_COUNT; i++) {
+		analog = &main_analog[i];
+		if (analog->subscriptionId != 0)
+			continue;
+
+		analog->subscriptionId = subscriptionId;
+		analog->pinno = pinno;
+		analog->threshold = threshold;
+
+		arduino_analogRead(analog->pinno, &aval);
+
+		analog->state = (aval < analog->threshold);
+		analog->count = 0;
+
+		return E_OK;
+	}
+
+	return E_NOMEM;
+}
+
+ER main_del_threshold(int subscriptionId)
+{
+	int i;
+	analog_state_t *analog;
+
+	for (i = 0; i < MAIN_ANALOG_COUNT; i++) {
+		analog = &main_analog[i];
+		if (analog->subscriptionId != subscriptionId)
+			continue;
+
+		analog->subscriptionId = 0;
+
+		return E_OK;
+	}
+
+	return E_OBJ;
 }
 
@@ -829,11 +960,11 @@
 
 	ret = ecn_itr_ini(&enm, esv);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_itr_ini");
 		return;
 	}
 
-	for(;;) {
-		while((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
+	for (;;) {
+		while ((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
 			switch (epc) {
 			case 0x80:
@@ -843,9 +974,9 @@
 			}
 		}
-		if(ret != E_BOVR){
+		if (ret != E_BOVR) {
 			syslog(LOG_ERROR, "ecn_itr_nxt");
 			break;
 		}
-		if(enm.is_eof)
+		if (enm.is_eof)
 			break;
 	}
@@ -858,5 +989,5 @@
 {
 	/* 押されて戻った時に処理する */
-	if(push)
+	if (push)
 		return;
 
@@ -873,4 +1004,14 @@
 
 /*
+ * GPIO状態変化処理
+ */
+static void main_gpio_change(int pinno, uint16_t value)
+{
+	main_gpio_pubid++;
+
+	wamp_broker_publish_pin(&wamp.broker, main_gpio_pubid, 1, pinno, value);
+}
+
+/*
  * 機器の検索
  */
@@ -882,5 +1023,5 @@
 	/* 機器の検索 */
 	ret = ecn_esv_inf_req(&esv, EOBJ_NULL, 0xD6);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_esv_inf_req");
 		return ret;
@@ -889,5 +1030,5 @@
 	/* 電文送信 */
 	ret = ecn_snd_esv(esv);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_snd_esv");
 		return ret;
@@ -906,5 +1047,5 @@
 
 	ret = psnd_dtq(WEBSOCKET_MBXID, (intptr_t)msg.ptr);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "psnd_dtq(WEBSOCKET_MBXID) : result=%d", ret);
 		_ecn_fbs_del(msg);
@@ -923,10 +1064,10 @@
 	ER ret;
 
-	if(request_info->requestId != 0)
+	if (request_info->requestId != 0)
 		return E_QOVR;
 
 	/* 機器の検索 */
 	ret = main_search_device();
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		return ret;
 	}
@@ -948,5 +1089,5 @@
 	for (;;) {
 		ret = ecn_agent_get_device_list(ECHONET_API_MAILBOX, request_info->requestId, &req);
-		if(ret != E_OK){
+		if (ret != E_OK) {
 			syslog(LOG_ERROR, "ecn_agent_get_device_list");
 			break;
@@ -1005,9 +1146,9 @@
 	ECN_FBS_ID req;
 
-	if(request_info->requestId != 0)
+	if (request_info->requestId != 0)
 		return E_QOVR;
 
 	ret = ecn_udp_get_ipaddr(ECHONET_API_MAILBOX, requestId, addrid, &req);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		return ret;
 	}
@@ -1063,9 +1204,9 @@
 	ECN_FBS_ID req;
 
-	if(request_info->requestId != 0)
+	if (request_info->requestId != 0)
 		return E_QOVR;
 
 	ret = ecn_agent_get_device_info(ECHONET_API_MAILBOX, requestId, eobjid, &req);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		return ret;
 	}
@@ -1118,10 +1259,10 @@
 	T_EDATA *esv;
 
-	if(request_info->requestId != 0)
+	if (request_info->requestId != 0)
 		return E_QOVR;
 
 	/* プロパティ取得電文作成 */
 	ret = ecn_esv_get(&esv, eobjid, epc);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_esv_get");
 		return ret;
@@ -1130,5 +1271,5 @@
 	/* 電文送信 */
 	ret = ecn_snd_esv(esv);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_snd_esv");
 		return ret;
@@ -1156,5 +1297,5 @@
 	T_ENUM_EPC enm;
 
-	if(request_info->eobjid != eobjid)
+	if (request_info->eobjid != eobjid)
 		return;
 
@@ -1166,20 +1307,20 @@
 
 	ret = ecn_itr_ini(&enm, esv);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_itr_ini");
 		return;
 	}
 
-	for(;;) {
-		while((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
+	for (;;) {
+		while ((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
 			if (request_info->epc == epc) {
 				wamp_dealer_kadecot_get(dealer, eobjid, epc, pdc, p_edt);
 			}
 		}
-		if(ret != E_BOVR){
+		if (ret != E_BOVR) {
 			syslog(LOG_ERROR, "ecn_itr_nxt");
 			break;
 		}
-		if(enm.is_eof)
+		if (enm.is_eof)
 			break;
 	}
@@ -1193,10 +1334,10 @@
 	T_EDATA *esv;
 
-	if(request_info->requestId != 0)
+	if (request_info->requestId != 0)
 		return E_QOVR;
 
 	/* プロパティ取得電文作成 */
 	ret = ecn_esv_setc(&esv, eobjid, epc, pdc, edt);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_esv_setc");
 		return ret;
@@ -1205,5 +1346,5 @@
 	/* 電文送信 */
 	ret = ecn_snd_esv(esv);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_snd_esv");
 		return ret;
@@ -1234,5 +1375,5 @@
 		return;
 
-	if(request_info->eobjid != eobjid)
+	if (request_info->eobjid != eobjid)
 		return;
 
@@ -1243,20 +1384,20 @@
 
 	ret = ecn_itr_ini(&enm, esv);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_itr_ini");
 		return;
 	}
 
-	for(;;) {
-		while((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
+	for (;;) {
+		while ((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
 			if (request_info->epc == epc) {
 				wamp_dealer_kadecot_set(dealer, eobjid, epc);
 			}
 		}
-		if(ret != E_BOVR){
+		if (ret != E_BOVR) {
 			syslog(LOG_ERROR, "ecn_itr_nxt");
 			break;
 		}
-		if(enm.is_eof)
+		if (enm.is_eof)
 			break;
 	}
@@ -1268,10 +1409,10 @@
 	ER ret;
 
-	if(request_info->requestId != 0)
+	if (request_info->requestId != 0)
 		return E_QOVR;
 
 	/* 電文送信 */
 	ret = ecn_snd_esv(esv);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_snd_esv");
 		return ret;
@@ -1304,10 +1445,10 @@
 	ER ret;
 
-	if(request_info->requestId != 0)
+	if (request_info->requestId != 0)
 		return E_QOVR;
 
 	/* 電文送信 */
 	ret = ecn_snd_esv(esv);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_snd_esv");
 		return ret;
@@ -1340,10 +1481,10 @@
 	ER ret;
 
-	if(request_info->requestId != 0)
+	if (request_info->requestId != 0)
 		return E_QOVR;
 
 	/* 電文送信 */
 	ret = ecn_snd_esv(esv);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_snd_esv");
 		return ret;
@@ -1375,5 +1516,5 @@
 	struct wamp_dealer *dealer = request_info->dealer;
 
-	switch(request_info->state) {
+	switch (request_info->state) {
 	case request_info_state_search_device:
 		main_search_device_timeout();
@@ -1422,20 +1563,20 @@
 
 	ret = ecn_itr_ini(&enm, esv);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_itr_ini");
 		return;
 	}
 
-	for(;;) {
-		while((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
+	for (;;) {
+		while ((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
 			wamp_broker_publish_inf(&wamp.broker, esv->hdr.ecn_hdr.tid, eobjid,
 				devType, epc, pdc, p_edt);
 		}
-		if(ret != E_BOVR){
+		if (ret != E_BOVR) {
 			syslog(LOG_ERROR, "ecn_itr_nxt");
 			break;
 		}
-		if(enm.is_eof)
-			break;
-	}
-}
+		if (enm.is_eof)
+			break;
+	}
+}
