forked from funk222/Cruise_ECU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendfakemsg.ino
202 lines (187 loc) · 4.38 KB
/
sendfakemsg.ino
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
void comma_communication() {
//________________send Fingerprint msgs
for (int ii = 0; ii < 3; ii++) {
CAN.beginPacket(addr[ii]);
for (int i = 0; i < 8; i++) {
CAN.write(data[i]);
}
CAN.endPacket();
}
//________________0x1d2 msg PCM_CRUISE
uint8_t dat[8];
dat[0] = (flag2 << 5) & 0x20 | (!gas_pedal_state << 4) & 0x10;
dat[1] = 0x0;
dat[2] = 0x0;
dat[3] = 0x0;
dat[4] = 0x0;
dat[5] = 0x0;
dat[6] = (flag2 << 7) & 0x80;
dat[7] = can_cksum(dat, 7, 0x1d2);
CAN.beginPacket(0x1d2);
for (int ii = 0; ii < 8; ii++) {
CAN.write(dat[ii]);
}
CAN.endPacket();
//________________0x1d3 msg PCM_CRUISE_2
uint8_t dat2[8];
dat2[0] = 0x0;
dat2[1] = (flag1 << 7) & 0x80 | 0x28;
dat2[2] = set_speed;
dat2[3] = 0x0;
dat2[4] = 0x0;
dat2[5] = 0x0;
dat2[6] = 0x0;
dat2[7] = can_cksum(dat2, 7, 0x1d3);
CAN.beginPacket(0x1d3);
for (int ii = 0; ii < 8; ii++) {
CAN.write(dat2[ii]);
}
CAN.endPacket();
//________________0xaa msg defaults 1a 6f WHEEL_SPEEDS
uint8_t dat3[8];
uint16_t wheelspeed = 0x1a6f + (average * 100);
dat3[0] = (wheelspeed >> 8) & 0xFF;
dat3[1] = (wheelspeed >> 0) & 0xFF;
dat3[2] = (wheelspeed >> 8) & 0xFF;
dat3[3] = (wheelspeed >> 0) & 0xFF;
dat3[4] = (wheelspeed >> 8) & 0xFF;
dat3[5] = (wheelspeed >> 0) & 0xFF;
dat3[6] = (wheelspeed >> 8) & 0xFF;
dat3[7] = (wheelspeed >> 0) & 0xFF;
CAN.beginPacket(0xaa);
for (int ii = 0; ii < 8; ii++) {
CAN.write(dat3[ii]);
}
CAN.endPacket();
//________________0x3b7 msg ESP_CONTROL
uint8_t dat5[8];
dat5[0] = 0x0;
dat5[1] = 0x0;
dat5[2] = 0x0;
dat5[3] = 0x0;
dat5[4] = 0x0;
dat5[5] = 0x0;
dat5[6] = 0x0;
dat5[7] = 0x08;
CAN.beginPacket(0x3b7);
for (int ii = 0; ii < 8; ii++) {
CAN.write(dat5[ii]);
}
CAN.endPacket();
//________________0x620 msg STEATS_DOORS
uint8_t dat6[8];
dat6[0] = 0x10;
dat6[1] = 0x0;
dat6[2] = 0x0;
dat6[3] = 0x1d;
dat6[4] = 0xb0;
dat6[5] = 0x40;
dat6[6] = 0x0;
dat6[7] = 0x0;
CAN.beginPacket(0x620);
for (int ii = 0; ii < 8; ii++) {
CAN.write(dat6[ii]);
}
CAN.endPacket();
//________________0x3bc msg GEAR_PACKET
uint8_t dat7[8];
dat7[0] = 0x0;
dat7[1] = 0x0;
dat7[2] = 0x0;
dat7[3] = 0x0;
dat7[4] = 0x0;
dat7[5] = 0x80;
dat7[6] = 0x0;
dat7[7] = 0x0;
CAN.beginPacket(0x3bc);
for (int ii = 0; ii < 8; ii++) {
CAN.write(dat7[ii]);
}
CAN.endPacket();
//________________0x2c1 msg GAS_PEDAL
uint8_t dat10[8];
dat10[0] = (!gas_pedal_state << 3) & 0x08;
dat10[1] = 0x0;
dat10[2] = 0x0;
dat10[3] = 0x0;
dat10[4] = 0x0;
dat10[5] = 0x0;
dat10[6] = 0x0;
dat10[7] = 0x0;
CAN.beginPacket(0x2c1);
for (int ii = 0; ii < 8; ii++) {
CAN.write(dat10[ii]);
}
CAN.endPacket();
//________________0x224 msg fake brake module
uint8_t dat11[8];
dat11[0] = 0x0;
dat11[1] = 0x0;
dat11[2] = 0x0;
dat11[3] = 0x0;
dat11[4] = 0x0;
dat11[5] = 0x0;
dat11[6] = 0x0;
dat11[7] = 0x8;
CAN.beginPacket(0x224);
for (int ii = 0; ii < 8; ii++) {
CAN.write(dat11[ii]);
}
CAN.endPacket();
//________________send 0x262 fake EPS_STATUS
uint8_t dat262[8];
dat262[0] = 0x0;
dat262[1] = 0x18;
dat262[2] = 0x0;
dat262[3] = (LKA_STATE << 7) & 0x40 | (TYPE << 0) & 0x1;
dat262[4] = can_cksum(dat262, 7, 0x262);
CAN.beginPacket(0x262);
for (int ii = 0; ii < 5; ii++) {
CAN.write(dat262[ii]);
}
CAN.endPacket();
//________________0x25 fake STEER_ANGLE
uint8_t dat25[8];
dat25[0] = 0x0f;
dat25[1] = 0xff;
dat25[2] = 0x00;
dat25[3] = 0x01;
dat25[4] = 0xc0;
dat25[5] = 0x03;
dat25[6] = 0x00;
dat25[7] = 0xff;
CAN.beginPacket(0x25);
for (int ii = 0; ii < 8; ii++) {
CAN.write(dat25[ii]);
}
CAN.endPacket();
//________________0x260 fake STEER_TORQUE_SENSOR
uint8_t dat9[8];
dat9[0] = 0x08;
dat9[1] = 0xff;
dat9[2] = 0xfb;
dat9[3] = 0x0;
dat9[4] = 0x0;
dat9[5] = 0xff;
dat9[6] = 0xdc;
dat9[7] = 0x47;
CAN.beginPacket(0x260);
for (int ii = 0; ii < 8; ii++) {
CAN.write(dat9[ii]);
}
CAN.endPacket();
//________________0x423 fake EPS message
CAN.beginPacket(0x423);
CAN.write(0x00);
CAN.endPacket();
}
//TOYOTA CAN CHECKSUM
int can_cksum (uint8_t *dat, uint8_t len, uint16_t addr) {
uint8_t checksum = 0;
checksum = ((addr & 0xFF00) >> 8) + (addr & 0x00FF) + len + 1;
//uint16_t temp_msg = msg;
for (int ii = 0; ii < len; ii++) {
checksum += (dat[ii]);
}
return checksum;
}