85 lines
2.4 KiB
Python
85 lines
2.4 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 pickle import dump, load
|
|
from time import sleep
|
|
|
|
from flask import Flask, make_response, request
|
|
|
|
from typing import List
|
|
|
|
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
|
|
|
|
self.web = Flask(__name__)
|
|
|
|
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 = ecu.get_st(state)
|
|
return datastr
|
|
|
|
def get_ecu_param(self, doc, param):
|
|
ecu = self.get_ecu_by_doc(doc)
|
|
datastr = ecu.get_pr(param)
|
|
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)
|
|
|
|
|