private void saveCommonFaultDic() { List<FaultCodeInfo> faultCodeList = getFaultCodeList(); String version = getCommonFaultDicVersion(); if (faultCodeList != null && faultCodeList.size() > 0) { SaveDB.getSaveDB(this).updateFaultCode("common", version, faultCodeList, true); } if (mCommonFaultDicDB.isOpen()) { mCommonFaultDicDB.close(); mCommonFaultDicDB = null; } }
private List<FaultCodeInfo> getFaultCodeList() { List<FaultCodeInfo> faultCodeList = null; if (mCommonFaultDicDB.isOpen()) { Cursor query = mCommonFaultDicDB.query(SaveDB.DICTIONARY_TABLE_NAME, null, null, null, null, null, null); faultCodeList = new ArrayList<FaultCodeInfo>(); while (query.moveToNext()) { faultCodeList.add(SaveDB.getFaultInfoFromCursor(query)); } query.close(); } return faultCodeList; }
/** * 处理收到的故障码,生成车况提示信息 * * @param codeStrs 类似:pu003,pu9999 */ private void prosseingOBDError(final String codeStrs) { if (!TongGouApplication.connetedOBD || codeStrs == null || "".equals(codeStrs)) { return; } String userID = getSharedPreferences(BaseActivity.SETTING_INFOS, 0).getString(BaseActivity.NAME, ""); String modleId = getSharedPreferences(BaseActivity.SETTING_INFOS, 0) .getString(BaseActivity.VEHICLE_MODE_ID, "NULL"); String[] errors = codeStrs.split(","); // errors[0] = "P0403"; for (int i = 0; i < errors.length; i++) { if (errors[i].indexOf("#") != -1) { continue; } ArrayList<FaultCodeInfo> modleFaults = SaveDB.getSaveDB(this).getSomeFaultCodesById(modleId, errors[i]); if (modleFaults == null || modleFaults.size() == 0) { modleFaults = SaveDB.getSaveDB(this).getSomeFaultCodesById("common", errors[i]); } if (modleFaults != null && modleFaults.size() > 0) { FaultCodeInfo oneFault = modleFaults.get(0); CarCondition oneConditionMessage = new CarCondition(); oneConditionMessage.setAlarmId(System.currentTimeMillis() + ""); oneConditionMessage.setUserID(userID); oneConditionMessage.setFaultCode(oneFault.getFaultCode()); if (modleFaults.size() >= 2) { // 两条以上 StringBuffer sber = new StringBuffer(); for (int j = 0; j < modleFaults.size(); j++) { sber.append(modleFaults.get(j).getDescription()); sber.append("\n"); } oneConditionMessage.setContent(sber.toString()); } else { oneConditionMessage.setContent(oneFault.getDescription()); } oneConditionMessage.setReportTime(System.currentTimeMillis() + ""); oneConditionMessage.setVehicleVin(TongGouApplication.connetedVIN); SaveDB.getSaveDB(this).saveAlarm(oneConditionMessage); // 保存到数据库 } else { CarCondition oneConditionMessage = new CarCondition(); oneConditionMessage.setAlarmId(System.currentTimeMillis() + ""); oneConditionMessage.setUserID( getSharedPreferences(BaseActivity.SETTING_INFOS, 0).getString(BaseActivity.NAME, "")); oneConditionMessage.setFaultCode(errors[i]); oneConditionMessage.setContent("不能识别的故障码"); oneConditionMessage.setReportTime(System.currentTimeMillis() + ""); oneConditionMessage.setVehicleVin(TongGouApplication.connetedVIN); SaveDB.getSaveDB(this).saveAlarm(oneConditionMessage); // 保存到数据库 } } if (errors.length > 0) { // 提示用户 SharedPreferences settingPres = getSharedPreferences(BaseActivity.SETTING_INFOS, 0); if (settingPres != null && settingPres.getBoolean(BaseActivity.LOGINED, false)) { // 如果是登录状态 Intent intent = new Intent(this, CarErrorActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } else { Intent toLogin = new Intent(this, PreLoginActivity.class); toLogin.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(toLogin); } new Thread() { public void run() { sendVehicleProblem(codeStrs); } }.start(); } }