예제 #1
0
        @Override
        public void onOOBDataArrived(String dataName, String dataValue) {
          msg("(OOB Message) " + dataName + "=" + dataValue);

          // state change?
          if (dataName.equals(OOBMessageTypes.IO_STATE_CHANGE)) {
            int newState = 0;
            try {
              newState = Integer.valueOf(dataValue);
              ioStateChanged(newState);
            } catch (Exception e) {
              msg(
                  "ERROR: Could not interpret new state as string: "
                      + dataValue
                      + " E="
                      + e.getMessage());
            }
          } // end of "if this was a io state change".

          // Bluetooth unable to connect to peer?
          if (dataName.equals(OOBMessageTypes.BLUETOOTH_FAILED_CONNECT)) {

            if (dataValue.equals("0")) {
              msg("Unable to find peer. Searching for nearby OBD adapters.");
              aHelper.startDiscovering();
            }
          }

          // session state change?
          if (dataName.equals(OOBMessageTypes.SESSION_STATE_CHANGE)) {
            int newState = 0;

            // convert from string to integer.
            try {
              newState = Integer.valueOf(dataValue);
            } catch (NumberFormatException e) {
              return;
            }

            // just connected?
            if (newState >= OBD2Session.STATE_OBDCONNECTED) {
              msg("Just connected - adding SPEED DPN to routinescan.");

              // Add some datapoints to the "routine scan" which is an
              // automatic loop that continuously scans those PIDs.
              hs.getRoutineScan().addDPN("SPEED");
              hs.getRoutineScan().addDPN("RPM");
            } else {
              msg("Just disconnected. removing all DPNs from routinescan.");
              hs.getRoutineScan().removeAllDPNs();
            }
          } // end of session state change handler.

          // Did we just perform detection stuff?
          if (dataName.equals(OOBMessageTypes.AUTODETECT_SUMMARY)) {
            if (hs.isDetectionValid() != true) return;

            SetupSessionBasedOnCapabilities();
          } // end of "if this is a autodetect summary"
        } // end of OOB event arrived handler function definition.
예제 #2
0
  /**
   * Call this method upon connecting. We'll see what the capabilities are and set up the
   * appropriate session.
   */
  private void SetupSessionBasedOnCapabilities() {

    if (hs.isDetectionValid() != true) {
      return;
    }

    if (hs.isHardwareSniffable() == true) {
      msg("Monitor is supported! Switching to monitor mode.");
      hs.setActiveSession(HybridSession.SESSION_TYPE_MONITOR);
      // at this point, monitor mode is active and it will automatically detect the network if
      // available.

    } else {
      msg("Monitor mode not supported so we'll enable OBD2 scanning.");

      // switch to OBD2 communications mode
      hs.setActiveSession(HybridSession.SESSION_TYPE_OBD2);

      // sanity check
      if (hs.getRoutineScan() == null) return;

      // add one or more datapoints to the routine scan class so that it actively scans that PID to
      // generate DPN arrived events.
      hs.getRoutineScan().addDPN("RPM");
    }

    //		// OBD2?
    //		if (hs.isDetectionValid() == true) {
    //			msg("Detection was successful, switching to OBD mode and adding a few datapoints to the
    // scan...");
    //			// switch to OBD mode.
    //			hs.setActiveSession(HybridSession.SESSION_TYPE_OBD2);
    //
    //			// start with a clean slate
    //			hs.getRoutineScan().removeAllDPNs();
    //			// add speed and RPM to the routinescan. Routinescan will
    //			// continuously request PIDs and as they are decoded, the
    //			// DPDecoded event will fire.
    //			hs.getRoutineScan().addDPN("SPEED");
    //			hs.getRoutineScan().addDPN("RPM");
    //		}

  }