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
0c522b34
Commit
0c522b34
authored
Feb 20, 2020
by
Lee Jaebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BLE対応(リモートデバイスが提供するサービスが見つからない場合は、リモートデバイスのキャッシュをリフレッシュさせてから再接続を行うように修正)
parent
6bd18805
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
14 deletions
+48
-14
ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/BleManagerUtil.java
+47
-13
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/common/activity/ABVCheckContentViewActivity.java
+1
-1
No files found.
ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/BleManagerUtil.java
View file @
0c522b34
...
...
@@ -14,8 +14,10 @@ import android.bluetooth.le.ScanResult;
import
android.content.Context
;
import
android.os.Build
;
import
android.os.Handler
;
import
android.os.Looper
;
import
android.widget.Toast
;
import
java.lang.reflect.Method
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteOrder
;
import
java.util.List
;
...
...
@@ -82,7 +84,7 @@ public class BleManagerUtil {
}
if
(
status
==
BluetoothGatt
.
GATT_SUCCESS
&&
BluetoothProfile
.
STATE_CONNECTED
==
newState
)
{
mHandler
.
postDelayed
(
new
Runnable
()
{
new
Handler
(
Looper
.
getMainLooper
())
.
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
// 接続完了
...
...
@@ -103,7 +105,7 @@ public class BleManagerUtil {
if
(
BluetoothProfile
.
STATE_DISCONNECTED
==
newState
)
{
// 切断完了(接続可能範囲から外れて切断された)
// 切断が発生する場合、Bluetoothと接続を切断する。
disconnect
();
disconnect
(
true
);
return
;
}
}
...
...
@@ -117,7 +119,8 @@ public class BleManagerUtil {
Logger
.
d
(
TAG
,
"--gattSize : "
+
gatt
.
getServices
().
size
());
if
(
gatt
.
getServices
().
size
()
==
0
)
{
mListener
.
onGetDeviceInfoFailed
(-
1
);
// サービスがない場合は、再接続
bleGattReconnect
();
return
;
}
mBluetoothGatt
.
requestConnectionPriority
(
BluetoothGatt
.
CONNECTION_PRIORITY_HIGH
);
...
...
@@ -317,10 +320,12 @@ public class BleManagerUtil {
}
else
{
mBluetoothGatt
=
device
.
connectGatt
(
mContext
,
false
,
mGattcallback
);
}
// 該当デバイスのキャッシュをリフレッシュ
refreshDeviceCache
(
mBluetoothGatt
);
}
// 切断
public
void
disconnect
()
{
public
void
disconnect
(
boolean
listenerFlg
)
{
if
(
mBluetoothGatt
==
null
)
{
return
;
}
...
...
@@ -334,14 +339,15 @@ public class BleManagerUtil {
mBluetoothGatt
.
disconnect
();
mBluetoothGatt
.
close
();
mBluetoothGatt
=
null
;
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
// 切断トーストメッセージを表示する。
mListener
.
onDisConnectionState
();
}
});
if
(
listenerFlg
)
{
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
// 切断トーストメッセージを表示する。
mListener
.
onDisConnectionState
();
}
});
}
}
// キャラクタリスティックの読み込み
...
...
@@ -375,7 +381,7 @@ public class BleManagerUtil {
// Signed short (16-bit) Two's complement to short, String
public
String
byteToString
(
byte
[]
bytes
)
{
short
sht
=
ByteBuffer
.
wrap
(
bytes
).
order
(
ByteOrder
.
LITTLE_ENDIAN
).
getShort
();
float
flt
=
sht
/
(
float
)
100
;
float
flt
=
sht
/
(
float
)
100
;
return
String
.
valueOf
(
flt
);
}
...
...
@@ -407,4 +413,32 @@ public class BleManagerUtil {
UUID_CHARACTERISTIC_PRIVATE
=
UUID
.
fromString
(
"46202b74-cfe1-11e7-abc4-cec278b6b50a"
);
}
}
/**
* bleGattのcache更新
* @param gatt
* @return
*/
private
boolean
refreshDeviceCache
(
BluetoothGatt
gatt
){
try
{
BluetoothGatt
localBluetoothGatt
=
gatt
;
Method
localMethod
=
localBluetoothGatt
.
getClass
().
getMethod
(
"refresh"
,
new
Class
[
0
]);
if
(
localMethod
!=
null
)
{
boolean
bool
=
((
Boolean
)
localMethod
.
invoke
(
localBluetoothGatt
,
new
Object
[
0
])).
booleanValue
();
return
bool
;
}
}
catch
(
Exception
localException
)
{
Logger
.
e
(
TAG
,
"An exception occured while refreshing device"
);
}
return
false
;
}
/**
* 再接続処理
*/
private
void
bleGattReconnect
()
{
disconnect
(
false
);
connect
(
mBleConnectDeviceType
,
mDeviceAddress
);
}
}
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/common/activity/ABVCheckContentViewActivity.java
View file @
0c522b34
...
...
@@ -878,7 +878,7 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
* 中心温度計の接続を切る
*/
protected
void
bleManagerDisconnect
()
{
bleManagerUtil
.
disconnect
();
bleManagerUtil
.
disconnect
(
true
);
}
/**
...
...
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