블루투스로 들어오는 데이터가 1234567890 이면
1
234567890
이렇게 나눠들어오는걸 아래와 같이하니 한 문장으로 붙어서 들어왔습니다.
그런데 최고가 10byte더라구요. 1234567890123456을보내면
1234567890
123456 이렇게 나눠서 또 들어옶니다. 이방법을 해결할 방법이 없을까요?
public void run() {
Log.i(TAG, "BEGIN mConnectedThread");
byte[] buffer = new byte[1024];
int bytes;
int check_bytes = 0;
byte[] buffer_b = new byte[1024];
// Keep listening to the InputStream while connected
while (true) {
try {
// Read from the InputStream
bytes = mmInStream.read(buffer);
if(bytes == 1)
{
//buffer_b 에 buffer 를 1byte copy
System.arraycopy(buffer, 0, buffer_b, 0, 1);
check_bytes = 1;
}
else
{
if(check_bytes==1)
{
//buffer_b에 buffer를 붙이고 bytes+1 해서 보냄
System.arraycopy(buffer, 0, buffer_b, 1, bytes);
mHandler.obtainMessage(Sensor_mode.MESSAGE_READ, bytes+1, -1, buffer_b)
.sendToTarget();
check_bytes=0;
}else
{
// Send the obtained bytes to the UI Activity
mHandler.obtainMessage(Sensor_mode.MESSAGE_READ, bytes, -1, buffer)
.sendToTarget();
}
}
} catch (IOException e) {
Log.e(TAG, "disconnected", e);
connectionLost();
break;
}
}
}