Esempio n. 1
0
  // [System][Manufacturer][SubSystem][Problem] eg. "P0071" Powertrain
  // References:
  //   http://www.obd-codes.com/trouble_codes/
  //   http://obdcon.sourceforge.net/2010/06/obd-ii-pids/
  public static long EncodeFault_OBDII(String dtcStr) {
    long faultCode = TYPE_OBDII;

    /* trim */
    dtcStr = StringTools.trim(dtcStr);
    if (dtcStr.indexOf(",") >= 0) {
      dtcStr = dtcStr.substring(0, dtcStr.indexOf(",")).trim();
    }
    if (dtcStr.equals("")) {
      return faultCode;
    }

    /* check length */
    if (dtcStr.length() == 4) {
      dtcStr = "U" + dtcStr; // unknown
    } else if (dtcStr.length() != 5) {
      return faultCode;
    }

    /* active */
    faultCode |= EncodeActive(true); // [ACTIVE_MASK]    0x0100000000000000

    /* encode system cjaracter (ie. "Powertrain") */
    faultCode |= EncodeSystem(dtcStr.charAt(0)); // [MID_MASK]       0x00FFFFFF00000000

    /* encode manufacturer specific and subsystem */
    int mfgCode = StringTools.parseInt(dtcStr.substring(1, 2), 0);
    int spid = (mfgCode != 0) ? 0x8000 : 0;
    int subSys = StringTools.parseInt(dtcStr.substring(2, 5), 0);
    spid |= (subSys & 0xFFF);
    faultCode |= EncodeSPID(spid); // [SPID_MASK]      0x00000000FFFF0000

    /* return fault code */
    return faultCode;
  }
Esempio n. 2
0
 public Field(String s) {
   String f[] = StringTools.parseString(s, FIELD_VALUE_SEPARATOR);
   if ((f.length > 0) && (f[0].length() > 0) && Character.isLetter(f[0].charAt(0))) {
     this.isHiRes = (f.length > 0) ? f[0].equalsIgnoreCase("H") : false;
     this.type = (f.length > 1) ? StringTools.parseInt(f[1], -1) : -1;
   } else {
     this.type = (f.length > 0) ? StringTools.parseInt(f[0], -1) : -1;
     this.isHiRes = (f.length > 1) ? f[1].equalsIgnoreCase("H") : false;
   }
   this.index = (f.length > 2) ? StringTools.parseInt(f[2], 0) : 0;
   this.length = (f.length > 3) ? StringTools.parseInt(f[3], 0) : 0;
   this.isValid = (f.length == 4) && (this.type >= 0) && (this.index >= 0) && (this.length > 0);
 }