I'm using Python CAN to look for events in BLF files, specifically J1939 TD events so I can determine in which log a "real world"/vehicle timestamped events occurred.
Something along the lines of:
log = can.BLFReader(filename)
for msg in log:
if (is_Message_FEE6(msg))
etc
However, if I want to find the first and last TD messages in a log, I have to search the entire log "forwards" in order to find the last TD. Since some of the log files are hundreds of MB, this is somewhat time consuming.
So, is it possible to read the log file in reverse?
e.g.
foundFirst = False
foundLast = False
open log
for msg in log:
if isMessageFEE6(msg):
first_TD = ExtractTD(msg)
FoundFirst = True
break
for msg in log.reversed():
if isMessageFEE6(msg):
last_TD = ExtractTD(msg)
FoundLast = True
break
Thanks in advance