public ConnectedThread(BluetoothSocket socket, BFVService service) {

    this.service = service;

    Log.d(BFVService.TAG, "create ConnectedThread");
    mmSocket = socket;
    InputStream tmpIn = null;
    OutputStream tmpOut = null;
    BufferedReader tmpReader = null;

    // Get the BluetoothSocket input and output streams
    try {
      tmpIn = socket.getInputStream();
      tmpOut = socket.getOutputStream();
      tmpReader = new BufferedReader(new InputStreamReader(tmpIn), 256);
    } catch (IOException e) {
      Log.e(BFVService.TAG, "temp sockets not created", e);
    }

    mmOutStream = tmpOut;
    mmReader = tmpReader;

    chargeFromVolts = new PiecewiseLinearFunction(new Point2d(3.6, 0.0));
    chargeFromVolts.addNewPoint(new Point2d(3.682, 0.032));
    chargeFromVolts.addNewPoint(new Point2d(3.696, 0.124));
    chargeFromVolts.addNewPoint(new Point2d(3.75, 0.212));
    chargeFromVolts.addNewPoint(new Point2d(3.875, 0.624));
    chargeFromVolts.addNewPoint(new Point2d(3.96, 0.73));
    chargeFromVolts.addNewPoint(new Point2d(4.16, 1.0));

    firstPressure = false;
  }
  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;
    }
  }