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

Is there an error in the file transfer example? #89

Open
yursky91 opened this issue Mar 27, 2022 · 2 comments
Open

Is there an error in the file transfer example? #89

yursky91 opened this issue Mar 27, 2022 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@yursky91
Copy link

Hi!

I don't quite understand the values used in the uart_tx_file.ino file.
Why we use (MAX_PACKET_SIZE - 2) in some places, and just MAX_PACKET_SIZE in others.
In particular, the calculation of numPackets seems to be going wrong:

uint16_t numPackets = fileSize / (MAX_PACKET_SIZE - 2); // Reserve one byte for current file index
if (fileSize % MAX_PACKET_SIZE) // Add an extra transmission if needed
  numPackets++;

This comment is also not very clear: // Reserve one byte for current file index

Same here:

uint16_t fileIndex = i * MAX_PACKET_SIZE; // Determine the current file index
uint8_t dataLen = MAX_PACKET_SIZE - 2;

if ((fileIndex + (MAX_PACKET_SIZE - 2)) > fileSize) // Determine data length for the last packet if file length is not an exact multiple of MAX_PACKET_SIZE-2
  dataLen = fileSize - fileIndex;

What does -2 mean?

@mickeyvanolst
Copy link

@yursky91 did you end up figuring out how to get this to work?

@PowerBroker2
Copy link
Owner

The code itself should be more or less ok as is, but there is a typo in the comment - I reserve "two" bytes for the current file index, not just one. That's where the -2 comes from

@PowerBroker2 PowerBroker2 self-assigned this Apr 15, 2022
@PowerBroker2 PowerBroker2 added the question Further information is requested label Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants