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

gcode: Update M20 to fit common marlin behaviour #3765

Closed
wants to merge 1 commit into from

Conversation

bkerler
Copy link
Contributor

@bkerler bkerler commented Feb 18, 2024

This addresses the issue #3054.

It improves the gcode M20 to:

  1. Support listing of subdirectories and files
  2. Differentiate between directories and files
  3. Adds support for timestamp ("T") and long filenames ("L") to match the marlin firmware behaviour

@arekm
Copy link

arekm commented Feb 19, 2024

EXTENDED_M20 capability needs to be reported, too

https://reprap.org/wiki/Firmware_Capabilities_Protocol#Cap:EXTENDED_M20

src/marlin_stubs/sdcard/M20-M30_M32-M34.cpp Outdated Show resolved Hide resolved
src/marlin_stubs/sdcard/M20-M30_M32-M34.cpp Outdated Show resolved Hide resolved
src/marlin_stubs/sdcard/M20-M30_M32-M34.cpp Outdated Show resolved Hide resolved
src/marlin_stubs/sdcard/M20-M30_M32-M34.cpp Outdated Show resolved Hide resolved
@bkerler
Copy link
Contributor Author

bkerler commented Feb 19, 2024

image

Implementation has been updated.

@bkerler bkerler requested review from arekm and danopernis February 19, 2024 19:51
@bkerler bkerler force-pushed the m20_upgrade branch 3 times, most recently from 8568873 to a419933 Compare February 19, 2024 20:29
src/marlin_stubs/sdcard/M20-M30_M32-M34.cpp Outdated Show resolved Hide resolved
src/marlin_stubs/sdcard/M20-M30_M32-M34.cpp Outdated Show resolved Hide resolved
src/marlin_stubs/sdcard/M20-M30_M32-M34.cpp Outdated Show resolved Hide resolved
src/marlin_stubs/sdcard/M20-M30_M32-M34.cpp Outdated Show resolved Hide resolved
src/marlin_stubs/sdcard/M20-M30_M32-M34.cpp Outdated Show resolved Hide resolved
src/marlin_stubs/sdcard/M20-M30_M32-M34.cpp Outdated Show resolved Hide resolved
src/marlin_stubs/sdcard/M20-M30_M32-M34.cpp Outdated Show resolved Hide resolved
Copy link

@arekm arekm left a comment

Choose a reason for hiding this comment

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

Have no way to test this on a printer but tested time_to_m20() implementation on Linux and it correctly translates dates/times that fit into 32bit (tests from OctoPrint test suite, beside 64bit one).

I would move printing LFN inside stat() success path because other implementations parse fat dir directly and always know the size (thus always return it). OctoPrint parser was made with that in mind and won't be able to parse long file name from just
shortfilename "longfilename"
output. It needs at least size in 3 element lines (so "shortfilename size timestamp" or "shortfilename size longfilename)

For reference:
https://github.com/OctoPrint/OctoPrint/blob/1.10.0rc2/src/octoprint/util/comm.py#L6451-L6472

@bkerler
Copy link
Contributor Author

bkerler commented Feb 20, 2024

Have no way to test this on a printer but tested time_to_m20() implementation on Linux and it correctly translates dates/times that fit into 32bit (tests from OctoPrint test suite, beside 64bit one).

I would move printing LFN inside stat() success path because other implementations parse fat dir directly and always know the size (thus always return it). OctoPrint parser was made with that in mind and won't be able to parse long file name from just shortfilename "longfilename" output. It needs at least size in 3 element lines (so "shortfilename size timestamp" or "shortfilename size longfilename)

For reference: https://github.com/OctoPrint/OctoPrint/blob/1.10.0rc2/src/octoprint/util/comm.py#L6451-L6472

Agree. I've moved it into the stat() success path.

@bkerler bkerler requested a review from arekm February 20, 2024 22:55
Copy link
Member

@danopernis danopernis left a comment

Choose a reason for hiding this comment

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

Starting to shape up, good job 😉


static void print_file_info(const char *const path, const char *const long_path, const struct TimeFlags tf) {
// &path[5] and &long_path[5], because we skip the /usb/ prefix on print as it is only used internally
SERIAL_ECHO(&path[5]);
Copy link
Member

Choose a reason for hiding this comment

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

There's a strlen_constexpr() in str_utils.hpp, we should be able to use that. Not that I am expecting the internal path to change, it just looks more readable/maintainable to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, good idea.

SERIAL_ECHOLN(entry->d_name);
char path[5 + sizeof(entry->d_name) * 2];
snprintf(path, sizeof(path), "%s/%s", prefix, entry->d_name);
char long_path[5 + sizeof(entry->lfn) * 2];
Copy link
Member

Choose a reason for hiding this comment

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

I still don't understand these buffer sizes. Why *2 ? We are only supporting root directory, right? I would imagine we need "/usb/" + respective filename (sfn or lfn) + possibly a null terminator. What am I missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea was that sizeof(entry->d_name) has the same size as prefix. But yeah, I've changed that completely because it wasn't clean and safe. Should be fine now.

@bkerler
Copy link
Contributor Author

bkerler commented May 18, 2024

Closing in favor of #3976, which has additional support

@bkerler bkerler closed this May 18, 2024
@bkerler bkerler deleted the m20_upgrade branch May 18, 2024 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants