rendash test commit

This commit is contained in:
marios8543 2024-05-01 17:04:59 +03:00
parent f25ef3718d
commit b11919ea86
4 changed files with 82 additions and 3 deletions

View File

@ -519,7 +519,8 @@ class ECU:
help = ""
if mod_globals.opt_csv_human and csvf!=0 and (dr.type=='State' or dr.type=='Parameter'):
csvline += ";" + pyren_encode(csvd)
if datastr.startswith("ET053"):
pass
if not (mod_globals.opt_csv and mod_globals.opt_csv_only):
strlst.append(datastr)
if mod_globals.opt_verbose and len(help)>0:

View File

@ -174,6 +174,12 @@ class ecu_parameter:
for mn in Mnemo:
self.mnemolist.append(mn.getAttribute("name"))
def __str__(self) -> str:
return self.label
def __repr__(self) -> str:
return str(self)
class ecu_parameters:
def __init__(self, parameter_list, mdoc, opt, tran ):
@ -182,4 +188,3 @@ class ecu_parameters:
for pr in Parameters:
parameter = ecu_parameter( pr, opt, tran )
parameter_list[parameter.name] = parameter

View File

@ -150,6 +150,12 @@ class ecu_state:
for mn in Mnemo:
self.mnemolist.append(mn.getAttribute("name"))
def __str__(self) -> str:
return self.label
def __repr__(self) -> str:
return str(self)
class ecu_states:
def __init__(self, state_list, mdoc, opt, tran ):

67
pyren3/rendash_main.py Normal file
View File

@ -0,0 +1,67 @@
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_ecu_state import get_state
from pickle import dump, load
from typing import List
import mod_globals
mod_globals.opt_demo = True
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+"))
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:
return ecu
def get_ecu_states(self, doc):
ecu = self.get_ecu_by_doc(doc)
return ecu.States
def get_ecu_state(self, doc, state):
ecu = self.get_ecu_by_doc(doc)
if self.current_ecu is not ecu:
ecu.initELM(self.elm)
self.current_ecu = ecu
datastr, help, csvd = get_state( ecu.States[state], ecu.Mnemonics, ecu.Services, self.elm, ecu.calc)
return datastr
if __name__ == "__main__":
rd = RenDash("/dev/tty0")
print(rd.get_ecu_names())
while True:
print(rd.get_ecu_state("UCH_J84_SE_0450_4C_A", "E031"))