Skip to content

Commit

Permalink
Changed elm log format to be CSV compliant and added headers
Browse files Browse the repository at this point in the history
  • Loading branch information
josefe17 committed Oct 18, 2023
1 parent c8bf067 commit ae01a61
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions elm.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ def __init__(self, portName, rate, adapter_type="STD", maxspeed="No"):
if len(options.log) > 0:
self.lf = open("./logs/elm_" + options.log + ".txt", "at", encoding="utf-8")
self.vf = open("./logs/ecu_" + options.log + ".txt", "at", encoding="utf-8")
self.vf.write("Timestamp;ECU_CAN_Address_HEX;Raw_Command_HEX;Raw_Response_HEX_or_STR;Error_message_if_happens\n")

self.lastCMDtime = 0
self.ATCFC0 = options.opt_cfc0
Expand Down Expand Up @@ -735,9 +736,9 @@ def request(self, req, positive='', cache=True, serviceDelay="0"):
if self.vf != 0:
tmstr = datetime.now().strftime("%H:%M:%S.%f")[:-3]
if self.currentaddress in dnat:
self.vf.write(tmstr + ";" + dnat[self.currentaddress] + ";" + req + ";" + rsp + "\n")
self.vf.write(tmstr + ";" + "0x" + dnat[self.currentaddress] + ";" + "0x" + req + ";" + "0x" + rsp.rstrip().replace(" ", ",0x") + ";" +"\n")
else:
print("Unknown address ", self.currentaddress, req, rsp)
print("Unknown address: ", self.currentaddress, "0x" + req, "0x" + rsp)
self.vf.flush()

return rsp
Expand Down Expand Up @@ -912,7 +913,7 @@ def send_can(self, command):
if self.vf != 0:
tmstr = datetime.now().strftime("%H:%M:%S.%f")[:-3]
self.vf.write(
tmstr + ";" + dnat[self.currentaddress] + ";" + command + ";" + result + ";" + errorstr + "\n")
tmstr + ";" + dnat[self.currentaddress] + ";" + "0x" + command + ";" + result + ";" + errorstr + "\n")
self.vf.flush()

# populate L1 cache
Expand Down

0 comments on commit ae01a61

Please sign in to comment.