블루투스에서 첫번째 데이터와 나머지데이터가 따로 들어와서
다음과 같이 해결을 했는데요. 데이터가 10byte만들어와서요 최소 20byte가 들어와야하는데 어떻게 해야할까요?
public void run() {
Log.i(TAG, "BEGIN mConnectedThread");
byte[] buffer = new byte[1024];
int bytes;
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;
}
}
}