Commit 55311ee9 by Lee Jaebin

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

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