-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcan0swc.py
executable file
·254 lines (230 loc) · 14.4 KB
/
can0swc.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
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# can0swc fg falcon swc-can adapter
# https://github.com/jakka351/FG-Falcon | https://github.com/jakka351/can0swc
# assumes ms-can is up on can0
# buffers several CAN IDS, then matches byte specific data
# when it matches, emits keypress
############################
# Import modules
############################
import can
import time
import os
#import uinput
import queue
from threading import Thread
import sys, traceback
print("""
#@@@@@@@@@#++++++++++@@@#++++++++%@@%+++++@@@@@@@+++#@@@++++++++++%@@%++++++++++++@%+++%@@@@@@@@+++#@@@++++++++++#@@@@@@@@@@@@
#@@@@@@@@@*----------@@@*--------#@@#-----@@@@@@@---*@@@----------#@@#------------@#---#@@@@@@@@---*@@@----------*@@@@@@@@@@@@
#@@@@@@@%=--#%%%%%%%%@%=--#%%%%*-==@#-----=+@@@@@---*@+=-=%%%=----==@#---#%%%%%%%%@#---#@@@@@@@@---*@+=-=%%%%%%%%@@@@@@@@@@@@@
#@@@@@@@#---#@@@@@@@@@#---#%%%%*---@#---==-=%@@@@---*@=--=@@%=-=----@#---#%%%%%%%%@#---#@@@%@@@@---*@=--=@@@@@@@@@@@@@@@@@@@@@
#@@@@@@@#---#@@@@@@@@@#------------@#---#@---*@@@---*@=--=@*---@*---@#------------@#---#@@#-*@@@---*@=--=@@@@@@@@@@@@@@@@@@@@@
#@@@@@@@#---#@@@@@@@@@#---+++++=---@#---#@++-+#%@---*@=--=#+-++@*---@%++++++++=---@#---#@#*-+#%@---*@=--=@@@@@@@@@@@@@@@@@@@@@
#@@@@@@@#---#@@@@@@@@@#---#@@@@*---@#---#@@#---#@---*@=------#@@*---@@@@@@@@@@*---@#---#@-----#@---*@=--=@@@@@@@@@@@@@@@@@@@@@
#@@@@@@@%#+-+++++++++@#---#@@@@*---@#---#@@%#+-++---*@##-----+++=-*#@%++++++++=---@%#+-++-=#+-++-=#%@##-=++++++++#@@@@@@@@@@@@
#@@@@@@@@@*----------@#---#@@@@*---@#---#@@@@*------*@@@----------#@@#------------@@@*----=@*----=@@@@@----------*@@@@@@@@@@@@
""")
print(' I??+=++=~~~~~~~~~~~?I777IIII??++====~======????+==+==~~~~:::::::::~~~~~~~~~====+==I, ')
print(' ?I+=~~=++~~~~~~~~=?=:+IIIII??++++===~:~~~~~~~=???=?:=~~~~~::::::::~~~~~~~~~~=~=+?7~: ')
print(' ?+=~~~~=++~~~~~+???~=?7II??+++++++==~~:~~~~~~:~~???=+:~~~~~~:::::::::~~~~=++:,.,+=,, ')
print(' =?I+~~~==++~~:+??~====+I?+===+++++==~~~::::::::::~????~~~~~:::::~:~==+:,,,,?..::+=: ')
print(' =?I=~~~==++=+++~==:,~~=+====+++++:,,...:,::~:::::~~~~+~:~~:~~==,.,,.?I~,..::~~=,: ')
print(' ~=+I?=~~=~+++~~=...,~:=+====++?:~+=?I~,I=I??..~III7I:==~,.,,.,,.,,,...::~~++~:~: ')
print(' ~?I+=~~~~+~~~.:+,,,:=+===+++~+==~=+:III=?I?77777I~~~===,,,,.,.,,~~~~=+=~::,,: ')
print(' ~?I+=:~~~~~~,,+:,,+==~+++++,:~~:==,??,:,,=??I++,,,:~===,,,::~~=++=:::~=..,, ')
print(' ,,,,:=+?==~~~~.=:~~,..,=+++++=~:=+=~:.,:,,,,::?=I=:::::+~====++++=~:::?I+?,.., ')
print(' :,,,,~+====~:,,,:=,.,,,~~===~~~,:==~~~~~~:..,,,,,,..,,,~==+++~:,~++I++II?... ')
print(' :,,,,,,+==+,:..:==.:,,~:~~~~~:,,,,:~~~~~~~~=========~++++~,....II+II+?...,: ')
print(' ,,,,,,,++.,,.,,,,=:,,~:::~:::,,,,,,,,,::~~~=====~====~.......?I=I.....,:~ ')
print(' ::,,,,,,:~::,~+I+,..~::::::,,,,,,,,,,,,,,,,,~==~~~.........+.......,:,, ')
print("""
This 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 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 file. If not, see <https://www.gnu.org/licenses/>.
""")
time.sleep(1)
c = ''
count = 0
# CAN Id's
SWC = 0x2F2
SWM = 0x2EC
ICC = 0x2FC #id 764
BEM = 0x307
# SWC Button CAN Data
SWC_SEEK = (0x08, 0x09, 0x0C) # seek button on bit [7] of id 0x2f2
SWC_VOLUP = (0x10, 0x11, 0x14) # volume + button on bit [7] of id 0x2f2
SWC_VOLDOWN = (0x18, 0x19, 0x1C) # volume - button on bit [7] of id 0x2f2
SWC_PHONE = (0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, ) # phone button on bit [6] of id 0x2f2
SWC_MODE = (0x10)
#AudioCurrentMediaMode byte 6 0x2f2
AUX = (0x01, 0x02, 0x41, 0x42, 0xC1)
CDMP3 = (0x03, 0x43)
PHONE = (0x06, 0x46, 0xC6)
RADIO = (0x05, 0x04, 0x44, 0xC5, 0x45)
AUDIOOFF = (0x08, 0x48)
# ICC Button CAN Data
ICC_VOLUP = 0x41 # vol + button on bit [3] of id 0x2fc
ICC_VOLDOWN = 0x81 # vol - button on bit [3] of id 0x2fc
ICC_NEXT = 0x04 # seek + button on bit [0] of id 0x2fc
ICC_PREV = 0x08 # seek - button on bit [0] of id 0x2fc
ICC_EJECT = 0x80 # eject button on bit [1] of id 0x2fc
ICC_LOAD = 0x40 # load button on bit [1] of id 0x2fc
#ICC_SCAN = 0x20
#ICC_CDAUX = 0x10
#ICC_FMAM = 0x08
#ICC_OK = 0x04
#ICC_MENU = 0x02
# Body Butonn CAN Data
#BEM_LOCK = 0x04
#BEM_UNLOCK = 0x02
#BEM_DSC = 0x80
#BEM_DOMELIGHT = 0x90
BEM_HAZARD = 0x01
def scroll():
#prints logo to console
print(' ')
print('''
,777I77II??~++++=~::,,,,::::::::::~~~==+~
,IIIIII,IIII+~..,,:,,,,,:~:,,.....,~,,:::~+?+?=
:=I7777I=IIIIII~...:===,:,=~:,,,,,,::=,,,:::~~:=?===
~=,?I?777II7IIIII=~,.,,,,,,,,,,,:,,,,,,::,,,,~:~~~~:~+:~:~
I=I?IIIIII~IIIIIII+:..,,,,,,,,,,,,.,.,,::.,,,,:::~~=~:=+~?~~
I77?+?IIIIIIIII7I7=~,.,,,..,,,,.,.,.......,.,.,.,..,,,:~=~:==~~
+=I7777I?+???IIIIII+=:..,,,,,,,,,,,...,,,,,,,,,,,,..,,,:..:?I7+...,,
+=+=I7777I=~~+~:~IIII~,..,,,,,,,,,,..,,,,,...~+II?I?+?III7IIII777I7=.....
==++++III=~~~::~+I:+?~:.........:+IIIIIIII+=?IIIIIII???????????III7II7I....
?+= ██████ █████ ███ ██ ██████ ███████ ██ ██ ██████++++???II?III....
?+= ██ ██ ██ ████ ██ ██ ████ ██ ██ ██ ██ ======++?II?+7II.
??+ ██ ███████ ██ ██ ██ ██ ██ ██ ███████ ██ █ ██ ██ ~~~~======+???++II.
??+ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ███ ██ ██ ~~~~~~~~~===++++=II,
I?? ██████ ██ ██ ██ ████ ██████ ███████ ███ ███ ██████:::~~~~~~~~~====+==I,
?I+=~~fg+falcon+swc+adapter+??++++===~:~~~~~~~=???=?:=~~~~~::::::::~~~~~~~~~~=~=+?7~:
?+=~~~~=++~~~~~+???~=?7II??+++++++==~~:~~~~~~:~~???=+:~~~~~~:::::::::~~~~=++:,.,+=,,
=?I+~~~==++~~:+??~====+I?+===+++++==~~~::::::::::~????~~~~~:::::~:~==+:,,,,?..::+=:
=?I=~~~==++=+++~==:,~~=+====+++++:,,...:,::~:::::~~~~+~:~~:~~==,.,,.?I~,..::~~=,:
~=+I?=~~=~+++~~=...,~:=+====++?:~+=?I~,I=I??..~III7I:==~,.,,.,,.,,,...::~~++~:~:
~?I+=~~~~+~~~.:+,,,:=+===+++~+==~=+:III=?I?77777I~~~===,,,,.,.,,~~~~=+=~::,,:
~?I+=:~~~~~~,,+:,,+==~+++++,:~~:==,??,:,,=??I++,,,:~===,,,::~~=++=:::~=..,,
,,,,:=+?==~~~~.=:~~,..,=+++++=~:=+=~:.,:,,,,::?=I=:::::+~====++++=~:::?I+?,..,
:,,,,~+====~:,,,:=,.,,,~~===~~~,:==~~~~~~:..,,,,,,..,,,~==+++~:,~++I++II?...
:,,,,,,+==+,:..:==.:,,~:~~~~~:,,,,:~~~~~~~~=========~++++~,....II+II+?...,:
,,,,,,,++.,,.,,,,=:,,~:::~:::,,,,,,,,,::~~~=====~====~.......?I=I.....,:~
::,,,,,,:~::,~+I+,..~::::::,,,,,,,,,,,,,,,,,~==~~~.........+.......,:,, ''')
def setup():
global bus
# os.system("sudo modprobe uinput")
try:
bus = can.interface.Bus(channel='vcan0', bustype='socketcan_native')
except OSError:
sys.exit() # quits if there is no canbus interface
print(" ")
print(" CANbus active on", bus)
print(" waiting for matching can frame...") #this line gets replaced by the next matching can frame
print(" ready to emit keypress...") # this line gets replaced by the button in the car that is pushed
def msgbuffer():
global message, q, SWC, ICC, BEM
while True:
message = bus.recv() # if recieving can frames then put these can arb id's into a queue
if message.arbitration_id == SWC:
q.put(message)
def displaytext():
pass
def cleardtc():
pass
def demister():
pass
def backlite():
pass
def bluetoothpair():
#connect a phone to Bluetooth Phone Module and display bluetooth pin
#Press Menu on the ICC candump can0,2ce:1fffffff -c -e -a -x
pass
def cleanline(): # cleans the last output line from the console
sys.stdout.write('\x1b[1A')
sys.stdout.write('\x1b[2K')
def cleanscreen(): # cleans the whole console screen
os.system("clear")
def ccp():
cleanline()
cleanline()
print(message)
def main():
try:
while True:
for i in range(8):
while(q.empty() == True): # wait for messages to queue
pass
message = q.get()
c = '{0:f},{1:d},'.format(message.timestamp,count)
if message.arbitration_id == SWC and message.data[6] in AUX:
if message.arbitration_id == SWC and message.data[7] in SWC_SEEK:
#device.emit_click(uinput.KEY_N)
ccp()
print("SWCSeekBtn pushed @", message.timestamp)
# AUX SEEK FUNCTION HERE
elif message.arbitration_id == SWC and message.data[7] in SWC_VOLUP:
#device.emit_click(uinput.KEY_VOLUMEUP) #volup openauto
time.sleep(0.2)
ccp()
print("SWCVolUpBtn pushed @", message.timestamp)
# AUX VOL + FUNCTION
elif message.data[7] in SWC_VOLDOWN:
#device.emit_click(uinput.KEY_VOLUMEDOWN) #voldown openauto
ccp()
print("SWCVolDownBtn pushed @", message.timestamp)
# AUX VOL - FUNCTION
elif message.arbitration_id == SWC and message.data[6] in SWC_PHONE:
#device.emit_click(uinput.KEY_F) #opendash cycle pages
ccp()
print("SWCPhoneBtn pushed @", message.timestamp)
else:
pass
elif message.arbitration_id == SWC and message.data[6] in RADIO:
if message.arbitration_id == SWC and message.data[7] in SWC_SEEK:
#device.emit_click(uinput.KEY_N)
ccp()
print("SWCSeekBtn pushed @", message.timestamp)
# RADIO SEEK FUNCTION HERE
elif message.arbitration_id == SWC and message.data[7] in SWC_VOLUP:
#device.emit_click(uinput.KEY_VOLUMEUP) #volup openauto
time.sleep(0.2)
ccp()
print("SWCVolUpBtn pushed @", message.timestamp)
# RADIO VOL + FUNCTION
elif message.data[7] in SWC_VOLDOWN:
#device.emit_click(uinput.KEY_VOLUMEDOWN) #voldown openauto
ccp()
print("SWCVolDownBtn pushed @", message.timestamp)
# RADIO VOL - FUNCTION
elif message.arbitration_id == SWC and message.data[6] in SWC_PHONE:
#device.emit_click(uinput.KEY_F) #opendash cycle pages
ccp()
print("SWCPhoneBtn pushed @", message.timestamp)
else:
pass
elif message.arbitration_id == SWC and message.data[6] in PHONE:
pass
else:
pass
except KeyboardInterrupt:
sys.exit(0) # quit if ctl + c is hit
except Exception:
traceback.print_exc(file=sys.stdout) # quit if there is a python problem
sys.exit()
except OSError:
sys.exit() # quit if there is a system issue
############################
# can0swc
############################
if __name__ == "__main__":
q = queue.Queue() #
rx = Thread(target = msgbuffer) #
cleanscreen() # clean the console screen
scroll() # scroll out fancy logo text
setup() # set the can interface
rx.start() # start the rx thread and queue msgs
main() # match ca