Index: asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/src/echonet_main.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/src/echonet_main.c	(revision 359)
+++ asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/src/echonet_main.c	(revision 364)
@@ -1,7 +1,7 @@
 /*
  *  TOPPERS ECHONET Lite Communication Middleware
- * 
+ *
  *  Copyright (C) 2014-2018 Cores Co., Ltd. Japan
- * 
+ *
  *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
  *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
@@ -26,5 +26,5 @@
  *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
  *      免責すること．
- * 
+ *
  *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
  *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
@@ -32,9 +32,9 @@
  *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
  *  の責任を負わない．
- * 
+ *
  *  @(#) $Id$
  */
 
-/* 
+/*
  *  サンプルプログラム(1)の本体
  */
@@ -55,4 +55,12 @@
 #include "adafruit_st7735.h"
 #include "draw_font.h"
+#include <tinet_defs.h>
+#include <tinet_config.h>
+#include <netinet/in.h>
+#include <netinet/in_var.h>
+#include <net/ethernet.h>
+#include <net/if_var.h>
+
+extern uint8_t mac_addr[6];
 
 /* TODO: メーカーコードを設定 */
@@ -111,10 +119,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:
@@ -126,5 +134,5 @@
 		data[1] = *(uint8_t *)src;
 		ret = ecn_brk_wai(data, sizeof(data));
-		if(ret != E_OK){
+		if (ret != E_OK) {
 			syslog(LOG_ERROR, "ecn_brk_wai");
 			return 1;
@@ -145,10 +153,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:
@@ -176,15 +184,15 @@
 
 	/* サイズが2以外は受け付けない */
-	if(size != 2)
+	if (size != 2)
 		return 0;
 
 	value = (((uint8_t *)src)[0] << 8) | (((uint8_t *)src)[1] & 0xFF);
 
-	if((value >= -2732) && (value <= 32766)){
+	if ((value >= -2732) && (value <= 32766)) {
 		eobj->propertyE0 = value;
 		/* メインタスクに通知 */
 		data[0] = 0xE0;
 		ret = ecn_brk_wai(data, sizeof(data));
-		if(ret != E_OK){
+		if (ret != E_OK) {
 			syslog(LOG_ERROR, "ecn_brk_wai");
 			return 2;
@@ -192,5 +200,5 @@
 	}
 	/* 上記以外は受け付けない */
-	else{
+	else {
 		return 0;
 	}
@@ -199,5 +207,5 @@
 }
 
-/* 
+/*
  * 温度計測値取得関数
  */
@@ -208,5 +216,5 @@
 
 	/* サイズが2以外は受け付けない */
-	if(size != 2)
+	if (size != 2)
 		return 0;
 
@@ -240,10 +248,10 @@
 
 	ret2 = get_tim(&now);
-	if (ret2 != E_OK){
+	if (ret2 != E_OK) {
 		syslog(LOG_ERROR, "get_tim");
 		return;
 	}
 
-	for(;;){
+	for (;;) {
 		prev = now;
 
@@ -253,5 +261,5 @@
 		/* 応答電文待ち */
 		ret = ecn_trcv_esv(&esv, timer);
-		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");
 			break;
@@ -259,5 +267,5 @@
 
 		ret2 = get_tim(&now);
-		if (ret2 != E_OK){
+		if (ret2 != E_OK) {
 			syslog(LOG_ERROR, "get_tim");
 			break;
@@ -274,5 +282,5 @@
 			/* 領域解放 */
 			ret = ecn_rel_esv(esv);
-			if (ret != E_OK){
+			if (ret != E_OK) {
 				syslog(LOG_ERROR, "ecn_rel_esv");
 				break;
@@ -283,5 +291,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");
 				break;
@@ -293,5 +301,5 @@
 			/* 領域解放 */
 			ret = ecn_rel_esv(esv);
-			if (ret != E_OK){
+			if (ret != E_OK) {
 				syslog(LOG_ERROR, "ecn_rel_esv");
 				break;
@@ -304,6 +312,4 @@
 }
 
-bool_t started = false;
-
 void echonet_change_netif_link(uint8_t link_up, uint8_t up)
 {
@@ -313,14 +319,10 @@
 		return;
 
-	if (up && !started) {
-		started = true;
-
-		/* ECHONETミドルウェアを起動 */
-		ret = ecn_sta_svc();
-		if (ret != E_OK)
-			return;
-
-		/* ECHONETミドルウェアを起動するのを待つ */
-		dly_tsk(100);
+	if (up) {
+		/* インスタンスリスト通知の送信 */
+		ret = ecn_ntf_inl();
+		if (ret != E_OK) {
+			syslog(LOG_ERROR, "ecn_ntf_inl");
+		}
 	}
 
@@ -328,5 +330,5 @@
 	uint8_t data[2];
 	data[0] = 0x01;
-	data[1] = up ? 0x01 : 0x02;
+	data[1] = (up ? 0x01 : 0x02) | (link_up ? 0x10 : 0x20);
 	ret = ecn_brk_wai(data, sizeof(data));
 	if (ret != E_OK) {
@@ -336,10 +338,11 @@
 }
 
-enum main_state_t{
+enum main_state_t {
+	main_state_start,
 	main_state_idle,
 };
 
 int main_timer = TMO_FEVR;
-enum main_state_t main_state = main_state_idle;
+enum main_state_t main_state = main_state_start;
 
 int main_lcd_timer = TMO_FEVR;
@@ -386,6 +389,7 @@
 	analogin_init(&joystick, P1_12);
 
-	/* 10ms後にボタン状態を確認 */
-	main_timer = 10 * 1000;
+	/* ECHONETミドルウェアを起動するのを待つ */
+	main_state = main_state_start;
+	main_timer = 1000 * 1000;
 
 	/* ボタン状態読み込み */
@@ -397,5 +401,5 @@
 	spi_init(&lcd.hspi, P10_14, P10_15, P10_12, NC);
 	spi_format(&lcd.hspi, 8, 0, 0);
-	spi_frequency(&lcd.hspi, 1000000);
+	spi_frequency(&lcd.hspi, 4000000);
 
 	gpio_init_out(&lcd.cs_pin, P10_13);
@@ -416,4 +420,5 @@
 	main_lcd_timer = 1000 * 1000;
 
+	/* メインタスクを起動 */
 	ER ret = act_tsk(MAIN_TASK);
 	if (ret != E_OK) {
@@ -429,6 +434,6 @@
 	int result = main_timer;
 
-	if((result == TMO_FEVR)
-		|| ((main_lcd_timer != TMO_FEVR) && (main_lcd_timer < result))){
+	if ((result == TMO_FEVR)
+		|| ((main_lcd_timer != TMO_FEVR) && (main_lcd_timer < result))) {
 		result = main_lcd_timer;
 	}
@@ -442,14 +447,14 @@
 static void main_progress(int interval)
 {
-	if(main_timer != TMO_FEVR){
+	if (main_timer != TMO_FEVR) {
 		main_timer -= interval;
-		if(main_timer < 0){
+		if (main_timer < 0) {
 			main_timer = 0;
 		}
 	}
 
-	if(main_lcd_timer != TMO_FEVR){
+	if (main_lcd_timer != TMO_FEVR) {
 		main_lcd_timer -= interval;
-		if(main_lcd_timer < 0){
+		if (main_lcd_timer < 0) {
 			main_lcd_timer = 0;
 		}
@@ -472,14 +477,14 @@
 
 	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 0xE0:
-				if(in_get && (esv->hdr.edata.esv == ESV_SET_GET_RES)){
+				if (in_get && (esv->hdr.edata.esv == ESV_SET_GET_RES)) {
 					check_response(pdc, p_edt);
 				}
@@ -487,9 +492,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;
 
@@ -504,11 +509,23 @@
 static void main_break_wait(uint8_t *brkdat, int32_t len)
 {
+	char mac_text[30] = "mac: ";
+	char ipaddr_text[30] = "ipadr: ";
+	const T_IN4_ADDR *ip4_addr;
+	int pos;
+
 	if (brkdat[0] == 0x01) {
-		// Link up/down
+		pos = str_macaddr(&mac_text[4], sizeof(mac_text) - 4, mac_addr, 0);
+		mac_text[pos + 4] = '\0';
+		lcd_drawString(&lcd, mac_text, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 11), ST7735_BLACK, ST7735_WHITE);
+
+		ip4_addr = in4_get_ifaddr(0);
+		pos = str_ipv4addr(&ipaddr_text[6], sizeof(ipaddr_text) - 6, ip4_addr, 0);
+		ipaddr_text[pos + 6] = '\0';
+		lcd_drawString(&lcd, ipaddr_text, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 12), ST7735_BLACK, ST7735_WHITE);
 		return;
 	}
 
 	if ((len == 2) && (brkdat[0] == 0x80)) {
-		switch(brkdat[1]){
+		switch (brkdat[1]) {
 		/* ONの場合 */
 		case 0x30:
@@ -533,9 +550,9 @@
 static void main_timeout()
 {
-	if(main_timer == 0){
+	if (main_timer == 0) {
 		main_ontimer();
 	}
 
-	if(main_lcd_timer == 0){
+	if (main_lcd_timer == 0) {
 		main_lcd_ontimer();
 	}
@@ -543,7 +560,7 @@
 
 #define main_ad_count 3
+#define main_ad_table_count 64
 static int16_t main_ad_tempr[main_ad_count] = { 200, 200, 200 };
-static uint16_t main_ad_table[64];
-#define main_ad_table_count (sizeof(main_ad_table) / sizeof(main_ad_table[0]))
+static uint16_t main_ad_table[main_ad_count][main_ad_table_count];
 static int main_ad_pos = 0;
 static uint32_t main_ad_avelage[main_ad_count];
@@ -556,9 +573,21 @@
 static void main_ontimer()
 {
+	ER ret;
 	uint8_t btn;
 	uint16_t ad_value;
 	int16_t ad_tempr;
 
-	switch(main_state){
+	switch (main_state) {
+	case main_state_start:
+		/* ECHONETミドルウェアを起動 */
+		ret = ecn_sta_svc();
+		if (ret != E_OK) {
+			syslog(LOG_ERROR, "ecn_sta_svc");
+		}
+
+		/* 10ms後にボタン状態を確認 */
+		main_state = main_state_idle;
+		main_timer = 10 * 1000;
+		break;
 	case main_state_idle:
 		/* 10ms後にボタン状態を確認 */
@@ -567,12 +596,12 @@
 		/* ADCの変換結果取得 */
 		for (int i = 0; i < main_ad_count; i++) {
-			main_ad_avelage[i] -= main_ad_table[main_ad_pos];
+			main_ad_avelage[i] -= main_ad_table[i][main_ad_pos];
 			ad_value = analogin_read_u16(&analogin[i]) >> 4;	// 16bit値取得->12bit
-			main_ad_table[main_ad_pos] = ad_value;
+			main_ad_table[i][main_ad_pos] = ad_value;
 			main_ad_avelage[i] += ad_value;
 		}
 
 		main_ad_pos++;
-		if(main_ad_pos >= main_ad_table_count){
+		if (main_ad_pos >= main_ad_table_count) {
 			main_ad_pos = 0;
 		}
@@ -586,4 +615,5 @@
 				}
 				else {
+					main_count[i] = 0;
 					main_ad_tempr[i] = ad_tempr;
 
@@ -601,7 +631,7 @@
 
 		/* ボタン１の処理 */
-		if((btn == BUTTON_LEFT) && !main_btn1_state){
+		if ((btn == BUTTON_LEFT) && !main_btn1_state) {
 			main_btn1_count++;
-			if(main_btn1_count > 10){
+			if (main_btn1_count > 10) {
 				main_btn1_count = 0;
 				main_btn1_state = true;
@@ -610,7 +640,7 @@
 			}
 		}
-		else if((btn != BUTTON_LEFT) && main_btn1_state){
+		else if ((btn != BUTTON_LEFT) && main_btn1_state) {
 			main_btn1_count++;
-			if(main_btn1_count > 10){
+			if (main_btn1_count > 10) {
 				main_btn1_count = 0;
 				main_btn1_state = false;
@@ -621,7 +651,7 @@
 
 		/* ボタン２の処理 */
-		if((btn == BUTTON_RIGHT) && !main_btn2_state){
+		if ((btn == BUTTON_RIGHT) && !main_btn2_state) {
 			main_btn2_count++;
-			if(main_btn2_count > 10){
+			if (main_btn2_count > 10) {
 				main_btn2_count = 0;
 				main_btn2_state = true;
@@ -630,7 +660,7 @@
 			}
 		}
-		else if((btn != BUTTON_RIGHT) && main_btn2_state){
+		else if ((btn != BUTTON_RIGHT) && main_btn2_state) {
 			main_btn2_count++;
-			if(main_btn2_count > 10){
+			if (main_btn2_count > 10) {
 				main_btn2_count = 0;
 				main_btn2_state = false;
@@ -645,7 +675,7 @@
 static void main_lcd_ontimer()
 {
-	char temp1[] = "温度1：+00.0℃";
-	char temp2[] = "温度2：+00.0℃";
-	char humid[] = "湿度 ：+00.0％";
+	char temp1[] = "温度1：+000.0℃";
+	char temp2[] = "温度2：+000.0℃";
+	char humid[] = "湿度 ：+000.0％";
 	char *btn_texts[] = { "none  ", "down  ", "left  ", "select", "up    ", "right " };
 	int temp, btn;
@@ -653,46 +683,55 @@
 	switch (main_lcd_state) {
 	case 0:
-		temp1[9] = (temperature_sensor1_data.propertyE0 >= 0) ? ' ' : '-';
+		temp1[10] = (temperature_sensor1_data.propertyE0 >= 0) ? ' ' : '-';
 		temp = (temperature_sensor1_data.propertyE0 / 1000) % 10;
 		if (temp < 0)
 			temp = -temp;
-		temp1[10] = '0' + temp;
+		temp1[11] = '0' + temp;
 		temp = (temperature_sensor1_data.propertyE0 / 100) % 10;
 		if (temp < 0)
 			temp = -temp;
-		temp1[11] = '0' + temp;
+		temp1[12] = '0' + temp;
 		temp = (temperature_sensor1_data.propertyE0 / 10) % 10;
 		if (temp < 0)
 			temp = -temp;
 		temp1[13] = '0' + temp;
-		lcd_drawString(&lcd, &temp1[9], X_LINE_HALF_TO_PIX(&lcd, 8) + 10, Y_ROW_TO_PIX(&lcd, main_lcd_state + 4) + 10, ST7735_BLACK, ST7735_WHITE);
+		temp = (temperature_sensor1_data.propertyE0 / 1) % 10;
+		if (temp < 0)
+			temp = -temp;
+		temp1[15] = '0' + temp;
+		lcd_drawString(&lcd, &temp1[10], X_LINE_HALF_TO_PIX(&lcd, 7), Y_ROW_TO_PIX(&lcd, main_lcd_state + 2), ST7735_BLACK, ST7735_WHITE);
 		main_lcd_state++;
 		break;
 	case 1:
-		temp2[9] = (temperature_sensor2_data.propertyE0 >= 0) ? ' ' : '-';
+		temp2[10] = (temperature_sensor2_data.propertyE0 >= 0) ? ' ' : '-';
 		temp = (temperature_sensor2_data.propertyE0 / 1000) % 10;
 		if (temp < 0)
 			temp = -temp;
-		temp2[10] = '0' + temp;
+		temp2[11] = '0' + temp;
 		temp = (temperature_sensor2_data.propertyE0 / 100) % 10;
 		if (temp < 0)
 			temp = -temp;
-		temp2[11] = '0' + temp;
+		temp2[12] = '0' + temp;
 		temp = (temperature_sensor2_data.propertyE0 / 10) % 10;
 		if (temp < 0)
 			temp = -temp;
 		temp2[13] = '0' + temp;
-		lcd_drawString(&lcd, &temp2[9], X_LINE_HALF_TO_PIX(&lcd, 8) + 10, Y_ROW_TO_PIX(&lcd, main_lcd_state + 4) + 10, ST7735_BLACK, ST7735_WHITE);
+		temp = (temperature_sensor2_data.propertyE0 / 1) % 10;
+		if (temp < 0)
+			temp = -temp;
+		temp2[15] = '0' + temp;
+		lcd_drawString(&lcd, &temp2[10], X_LINE_HALF_TO_PIX(&lcd, 7), Y_ROW_TO_PIX(&lcd, main_lcd_state + 2), ST7735_BLACK, ST7735_WHITE);
 		main_lcd_state++;
 		break;
 	case 2:
-		humid[9] = ' ';
-		temp = (humidity_sensor_data.propertyE0 / 1000) % 10;
-		humid[10] = '0' + temp;
+		humid[10] = ' ';
+		humid[11] = ' ';
 		temp = (humidity_sensor_data.propertyE0 / 100) % 10;
-		humid[11] = '0' + temp;
+		humid[12] = '0' + temp;
 		temp = (humidity_sensor_data.propertyE0 / 10) % 10;
 		humid[13] = '0' + temp;
-		lcd_drawString(&lcd, &humid[9], X_LINE_HALF_TO_PIX(&lcd, 8) + 10, Y_ROW_TO_PIX(&lcd, main_lcd_state + 4) + 10, ST7735_BLACK, ST7735_WHITE);
+		temp = (humidity_sensor_data.propertyE0 / 1) % 10;
+		humid[15] = '0' + temp;
+		lcd_drawString(&lcd, &humid[10], X_LINE_HALF_TO_PIX(&lcd, 7), Y_ROW_TO_PIX(&lcd, main_lcd_state + 2), ST7735_BLACK, ST7735_WHITE);
 		main_lcd_state++;
 		break;
@@ -704,5 +743,5 @@
 	case 6:
 		btn = main_read_button(&joystick);
-		lcd_drawString(&lcd, btn_texts[btn], X_LINE_TO_PIX(&lcd, 0) + 10, Y_ROW_TO_PIX(&lcd, 10) + 10, ST7735_BLACK, ST7735_WHITE);
+		lcd_drawString(&lcd, btn_texts[btn], X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 9), ST7735_BLACK, ST7735_WHITE);
 		main_lcd_state++;
 		break;
@@ -711,8 +750,8 @@
 		break;
 	case 10:
-		lcd_drawString(&lcd, "温度湿度計", X_LINE_TO_PIX(&lcd, 9) + 10, Y_ROW_TO_PIX(&lcd, 0) + 10, ST7735_BLACK, ST7735_WHITE);
-		lcd_drawString(&lcd, temp1, X_LINE_TO_PIX(&lcd, 0) + 10, Y_ROW_TO_PIX(&lcd, 0 + 4) + 10, ST7735_BLACK, ST7735_WHITE);
-		lcd_drawString(&lcd, temp2, X_LINE_TO_PIX(&lcd, 0) + 10, Y_ROW_TO_PIX(&lcd, 1 + 4) + 10, ST7735_BLACK, ST7735_WHITE);
-		lcd_drawString(&lcd, humid, X_LINE_TO_PIX(&lcd, 0) + 10, Y_ROW_TO_PIX(&lcd, 2 + 4) + 10, ST7735_BLACK, ST7735_WHITE);
+		lcd_drawString(&lcd, "温度湿度計", X_LINE_TO_PIX(&lcd, 5), Y_ROW_TO_PIX(&lcd, 0), ST7735_BLACK, ST7735_WHITE);
+		lcd_drawString(&lcd, temp1, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 0 + 2), ST7735_BLACK, ST7735_WHITE);
+		lcd_drawString(&lcd, temp2, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 1 + 2), ST7735_BLACK, ST7735_WHITE);
+		lcd_drawString(&lcd, humid, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 2 + 2), ST7735_BLACK, ST7735_WHITE);
 		main_lcd_state = 0;
 		break;
@@ -755,5 +794,5 @@
 	/* プロパティ設定電文作成 */
 	ret = ecn_esv_setc(&esv, eobj, 0xE0, 2, p_edt);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_esv_setc");
 		return;
@@ -761,5 +800,8 @@
 
 	/* 電文送信 */
-	ecn_snd_esv(esv);
+	ret = ecn_snd_esv(esv);
+	if (ret != E_OK) {
+		syslog(LOG_ERROR, "ecn_snd_esv");
+	}
 }
 
@@ -798,10 +840,10 @@
 
 	/* 押されて戻った時に処理する */
-	if(push)
+	if (push)
 		return;
 
 	/* 温度計測値 */
 	main_tmpr -= 10;	/* - 1.0℃ */
-	if(main_tmpr < -100)	/* -10.0℃までとする */
+	if (main_tmpr < -100)	/* -10.0℃までとする */
 		main_tmpr = -100;
 
@@ -811,5 +853,5 @@
 	/* プロパティ値書き込み・読み出し要求電文作成 */
 	ret = ecn_esv_set_get(&esv, TEMP_SENSOR_02_EOBJ, 0xE0, 2, p_edt);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_esv_setc");
 		return;
@@ -820,5 +862,5 @@
 	/* 書き込みプロパティ追加 */
 	ret = ecn_add_edt(esv, 0x80, 1, p_edt);
-	if(ret) {
+	if (ret) {
 		syslog(LOG_ERROR, "ecn_add_edt");
 		goto error;
@@ -827,5 +869,5 @@
 	/* プロパティ値書き込み・読み出し要求電文作成：折り返し指定 */
 	ret = ecn_trn_set_get(esv, &trn_pos);
-	if(ret) {
+	if (ret) {
 		syslog(LOG_ERROR, "ecn_trn_set_get");
 		goto error;
@@ -834,5 +876,5 @@
 	/* 読み出しプロパティ追加 */
 	ret = ecn_add_epc(esv, 0xE0);
-	if(ret) {
+	if (ret) {
 		syslog(LOG_ERROR, "ecn_add_epc");
 		goto error;
@@ -841,5 +883,5 @@
 	/* プロパティ値書き込み・読み出し要求電文作成：終了指定 */
 	ret = ecn_end_set_get(esv, trn_pos);
-	if(ret) {
+	if (ret) {
 		syslog(LOG_ERROR, "ecn_end_set_get");
 		goto error;
@@ -848,5 +890,5 @@
 	/* 電文送信 */
 	ret = ecn_snd_esv(esv);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_snd_esv");
 	}
@@ -855,5 +897,5 @@
 	/* 領域解放 */
 	ret = ecn_rel_esv(esv);
-	if (ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_rel_esv");
 	}
@@ -871,10 +913,10 @@
 
 	/* 押されて戻った時に処理する */
-	if(push)
+	if (push)
 		return;
 
 	/* 温度計測値 */
 	main_tmpr += 10;	/* + 1.0℃ */
-	if(main_tmpr > 400)	/* +40.0℃までとする */
+	if (main_tmpr > 400)	/* +40.0℃までとする */
 		main_tmpr = 400;
 
@@ -884,5 +926,5 @@
 	/* プロパティ値書き込み・読み出し要求電文作成 */
 	ret = ecn_esv_set_get(&esv, TEMP_SENSOR_02_EOBJ, 0xE0, 2, p_edt);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_esv_setc");
 		return;
@@ -893,5 +935,5 @@
 	/* 書き込みプロパティ追加 */
 	ret = ecn_add_edt(esv, 0x80, 1, p_edt);
-	if(ret) {
+	if (ret) {
 		syslog(LOG_ERROR, "ecn_add_edt");
 		goto error;
@@ -900,5 +942,5 @@
 	/* プロパティ値書き込み・読み出し要求電文作成：折り返し指定 */
 	ret = ecn_trn_set_get(esv, &trn_pos);
-	if(ret) {
+	if (ret) {
 		syslog(LOG_ERROR, "ecn_trn_set_get");
 		goto error;
@@ -907,5 +949,5 @@
 	/* 読み出しプロパティ追加 */
 	ret = ecn_add_epc(esv, 0xE0);
-	if(ret) {
+	if (ret) {
 		syslog(LOG_ERROR, "ecn_add_epc");
 		goto error;
@@ -914,5 +956,5 @@
 	/* プロパティ値書き込み・読み出し要求電文作成：終了指定 */
 	ret = ecn_end_set_get(esv, trn_pos);
-	if(ret) {
+	if (ret) {
 		syslog(LOG_ERROR, "ecn_end_set_get");
 		goto error;
@@ -921,5 +963,5 @@
 	/* 電文送信 */
 	ret = ecn_snd_esv(esv);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_snd_esv");
 	}
@@ -928,5 +970,5 @@
 	/* 領域解放 */
 	ret = ecn_rel_esv(esv);
-	if (ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_rel_esv");
 	}
@@ -938,8 +980,7 @@
 static bool_t check_response(uint8_t pdc, uint8_t *p_edt)
 {
-	if((pdc != 2)
+	if ((pdc != 2)
 		|| (p_edt[0] != ((uint16_t)main_tmpr) >> 8)
-		|| (p_edt[1] != ((uint16_t)main_tmpr) & 0xFF))
-	{
+		|| (p_edt[1] != ((uint16_t)main_tmpr) & 0xFF)) {
 		syslog(LOG_WARNING, "epc_set_get response NG");
 		return false;
Index: asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/src/main.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/src/main.c	(revision 359)
+++ asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/src/main.c	(revision 364)
@@ -79,5 +79,7 @@
 
 ID ws_api_mailboxid = MAIN_DATAQUEUE;
+#ifndef NOUSE_MPF_NET_BUF
 ID ws_mempoolid = MPF_NET_BUF_256;
+#endif
 
 #ifdef IF_ETHER_BTUSB
@@ -111,7 +113,42 @@
 static void main_timeout();
 
+extern int ntshell_exit;
+
 int uart_read(char *buf, int cnt, void *extobj)
 {
-	return serial_rea_dat(SIO_PORTID, (char *)buf, cnt);
+	struct main_t *obj = (struct main_t *)extobj;
+	int result;
+	ER ret;
+	int timer;
+
+	obj->prev = obj->now;
+
+	/* タイマー取得 */
+	timer = main_get_timer();
+
+	/* 待ち */
+	ret = serial_trea_dat(SIO_PORTID, buf, cnt, timer);
+	if ((ret < 0) && (ret != E_OK) && (ret != E_TMOUT)) {
+		syslog(LOG_NOTICE, "tslp_tsk ret: %s %d", itron_strerror(ret), timer);
+		ntshell_exit = 1;
+		return -1;
+	}
+	result = (int)ret;
+
+	ret = get_tim(&obj->now);
+	if (ret != E_OK) {
+		syslog(LOG_NOTICE, "get_tim ret: %s", itron_strerror(ret));
+		ntshell_exit = 1;
+		return -1;
+	}
+
+			/* 時間経過 */
+	int elapse = obj->now - obj->prev;
+	main_progress(elapse);
+
+	/* タイムアウト処理 */
+	main_timeout();
+
+	return result;
 }
 
@@ -119,19 +156,4 @@
 {
 	return serial_wri_dat(SIO_PORTID, buf, cnt);
-}
-
-unsigned char ntstdio_xi(struct ntstdio_t *handle)
-{
-	char buf[1];
-	if(serial_rea_dat(SIO_PORTID, buf, 1) != 1)
-		return -EIO;
-	return buf[0];
-}
-
-void ntstdio_xo(struct ntstdio_t *handle, unsigned char c)
-{
-	char buf[1];
-	buf[0] = c;
-	serial_wri_dat(SIO_PORTID, buf, 1);
 }
 
@@ -150,5 +172,5 @@
 	main_initialize();
 
-	ntshell_init(&ntshell, uart_read, uart_write, cmd_execute, NULL);
+	ntshell_init(&ntshell, uart_read, uart_write, cmd_execute, &main_obj);
 	ntshell_set_prompt(&ntshell, "NTShell>");
 	ntshell_execute(&ntshell);
@@ -168,5 +190,10 @@
 	ER ret;
 
-	ntshell_task_init();
+#ifdef TOPPERS_OMIT_TECS
+	serial_opn_por(SIO_PORTID);
+#endif
+	serial_ctl_por(SIO_PORTID, IOCTL_FCSND | IOCTL_FCRCV);
+
+	ntshell_task_init(uart_read, uart_write, &main_obj);
 
 	main_obj.timer = TMO_FEVR;
Index: asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/src/main.cfg
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/src/main.cfg	(revision 359)
+++ asp3_tinet_ecnl_arm/trunk/app5_temp_sensor/src/main.cfg	(revision 364)
@@ -54,5 +54,4 @@
 INCLUDE("tinet/tinet_asp.cfg");
 INCLUDE("tinet_main.cfg");
-INCLUDE("netinet/ip_igmp.cfg");
 
 /* DHCP クライアント */
