# Conflicts:
#	main.py
This commit is contained in:
Etienne Chassaing 2025-07-17 12:32:29 +02:00
commit edc3a45194
3 changed files with 36 additions and 23 deletions

5
.gitignore vendored
View File

@ -1 +1,6 @@
__pycache__/main.cpython-311.pyc __pycache__/main.cpython-311.pyc
recordings/recording_20250716_145535.csv
recordings/recording_20250716_143101.csv
recordings/recording_20250716_143537.csv
recordings/recording_20250716_150700.csv
recordings/recording_20250716_181008.csv

View File

@ -85,13 +85,13 @@ class CANBackend:
mv07Cmd = node.sdo[0x2015][1].raw mv07Cmd = node.sdo[0x2015][1].raw
mv08Cmd = node.sdo[0x2022][1].raw mv08Cmd = node.sdo[0x2022][1].raw
mv02fb = node.sdo[0x3000][2].raw # mv02fb = node.sdo[0x3000][2].raw
mv03fb = node.sdo[0x3000][3].raw # mv03fb = node.sdo[0x3000][3].raw
mv04fb = node.sdo[0x3000][4].raw # mv04fb = node.sdo[0x3000][4].raw
mv05fb = node.sdo[0x3000][5].raw # mv05fb = node.sdo[0x3000][5].raw
mv06fb = node.sdo[0x3000][6].raw # mv06fb = node.sdo[0x3000][6].raw
mv07fb = node.sdo[0x3000][7].raw # mv07fb = node.sdo[0x3000][7].raw
mv08fb = node.sdo[0x3000][8].raw # mv08fb = node.sdo[0x3000][8].raw
self.latest_data[pu_number] = { self.latest_data[pu_number] = {
"FM1": (fm1 / 100.0) * 60.0, "FM1": (fm1 / 100.0) * 60.0,
@ -104,21 +104,21 @@ class CANBackend:
"PS3": ps3 / 1000.0, "PS3": ps3 / 1000.0,
"PS4": ps4 / 1000.0, "PS4": ps4 / 1000.0,
"MV02_sp" : mv02Cmd, "MV02_sp" : mv02Cmd / 100.0,
"MV03_sp" : mv03Cmd, "MV03_sp" : mv03Cmd / 100.0,
"MV04_sp" : mv04Cmd, "MV04_sp" : mv04Cmd / 100.0,
"MV05_sp" : mv05Cmd, "MV05_sp" : mv05Cmd / 100.0,
"MV06_sp" : mv06Cmd, "MV06_sp" : mv06Cmd / 100.0,
"MV07_sp" : mv07Cmd, "MV07_sp" : mv07Cmd / 100.0,
"MV08_sp" : mv08Cmd, "MV08_sp" : mv08Cmd / 100.0,
"MV02" : mv02fb, # "MV02" : mv02fb,
"MV03" : mv03fb, # "MV03" : mv03fb,
"MV04" : mv04fb, # "MV04" : mv04fb,
"MV05" : mv05fb, # "MV05" : mv05fb,
"MV06" : mv06fb, # "MV06" : mv06fb,
"MV07" : mv07fb, # "MV07" : mv07fb,
"MV08" : mv08fb, # "MV08" : mv08fb,
} }
print(f"[PU{pu_number}] FM1: {fm1}, PS1: {ps1}") print(f"[PU{pu_number}] FM1: {fm1}, PS1: {ps1}")

12
main.py
View File

@ -249,10 +249,12 @@ async def update_latest_data():
@app.get("/monitor") @app.get("/monitor")
async def get_monitor_data(pu_number: Optional[int] = Query(None)): async def get_monitor_data(pu_number: Optional[float] = Query(None)):
print(f"pu_number is {pu_number}")
if pu_number is not None: if pu_number is not None:
return latest_data.get(f"PU_{pu_number}", {}) return latest_data.get(f"PU_{pu_number}", {})
else: else:
# print(latest_data)
return latest_data return latest_data
@ -290,7 +292,7 @@ async def start_recording():
filepath = os.path.join("recordings", filename) filepath = os.path.join("recordings", filename)
recording_file = open(filepath, "w", newline="") recording_file = open(filepath, "w", newline="")
fieldnames = ["timestamp", "pu"] + list(format_data({}).keys()) fieldnames = ["timestamp", "pu", "QSkid"] + list(format_data({}).keys())
recording_writer = csv.DictWriter(recording_file, fieldnames=fieldnames) recording_writer = csv.DictWriter(recording_file, fieldnames=fieldnames)
recording_writer.writeheader() recording_writer.writeheader()
@ -328,6 +330,12 @@ async def record_data_loop():
for pu, data in latest_data.items(): for pu, data in latest_data.items():
if data: if data:
row = {"timestamp": timestamp, "pu": pu, **data} row = {"timestamp": timestamp, "pu": pu, **data}
print("record_data",data)
row = {
"timestamp": timestamp,
"pu": pu,
**data
}
recording_writer.writerow(row) recording_writer.writerow(row)
# Flush every flush_interval seconds # Flush every flush_interval seconds