SerialTransfer icon indicating copy to clipboard operation
SerialTransfer copied to clipboard

Is there an error in the file transfer example?

Open yursky91 opened this issue 3 years ago • 2 comments
trafficstars

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?

yursky91 avatar Mar 27 '22 16:03 yursky91

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

mickeyvanolst avatar Apr 14 '22 20:04 mickeyvanolst

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 avatar Apr 15 '22 01:04 PowerBroker2