From 37f7d9988322c967c638a5972ed571ffb98e51f3 Mon Sep 17 00:00:00 2001 From: Mathieu Moran Date: Mon, 6 Nov 2023 17:46:54 -0500 Subject: [PATCH] add dtc codes, wip --- app_account.py | 24 +++++++++++++++++++++++- app_car.py | 3 +-- app_obd.py | 15 +++++++++++++++ static/js/yaris.js | 14 ++++++++++++++ templates/dtc.html | 4 +++- 5 files changed, 56 insertions(+), 4 deletions(-) diff --git a/app_account.py b/app_account.py index 7ae368d..8132564 100644 --- a/app_account.py +++ b/app_account.py @@ -1,5 +1,27 @@ +import app_car as Car + +account_car = Car() +account_car.model = "YARIS" +account_pp_image = "static\img\image.png" +account_info = ["name","pp_image", "car_model"] + class Account: def __init__(self): self.name = "quoije" self.pp_image = None - self.car = None \ No newline at end of file + self.car = account_car.model + +def account_info(): + obd_speed_lock.acquire() + cmd = obd.commands.GET_DTC # select an OBD command (sensor) + response = connection.query(cmd) # send the command and parse the response + try: + if response.is_null(): + error_txt = "No data received." + print(error_txt) + socketio.emit('obd_dtc', error_txt) + else: + print(response.value) + socketio.emit('obd_dtc', response.value) + finally: + obd_rpm_lock.release() \ No newline at end of file diff --git a/app_car.py b/app_car.py index 72e47b9..e185df7 100644 --- a/app_car.py +++ b/app_car.py @@ -1,4 +1,3 @@ class Car: def __init__(self): - self.model = None - self.obd = None \ No newline at end of file + self.model = None \ No newline at end of file diff --git a/app_obd.py b/app_obd.py index 29a0fe6..1798a52 100644 --- a/app_obd.py +++ b/app_obd.py @@ -95,6 +95,21 @@ def obd_rpm(): socketio.emit('obd_speed', response.value.to("kph")) finally: obd_rpm_lock.release() + +def obd_dtc(): + obd_speed_lock.acquire() + cmd = obd.commands.GET_DTC # select an OBD command (sensor) + response = connection.query(cmd) # send the command and parse the response + try: + if response.is_null(): + error_txt = "No data received." + print(error_txt) + socketio.emit('obd_dtc', error_txt) + else: + print(response.value) + socketio.emit('obd_dtc', response.value) + finally: + obd_rpm_lock.release() def kill_obd(obd_type): if obd_type == "speed": diff --git a/static/js/yaris.js b/static/js/yaris.js index 50feb9e..133183f 100644 --- a/static/js/yaris.js +++ b/static/js/yaris.js @@ -38,6 +38,14 @@ socket.on('connect', function(data) { console.log('socket.io is connected') }); +socket.on('account_info', function(data) { + console.log(data); + + // car model + const car_model = document.getElementById('index-car-model'); + car_model.innerHTML = data; +}); + socket.on('obd_status', function(data) { console.log(data); const status = document.getElementById('obd-status'); @@ -75,6 +83,12 @@ socket.on('obd_rpm', function(data) { status.innerHTML = data; }); +socket.on('obd_dtc', function(data) { + console.log("obd dtc "+data); + const status = document.getElementById('obd-dtc'); + status.innerHTML = data; +}); + socket.on('obd_error', function(data) { console.log("obd errors "+data); const status = document.getElementById('obd-error'); diff --git a/templates/dtc.html b/templates/dtc.html index ba74135..a4abe0f 100644 --- a/templates/dtc.html +++ b/templates/dtc.html @@ -58,7 +58,9 @@

Output

-
+
+

+