Index: /EcnlProtoTool/trunk/ntshell/src/main.c
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/main.c	(revision 431)
+++ /EcnlProtoTool/trunk/ntshell/src/main.c	(revision 432)
@@ -79,5 +79,4 @@
 char command[NTOPT_TEXT_MAXLEN];
 ntstdio_t ntstdio;
-ntshell_t ntshell;
 
 unsigned char ntstdio_xi(struct ntstdio_t *handle)
@@ -118,4 +117,5 @@
 
 struct main_obj_t {
+	ntshell_t ntshell;
 	TMO timer;
 	enum main_state_t state;
@@ -127,9 +127,9 @@
 struct main_obj_t main_obj;
 
-static void netif_link_callback(T_IFNET *ether);
-static void main_initialize();
-static TMO main_get_timer();
-static void main_progress(TMO interval);
-static void main_timeout();
+static void main_change_netif_link(T_IFNET *ether);
+static void main_initialize(struct main_obj_t *obj);
+static TMO main_get_timer(struct main_obj_t *obj);
+static void main_progress(struct main_obj_t *obj, TMO elapse);
+static void main_timeout(struct main_obj_t *obj);
 extern int execute_command(int wait);
 static int usrcmd_ntopt_callback(long *args, void *extobj);
@@ -143,86 +143,4 @@
 {
 	return serial_rea_dat(SIO_PORTID, (char *)buf, cnt);
-#if 0
-	int result = cnt;
-	ER ret;
-	bool_t tmo = false;
-
-	while (cnt > 0) {
-		/* タイムアウト処理 */
-		if (tmo) {
-			tmo = false;
-			main_timeout();
-		}
-
-		if (main_obj.rcvmsg.ptr == NULL) {
-			ER ret2;
-			TMO timer;
-			WS_FBS_ID msg;
-
-			main_obj.prev = main_obj.now;
-
-			timer = main_get_timer();
-
-			ret = trcv_dtq(MAIN_DATAQUEUE, (intptr_t *)&msg, timer);
-			if ((ret != E_OK) && (ret != E_TMOUT)) {
-				syslog(LOG_ERROR, "trcv_dtq => %d", ret);
-				ext_tsk();
-				return 0;
-			}
-
-			ret2 = get_tim(&main_obj.now);
-			if (ret2 != E_OK) {
-				syslog(LOG_ERROR, "get_tim");
-				ext_tsk();
-				return 0;
-			}
-
-			/* 時間経過 */
-			main_progress(main_obj.now - main_obj.prev);
-
-			if (ret == E_OK) {
-				/* メッセージ受信処理 */
-				if (main_obj.rcvmsg.ptr == NULL) {
-					main_obj.rcvmsg = msg;
-				}
-				else {
-					ws_fbs_enqueue(&main_obj.wbs_queue, msg.ptr);
-				}
-			}
-
-			tmo = true;
-		}
-		else {
-			WS_FBS_SSIZE_T len, slen;
-
-			len = _ws_fbs_get_datalen(main_obj.rcvmsg);
-			if (len > cnt)
-				len = cnt;
-
-			ret = _ws_fbs_get_data(main_obj.rcvmsg, buf, len, &slen);
-			if (ret != E_OK) {
-				syslog(LOG_ERROR, "_ws_fbs_get_data msg = %p, type = %d, result = %d", main_obj.rcvmsg.ptr, main_obj.rcvmsg.ptr->hdr.type, ret);
-				ext_tsk();
-			}
-			cnt -= slen;
-
-			/* データが空の場合 */
-			if (!_ws_fbs_exist_data(main_obj.rcvmsg)) {
-				ret = _ws_fbs_del(main_obj.rcvmsg);
-				if (ret != E_OK) {
-					syslog(LOG_ERROR, "trcv_dtq msg = %p, type = %d, result = %d", main_obj.rcvmsg.ptr, main_obj.rcvmsg.ptr->hdr.type, ret);
-					ext_tsk();
-				}
-
-				main_obj.rcvmsg.ptr = NULL;
-
-				/* キューからデータを取得 */
-				ret = ws_fbs_dequeue(&main_obj.wbs_queue, &main_obj.rcvmsg.ptr);
-			}
-		}
-	}
-
-	return result;
-#endif
 }
 
@@ -230,27 +148,7 @@
 {
 	return serial_wri_dat(SIO_PORTID, buf, cnt);
-#if 0
-	int result = cnt;
-	ER ret;
-
-	while (cnt > 0) {
-		_ws_fbs_cre(cnt, &main_obj.sndmsg);
-
-		//((ID *)main_obj.sndmsg.ptr->_gap)[0] = wbsid;
-		_ws_fbs_add_data(main_obj.sndmsg, buf, cnt);
-
-		ret = psnd_dtq(WEBSOCKET_MBXID, (intptr_t)main_obj.sndmsg.ptr);
-		if (ret != E_OK) {
-			syslog(LOG_ERROR, "psnd_dtq(WEBSOCKET_MBXID) : result=%d", ret);
-			_ws_fbs_del(main_obj.sndmsg);
-			return ret;
-		}
-	}
-
-	return result;
-#endif
-}
-
-static int cmd_execute(const char *text, void *extobj)
+}
+
+int cmd_execute(const char *text, void *extobj)
 {
 	if (text != NULL) {
@@ -273,9 +171,11 @@
 void main_task(intptr_t exinf)
 {
-	main_initialize();
-
-	ntshell_init(&ntshell, uart_read, uart_write, cmd_execute, NULL);
-	ntshell_set_prompt(&ntshell, "NTShell>");
-	ntshell_execute(&ntshell);
+	struct main_obj_t *obj = (struct main_obj_t *)&main_obj;
+
+	main_initialize(obj);
+
+	ntshell_init(&obj->ntshell, uart_read, uart_write, cmd_execute, obj);
+	ntshell_set_prompt(&obj->ntshell, "NTShell>");
+	ntshell_execute(&obj->ntshell);
 }
 
@@ -283,5 +183,5 @@
  * 初期化
  */
-static void main_initialize()
+static void main_initialize(struct main_obj_t *obj)
 {
 	FILINFO fno;
@@ -291,10 +191,10 @@
 	fno.lfsize = _MAX_LFN + 1;
 #endif
-	ER ret2;
+	ER ret;
 
 	ntstdio_init(&ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, ntstdio_xi, ntstdio_xo);
 
-	main_obj.timer = TMO_FEVR;
-	main_obj.state = main_state_start;
+	obj->timer = TMO_FEVR;
+	obj->state = main_state_start;
 
 	gpio_t led_blue, led_green, led_red, sw;
@@ -310,5 +210,5 @@
 	gpio_write(&led_red, 0);
 
-	ether_set_link_callback(netif_link_callback);
+	ether_set_link_callback(main_change_netif_link);
 
 	/* 初期化 */
@@ -336,6 +236,6 @@
 	}
 
-	ret2 = get_tim(&main_obj.now);
-	if (ret2 != E_OK) {
+	ret = get_tim(&obj->now);
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "get_tim");
 		ext_tsk();
@@ -347,7 +247,7 @@
  * タイマー取得
  */
-static TMO main_get_timer()
-{
-	TMO timer = main_obj.timer;
+static TMO main_get_timer(struct main_obj_t *obj)
+{
+	TMO timer = obj->timer;
 
 	return timer;
@@ -357,10 +257,10 @@
  * 時間経過
  */
-static void main_progress(TMO interval)
-{
-	if (main_obj.timer != TMO_FEVR) {
-		main_obj.timer -= interval;
-		if (main_obj.timer < 0) {
-			main_obj.timer = 0;
+static void main_progress(struct main_obj_t *obj, TMO elapse)
+{
+	if (obj->timer != TMO_FEVR) {
+		obj->timer -= elapse;
+		if (obj->timer < 0) {
+			obj->timer = 0;
 		}
 	}
@@ -370,7 +270,7 @@
  * タイムアウト処理
  */
-static void main_timeout()
-{
-	//if (main_obj.timer == 0) {
+static void main_timeout(struct main_obj_t *obj)
+{
+	//if (obj->timer == 0) {
 	//}
 }
@@ -382,5 +282,5 @@
 }
 
-static void netif_link_callback(T_IFNET *ether)
+static void main_change_netif_link(T_IFNET *ether)
 {
 	FLGPTN flgptn;
@@ -406,10 +306,4 @@
 	shellcmd_state = 2;
 }
-
-typedef struct
-{
-	const cmd_table_t *table;
-	int count;
-} cmd_table_info_t;
 
 static const cmd_table_t cmdlist[] = {
@@ -429,4 +323,10 @@
 {
 	const cmd_table_t *p = cmd_table_info.table;
+	int result = 0;
+	int found = 0;
+
+	if (*args == 0)
+		return result;
+
 	if (ntlibc_strcmp((const char *)args[1], "help") == 0) {
 		usrcmd_help(args[0], (char **)&args[1]);
Index: /EcnlProtoTool/trunk/ntshell/src/main.h
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/main.h	(revision 431)
+++ /EcnlProtoTool/trunk/ntshell/src/main.h	(revision 432)
@@ -52,5 +52,5 @@
  */
 
-#define MAIN_PRIORITY	5		/* メインタスクの優先度 */
+#define MAIN_PRIORITY	5			/* メインタスクの優先度 */
 #define SHELLCMD_PRIORITY	4		/* shellcmdタスクの優先度 */
 
@@ -58,5 +58,5 @@
 #define SHELLCMD_STACK_SIZE	0x00800000	/* shellcmdタスクのスタック領域のサイズ */
 
-#define NUM_MAIN_DATAQUEUE	1	/* メインタスクで待ち受けているデータキューのサイズ */
+#define NUM_MAIN_DATAQUEUE	1		/* メインタスクで待ち受けているデータキューのサイズ */
 #define NUM_SHELLCMD_DATAQUEUE	1	/* shellcmdタスクで待ち受けているデータキューのサイズ */
 
@@ -66,9 +66,18 @@
 #ifndef TOPPERS_MACRO_ONLY
 
+typedef struct
+{
+	const cmd_table_t *table;
+	int count;
+} cmd_table_info_t;
+
 /* メインタスク */
-extern void main_task(intptr_t exinf);
+void main_task(intptr_t exinf);
 
 /* shellcmdタスク */
-extern void shellcmd_task(intptr_t exinf);
+void shellcmd_task(intptr_t exinf);
+
+/* コマンド実行 */
+int cmd_execute(const char *text, void *extobj);
 
 /* 
