예제 #1
0
  /**
   * This method gets called by the broadcast receiver, for bluetooth devices which are "OBD"
   * devices. This takes care of any necessary actions to open a connection to the specified device.
   * Run synchronized in case the discovery process throws us multiple devices. We only want the
   * first valid one.
   *
   * @param deviceMACAddress
   * @return - true on success, false otherwise.
   */
  private synchronized boolean setupSession(String deviceMACAddress) {
    // If there's an existing hybrid session, shut it down.
    if (hs != null) {
      hs.shutdown();
    }

    // instantiate dashDB if necessary.
    if (ddb == null) {
      msg("Spinning up DashDB...");
      ddb = new DashDB(MainActivity.this);
      msg("DashDB Ready.");
    }

    msg("Setting up hybridSession. It will now establish a bluetooth connection.");

    aHelper.setLastUsedMAC(deviceMACAddress);

    // instantiate hybridsession, which is just a class that controls
    // subclasses such as Monitorsession and OBDSession, that communicate
    // with the network in different ways.
    hs =
        new HybridSession(
            BluetoothAdapter.getDefaultAdapter(),
            deviceMACAddress,
            ddb,
            mLocalecbOOBMessageHandler);
    // after hybridsession is successful at opening the bluetooth
    // connection, we will get an OOB notification that the IO state changed
    // to "1".

    // Sets the session type to OBD2. nothing fancy.
    // hs.setActiveSession(HybridSession.SESSION_TYPE_OBD2);

    // register a method to be called when new data arrives.
    hs.registerDPArrivedCallback(mLocalDPNArrivedHandler);

    mBTPeerAddr = deviceMACAddress;

    return true;
  }
예제 #2
0
  protected void onDestroy() {
    super.onDestroy();

    // give hs a chance to properly close the network/bluetooth link.
    if (hs != null) hs.shutdown();
  };