Currently, there is a single function called voyager_bootloader_process_receieved_packet()
that may be called asynchronously to let the bootloader know that the next packet can be processed.
NOTE: There may be a bug in this function as voyager_data.pending_data
is set to true
before the length and message buffer are valid - this should probably be done AFTER they are valid :-)
If I am receiving data from a physical UART (not a CDC UART) then I don't really know when a full "packet" has been received. Yes, I could distinguish a DFU start packet from a data packet, or I could put a character receive timeout on the UART handler, but that requires that my stream handler knows about how Voyager handles data, and we don't want that.
If I call voyager_bootloader_process_receieved_packet()
before a full packet is received, the previous contents of message buffer are overwritten instead of appended and things just break.
With an API called voyager_bootloader_check_received_packet()
we can have the Voyager bootloader do some rudimentary checking of the message type, length, and tell us if this buffer is ready to process. Return values are:
-1 - buffer has some kind of error (like unknown packet type), you figure out how you want to handle the error
0 - packet is not ready to process yet, but no major errors either
1-n - packet of length (n) is ready to process
When the n bytes are ready to be processed, call voyager_bootloader_process_receieved_packet()
as before, and then figure out how to handle any additional characters in your UART buffer ...
Does this make sense?