Commit b71b72a9 by onuma

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

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