Commit e931b805 by onuma

TR41をスキャンして温度を取得できるように修正途中。

parent 39e4fbdc
...@@ -176,7 +176,7 @@ public class Constant { ...@@ -176,7 +176,7 @@ public class Constant {
int barcode = 3; // バーコード int barcode = 3; // バーコード
int radiationThermomete = 4; // 放射温度計 int radiationThermomete = 4; // 放射温度計
int sppBluetoothMachine = 5; // SPP通信機器 int sppBluetoothMachine = 5; // SPP通信機器
int nfc = 7; // nfc機器 int nfc = 7; // nfc機器 .... テスト用に 6 -> 7に変更
int tr41 = 6; // TR41温度計 int tr41 = 6; // TR41温度計
} }
} }
...@@ -48,14 +48,16 @@ public class TR41BluetoothUtil { ...@@ -48,14 +48,16 @@ public class TR41BluetoothUtil {
public static final String TAG = "TR41BluetootUtil"; public static final String TAG = "TR41BluetootUtil";
private BluetoothManager mBluetoothManager ; private BluetoothManager mBluetoothManager ;
private BluetoothAdapter mBluetoothAdapter ; public BluetoothAdapter mBluetoothAdapter ;
private BluetoothLeScanner mBluetoothLeScanner; private BluetoothLeScanner mBluetoothLeScanner;
private TR41BluetoothUtilLeScanner mListener; private TR41BluetoothUtilLeScanner mListener;
private Context mContext; private Context mContext;
private Handler mHandler; private Handler mHandler;
private static final long SCAN_PERIOD = 10000; // スキャン時間。単位はミリ秒 private boolean mIsScaning;
private static final long SCAN_PERIOD = 60000; // スキャン時間。単位はミリ秒
/** /**
* *
...@@ -66,6 +68,7 @@ public class TR41BluetoothUtil { ...@@ -66,6 +68,7 @@ public class TR41BluetoothUtil {
void onScanFailed(int errorCode); void onScanFailed(int errorCode);
//void onScanResult(int callbackType, ScanResult result); //void onScanResult(int callbackType, ScanResult result);
void onScanResult(String strTemperature); // デバイスから温度を渡す void onScanResult(String strTemperature); // デバイスから温度を渡す
void onScanStop(); // スキャンを停止した
} }
public TR41BluetoothUtil(Context context, TR41BluetoothUtilLeScanner listener) public TR41BluetoothUtil(Context context, TR41BluetoothUtilLeScanner listener)
...@@ -73,6 +76,8 @@ public class TR41BluetoothUtil { ...@@ -73,6 +76,8 @@ public class TR41BluetoothUtil {
mContext = context; mContext = context;
mListener = listener; mListener = listener;
mHandler = new Handler(); mHandler = new Handler();
mIsScaning = false;
} }
// ************************************************************************ // ************************************************************************
// void Sb_Init_Ble_Scan() // void Sb_Init_Ble_Scan()
...@@ -83,19 +88,16 @@ public class TR41BluetoothUtil { ...@@ -83,19 +88,16 @@ public class TR41BluetoothUtil {
// ************************************************************************ // ************************************************************************
private void Sb_Init_Ble_Scan() private void Sb_Init_Ble_Scan()
{ {
if(mBluetoothAdapter != null){ if (mBluetoothAdapter == null){
return; return;
} }
//BluetoothAdapter取得
BluetoothAdapter btAdpt = BluetoothAdapter.getDefaultAdapter() ;
// boolean btEnable = btAdpt.isEnabled() ; boolean btEnable = mBluetoothAdapter.isEnabled() ;
// if(btEnable == true) { if(btEnable == true) {
// Bluetoothアダプタ作成 // Bluetoothアダプタ作成
mBluetoothManager = (BluetoothManager) mContext.getSystemService( Context.BLUETOOTH_SERVICE ); mBluetoothManager = (BluetoothManager) mContext.getSystemService( Context.BLUETOOTH_SERVICE );
mBluetoothAdapter = mBluetoothManager.getAdapter() ;
mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner() ; mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner() ;
// } }
} }
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
...@@ -120,14 +122,18 @@ public class TR41BluetoothUtil { ...@@ -120,14 +122,18 @@ public class TR41BluetoothUtil {
@Override @Override
public void run() { public void run() {
// SCAN_PERIOD 秒後に呼ばれた時はスキャンで端末を取得できなかったと見做す。 // SCAN_PERIOD 秒後に呼ばれた時はスキャンで端末を取得できなかったと見做す。
mBluetoothLeScanner.stopScan(mScanCallback) ; mListener.onScanStop();
Sb_StopScan();
Logger.d(TAG, "scan in 20 sec"); Logger.d(TAG, "scan in 20 sec");
} }
}, SCAN_PERIOD ); }, SCAN_PERIOD );
mIsScaning = true;
} }
public void Sb_StopScan() public void Sb_StopScan()
{ {
mIsScaning = false;
mBluetoothLeScanner.stopScan(mScanCallback) ; mBluetoothLeScanner.stopScan(mScanCallback) ;
} }
...@@ -163,6 +169,12 @@ public class TR41BluetoothUtil { ...@@ -163,6 +169,12 @@ public class TR41BluetoothUtil {
@Override @Override
public void onScanResult(int callbackType, ScanResult result) { public void onScanResult(int callbackType, ScanResult result) {
if(!mIsScaning){
Logger.d(TAG, "mIsScaning == false");
return;
}
BluetoothDevice device = result.getDevice() ; BluetoothDevice device = result.getDevice() ;
byte[] scanRecord = result.getScanRecord().getBytes() ; byte[] scanRecord = result.getScanRecord().getBytes() ;
......
...@@ -346,8 +346,11 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity { ...@@ -346,8 +346,11 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
Logger.e(TAG,"BluetoothAdapter is null."); Logger.e(TAG,"BluetoothAdapter is null.");
} }
// TR41温度センサー
if (mBluetoothAdapter != null){ if (mBluetoothAdapter != null){
// TR41温度センサー
mIsTR41Scaning = false;
mTR41SerialNo = "";
mTR41BluetoothUtil = new TR41BluetoothUtil(this, new TR41BluetoothUtil.TR41BluetoothUtilLeScanner() { mTR41BluetoothUtil = new TR41BluetoothUtil(this, new TR41BluetoothUtil.TR41BluetoothUtilLeScanner() {
@Override @Override
public void onScanFailed(int errorCode) { public void onScanFailed(int errorCode) {
...@@ -380,12 +383,20 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity { ...@@ -380,12 +383,20 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
setNfcData(strTemperature); setNfcData(strTemperature);
// 取得できたら、ダイアログ消す。 // 取得できたら、ダイアログ消す。
dismissWaitngDialog(); dismissWaitngDialog();
// TR41スキャン停止 // TR41スキャン停止
stopTR41BeaconScan(); stopTR41BeaconScan();
} }
} }
@Override
public void onScanStop() {
Logger.d(TAG,"-------------------------------------------------");
Logger.d(TAG, "onScanStop");
Logger.d(TAG,"-------------------------------------------------");
// TR41スキャン停止
stopTR41BeaconScan();
}
}); });
mTR41BluetoothUtil.mBluetoothAdapter = this.mBluetoothAdapter;
} }
} }
...@@ -702,6 +713,8 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity { ...@@ -702,6 +713,8 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
if (!mIsTR41Scaning) { if (!mIsTR41Scaning) {
mTR41BluetoothUtil.Sb_StartScan(); mTR41BluetoothUtil.Sb_StartScan();
mIsTR41Scaning = true; mIsTR41Scaning = true;
showWaitingDialog(getString(R.string.tr41_thermometer),getString(R.string.pairing_search_scaning));
} }
} }
} }
...@@ -716,11 +729,13 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity { ...@@ -716,11 +729,13 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
if (mIsTR41Scaning) { if (mIsTR41Scaning) {
mTR41BluetoothUtil.Sb_StopScan(); mTR41BluetoothUtil.Sb_StopScan();
mIsTR41Scaning = false; mIsTR41Scaning = false;
dismissWaitngDialog();
} }
} }
/** /**
* 中心温度計、置くだけセンサー接続の待機ダイヤログ表示 * 中心温度計、置くだけセンサー接続の待機、TR41温度センサースキャン中、ダイヤログ表示
* @param title タイトル * @param title タイトル
* @param message 内容 * @param message 内容
*/ */
...@@ -739,7 +754,7 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity { ...@@ -739,7 +754,7 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
case DeviceType.centerThermomete: case DeviceType.centerThermomete:
case DeviceType.radiationThermomete: case DeviceType.radiationThermomete:
Logger.d(TAG,"-------------------------------------------------"); Logger.d(TAG,"-------------------------------------------------");
Logger.d(TAG,"中止"); Logger.d(TAG,"放射・中心温度計 接続待中止");
Logger.d(TAG,"-------------------------------------------------"); Logger.d(TAG,"-------------------------------------------------");
bleManagerDisconnect(true); // 放射温度計、中心温度計接続切断 bleManagerDisconnect(true); // 放射温度計、中心温度計接続切断
break; break;
...@@ -762,6 +777,9 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity { ...@@ -762,6 +777,9 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
mNfcAdapter.disableForegroundDispatch(ABVCheckContentViewActivity.this); mNfcAdapter.disableForegroundDispatch(ABVCheckContentViewActivity.this);
break; break;
case DeviceType.tr41: // TR41温度センサー case DeviceType.tr41: // TR41温度センサー
Logger.d(TAG,"-------------------------------------------------");
Logger.d(TAG,"TR41温度センサー スキャン中止");
Logger.d(TAG,"-------------------------------------------------");
stopTR41BeaconScan(); stopTR41BeaconScan();
break; break;
} }
......
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