Commit 55311ee9 by Lee Jaebin

SPP通信でデータ取得時、成功音を鳴らす処理追加、SPP通信で受信されない問題修正

parent 5e5dbf1b
......@@ -55,8 +55,8 @@ public class YamatoBluetoothReceiveTask extends Thread {
@Override
public void run() {
Logger.i(TAG, "bluetoothReciveTask run");
byte[] buffer = new byte[1024];
int readSize = 0;
String str = "";
while (mInputStream != null) {
Logger.i(TAG, "start read mInputStream.");
......@@ -66,14 +66,17 @@ public class YamatoBluetoothReceiveTask extends Thread {
}
try {
byte[] buffer = new byte[1024];
readSize = mInputStream.read(buffer);
String str = new String(buffer, 0, readSize);
str += new String(buffer, 0, readSize);
Logger.i(TAG, "getData : " + str);
if (str.indexOf(new Character((char) STX).toString()) != -1 && str.indexOf(new Character((char) ETX).toString()) != -1) {
String dataStr = str.substring(str.indexOf(new Character((char) STX).toString()) + 1, str.indexOf(new Character((char) ETX).toString()));
Logger.i(TAG, "convert data : " + dataStr);
String result = dataStr.substring(mSppDeviceDto.dataStartIndex - 1, mSppDeviceDto.dataEndIndex - 1).replaceAll(" ", "");
// データを取得したらリセット
str = "";
mListener.onGetData(result);
}
Thread.sleep(500);
......
......@@ -670,8 +670,10 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
final BluetoothDevice bluetoothDevice = mBluetoothAdapter.getRemoteDevice(sppDeviceDto.pairingDeviceAddress);
if (bluetoothDevice != null) {
Logger.d(TAG, "----bluetoothDevice is not null");
// 既に接続している場合、端末アドレスが一致すれば、接続済みと見做す。
if (mSppBluetoothConnectThread != null && mSppBluetoothConnectThread.getConnectedAddress().equals(bluetoothDevice.getAddress())) {
Logger.d(TAG, "----device address Same");
// 接続完了後、処理
if (mWaitingDialog != null) {
handler.post(new Runnable() {
......@@ -684,7 +686,7 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
} else { // 初回のbluetooth接続・bluetooth対象アドレスが異なる場合、新規で接続するようにする。
// 初回ではない場合はbluetoothを一度接続を切る。
if (mSppBluetoothConnectThread != null) {
Logger.i("------------------------------1");
Logger.d(TAG, "address diff change bluetoothThread");
disConnectSppBluetooth();
handler.postDelayed(new Runnable() {
@Override
......@@ -693,6 +695,7 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
}
}, 5000);
} else {
Logger.d(TAG, "new connect spp bluetooth");
setSppBluetoothThread(bluetoothDevice, sppDeviceDto);
}
}
......@@ -857,7 +860,10 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
sppBluetoothMachineDataJson.put(ABookKeys.TASK_QUESTION_ID, mQid);
sppBluetoothMachineDataJson.put("value", strData);
afterABookCheckApi(mCmd, "", 0, "", sppBluetoothMachineDataJson.toString());
// 値が空ではない場合、成功音を出す。
if (strData != null && strData.length() > 0) {
audioPlay();
}
// 閉じる
dismissWaitngDialog();
}
......@@ -991,6 +997,7 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
@Override
protected void onStop() {
super.onStop();
Logger.d(TAG, "--onStop");
// SPP通信の接続を切る
disConnectSppBluetooth();
......
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