마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

블루투스 통신에서 상대편에서 오는 값이 출력이 되지 않고 있습니다... [closed]

0 추천
byte[] readBuf = (byte[]) msg.obj;
    // construct a string from the valid bytes in the buffer
    String readMessage = new String(readBuf, 0, msg.arg1);
    dataRecieved = readMessage;
    rx.setText(dataRecieved);

    dataRecieved = dataRecieved.trim(); //공백 제거
    String[] bytes = dataRecieved.split(" ");

if((dataRecieved != null) && (dataRecieved.matches("\\s*[0-9A-Fa-f]{2} [0-9A-Fa-f]{2}\\s*\r?\n?" ))) {

 dataRecieved = dataRecieved.trim();
 String[] bytes = dataRecieved.split(" ");

 if((bytes[0] != null)&&(bytes[1] != null)) {
  
  PID = Integer.parseInt(bytes[0].trim(), 16);
  value = Integer.parseInt(bytes[1].trim(), 16); 
  }
 


 
      int RPM_value = (value*256)/4;
      needle_value = ((RPM_value * 22)/1000) - 85;
      
      if(prev_RPM == 0) {
          RotateAnimation RPM_animation = new RotateAnimation(-85, needle_value, 30, 97);
          RPM_animation.setInterpolator(new LinearInterpolator());
             RPM_animation.setDuration(500);
             RPM_animation.setFillAfter(true);
             ((View) pointer).startAnimation(RPM_animation);
             prev_RPM = needle_value;
      }
      else {
       RotateAnimation RPM_animation = new RotateAnimation(prev_RPM, needle_value, 30, 97);
          RPM_animation.setInterpolator(new LinearInterpolator());
             RPM_animation.setDuration(500);
             RPM_animation.setFillAfter(true);
             ((View) pointer).startAnimation(RPM_animation);
             prev_RPM = needle_value;
      }
      
      String displayRPM = String.valueOf(RPM_value);
          RPM.setText(displayRPM);
 

}
else if((dataRecieved != null) && (dataRecieved.matches("\\s*[0-9A-Fa-f]{1,2} [0-9A-Fa-f]{2} [0-9A-Fa-f]{2}\\s*\r?\n?" ))) {

dataRecieved = dataRecieved.trim();
String[] bytes = dataRecieved.split(" ");

if((bytes[0] != null)&&(bytes[1] != null)&&(bytes[2] != null)) {

PID = Integer.parseInt(bytes[0].trim(), 16);
value = Integer.parseInt(bytes[1].trim(), 16);
value2 = Integer.parseInt(bytes[2].trim(), 16);
}


int RPM_value = ((value*256)+value2)/4;
int needle_value = ((RPM_value * 22)/1000) - 85;

if(prev_RPM == 0) {
 RotateAnimation RPM_animation = new RotateAnimation(-85, needle_value, 30, 97);
 RPM_animation.setInterpolator(new LinearInterpolator());
    RPM_animation.setDuration(500);
    RPM_animation.setFillAfter(true);
    ((View) pointer).startAnimation(RPM_animation);
    prev_RPM = needle_value;
}
else {
 RotateAnimation RPM_animation = new RotateAnimation(prev_RPM, needle_value, 30, 97);
 RPM_animation.setInterpolator(new LinearInterpolator());
    RPM_animation.setDuration(500);
    RPM_animation.setFillAfter(true);
    ((View) pointer).startAnimation(RPM_animation);
    prev_RPM = needle_value;
}

String displayRPM = String.valueOf(RPM_value);
 RPM.setText(displayRPM);

상대편이 보내는 값을 직접 출력을 하는 창에서는 제대로 출력이 되는데 이것을 변환 해서 다시 출력을 하면 출력이 되지 않고 있습니다....뭐가 잘 못인지...현재 OBD 스캔을 만들려고 하고 있는데...이 부분 때문에 완료를 못하고 있습니다...좋은 의견이 있으면 말씀 좀 해주시면 감사하겠습니다 ㅜㅜ

질문을 종료한 이유: 해결
안왕초보 (1,390 포인트) 님이 2014년 2월 19일 질문
안왕초보님이 2014년 3월 4일 closed

1개의 답변

0 추천
변환하는 부분에 문제가 있는 것 같네요.

 

위 코드가 변환하는 부분인가요? dataReceived, PID, value 등의 변수에 값은 들어가나요?
방귀과장 (18,940 포인트) 님이 2014년 2월 20일 답변
dataReceived는 String으로 비어 있는 상태이고 PID, value는 0으로 초기화 한 것 뿐입니다 ㅜㅜ
...