91 lines
2.9 KiB
Python
91 lines
2.9 KiB
Python
from mod_utils import chkDirTree
|
|
from mod_db_manager import find_DBs
|
|
from mod_elm import ELM
|
|
from mod_scan_ecus import ScanEcus
|
|
from mod_optfile import optfile
|
|
from mod_ecu import ECU
|
|
from mod_ply import Calc
|
|
from mod_ecu_state import get_state
|
|
from mod_ecu_parameter import get_parameter
|
|
|
|
from pickle import dump, load
|
|
from time import sleep
|
|
from mod_utils import clearScreen
|
|
|
|
from typing import List
|
|
|
|
REQUIRED_ECU_STATES = {
|
|
"UCH_J84_SE_0450_4C_A": ["E031", "E032", "E029", "E030", "E027", "E074", "E075", "E078", "E122", "E073", "E100", "E072"],
|
|
"INJ_S30001_A754_00_A": ["E092", "E093", "P004", "P006", "P007", "P051"],
|
|
"UPC_X 84 C_0600_00_A": ["E001", "E004", "E005", "E006"],
|
|
"FRE_FPA_FF_0300_08_A": ["E002"]
|
|
}
|
|
|
|
class RenDash:
|
|
def __init__(self,
|
|
elm_port,
|
|
elm_speed=38400,
|
|
model_number=58,
|
|
rescan=False) -> None:
|
|
chkDirTree()
|
|
find_DBs()
|
|
|
|
self.elm = ELM(elm_port, elm_speed, "")
|
|
self.lang = optfile("Location/DiagOnCAN_GB.bqm", False)
|
|
self.ecus: List[ECU] = []
|
|
self.current_ecu = None
|
|
|
|
if rescan is False:
|
|
try:
|
|
self.ecus = load(open("frozen_ecus.p", "rb"))
|
|
except Exception as e:
|
|
pass
|
|
if not self.ecus:
|
|
ecu_scanner = ScanEcus(self.elm)
|
|
ecu_scanner.chooseModel(model_number)
|
|
ecu_scanner.scanAllEcus()
|
|
for ecu in ecu_scanner.detectedEcus:
|
|
self.ecus.append(ECU(ecu, self.lang.dict))
|
|
dump(self.ecus, open("frozen_ecus.p", "wb+"))
|
|
|
|
for ecu in self.ecus:
|
|
setattr(ecu, "calc", Calc())
|
|
|
|
def get_ecu_names(self):
|
|
return [ecu.ecudata["doc"] for ecu in self.ecus]
|
|
|
|
def get_ecu_by_doc(self, doc):
|
|
for ecu in self.ecus:
|
|
if ecu.ecudata["doc"] == doc:
|
|
if self.current_ecu is not ecu:
|
|
ecu.initELM(self.elm)
|
|
self.current_ecu = ecu
|
|
return ecu
|
|
|
|
def get_ecu_states(self, doc):
|
|
ecu = self.get_ecu_by_doc(doc)
|
|
return ecu.Parameters
|
|
|
|
def get_ecu_state(self, doc, state):
|
|
ecu = self.get_ecu_by_doc(doc)
|
|
datastr, help, csvd = get_state(ecu.States[state], ecu.Mnemonics, ecu.Services, self.elm, ecu.calc)
|
|
return datastr
|
|
|
|
def get_ecu_param(self, doc, param):
|
|
ecu = self.get_ecu_by_doc(doc)
|
|
datastr, help, csvd = get_parameter(ecu.Parameters[param], ecu.Mnemonics, ecu.Services, self.elm, ecu.calc)
|
|
return datastr
|
|
|
|
if __name__ == "__main__":
|
|
rd = RenDash("/dev/tty0")
|
|
while True:
|
|
clearScreen()
|
|
for ecu_doc, values in REQUIRED_ECU_STATES.items():
|
|
for val in values:
|
|
if val.startswith("E"):
|
|
print(rd.get_ecu_state(ecu_doc, val))
|
|
elif val.startswith("P"):
|
|
print(rd.get_ecu_param(ecu_doc, val))
|
|
sleep(0.1)
|
|
|
|
|