Esempio n. 1
0
 /* encode "type=<type> ..." into long value */
 public static long EncodeFault(RTProperties rtp) {
   String type = rtp.getString(PROP_TYPE, null);
   if (type.equalsIgnoreCase(NAME_J1708)) {
     int mid = rtp.getInt(PROP_MID, 0);
     int sid = rtp.getInt(PROP_SID, -1);
     int pid = rtp.getInt(PROP_PID, -1);
     int pidSid = (sid >= 0) ? sid : pid;
     int fmi = rtp.getInt(PROP_FMI, 0);
     int count = rtp.getInt(PROP_COUNT, 0);
     boolean active = rtp.getBoolean(PROP_ACTIVE, true);
     return EncodeFault_J1708(mid, (sid >= 0), pidSid, fmi, count, active);
   } else if (type.equalsIgnoreCase(NAME_J1939)) {
     int spn = rtp.getInt(PROP_SPN, 0);
     int fmi = rtp.getInt(PROP_FMI, 0);
     int count = rtp.getInt(PROP_COUNT, 0);
     boolean active = rtp.getBoolean(PROP_ACTIVE, true);
     return EncodeFault_J1939(spn, fmi, count);
   } else if (type.equalsIgnoreCase(NAME_OBDII)) {
     String dtc = rtp.getString(PROP_DTC, ""); // "P0071"
     return EncodeFault_OBDII(dtc);
   } else {
     return 0L;
   }
 }
Esempio n. 2
0
 /* return string representation of fault code */
 public static String GetFaultString(RTProperties fault) {
   if (fault != null) {
     StringBuffer sb = new StringBuffer();
     String type = fault.getString(PROP_TYPE, "");
     if (type.equalsIgnoreCase(NAME_J1708)) {
       // J1708: type=j1708 mil=1 mid=123 pid=123 fmi=1 count=1 active=false
       // SID: "128/s123/1"
       // PID: "128/123/1"
       boolean active = fault.getBoolean(PROP_ACTIVE, true);
       int mid = fault.getInt(PROP_MID, 0);
       int fmi = fault.getInt(PROP_FMI, 0);
       if (!active) {
         sb.append("[");
       }
       sb.append(mid); // MID
       sb.append("/");
       if (fault.hasProperty(PROP_SID)) {
         int sid = fault.getInt(PROP_SID, 0);
         sb.append("s").append(sid); // SID "128/s123/1"
       } else {
         int pid = fault.getInt(PROP_PID, 0);
         sb.append(pid); // PID "128/123/1"
       }
       sb.append("/");
       sb.append(fmi); // FMI
       if (!active) {
         sb.append("]");
       }
       return sb.toString();
     } else if (type.equalsIgnoreCase(NAME_J1939)) {
       // J1939: type=i1939 mil=1 spn=1234 fmi=12 count=1 active=false
       // SPN: "128/1"
       boolean active = fault.getBoolean(PROP_ACTIVE, true);
       int spn = fault.getInt(PROP_SPN, 0);
       int fmi = fault.getInt(PROP_FMI, 0);
       if (!active) {
         sb.append("[");
       }
       sb.append(spn); // SPN
       sb.append("/");
       sb.append(fmi); // FMI
       if (!active) {
         sb.append("]");
       }
       return sb.toString();
     } else if (type.equalsIgnoreCase(NAME_OBDII)) {
       // OBDII: type=obdii mil=1 dtc=P0071
       // DTC: "P0071" [was "024C"]
       boolean active = fault.getBoolean(PROP_ACTIVE, true);
       String dtcStr = fault.getString(PROP_DTC, ""); // ie "P0123,P0321,P1234"
       if (!StringTools.isBlank(dtcStr)) {
         if (!active) {
           sb.append("[");
         }
         sb.append(dtcStr);
         if (!active) {
           sb.append("]");
         }
       }
       return sb.toString();
     } else {
       // unrecognized
     }
   }
   return "";
 }