Skip to content

Resolve SW-13543 "Update the first line of asc file to use logging start time instead of asc file created time" #1903

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions can/io/asc.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ def __init__(
self.channel = channel

# write start of file header
start_time = self._format_header_datetime(datetime.now())
self.file.write(f"date {start_time}\n")
self.start_time = self._format_header_datetime(datetime.now())
self.file.write(f"date {self.start_time}\n")
self.file.write("base hex timestamps absolute\n")
self.file.write("internal events logged\n")

Expand All @@ -394,6 +394,14 @@ def stop(self) -> None:
# This is guaranteed to not be None since we raise ValueError in __init__
if not self.file.closed:
self.file.write("End TriggerBlock\n")
if self.started is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you check for None?

formatted_date = self._format_header_datetime(
datetime.fromtimestamp(self.started)
)
self.file.seek(0)
self.file.write(f"date {formatted_date}\n")
else:
logger.warning("No messages logged; 'started' timestamp is None.")
super().stop()

def log_event(self, message: str, timestamp: Optional[float] = None) -> None:
Expand Down
Loading