-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDTCInfo.java
61 lines (52 loc) · 1.6 KB
/
DTCInfo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package DTCController;
public class DTCInfo {
int nbDTC; // Number of DTC
int faultPathAddr; // Fault path (list of [4xUWORD])
int codeAddr; // Fault code (list of [UWORD])
int classAddr; // Fault class (list of [UBYTE])
int envAddr; // Fault environment (list ot [5xUBYTE])
int defClassAddr; // Start of class definition
/**
* Return string representation of a DTC Info
* @param b1 First byte
* @param b2 Second byte
*/
public static String getStr(byte b1,byte b2) {
StringBuffer code = new StringBuffer();
int c0 = (((int)b1 & 0xC0) >> 6) & 0x0F;
int c1 = (((int)b1 & 0x30) >> 4) & 0x0F;
switch (c0) {
case 0:
code.append('P');
break;
case 1:
code.append('C');
break;
case 2:
code.append('B');
break;
case 3:
code.append('U');
break;
}
code.append(Integer.toString(c1));
code.append(Integer.toString(((int)b1) & 0x0F));
code.append(String.format("%02X",b2));
return code.toString();
}
public static String getEnvStr(byte env) {
int envIdx = (((int) env) & 0xFF);
return DTCEnv.sigNames[envIdx];
}
@Override
public String toString() {
return "DTC{" +
"nbDTC=" + nbDTC +
", faultPathAddr=" + String.format("%06X",faultPathAddr) +
", codeAddr=" + String.format("%06X",codeAddr) +
", classAddr="+ String.format("%06X",classAddr) +
", envAddr="+ String.format("%06X",envAddr) +
", defClassAddr="+ String.format("%06X",defClassAddr) +
'}';
}
}