Commit b71b72a9 by onuma

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

parent 349e1746
...@@ -1527,4 +1527,5 @@ ...@@ -1527,4 +1527,5 @@
<string name="msg_location_device_no_allow">端末の設定から位置情報をONにしてください。</string> <string name="msg_location_device_no_allow">端末の設定から位置情報をONにしてください。</string>
<string name="alc_checker_setting">アルコールチェッカー設定</string> <string name="alc_checker_setting">アルコールチェッカー設定</string>
<string name="alcohl_checker">アルコールチェッカー</string> <string name="alcohl_checker">アルコールチェッカー</string>
<string name="ble_connecting">の電源を入れて、電源ボタンを押してください</string>
</resources> </resources>
...@@ -105,7 +105,7 @@ public class AlcoholCheckerUtil { ...@@ -105,7 +105,7 @@ public class AlcoholCheckerUtil {
public static final UUID TX_CHARACTERISTIC_UUID = UUID.fromString("442F1572-8A00-9A28-CBE1-E1D4212D53EB"); // Taiyo Yuden Tx Characteristic public static final UUID TX_CHARACTERISTIC_UUID = UUID.fromString("442F1572-8A00-9A28-CBE1-E1D4212D53EB"); // Taiyo Yuden Tx Characteristic
private final int MAX_MESSAGE_COUNT = 20; // Number of messages to show in UI private final int MAX_MESSAGE_COUNT = 20; // Number of messages to show in UI
private String rxMessage; // private String rxMessage;
public static final String ACTION_TX_FINISHED = "com.taiyoyuden.tyapp_terminal.ACTION_TX_FINISHED"; public static final String ACTION_TX_FINISHED = "com.taiyoyuden.tyapp_terminal.ACTION_TX_FINISHED";
public static final String ACTION_TX_ERROR = "com.taiyoyuden.tyapp_terminal.ACTION_TX_ERROR"; public static final String ACTION_TX_ERROR = "com.taiyoyuden.tyapp_terminal.ACTION_TX_ERROR";
...@@ -138,12 +138,12 @@ public class AlcoholCheckerUtil { ...@@ -138,12 +138,12 @@ public class AlcoholCheckerUtil {
// BLE管理 // BLE管理
bleManagerUtil = new BleManagerUtil(context, new BleManagerUtilListener() { bleManagerUtil = new BleManagerUtil(context, new BleManagerUtilListener() {
@Override // @Override
public void onGetDeviceInfo(String strTemperature) { // public void onGetDeviceInfo(String strTemperature) {
Logger.i(TAG,"------------------------------------"); // Logger.i(TAG,"------------------------------------");
Logger.i(TAG,"onGetDeviceInfo = %s", strTemperature); // Logger.i(TAG,"onGetDeviceInfo = %s", strTemperature);
Logger.i(TAG,"------------------------------------"); // Logger.i(TAG,"------------------------------------");
} // }
@Override @Override
public void onGetDeviceInfoFailed(int status) { public void onGetDeviceInfoFailed(int status) {
...@@ -210,42 +210,19 @@ public class AlcoholCheckerUtil { ...@@ -210,42 +210,19 @@ public class AlcoholCheckerUtil {
if (status == BluetoothGatt.GATT_SUCCESS) { if (status == BluetoothGatt.GATT_SUCCESS) {
Logger.i(TAG,"------------------------------------------------------ BluetoothGatt.GATT_SUCCESS"); Logger.i(TAG,"------------------------------------------------------ BluetoothGatt.GATT_SUCCESS");
Logger.i(TAG,"BluetoothGatt.GATT_SUCCESS"); Logger.i(TAG,"BluetoothGatt.GATT_SUCCESS");
// for (BluetoothGattService svc : gatt.getServices()){
// //Log.d(TAG,svc.getUuid().toString());
// System.out.println("" + svc.getUuid().toString());
// }
//listener.onFugoAction(ACTION_GATT_SERVICES,null, null, null, null);
Logger.i(TAG,"ACTION_GATT_SERVICES");
// Check if the required services are available
// Check if this is a Taiyo Yuden device
TaiyoYudenService = bleManagerUtil.mBluetoothGatt.getService(TY_SERVICE_UUID); TaiyoYudenService = bleManagerUtil.mBluetoothGatt.getService(TY_SERVICE_UUID);
if (TaiyoYudenService == null) { if (TaiyoYudenService == null) {
Logger.i(TAG,"Not a TaiyoYuden device"); Logger.e(TAG,"Not a TaiyoYuden device");
//Toast.makeText(getApplicationContext(), "Not a TaiyoYuden device", Toast.LENGTH_SHORT).show();
//mService.disconnectDevice();
} else { } else {
// Check TX and RX UUIDs // Check TX and RX UUIDs
// BluetoothGattCharacteristic RxChar = TaiyoYudenService.getCharacteristic(RX_CHARACTERISTIC_UUID);
// BluetoothGattCharacteristic TxChar = TaiyoYudenService.getCharacteristic(TX_CHARACTERISTIC_UUID);
RxChar = TaiyoYudenService.getCharacteristic(RX_CHARACTERISTIC_UUID); RxChar = TaiyoYudenService.getCharacteristic(RX_CHARACTERISTIC_UUID);
TxChar = TaiyoYudenService.getCharacteristic(TX_CHARACTERISTIC_UUID); TxChar = TaiyoYudenService.getCharacteristic(TX_CHARACTERISTIC_UUID);
// if (RxChar == null || TxChar == null) {
if (RxChar == null || TxChar == null) { if (RxChar == null || TxChar == null) {
// TaiyoYuden device doesn't support Tx/Rx communication Logger.e(TAG,"No Tx/Rx");
System.out.println("No Tx/Rx");
//Toast.makeText(getApplicationContext(), "Device is not running terminal service", Toast.LENGTH_SHORT).show();
} else { } else {
System.out.println("Terminal Start...............................");
// @Info
//mListener.onStartFugo();
//Intent fugosmartdemo = new Intent(getApplicationContext(), FugoSmartDemo.class);
// Stop Bluetooth scanning while the terminal activity is open
//mService.stopScan(mLeScanCallback);
// Start terminal application
//startActivityForResult(fugosmartdemo, REQUEST_OPEN_TERMINAL);
gi_status = F_BLE_COM_INIT; gi_status = F_BLE_COM_INIT;
//((TextView)findViewById(R.id.txtStatus)).setText("F_BLE_COM_INIT");
gi_rxlength = 0; gi_rxlength = 0;
gf_result_flg = false; gf_result_flg = false;
...@@ -262,8 +239,6 @@ public class AlcoholCheckerUtil { ...@@ -262,8 +239,6 @@ public class AlcoholCheckerUtil {
bleManagerUtil.readPhyConnection(); bleManagerUtil.readPhyConnection();
rxMessage = "";
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);
...@@ -274,7 +249,7 @@ public class AlcoholCheckerUtil { ...@@ -274,7 +249,7 @@ public class AlcoholCheckerUtil {
Thread thread = new Thread(new Runnable() { Thread thread = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
timer(); timerStart();
} }
}); });
thread.start(); thread.start();
...@@ -282,9 +257,8 @@ public class AlcoholCheckerUtil { ...@@ -282,9 +257,8 @@ public class AlcoholCheckerUtil {
} }
listener.onServicesDiscovered(status); listener.onServicesDiscovered(status);
//mIsBluetoothEnable = true;
} else { } else {
//System.out.println("onServicesDiscovered received: " + status); Logger.d(TAG,"");
} }
} }
...@@ -318,22 +292,26 @@ public class AlcoholCheckerUtil { ...@@ -318,22 +292,26 @@ public class AlcoholCheckerUtil {
if (!bleManagerUtil.startDeviceInfo()) { if (!bleManagerUtil.startDeviceInfo()) {
return false; return false;
} }
// 状態管理タイマースタート //timerStart();
// alcoholCheckerTimerTask = new AlcoholCheckerTimerTask(context, listener);
// Timer timer = new Timer(true);
// timer.schedule(alcoholCheckerTimerTask, 0, 1000);
return true; return true;
} }
private void timer() { /**
* アルコールチェッカーを監視するタイマーを開始する
*/
private void timerStart() {
if (alcoholCheckerTimerTask != null) {
alcoholCheckerTimerTask.cancel();
alcoholCheckerTimerTask = null;
}
alcoholCheckerTimerTask = new AlcoholCheckerTimerTask(this, listener); alcoholCheckerTimerTask = new AlcoholCheckerTimerTask(this, listener);
Timer timer = new Timer(true); Timer timer = new Timer(true);
timer.schedule(alcoholCheckerTimerTask, 0, 1000); timer.schedule(alcoholCheckerTimerTask, 0, 1000);
} }
private void init() { private void init() {
rxMessage = ""; //rxMessage = "";
bleManagerUtil.mBluetoothGatt.setCharacteristicNotification(NotificationChar, true); bleManagerUtil.mBluetoothGatt.setCharacteristicNotification(NotificationChar, true);
BluetoothGattDescriptor notification_descriptor = NotificationChar.getDescriptor(CCCD); BluetoothGattDescriptor notification_descriptor = NotificationChar.getDescriptor(CCCD);
...@@ -350,6 +328,10 @@ public class AlcoholCheckerUtil { ...@@ -350,6 +328,10 @@ public class AlcoholCheckerUtil {
// 切断 // 切断
public void disconnect(boolean listenerFlg) { public void disconnect(boolean listenerFlg) {
bleManagerUtil.disconnect(listenerFlg); bleManagerUtil.disconnect(listenerFlg);
if (alcoholCheckerTimerTask != null) {
alcoholCheckerTimerTask.cancel();
alcoholCheckerTimerTask = null;
}
} }
...@@ -787,7 +769,8 @@ public class AlcoholCheckerUtil { ...@@ -787,7 +769,8 @@ public class AlcoholCheckerUtil {
str_msg += "[mg/L]"; str_msg += "[mg/L]";
//((TextView)findViewById(R.id.TBV_Calc)).setText(str_msg); // @ //((TextView)findViewById(R.id.TBV_Calc)).setText(str_msg); // @
listener.onUpdateTBVCalc(str_msg + " 0x0C 測定結果表示状態"); //listener.onUpdateTBVCalc(str_msg + " 0x0C 測定結果表示状態");
listener.onGetDeviceInfo(str_msg);
} else { } else {
// Error // Error
......
...@@ -43,8 +43,8 @@ public class BleManagerUtil { ...@@ -43,8 +43,8 @@ public class BleManagerUtil {
// 定数(Bluetooth LE Gatt UUID) // 定数(Bluetooth LE Gatt UUID)
// Private Service // Private Service
private UUID UUID_SERVICE_PRIVATE; //private UUID UUID_SERVICE_PRIVATE;
private UUID UUID_CHARACTERISTIC_PRIVATE; //private UUID UUID_CHARACTERISTIC_PRIVATE;
// for Notification // for Notification
private UUID UUID_NOTIFY; private UUID UUID_NOTIFY;
...@@ -127,6 +127,7 @@ public class BleManagerUtil { ...@@ -127,6 +127,7 @@ public class BleManagerUtil {
} }
mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH); mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
// アルコールチェッカー
if (mBleConnectDeviceType == Constant.DeviceType.alcoholChecker) { if (mBleConnectDeviceType == Constant.DeviceType.alcoholChecker) {
mListener.onServicesDiscovered(status); mListener.onServicesDiscovered(status);
return; return;
...@@ -147,32 +148,31 @@ public class BleManagerUtil { ...@@ -147,32 +148,31 @@ public class BleManagerUtil {
} }
// プライベートサービス // プライベートサービス
if(UUID_SERVICE_PRIVATE.equals(service.getUuid())) { // if(UUID_SERVICE_PRIVATE.equals(service.getUuid())) {
// 最初の読み取り // // 最初の読み取り
readCharacteristic(UUID_SERVICE_PRIVATE, UUID_CHARACTERISTIC_PRIVATE); // readCharacteristic(UUID_SERVICE_PRIVATE, UUID_CHARACTERISTIC_PRIVATE);
//
runOnUiThread( new Runnable() { // runOnUiThread( new Runnable() {
@Override // @Override
public void run() { // public void run() {
// 操作可能 // // 操作可能
mListener.onConnectionState(status); // mListener.onConnectionState(status);
} // }
}); // });
continue; // continue;
} // }
} }
} }
// キャラクタリスティックが読み込まれたときの処理 // キャラクタリスティックが読み込まれたときの処理
@Override // @Override
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status ) { // public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status ) {
Logger.i(TAG,"onCharacteristicChanged"); // Logger.i(TAG,"onCharacteristicChanged");
if( BluetoothGatt.GATT_SUCCESS != status ) { // if( BluetoothGatt.GATT_SUCCESS != status ) {
return; // return;
} // }
if( UUID_CHARACTERISTIC_PRIVATE.equals(characteristic.getUuid())) { // if( UUID_CHARACTERISTIC_PRIVATE.equals(characteristic.getUuid())) {
// final String strTemperature = byteToString(characteristic.getValue()); // final String strTemperature = byteToString(characteristic.getValue());
// runOnUiThread( new Runnable() { // runOnUiThread( new Runnable() {
// @Override // @Override
// public void run() { // public void run() {
...@@ -181,12 +181,11 @@ public class BleManagerUtil { ...@@ -181,12 +181,11 @@ public class BleManagerUtil {
//// mListener.onGetDeviceInfo(strTemperature); //// mListener.onGetDeviceInfo(strTemperature);
// } // }
// }); // });
// // 通知設定
// 通知設定 // setCharacteristicNotification(UUID_SERVICE_PRIVATE, UUID_CHARACTERISTIC_PRIVATE, true);
setCharacteristicNotification(UUID_SERVICE_PRIVATE, UUID_CHARACTERISTIC_PRIVATE, true); // return;
return; // }
} // }
}
// キャラクタリスティック変更が通知されたときの処理 // キャラクタリスティック変更が通知されたときの処理
@Override @Override
...@@ -196,22 +195,22 @@ public class BleManagerUtil { ...@@ -196,22 +195,22 @@ public class BleManagerUtil {
mListener.onCharacteristicChanged(gatt, characteristic); mListener.onCharacteristicChanged(gatt, characteristic);
return; return;
} }
if( UUID_CHARACTERISTIC_PRIVATE.equals( characteristic.getUuid() ) ) { // if( UUID_CHARACTERISTIC_PRIVATE.equals( characteristic.getUuid() ) ) {
final String strTemperature = byteToString(characteristic.getValue()); // final String strTemperature = byteToString(characteristic.getValue());
//
runOnUiThread( new Runnable() { // runOnUiThread( new Runnable() {
@Override // @Override
public void run() { // public void run() {
// 複数呼ばれるため、mBluetoothGattがnullの場合、以下の処理を行わない // // 複数呼ばれるため、mBluetoothGattがnullの場合、以下の処理を行わない
if(mBluetoothGatt == null) { // if(mBluetoothGatt == null) {
return; // return;
} // }
// 芯温計の温度を渡す。 // // 芯温計の温度を渡す。
mListener.onGetDeviceInfo(strTemperature); // mListener.onGetDeviceInfo(strTemperature);
} // }
}); // });
return; // return;
} // }
} }
}; };
...@@ -396,9 +395,9 @@ public class BleManagerUtil { ...@@ -396,9 +395,9 @@ public class BleManagerUtil {
*/ */
public boolean startDeviceInfo() { public boolean startDeviceInfo() {
// Bluetoothアダプタの取得 // Bluetoothアダプタの取得
BluetoothManager bluetoothManager = (BluetoothManager) mContext.getSystemService( Context.BLUETOOTH_SERVICE ); BluetoothManager bluetoothManager2 = (BluetoothManager) mContext.getSystemService( Context.BLUETOOTH_SERVICE );
if (bluetoothManager != null) { if (bluetoothManager2 != null) {
mBluetoothAdapter = bluetoothManager.getAdapter(); mBluetoothAdapter = bluetoothManager2.getAdapter();
if( mBluetoothAdapter == null ) { // Android端末がBluetoothをサポートしていない if( mBluetoothAdapter == null ) { // Android端末がBluetoothをサポートしていない
Toast.makeText( mContext, R.string.bluetooth_is_not_supported, Toast.LENGTH_SHORT ).show(); Toast.makeText( mContext, R.string.bluetooth_is_not_supported, Toast.LENGTH_SHORT ).show();
return false; return false;
...@@ -412,15 +411,15 @@ public class BleManagerUtil { ...@@ -412,15 +411,15 @@ public class BleManagerUtil {
// UUIDセット // UUIDセット
private void setUUID() { private void setUUID() {
if (mBleConnectDeviceType == Constant.DeviceType.centerThermomete) { // if (mBleConnectDeviceType == Constant.DeviceType.centerThermomete) {
// 中心温度計のUUIDセット // // 中心温度計のUUIDセット
UUID_SERVICE_PRIVATE = UUID.fromString("05fd8c58-9d23-11e7-abc4-cec278b6b50a"); // UUID_SERVICE_PRIVATE = UUID.fromString("05fd8c58-9d23-11e7-abc4-cec278b6b50a");
UUID_CHARACTERISTIC_PRIVATE = UUID.fromString("05fd8f5a-9d23-11e7-abc4-cec278b6b50a"); // UUID_CHARACTERISTIC_PRIVATE = UUID.fromString("05fd8f5a-9d23-11e7-abc4-cec278b6b50a");
} else if (mBleConnectDeviceType == Constant.DeviceType.radiationThermomete) { // } else if (mBleConnectDeviceType == Constant.DeviceType.radiationThermomete) {
// 放射温度計のUUIDセット // // 放射温度計のUUIDセット
UUID_SERVICE_PRIVATE = UUID.fromString("462026f6-cfe1-11e7-abc4-cec278b6b50a"); // UUID_SERVICE_PRIVATE = UUID.fromString("462026f6-cfe1-11e7-abc4-cec278b6b50a");
UUID_CHARACTERISTIC_PRIVATE = UUID.fromString("46202b74-cfe1-11e7-abc4-cec278b6b50a"); // UUID_CHARACTERISTIC_PRIVATE = UUID.fromString("46202b74-cfe1-11e7-abc4-cec278b6b50a");
} // }
} }
/** /**
......
...@@ -4,7 +4,7 @@ import android.bluetooth.BluetoothGatt; ...@@ -4,7 +4,7 @@ import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattCharacteristic;
public interface BleManagerUtilListener { public interface BleManagerUtilListener {
void onGetDeviceInfo(String strTemperature); // ディバイスから渡す情報 // void onGetDeviceInfo(String strTemperature); // ディバイスから渡す情報
void onGetDeviceInfoFailed(int status); // ディバイスと接続失敗時の情報渡す。 void onGetDeviceInfoFailed(int status); // ディバイスと接続失敗時の情報渡す。
void onConnectionState(int status); // ディバイスと接続された時情報渡す。 void onConnectionState(int status); // ディバイスと接続された時情報渡す。
void onDisConnectionState(); // ディバイスと切断時 void onDisConnectionState(); // ディバイスと切断時
......
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