Commit 97554d16 by onuma

2回目計測可能。キャンセル時は必ず切断するように修正した。

parent 25e12974
......@@ -130,11 +130,8 @@ public class AlcoholCheckerUtil {
private Context context;
public BleManagerUtil bleManagerUtil;
private AlcoholCheckerUtilListener listener;
// @Timer
//private AlcoholCheckerTimerTask alcoholCheckerTimerTask = null;
public static boolean isConnected = false;
// アルコール濃度
private String strAlcoholValue = "";
......@@ -145,7 +142,9 @@ public class AlcoholCheckerUtil {
public static final int fugo_wait_go = 3;
public static final int fugo_fu_error = 4;
public static final int fugo_restart = 5;
//public int alcStatus = 0;
// mutex
private Object lockObj = new Object();
public AlcoholCheckerUtil(Context context, AlcoholCheckerUtilListener listener) {
this.context = context;
......@@ -155,15 +154,27 @@ public class AlcoholCheckerUtil {
public void finish() {
isConnected = false;
disconnect(true);
disconnect();
}
// Bluetoothアダプタの取得処理
public boolean startGetDeviceInfo() {
// BLE管理
bleManagerUtil = new BleManagerUtil(context, new BleManagerUtilListener() {
@Override
public void onGetDeviceInfoFailed(int status) {
}
@Override
public void onGetDeviceInfo(String strTemperature) {
}
@Override
public void onConnectionState(int status) {
// Logger.i(TAG,"-------------------------------------------------------------- = %s", status);
// Logger.i(TAG,"onConnectionState = %s", status);
......@@ -249,13 +260,9 @@ public class AlcoholCheckerUtil {
gi_status = F_BLE_COM_RP_START;
//startAlcTimer();
SendMessageFromApp(gi_status);
listener.onServicesDiscovered(status);
//Logger.i(TAG,"iiiiiiiiiiiiiiiiiiiiiii");
}
}
} else {
......@@ -265,16 +272,18 @@ public class AlcoholCheckerUtil {
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
//Logger.d(TAG,"onCharacteristicChanged");
byte[] rx = characteristic.getValue();
String rxStr = " ";
if (rx != null && rx.length > 0) {
for ( byte rx1 : rx) {
rxStr += rx1 + " ,";
synchronized (lockObj) {
Logger.d(TAG, "onCharacteristicChanged");
byte[] rx = characteristic.getValue();
String rxStr = " ";
if (rx != null && rx.length > 0) {
for (byte rx1 : rx) {
rxStr += rx1 + " ,";
}
}
sub_rx_chk(rx);
}
sub_rx_chk(rx);
}
@Override
......@@ -337,34 +346,36 @@ public class AlcoholCheckerUtil {
// public int lastSendCmd;
public void SendMessageFromApp(final int giStatus) {
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, "giStatus = " + giStatus);
} else {
Logger.w(TAG,"UNKOWN COMMAND");
}
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) {
Logger.d(TAG, "gi_status = " + giStatus);
} else {
Logger.w(TAG, "UNKOWN COMMAND");
}
//lastSendCmd = giStatus;
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//lastSendCmd = giStatus;
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (giStatus == F_BLE_COM_RP_START) {
sendMessage(F_BLE_COM_RP_COMMAND);
} else if (giStatus == F_BLE_COM_RD_START) {
sendMessage(F_BLE_COM_RD_COMMAND);
} else if (giStatus == F_BLE_COM_FC_START) {
sendMessage(F_BLE_COM_FC_COMMAND_F11);
} else if (giStatus == F_BLE_COM_FC_START22) {
sendMessage(F_BLE_COM_FC_COMMAND_F22);
if (giStatus == F_BLE_COM_RP_START) {
sendMessage(F_BLE_COM_RP_COMMAND);
} else if (giStatus == F_BLE_COM_RD_START) {
sendMessage(F_BLE_COM_RD_COMMAND);
} else if (giStatus == F_BLE_COM_FC_START) {
sendMessage(F_BLE_COM_FC_COMMAND_F11);
} else if (giStatus == F_BLE_COM_FC_START22) {
sendMessage(F_BLE_COM_FC_COMMAND_F22);
}
}
}
});
thread.start();
});
thread.start();
}
}
public void connect(int connectTargetDeviceType, String deviceAddress) {
......@@ -372,9 +383,9 @@ public class AlcoholCheckerUtil {
}
// 切断
public void disconnect(boolean listenerFlg) {
public void disconnect() {
isConnected = false;
bleManagerUtil.disconnect(listenerFlg);
bleManagerUtil.disconnect();
}
......@@ -672,6 +683,7 @@ public class AlcoholCheckerUtil {
si_ret = F_BLE_COM_RP_START;
break;
case (byte) 0x0A:
// 計測
listener.onUpdateTBVCalc("Go");
// Blow
gf_result_flg = false;
......@@ -815,6 +827,7 @@ public class AlcoholCheckerUtil {
if(!StringUtil.isNullOrEmpty(strAlcoholValue)) {
// 測定値あれば成功
listener.onGetDeviceInfo(strAlcoholValue);
strAlcoholValue = "";
}
fcWaitMode = 0;
si_ret = F_BLE_COM_RP_START;
......@@ -848,6 +861,7 @@ public class AlcoholCheckerUtil {
if (!StringUtil.isNullOrEmpty(strAlcoholValue)) {
// 測定値あれば成功
listener.onGetDeviceInfo(strAlcoholValue);
strAlcoholValue = "";
}
fcWaitMode = 0;
si_ret = F_BLE_COM_RP_START;
......
......@@ -12,11 +12,9 @@ import android.bluetooth.BluetoothProfile;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanResult;
import android.content.Context;
import android.graphics.RenderNode;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
......@@ -24,7 +22,6 @@ import java.nio.ByteOrder;
import java.util.UUID;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.launcher.android.R;
import jp.agentec.adf.util.StringUtil;
import static android.bluetooth.BluetoothDevice.TRANSPORT_LE;
......@@ -76,13 +73,6 @@ public class BleManagerUtil {
Logger.e(TAG,"onConnectionStateChange status = " + status);
}
});
// runOnUiThread(new Runnable() {
// @Override
// public void run() {
// //mBluetoothGatt = device.connectGatt(mContext, false, mGattcallback, TRANSPORT_LE);
// bleGattReconnect();
// }
// });
return;
}
......@@ -105,7 +95,9 @@ public class BleManagerUtil {
runOnUiThread( new Runnable() { // 接続失敗
@Override
public void run() {
//mListener.onGetDeviceInfoFailed(status);
if (mListener != null) {
mListener.onGetDeviceInfoFailed(status);
}
Logger.e("onConnectionStateChange status = " + status);
}
});
......@@ -116,10 +108,12 @@ public class BleManagerUtil {
}
if( BluetoothProfile.STATE_DISCONNECTED == newState ) { // 切断完了(接続可能範囲から外れて切断された)
Logger.e(TAG,"out of range");
Logger.w(TAG,"BluetoothProfile.STATE_DISCONNECTED");
//Logger.e(TAG,"out of range");
// 切断が発生する場合、Bluetoothと接続を切断する。
disconnect(true);
return;
if (mListener != null) {
mListener.onConnectionError(status);
}
}
}
......@@ -133,10 +127,13 @@ public class BleManagerUtil {
return;
}
//mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
if (mBluetoothGatt == null) {
mBluetoothGatt = gatt;
}
mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
if (mListener != null)
{
if (mListener != null) {
// アルコールチェッカー
mListener.onServicesDiscovered(status);
}
......@@ -163,26 +160,18 @@ public class BleManagerUtil {
@Override
public void onCharacteristicChanged(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic ) {
Logger.d(TAG,"onCharacteristicChanged");
mListener.onCharacteristicChanged(gatt, characteristic);
// runOnUiThread(new Runnable() {
// @Override
// public void run() {
// try {
// if (mListener != null) {
// mListener.onCharacteristicChanged(gatt, characteristic);
// }
// } catch (Exception e) {
// Logger.e(TAG,e);
// }
// }
// });
if (mListener != null) {
mListener.onCharacteristicChanged(gatt, characteristic);
}
}
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status){
Logger.d(TAG,"onDescriptorWrite");
try {
mListener.onDescriptorWrite(gatt, descriptor, status);
if (mListener != null) {
mListener.onDescriptorWrite(gatt, descriptor, status);
}
} catch ( Exception e) {
Logger.e(TAG,e);
}
......@@ -223,7 +212,9 @@ public class BleManagerUtil {
runOnUiThread( new Runnable() {
@Override
public void run() {
mListener.onConnectionError(errorCode);
if (mListener != null) {
mListener.onConnectionError(errorCode);
}
}
});
}
......@@ -300,7 +291,7 @@ public class BleManagerUtil {
}
// 切断
public void disconnect(boolean listenerFlg) {
public void disconnect() {
if(mBluetoothGatt == null) {
return;
......@@ -397,7 +388,7 @@ public class BleManagerUtil {
* 再接続処理
*/
private void bleGattReconnect() {
disconnect(false);
disconnect();
connect(mBleConnectDeviceType, mDeviceAddress);
}
......
......@@ -5,9 +5,12 @@ import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
public interface BleManagerUtilListener {
void onConnectionState(int status); // ディバイスと接続された時情報渡す。
void onDisConnectionState(); // ディバイスと切断時
void onConnectionError(int status); // ディバイス接続エラー
void onGetDeviceInfo(String strTemperature); // ディバイスから渡す情報
void onGetDeviceInfoFailed(int status); // ディバイスと接続失敗時の情報渡す。
void onConnectionState(int status); // ディバイスと接続された時情報渡す。
void onDisConnectionState(); // ディバイスと切断時
void onConnectionError(int status); // ディバイス接続エラー
// アルコールチェッカーで追加
void onServicesDiscovered(int status);
void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic);
void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status);
......
......@@ -66,7 +66,6 @@ import jp.agentec.abook.abv.cl.helper.ContentMarkingFileHelper;
import jp.agentec.abook.abv.cl.util.AlcoholCheckerUtil;
import jp.agentec.abook.abv.cl.util.AlcoholCheckerUtilListener;
import jp.agentec.abook.abv.cl.util.AndroidStringUtil;
import jp.agentec.abook.abv.cl.util.BleManagerUtil;
import jp.agentec.abook.abv.cl.util.ContentLogUtil;
import jp.agentec.abook.abv.cl.util.LocationManagerUtil;
import jp.agentec.abook.abv.cl.util.PreferenceUtil;
......@@ -184,13 +183,15 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
private int mDeviceType;
// 設問ID
private String mQid = "";
// アルコールチェッカー二重初期化防止フラグ
private boolean isInitAlcChecker = false;
private boolean isInitBLE = false;
// 二重起動防止フラグ(アルコールチェッカー)
private boolean isAlcBlock = false;
// 終了フラグ
//private boolean isFinish = false;
// ステータス
private int checkerStatus = AlcoholCheckerUtil.fugo_init;
// BLE接続中にonStopしたら、再接続からやりなおし
//private boolean isReconnect = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -262,12 +263,20 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
contentDownloader.pauseAll();
showUpdateContentAlert(contentId);
isInitAlcChecker = false;
isInitBLE = false;
}
/**
* アルコールチェッカー、ユーティリティ初期化
*/
private void initAlcoholCheckerUtil() {
Logger.i(TAG,"initAlcoholCheckerUtil");
if (alcoholCheckerUtil != null) {
checkerStatus = AlcoholCheckerUtil.fugo_init;
return;
}
alcoholCheckerUtil = new AlcoholCheckerUtil(this, new AlcoholCheckerUtilListener() {
......@@ -317,7 +326,12 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override
public void onStartMeasurement() {
Logger.d(TAG, "onStartMeasurement");
final boolean isFromError;
if (checkerStatus == AlcoholCheckerUtil.fugo_conntected) {
isFromError = false;
checkerStatus = AlcoholCheckerUtil.fugo_wait_go;
} else if (checkerStatus == AlcoholCheckerUtil.fugo_fu_error) {
isFromError = true;
checkerStatus = AlcoholCheckerUtil.fugo_wait_go;
} else {
return;
......@@ -325,11 +339,17 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (mWaitMeasureDialog != null) {
mWaitMeasureDialog.dismiss();
mWaitMeasureDialog = null;
if (isFromError) {
if (mMeasureDialog != null) {
mMeasureDialog.setMessage(getString(R.string.msg_breath_error));
}
} else {
if (mWaitMeasureDialog != null) {
mWaitMeasureDialog.dismiss();
mWaitMeasureDialog = null;
}
showMeasureDialog(getString(R.string.alcohol_checker), getString(R.string.wait_breathe));
}
showMeasureDialog(getString(R.string.alcohol_checker), getString(R.string.wait_breathe));
}
});
}
......@@ -436,10 +456,18 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override
public void run() {
dismissAllDialog();
alcoholCheckerUtil.SendMessageFromApp(AlcoholCheckerUtil.F_BLE_COM_FC_START);
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;
}
......@@ -459,7 +487,9 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override
public void onClick(DialogInterface dialog, int which) {
Logger.i(TAG, "waiting Dialog stop click");
//AlcoholCheckerUtil.isConnected = false;
errorAfterAbookCheckApi("", false);
//alcoholCheckerUtil.disconnect();
}
});
mWaitingDialog.show();
......@@ -478,7 +508,9 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override
public void onClick(DialogInterface dialog, int which) {
Logger.i(TAG, "waiting mWaitMeasureDialog stop clickf");
//AlcoholCheckerUtil.isConnected = false;
errorAfterAbookCheckApi("", false);
//alcoholCheckerUtil.disconnect();
}
});
mWaitMeasureDialog.show();
......@@ -497,32 +529,60 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override
public void onClick(DialogInterface dialog, int which) {
Logger.i(TAG, "wait mMeasureDialog stop click");
//AlcoholCheckerUtil.isConnected = false;
errorAfterAbookCheckApi("", false);
//alcoholCheckerUtil.disconnect();
}
});
mMeasureDialog.show();
}
/**
* アルコールチェッカー処理
* @param abookCheckParam
*/
private void getDeviceInfo(Map<String, String> abookCheckParam) {
Logger.i(TAG,"getDeviceInfo start.");
Logger.i(TAG, "getDeviceInfo start.");
mDeviceType = Integer.parseInt(abookCheckParam.get(ABookKeys.TASK_DEVICE_TYPE));
mQid = abookCheckParam.get(ABookKeys.TASK_QUESTION_ID);
// アルコールチェッカー初期化
initAlcoholCheckerUtil();
if (!alcoholCheckerUtil.startGetDeviceInfo()) {
// 端末がBluetoothをサポートしていないなどの理由で、アルコールチェッカーが使えない
Logger.e(TAG,"bluetooth not support.");
if (!isInitAlcChecker) {
// アルコールチェッカー初期化
initAlcoholCheckerUtil();
}
// アルコールチェッカー接続
connectToAlcholChecker();
if (isInitBLE == false) {
if (!alcoholCheckerUtil.startGetDeviceInfo()) {
// 端末がBluetoothをサポートしていないなどの理由で、アルコールチェッカーが使えない
Logger.e(TAG, "bluetooth not support.");
afterABookCheckApi(mCmd, "", 1, getString(R.string.bluetooth_is_not_supported), null);
return;
} else {
isInitBLE = true;
}
}
if (!isInitAlcChecker) {
// アルコールチェッカー接続
connectToAlcholChecker();
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);
}
}
}
/**
......@@ -626,23 +686,9 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override
protected void onPause() {
super.onPause();
Logger.d(TAG,"-------------------------------------------------");
Logger.i(TAG,"onPause");
Logger.d(TAG,"-------------------------------------------------");
// ダイアログ閉じる
dismissAllDialog();
// タイマーにFCコマンド
if (alcoholCheckerUtil != null) {
alcoholCheckerUtil.SendMessageFromApp(AlcoholCheckerUtil.F_BLE_COM_FC_START);
isAlcBlock = false;
handler.postDelayed(new Runnable() {
@Override
public void run() {
// チェッカーも終了
alcoholCheckerUtil.finish();
}
}, 1000);
if (mCmd.equals(ABookKeys.CMD_GET_DEVICE_INFO)) {
errorAfterAbookCheckApi("", false);
}
}
......@@ -1700,23 +1746,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
if (cmd.equals(ABookKeys.CMD_GET_DEVICE_INFO)) {
// アルコールチェッカー終了
isAlcBlock = false;
// if (alcoholCheckerUtil != null) {
// if (!isFinish) {
// alcoholCheckerUtil.gi_status = AlcoholCheckerUtil.F_BLE_COM_FC_START22;
// } else {
// alcoholCheckerUtil.gi_status = AlcoholCheckerUtil.F_BLE_COM_FC_START;
// }
// }
}
// if (cmd.equals(ABookKeys.CMD_GET_DEVICE_INFO)) {
//// if (alcoholCheckerUtil != null) {
//// alcoholCheckerUtil.finish();
//// alcoholCheckerUtil = null;
//// }
// // アルコールチェッカー終了
// isAlcBlock = false;
// }
}
});
}
......@@ -1969,11 +1999,16 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
}
}
/**
* 全Bluetoothデバイスとの接続を切る
*/
private void disconnectBluetoothDevice() {
Logger.d(TAG, "disconnectBluetoothDevice");
if (alcoholCheckerUtil != null) {
alcoholCheckerUtil.finish();
alcoholCheckerUtil = null;
}
isInitAlcChecker = false;
isInitBLE = false;
}
}
\ No newline at end of file
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