Commit be3aab96 by Lee Jaebin

SPP通信 受信処理修正

parent b7d1d87e
......@@ -2,10 +2,8 @@ package jp.agentec.abook.abv.cl.util;
import android.bluetooth.BluetoothSocket;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.bl.dto.SppDeviceDto;
......@@ -59,6 +57,7 @@ public class YamatoBluetoothReceiveTask extends Thread {
Logger.i(TAG, "bluetoothReciveTask run");
int readSize = 0;
String str = "";
while (mInputStream != null) {
Logger.i(TAG, "start read mInputStream.");
......@@ -68,20 +67,17 @@ public class YamatoBluetoothReceiveTask extends Thread {
}
try {
BufferedReader br = new BufferedReader(new InputStreamReader(mInputStream));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
String str = sb.toString();
byte[] buffer = new byte[1024];
readSize = mInputStream.read(buffer);
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);
......
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