안녕하세요?
블루트스 (HC-06) 으로 안드로이드 폰에 데이터를 읽어오는건 되었는데요.
08-09 16:43:21.360: I/System.out(954): start stx 71
08-09 16:43:21.360: I/System.out(954): strMsgsyso ------ 5,E,
08-09 16:43:21.395: I/System.out(954): strMsgsyso ------ 1,06,1.8,12.9,M,19.2,M,,0000*6D
08-09 16:43:21.395: I/System.out(954): $GPGSA,A,3,19,17,06,09,23,28,,,
08-09 16:43:21.395: I/System.out(954): strMsgsyso ------ ,,,,2.9,1.8,2.4*3C
08-09 16:43:21.395: I/System.out(954): $GPGSV,3,1,11,19,83,354,25,17,69,126,19,06,6
08-09 16:43:21.395: I/System.out(954): strMsgsyso ------ 1,320,20,09,34,116,22*73
08-09 16:43:21.395: I/System.out(954): $GPGSV,3,2,11,23,31,081,16,28,12,184,2
08-09 16:43:21.400: I/System.out(954): strMsgsyso ------ 4,03,21,045,15,05,00,223,15*70
08-09 16:43:21.400: I/System.out(954): $GPGSV,3,3,11,22,01,047,15,02,27,
08-09 16:43:21.430: I/System.out(954): strMsgsyso ------ 284,,12,19,314,*4B
08-09 16:43:21.430: I/System.out(954): $GPRMC,074307.000,A,3734.6901,N,12653.7365,
08-09 16:43:21.435: I/System.out(954): strMsgsyso ------ E,0.65,253.79,090816,,,A*6F
08-09 16:43:21.435: I/System.out(954):
08-09 16:43:21.435: I/System.out(954):
08-09 16:43:21.435: I/System.out(954): end etx
이 로그처럼 stx 와 etx 사이에 $GPRMC,074307.000,A,3734.6901,N,12653.7365, .................. 이런게 데이터입니다.
byte[] readBuf = (byte[]) msg.obj;
String strMsg = new String(readBuf, 0, msg.arg1);
byte로 들어온 값을 string 으로 바꿔보면 잘 보이는데 문제가..
stx G1~~~~~~~~~~~~~~~ etx 이게 한 뭉터긴데
stxG1~~~
-- 따로 들어옴
~~~~
-- 따로 들어옴
이렇게 와서
static ByteBuffer bufferBT = ByteBuffer.allocateDirect(3072);
if(tempStatus.equals("S")){
bufferBT.put((byte) readBuf[k]);
System.out.println("[각 데이터 저장]");
}
if(STX == readBuf[k]){
tempStatus = "S";
}
if(ETX == readBuf[k]){
tempStatus = "E";
byte[] bytes = new byte[bufferBT.position()];
bufferBT.flip();
bufferBT.get(bytes);
String bufferBTToString = new String(bytes);
//String bufferBTToString = new String(bytes,"US_ASCII");
//화면 출력
mActivityHandler.obtainMessage(Constants.MESSAGE_READ_CHAT_DATA, bufferBTToString).sendToTarget();
System.out.println("bufferBT--------------------->" + bufferBTToString);
StringBuilder requestUrl = new StringBuilder("/bluetooth_gps_log.php");
requestUrl.append("?strMsg="+bufferBTToString);
HttpAsyncTask task = new HttpAsyncTask(mHTTPListener, 0, requestUrl.toString(), HttpInterface.REQUEST_TYPE_GET);
task.execute();
mCommandParser.resetParser();
printState(bufferBT);
System.out.println("3072바이트 읽음");
bufferBT.clear();
System.out.println("[clear 실행]");
printState(bufferBT);
}
이렇게 해서 버퍼에 하나씩하니씩 쌓아서 etx가 오면 클리어 시키고 다시 쌓을려고 하는데요.
이상한게 꼭 중간만 문자가 다 깨집니다..
그래서
for (int k = 0; k < readBuf.length; k++) {
String toHexString = Integer.toHexString((readBuf[k]&0xff));
System.out.println("readBuf toHexString "+ toHexString );
//back String
int intVal = Integer.parseInt(toHexString, 16);
char HextoString = (char) intVal;
System.out.println("readBuf toHexString ---- "+HextoString);
}
해서 하나씩 헥사 값과 그걸 다시 스트링으로 바꿔서 출력해보면
헥사 : 0
스트링 : 깨짐
으로 나옵니다..
헥사가 0 이면 잘못된 값 같은데.. 그러면 그냥 화면에 찍을때도 깨져서 보여야한다고 생각하는데.. 화면에서는 또 정상적인 값이 찍혀나옵니다..
;;; 이걸 어떻게 더 확인을 하고 수정을 해야할까요??ㅜㅠ GPS 가 데이터는 잘 보내주는거 같은데 ㅜㅠ
이게 왜.. 어디서 이렇게 깨지는지 모르겠습니다..ㅜㅠ