This repository has been archived by the owner on Jun 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathecu_simulator.py
54 lines (38 loc) · 1.59 KB
/
ecu_simulator.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
import os
import sys
from threading import Thread
import ecu_config
from obd import listener as obd_listener
from uds import listener as uds_listener
from loggers import logger_app, logger_can, logger_isotp
SETUP_VCAN_FILE = "setup_vcan.sh"
SETUP_CAN_FILE = "setup_can.sh"
def main():
logger_app.configure()
logger_app.logger.info("Starting ECU-Simulator")
set_up_can_interface()
star_can_logger_thread()
star_isotp_logger_thread()
start_obd_listener_thread()
start_uds_listener_thread()
def set_up_can_interface():
interface_type = ecu_config.get_can_interface_type()
can_interface = ecu_config.get_can_interface()
isotp_ko_file_path = ecu_config.get_isotp_ko_file_path()
if interface_type == "virtual":
logger_app.logger.info("Setting up virtual CAN interface: " + can_interface)
os.system("sh " + SETUP_VCAN_FILE + " " + can_interface + " " + isotp_ko_file_path)
elif interface_type == "hardware":
logger_app.logger.info("Setting up CAN interface: " + can_interface)
logger_app.logger.info("Loading ISO-TP module from: " + isotp_ko_file_path)
os.system("sh " + SETUP_CAN_FILE + " " + can_interface + " " + ecu_config.get_can_bitrate() + " " + isotp_ko_file_path)
def star_can_logger_thread():
Thread(target=logger_can.start).start()
def star_isotp_logger_thread():
Thread(target=logger_isotp.start).start()
def start_obd_listener_thread():
Thread(target=obd_listener.start).start()
def start_uds_listener_thread():
Thread(target=uds_listener.start).start()
if __name__ == '__main__':
sys.exit(main())