/**
   * @param devices
   * @param defaultObdSN
   * @return 成功 或失败
   * @throws InterruptedException
   */
  private void cricleConnetOBD(ArrayList<BluetoothDevice> devices) throws InterruptedException {
    if (devices == null || devices.size() == 0) {
      // Log.d("testthread", "devices devices.size()==0");
      return;
    }

    for (final BluetoothDevice device : devices) {
      if (device.getAddress() == null) {
        continue;
      }

      boolean inMyList = false;
      OBDBindInfo obdInfo = null;
      for (int i = 0; i < TongGouApplication.obdLists.size(); i++) {
        obdInfo = TongGouApplication.obdLists.get(i);
        if (device.getAddress().equals(obdInfo.getObdSN())) {
          inMyList = true;
          break;
        }
      }
      if (!inMyList) {
        continue;
      }

      // Log.d("testthread", "circle connecting 111111111111");

      myBTService.connecting(device); // 连接obd

      synchronized (allowA) {
        allowA.wait();
      }

      // Log.d("testthread", "circle connecting 222222222222");

      if (!connectOBDSuccess) {
        continue;
      }

      // 连接成功
      // 读车辆vin 再做判定这个obd和车辆的绑定关系
      // Log.d("testthread", "circle readVin 111111111111");
      String currentConnectVin = readVinFromOBD();
      // Log.d("testthread", "circle readVin 222222222222:"+currentConnectVin);

      boolean bInMyVehicleList = false; // 是否在自己的车列表里
      boolean bBindNoChange = false; // 车与OBD关系是否不变
      if (currentConnectVin != null && obdInfo.getVehicleInfo() != null) {
        // 是否在自己的车列表里
        if (matchObdVin(currentConnectVin) || "".equals(currentConnectVin)) {
          bInMyVehicleList = true;
        } else {
          bInMyVehicleList = false;
        }
        if (!bInMyVehicleList) {
          // 断开
          stopConnect();
          continue;
        }

        String thisObdVin = obdInfo.getVehicleInfo().getVehicleVin(); // 这个obd上对应的车
        if (currentConnectVin.equals(thisObdVin)) { // 车与OBD关系是否不变
          bBindNoChange = true;
        }
        finishConnectOBD(
            obdInfo.getVehicleInfo().getVehicleBrand()
                + " "
                + obdInfo.getVehicleInfo().getVehicleModel(),
            currentConnectVin,
            obdInfo.getVehicleInfo().getVehicleModelId(),
            device.getAddress(),
            obdInfo.getVehicleInfo().getVehicleId());
        if (!bBindNoChange) {
          // 通知服务器!!!!!!!!新的obd和vin的绑定关系!!!!!!!!!!!
          // TODO
        }
        return;
      } else {
        // 断开
        stopConnect();
      }
    }
  }
Exemple #2
0
  public void saveSomeInformation(
      Context context,
      LoginResponse loginResponse,
      SharedPreferences sharedPreferences,
      String userID,
      String userPassword) {
    if (!TextUtils.isEmpty(userID)) {
      PreferenceUtil.putString(context, BaseActivity.SETTING_INFOS, BaseActivity.NAME, userID);
    }
    if (!TextUtils.isEmpty(userPassword)) {
      PreferenceUtil.putString(
          context, BaseActivity.SETTING_INFOS, BaseActivity.PASSWORD, userPassword);
    }
    // if(imageVersion!=null&&!"".equals(imageVersion)){
    // sharedPreferences.edit()
    // .putString(BaseActivity.SCREEN, imageVersion).commit();
    // }

    // sharedPreferences.edit().putBoolean(BaseActivity.LOGINED,
    // true).commit();

    // obdLists = loginParser.getLoginResponse().getObdList();
    // mLoginHandler.sendEmptyMessage(0);
    setLogin(true);
    AppConfig appConfig = loginResponse.getAppConfig();
    if (appConfig != null) {
      String obdReadInterval = appConfig.getObdReadInterval();
      if (obdReadInterval != null && !"".equals(obdReadInterval)) {
        sharedPreferences
            .edit()
            .putString(BaseActivity.APPCONFIG_OBD_READ_INTERVAL, obdReadInterval)
            .commit();
      }
      String serverReadInterval = appConfig.getServerReadInterval();
      if (serverReadInterval != null && !"".equals(serverReadInterval)) {
        sharedPreferences
            .edit()
            .putString(BaseActivity.APPCONFIG_SERVER_READ_INTERVAL, serverReadInterval)
            .commit();
      }
      String mileageInformInterval = appConfig.getMileageInformInterval();
      if (mileageInformInterval != null && !"".equals(mileageInformInterval)) {
        sharedPreferences
            .edit()
            .putString(BaseActivity.APPCONFIG_MILEAGE_INFORM_INTERVAL, mileageInformInterval)
            .commit();
      }

      String appVehicleErrorCodeWarnIntervals = appConfig.getAppVehicleErrorCodeWarnIntervals();
      if (appVehicleErrorCodeWarnIntervals != null
          && !"".equals(appVehicleErrorCodeWarnIntervals)) {
        sharedPreferences
            .edit()
            .putString(
                BaseActivity.APPCONFIG_ERROR_ALERT_INTERVAL, appVehicleErrorCodeWarnIntervals)
            .commit();
      }

      String remainOilMassWarn = appConfig.getRemainOilMassWarn();
      if (remainOilMassWarn != null && !"".equals(remainOilMassWarn)) {
        // sharedPreferences.edit().putString(BaseActivity.APPCONFIG_OIL_ALERT_INTERVAL,
        // remainOilMassWarn).commit();
        if (remainOilMassWarn.indexOf("_") != -1) {
          try {
            TongGouService.interOne =
                Integer.parseInt(remainOilMassWarn.substring(0, remainOilMassWarn.indexOf("_")));
            TongGouService.interTwo =
                Integer.parseInt(remainOilMassWarn.substring(remainOilMassWarn.indexOf("_") + 1));
          } catch (NumberFormatException er) {
          }
        }
      }
    }

    List<OBDBindInfo> obdList = loginResponse.getObdList();
    List<VehicleInfo> vehicleList = new ArrayList<VehicleInfo>();
    for (OBDBindInfo obd : obdList) {
      VehicleInfo vehicleInfo = obd.getVehicleInfo();
      if (vehicleInfo != null) {
        vehicleInfo.setObdSN(obd.getObdSN());
        vehicleList.add(vehicleInfo);
      }
    }
    PreferenceUtil.remove(this, BaseActivity.SETTING_INFOS, BaseActivity.BRAND);
    PreferenceUtil.remove(this, BaseActivity.SETTING_INFOS, BaseActivity.MODEL);
    PreferenceUtil.remove(this, BaseActivity.SETTING_INFOS, BaseActivity.VEHICLENUM);
    PreferenceUtil.remove(this, BaseActivity.SETTING_INFOS, BaseActivity.VEHICLE_MODE_ID);
    if (vehicleList.isEmpty()) {
      queryVehicleList(context);

    } else {
      setDefaultVehicleBindOBDs(vehicleList);
    }
    // doScanOBDAndPulling();

  }