From f219b90d7f1630f0048ffeac69d4f7aa85d8ac97 Mon Sep 17 00:00:00 2001
From: Daisuke Baba <baba.daisuke@gmail.com>
Date: Wed, 27 Jul 2016 14:48:28 +0900
Subject: [PATCH 1/5] Add a new function to monitor the inactivation state of
 USB ACM, USB ECM is out of scope here

---
 systemd/start_systemd.sh | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/systemd/start_systemd.sh b/systemd/start_systemd.sh
index 84b038b..9ab66dc 100755
--- a/systemd/start_systemd.sh
+++ b/systemd/start_systemd.sh
@@ -24,6 +24,20 @@ function wait_for_modem_usb_active {
   done
 }
 
+function wait_for_modem_usb_acm_inactive {
+  MAX=40
+  COUNTER=0
+  while [ ${COUNTER} -lt ${MAX} ];
+  do
+    RET=`lsusb | grep 1ecb:0202`
+    if [ "$?" != "0" ]; then
+      break
+    fi
+    sleep 0.5
+    let COUNTER=COUNTER+1
+  done
+}
+
 function wait_for_modem_usb_inactive {
   MAX=40
   COUNTER=0
@@ -101,7 +115,7 @@ function diagnose_self {
 
     look_for_serial_port
     change_usb_data_conn
-    wait_for_modem_usb_inactive
+    wait_for_modem_usb_acm_inactive
     wait_for_modem_usb_active
     if [ -z "${MODEM_USB_MODE}" ]; then
       return
@@ -109,7 +123,6 @@ function diagnose_self {
 
     look_for_serial_port
     enable_auto_connect
-    wait_for_modem_usb_inactive
     wait_for_modem_usb_active
     if [ -z "${MODEM_USB_MODE}" ]; then
       return

From 6ae5a965a114f1b02697871c21ce597becfec2b3 Mon Sep 17 00:00:00 2001
From: Daisuke Baba <baba.daisuke@gmail.com>
Date: Wed, 27 Jul 2016 14:49:06 +0900
Subject: [PATCH 2/5] Add a new function to register new vendor ID and product
 ID to USB serial

---
 systemd/start_systemd.sh | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/systemd/start_systemd.sh b/systemd/start_systemd.sh
index 9ab66dc..0d496f8 100755
--- a/systemd/start_systemd.sh
+++ b/systemd/start_systemd.sh
@@ -85,7 +85,10 @@ function enable_auto_connect {
   logger -t ltepi2 "Enabling auto-connect mode"
   /usr/bin/env python /opt/candy-line/ltepi2/server_main.py ${MODEM_SERIAL_PORT} /var/run/candy-board-service.sock init2
   RET=$?
-  if [ "${RET}" != "0" ]; then
+  if [ "${RET}" == "1" ]; then
+    logger -t ltepi2 "** Waiting for USB being inactivated ***"
+    wait_for_modem_usb_inactive
+  elif [ "${RET}" != "0" ]; then
     exit ${RET}
   fi
 }
@@ -104,6 +107,17 @@ function wait_for_default_route {
   done
 }
 
+function register_usbserial {
+  # Registering a new id
+  modprobe usbserial vendor=0x1ecb product=0x0208
+  RET=$?
+  if [ "${RET}" != "0" ]; then
+    if [ -e "/sys/bus/usb-serial/drivers/pl2303" ]; then
+      echo "1ecb 0208" > /sys/bus/usb-serial/drivers/pl2303/new_id
+    fi
+  fi
+}
+
 function diagnose_self {
   wait_for_modem_usb_active
   if [ -z "${MODEM_USB_MODE}" ]; then
@@ -121,6 +135,7 @@ function diagnose_self {
       return
     fi
 
+    register_usbserial
     look_for_serial_port
     enable_auto_connect
     wait_for_modem_usb_active
@@ -146,14 +161,7 @@ function activate_lte {
   if [ -n "${IF_NAME}" ]; then
     ifconfig ${IF_NAME} up
     logger -t ltepi2 "The interface [${IF_NAME}] is up!"
-    # Registering a new id
-    modprobe usbserial vendor=0x1ecb product=0x0208
-    RET=$?
-    if [ "${RET}" != "0" ]; then
-      if [ -e "/sys/bus/usb-serial/drivers/pl2303" ]; then
-        echo "1ecb 0208" > /sys/bus/usb-serial/drivers/pl2303/new_id
-      fi
-    fi
+    register_usbserial
     look_for_serial_port
     wait_for_default_route
 

From 0742bafeea12946439c4cf1d45c70657a92a8d0e Mon Sep 17 00:00:00 2001
From: Daisuke Baba <baba.daisuke@gmail.com>
Date: Wed, 27 Jul 2016 14:49:15 +0900
Subject: [PATCH 3/5] Add ToC

---
 README.md | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index d6ac414..2b5750c 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,5 @@
-
+ltepi2-service
+===
 
 [![GitHub release](https://img.shields.io/github/release/CANDY-LINE/ltepi2-service.svg)](https://github.com/CANDY-LINE/ltepi2-service/releases/latest)
 [![License BSD3](https://img.shields.io/github/license/CANDY-LINE/ltepi2-service.svg)](http://opensource.org/licenses/BSD-3-Clause)
@@ -22,6 +23,19 @@ ltepi2-serviceは、Raspberry Pi上で動作する[LTEPi for D](http://www.candy
 以下のモジュールは、インストールの可否を選択可能です。 **通常はインストールされます。**
 - [CANDY RED](https://github.com/dbaba/candy-red) ... CANDY EGGクラウドサービスに接続可能なNode-REDベースのフローエディターです。Node.js v0.12またはv4.3が入っていない場合は、Node.js v0.12もインストールされます。すべてのインストールを終えるまでは、有線LAN環境で1~2時間以上かかる場合があります。
 
+# 目次
+
+1. [LTEPi for Dって何?](#ltepi-for-dって何)
+1. [対応ハードウェア](#対応ハードウェア)
+1. [対応OS](#対応OS)
+1. [準備するもの](#準備するもの)
+1. [バージョンアップ方法](#バージョンアップ方法)
+1. [インストール方法](#インストール方法)
+1. [アンインストール方法](#アンインストール方法)
+1. [設定](#設定)
+1. [LTEPi for D基板のGPIOピンマッピング](#ltepi-for-d基板のgpioピンマッピング)
+
+
 # [LTEPi for D](http://www.candy-line.io/test/proandsv.html#ltepiford)って何?
 Raspberry Pi B+やRaspberry Pi 2 Model Bに取り付けが可能なLTE通信モジュールを搭載した基板です。NTT DOCOMO及びNTT DOCOMOの回線を利用するMVNOのSIMを利用することができます。
 

From 4708ab432dfa6e9914e5e46a19ef9098ab8cdece Mon Sep 17 00:00:00 2001
From: Daisuke Baba <baba.daisuke@gmail.com>
Date: Wed, 27 Jul 2016 14:53:36 +0900
Subject: [PATCH 4/5] Bump version

---
 README.md  | 2 ++
 install.sh | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 2b5750c..db7176f 100644
--- a/README.md
+++ b/README.md
@@ -424,6 +424,8 @@ $ time sudo SRC_DIR=$(pwd) DEBUG=1 CANDY_RED=0 ./install.sh
 ```
 
 # 履歴
+* 1.0.2
+    - AMP520の初期設定にかかる所要時間を短縮
 * 1.0.1
     - AMP520において、自動接続モードがデフォルトで有効になるように修正
 * 1.0.0
diff --git a/install.sh b/install.sh
index 0bb53d1..6fcea77 100755
--- a/install.sh
+++ b/install.sh
@@ -4,7 +4,7 @@ VENDOR_HOME=/opt/candy-line
 
 SERVICE_NAME=ltepi2
 GITHUB_ID=CANDY-LINE/ltepi2-service
-VERSION=1.0.1
+VERSION=1.0.2
 
 NODEJS_VERSIONS="v0.12 v4.3"
 

From d6456a3329cc100e808a15edbf75eaf762301cfb Mon Sep 17 00:00:00 2001
From: Daisuke Baba <baba.daisuke@gmail.com>
Date: Wed, 27 Jul 2016 14:55:53 +0900
Subject: [PATCH 5/5] Bump up Node.js v4 version to latest

---
 README.md  | 2 +-
 install.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index db7176f..a64a4be 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ ltepi2-serviceは、Raspberry Pi上で動作する[LTEPi for D](http://www.candy
 - [candy-board-amt](https://github.com/CANDY-LINE/candy-board-amt) ... CANDY-LINE基板AM Telecomモデム向け共通モジュール
 
 以下のモジュールは、インストールの可否を選択可能です。 **通常はインストールされます。**
-- [CANDY RED](https://github.com/dbaba/candy-red) ... CANDY EGGクラウドサービスに接続可能なNode-REDベースのフローエディターです。Node.js v0.12またはv4.3が入っていない場合は、Node.js v0.12もインストールされます。すべてのインストールを終えるまでは、有線LAN環境で1~2時間以上かかる場合があります。
+- [CANDY RED](https://github.com/dbaba/candy-red) ... CANDY EGGクラウドサービスに接続可能なNode-REDベースのフローエディターです。Node.js v0.12またはv4.4が入っていない場合は、Node.js v0.12もインストールされます。すべてのインストールを終えるまでは、有線LAN環境で1~2時間以上かかる場合があります。
 
 # 目次
 
diff --git a/install.sh b/install.sh
index 6fcea77..bde5eb1 100755
--- a/install.sh
+++ b/install.sh
@@ -6,7 +6,7 @@ SERVICE_NAME=ltepi2
 GITHUB_ID=CANDY-LINE/ltepi2-service
 VERSION=1.0.2
 
-NODEJS_VERSIONS="v0.12 v4.3"
+NODEJS_VERSIONS="v0.12 v4.4"
 
 SERVICE_HOME=${VENDOR_HOME}/${SERVICE_NAME}
 SRC_DIR="${SRC_DIR:-/tmp/ltepi2-service-${VERSION}}"