Fix data logger

This commit is contained in:
marios8543 2024-05-16 15:25:10 +03:00
parent ee90fa861e
commit 67aba95ef6
4 changed files with 39 additions and 15 deletions

View File

@ -76,7 +76,7 @@ class DDT_MON():
framefilter = ''
def __init__(self, elm, xmlfile, outfile, infile ):
self.elm = elm
self.elm: ELM = elm
clearScreen()
print("Starting DDT process")
@ -391,8 +391,6 @@ def chooseXml():
return choice[0]
def main():
global candef

View File

@ -5,6 +5,7 @@ from csv import writer, QUOTE_MINIMAL
from datetime import datetime
import mod_globals
mod_globals.opt_demo = True
dash = RenDash("/dev/tty1")
@ -19,24 +20,34 @@ running = False
bg_thread = None
def mainloop():
global running, watched_datarefs, watched_ecu, should_log, freeze
if should_log:
log_filename = f'{datetime.now().strftime("%m/%d/%Y, %H:%M:%S")}.csv'
log_filename = f'../logs/{datetime.now().strftime("%m-%d-%Y %H:%M:%S")}.csv'
print("Creating log on file: " + log_filename)
with open(log_filename, "w+") as file:
csv_writer = writer(file,delimiter=' ', quotechar='|', quoting=QUOTE_MINIMAL)
csv_writer.writerow(["freeze"].extend(watched_datarefs))
file = open(log_filename, "w")
csv_writer = writer(
file, delimiter=" ", quotechar="|", quoting=QUOTE_MINIMAL
)
csv_writer.writerow(["freeze"] + watched_datarefs)
print("Starting data loop")
while running:
frame = [dash.get_ecu_dataref(watched_ecu, dataref) for dataref in watched_datarefs]
frame = [
dash.get_ecu_dataref(watched_ecu, dataref)[0] for dataref in watched_datarefs
]
socket.emit("frame", {"frame": frame})
if should_log:
csv_writer.writerow([freeze].extend(frame))
csv_writer.writerow([freeze] + frame)
freeze = 0
print(frame)
if should_log:
file.flush()
file.close()
@socket.on("freeze")
def freeze_event():
global freeze
@ -48,14 +59,17 @@ def get_ecus():
ecus = dash.get_ecu_names()
return jsonify(ecus)
@web.get("/ecus/<ecu_doc>/states")
def get_ecu_states(ecu_doc):
return jsonify(dash.get_ecu_states(ecu_doc))
@web.get("/ecus/<ecu_doc>/parameters")
def get_ecu_parameters(ecu_doc):
return jsonify(dash.get_ecu_parameters(ecu_doc))
@web.post("/ecus/<ecu_doc>/watch")
def ecu_watch(ecu_doc):
global watched_ecu, watched_datarefs
@ -63,8 +77,9 @@ def ecu_watch(ecu_doc):
datarefs = request.get_json()
watched_datarefs = []
for dataref in datarefs:
if dataref in dash.get_ecu_parameters(ecu_doc) \
or dataref in dash.get_ecu_states(ecu_doc):
if dataref in dash.get_ecu_parameters(
ecu_doc
) or dataref in dash.get_ecu_states(ecu_doc):
watched_datarefs.append(dataref)
else:
watched_datarefs = []
@ -73,10 +88,13 @@ def ecu_watch(ecu_doc):
return jsonify({"ecu": watched_ecu, "datarefs": watched_datarefs})
@web.get("/start")
def start():
global should_log, bg_thread, running
if running:
return jsonify({"success": False})
log = request.args.get("log")
if log == "true":
should_log = True
@ -87,6 +105,7 @@ def start():
bg_thread = socket.start_background_task(mainloop)
return jsonify({"success": True})
@web.get("/stop")
def stop():
global bg_thread, running
@ -95,9 +114,11 @@ def stop():
bg_thread.join()
return jsonify({"success": True})
@web.get("/")
def index():
return send_file("index.html")
if __name__ == "__main__":
socket.run(web, "0.0.0.0", 5000)

View File

@ -31,6 +31,7 @@
</div>
<div v-if="watching">
<h2>Watching</h2>
<button style="width: auto; height: auto; font-size: xx-large;" v-if="logging" @click="sendFreeze">FREEZE</button><br>
<div v-for="item in selectedItems" :key="item">
{{ statesAndParams[item] }}: {{ itemValues[item] }}
</div>
@ -112,6 +113,9 @@
method: "GET",
});
},
async sendFreeze() {
socket.emit("freeze");
}
},
mounted() {
this.fetchEcuList();

View File

@ -42,7 +42,8 @@ def get_parameter( pr, mn, se, elm, calc, dataids = {} ):
tmpmin = ''
tmpmax = ''
return "%5s %10s %-10s %-5s"%(tmpmin,pr.value,pr.unit,tmpmax), pr.helps, csv_data
#return "%5s %10s %-10s %-5s"%(tmpmin,pr.value,pr.unit,tmpmax), pr.helps, csv_data
return "%10s"%(pr.value), pr.helps, csv_data
class ecu_parameter: