Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
abook_check
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abook_android
abook_check
Commits
62057b49
Commit
62057b49
authored
Jul 06, 2022
by
onuma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
計測1回ごとにBLEを切断する。長押しで接続する時に、一部の機種の為3000msのWaitを入れた。
parent
ad32ff5f
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
198 additions
and
256 deletions
+198
-256
ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/AlcoholCheckerUtil.java
+83
-66
ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/AlcoholCheckerUtilListener.java
+2
-0
ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/BleManagerUtil.java
+15
-11
ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/BleManagerUtilListener.java
+1
-1
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/common/activity/ABVContentViewActivity.java
+94
-112
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/home/activity/BlePairingSettingActivity.java
+3
-66
No files found.
ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/AlcoholCheckerUtil.java
View file @
62057b49
...
...
@@ -5,6 +5,7 @@ import android.bluetooth.BluetoothGattCharacteristic;
import
android.bluetooth.BluetoothGattDescriptor
;
import
android.bluetooth.BluetoothGattService
;
import
android.content.Context
;
import
android.os.Handler
;
import
java.io.UnsupportedEncodingException
;
import
java.util.ArrayList
;
...
...
@@ -142,10 +143,13 @@ public class AlcoholCheckerUtil {
public
static
final
int
fugo_wait_go
=
3
;
public
static
final
int
fugo_fu_error
=
4
;
public
static
final
int
fugo_restart
=
5
;
public
static
final
int
fugo_finish
=
6
;
private
boolean
isFirst
=
true
;
// mutex
private
Object
lockObj
=
new
Object
();
private
Handler
handler
=
new
Handler
();
public
BleManagerUtilListener
bleManagerUtilListener
=
new
BleManagerUtilListener
()
{
@Override
...
...
@@ -175,12 +179,12 @@ public class AlcoholCheckerUtil {
}
@Override
public
void
onServicesDiscovered
(
int
status
)
{
public
void
onServicesDiscovered
(
BluetoothGatt
gatt
,
int
status
)
{
Logger
.
i
(
TAG
,
"onServicesDiscovered = %s"
,
status
);
if
(
status
==
BluetoothGatt
.
GATT_SUCCESS
)
{
Logger
.
i
(
TAG
,
"BluetoothGatt.GATT_SUCCESS"
);
TaiyoYudenService
=
bleManagerUtil
.
mBluetoothG
att
.
getService
(
TY_SERVICE_UUID
);
TaiyoYudenService
=
g
att
.
getService
(
TY_SERVICE_UUID
);
if
(
TaiyoYudenService
==
null
)
{
Logger
.
e
(
TAG
,
"Not a TaiyoYuden device"
);
}
else
{
...
...
@@ -190,14 +194,8 @@ public class AlcoholCheckerUtil {
if
(
RxChar
==
null
||
TxChar
==
null
)
{
Logger
.
e
(
TAG
,
"No Tx/Rx"
);
}
else
{
gi_status
=
F_BLE_COM_INIT
;
gi_rxlength
=
0
;
gf_result_flg
=
false
;
gi_rxretry_cnt
=
0
;
gatt
.
requestConnectionPriority
(
BluetoothGatt
.
CONNECTION_PRIORITY_HIGH
);
BluetoothGatt
gatt
=
bleManagerUtil
.
mBluetoothGatt
;
TaiyoYudenService
=
gatt
.
getService
(
TY_SERVICE_UUID
);
BatteryService
=
gatt
.
getService
(
BATTERY_SERVICE_UUID
);
NotificationChar
=
TaiyoYudenService
.
getCharacteristic
(
NOTIFICATION_CHARACTERISTIC_UUID
);
IndicationChar
=
TaiyoYudenService
.
getCharacteristic
(
INDICATION_CHARACTERISTIC_UUID
);
...
...
@@ -205,16 +203,22 @@ public class AlcoholCheckerUtil {
batteryLevelChar
=
BatteryService
.
getCharacteristic
(
BATTERY_LEVEL_UUID
);
connectionPHY
=
0
;
bleManagerUtil
.
readPhyConnection
();
//gatt.readPhy
();
bleManagerUtil
.
mBluetoothGatt
.
setCharacteristicNotification
(
NotificationChar
,
true
);
gatt
.
setCharacteristicNotification
(
NotificationChar
,
true
);
BluetoothGattDescriptor
notification_descriptor
=
NotificationChar
.
getDescriptor
(
CCCD
);
notification_descriptor
.
setValue
(
BluetoothGattDescriptor
.
ENABLE_NOTIFICATION_VALUE
);
bleManagerUtil
.
mBluetoothGatt
.
writeDescriptor
(
notification_descriptor
);
gatt
.
writeDescriptor
(
notification_descriptor
);
//gi_status = F_BLE_COM_INIT;
bleManagerUtil
.
setBluetoothGatt
(
gatt
);
gi_rxlength
=
0
;
gf_result_flg
=
false
;
gi_rxretry_cnt
=
0
;
gi_status
=
F_BLE_COM_RP_START
;
SendMessageFrom
App
(
gi_status
);
SendMessageFrom
Central
(
gi_status
);
listener
.
onServicesDiscovered
(
status
);
}
...
...
@@ -227,7 +231,7 @@ public class AlcoholCheckerUtil {
@Override
public
void
onCharacteristicChanged
(
BluetoothGatt
gatt
,
BluetoothGattCharacteristic
characteristic
)
{
synchronized
(
lockObj
)
{
Logger
.
d
(
TAG
,
"onCharacteristicChanged"
);
//
Logger.d(TAG, "onCharacteristicChanged");
byte
[]
rx
=
characteristic
.
getValue
();
String
rxStr
=
" "
;
...
...
@@ -242,50 +246,26 @@ public class AlcoholCheckerUtil {
@Override
public
void
onDescriptorWrite
(
BluetoothGatt
gatt
,
BluetoothGattDescriptor
descriptor
,
int
status
)
{
//Logger.d(TAG,"onDescriptorWrite"
);
if
(
bleManagerUtil
.
mBluetoothGatt
!=
null
)
{
if
(
bleManagerUtil
.
mBluetoothG
att
.
getService
(
TY_SERVICE_UUID
).
getCharacteristic
(
INDICATION_CHARACTERISTIC_UUID
)
==
null
)
{
Logger
.
d
(
TAG
,
"Old version"
);
UUID
characteristic_uuid
=
descriptor
.
getCharacteristic
().
getUuid
(
);
if
(
g
att
.
getService
(
TY_SERVICE_UUID
).
getCharacteristic
(
INDICATION_CHARACTERISTIC_UUID
)
==
null
)
{
Logger
.
e
(
TAG
,
"Old version"
);
// This version doesn't support latest characteristics
return
;
}
}
else
{
return
;
}
gatt
=
bleManagerUtil
.
mBluetoothGatt
;
TaiyoYudenService
=
gatt
.
getService
(
TY_SERVICE_UUID
);
BatteryService
=
gatt
.
getService
(
BATTERY_SERVICE_UUID
);
NotificationChar
=
TaiyoYudenService
.
getCharacteristic
(
NOTIFICATION_CHARACTERISTIC_UUID
);
IndicationChar
=
TaiyoYudenService
.
getCharacteristic
(
INDICATION_CHARACTERISTIC_UUID
);
WriteChar
=
TaiyoYudenService
.
getCharacteristic
(
WRITE_NO_RESPONSE_CHARACTERISTIC_UUID
);
batteryLevelChar
=
BatteryService
.
getCharacteristic
(
BATTERY_LEVEL_UUID
);
connectionPHY
=
0
;
bleManagerUtil
.
readPhyConnection
();
bleManagerUtil
.
mBluetoothGatt
.
setCharacteristicNotification
(
NotificationChar
,
true
);
BluetoothGattDescriptor
notification_descriptor
=
NotificationChar
.
getDescriptor
(
CCCD
);
notification_descriptor
.
setValue
(
BluetoothGattDescriptor
.
ENABLE_NOTIFICATION_VALUE
);
bleManagerUtil
.
mBluetoothGatt
.
writeDescriptor
(
notification_descriptor
);
UUID
characteristic_uuid
=
descriptor
.
getCharacteristic
().
getUuid
();
if
(
characteristic_uuid
.
equals
(
NOTIFICATION_CHARACTERISTIC_UUID
)){
if
(
IndicationChar
==
null
)
{
IndicationChar
=
TaiyoYudenService
.
getCharacteristic
(
INDICATION_CHARACTERISTIC_UUID
);
}
if
(
characteristic_uuid
.
equals
(
NOTIFICATION_CHARACTERISTIC_UUID
))
{
gatt
.
setCharacteristicNotification
(
IndicationChar
,
true
);
BluetoothGattDescriptor
indication_descriptor
=
IndicationChar
.
getDescriptor
(
CCCD
);
indication_descriptor
.
setValue
(
BluetoothGattDescriptor
.
ENABLE_INDICATION_VALUE
);
gatt
.
writeDescriptor
(
indication_descriptor
);
}
else
if
(
characteristic_uuid
.
equals
(
INDICATION_CHARACTERISTIC_UUID
)){
// Enable notification on receiving data
}
else
if
(
characteristic_uuid
.
equals
(
INDICATION_CHARACTERISTIC_UUID
))
{
gatt
.
setCharacteristicNotification
(
batteryLevelChar
,
true
);
notification_descriptor
=
batteryLevelChar
.
getDescriptor
(
CCCD
);
BluetoothGattDescriptor
notification_descriptor
=
batteryLevelChar
.
getDescriptor
(
CCCD
);
notification_descriptor
.
setValue
(
BluetoothGattDescriptor
.
ENABLE_NOTIFICATION_VALUE
);
gatt
.
writeDescriptor
(
notification_descriptor
);
}
else
if
(
characteristic_uuid
.
equals
(
BATTERY_LEVEL_UUID
))
{
Logger
.
d
(
TAG
,
"Wrote descriptor: "
+
BATTERY_LEVEL_UUID
);
}
else
if
(
characteristic_uuid
.
equals
(
BATTERY_LEVEL_UUID
))
{
Logger
.
i
(
TAG
,
"Wrote descriptor: "
+
BATTERY_LEVEL_UUID
);
}
}
};
...
...
@@ -294,9 +274,11 @@ public class AlcoholCheckerUtil {
this
.
context
=
context
;
isConnected
=
false
;
this
.
listener
=
listener
;
isFirst
=
true
;
}
public
void
finish
()
{
Logger
.
d
(
TAG
,
"finish"
);
isConnected
=
false
;
disconnect
();
}
...
...
@@ -314,38 +296,59 @@ public class AlcoholCheckerUtil {
return
true
;
}
// public int lastSendCmd;
public
void
initAlcoholCheckerSettings
(
BluetoothGatt
gatt
)
{
Logger
.
d
(
TAG
,
"initAlcoholCheckerSettings"
);
if
(
gatt
!=
null
)
{
TaiyoYudenService
=
gatt
.
getService
(
TY_SERVICE_UUID
);
BatteryService
=
gatt
.
getService
(
BATTERY_SERVICE_UUID
);
NotificationChar
=
TaiyoYudenService
.
getCharacteristic
(
NOTIFICATION_CHARACTERISTIC_UUID
);
IndicationChar
=
TaiyoYudenService
.
getCharacteristic
(
INDICATION_CHARACTERISTIC_UUID
);
WriteChar
=
TaiyoYudenService
.
getCharacteristic
(
WRITE_NO_RESPONSE_CHARACTERISTIC_UUID
);
batteryLevelChar
=
BatteryService
.
getCharacteristic
(
BATTERY_LEVEL_UUID
);
connectionPHY
=
0
;
gatt
.
readPhy
();
gatt
.
setCharacteristicNotification
(
NotificationChar
,
true
);
BluetoothGattDescriptor
notification_descriptor
=
NotificationChar
.
getDescriptor
(
CCCD
);
notification_descriptor
.
setValue
(
BluetoothGattDescriptor
.
ENABLE_NOTIFICATION_VALUE
);
gatt
.
writeDescriptor
(
notification_descriptor
);
}
else
{
Logger
.
e
(
TAG
,
"initAlcoholCheckerSettings gatt is null"
);
}
}
public
void
SendMessageFromCentral
(
final
int
giStatus
)
{
Logger
.
d
(
TAG
,
"SendMessageFromCentral"
);
public
void
SendMessageFromApp
(
final
int
giStatus
)
{
synchronized
(
lockObj
)
{
if
(
giStatus
==
F_BLE_COM_RP_START
||
giStatus
==
F_BLE_COM_RD_START
||
giStatus
==
F_BLE_COM_FC_START
||
giStatus
==
F_BLE_COM_FC_START22
)
{
Logger
.
d
(
TAG
,
"gi_status = "
+
giStatus
);
}
else
{
Logger
.
w
(
TAG
,
"UNKOWN COMMAND"
);
}
long
delay
=
1000
;
if
(
isFirst
)
{
delay
=
3000
;
}
//lastSendCmd = giStatus;
Thread
thread
=
new
Thread
(
new
Runnable
()
{
handler
.
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
Thread
.
sleep
(
1000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
if
(
giStatus
==
F_BLE_COM_RP_START
)
{
Logger
.
d
(
TAG
,
"F_BLE_COM_RP_START"
);
sendMessage
(
F_BLE_COM_RP_COMMAND
);
}
else
if
(
giStatus
==
F_BLE_COM_RD_START
)
{
Logger
.
d
(
TAG
,
"F_BLE_COM_RD_START"
);
sendMessage
(
F_BLE_COM_RD_COMMAND
);
}
else
if
(
giStatus
==
F_BLE_COM_FC_START
)
{
Logger
.
d
(
TAG
,
"F_BLE_COM_FC_START"
);
sendMessage
(
F_BLE_COM_FC_COMMAND_F11
);
}
else
if
(
giStatus
==
F_BLE_COM_FC_START22
)
{
Logger
.
d
(
TAG
,
"F_BLE_COM_FC_START22"
);
sendMessage
(
F_BLE_COM_FC_COMMAND_F22
);
}
}
});
thread
.
start
();
},
delay
);
}
}
...
...
@@ -573,7 +576,7 @@ public class AlcoholCheckerUtil {
}
if
(
oldgiStatus
!=
gi_status
)
{
Logger
.
i
(
TAG
,
"chageStatus:"
+
gi_status
);
SendMessageFrom
App
(
gi_status
);
SendMessageFrom
Central
(
gi_status
);
}
}
catch
(
IndexOutOfBoundsException
e
)
{
Logger
.
e
(
TAG
,
e
);
...
...
@@ -715,7 +718,7 @@ public class AlcoholCheckerUtil {
listener
.
onUpdateTBVCalc
(
"Calculationg"
);
gf_result_flg
=
false
;
si_ret
=
F_BLE_COM_RP_START
;
Logger
.
d
(
TAG
,
"ERROR
0x15 si_ret = F_BLE_COM_RP_START"
);
//Logger.d(TAG, "
0x15 si_ret = F_BLE_COM_RP_START");
break
;
case
(
byte
)
0x1F
:
listener
.
onOverUsedError
(
"Over Used"
);
...
...
@@ -761,6 +764,11 @@ public class AlcoholCheckerUtil {
return
si_ret
;
}
/**
* BLEに戻す場合のfc コマンドチェック
* @param rxdata コマンドのbyte配列
* @return 次回モード
*/
private
int
fn_rx_fc_chk
(
byte
[]
rxdata
)
{
Logger
.
d
(
TAG
,
"fn_rx_fc_chk"
);
int
si_ret
=
F_BLE_COM_FC_WAIT
;
...
...
@@ -780,9 +788,11 @@ public class AlcoholCheckerUtil {
//
if
(
fcWaitMode
==
0
)
{
if
(
rxdata
[
0
]
==
1
&&
rxdata
[
1
]
==
102
&&
rxdata
[
2
]
==
99
&&
rxdata
[
3
]
==
3
)
{
// fcコマンド
fcWaitMode
=
1
;
}
if
(
rxdata
[
0
]
==
1
&&
rxdata
[
1
]
==
114
&&
rxdata
[
2
]
==
112
&&
rxdata
[
3
]
==
2
)
{
// RP上位が入ってくる場合があった
si_ret
=
F_BLE_COM_RP_WAIT
;
return
si_ret
;
}
...
...
@@ -791,9 +801,9 @@ public class AlcoholCheckerUtil {
// 49 05 32 35 4
// 0x31 05 20 23 4 実行完了 本体動作モード リアルタイム測定進行状況 チェックサム 4
if
(
rxdata
[
0
]
==
49
&&
rxdata
[
1
]
==
2
)
{
//Logger.i(TAG, "------FC失敗");
}
//
if (rxdata[0] ==49 && rxdata[1] == 2) {
//
//Logger.i(TAG, "------FC失敗");
//
}
if
(!
StringUtil
.
isNullOrEmpty
(
strAlcoholValue
))
{
// 測定値あれば成功
...
...
@@ -808,6 +818,11 @@ public class AlcoholCheckerUtil {
}
/**
* RDYに戻す場合のfc コマンドチェック
* @param rxdata コマンドのbyte配列
* @return 次回モード
*/
private
int
fn_rx_fc_chk2
(
byte
[]
rxdata
)
{
Logger
.
d
(
TAG
,
"fn_rx_fc_chk2"
);
for
(
byte
b:
rxdata
)
{
...
...
@@ -816,6 +831,7 @@ public class AlcoholCheckerUtil {
int
si_ret
=
F_BLE_COM_FC_WAIT22
;
if
(
fcWaitMode
==
0
)
{
if
(
rxdata
[
0
]
==
1
&&
rxdata
[
1
]
==
102
&&
rxdata
[
2
]
==
99
&&
rxdata
[
3
]
==
3
)
{
// fcコマンド
fcWaitMode
=
1
;
}
}
else
if
(
fcWaitMode
==
1
)
{
...
...
@@ -893,7 +909,8 @@ public class AlcoholCheckerUtil {
//str_msg += "[mg/L]";
// 0x0C 測定結果表示状態");
strAlcoholValue
=
str_msg
;
si_ret
=
F_BLE_COM_FC_START22
;
// BLE に戻す
si_ret
=
F_BLE_COM_FC_START
;
return
si_ret
;
}
else
{
...
...
ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/AlcoholCheckerUtilListener.java
View file @
62057b49
package
jp
.
agentec
.
abook
.
abv
.
cl
.
util
;
import
android.bluetooth.BluetoothGatt
;
public
interface
AlcoholCheckerUtilListener
{
void
onConnectionError
(
int
status
);
// ディバイス接続エラー
void
onMeasurementError
(
String
txt
);
// 吹付エラー
...
...
ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/BleManagerUtil.java
View file @
62057b49
...
...
@@ -133,7 +133,7 @@ public class BleManagerUtil {
// サービス検索が完了したときの処理(mBluetoothGatt.discoverServices()の結果として呼ばれる。)
@Override
public
void
onServicesDiscovered
(
BluetoothGatt
gatt
,
final
int
status
)
{
public
void
onServicesDiscovered
(
BluetoothGatt
gatt
,
int
status
)
{
try
{
Logger
.
i
(
TAG
,
"onServicesDiscovered status = %s"
,
status
);
...
...
@@ -141,15 +141,14 @@ public class BleManagerUtil {
return
;
}
//mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
if
(
mBluetoothGatt
==
null
)
{
mBluetoothGatt
=
gatt
;
for
(
BluetoothGattService
svc
:
gatt
.
getServices
()){
Logger
.
d
(
TAG
,
svc
.
getUuid
().
toString
());
}
mBluetoothGatt
.
requestConnectionPriority
(
BluetoothGatt
.
CONNECTION_PRIORITY_HIGH
);
//mBluetoothGatt = gatt;
//mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
if
(
mListener
!=
null
)
{
// アルコールチェッカー
mListener
.
onServicesDiscovered
(
status
);
mListener
.
onServicesDiscovered
(
gatt
,
status
);
}
}
catch
(
Exception
e
)
{
Logger
.
d
(
TAG
,
e
);
...
...
@@ -182,13 +181,9 @@ public class BleManagerUtil {
@Override
public
void
onDescriptorWrite
(
BluetoothGatt
gatt
,
BluetoothGattDescriptor
descriptor
,
int
status
){
Logger
.
d
(
TAG
,
"onDescriptorWrite"
);
try
{
if
(
mListener
!=
null
)
{
mListener
.
onDescriptorWrite
(
gatt
,
descriptor
,
status
);
}
}
catch
(
Exception
e
)
{
Logger
.
e
(
TAG
,
e
);
}
}
};
...
...
@@ -318,7 +313,9 @@ public class BleManagerUtil {
// ②「接続可能範囲から外れた切断」は、内部処理でmBluetoothGatt.disconnect()処理が実施される。
// 切断時のコールバックでmBluetoothGatt.connect()を呼んでおくと、接続可能範囲に入ったら自動接続する。
mBluetoothGatt
.
disconnect
();
mBluetoothGatt
.
close
();
mBluetoothGatt
=
null
;
mListener
=
null
;
}
...
...
@@ -435,6 +432,13 @@ public class BleManagerUtil {
return
true
;
}
public
BluetoothGatt
getBluetoothGatt
()
{
return
mBluetoothGatt
;
}
public
void
setBluetoothGatt
(
BluetoothGatt
gatt
)
{
mBluetoothGatt
=
gatt
;
}
/**
* リスナー設定
* @param listener リスナー
...
...
ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/BleManagerUtilListener.java
View file @
62057b49
...
...
@@ -11,7 +11,7 @@ public interface BleManagerUtilListener {
void
onDisConnectionState
();
// ディバイスと切断時
void
onConnectionError
(
int
status
);
// ディバイス接続エラー
// アルコールチェッカーで追加
void
onServicesDiscovered
(
int
status
);
void
onServicesDiscovered
(
BluetoothGatt
gatt
,
int
status
);
void
onCharacteristicChanged
(
BluetoothGatt
gatt
,
BluetoothGattCharacteristic
characteristic
);
void
onDescriptorWrite
(
BluetoothGatt
gatt
,
BluetoothGattDescriptor
descriptor
,
int
status
);
}
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/common/activity/ABVContentViewActivity.java
View file @
62057b49
...
...
@@ -95,7 +95,6 @@ import jp.agentec.adf.util.DateTimeUtil;
import
jp.agentec.adf.util.FileUtil
;
import
jp.agentec.adf.util.StringUtil
;
import
static
java
.
lang
.
Thread
.
sleep
;
import
static
jp
.
agentec
.
abook
.
abv
.
bl
.
common
.
Constant
.
ReportType
.
RoutineTask
;
...
...
@@ -183,15 +182,10 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
private
int
mDeviceType
;
// 設問ID
private
String
mQid
=
""
;
// アルコールチェッカー二重初期化防止フラグ
private
boolean
isInitAlcChecker
=
false
;
private
boolean
isInitBLE
=
false
;
// 二重起動防止フラグ(アルコールチェッカー)
private
boolean
isAlcBlock
=
false
;
// ステータス
private
int
checkerStatus
=
AlcoholCheckerUtil
.
fugo_init
;
// BLE接続中にonStopしたら、再接続からやりなおし
//private boolean isReconnect = false;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
...
@@ -263,11 +257,67 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
contentDownloader
.
pauseAll
();
showUpdateContentAlert
(
contentId
);
}
/**
* 各デバイスから値を正常に取得された場合、HTML側にコールする
* @param value 各種デバイスから取得した値
*/
private
void
successAfterAbookCheckApi
(
final
String
value
,
boolean
isFinish
)
{
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
dismissAllDialog
();
JSONObject
responseJson
=
new
JSONObject
();
responseJson
.
put
(
ABookKeys
.
TASK_QUESTION_ID
,
mQid
);
responseJson
.
put
(
"value"
,
value
);
afterABookCheckApi
(
mCmd
,
""
,
0
,
""
,
responseJson
.
toString
());
Logger
.
i
(
TAG
,
"successAfterAbookCheckAip JSON [%s]"
,
responseJson
.
toString
());
isAlcBlock
=
false
;
handler
.
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
alcoholCheckerUtil
.
finish
();
}
},
2000
);
}
});
}
isInitAlcChecker
=
false
;
isInitBLE
=
false
;
/**
* 各デバイスからエラー(接続不能など)発生した場合、HTML側にコールする
* @param errorMessage 各種デバイスから取得した値
*/
private
void
errorAfterAbookCheckApi
(
final
String
errorMessage
,
final
boolean
isSendResult
)
{
// エラーの時は終了
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
dismissAllDialog
();
if
(
AlcoholCheckerUtil
.
isConnected
)
{
// BLE接続中であれば、BLE表示に戻す
alcoholCheckerUtil
.
SendMessageFromCentral
(
AlcoholCheckerUtil
.
F_BLE_COM_FC_START
);
}
handler
.
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
if
(
isSendResult
)
{
afterABookCheckApi
(
mCmd
,
""
,
1
,
errorMessage
,
null
);
}
if
(
alcoholCheckerUtil
!=
null
)
{
alcoholCheckerUtil
.
finish
();
alcoholCheckerUtil
=
null
;
}
Logger
.
e
(
TAG
,
errorMessage
);
isAlcBlock
=
false
;
}
},
2000
);
}
});
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// アルコールチェッカーここから
/**
* アルコールチェッカー、ユーティリティ初期化
*/
...
...
@@ -311,6 +361,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
public
void
run
()
{
Logger
.
d
(
TAG
,
"測定完了 = "
+
alcohol
);
if
(!
alcohol
.
equals
(
""
))
{
checkerStatus
=
AlcoholCheckerUtil
.
fugo_finish
;
successAfterAbookCheckApi
(
alcohol
,
false
);
}
else
{
...
...
@@ -351,21 +402,6 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
}
@Override
public
void
onConnectionError
(
int
status
)
{
Logger
.
d
(
TAG
,
"onConnectionError = "
+
status
);
String
message
=
""
;
if
(
status
==
133
||
status
==
8
)
{
message
=
getString
(
R
.
string
.
msg_connection_timeout
);
// デバイスと接続されていない
}
else
if
(
status
==
19
)
{
message
=
getString
(
R
.
string
.
msg_disconnected_device
);
}
if
(
alcoholCheckerUtil
!=
null
)
{
alcoholCheckerUtil
.
isConnected
=
false
;
}
errorAfterAbookCheckApi
(
message
,
true
);
}
@Override
public
void
onMeasurementError
(
String
text
)
{
Logger
.
d
(
TAG
,
"onMeasurementError = "
+
text
);
if
(
mMeasureDialog
!=
null
)
{
...
...
@@ -380,6 +416,26 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
}
@Override
public
void
onConnectionError
(
int
status
)
{
Logger
.
d
(
TAG
,
"onConnectionError = "
+
status
);
if
(
checkerStatus
==
AlcoholCheckerUtil
.
fugo_finish
)
{
Logger
.
d
(
TAG
,
"fugo_finish."
);
return
;
}
checkerStatus
=
AlcoholCheckerUtil
.
fugo_finish
;
String
message
=
getString
(
R
.
string
.
msg_disconnected_device
);
if
(
status
==
133
||
status
==
8
)
{
message
=
getString
(
R
.
string
.
msg_connection_timeout
);
// デバイスと接続されていない
}
else
if
(
status
==
19
)
{
message
=
getString
(
R
.
string
.
msg_disconnected_device
);
}
if
(
alcoholCheckerUtil
!=
null
)
{
alcoholCheckerUtil
.
isConnected
=
false
;
}
errorAfterAbookCheckApi
(
message
,
true
);
}
@Override
public
void
onBreakDownError
(
String
text
)
{
errorAfterAbookCheckApi
(
getString
(
R
.
string
.
msg_break_down_device
),
true
);
}
...
...
@@ -424,53 +480,6 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
}
/**
* 各デバイスから値を正常に取得された場合、HTML側にコールする
* @param value 各種デバイスから取得した値
*/
private
void
successAfterAbookCheckApi
(
final
String
value
,
boolean
isFinish
)
{
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
dismissAllDialog
();
JSONObject
responseJson
=
new
JSONObject
();
responseJson
.
put
(
ABookKeys
.
TASK_QUESTION_ID
,
mQid
);
responseJson
.
put
(
"value"
,
value
);
afterABookCheckApi
(
mCmd
,
""
,
0
,
""
,
responseJson
.
toString
());
Logger
.
i
(
TAG
,
"successAfterAbookCheckAip JSON [%s]"
,
responseJson
.
toString
());
isAlcBlock
=
false
;
}
});
}
/**
* 各デバイスからエラー(接続不能など)発生した場合、HTML側にコールする
* @param errorMessage 各種デバイスから取得した値
*/
private
void
errorAfterAbookCheckApi
(
final
String
errorMessage
,
final
boolean
isSendResult
)
{
// エラーの時は終了
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
dismissAllDialog
();
if
(
AlcoholCheckerUtil
.
isConnected
)
{
alcoholCheckerUtil
.
SendMessageFromApp
(
AlcoholCheckerUtil
.
F_BLE_COM_FC_START
);
}
if
(
isSendResult
)
{
afterABookCheckApi
(
mCmd
,
""
,
1
,
errorMessage
,
null
);
}
if
(
alcoholCheckerUtil
!=
null
)
{
alcoholCheckerUtil
.
finish
();
alcoholCheckerUtil
=
null
;
}
isInitAlcChecker
=
false
;
isInitBLE
=
false
;
Logger
.
e
(
TAG
,
errorMessage
);
isAlcBlock
=
false
;
}
});
}
/**
* 接続待ち
* @param title タイトル
* @param message 内容
...
...
@@ -483,9 +492,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
Logger
.
i
(
TAG
,
"waiting Dialog stop click"
);
//AlcoholCheckerUtil.isConnected = false;
errorAfterAbookCheckApi
(
""
,
false
);
//alcoholCheckerUtil.disconnect();
}
});
mWaitingDialog
.
show
();
...
...
@@ -503,10 +510,8 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
mWaitMeasureDialog
.
setButton
(
DialogInterface
.
BUTTON_POSITIVE
,
getString
(
R
.
string
.
cancel
),
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
Logger
.
i
(
TAG
,
"waiting mWaitMeasureDialog stop clickf"
);
//AlcoholCheckerUtil.isConnected = false;
Logger
.
i
(
TAG
,
"waiting mWaitMeasureDialog stop click"
);
errorAfterAbookCheckApi
(
""
,
false
);
//alcoholCheckerUtil.disconnect();
}
});
mWaitMeasureDialog
.
show
();
...
...
@@ -525,9 +530,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
Logger
.
i
(
TAG
,
"wait mMeasureDialog stop click"
);
//AlcoholCheckerUtil.isConnected = false;
errorAfterAbookCheckApi
(
""
,
false
);
//alcoholCheckerUtil.disconnect();
}
});
mMeasureDialog
.
show
();
...
...
@@ -544,42 +547,20 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
mDeviceType
=
Integer
.
parseInt
(
abookCheckParam
.
get
(
ABookKeys
.
TASK_DEVICE_TYPE
));
mQid
=
abookCheckParam
.
get
(
ABookKeys
.
TASK_QUESTION_ID
);
if
(!
isInitAlcChecker
)
{
// アルコールチェッカー初期化
initAlcoholCheckerUtil
();
}
if
(
isInitBLE
==
false
)
{
if
(!
alcoholCheckerUtil
.
startGetDeviceInfo
())
{
// 端末がBluetoothをサポートしていないなどの理由で、アルコールチェッカーが使えない
Logger
.
e
(
TAG
,
"bluetooth not support."
);
afterABookCheckApi
(
mCmd
,
""
,
1
,
getString
(
R
.
string
.
bluetooth_is_not_supported
),
null
);
return
;
}
else
{
isInitBLE
=
true
;
}
}
alcoholCheckerUtil
.
bleManagerUtil
.
setListener
(
alcoholCheckerUtil
.
bleManagerUtilListener
);
if
(!
isInitAlcChecker
)
{
checkerStatus
=
AlcoholCheckerUtil
.
fugo_init
;
// アルコールチェッカー接続
connectToAlcholChecker
();
isInitAlcChecker
=
true
;
}
else
{
BluetoothPairingDeviceInfoDto
dto
=
getABVUIDataCache
().
getPairingBluetoothDeviceInfo
(
Constant
.
DeviceType
.
alcoholChecker
);
checkerStatus
=
AlcoholCheckerUtil
.
fugo_wait_connect
;
if
(
AlcoholCheckerUtil
.
isConnected
)
{
Logger
.
d
(
TAG
,
"isConnection = true"
);
checkerStatus
=
AlcoholCheckerUtil
.
fugo_conntected
;
showWaitMeasureDialog
(
getString
(
R
.
string
.
alcohol_checker
),
getString
(
R
.
string
.
connection_completed
));
}
else
{
Logger
.
d
(
TAG
,
"isConnection = false"
);
// 登録されているアルコールチェッカーがある
String
message
=
String
.
format
(
getString
(
R
.
string
.
ble_connecting
),
dto
.
deviceName
);
showWaitingDialog
(
getString
(
R
.
string
.
alcohol_checker
),
message
);
// 接続まち
alcoholCheckerUtil
.
connect
(
Constant
.
DeviceType
.
alcoholChecker
,
dto
.
deviceAddress
);
}
}
startAlcholChecker
();
}
/**
...
...
@@ -599,7 +580,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
/**
* BLEディバイスのアルコールチェッカーの情報取得
*/
private
void
connectTo
AlcholChecker
()
{
private
void
start
AlcholChecker
()
{
if
(
requestBluetoothFeature
(
REQUEST_CODE_ENABLEBLUETOOTH_ALCOHL_CHECKER
))
{
//端末のBluetooth設定を確認
String
deviceAddress
=
getABVUIDataCache
().
getPairingBluetoothDeviceAddress
(
Constant
.
DeviceType
.
alcoholChecker
);
...
...
@@ -610,11 +591,12 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
}
BluetoothPairingDeviceInfoDto
dto
=
getABVUIDataCache
().
getPairingBluetoothDeviceInfo
(
Constant
.
DeviceType
.
alcoholChecker
);
checkerStatus
=
AlcoholCheckerUtil
.
fugo_wait_connect
;
if
(
AlcoholCheckerUtil
.
isConnected
)
{
Logger
.
d
(
TAG
,
"isConnection = true"
);
checkerStatus
=
AlcoholCheckerUtil
.
fugo_conntected
;
showWaitMeasureDialog
(
getString
(
R
.
string
.
alcohol_checker
),
getString
(
R
.
string
.
connection_completed
));
}
else
{
// if (AlcoholCheckerUtil.isConnected) {
// Logger.d(TAG, "isConnection = true");
// checkerStatus = AlcoholCheckerUtil.fugo_conntected;
// showWaitMeasureDialog(getString(R.string.alcohol_checker), getString(R.string.connection_completed));
// } else
{
Logger
.
d
(
TAG
,
"isConnection = false"
);
// 登録されているアルコールチェッカーがある
String
message
=
String
.
format
(
getString
(
R
.
string
.
ble_connecting
),
dto
.
deviceName
);
...
...
@@ -625,6 +607,9 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
}
}
// アルコールチェッカーここまで
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private
void
showUpdateContentAlert
(
long
contentId
)
{
if
(
meetingManager
.
isConnected
())
{
ContentDto
contentDto
=
contentDao
.
getContent
(
contentId
);
...
...
@@ -684,7 +669,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
protected
void
onPause
()
{
super
.
onPause
();
Logger
.
i
(
TAG
,
"onPause"
);
if
(
mCmd
.
equals
(
ABookKeys
.
CMD_GET_DEVICE_INFO
))
{
if
(
mCmd
!=
null
&&
mCmd
.
equals
(
ABookKeys
.
CMD_GET_DEVICE_INFO
))
{
errorAfterAbookCheckApi
(
""
,
false
);
}
}
...
...
@@ -2005,7 +1990,5 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
alcoholCheckerUtil
.
finish
();
alcoholCheckerUtil
=
null
;
}
isInitAlcChecker
=
false
;
isInitBLE
=
false
;
}
}
\ No newline at end of file
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/home/activity/BlePairingSettingActivity.java
View file @
62057b49
...
...
@@ -3,17 +3,12 @@ package jp.agentec.abook.abv.ui.home.activity;
import
android.app.Activity
;
import
android.bluetooth.BluetoothAdapter
;
import
android.bluetooth.BluetoothDevice
;
import
android.bluetooth.BluetoothGatt
;
import
android.bluetooth.BluetoothGattCallback
;
import
android.bluetooth.BluetoothManager
;
import
android.bluetooth.BluetoothProfile
;
import
android.bluetooth.le.BluetoothLeScanner
;
import
android.bluetooth.le.ScanCallback
;
import
android.bluetooth.le.ScanResult
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.location.LocationManager
;
import
android.os.Build
;
import
android.os.Bundle
;
...
...
@@ -24,7 +19,6 @@ import android.widget.AdapterView;
import
android.widget.Button
;
import
android.widget.ListView
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
...
...
@@ -32,10 +26,8 @@ import java.util.List;
import
jp.agentec.abook.abv.bl.common.Constant
;
import
jp.agentec.abook.abv.bl.common.Constant.DeviceType
;
import
jp.agentec.abook.abv.bl.common.constant.ABookKeys
;
import
jp.agentec.abook.abv.bl.common.log.Logger
;
import
jp.agentec.abook.abv.bl.dto.BluetoothPairingDeviceInfoDto
;
import
jp.agentec.abook.abv.cl.util.AlcoholCheckerUtil
;
import
jp.agentec.abook.abv.cl.util.BleManagerUtil
;
import
jp.agentec.abook.abv.launcher.android.R
;
import
jp.agentec.abook.abv.ui.common.activity.ABVUIActivity
;
...
...
@@ -45,8 +37,6 @@ import jp.agentec.abook.abv.ui.home.adapter.common.SectionHeaderData;
import
jp.agentec.abook.abv.ui.home.helper.ABookPermissionHelper
;
import
jp.agentec.adf.util.CollectionUtil
;
import
static
android
.
bluetooth
.
BluetoothDevice
.
TRANSPORT_LE
;
public
class
BlePairingSettingActivity
extends
ABVUIActivity
{
private
static
final
String
TAG
=
"BlePairingSettingActivity"
;
...
...
@@ -160,6 +150,7 @@ public class BlePairingSettingActivity extends ABVUIActivity {
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
Logger
.
d
(
TAG
,
"position = "
+
position
);
stopScan
();
BleListRowData
bleListRowData
=
(
BleListRowData
)
parent
.
getItemAtPosition
(
position
);
// 既に保存されてる場合は何もしない
if
(!
bleListRowData
.
isSaved
)
{
...
...
@@ -239,7 +230,7 @@ public class BlePairingSettingActivity extends ABVUIActivity {
//端末側の位置情報許可チェック
if
(!(
gpsEnabled
||
secureLocationGpsEnabled
))
{
//showSimpleAlertDialog(R.string.chino_machine
, R.string.msg_location_device_no_allow);
showSimpleAlertDialog
(
R
.
string
.
alcohol_checker
,
R
.
string
.
msg_location_device_no_allow
);
return
;
}
...
...
@@ -429,29 +420,8 @@ public class BlePairingSettingActivity extends ABVUIActivity {
return
false
;
}
////////////////////////////////////////////////////////////////////////
private
BluetoothGatt
bluetoothGatt
=
null
;
private
BluetoothAdapter
bluetoothAdapter
=
null
;
@Override
protected
void
onDestroy
()
{
super
.
onDestroy
();
//unregisterReceiver(PairingRequest);
if
(
bluetoothGatt
!=
null
)
{
bluetoothGatt
.
close
();
bluetoothGatt
=
null
;
}
}
BroadcastReceiver
PairingRequest
=
new
BroadcastReceiver
()
{
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
if
(
intent
.
getAction
().
equals
(
BluetoothDevice
.
ACTION_PAIRING_REQUEST
))
{
Logger
.
d
(
TAG
,
"PEAR"
);
}
}
};
//private BluetoothDevice device = null;
private
void
PairingDevice
(
String
deviceAddress
)
{
BluetoothManager
bleMgr
=
(
BluetoothManager
)
this
.
getSystemService
(
Context
.
BLUETOOTH_SERVICE
);
...
...
@@ -462,39 +432,6 @@ public class BlePairingSettingActivity extends ABVUIActivity {
}
}
BluetoothDevice
device
=
bluetoothAdapter
.
getRemoteDevice
(
deviceAddress
);
//bluetoothGatt = device.connectGatt(this, false, gattcallback, TRANSPORT_LE);
device
.
createBond
();
//IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
//registerReceiver(PairingRequest, filter);
}
private
final
BluetoothGattCallback
gattcallback
=
new
BluetoothGattCallback
()
{
@Override
public
void
onConnectionStateChange
(
BluetoothGatt
gatt
,
int
status
,
int
newState
)
{
super
.
onConnectionStateChange
(
gatt
,
status
,
newState
);
if
(
newState
==
BluetoothProfile
.
STATE_CONNECTED
)
{
//
Logger
.
d
(
TAG
,
"STATE_CONNECTED"
);
gatt
.
discoverServices
();
}
else
if
(
newState
==
BluetoothProfile
.
STATE_DISCONNECTED
)
{
//
Logger
.
d
(
TAG
,
"STATE_DISCONNECTED"
);
if
(
bluetoothGatt
!=
null
)
{
bluetoothGatt
.
close
();
bluetoothGatt
=
null
;
}
}
}
@Override
public
void
onServicesDiscovered
(
BluetoothGatt
gatt
,
int
status
)
{
super
.
onServicesDiscovered
(
gatt
,
status
);
if
(
status
==
BluetoothGatt
.
GATT_SUCCESS
)
{
bluetoothGatt
=
gatt
;
Logger
.
d
(
TAG
,
"BluetoothGatt.GATT_SUCCESS"
);
}
}
};
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment