Commit 7fb708ab by onuma

#47941 HW連携 アルコールチェッカーから値を取得する処理を追加中5

parent 26838b37
......@@ -1527,11 +1527,12 @@
<string name="msg_pairing_device_no_info">登録されたアルコールチェッカー情報がありません。\n設定画面のアルコールチェッカーHW設定から登録できます。</string>
<string name="msg_power_on">登録された機器の電源をオンにしてください。</string>
<string name="msg_press_button">アルコール濃度を測定するため、機器のボタン押してください</string>
<string name="msg_breath_error">正しく呼気が吹き込まれませんでした。ボタンを押して再計測してください。</string>
<string name="msg_break_down_device">機器が故障している可能性があります。購入元へご連絡ください。</string>
<string name="msg_low_battery">バッテリー不足です。機器の電池を交換してください。</string>
<string name="msg_over_used">使用回数が上限を超えました。他の機器を使用してください。</string>
<string name="msg_power_off">機器の電源がOFFになりました。電源を入れて再接続してください。</string>
<string name="msg_disconnected_device">アルコールチェッカーと切断されました。</string>
<!--
<string name="pairing_search_scan">スキャン</string>
<string name="pairing_search_scaning">スキャン中..</string>
......
......@@ -1531,7 +1531,8 @@
<string name="wait_breathe">입김을 불어주십시오. </string>
<string name="msg_pairing_device_no_info">등록된 기기 정보가 없습니다. 설정화면의 알코올체커설정을 확인해주십시오.</string>
<string name="msg_power_on">등록된 기기의 전원을 켜 주십시오.</string>
<string name="msg_press_button">올바르게 입김을 불어 넣어주시지 않으셨습니다. 버튼을 눌러 재측정을 하십시오</string>
<string name="msg_press_button">알코올 농도를 측정하기 위해 기기의 버튼 누르십시오.</string>
<string name="msg_breath_error">올바르게 입김을 불어 넣어주시지 않으셨습니다. 버튼을 눌러 재측정을 하십시오</string>
<string name="msg_break_down_device">기기가 고장났을 가능성이 있습니다.구입처로 연락해 주십시오</string>
<string name="msg_low_battery">배터리 부족입니다.기기의 베터리를 교환해 주십시오.</string>
<string name="msg_over_used">사용 횟수가 상한을 넘었습니다.다른 기기를 사용해 주십시오.</string>
......
......@@ -1529,11 +1529,15 @@
<string name="msg_pairing_device_no_info">There is no registered device information. Check the alcohol checker settings on the settings screen.</string>
<string name="msg_power_on">Please turn on the power of the registered device.</string>
<string name="msg_press_button">Press the button on the device to measure the alcohol concentration.</string>
<string name="msg_breath_error">The breath was not blown correctly. Press the button to remeasure.</string>
<string name="msg_break_down_device">The device may be out of order. Please contact the place of purchase.</string>
<string name="msg_low_battery">The battery is low. Replace the battery of the device.</string>
<string name="msg_over_used">The number of uses has exceeded the upper limit. Please use other device.</string>
<string name="msg_power_off">The power of the device has been turned off. Turn on the power and reconnect.</string>
<!--
<string name="msg_connection_timeout">デバイスと接続できませんでした</string>
<string name="msg_disconnected_device">デバイスと切断されました。</string>
<!--
<string name="center_thermometer">中心温度計</string>
<string name="pairing_search_scan">Scan</string>
<string name="pairing_search_scaning">Scaning...</string>
......
......@@ -76,7 +76,7 @@
<PreferenceCategory android:title="@string/set_title_pairing" android:key="set_pairing" android:layout="@layout/custom_preference_category">
<PreferenceScreen
android:key="setAlcPairing"
android:title="@string/alc_checker_setting"
android:title="@string/set_title_pairing"
android:layout="@layout/custom_preference_screen">
</PreferenceScreen>
</PreferenceCategory>
......
package jp.agentec.abook.abv.cl.util;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import java.util.TimerTask;
import java.util.UUID;
import jp.agentec.abook.abv.bl.common.log.Logger;
......
package jp.agentec.abook.abv.cl.util;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
......@@ -8,15 +7,12 @@ import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Timer;
import java.util.UUID;
import jp.agentec.abook.abv.bl.common.constant.ABookKeys;
import jp.agentec.abook.abv.bl.common.log.Logger;
public class AlcoholCheckerUtil {
......@@ -76,6 +72,11 @@ public class AlcoholCheckerUtil {
public static final String F_BLE_COM_FC_COMMAND = "01464301F37E04"; // 測定開始
public static final String F_BLE_COM_FC_COMMAND_F1 = "01464301F17E04"; // BLE接続解除
public static final String F_BLE_COM_FC_COMMAND_F2 = "01464301F27E04"; // 測定中断
public static final String F_BLE_COM_FC_COMMAND_F22 = "01464301F27D04"; // 中断コマンド(rdyに戻す
// RPコマンド 01525000A304
// RDコマンド 015244009704
// FC(中断)コマンド 01464301F27D04
// @BLE Rx
private final int F_RX_BUFSIZE = 32;
......@@ -134,14 +135,9 @@ public class AlcoholCheckerUtil {
this.listener = listener;
}
// public void initAlcoholChecker() {
// stopAlcTimer();
// disconnect(true);
// }
public void finish() {
stopAlcTimer();
//disconnect(true);
disconnect(true);
//listener = null;
}
......@@ -153,23 +149,18 @@ public class AlcoholCheckerUtil {
@Override
public void onGetDeviceInfoFailed(int status) {
Logger.i(TAG,"------------------------------------");
Logger.i(TAG,"onGetDeviceInfoFailed = %s", status);
Logger.i(TAG,"------------------------------------");
listener.onGetDeviceInfoFailed(status);
}
@Override
public void onConnectionState(int status) {
Logger.i(TAG,"------------------------------------");
Logger.i(TAG,"onConnectionState = %s" + status);
Logger.i(TAG,"------------------------------------");
if (status == BluetoothProfile.STATE_CONNECTED) {
Log.i(TAG, "Connected to GATT server.");
listener.onFugoAction(ACTION_GATT_CONNECTED, null, null, null, null);
// @@@@@
// ペリフェラルとの接続に成功した時点でサービスを検索する
if (bleManagerUtil.mBluetoothGatt.discoverServices()) {
Logger.i(TAG, "Started discovering services");
} else {
......@@ -182,8 +173,7 @@ public class AlcoholCheckerUtil {
return;
} else {
Logger.i(TAG, "Disconnected from GATT server.");
listener.onFugoAction(ACTION_GATT_DISCONNECTED, null, null, null, null);
bleManagerUtil.disconnect(true);
listener.onConnectionError(19);
}
} else {
......@@ -192,29 +182,24 @@ public class AlcoholCheckerUtil {
@Override
public void onDisConnectionState() {
Logger.i(TAG,"------------------------------------");
//Logger.i(TAG,"------------------------------------");
Logger.i(TAG,"onDisConnectionState");
Logger.i(TAG,"------------------------------------");
//Logger.i(TAG,"------------------------------------");
isConnected = false;
listener.onConnectionError(0);
}
@Override
public void onConnectionError(int status) {
Logger.i(TAG,"------------------------------------");
Logger.i(TAG,"onConnectionError = %s", status);
Logger.i(TAG,"------------------------------------");
isConnected = false;
listener.onConnectionError(status);
}
@Override
public void onServicesDiscovered(int status) {
Logger.i(TAG,"------------------------------------");
Logger.i(TAG,"onServicesDiscovered = %s", status);
Logger.i(TAG,"------------------------------------");
if (status == BluetoothGatt.GATT_SUCCESS) {
Logger.i(TAG,"------------------------------------------------------ BluetoothGatt.GATT_SUCCESS");
Logger.i(TAG,"BluetoothGatt.GATT_SUCCESS");
TaiyoYudenService = bleManagerUtil.mBluetoothGatt.getService(TY_SERVICE_UUID);
......@@ -226,7 +211,7 @@ public class AlcoholCheckerUtil {
TxChar = TaiyoYudenService.getCharacteristic(TX_CHARACTERISTIC_UUID);
if (RxChar == null || TxChar == null) {
Logger.e(TAG,"No Tx/Rx");
Logger.e(TAG, "No Tx/Rx");
} else {
gi_status = F_BLE_COM_INIT;
......@@ -252,17 +237,11 @@ public class AlcoholCheckerUtil {
gi_status = F_BLE_COM_RP_START;
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
startAlcTimer();
}
});
thread.start();
}
}
listener.onServicesDiscovered(status);
}
}
} else {
Logger.d(TAG,"");
}
......@@ -281,6 +260,32 @@ public class AlcoholCheckerUtil {
}
sub_rx_chk(rx);
}
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
Logger.i(TAG,"onDescriptorWrite");
if (bleManagerUtil.mBluetoothGatt.getService(TY_SERVICE_UUID).getCharacteristic(INDICATION_CHARACTERISTIC_UUID) == null){
Logger.d(TAG, "Old version");
// This version doesn't support latest characteristics
return;
}
UUID characteristic_uuid = descriptor.getCharacteristic().getUuid();
if(characteristic_uuid.equals(NOTIFICATION_CHARACTERISTIC_UUID)){
bleManagerUtil.mBluetoothGatt.setCharacteristicNotification(IndicationChar, true);
BluetoothGattDescriptor indication_descriptor = IndicationChar.getDescriptor(CCCD);
indication_descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
bleManagerUtil.mBluetoothGatt.writeDescriptor(indication_descriptor);
} else if(characteristic_uuid.equals(INDICATION_CHARACTERISTIC_UUID)){
// Enable notification on receiving data
bleManagerUtil.mBluetoothGatt.setCharacteristicNotification(batteryLevelChar, true);
BluetoothGattDescriptor notification_descriptor = batteryLevelChar.getDescriptor(CCCD);
notification_descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
bleManagerUtil.mBluetoothGatt.writeDescriptor(notification_descriptor);
} else if(characteristic_uuid.equals(BATTERY_LEVEL_UUID)){
Logger.i(TAG, "Wrote descriptor: " + BATTERY_LEVEL_UUID);
}
}
});
......@@ -294,7 +299,7 @@ public class AlcoholCheckerUtil {
/**
* アルコールチェッカーを監視するタイマーを開始する
*/
private void startAlcTimer() {
public void startAlcTimer() {
if (alcoholCheckerTimerTask != null) {
alcoholCheckerTimerTask.cancel();
alcoholCheckerTimerTask = null;
......@@ -315,17 +320,6 @@ public class AlcoholCheckerUtil {
}
private void init() {
//rxMessage = "";
bleManagerUtil.mBluetoothGatt.setCharacteristicNotification(NotificationChar, true);
BluetoothGattDescriptor notification_descriptor = NotificationChar.getDescriptor(CCCD);
notification_descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
bleManagerUtil.mBluetoothGatt.writeDescriptor(notification_descriptor);
gi_status = F_BLE_COM_RP_START;
}
public void connect(int connectTargetDeviceType, String deviceAddress) {
bleManagerUtil.connect(connectTargetDeviceType, deviceAddress);
}
......@@ -427,12 +421,12 @@ public class AlcoholCheckerUtil {
}
//Intent intent;
if (!error_msg.equals("")) {
listener.onFugoAction(ACTION_TX_ERROR, null, null, error_msg, null);
} else {
listener.onFugoAction(ACTION_TX_FINISHED, null, null, message, null);
}
// if (!error_msg.equals("")) {
// listener.onFugoAction(ACTION_TX_ERROR, null, null, error_msg, null);
// } else {
//
// listener.onFugoAction(ACTION_TX_FINISHED, null, null, message, null);
// }
}
}
Thread thread = new Thread(new MessageSender(message));
......
package jp.agentec.abook.abv.cl.util;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import java.util.UUID;
public interface AlcoholCheckerUtilListener {
void onFugoAction(String action, UUID CHAR, byte[] data, String MESSAGE, String Type);
void onGetDeviceInfoFailed(int status);
void onConnectionError(int status); // ディバイス接続エラー
......
......@@ -15,20 +15,16 @@ import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.List;
import java.util.UUID;
import jp.agentec.abook.abv.bl.common.Constant;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.launcher.android.R;
import jp.agentec.adf.util.StringUtil;
import oz.lottie.animation.content.Content;
import static android.bluetooth.BluetoothDevice.TRANSPORT_LE;
import static org.chromium.base.ThreadUtils.runOnUiThread;
......@@ -78,7 +74,8 @@ public class BleManagerUtil {
@Override
public void run() {
mListener.onConnectionError(status);
disconnect(true);
//disconnect(true);
Logger.e(TAG,"onConnectionStateChange status = " + status);
}
});
return;
......@@ -120,19 +117,19 @@ public class BleManagerUtil {
return;
}
Logger.d(TAG, "--gattSize : " + gatt.getServices().size());
if (gatt.getServices().size() == 0) {
// サービスがない場合は、再接続
bleGattReconnect();
return;
}
// Logger.d(TAG, "--gattSize : " + gatt.getServices().size());
// if (gatt.getServices().size() == 0) {
// // サービスがない場合は、再接続
// bleGattReconnect();
// return;
// }
mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
// アルコールチェッカー
if (mBleConnectDeviceType == Constant.DeviceType.alcoholChecker) {
//if (mBleConnectDeviceType == Constant.DeviceType.alcoholChecker) {
mListener.onServicesDiscovered(status);
return;
}
//return;
//}
// 発見されたサービスのループ
// for(BluetoothGattService service : gatt.getServices()) {
......@@ -168,10 +165,11 @@ public class BleManagerUtil {
// キャラクタリスティックが読み込まれたときの処理
@Override
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status ) {
Logger.i(TAG,"onCharacteristicChanged");
if( BluetoothGatt.GATT_SUCCESS != status ) {
Logger.i(TAG, "onCharacteristicRead");
if (BluetoothGatt.GATT_SUCCESS != status) {
return;
}
}
// if( UUID_CHARACTERISTIC_PRIVATE.equals(characteristic.getUuid())) {
// final String strTemperature = byteToString(characteristic.getValue());
// runOnUiThread( new Runnable() {
......@@ -186,16 +184,16 @@ public class BleManagerUtil {
// setCharacteristicNotification(UUID_SERVICE_PRIVATE, UUID_CHARACTERISTIC_PRIVATE, true);
// return;
// }
}
// }
// キャラクタリスティック変更が通知されたときの処理
@Override
public void onCharacteristicChanged( BluetoothGatt gatt, BluetoothGattCharacteristic characteristic ) {
Logger.i(TAG,"onCharacteristicChanged");
if (mBleConnectDeviceType == Constant.DeviceType.alcoholChecker) {
//if (mBleConnectDeviceType == Constant.DeviceType.alcoholChecker) {
mListener.onCharacteristicChanged(gatt, characteristic);
return;
}
//return;
//}
// if( UUID_CHARACTERISTIC_PRIVATE.equals( characteristic.getUuid() ) ) {
// final String strTemperature = byteToString(characteristic.getValue());
//
......@@ -213,6 +211,11 @@ public class BleManagerUtil {
// return;
// }
}
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status){
Logger.i(TAG,"onDescriptorWrite");
mListener.onDescriptorWrite(gatt, descriptor, status);
}
};
/**
......
......@@ -2,13 +2,14 @@ package jp.agentec.abook.abv.cl.util;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
public interface BleManagerUtilListener {
// 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);
}
......@@ -111,7 +111,7 @@ public class BlePairingSettingActivity extends ABVUIActivity {
setContentView(R.layout.pairing_setting);
TextView deviceTitle = (TextView) findViewById(R.id.device_toolbar_title);
deviceTitle.setText(getString(R.string.alc_checker_setting));
deviceTitle.setText(getString(R.string.set_title_pairing));
// 戻り値の初期化
setResult( Activity.RESULT_CANCELED );
......@@ -211,7 +211,7 @@ public class BlePairingSettingActivity extends ABVUIActivity {
switch (requestCode) {
case REQUEST_ENABLEBLUETOOTH: // Bluetooth有効化要求
if( Activity.RESULT_CANCELED == resultCode ) { // 有効にされなかった
ABVToastUtil.showMakeText(getApplicationContext(), String.format(getString(R.string.msg_scan_bluetooth_no_allow), getString(R.string.chino_machine)), Toast.LENGTH_SHORT);
//ABVToastUtil.showMakeText(getApplicationContext(), String.format(getString(R.string.msg_scan_bluetooth_no_allow), getString(R.string.chino_machine)), Toast.LENGTH_SHORT);
return;
}
break;
......@@ -237,7 +237,7 @@ public class BlePairingSettingActivity extends ABVUIActivity {
//端末側の位置情報許可チェック
if (!(gpsEnabled || secureLocationGpsEnabled)) {
showSimpleAlertDialog(R.string.chino_machine, R.string.msg_location_device_no_allow);
//showSimpleAlertDialog(R.string.chino_machine, R.string.msg_location_device_no_allow);
return;
}
......@@ -356,21 +356,16 @@ public class BlePairingSettingActivity extends ABVUIActivity {
if (CollectionUtil.isNotEmpty(bluetoothPairingInfoDtoList)) {
for (BluetoothPairingDeviceInfoDto bluetoothPairingDeviceInfoDto : bluetoothPairingInfoDtoList) {
// ペアリング情報が既に保存されてる場合はヘッダー情報を各機器毎に追加する
// if (bluetoothPairingDeviceInfoDto.deviceType.equals(DeviceType.centerThermomete)) {
// sectionList.add(new SectionHeaderData(String.format(getString(R.string.pairing_save_machine), getString(R.string.center_thermometer))));
// } else if (bluetoothPairingDeviceInfoDto.deviceType.equals(DeviceType.radiationThermomete)) {
// sectionList.add(new SectionHeaderData(String.format(getString(R.string.pairing_save_machine), getString(R.string.radiation_thermometer))));
// } else
if (bluetoothPairingDeviceInfoDto.deviceType.equals(DeviceType.alcoholChecker)) {
sectionList.add(new SectionHeaderData(String.format(getString(R.string.pairing_save_machine), getString(R.string.alcohl_checker))));
sectionList.add(new SectionHeaderData(String.format(getString(R.string.pairing_save_machine))));
}
}
}
// その他のヘッダー情報追加
if (mScanning) {
sectionList.add(new SectionHeaderData(String.format(getString(R.string.pairing_other_machine_searching), getString(R.string.alcohl_checker))));
sectionList.add(new SectionHeaderData(String.format(getString(R.string.pairing_other_machine_searching))));
} else {
sectionList.add(new SectionHeaderData(String.format(getString(R.string.alc_checker_setting))));
sectionList.add(new SectionHeaderData(String.format(getString(R.string.set_title_pairing))));
}
return sectionList;
}
......
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