Commit e931b805 by onuma

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

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