-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCanToCanToolMsg.java
More file actions
51 lines (47 loc) · 1.35 KB
/
CanToCanToolMsg.java
File metadata and controls
51 lines (47 loc) · 1.35 KB
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
package com.work.service;
import com.work.model.CAN;
public class CanToCanToolMsg {
//CAN解析为cantool信息
public static String canToCanToolMsg(CAN can) {
StringBuffer canToolMsg = new StringBuffer();
String CID = Integer.toHexString(can.getCID())+"";
String DLC = can.getDATA().length+"";
int[] data = can.getDATA();
canToolMsg.append("T")
.append(CID)
.append(DLC)
;
for (int i : data) {
if(i == 0) {//0的格式 CanTool格式数据中应该显示00,而不是0
canToolMsg.append("00");
continue;
}
canToolMsg.append(Integer.toHexString(i)+"");
}
return canToolMsg.toString();
}
public static void main(String[] args) {
CAN can1 = new CAN();
can1.setCID(0x3d);
can1.setDLC(0x08);
int[] DATA = {0x00,0x11,0x12,0x13,0x14,0x15,0x16,0x17};
can1.setDATA(DATA);
StringBuffer canToolMsg = new StringBuffer();
String CID = Integer.toHexString(can1.getCID())+"";
String DLC = can1.getDATA().length+"";
int[] data = can1.getDATA();
canToolMsg.append("T")
.append(CID)
.append(DLC)
;
for (int i : data) {
if(i == 0) {//0的格式 CanTool格式数据中应该显示00,而不是0
canToolMsg.append("00");
continue;
}else {
canToolMsg.append(Integer.toHexString(i)+"");
}
}
System.out.println(canToolMsg.toString());
}
}