Commit 62057b49 by onuma

計測1回ごとにBLEを切断する。長押しで接続する時に、一部の機種の為3000msのWaitを入れた。

parent ad32ff5f
...@@ -5,6 +5,7 @@ import android.bluetooth.BluetoothGattCharacteristic; ...@@ -5,6 +5,7 @@ import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor; import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService; import android.bluetooth.BluetoothGattService;
import android.content.Context; import android.content.Context;
import android.os.Handler;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -142,10 +143,13 @@ public class AlcoholCheckerUtil { ...@@ -142,10 +143,13 @@ public class AlcoholCheckerUtil {
public static final int fugo_wait_go = 3; public static final int fugo_wait_go = 3;
public static final int fugo_fu_error = 4; public static final int fugo_fu_error = 4;
public static final int fugo_restart = 5; public static final int fugo_restart = 5;
public static final int fugo_finish = 6;
private boolean isFirst = true;
// mutex // mutex
private Object lockObj = new Object(); private Object lockObj = new Object();
private Handler handler = new Handler();
public BleManagerUtilListener bleManagerUtilListener = new BleManagerUtilListener() { public BleManagerUtilListener bleManagerUtilListener = new BleManagerUtilListener() {
@Override @Override
...@@ -175,12 +179,12 @@ public class AlcoholCheckerUtil { ...@@ -175,12 +179,12 @@ public class AlcoholCheckerUtil {
} }
@Override @Override
public void onServicesDiscovered(int status) { public void onServicesDiscovered(BluetoothGatt gatt, int status) {
Logger.i(TAG,"onServicesDiscovered = %s", status); Logger.i(TAG,"onServicesDiscovered = %s", status);
if (status == BluetoothGatt.GATT_SUCCESS) { if (status == BluetoothGatt.GATT_SUCCESS) {
Logger.i(TAG,"BluetoothGatt.GATT_SUCCESS"); Logger.i(TAG,"BluetoothGatt.GATT_SUCCESS");
TaiyoYudenService = bleManagerUtil.mBluetoothGatt.getService(TY_SERVICE_UUID); TaiyoYudenService = gatt.getService(TY_SERVICE_UUID);
if (TaiyoYudenService == null) { if (TaiyoYudenService == null) {
Logger.e(TAG,"Not a TaiyoYuden device"); Logger.e(TAG,"Not a TaiyoYuden device");
} else { } else {
...@@ -190,14 +194,8 @@ public class AlcoholCheckerUtil { ...@@ -190,14 +194,8 @@ public class AlcoholCheckerUtil {
if (RxChar == null || TxChar == null) { if (RxChar == null || TxChar == null) {
Logger.e(TAG, "No Tx/Rx"); Logger.e(TAG, "No Tx/Rx");
} else { } else {
gi_status = F_BLE_COM_INIT; gatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
gi_rxlength = 0;
gf_result_flg = false;
gi_rxretry_cnt = 0;
BluetoothGatt gatt = bleManagerUtil.mBluetoothGatt;
TaiyoYudenService = gatt.getService(TY_SERVICE_UUID);
BatteryService = gatt.getService(BATTERY_SERVICE_UUID); BatteryService = gatt.getService(BATTERY_SERVICE_UUID);
NotificationChar = TaiyoYudenService.getCharacteristic(NOTIFICATION_CHARACTERISTIC_UUID); NotificationChar = TaiyoYudenService.getCharacteristic(NOTIFICATION_CHARACTERISTIC_UUID);
IndicationChar = TaiyoYudenService.getCharacteristic(INDICATION_CHARACTERISTIC_UUID); IndicationChar = TaiyoYudenService.getCharacteristic(INDICATION_CHARACTERISTIC_UUID);
...@@ -205,16 +203,22 @@ public class AlcoholCheckerUtil { ...@@ -205,16 +203,22 @@ public class AlcoholCheckerUtil {
batteryLevelChar = BatteryService.getCharacteristic(BATTERY_LEVEL_UUID); batteryLevelChar = BatteryService.getCharacteristic(BATTERY_LEVEL_UUID);
connectionPHY = 0; connectionPHY = 0;
bleManagerUtil.readPhyConnection(); //gatt.readPhy();
bleManagerUtil.mBluetoothGatt.setCharacteristicNotification(NotificationChar, true); gatt.setCharacteristicNotification(NotificationChar,true);
BluetoothGattDescriptor notification_descriptor = NotificationChar.getDescriptor(CCCD); BluetoothGattDescriptor notification_descriptor = NotificationChar.getDescriptor(CCCD);
notification_descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); notification_descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
bleManagerUtil.mBluetoothGatt.writeDescriptor(notification_descriptor); gatt.writeDescriptor(notification_descriptor);
//gi_status = F_BLE_COM_INIT;
bleManagerUtil.setBluetoothGatt(gatt);
gi_rxlength = 0;
gf_result_flg = false;
gi_rxretry_cnt = 0;
gi_status = F_BLE_COM_RP_START; gi_status = F_BLE_COM_RP_START;
SendMessageFromApp(gi_status); SendMessageFromCentral(gi_status);
listener.onServicesDiscovered(status); listener.onServicesDiscovered(status);
} }
...@@ -227,7 +231,7 @@ public class AlcoholCheckerUtil { ...@@ -227,7 +231,7 @@ public class AlcoholCheckerUtil {
@Override @Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
synchronized (lockObj) { synchronized (lockObj) {
Logger.d(TAG, "onCharacteristicChanged"); //Logger.d(TAG, "onCharacteristicChanged");
byte[] rx = characteristic.getValue(); byte[] rx = characteristic.getValue();
String rxStr = " "; String rxStr = " ";
...@@ -242,50 +246,26 @@ public class AlcoholCheckerUtil { ...@@ -242,50 +246,26 @@ public class AlcoholCheckerUtil {
@Override @Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
//Logger.d(TAG,"onDescriptorWrite"); UUID characteristic_uuid = descriptor.getCharacteristic().getUuid();
if (bleManagerUtil.mBluetoothGatt != null) {
if (bleManagerUtil.mBluetoothGatt.getService(TY_SERVICE_UUID).getCharacteristic(INDICATION_CHARACTERISTIC_UUID) == null) { if (gatt.getService(TY_SERVICE_UUID).getCharacteristic(INDICATION_CHARACTERISTIC_UUID) == null) {
Logger.d(TAG, "Old version"); Logger.e(TAG, "Old version");
// This version doesn't support latest characteristics // This version doesn't support latest characteristics
return;
}
} else {
return; return;
} }
gatt = bleManagerUtil.mBluetoothGatt;
TaiyoYudenService = gatt.getService(TY_SERVICE_UUID);
BatteryService = gatt.getService(BATTERY_SERVICE_UUID);
NotificationChar = TaiyoYudenService.getCharacteristic(NOTIFICATION_CHARACTERISTIC_UUID);
IndicationChar = TaiyoYudenService.getCharacteristic(INDICATION_CHARACTERISTIC_UUID);
WriteChar = TaiyoYudenService.getCharacteristic(WRITE_NO_RESPONSE_CHARACTERISTIC_UUID);
batteryLevelChar = BatteryService.getCharacteristic(BATTERY_LEVEL_UUID);
connectionPHY = 0;
bleManagerUtil.readPhyConnection();
bleManagerUtil.mBluetoothGatt.setCharacteristicNotification(NotificationChar, true);
BluetoothGattDescriptor notification_descriptor = NotificationChar.getDescriptor(CCCD);
notification_descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
bleManagerUtil.mBluetoothGatt.writeDescriptor(notification_descriptor);
if (characteristic_uuid.equals(NOTIFICATION_CHARACTERISTIC_UUID)) {
UUID characteristic_uuid = descriptor.getCharacteristic().getUuid();
if(characteristic_uuid.equals(NOTIFICATION_CHARACTERISTIC_UUID)){
if (IndicationChar == null) {
IndicationChar = TaiyoYudenService.getCharacteristic(INDICATION_CHARACTERISTIC_UUID);
}
gatt.setCharacteristicNotification(IndicationChar, true); gatt.setCharacteristicNotification(IndicationChar, true);
BluetoothGattDescriptor indication_descriptor = IndicationChar.getDescriptor(CCCD); BluetoothGattDescriptor indication_descriptor = IndicationChar.getDescriptor(CCCD);
indication_descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE); indication_descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
gatt.writeDescriptor(indication_descriptor); gatt.writeDescriptor(indication_descriptor);
} else if(characteristic_uuid.equals(INDICATION_CHARACTERISTIC_UUID)){ } else if (characteristic_uuid.equals(INDICATION_CHARACTERISTIC_UUID)) {
// Enable notification on receiving data
gatt.setCharacteristicNotification(batteryLevelChar, true); gatt.setCharacteristicNotification(batteryLevelChar, true);
notification_descriptor = batteryLevelChar.getDescriptor(CCCD); BluetoothGattDescriptor notification_descriptor = batteryLevelChar.getDescriptor(CCCD);
notification_descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); notification_descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
gatt.writeDescriptor(notification_descriptor); gatt.writeDescriptor(notification_descriptor);
} else if(characteristic_uuid.equals(BATTERY_LEVEL_UUID)){ } else if (characteristic_uuid.equals(BATTERY_LEVEL_UUID)) {
Logger.d(TAG, "Wrote descriptor: " + BATTERY_LEVEL_UUID); Logger.i(TAG, "Wrote descriptor: " + BATTERY_LEVEL_UUID);
} }
} }
}; };
...@@ -294,9 +274,11 @@ public class AlcoholCheckerUtil { ...@@ -294,9 +274,11 @@ public class AlcoholCheckerUtil {
this.context = context; this.context = context;
isConnected = false; isConnected = false;
this.listener = listener; this.listener = listener;
isFirst = true;
} }
public void finish() { public void finish() {
Logger.d(TAG,"finish");
isConnected = false; isConnected = false;
disconnect(); disconnect();
} }
...@@ -314,38 +296,59 @@ public class AlcoholCheckerUtil { ...@@ -314,38 +296,59 @@ public class AlcoholCheckerUtil {
return true; return true;
} }
// public int lastSendCmd; public void initAlcoholCheckerSettings(BluetoothGatt gatt) {
Logger.d(TAG,"initAlcoholCheckerSettings");
if (gatt != null) {
TaiyoYudenService = gatt.getService(TY_SERVICE_UUID);
BatteryService = gatt.getService(BATTERY_SERVICE_UUID);
NotificationChar = TaiyoYudenService.getCharacteristic(NOTIFICATION_CHARACTERISTIC_UUID);
IndicationChar = TaiyoYudenService.getCharacteristic(INDICATION_CHARACTERISTIC_UUID);
WriteChar = TaiyoYudenService.getCharacteristic(WRITE_NO_RESPONSE_CHARACTERISTIC_UUID);
batteryLevelChar = BatteryService.getCharacteristic(BATTERY_LEVEL_UUID);
connectionPHY = 0;
gatt.readPhy();
gatt.setCharacteristicNotification(NotificationChar,true);
BluetoothGattDescriptor notification_descriptor = NotificationChar.getDescriptor(CCCD);
notification_descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
gatt.writeDescriptor(notification_descriptor);
} else {
Logger.e(TAG,"initAlcoholCheckerSettings gatt is null");
}
}
public void SendMessageFromCentral(final int giStatus) {
Logger.d(TAG,"SendMessageFromCentral");
public void SendMessageFromApp(final int giStatus) {
synchronized (lockObj) { synchronized (lockObj) {
if (giStatus == F_BLE_COM_RP_START || giStatus == F_BLE_COM_RD_START || giStatus == F_BLE_COM_FC_START || giStatus == F_BLE_COM_FC_START22) { if (giStatus == F_BLE_COM_RP_START || giStatus == F_BLE_COM_RD_START || giStatus == F_BLE_COM_FC_START || giStatus == F_BLE_COM_FC_START22) {
Logger.d(TAG, "gi_status = " + giStatus); Logger.d(TAG, "gi_status = " + giStatus);
} else { } else {
Logger.w(TAG, "UNKOWN COMMAND"); Logger.w(TAG, "UNKOWN COMMAND");
} }
long delay = 1000;
if (isFirst) {
delay = 3000;
}
//lastSendCmd = giStatus; handler.postDelayed(new Runnable() {
Thread thread = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (giStatus == F_BLE_COM_RP_START) { if (giStatus == F_BLE_COM_RP_START) {
Logger.d(TAG,"F_BLE_COM_RP_START");
sendMessage(F_BLE_COM_RP_COMMAND); sendMessage(F_BLE_COM_RP_COMMAND);
} else if (giStatus == F_BLE_COM_RD_START) { } else if (giStatus == F_BLE_COM_RD_START) {
Logger.d(TAG,"F_BLE_COM_RD_START");
sendMessage(F_BLE_COM_RD_COMMAND); sendMessage(F_BLE_COM_RD_COMMAND);
} else if (giStatus == F_BLE_COM_FC_START) { } else if (giStatus == F_BLE_COM_FC_START) {
Logger.d(TAG,"F_BLE_COM_FC_START");
sendMessage(F_BLE_COM_FC_COMMAND_F11); sendMessage(F_BLE_COM_FC_COMMAND_F11);
} else if (giStatus == F_BLE_COM_FC_START22) { } else if (giStatus == F_BLE_COM_FC_START22) {
Logger.d(TAG,"F_BLE_COM_FC_START22");
sendMessage(F_BLE_COM_FC_COMMAND_F22); sendMessage(F_BLE_COM_FC_COMMAND_F22);
} }
} }
}); },delay);
thread.start();
} }
} }
...@@ -573,7 +576,7 @@ public class AlcoholCheckerUtil { ...@@ -573,7 +576,7 @@ public class AlcoholCheckerUtil {
} }
if (oldgiStatus != gi_status) { if (oldgiStatus != gi_status) {
Logger.i(TAG,"chageStatus:" + gi_status); Logger.i(TAG,"chageStatus:" + gi_status);
SendMessageFromApp(gi_status); SendMessageFromCentral(gi_status);
} }
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
Logger.e(TAG,e); Logger.e(TAG,e);
...@@ -715,7 +718,7 @@ public class AlcoholCheckerUtil { ...@@ -715,7 +718,7 @@ public class AlcoholCheckerUtil {
listener.onUpdateTBVCalc("Calculationg"); listener.onUpdateTBVCalc("Calculationg");
gf_result_flg = false; gf_result_flg = false;
si_ret = F_BLE_COM_RP_START; si_ret = F_BLE_COM_RP_START;
Logger.d(TAG, "ERROR 0x15 si_ret = F_BLE_COM_RP_START"); //Logger.d(TAG, "0x15 si_ret = F_BLE_COM_RP_START");
break; break;
case (byte) 0x1F: case (byte) 0x1F:
listener.onOverUsedError("Over Used"); listener.onOverUsedError("Over Used");
...@@ -761,6 +764,11 @@ public class AlcoholCheckerUtil { ...@@ -761,6 +764,11 @@ public class AlcoholCheckerUtil {
return si_ret; return si_ret;
} }
/**
* BLEに戻す場合のfc コマンドチェック
* @param rxdata コマンドのbyte配列
* @return 次回モード
*/
private int fn_rx_fc_chk(byte[] rxdata) { private int fn_rx_fc_chk(byte[] rxdata) {
Logger.d(TAG,"fn_rx_fc_chk"); Logger.d(TAG,"fn_rx_fc_chk");
int si_ret = F_BLE_COM_FC_WAIT; int si_ret = F_BLE_COM_FC_WAIT;
...@@ -780,9 +788,11 @@ public class AlcoholCheckerUtil { ...@@ -780,9 +788,11 @@ public class AlcoholCheckerUtil {
// //
if (fcWaitMode == 0) { if (fcWaitMode == 0) {
if (rxdata[0] == 1 && rxdata[1] == 102 && rxdata[2] == 99 && rxdata[3] == 3) { if (rxdata[0] == 1 && rxdata[1] == 102 && rxdata[2] == 99 && rxdata[3] == 3) {
// fcコマンド
fcWaitMode = 1; fcWaitMode = 1;
} }
if (rxdata[0] == 1 && rxdata[1] == 114 && rxdata[2] == 112 && rxdata[3] == 2) { if (rxdata[0] == 1 && rxdata[1] == 114 && rxdata[2] == 112 && rxdata[3] == 2) {
// RP上位が入ってくる場合があった
si_ret = F_BLE_COM_RP_WAIT; si_ret = F_BLE_COM_RP_WAIT;
return si_ret; return si_ret;
} }
...@@ -791,9 +801,9 @@ public class AlcoholCheckerUtil { ...@@ -791,9 +801,9 @@ public class AlcoholCheckerUtil {
// 49 05 32 35 4 // 49 05 32 35 4
// 0x31 05 20 23 4 実行完了 本体動作モード リアルタイム測定進行状況 チェックサム 4 // 0x31 05 20 23 4 実行完了 本体動作モード リアルタイム測定進行状況 チェックサム 4
if (rxdata[0] ==49 && rxdata[1] == 2) { // if (rxdata[0] ==49 && rxdata[1] == 2) {
//Logger.i(TAG, "------FC失敗"); // //Logger.i(TAG, "------FC失敗");
} // }
if(!StringUtil.isNullOrEmpty(strAlcoholValue)) { if(!StringUtil.isNullOrEmpty(strAlcoholValue)) {
// 測定値あれば成功 // 測定値あれば成功
...@@ -808,6 +818,11 @@ public class AlcoholCheckerUtil { ...@@ -808,6 +818,11 @@ public class AlcoholCheckerUtil {
} }
/**
* RDYに戻す場合のfc コマンドチェック
* @param rxdata コマンドのbyte配列
* @return 次回モード
*/
private int fn_rx_fc_chk2(byte[] rxdata) { private int fn_rx_fc_chk2(byte[] rxdata) {
Logger.d(TAG, "fn_rx_fc_chk2"); Logger.d(TAG, "fn_rx_fc_chk2");
for (byte b: rxdata) { for (byte b: rxdata) {
...@@ -816,6 +831,7 @@ public class AlcoholCheckerUtil { ...@@ -816,6 +831,7 @@ public class AlcoholCheckerUtil {
int si_ret = F_BLE_COM_FC_WAIT22; int si_ret = F_BLE_COM_FC_WAIT22;
if (fcWaitMode == 0) { if (fcWaitMode == 0) {
if (rxdata[0] == 1 && rxdata[1] == 102 && rxdata[2] == 99 && rxdata[3] == 3) { if (rxdata[0] == 1 && rxdata[1] == 102 && rxdata[2] == 99 && rxdata[3] == 3) {
// fcコマンド
fcWaitMode = 1; fcWaitMode = 1;
} }
} else if (fcWaitMode == 1) { } else if (fcWaitMode == 1) {
...@@ -893,7 +909,8 @@ public class AlcoholCheckerUtil { ...@@ -893,7 +909,8 @@ public class AlcoholCheckerUtil {
//str_msg += "[mg/L]"; //str_msg += "[mg/L]";
// 0x0C 測定結果表示状態"); // 0x0C 測定結果表示状態");
strAlcoholValue = str_msg; strAlcoholValue = str_msg;
si_ret = F_BLE_COM_FC_START22; // BLE に戻す
si_ret = F_BLE_COM_FC_START;
return si_ret; return si_ret;
} else { } else {
......
package jp.agentec.abook.abv.cl.util; package jp.agentec.abook.abv.cl.util;
import android.bluetooth.BluetoothGatt;
public interface AlcoholCheckerUtilListener { public interface AlcoholCheckerUtilListener {
void onConnectionError(int status); // ディバイス接続エラー void onConnectionError(int status); // ディバイス接続エラー
void onMeasurementError(String txt); // 吹付エラー void onMeasurementError(String txt); // 吹付エラー
......
...@@ -133,7 +133,7 @@ public class BleManagerUtil { ...@@ -133,7 +133,7 @@ public class BleManagerUtil {
// サービス検索が完了したときの処理(mBluetoothGatt.discoverServices()の結果として呼ばれる。) // サービス検索が完了したときの処理(mBluetoothGatt.discoverServices()の結果として呼ばれる。)
@Override @Override
public void onServicesDiscovered(BluetoothGatt gatt, final int status) { public void onServicesDiscovered(BluetoothGatt gatt, int status) {
try { try {
Logger.i(TAG, "onServicesDiscovered status = %s", status); Logger.i(TAG, "onServicesDiscovered status = %s", status);
...@@ -141,15 +141,14 @@ public class BleManagerUtil { ...@@ -141,15 +141,14 @@ public class BleManagerUtil {
return; return;
} }
//mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH); for (BluetoothGattService svc : gatt.getServices()){
if (mBluetoothGatt == null) { Logger.d(TAG, svc.getUuid().toString());
mBluetoothGatt = gatt;
} }
mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
//mBluetoothGatt = gatt;
//mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
if (mListener != null) { if (mListener != null) {
// アルコールチェッカー mListener.onServicesDiscovered(gatt, status);
mListener.onServicesDiscovered(status);
} }
} catch (Exception e) { } catch (Exception e) {
Logger.d(TAG,e); Logger.d(TAG,e);
...@@ -182,12 +181,8 @@ public class BleManagerUtil { ...@@ -182,12 +181,8 @@ public class BleManagerUtil {
@Override @Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status){ public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status){
Logger.d(TAG,"onDescriptorWrite"); Logger.d(TAG,"onDescriptorWrite");
try { if (mListener != null) {
if (mListener != null) { mListener.onDescriptorWrite(gatt, descriptor, status);
mListener.onDescriptorWrite(gatt, descriptor, status);
}
} catch ( Exception e) {
Logger.e(TAG,e);
} }
} }
}; };
...@@ -318,7 +313,9 @@ public class BleManagerUtil { ...@@ -318,7 +313,9 @@ public class BleManagerUtil {
// ②「接続可能範囲から外れた切断」は、内部処理でmBluetoothGatt.disconnect()処理が実施される。 // ②「接続可能範囲から外れた切断」は、内部処理でmBluetoothGatt.disconnect()処理が実施される。
// 切断時のコールバックでmBluetoothGatt.connect()を呼んでおくと、接続可能範囲に入ったら自動接続する。 // 切断時のコールバックでmBluetoothGatt.connect()を呼んでおくと、接続可能範囲に入ったら自動接続する。
mBluetoothGatt.disconnect(); mBluetoothGatt.disconnect();
mBluetoothGatt.close();
mBluetoothGatt = null; mBluetoothGatt = null;
mListener = null; mListener = null;
} }
...@@ -435,6 +432,13 @@ public class BleManagerUtil { ...@@ -435,6 +432,13 @@ public class BleManagerUtil {
return true; return true;
} }
public BluetoothGatt getBluetoothGatt() {
return mBluetoothGatt;
}
public void setBluetoothGatt(BluetoothGatt gatt) {
mBluetoothGatt = gatt;
}
/** /**
* リスナー設定 * リスナー設定
* @param listener リスナー * @param listener リスナー
......
...@@ -11,7 +11,7 @@ public interface BleManagerUtilListener { ...@@ -11,7 +11,7 @@ public interface BleManagerUtilListener {
void onDisConnectionState(); // ディバイスと切断時 void onDisConnectionState(); // ディバイスと切断時
void onConnectionError(int status); // ディバイス接続エラー void onConnectionError(int status); // ディバイス接続エラー
// アルコールチェッカーで追加 // アルコールチェッカーで追加
void onServicesDiscovered(int status); void onServicesDiscovered(BluetoothGatt gatt, int status);
void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic); void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic);
void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status); void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status);
} }
...@@ -95,7 +95,6 @@ import jp.agentec.adf.util.DateTimeUtil; ...@@ -95,7 +95,6 @@ import jp.agentec.adf.util.DateTimeUtil;
import jp.agentec.adf.util.FileUtil; import jp.agentec.adf.util.FileUtil;
import jp.agentec.adf.util.StringUtil; import jp.agentec.adf.util.StringUtil;
import static java.lang.Thread.sleep;
import static jp.agentec.abook.abv.bl.common.Constant.ReportType.RoutineTask; import static jp.agentec.abook.abv.bl.common.Constant.ReportType.RoutineTask;
...@@ -183,15 +182,10 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -183,15 +182,10 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
private int mDeviceType; private int mDeviceType;
// 設問ID // 設問ID
private String mQid = ""; private String mQid = "";
// アルコールチェッカー二重初期化防止フラグ
private boolean isInitAlcChecker = false;
private boolean isInitBLE = false;
// 二重起動防止フラグ(アルコールチェッカー) // 二重起動防止フラグ(アルコールチェッカー)
private boolean isAlcBlock = false; private boolean isAlcBlock = false;
// ステータス // ステータス
private int checkerStatus = AlcoholCheckerUtil.fugo_init; private int checkerStatus = AlcoholCheckerUtil.fugo_init;
// BLE接続中にonStopしたら、再接続からやりなおし
//private boolean isReconnect = false;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -263,11 +257,67 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -263,11 +257,67 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
contentDownloader.pauseAll(); contentDownloader.pauseAll();
showUpdateContentAlert(contentId); showUpdateContentAlert(contentId);
}
/**
* 各デバイスから値を正常に取得された場合、HTML側にコールする
* @param value 各種デバイスから取得した値
*/
private void successAfterAbookCheckApi(final String value, boolean isFinish) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dismissAllDialog();
JSONObject responseJson = new JSONObject();
responseJson.put(ABookKeys.TASK_QUESTION_ID, mQid);
responseJson.put("value", value);
afterABookCheckApi(mCmd, "", 0, "", responseJson.toString());
Logger.i(TAG, "successAfterAbookCheckAip JSON [%s]", responseJson.toString());
isAlcBlock = false;
handler.postDelayed(new Runnable() {
@Override
public void run() {
alcoholCheckerUtil.finish();
}
},2000);
}
});
}
isInitAlcChecker = false; /**
isInitBLE = false; * 各デバイスからエラー(接続不能など)発生した場合、HTML側にコールする
* @param errorMessage 各種デバイスから取得した値
*/
private void errorAfterAbookCheckApi(final String errorMessage, final boolean isSendResult) {
// エラーの時は終了
runOnUiThread(new Runnable() {
@Override
public void run() {
dismissAllDialog();
if (AlcoholCheckerUtil.isConnected) {
// BLE接続中であれば、BLE表示に戻す
alcoholCheckerUtil.SendMessageFromCentral(AlcoholCheckerUtil.F_BLE_COM_FC_START);
}
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (isSendResult) {
afterABookCheckApi(mCmd, "", 1, errorMessage, null);
}
if(alcoholCheckerUtil != null) {
alcoholCheckerUtil.finish();
alcoholCheckerUtil = null;
}
Logger.e(TAG,errorMessage);
isAlcBlock = false;
}
}, 2000);
}
});
} }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// アルコールチェッカーここから
/** /**
* アルコールチェッカー、ユーティリティ初期化 * アルコールチェッカー、ユーティリティ初期化
*/ */
...@@ -311,6 +361,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -311,6 +361,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
public void run() { public void run() {
Logger.d(TAG, "測定完了 = " + alcohol); Logger.d(TAG, "測定完了 = " + alcohol);
if (!alcohol.equals("")) { if (!alcohol.equals("")) {
checkerStatus = AlcoholCheckerUtil.fugo_finish;
successAfterAbookCheckApi(alcohol, false); successAfterAbookCheckApi(alcohol, false);
} else { } else {
...@@ -351,21 +402,6 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -351,21 +402,6 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
} }
@Override @Override
public void onConnectionError(int status) {
Logger.d(TAG,"onConnectionError = " + status);
String message = "";
if (status == 133 || status == 8) {
message = getString(R.string.msg_connection_timeout); // デバイスと接続されていない
} else if (status == 19) {
message = getString(R.string.msg_disconnected_device);
}
if (alcoholCheckerUtil != null) {
alcoholCheckerUtil.isConnected = false;
}
errorAfterAbookCheckApi(message,true);
}
@Override
public void onMeasurementError(String text) { public void onMeasurementError(String text) {
Logger.d(TAG,"onMeasurementError = " + text); Logger.d(TAG,"onMeasurementError = " + text);
if (mMeasureDialog != null) { if (mMeasureDialog != null) {
...@@ -380,6 +416,26 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -380,6 +416,26 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
} }
@Override @Override
public void onConnectionError(int status) {
Logger.d(TAG,"onConnectionError = " + status);
if (checkerStatus == AlcoholCheckerUtil.fugo_finish) {
Logger.d(TAG,"fugo_finish.");
return;
}
checkerStatus = AlcoholCheckerUtil.fugo_finish;
String message = getString(R.string.msg_disconnected_device);
if (status == 133 || status == 8) {
message = getString(R.string.msg_connection_timeout); // デバイスと接続されていない
} else if (status == 19) {
message = getString(R.string.msg_disconnected_device);
}
if (alcoholCheckerUtil != null) {
alcoholCheckerUtil.isConnected = false;
}
errorAfterAbookCheckApi(message,true);
}
@Override
public void onBreakDownError(String text) { public void onBreakDownError(String text) {
errorAfterAbookCheckApi(getString(R.string.msg_break_down_device),true); errorAfterAbookCheckApi(getString(R.string.msg_break_down_device),true);
} }
...@@ -424,53 +480,6 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -424,53 +480,6 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
} }
/** /**
* 各デバイスから値を正常に取得された場合、HTML側にコールする
* @param value 各種デバイスから取得した値
*/
private void successAfterAbookCheckApi(final String value, boolean isFinish) {
runOnUiThread(new Runnable() {
@Override
public void run() {
dismissAllDialog();
JSONObject responseJson = new JSONObject();
responseJson.put(ABookKeys.TASK_QUESTION_ID, mQid);
responseJson.put("value", value);
afterABookCheckApi(mCmd, "", 0, "", responseJson.toString());
Logger.i(TAG, "successAfterAbookCheckAip JSON [%s]", responseJson.toString());
isAlcBlock = false;
}
});
}
/**
* 各デバイスからエラー(接続不能など)発生した場合、HTML側にコールする
* @param errorMessage 各種デバイスから取得した値
*/
private void errorAfterAbookCheckApi(final String errorMessage, final boolean isSendResult) {
// エラーの時は終了
runOnUiThread(new Runnable() {
@Override
public void run() {
dismissAllDialog();
if (AlcoholCheckerUtil.isConnected) {
alcoholCheckerUtil.SendMessageFromApp(AlcoholCheckerUtil.F_BLE_COM_FC_START);
}
if (isSendResult) {
afterABookCheckApi(mCmd, "", 1, errorMessage, null);
}
if(alcoholCheckerUtil != null) {
alcoholCheckerUtil.finish();
alcoholCheckerUtil = null;
}
isInitAlcChecker = false;
isInitBLE = false;
Logger.e(TAG,errorMessage);
isAlcBlock = false;
}
});
}
/**
* 接続待ち * 接続待ち
* @param title タイトル * @param title タイトル
* @param message 内容 * @param message 内容
...@@ -483,9 +492,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -483,9 +492,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Logger.i(TAG, "waiting Dialog stop click"); Logger.i(TAG, "waiting Dialog stop click");
//AlcoholCheckerUtil.isConnected = false;
errorAfterAbookCheckApi("", false); errorAfterAbookCheckApi("", false);
//alcoholCheckerUtil.disconnect();
} }
}); });
mWaitingDialog.show(); mWaitingDialog.show();
...@@ -503,10 +510,8 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -503,10 +510,8 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
mWaitMeasureDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.cancel), new DialogInterface.OnClickListener() { mWaitMeasureDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Logger.i(TAG, "waiting mWaitMeasureDialog stop clickf"); Logger.i(TAG, "waiting mWaitMeasureDialog stop click");
//AlcoholCheckerUtil.isConnected = false;
errorAfterAbookCheckApi("", false); errorAfterAbookCheckApi("", false);
//alcoholCheckerUtil.disconnect();
} }
}); });
mWaitMeasureDialog.show(); mWaitMeasureDialog.show();
...@@ -525,9 +530,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -525,9 +530,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Logger.i(TAG, "wait mMeasureDialog stop click"); Logger.i(TAG, "wait mMeasureDialog stop click");
//AlcoholCheckerUtil.isConnected = false;
errorAfterAbookCheckApi("", false); errorAfterAbookCheckApi("", false);
//alcoholCheckerUtil.disconnect();
} }
}); });
mMeasureDialog.show(); mMeasureDialog.show();
...@@ -544,42 +547,20 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -544,42 +547,20 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
mDeviceType = Integer.parseInt(abookCheckParam.get(ABookKeys.TASK_DEVICE_TYPE)); mDeviceType = Integer.parseInt(abookCheckParam.get(ABookKeys.TASK_DEVICE_TYPE));
mQid = abookCheckParam.get(ABookKeys.TASK_QUESTION_ID); mQid = abookCheckParam.get(ABookKeys.TASK_QUESTION_ID);
if (!isInitAlcChecker) { // アルコールチェッカー初期化
// アルコールチェッカー初期化 initAlcoholCheckerUtil();
initAlcoholCheckerUtil();
}
if (isInitBLE == false) { if (!alcoholCheckerUtil.startGetDeviceInfo()) {
if (!alcoholCheckerUtil.startGetDeviceInfo()) { // 端末がBluetoothをサポートしていないなどの理由で、アルコールチェッカーが使えない
// 端末がBluetoothをサポートしていないなどの理由で、アルコールチェッカーが使えない Logger.e(TAG, "bluetooth not support.");
Logger.e(TAG, "bluetooth not support."); afterABookCheckApi(mCmd, "", 1, getString(R.string.bluetooth_is_not_supported), null);
afterABookCheckApi(mCmd, "", 1, getString(R.string.bluetooth_is_not_supported), null); return;
return;
} else {
isInitBLE = true;
}
} }
alcoholCheckerUtil.bleManagerUtil.setListener(alcoholCheckerUtil.bleManagerUtilListener); alcoholCheckerUtil.bleManagerUtil.setListener(alcoholCheckerUtil.bleManagerUtilListener);
if (!isInitAlcChecker) { checkerStatus = AlcoholCheckerUtil.fugo_init;
// アルコールチェッカー接続 // アルコールチェッカー接続
connectToAlcholChecker(); startAlcholChecker();
isInitAlcChecker = true;
} else {
BluetoothPairingDeviceInfoDto dto = getABVUIDataCache().getPairingBluetoothDeviceInfo(Constant.DeviceType.alcoholChecker);
checkerStatus = AlcoholCheckerUtil.fugo_wait_connect;
if (AlcoholCheckerUtil.isConnected) {
Logger.d(TAG, "isConnection = true");
checkerStatus = AlcoholCheckerUtil.fugo_conntected;
showWaitMeasureDialog(getString(R.string.alcohol_checker), getString(R.string.connection_completed));
} else {
Logger.d(TAG, "isConnection = false");
// 登録されているアルコールチェッカーがある
String message = String.format(getString(R.string.ble_connecting), dto.deviceName);
showWaitingDialog(getString(R.string.alcohol_checker), message);
// 接続まち
alcoholCheckerUtil.connect(Constant.DeviceType.alcoholChecker, dto.deviceAddress);
}
}
} }
/** /**
...@@ -599,7 +580,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -599,7 +580,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
/** /**
* BLEディバイスのアルコールチェッカーの情報取得 * BLEディバイスのアルコールチェッカーの情報取得
*/ */
private void connectToAlcholChecker() { private void startAlcholChecker() {
if (requestBluetoothFeature(REQUEST_CODE_ENABLEBLUETOOTH_ALCOHL_CHECKER)) { //端末のBluetooth設定を確認 if (requestBluetoothFeature(REQUEST_CODE_ENABLEBLUETOOTH_ALCOHL_CHECKER)) { //端末のBluetooth設定を確認
String deviceAddress = getABVUIDataCache().getPairingBluetoothDeviceAddress(Constant.DeviceType.alcoholChecker); String deviceAddress = getABVUIDataCache().getPairingBluetoothDeviceAddress(Constant.DeviceType.alcoholChecker);
...@@ -610,11 +591,12 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -610,11 +591,12 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
} }
BluetoothPairingDeviceInfoDto dto = getABVUIDataCache().getPairingBluetoothDeviceInfo(Constant.DeviceType.alcoholChecker); BluetoothPairingDeviceInfoDto dto = getABVUIDataCache().getPairingBluetoothDeviceInfo(Constant.DeviceType.alcoholChecker);
checkerStatus = AlcoholCheckerUtil.fugo_wait_connect; checkerStatus = AlcoholCheckerUtil.fugo_wait_connect;
if (AlcoholCheckerUtil.isConnected) { // if (AlcoholCheckerUtil.isConnected) {
Logger.d(TAG, "isConnection = true"); // Logger.d(TAG, "isConnection = true");
checkerStatus = AlcoholCheckerUtil.fugo_conntected; // checkerStatus = AlcoholCheckerUtil.fugo_conntected;
showWaitMeasureDialog(getString(R.string.alcohol_checker), getString(R.string.connection_completed)); // showWaitMeasureDialog(getString(R.string.alcohol_checker), getString(R.string.connection_completed));
} else { // } else
{
Logger.d(TAG, "isConnection = false"); Logger.d(TAG, "isConnection = false");
// 登録されているアルコールチェッカーがある // 登録されているアルコールチェッカーがある
String message = String.format(getString(R.string.ble_connecting), dto.deviceName); String message = String.format(getString(R.string.ble_connecting), dto.deviceName);
...@@ -625,6 +607,9 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -625,6 +607,9 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
} }
} }
// アルコールチェッカーここまで
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private void showUpdateContentAlert(long contentId) { private void showUpdateContentAlert(long contentId) {
if (meetingManager.isConnected()) { if (meetingManager.isConnected()) {
ContentDto contentDto = contentDao.getContent(contentId); ContentDto contentDto = contentDao.getContent(contentId);
...@@ -684,7 +669,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -684,7 +669,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
protected void onPause() { protected void onPause() {
super.onPause(); super.onPause();
Logger.i(TAG,"onPause"); Logger.i(TAG,"onPause");
if (mCmd.equals(ABookKeys.CMD_GET_DEVICE_INFO)) { if (mCmd != null && mCmd.equals(ABookKeys.CMD_GET_DEVICE_INFO)) {
errorAfterAbookCheckApi("", false); errorAfterAbookCheckApi("", false);
} }
} }
...@@ -2005,7 +1990,5 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -2005,7 +1990,5 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
alcoholCheckerUtil.finish(); alcoholCheckerUtil.finish();
alcoholCheckerUtil = null; alcoholCheckerUtil = null;
} }
isInitAlcChecker = false;
isInitBLE = false;
} }
} }
\ No newline at end of file
...@@ -3,17 +3,12 @@ package jp.agentec.abook.abv.ui.home.activity; ...@@ -3,17 +3,12 @@ package jp.agentec.abook.abv.ui.home.activity;
import android.app.Activity; import android.app.Activity;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothManager; import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.le.BluetoothLeScanner; import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback; import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanResult; import android.bluetooth.le.ScanResult;
import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.location.LocationManager; import android.location.LocationManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
...@@ -24,7 +19,6 @@ import android.widget.AdapterView; ...@@ -24,7 +19,6 @@ import android.widget.AdapterView;
import android.widget.Button; import android.widget.Button;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
...@@ -32,10 +26,8 @@ import java.util.List; ...@@ -32,10 +26,8 @@ import java.util.List;
import jp.agentec.abook.abv.bl.common.Constant; import jp.agentec.abook.abv.bl.common.Constant;
import jp.agentec.abook.abv.bl.common.Constant.DeviceType; import jp.agentec.abook.abv.bl.common.Constant.DeviceType;
import jp.agentec.abook.abv.bl.common.constant.ABookKeys;
import jp.agentec.abook.abv.bl.common.log.Logger; import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.bl.dto.BluetoothPairingDeviceInfoDto; import jp.agentec.abook.abv.bl.dto.BluetoothPairingDeviceInfoDto;
import jp.agentec.abook.abv.cl.util.AlcoholCheckerUtil;
import jp.agentec.abook.abv.cl.util.BleManagerUtil; import jp.agentec.abook.abv.cl.util.BleManagerUtil;
import jp.agentec.abook.abv.launcher.android.R; import jp.agentec.abook.abv.launcher.android.R;
import jp.agentec.abook.abv.ui.common.activity.ABVUIActivity; import jp.agentec.abook.abv.ui.common.activity.ABVUIActivity;
...@@ -45,8 +37,6 @@ import jp.agentec.abook.abv.ui.home.adapter.common.SectionHeaderData; ...@@ -45,8 +37,6 @@ import jp.agentec.abook.abv.ui.home.adapter.common.SectionHeaderData;
import jp.agentec.abook.abv.ui.home.helper.ABookPermissionHelper; import jp.agentec.abook.abv.ui.home.helper.ABookPermissionHelper;
import jp.agentec.adf.util.CollectionUtil; import jp.agentec.adf.util.CollectionUtil;
import static android.bluetooth.BluetoothDevice.TRANSPORT_LE;
public class BlePairingSettingActivity extends ABVUIActivity { public class BlePairingSettingActivity extends ABVUIActivity {
private static final String TAG = "BlePairingSettingActivity"; private static final String TAG = "BlePairingSettingActivity";
...@@ -160,6 +150,7 @@ public class BlePairingSettingActivity extends ABVUIActivity { ...@@ -160,6 +150,7 @@ public class BlePairingSettingActivity extends ABVUIActivity {
public void onItemClick(AdapterView<?> parent, View view, int position, public void onItemClick(AdapterView<?> parent, View view, int position,
long id) { long id) {
Logger.d(TAG, "position = " + position); Logger.d(TAG, "position = " + position);
stopScan();
BleListRowData bleListRowData = (BleListRowData)parent.getItemAtPosition(position); BleListRowData bleListRowData = (BleListRowData)parent.getItemAtPosition(position);
// 既に保存されてる場合は何もしない // 既に保存されてる場合は何もしない
if (!bleListRowData.isSaved) { if (!bleListRowData.isSaved) {
...@@ -239,7 +230,7 @@ public class BlePairingSettingActivity extends ABVUIActivity { ...@@ -239,7 +230,7 @@ public class BlePairingSettingActivity extends ABVUIActivity {
//端末側の位置情報許可チェック //端末側の位置情報許可チェック
if (!(gpsEnabled || secureLocationGpsEnabled)) { if (!(gpsEnabled || secureLocationGpsEnabled)) {
//showSimpleAlertDialog(R.string.chino_machine, R.string.msg_location_device_no_allow); showSimpleAlertDialog(R.string.alcohol_checker, R.string.msg_location_device_no_allow);
return; return;
} }
...@@ -429,29 +420,8 @@ public class BlePairingSettingActivity extends ABVUIActivity { ...@@ -429,29 +420,8 @@ public class BlePairingSettingActivity extends ABVUIActivity {
return false; return false;
} }
////////////////////////////////////////////////////////////////////////
private BluetoothGatt bluetoothGatt = null;
private BluetoothAdapter bluetoothAdapter = null; private BluetoothAdapter bluetoothAdapter = null;
//private BluetoothDevice device = null;
@Override
protected void onDestroy() {
super.onDestroy();
//unregisterReceiver(PairingRequest);
if(bluetoothGatt != null) {
bluetoothGatt.close();
bluetoothGatt = null;
}
}
BroadcastReceiver PairingRequest = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
Logger.d(TAG,"PEAR");
}
}
};
private void PairingDevice(String deviceAddress) { private void PairingDevice(String deviceAddress) {
BluetoothManager bleMgr = (BluetoothManager) this.getSystemService( Context.BLUETOOTH_SERVICE ); BluetoothManager bleMgr = (BluetoothManager) this.getSystemService( Context.BLUETOOTH_SERVICE );
...@@ -462,39 +432,6 @@ public class BlePairingSettingActivity extends ABVUIActivity { ...@@ -462,39 +432,6 @@ public class BlePairingSettingActivity extends ABVUIActivity {
} }
} }
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(deviceAddress); BluetoothDevice device = bluetoothAdapter.getRemoteDevice(deviceAddress);
//bluetoothGatt = device.connectGatt(this, false, gattcallback, TRANSPORT_LE);
device.createBond(); device.createBond();
//IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
//registerReceiver(PairingRequest, filter);
} }
private final BluetoothGattCallback gattcallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
super.onConnectionStateChange(gatt, status, newState);
if (newState == BluetoothProfile.STATE_CONNECTED) {
//
Logger.d(TAG, "STATE_CONNECTED");
gatt.discoverServices();
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
//
Logger.d(TAG, "STATE_DISCONNECTED");
if (bluetoothGatt != null) {
bluetoothGatt.close();
bluetoothGatt = null;
}
}
}
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
super.onServicesDiscovered(gatt, status);
if (status == BluetoothGatt.GATT_SUCCESS) {
bluetoothGatt = gatt;
Logger.d(TAG,"BluetoothGatt.GATT_SUCCESS");
}
}
};
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment