Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

M20 T support (timestamps for files on sd card) #4610

Merged
merged 5 commits into from
Aug 15, 2022

Conversation

arekm
Copy link
Contributor

@arekm arekm commented Aug 4, 2022

M20 T support (timestamps for files on sd card).

Use "M20 L T" (if CAPABILITY_EXTENDED_M20 is available) which gives
us long file names but also file timestamps.

Wire up that timestamp into "date" field which gives us "Uploaded: ...
ago" for files on SD card. Sorting by upload date also works.

Implementing this also fixes parsing of response to (for example
manually sent) "M20 T" command. Octoprint assumed that third entry
in response is always long file name while with M20 T it is timestamp.

@github-actions github-actions bot added docs Related to documentation targets devel The PR targets the devel branch approved Issue has been approved by the bot or manually for further processing labels Aug 4, 2022
@arekm arekm force-pushed the arekm/devel/m20t branch 6 times, most recently from 59d8602 to 54f242f Compare August 5, 2022 07:59
@arekm
Copy link
Contributor Author

arekm commented Aug 5, 2022

Printers don't have real time clock and on M28 upload they set ancient date (like 2000-01-01 01:00:00 - prusa mk3s does that) which then shows up in octoprint as "Uploaded: 23 years ago".

Printer tells us such timestamp in M20 T, so it is being shown but maybe it would be better to ignore such dates and show nothing(?)

Virtual printer emulates this behaviour, too. If you want updated timestamp just touch file in ~/.octoprint/virtualSd/.

timestamps on vfat filesystems (used on most sd cards) are considered to be in "local time" (this is behaviour of windows and macos). Linux unfortunately considers these UTC, so if someone mounts sd card on Linux (with default options), puts gcode files there and then put sd card into printer there will be offset shown, but we can't do nothing about this. If someone does the same on windows or macos then printer and octoprint will show correct upload time.

@foosel
Copy link
Member

foosel commented Aug 8, 2022

Printer tells us such timestamp in M20 T, so it is being shown but maybe it would be better to ignore such dates and show nothing(?)

I've always followed the approach that what the firmware reports gets used. Otherwise we'll get "bug reports" about missing timestamps. This way of course we'll risk "bug reports" about invalid timestamps, but at least we can then just point people to this PR and explain that we just display what the firmware reports and that it is up to the firmware to make a decision here (e.g. NOT return a timestamp for files created directly by the firmware).

Copy link
Member

@foosel foosel left a comment

Choose a reason for hiding this comment

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

Got some review annotations, mostly regarding the structure and test coverage.

src/octoprint/util/__init__.py Outdated Show resolved Hide resolved
src/octoprint/util/__init__.py Outdated Show resolved Hide resolved
src/octoprint/util/comm.py Outdated Show resolved Hide resolved
src/octoprint/util/files.py Outdated Show resolved Hide resolved
src/octoprint/util/comm.py Outdated Show resolved Hide resolved
src/octoprint/plugins/virtual_printer/virtual.py Outdated Show resolved Hide resolved
@foosel
Copy link
Member

foosel commented Aug 8, 2022

Please make sure to request a new review once you've implemented the requested changes.

@foosel
Copy link
Member

foosel commented Aug 8, 2022

I sadly only just now noticed that you opened this PR against devel. Since this is not a backwards incompatible new feature but rather an improvement of an existing one, this should be opened against maintenance instead. Also see the contribution guidelines and the dev docs.

@arekm arekm changed the base branch from devel to maintenance August 8, 2022 12:11
@arekm arekm changed the base branch from maintenance to devel August 8, 2022 12:11
@arekm arekm changed the base branch from devel to maintenance August 8, 2022 12:37
@arekm
Copy link
Contributor Author

arekm commented Aug 8, 2022

Should be now against maintenance branch (and I saw docs but wasn't sure what printers do if T is unrecognized. Fortunately they just ignore it).

@arekm arekm requested a review from foosel August 8, 2022 12:42
@arekm arekm force-pushed the arekm/devel/m20t branch 3 times, most recently from ad7141f to 3346f50 Compare August 8, 2022 17:28
Change the way line is built, so it will be easier to add new things
without duplicating conditions.
Use "M20 L T" (if CAPABILITY_EXTENDED_M20 is available) which gives
us long file names but also file timestamps.

Wire up that timestamp into "date" field which gives us "Uploaded: ...
ago" for files on SD card. Sorting by upload date also works.

Implementing this also fixes parsing of response to (for example
manually sent) "M20 T" command. Octoprint assumed that third entry
in response is always long file name while with M20 T it is timestamp.

Add conversion routines between M20 T timestamp and unix timestamp. Wire
up that conversion in virtual printer.
Move file list parsing into separate parse_file_list_line function and
add tests for it.

Add better timestamp validation.
@arekm
Copy link
Contributor Author

arekm commented Aug 13, 2022

Moved parsing into separate function, added tests.

Make m20_timestamp_to_unix_timestamp() directly accept hex timestamp
string. Use this function for timestamp validation.

unix_timestamp_to_m20_timestamp() returns hex string now.
@foosel
Copy link
Member

foosel commented Aug 15, 2022

Please make sure to request a new review once you're done working on this and it is ready for another review.

@arekm
Copy link
Contributor Author

arekm commented Aug 15, 2022

I see "foosel was requested for review" and I don't see any new way to request review again in github UI.

At this moment I have no pending changes/improvements.

@foosel
Copy link
Member

foosel commented Aug 15, 2022

I just kept seeing new and new pushes, so I wanted to make sure you really are done here before I give this another review. It's a bit tricky to hit a moving target ;)

@foosel foosel added targets maintenance The PR targets the maintenance branch and removed targets devel The PR targets the devel branch labels Aug 15, 2022
@foosel foosel added this to the 1.9.0 milestone Aug 15, 2022
@foosel
Copy link
Member

foosel commented Aug 15, 2022

Looks good now, merging, thank you :)

@foosel foosel merged commit 65e222d into OctoPrint:maintenance Aug 15, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Issue has been approved by the bot or manually for further processing docs Related to documentation targets maintenance The PR targets the maintenance branch
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants