Skip to content

Update getFileBlock #39

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

Merged
merged 9 commits into from
Feb 27, 2024
Merged

Conversation

fronders
Copy link
Contributor

@fronders fronders commented Feb 5, 2024

This addresses several things:

PaulZC and others added 6 commits August 21, 2023 09:22
Adding issue tracking .yml file for issue tracking in GH Projects.
This fixes sparkfun#38
When used with ARM GCC Toolchain supplied with Arduino_STM32 newlib nano version is built without C99 formats support, so the %zu format specifier doesn't work, and instead of putting the number it puts "zu" into the resulting string
This adds more error checking and command formatting to make it similar to other methods. Also makes detecting comma_idx (offset of file size in the response) more reliable
@PaulZC
Copy link
Collaborator

PaulZC commented Feb 5, 2024

Hi @fronders ,

Thanks for submitting this.

Some compilers are 'fussy' and will throw an error on %lu if the type isn't 'long'. I'll run the compile-sketch test on it...

Cheers,
Paul

@PaulZC
Copy link
Collaborator

PaulZC commented Feb 5, 2024

Yeah... %lu fails on ESP32:

image

It's messy, but you can fix this with a selective compile. Something like:

#ifdef ARDUINO_ARCH_ESP32 // ESP32 based boards
sprintf(command, "%s=\"%s\",%zu,%zu", SARA_R5_FILE_SYSTEM_READ_BLOCK, filename.c_str(), offset, requested_length);
#else
sprintf(command, "%s=\"%s\",%lu,%lu", SARA_R5_FILE_SYSTEM_READ_BLOCK, filename.c_str(), offset, requested_length);
#endif

@fronders
Copy link
Contributor Author

fronders commented Feb 5, 2024

@PaulZC I just noticed, that I forgot to add more error handling to response parser, hence the unused err variable. I'll get back when I have the code

@fronders
Copy link
Contributor Author

fronders commented Feb 5, 2024

@PaulZC I think using it with an explicit cast to unsigned long would be more universal than defining platform-dependant chunks:

// OK, yet insufficient with large sizes > ULONG_MAX
printf("%lu\n", (unsigned long) some_size_t_object); 

We should be fine with this for all 32-bit MCUs

Taken from here, what do you think?

Added sprintf arguments type casting from size_t to unsigned long (or unsigned long long on 64-bit arch)
This adds response error checking for getFileBlock and minor formatting fixes to make it similar to other methods
@fronders
Copy link
Contributor Author

fronders commented Feb 5, 2024

@PaulZC just added that fix from code above that should work everywhere.

Also added error handling and response checks for getFileBlock() as it turns out it didn't have any before

After more testing, kept only casting from size_t to unsigned long (compatible with 32-bit MCUs)
@PaulZC
Copy link
Collaborator

PaulZC commented Feb 5, 2024

Thanks @fronders ,

I'll give this another read through tomorrow, but all looks good...

Cheers,
Paul

@fronders
Copy link
Contributor Author

hey @PaulZC, any updates? :)

@PaulZC
Copy link
Collaborator

PaulZC commented Feb 23, 2024

Sorry @fronders - other stuff got in the way. I'll try and do this today. Please nudge me if I don't... Thanks!

@PaulZC PaulZC changed the base branch from main to release_candidate February 27, 2024 14:51
@PaulZC PaulZC merged commit 139b1b0 into sparkfun:release_candidate Feb 27, 2024
@fronders fronders deleted the fix-get-file-block branch March 20, 2024 07:29
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.

%zu not supported by newlib's printf in Arduino_STM32 toolchain
3 participants