최대 1 분 소요

안드로이드 예제 블루투스 채팅에서  Phone에서 나가는 데이터는 잘 받아지나.

ATmega128에서 오는 데이터는 자꾸 첫번째 바이트 읽고 나머지 바이트를 읽는 이슈가 있어서..

BluetoothChatService.java에서 아래와 같이 수정하였음.

이렇게 되면 문제 되는 부분은 해결이 된다. ㅋㅋㅋ 좋구나~~

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;

}

}

}