Commit 78b23091 by onuma

吹付エラーの後、10秒経過後に「息を吹きかけてください」が表示されなかったのを修正した。

parent 97554d16
...@@ -146,195 +146,166 @@ public class AlcoholCheckerUtil { ...@@ -146,195 +146,166 @@ public class AlcoholCheckerUtil {
// mutex // mutex
private Object lockObj = new Object(); private Object lockObj = new Object();
public AlcoholCheckerUtil(Context context, AlcoholCheckerUtilListener listener) { public BleManagerUtilListener bleManagerUtilListener = new BleManagerUtilListener() {
this.context = context;
isConnected = false;
this.listener = listener;
}
public void finish() {
isConnected = false;
disconnect();
}
// Bluetoothアダプタの取得処理 @Override
public boolean startGetDeviceInfo() { public void onGetDeviceInfoFailed(int status) {
}
// BLE管理 @Override
bleManagerUtil = new BleManagerUtil(context, new BleManagerUtilListener() { public void onGetDeviceInfo(String strTemperature) {
@Override
public void onGetDeviceInfoFailed(int status) {
} }
@Override @Override
public void onGetDeviceInfo(String strTemperature) { public void onConnectionState(int status) {
Logger.d(TAG,"onConnectionState = %s", status);
} }
@Override @Override
public void onConnectionState(int status) { public void onDisConnectionState() {
// Logger.i(TAG,"-------------------------------------------------------------- = %s", status); }
// Logger.i(TAG,"onConnectionState = %s", status);
// Logger.i(TAG,"-------------------------------------------------------------- = %s", status);
// if (status == BluetoothProfile.STATE_CONNECTED) {
// Log.d(TAG, "Connected to GATT server.");
//
// // ペリフェラルとの接続に成功した時点でサービスを検索する
// if (bleManagerUtil.mBluetoothGatt.discoverServices()) {
// Logger.d(TAG, "Started discovering services");
// } else {
// Logger.d(TAG, "Failed to start discovering services");
// }
// isConnected = true;
//
// } else if (status == BluetoothProfile.STATE_DISCONNECTED) {
//
// if (bleManagerUtil.mBluetoothGatt == null) {
// return;
// } else {
// Logger.i(TAG, "Disconnected from GATT server.");
// listener.onConnectionError(19);
// }
// } else {
// Logger.i(TAG,"UNKNOW STATE = " + status);
// }
}
@Override @Override
public void onDisConnectionState() { public void onConnectionError(int status) {
// Logger.d(TAG,"onDisConnectionState"); Logger.d(TAG,"onConnectionError = %s", status);
// listener.onConnectionError(0); listener.onConnectionError(status);
// //isConnected = false; }
}
@Override @Override
public void onConnectionError(int status) { public void onServicesDiscovered(int status) {
Logger.d(TAG,"onConnectionError = %s", status); Logger.i(TAG,"onServicesDiscovered = %s", status);
listener.onConnectionError(status); if (status == BluetoothGatt.GATT_SUCCESS) {
} Logger.i(TAG,"BluetoothGatt.GATT_SUCCESS");
@Override TaiyoYudenService = bleManagerUtil.mBluetoothGatt.getService(TY_SERVICE_UUID);
public void onServicesDiscovered(int status) { if (TaiyoYudenService == null) {
//Logger.i(TAG,"-------------------------------------------------------------- = %s", status); Logger.e(TAG,"Not a TaiyoYuden device");
Logger.i(TAG,"onServicesDiscovered = %s", status); } else {
//Logger.i(TAG,"-------------------------------------------------------------- = %s", status); // Check TX and RX UUIDs
if (status == BluetoothGatt.GATT_SUCCESS) { RxChar = TaiyoYudenService.getCharacteristic(RX_CHARACTERISTIC_UUID);
Logger.i(TAG,"BluetoothGatt.GATT_SUCCESS"); TxChar = TaiyoYudenService.getCharacteristic(TX_CHARACTERISTIC_UUID);
if (RxChar == null || TxChar == null) {
TaiyoYudenService = bleManagerUtil.mBluetoothGatt.getService(TY_SERVICE_UUID); Logger.e(TAG, "No Tx/Rx");
if (TaiyoYudenService == null) {
Logger.e(TAG,"Not a TaiyoYuden device");
} else { } else {
// Check TX and RX UUIDs gi_status = F_BLE_COM_INIT;
RxChar = TaiyoYudenService.getCharacteristic(RX_CHARACTERISTIC_UUID);
TxChar = TaiyoYudenService.getCharacteristic(TX_CHARACTERISTIC_UUID);
//Logger.i(TAG,"iiiiiiiiiiiiiiiiiiiiiii");
if (RxChar == null || TxChar == null) {
Logger.e(TAG, "No Tx/Rx");
} else {
//Logger.i(TAG,"iiiiiiiiiiiiiiiiiiiiiii");
gi_status = F_BLE_COM_INIT;
gi_rxlength = 0; gi_rxlength = 0;
gf_result_flg = false; gf_result_flg = false;
gi_rxretry_cnt = 0; gi_rxretry_cnt = 0;
BluetoothGatt gatt = bleManagerUtil.mBluetoothGatt; BluetoothGatt gatt = bleManagerUtil.mBluetoothGatt;
TaiyoYudenService = gatt.getService(TY_SERVICE_UUID); 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);
WriteChar = TaiyoYudenService.getCharacteristic(WRITE_NO_RESPONSE_CHARACTERISTIC_UUID); WriteChar = TaiyoYudenService.getCharacteristic(WRITE_NO_RESPONSE_CHARACTERISTIC_UUID);
batteryLevelChar = BatteryService.getCharacteristic(BATTERY_LEVEL_UUID); batteryLevelChar = BatteryService.getCharacteristic(BATTERY_LEVEL_UUID);
connectionPHY = 0; connectionPHY = 0;
bleManagerUtil.readPhyConnection(); bleManagerUtil.readPhyConnection();
bleManagerUtil.mBluetoothGatt.setCharacteristicNotification(NotificationChar, true); bleManagerUtil.mBluetoothGatt.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); bleManagerUtil.mBluetoothGatt.writeDescriptor(notification_descriptor);
gi_status = F_BLE_COM_RP_START; gi_status = F_BLE_COM_RP_START;
SendMessageFromApp(gi_status); SendMessageFromApp(gi_status);
listener.onServicesDiscovered(status); listener.onServicesDiscovered(status);
}
} }
} else {
} }
} else {
} }
}
@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 = " ";
if (rx != null && rx.length > 0) { if (rx != null && rx.length > 0) {
for (byte rx1 : rx) { for (byte rx1 : rx) {
rxStr += rx1 + " ,"; rxStr += rx1 + " ,";
}
} }
sub_rx_chk(rx);
} }
sub_rx_chk(rx);
} }
}
@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");
if (bleManagerUtil.mBluetoothGatt != null) { if (bleManagerUtil.mBluetoothGatt != null) {
if (bleManagerUtil.mBluetoothGatt.getService(TY_SERVICE_UUID).getCharacteristic(INDICATION_CHARACTERISTIC_UUID) == null) { if (bleManagerUtil.mBluetoothGatt.getService(TY_SERVICE_UUID).getCharacteristic(INDICATION_CHARACTERISTIC_UUID) == null) {
Logger.d(TAG, "Old version"); Logger.d(TAG, "Old version");
// This version doesn't support latest characteristics // This version doesn't support latest characteristics
return;
}
} else {
return; return;
} }
gatt = bleManagerUtil.mBluetoothGatt; } else {
TaiyoYudenService = gatt.getService(TY_SERVICE_UUID); return;
BatteryService = gatt.getService(BATTERY_SERVICE_UUID); }
NotificationChar = TaiyoYudenService.getCharacteristic(NOTIFICATION_CHARACTERISTIC_UUID); gatt = bleManagerUtil.mBluetoothGatt;
IndicationChar = TaiyoYudenService.getCharacteristic(INDICATION_CHARACTERISTIC_UUID); TaiyoYudenService = gatt.getService(TY_SERVICE_UUID);
WriteChar = TaiyoYudenService.getCharacteristic(WRITE_NO_RESPONSE_CHARACTERISTIC_UUID); BatteryService = gatt.getService(BATTERY_SERVICE_UUID);
batteryLevelChar = BatteryService.getCharacteristic(BATTERY_LEVEL_UUID); NotificationChar = TaiyoYudenService.getCharacteristic(NOTIFICATION_CHARACTERISTIC_UUID);
connectionPHY = 0; IndicationChar = TaiyoYudenService.getCharacteristic(INDICATION_CHARACTERISTIC_UUID);
WriteChar = TaiyoYudenService.getCharacteristic(WRITE_NO_RESPONSE_CHARACTERISTIC_UUID);
bleManagerUtil.readPhyConnection(); batteryLevelChar = BatteryService.getCharacteristic(BATTERY_LEVEL_UUID);
connectionPHY = 0;
bleManagerUtil.mBluetoothGatt.setCharacteristicNotification(NotificationChar, true);
BluetoothGattDescriptor notification_descriptor = NotificationChar.getDescriptor(CCCD); 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);
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);
BluetoothGattDescriptor indication_descriptor = IndicationChar.getDescriptor(CCCD);
indication_descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
gatt.writeDescriptor(indication_descriptor);
} else if(characteristic_uuid.equals(INDICATION_CHARACTERISTIC_UUID)){
// Enable notification on receiving data
gatt.setCharacteristicNotification(batteryLevelChar, true);
notification_descriptor = batteryLevelChar.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);
} else if(characteristic_uuid.equals(BATTERY_LEVEL_UUID)){
Logger.d(TAG, "Wrote descriptor: " + BATTERY_LEVEL_UUID);
}
}
};
public AlcoholCheckerUtil(Context context, AlcoholCheckerUtilListener listener) {
this.context = context;
isConnected = false;
this.listener = listener;
}
UUID characteristic_uuid = descriptor.getCharacteristic().getUuid(); public void finish() {
if(characteristic_uuid.equals(NOTIFICATION_CHARACTERISTIC_UUID)){ isConnected = false;
if (IndicationChar == null) { disconnect();
IndicationChar = TaiyoYudenService.getCharacteristic(INDICATION_CHARACTERISTIC_UUID); }
}
gatt.setCharacteristicNotification(IndicationChar, true); // Bluetoothアダプタの取得処理
BluetoothGattDescriptor indication_descriptor = IndicationChar.getDescriptor(CCCD); public boolean startGetDeviceInfo() {
indication_descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
gatt.writeDescriptor(indication_descriptor); // BLE管理
} else if(characteristic_uuid.equals(INDICATION_CHARACTERISTIC_UUID)){ bleManagerUtil = new BleManagerUtil(context, bleManagerUtilListener);
// Enable notification on receiving data
gatt.setCharacteristicNotification(batteryLevelChar, true);
notification_descriptor = batteryLevelChar.getDescriptor(CCCD);
notification_descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
gatt.writeDescriptor(notification_descriptor);
} else if(characteristic_uuid.equals(BATTERY_LEVEL_UUID)){
Logger.d(TAG, "Wrote descriptor: " + BATTERY_LEVEL_UUID);
}
}
});
if (!bleManagerUtil.startDeviceInfo()) { if (!bleManagerUtil.startDeviceInfo()) {
return false; return false;
......
...@@ -420,4 +420,12 @@ public class BleManagerUtil { ...@@ -420,4 +420,12 @@ public class BleManagerUtil {
mBluetoothGatt.readPhy(); mBluetoothGatt.readPhy();
return true; return true;
} }
/**
* リスナー設定
* @param listener リスナー
*/
public void setListener(BleManagerUtilListener listener) {
mListener = listener;
}
} }
...@@ -273,10 +273,6 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -273,10 +273,6 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
*/ */
private void initAlcoholCheckerUtil() { private void initAlcoholCheckerUtil() {
Logger.i(TAG,"initAlcoholCheckerUtil"); Logger.i(TAG,"initAlcoholCheckerUtil");
if (alcoholCheckerUtil != null) {
checkerStatus = AlcoholCheckerUtil.fugo_init;
return;
}
alcoholCheckerUtil = new AlcoholCheckerUtil(this, new AlcoholCheckerUtilListener() { alcoholCheckerUtil = new AlcoholCheckerUtil(this, new AlcoholCheckerUtilListener() {
...@@ -341,7 +337,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -341,7 +337,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
public void run() { public void run() {
if (isFromError) { if (isFromError) {
if (mMeasureDialog != null) { if (mMeasureDialog != null) {
mMeasureDialog.setMessage(getString(R.string.msg_breath_error)); mMeasureDialog.setMessage(getString(R.string.wait_breathe));
} }
} else { } else {
if (mWaitMeasureDialog != null) { if (mWaitMeasureDialog != null) {
...@@ -563,6 +559,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity { ...@@ -563,6 +559,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
isInitBLE = true; isInitBLE = true;
} }
} }
alcoholCheckerUtil.bleManagerUtil.setListener(alcoholCheckerUtil.bleManagerUtilListener);
if (!isInitAlcChecker) { if (!isInitAlcChecker) {
// アルコールチェッカー接続 // アルコールチェッカー接続
connectToAlcholChecker(); connectToAlcholChecker();
......
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