public void run() { // Log.i(BFVService.TAG, "BEGIN mConnectedThread"); String line = null; while (true) { try { // Read from the InputStream line = mmReader.readLine(); this.handleLine(line); } catch (IOException e) { Log.d(BFVService.TAG, "disconnected", e); service.connectionLost(); break; } } }
public void handleLine(String line) { try { if (line == null || service == null) { return; } String[] split = line.split(" "); if (split[0] == null) { return; } if (split[0].equals("PRS")) { if (this.lastUpdateType == UPDATE_BAT) { time = 0.04; } else { time = 0.02; } this.lastUpdateType = UPDATE_PRS; int pressure = Integer.parseInt(split[1], 16); service.updatePressure(pressure, time); if (!firstPressure) { service.firstPressure(); firstPressure = true; } if (split.length > 2) { int pressure2 = Integer.parseInt(split[2], 16); service.updatePitotPressures(pressure2, pressure); } } else if (split[0].equals("TMP")) { this.lastUpdateType = UPDATE_TMP; service.updateTemperature(Integer.parseInt(split[1])); } else if (split[0].equals("BAT")) { this.lastUpdateType = UPDATE_BAT; int bat = Integer.parseInt(split[1], 16); // bat is in mV service.updateBattery(chargeFromVolts.getValue(bat / 1000.0)); } else if (split[0].equals("BFV")) { this.lastUpdateType = UPDATE_VER; try { int ver = Integer.parseInt(split[1]); service.setHardwareVersion(ver); } catch (NumberFormatException e) { service.setHardwareVersion(0); } } else if (split[0].equals("BST")) { this.lastUpdateType = UPDATE_KEYS; service.updateHardwareSettingsKeys(line); } else if (split[0].equals("SET")) { this.lastUpdateType = UPDATE_VALUES; service.updateHardwareSettingsValues(line); } } catch (NumberFormatException e) { return; } }