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 스캔을 만들려고 하고 있는데...이 부분 때문에 완료를 못하고 있습니다...좋은 의견이 있으면 말씀 좀 해주시면 감사하겠습니다 ㅜㅜ