openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

326 lines
12 KiB

#!/usr/bin/env python
"""Used to Reverse/Test ELM protocol auto detect and OBD message response without a car."""
from __future__ import print_function
import sys
import os
import struct
import binascii
import time
import threading
from collections import deque
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))
from panda import Panda
def lin_checksum(dat):
return sum(dat) % 0x100
class ELMCarSimulator():
def __init__(self, sn, silent=False, can_kbaud=500,
can=True, can11b=True, can29b=True,
lin=True):
self.__p = Panda(sn if sn else Panda.list()[0])
self.__on = True
self.__stop = False
self.__silent = silent
self.__lin_timer = None
self.__lin_active = False
self.__lin_enable = lin
self.__lin_monitor_thread = threading.Thread(target=self.__lin_monitor)
self.__can_multipart_data = None
self.__can_kbaud = can_kbaud
self.__can_extra_noise_msgs = deque()
self.__can_enable = can
self.__can11b = can11b
self.__can29b = can29b
self.__can_monitor_thread = threading.Thread(target=self.__can_monitor)
@property
def panda(self):
return self.__p
def stop(self):
if self.__lin_timer:
self.__lin_timer.cancel()
self.__lin_timeout_handler()
self.__stop = True
def join(self):
if self.__lin_monitor_thread.is_alive():
self.__lin_monitor_thread.join()
if self.__can_monitor_thread.is_alive():
self.__can_monitor_thread.join()
if self.__p:
print("closing handle")
self.__p.close()
def set_enable(self, on):
self.__on = on
def start(self):
self.panda.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
if self.__lin_enable:
self.__lin_monitor_thread.start()
if self.__can_enable:
self.__can_monitor_thread.start()
#########################
# LIN related functions #
#########################
def __lin_monitor(self):
print("STARTING LIN THREAD")
self.panda.set_uart_baud(2, 10400)
self.panda.kline_drain() # Toss whatever was already there
lin_buff = bytearray()
while not self.__stop:
lin_msg = self.panda.serial_read(2)
if not lin_msg:
continue
lin_buff += lin_msg
#print(" ** Buff", lin_buff)
if lin_buff.endswith(b'\x00\xc1\x33\xf1\x81\x66'): # Leading 0 is wakeup
lin_buff = bytearray()
self.__lin_active = True
print("GOT LIN (KWP FAST) WAKEUP SIGNAL")
self._lin_send(0x10, b'\xC1\x8F\xE9')
self.__reset_lin_timeout()
continue
if self.__lin_active:
msglen = lin_buff[0] & 0x7
if lin_buff[0] & 0xF8 not in (0x80, 0xC0):
print("Invalid bytes at start of message")
print(" BUFF", lin_buff)
continue
if len(lin_buff) < msglen + 4: continue
if lin_checksum(lin_buff[:-1]) != lin_buff[-1]: continue
self.__lin_process_msg(lin_buff[0] & 0xF8, #Priority
lin_buff[1], lin_buff[2], lin_buff[3:-1])
lin_buff = bytearray()
def _lin_send(self, to_addr, msg):
if not self.__silent:
print(" LIN Reply (%x)" % to_addr, binascii.hexlify(msg))
PHYS_ADDR = 0x80
FUNC_ADDR = 0xC0
RECV = 0xF1
SEND = 0x33 # Car OBD Functional Address
headers = struct.pack("BBB", PHYS_ADDR | len(msg), RECV, to_addr)
if not self.__silent:
print(" Sending LIN", binascii.hexlify(headers+msg),
hex(sum(bytearray(headers+msg))%0x100))
self.panda.kline_send(headers + msg)
def __reset_lin_timeout(self):
if self.__lin_timer:
self.__lin_timer.cancel()
self.__lin_timer = threading.Timer(5, self.__lin_timeout_handler)
self.__lin_timer.start()
def __lin_timeout_handler(self):
print("LIN TIMEOUT")
self.__lin_timer = None
self.__lin_active = False
@property
def lin_active(self):
return self.__lin_active
def __lin_process_msg(self, priority, toaddr, fromaddr, data):
self.__reset_lin_timeout()
if not self.__silent and data != b'\x3E':
print("LIN MSG", "Addr:", hex(toaddr), "obdLen:", len(data),
binascii.hexlify(data))
outmsg = None
#if data == b'\x3E':
# print("KEEP ALIVE")
#el
if len(data) > 1:
outmsg = self._process_obd(data[0], data[1])
if outmsg:
obd_header = struct.pack("BB", 0x40 | data[0], data[1])
if len(outmsg) <= 5:
self._lin_send(0x10, obd_header + outmsg)
else:
Squashed 'panda/' changes from ae816c104..45d0d286f 45d0d286f remove whitespace (#255) e49d0dbbd Pedal: use avg between tracks (#253) c597dcc89 VERSION update after health packet changes and minor misra test change 01072bec0 Misra 11.x: pointer usage. (#250) fd68c26ab Propagate can_push errors (#249) ce1daf206 Misra check only done for EON config 70d4fd7f6 cleanup docker container on failure 04756a037 Turning back Misra check: unvoluntarily change fcb1208e1 fix weird code in USB_ReadPacket b983cc8fe Re-wrote test_misra.sh 0b1920636 Misra 17.7: The value returned by a function having non-void return type shall be used. We should hang on initial failed safety_set_mode 06ee8bd2d Ignore Misra 5.4 until cppcheck bug (?) is fixed 4be858224 Update cppcheck commit and pass predefined params to avoid impossible combinations of configs f45dd04c6 cppcheck: ignore redundantAssignment and selfAssignment for registers in llcan.h 9ce631155 Misra 12.1 (operator order) and 10.4 (incompatible essential types) fixes, arised after properly checking UID_BASE config 1cd34e564 Explicitly set the define and undefine for unknown configs in misra checks 5a024999d remove esp flash from run_automated_tests.sh 23e3684d7 Cppcheck unused functions (#247) c97d60be6 Removed bad language b031480a7 Missed adding Dockerfile 91ff6bb21 Run language checker in CI 205ec342a Improved language checker f7bbab072 Language checker test d9d0a62f2 Misra 5.5: missed this change from previous PR 85fa3c02a Misra 5.5: Identifiers shall be distinct from macro names (#246) 190d604a0 Pedal: 2 minor fixes to Misra 15.7 (else needed) and 17.7 (non-void output must be used) 8ea01ff12 Pedal: no built-in functions to avoid puts and putc re-definitions 1f40d1e6a Misra pedal (#245) a4554e3e6 Ignore advisory Misra 19.2: the union keyword should not be used e6dc4172b Minor indent error 247e128b4 Fix strict compiler on bootstub build ba6856921 Removed build strict test and enabled -Werror flag da11f0fa0 safety replay: update openpilot-tools after logreader fix fc8b9e49b Cppcheck: also check pedal f7bd2c2f3 Misra 10.4: fix last 2 violations (#242) 9be5fdead finished misra 17.8 (#241) 3c3aba3db Misra 10.4: Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category (#240) f2a3a177b Misra 15_7: fix what seems to be a false positive of cppcheck 812ace538 Misra 15_7: if … else if constructs should be terminated with an else clause (#230) 79e9735ae rename 5_wifi_udp.py 3c3ff0c03 Update Jenkinsfile (#239) 1bd928437 Misra 17.7: the value returned by a function having non-void return shall be used (#237) 18c9e88bc Merge pull request #238 from commaai/misra_17_8 7ac321de4 Merge pull request #235 from commaai/memxxx 004e543cc Jenkins: run EON test first 4bff28620 Merge branch 'memxxx' of github.com:commaai/panda into memxxx 7cd80de23 typo 385e33b32 12.1 regression 955842bae WIP ea908cbb7 10_1 violations: Operands shall not be of an inappropriate essential type (#233) fa3303805 Fix Misra 5.3: An identifier declared in an inner scope shall not hide an identifier declared in an outer scope (#236) ebfe1c512 Merge branch 'master' of github.com:commaai/panda into memxxx 8c11470ef Fix EON test case 64e18e841 fix inverted logic to differentiate between dev and EON panda builds 36755a0fd Merge branch 'master' of github.com:commaai/panda into memxxx e2981d612 skip wifi tests for EON panda build db2eec98c Merge branch 'master' of github.com:commaai/panda into memxxx 11257e79a Ignore test 5_wifi_udp.py_ignore: too unreliable for now 6973c2a81 fix wifi tests cf6985ad1 memxxx function changes to be Misra compliant 3a6cd2930 wifi threshold perc back to 20%. Problem wasn't this. d92a03528 faster docker build for safety replay 3e9469b3e Fixing tests after min->MIN change ecb9b6c01 Revert "Misra 10 1: Operands shall not be of an inappropriate essential type (#232)" 8732e4faf Misra 10 1: Operands shall not be of an inappropriate essential type (#232) git-subtree-dir: panda git-subtree-split: 45d0d286f4b5c893590a98ec1438b8a143b9605d old-commit-hash: 1ff59baea717f88e8038c01ead864ad5acb85f35
6 years ago
first_msg_len = min(4, len(outmsg)%4) or 4
self._lin_send(0x10, obd_header + b'\x01' +
b'\x00'*(4-first_msg_len) +
outmsg[:first_msg_len])
for num, i in enumerate(range(first_msg_len, len(outmsg), 4)):
self._lin_send(0x10, obd_header +
struct.pack('B', (num+2)%0x100) + outmsg[i:i+4])
#########################
# CAN related functions #
#########################
def __can_monitor(self):
print("STARTING CAN THREAD")
self.panda.set_can_speed_kbps(0, self.__can_kbaud)
self.panda.can_recv() # Toss whatever was already there
while not self.__stop:
for address, ts, data, src in self.panda.can_recv():
if self.__on and src is 0 and len(data) == 8 and data[0] >= 2:
if not self.__silent:
print("Processing CAN message", src, hex(address), binascii.hexlify(data))
self.__can_process_msg(data[1], data[2], address, ts, data, src)
elif not self.__silent:
print("Rejecting CAN message", src, hex(address), binascii.hexlify(data))
def can_mode_11b(self):
self.__can11b = True
self.__can29b = False
def can_mode_29b(self):
self.__can11b = False
self.__can29b = True
def can_mode_11b_29b(self):
self.__can11b = True
self.__can29b = True
def change_can_baud(self, kbaud):
self.__can_kbaud = kbaud
self.panda.set_can_speed_kbps(0, self.__can_kbaud)
def can_add_extra_noise(self, noise_msg, addr=None):
self.__can_extra_noise_msgs.append((addr, noise_msg))
def _can_send(self, addr, msg):
if not self.__silent:
print(" CAN Reply (%x)" % addr, binascii.hexlify(msg))
self.panda.can_send(addr, msg + b'\x00'*(8-len(msg)), 0)
if self.__can_extra_noise_msgs:
noise = self.__can_extra_noise_msgs.popleft()
self.panda.can_send(noise[0] if noise[0] is not None else addr,
noise[1] + b'\x00'*(8-len(noise[1])), 0)
def _can_addr_matches(self, addr):
if self.__can11b and (addr == 0x7DF or (addr & 0x7F8) == 0x7E0):
return True
if self.__can29b and (addr == 0x18db33f1 or (addr & 0x1FFF00FF) == 0x18da00f1):
return True
return False
def __can_process_msg(self, mode, pid, address, ts, data, src):
if not self.__silent:
print("CAN MSG", binascii.hexlify(data[1:1+data[0]]),
"Addr:", hex(address), "Mode:", hex(mode)[2:].zfill(2),
"PID:", hex(pid)[2:].zfill(2), "canLen:", len(data),
binascii.hexlify(data))
if self._can_addr_matches(address) and len(data) == 8:
outmsg = None
if data[:3] == b'\x30\x00\x00' and len(self.__can_multipart_data):
if not self.__silent:
print("Request for more data");
outaddr = 0x7E8 if address == 0x7DF or address == 0x7E0 else 0x18DAF110
msgnum = 1
while(self.__can_multipart_data):
Squashed 'panda/' changes from ae816c104..45d0d286f 45d0d286f remove whitespace (#255) e49d0dbbd Pedal: use avg between tracks (#253) c597dcc89 VERSION update after health packet changes and minor misra test change 01072bec0 Misra 11.x: pointer usage. (#250) fd68c26ab Propagate can_push errors (#249) ce1daf206 Misra check only done for EON config 70d4fd7f6 cleanup docker container on failure 04756a037 Turning back Misra check: unvoluntarily change fcb1208e1 fix weird code in USB_ReadPacket b983cc8fe Re-wrote test_misra.sh 0b1920636 Misra 17.7: The value returned by a function having non-void return type shall be used. We should hang on initial failed safety_set_mode 06ee8bd2d Ignore Misra 5.4 until cppcheck bug (?) is fixed 4be858224 Update cppcheck commit and pass predefined params to avoid impossible combinations of configs f45dd04c6 cppcheck: ignore redundantAssignment and selfAssignment for registers in llcan.h 9ce631155 Misra 12.1 (operator order) and 10.4 (incompatible essential types) fixes, arised after properly checking UID_BASE config 1cd34e564 Explicitly set the define and undefine for unknown configs in misra checks 5a024999d remove esp flash from run_automated_tests.sh 23e3684d7 Cppcheck unused functions (#247) c97d60be6 Removed bad language b031480a7 Missed adding Dockerfile 91ff6bb21 Run language checker in CI 205ec342a Improved language checker f7bbab072 Language checker test d9d0a62f2 Misra 5.5: missed this change from previous PR 85fa3c02a Misra 5.5: Identifiers shall be distinct from macro names (#246) 190d604a0 Pedal: 2 minor fixes to Misra 15.7 (else needed) and 17.7 (non-void output must be used) 8ea01ff12 Pedal: no built-in functions to avoid puts and putc re-definitions 1f40d1e6a Misra pedal (#245) a4554e3e6 Ignore advisory Misra 19.2: the union keyword should not be used e6dc4172b Minor indent error 247e128b4 Fix strict compiler on bootstub build ba6856921 Removed build strict test and enabled -Werror flag da11f0fa0 safety replay: update openpilot-tools after logreader fix fc8b9e49b Cppcheck: also check pedal f7bd2c2f3 Misra 10.4: fix last 2 violations (#242) 9be5fdead finished misra 17.8 (#241) 3c3aba3db Misra 10.4: Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category (#240) f2a3a177b Misra 15_7: fix what seems to be a false positive of cppcheck 812ace538 Misra 15_7: if … else if constructs should be terminated with an else clause (#230) 79e9735ae rename 5_wifi_udp.py 3c3ff0c03 Update Jenkinsfile (#239) 1bd928437 Misra 17.7: the value returned by a function having non-void return shall be used (#237) 18c9e88bc Merge pull request #238 from commaai/misra_17_8 7ac321de4 Merge pull request #235 from commaai/memxxx 004e543cc Jenkins: run EON test first 4bff28620 Merge branch 'memxxx' of github.com:commaai/panda into memxxx 7cd80de23 typo 385e33b32 12.1 regression 955842bae WIP ea908cbb7 10_1 violations: Operands shall not be of an inappropriate essential type (#233) fa3303805 Fix Misra 5.3: An identifier declared in an inner scope shall not hide an identifier declared in an outer scope (#236) ebfe1c512 Merge branch 'master' of github.com:commaai/panda into memxxx 8c11470ef Fix EON test case 64e18e841 fix inverted logic to differentiate between dev and EON panda builds 36755a0fd Merge branch 'master' of github.com:commaai/panda into memxxx e2981d612 skip wifi tests for EON panda build db2eec98c Merge branch 'master' of github.com:commaai/panda into memxxx 11257e79a Ignore test 5_wifi_udp.py_ignore: too unreliable for now 6973c2a81 fix wifi tests cf6985ad1 memxxx function changes to be Misra compliant 3a6cd2930 wifi threshold perc back to 20%. Problem wasn't this. d92a03528 faster docker build for safety replay 3e9469b3e Fixing tests after min->MIN change ecb9b6c01 Revert "Misra 10 1: Operands shall not be of an inappropriate essential type (#232)" 8732e4faf Misra 10 1: Operands shall not be of an inappropriate essential type (#232) git-subtree-dir: panda git-subtree-split: 45d0d286f4b5c893590a98ec1438b8a143b9605d old-commit-hash: 1ff59baea717f88e8038c01ead864ad5acb85f35
6 years ago
datalen = min(7, len(self.__can_multipart_data))
msgpiece = struct.pack("B", 0x20 | msgnum) + self.__can_multipart_data[:datalen]
self._can_send(outaddr, msgpiece)
self.__can_multipart_data = self.__can_multipart_data[7:]
msgnum = (msgnum+1)%0x10
time.sleep(0.01)
else:
outmsg = self._process_obd(mode, pid)
if outmsg:
outaddr = 0x7E8 if address == 0x7DF or address == 0x7E0 else 0x18DAF110
if len(outmsg) <= 5:
self._can_send(outaddr,
struct.pack("BBB", len(outmsg)+2, 0x40|data[1], pid) + outmsg)
else:
Squashed 'panda/' changes from ae816c104..45d0d286f 45d0d286f remove whitespace (#255) e49d0dbbd Pedal: use avg between tracks (#253) c597dcc89 VERSION update after health packet changes and minor misra test change 01072bec0 Misra 11.x: pointer usage. (#250) fd68c26ab Propagate can_push errors (#249) ce1daf206 Misra check only done for EON config 70d4fd7f6 cleanup docker container on failure 04756a037 Turning back Misra check: unvoluntarily change fcb1208e1 fix weird code in USB_ReadPacket b983cc8fe Re-wrote test_misra.sh 0b1920636 Misra 17.7: The value returned by a function having non-void return type shall be used. We should hang on initial failed safety_set_mode 06ee8bd2d Ignore Misra 5.4 until cppcheck bug (?) is fixed 4be858224 Update cppcheck commit and pass predefined params to avoid impossible combinations of configs f45dd04c6 cppcheck: ignore redundantAssignment and selfAssignment for registers in llcan.h 9ce631155 Misra 12.1 (operator order) and 10.4 (incompatible essential types) fixes, arised after properly checking UID_BASE config 1cd34e564 Explicitly set the define and undefine for unknown configs in misra checks 5a024999d remove esp flash from run_automated_tests.sh 23e3684d7 Cppcheck unused functions (#247) c97d60be6 Removed bad language b031480a7 Missed adding Dockerfile 91ff6bb21 Run language checker in CI 205ec342a Improved language checker f7bbab072 Language checker test d9d0a62f2 Misra 5.5: missed this change from previous PR 85fa3c02a Misra 5.5: Identifiers shall be distinct from macro names (#246) 190d604a0 Pedal: 2 minor fixes to Misra 15.7 (else needed) and 17.7 (non-void output must be used) 8ea01ff12 Pedal: no built-in functions to avoid puts and putc re-definitions 1f40d1e6a Misra pedal (#245) a4554e3e6 Ignore advisory Misra 19.2: the union keyword should not be used e6dc4172b Minor indent error 247e128b4 Fix strict compiler on bootstub build ba6856921 Removed build strict test and enabled -Werror flag da11f0fa0 safety replay: update openpilot-tools after logreader fix fc8b9e49b Cppcheck: also check pedal f7bd2c2f3 Misra 10.4: fix last 2 violations (#242) 9be5fdead finished misra 17.8 (#241) 3c3aba3db Misra 10.4: Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category (#240) f2a3a177b Misra 15_7: fix what seems to be a false positive of cppcheck 812ace538 Misra 15_7: if … else if constructs should be terminated with an else clause (#230) 79e9735ae rename 5_wifi_udp.py 3c3ff0c03 Update Jenkinsfile (#239) 1bd928437 Misra 17.7: the value returned by a function having non-void return shall be used (#237) 18c9e88bc Merge pull request #238 from commaai/misra_17_8 7ac321de4 Merge pull request #235 from commaai/memxxx 004e543cc Jenkins: run EON test first 4bff28620 Merge branch 'memxxx' of github.com:commaai/panda into memxxx 7cd80de23 typo 385e33b32 12.1 regression 955842bae WIP ea908cbb7 10_1 violations: Operands shall not be of an inappropriate essential type (#233) fa3303805 Fix Misra 5.3: An identifier declared in an inner scope shall not hide an identifier declared in an outer scope (#236) ebfe1c512 Merge branch 'master' of github.com:commaai/panda into memxxx 8c11470ef Fix EON test case 64e18e841 fix inverted logic to differentiate between dev and EON panda builds 36755a0fd Merge branch 'master' of github.com:commaai/panda into memxxx e2981d612 skip wifi tests for EON panda build db2eec98c Merge branch 'master' of github.com:commaai/panda into memxxx 11257e79a Ignore test 5_wifi_udp.py_ignore: too unreliable for now 6973c2a81 fix wifi tests cf6985ad1 memxxx function changes to be Misra compliant 3a6cd2930 wifi threshold perc back to 20%. Problem wasn't this. d92a03528 faster docker build for safety replay 3e9469b3e Fixing tests after min->MIN change ecb9b6c01 Revert "Misra 10 1: Operands shall not be of an inappropriate essential type (#232)" 8732e4faf Misra 10 1: Operands shall not be of an inappropriate essential type (#232) git-subtree-dir: panda git-subtree-split: 45d0d286f4b5c893590a98ec1438b8a143b9605d old-commit-hash: 1ff59baea717f88e8038c01ead864ad5acb85f35
6 years ago
first_msg_len = min(3, len(outmsg)%7)
payload_len = len(outmsg)+3
msgpiece = struct.pack("BBBBB", 0x10 | ((payload_len>>8)&0xF),
payload_len&0xFF,
0x40|data[1], pid, 1) + outmsg[:first_msg_len]
self._can_send(outaddr, msgpiece)
self.__can_multipart_data = outmsg[first_msg_len:]
#########################
# General OBD functions #
#########################
def _process_obd(self, mode, pid):
if mode == 0x01: # Mode: Show current data
if pid == 0x00: #List supported things
return b"\xff\xff\xff\xfe"#b"\xBE\x1F\xB8\x10" #Bitfield, random features
elif pid == 0x01: # Monitor Status since DTC cleared
return b"\x00\x00\x00\x00" #Bitfield, random features
elif pid == 0x04: # Calculated engine load
return b"\x2f"
elif pid == 0x05: # Engine coolant temperature
return b"\x3c"
elif pid == 0x0B: # Intake manifold absolute pressure
return b"\x90"
elif pid == 0x0C: # Engine RPM
return b"\x1A\xF8"
elif pid == 0x0D: # Vehicle Speed
return b"\x53"
elif pid == 0x10: # MAF air flow rate
return b"\x01\xA0"
elif pid == 0x11: # Throttle Position
return b"\x90"
elif pid == 0x33: # Absolute Barometric Pressure
return b"\x90"
elif mode == 0x09: # Mode: Request vehicle information
if pid == 0x02: # Show VIN
return b"1D4GP00R55B123456"
if pid == 0xFC: # test long multi message. Ligned up for LIN responses
return b''.join((struct.pack(">BBH", 0xAA, 0xAA, num+1) for num in range(80)))
if pid == 0xFD: # test long multi message
parts = (b'\xAA\xAA\xAA' + struct.pack(">I", num) for num in range(80))
return b'\xAA\xAA\xAA' + b''.join(parts)
if pid == 0xFE: # test very long multi message
parts = (b'\xAA\xAA\xAA' + struct.pack(">I", num) for num in range(584))
return b'\xAA\xAA\xAA' + b''.join(parts) + b'\xAA'
if pid == 0xFF:
return b'\xAA\x00\x00' +\
b"".join(((b'\xAA'*5)+struct.pack(">H", num+1) for num in range(584)))
#return b"\xAA"*100#(0xFFF-3)
if __name__ == "__main__":
serial = os.getenv("SERIAL") if os.getenv("SERIAL") else None
kbaud = int(os.getenv("CANKBAUD")) if os.getenv("CANKBAUD") else 500
bitwidth = int(os.getenv("CANBITWIDTH")) if os.getenv("CANBITWIDTH") else 0
canenable = bool(int(os.getenv("CANENABLE"))) if os.getenv("CANENABLE") else True
linenable = bool(int(os.getenv("LINENABLE"))) if os.getenv("LINENABLE") else True
sim = ELMCarSimulator(serial, can_kbaud=kbaud, can=canenable, lin=linenable)
if(bitwidth == 0):
sim.can_mode_11b_29b()
if(bitwidth == 11):
sim.can_mode_11b()
if(bitwidth == 29):
sim.can_mode_29b()
import signal
def signal_handler(signal, frame):
print('\nShutting down simulator')
sim.stop()
sim.join()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
sim.start()
signal.pause()