in tools/android-app/app/src/main/java/com/aws/iotfleetwise/Elm327.java [111:160]
private List<String> receiveResponse(int timeout, String request) throws IOException {
InputStream inputStream = mSocket.getInputStream();
List<String> result = new ArrayList<>();
StringBuilder lineBuilder = new StringBuilder();
int timeoutLeft = timeout;
while (true) {
if (inputStream.available() == 0) {
if (timeoutLeft <= 0) {
if (timeout > 0) {
Log.e("ELM327.rx", "timeout");
}
return null;
}
try {
Thread.sleep(TIMEOUT_POLL_MS);
timeoutLeft -= TIMEOUT_POLL_MS;
} catch (InterruptedException e) {
// Carry on
}
continue;
}
char chr = (char)inputStream.read();
switch (chr) {
case '>':
return result;
case '\n':
case '\r':
String line = lineBuilder.toString();
lineBuilder.setLength(0);
if (line.equals("?")) {
Log.e("ELM327.rx", line);
return null;
}
else if (line.equals("SEARCHING...")) {
Log.d("ELM327.rx", line);
}
else if (line.equals("") || line.equals(request)) {
// Ignore blank lines or the echoed command
}
else {
Log.i("ELM327.rx", line);
result.add(line);
}
break;
default:
lineBuilder.append(chr);
break;
}
}
}