Fix data logger
This commit is contained in:
parent
ee90fa861e
commit
67aba95ef6
@ -76,7 +76,7 @@ class DDT_MON():
|
|||||||
framefilter = ''
|
framefilter = ''
|
||||||
|
|
||||||
def __init__(self, elm, xmlfile, outfile, infile ):
|
def __init__(self, elm, xmlfile, outfile, infile ):
|
||||||
self.elm = elm
|
self.elm: ELM = elm
|
||||||
|
|
||||||
clearScreen()
|
clearScreen()
|
||||||
print("Starting DDT process")
|
print("Starting DDT process")
|
||||||
@ -391,8 +391,6 @@ def chooseXml():
|
|||||||
|
|
||||||
return choice[0]
|
return choice[0]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
global candef
|
global candef
|
||||||
|
@ -5,6 +5,7 @@ from csv import writer, QUOTE_MINIMAL
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import mod_globals
|
import mod_globals
|
||||||
|
|
||||||
mod_globals.opt_demo = True
|
mod_globals.opt_demo = True
|
||||||
|
|
||||||
dash = RenDash("/dev/tty1")
|
dash = RenDash("/dev/tty1")
|
||||||
@ -19,24 +20,34 @@ running = False
|
|||||||
|
|
||||||
bg_thread = None
|
bg_thread = None
|
||||||
|
|
||||||
|
|
||||||
def mainloop():
|
def mainloop():
|
||||||
global running, watched_datarefs, watched_ecu, should_log, freeze
|
global running, watched_datarefs, watched_ecu, should_log, freeze
|
||||||
if should_log:
|
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)
|
print("Creating log on file: " + log_filename)
|
||||||
with open(log_filename, "w+") as file:
|
file = open(log_filename, "w")
|
||||||
csv_writer = writer(file,delimiter=' ', quotechar='|', quoting=QUOTE_MINIMAL)
|
csv_writer = writer(
|
||||||
csv_writer.writerow(["freeze"].extend(watched_datarefs))
|
file, delimiter=" ", quotechar="|", quoting=QUOTE_MINIMAL
|
||||||
|
)
|
||||||
|
csv_writer.writerow(["freeze"] + watched_datarefs)
|
||||||
|
|
||||||
print("Starting data loop")
|
print("Starting data loop")
|
||||||
while running:
|
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})
|
socket.emit("frame", {"frame": frame})
|
||||||
if should_log:
|
if should_log:
|
||||||
csv_writer.writerow([freeze].extend(frame))
|
csv_writer.writerow([freeze] + frame)
|
||||||
freeze = 0
|
freeze = 0
|
||||||
print(frame)
|
print(frame)
|
||||||
|
|
||||||
|
if should_log:
|
||||||
|
file.flush()
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
|
||||||
@socket.on("freeze")
|
@socket.on("freeze")
|
||||||
def freeze_event():
|
def freeze_event():
|
||||||
global freeze
|
global freeze
|
||||||
@ -48,14 +59,17 @@ def get_ecus():
|
|||||||
ecus = dash.get_ecu_names()
|
ecus = dash.get_ecu_names()
|
||||||
return jsonify(ecus)
|
return jsonify(ecus)
|
||||||
|
|
||||||
|
|
||||||
@web.get("/ecus/<ecu_doc>/states")
|
@web.get("/ecus/<ecu_doc>/states")
|
||||||
def get_ecu_states(ecu_doc):
|
def get_ecu_states(ecu_doc):
|
||||||
return jsonify(dash.get_ecu_states(ecu_doc))
|
return jsonify(dash.get_ecu_states(ecu_doc))
|
||||||
|
|
||||||
|
|
||||||
@web.get("/ecus/<ecu_doc>/parameters")
|
@web.get("/ecus/<ecu_doc>/parameters")
|
||||||
def get_ecu_parameters(ecu_doc):
|
def get_ecu_parameters(ecu_doc):
|
||||||
return jsonify(dash.get_ecu_parameters(ecu_doc))
|
return jsonify(dash.get_ecu_parameters(ecu_doc))
|
||||||
|
|
||||||
|
|
||||||
@web.post("/ecus/<ecu_doc>/watch")
|
@web.post("/ecus/<ecu_doc>/watch")
|
||||||
def ecu_watch(ecu_doc):
|
def ecu_watch(ecu_doc):
|
||||||
global watched_ecu, watched_datarefs
|
global watched_ecu, watched_datarefs
|
||||||
@ -63,8 +77,9 @@ def ecu_watch(ecu_doc):
|
|||||||
datarefs = request.get_json()
|
datarefs = request.get_json()
|
||||||
watched_datarefs = []
|
watched_datarefs = []
|
||||||
for dataref in datarefs:
|
for dataref in datarefs:
|
||||||
if dataref in dash.get_ecu_parameters(ecu_doc) \
|
if dataref in dash.get_ecu_parameters(
|
||||||
or dataref in dash.get_ecu_states(ecu_doc):
|
ecu_doc
|
||||||
|
) or dataref in dash.get_ecu_states(ecu_doc):
|
||||||
watched_datarefs.append(dataref)
|
watched_datarefs.append(dataref)
|
||||||
else:
|
else:
|
||||||
watched_datarefs = []
|
watched_datarefs = []
|
||||||
@ -73,10 +88,13 @@ def ecu_watch(ecu_doc):
|
|||||||
|
|
||||||
return jsonify({"ecu": watched_ecu, "datarefs": watched_datarefs})
|
return jsonify({"ecu": watched_ecu, "datarefs": watched_datarefs})
|
||||||
|
|
||||||
|
|
||||||
@web.get("/start")
|
@web.get("/start")
|
||||||
def start():
|
def start():
|
||||||
global should_log, bg_thread, running
|
global should_log, bg_thread, running
|
||||||
|
|
||||||
|
if running:
|
||||||
|
return jsonify({"success": False})
|
||||||
log = request.args.get("log")
|
log = request.args.get("log")
|
||||||
if log == "true":
|
if log == "true":
|
||||||
should_log = True
|
should_log = True
|
||||||
@ -87,6 +105,7 @@ def start():
|
|||||||
bg_thread = socket.start_background_task(mainloop)
|
bg_thread = socket.start_background_task(mainloop)
|
||||||
return jsonify({"success": True})
|
return jsonify({"success": True})
|
||||||
|
|
||||||
|
|
||||||
@web.get("/stop")
|
@web.get("/stop")
|
||||||
def stop():
|
def stop():
|
||||||
global bg_thread, running
|
global bg_thread, running
|
||||||
@ -95,9 +114,11 @@ def stop():
|
|||||||
bg_thread.join()
|
bg_thread.join()
|
||||||
return jsonify({"success": True})
|
return jsonify({"success": True})
|
||||||
|
|
||||||
|
|
||||||
@web.get("/")
|
@web.get("/")
|
||||||
def index():
|
def index():
|
||||||
return send_file("index.html")
|
return send_file("index.html")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
socket.run(web, "0.0.0.0", 5000)
|
socket.run(web, "0.0.0.0", 5000)
|
@ -31,6 +31,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div v-if="watching">
|
<div v-if="watching">
|
||||||
<h2>Watching</h2>
|
<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">
|
<div v-for="item in selectedItems" :key="item">
|
||||||
{{ statesAndParams[item] }}: {{ itemValues[item] }}
|
{{ statesAndParams[item] }}: {{ itemValues[item] }}
|
||||||
</div>
|
</div>
|
||||||
@ -112,6 +113,9 @@
|
|||||||
method: "GET",
|
method: "GET",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
async sendFreeze() {
|
||||||
|
socket.emit("freeze");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.fetchEcuList();
|
this.fetchEcuList();
|
||||||
|
@ -42,7 +42,8 @@ def get_parameter( pr, mn, se, elm, calc, dataids = {} ):
|
|||||||
tmpmin = ''
|
tmpmin = ''
|
||||||
tmpmax = ''
|
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:
|
class ecu_parameter:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user