forked from daftracing/DaftRS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flash_rdu.py
executable file
·161 lines (131 loc) · 4.57 KB
/
flash_rdu.py
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
#!/usr/bin/env python3
"""
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>.
"""
import sys
sys.path.append('./tools')
from tools.vbflasher import Vbflasher
from helpers.carloop import *
def warning():
debug('''
[*] WARNING: DON'T LET THE LAPTOP FALL ASLEEP!!! Move mouse, etc. Breaking the flashing process can brick the module!
[!] Make sure that:
- The car is connected to an external power source
- Laptop is sufficiently charged / plugged to an external power source
- Laptop will not fall asleep/hibernate/etc during this process (power management settings on the host machine)
- You have the internet connection
[?] Do you wish to continue? (y/N) ''', end='')
if input().lower() != 'y':
return False
debug('''
[>] Great! Please follow the steps below:
1. Connect your Particle device to the computer's USB port but DO NOT plug it to the OBD port just yet
2. Connect it to this Virtual Machine (select Virtual Machine -> USB -> Connect Particle from the menu)
3. If you got your Carloop preflashed from DaftRacing it should be fading Gray by now.
[?] Hit return when ready... ''', end='')
input()
return True
def choose_calibration():
platform = [
"Ford Focus RS",
"Lincoln MKZ"
]
debug('\n[ ] Select platform:')
i = 0
for p in platform:
debug("\t[{}] {}".format(i, p))
i += 1
debug("[?] Type 0-{} and hit return... ".format(i-1), end='')
p = int(input())
calibrations = [
[
[ 'Stock', 'G1F7-14C366-AL.vbf'],
[ 'DaftRDU T5 (+12%, 1700Nm limit)', 'G1F7-14C366-AL-DAFT-T5.vbf' ],
[ 'DaftRDU T16 (LC: 2x1300Nm; +12%, 1700Nm limit)', 'G1F7-14C366-AL-DAFT-T16.vbf' ],
[ 'DaftRDU T11 [EXP] (+25%, SWVEC OFF, 1700Nm limit)', 'G1F7-14C366-AL-DAFT-T11.vbf' ],
[ 'DaftRDU T13 [EXP] (+25%, SWVEC ON, 1700Nm limit)', 'G1F7-14C366-AL-DAFT-T13.vbf' ],
[ 'DaftRDU T14 [EXP] (+12%, uncapped)', 'G1F7-14C366-AL-DAFT-T14.vbf' ],
[ 'DaftRDU T15 [EXP] (+25%, uncapped)', 'G1F7-14C366-AL-DAFT-T15.vbf' ],
[ 'DaftRDU T18 [EXP] (LC: 2x1300Nm, +12%, uncapped)', 'G1F7-14C366-AL-DAFT-T18.vbf' ],
[ 'DaftRDU X1 [CRAZY] (+50%, SWVEC OFF, uncapped)', 'G1F7-14C366-AL-DAFT-X1.vbf' ],
],
[
[ 'Stock', 'HP57-14C366-AG.vbf'],
[ 'DaftRDU T1 (+12%, 1700Nm limit)', 'HP57-14C366-AG-DAFT-T1.vbf' ],
]
]
debug('\n[ ] Which calibration to flash?')
i = 0
for c in calibrations[p]:
debug("\t[{}] {}".format(i, c[0]))
i += 1
debug("[?] Type 0-{} and hit return... ".format(i-1), end='')
c = input()
datasets = [
[
[ 'Stock', 'G1F7-14C367-AL.vbf' ],
[ 'DaftRDU DS1 (170C RDU Oil Temp Limit)', 'G1F7-14C367-AL-DAFT-DS1.vbf' ],
[ 'DaftRDU DS3 (FWD in Normal DM + 170C)', 'G1F7-14C367-AL-DAFT-DS3.vbf' ]
],
[
[ 'Stock', 'HP57-14C367-AG.vbf' ]
]
]
debug('\n[ ] Which parameter set to flash?')
i = 0
for d in datasets[p]:
debug("\t[{}] {}".format(i, d[0]))
i += 1
debug("[?] Type 0-{} and hit return... ".format(i-1), end='')
d = input()
try:
r = [calibrations[p][int(c)], datasets[p][int(d)]]
except ValueError:
debug('[!] Invalid calibration / parameters selected')
return None
except IndexError:
debug('[!] Invalid calibration / parameters selected')
return None
return r
def main():
if not warning():
return
if not carloop_init("HSCAN"):
return
v = choose_calibration()
if not v:
return
debug('''\n[>] All set, we are good to go!
1. Connect Carloop device to the OBD diagnostic port
2. Turn ON the ignition but do NOT start the engine
3. Hit return when ready to flash {} / {}'''.format(v[0][0], v[1][0]))
input()
try:
flasher = Vbflasher(can_interface = 'slcan0', sbl_path='vbf/G1F7-14C368-AA.vbf', exe_path='vbf/{}'.format(v[0][1]), \
data_path='vbf/{}'.format(v[1][1]))
except OSError as e:
enum = e.args[0]
if enum == 19:
debug('[!] Unable to open slcan0 device')
return
debug("\n[+] Successfully opened slcan0")
flasher.start()
flasher.flash()
flasher.ver()
debug('[+] Flashing completed!\n')
debug('''[>] Final steps:
1. Turn the ignition OFF
2. You can now safely disconnect Carloop
3. Start the engine
''')
if __name__ == '__main__':
main()
input()