-
Notifications
You must be signed in to change notification settings - Fork 617
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
mavlink_helpers: send one mavlink packet per uart write #353
Conversation
On Mon, 9 Sep 2019, Matthias Grob wrote:
The actual change is readability and how the function _mav_finalize_message_chan_send operates.
Before: It independently handled all the message parts magic number, header, payload, crc, signature independently and also sent them independently each
with a system call to the hardware. This saved one payload size of stack because nothing had to be copied but had the disadvantage of 3-4 system calls to
the UART and possibly even fragmentation of messages in the various applications the different users come up with like using the same UART for other
protocols at the same time or forwarding the bytes over UDP without reparsing.
New: That's why I suggest to fill up one buffer per message and sending it all at once. I made an effort to make the implementation as readable, efficient
and compatible as possible. I'm aware that there are other functions in the same helper which are partly duplicate and would also need adjustment. The
calculation of the signature can still be simplified a lot since distinguishing the message parts is not necessary.
Thanks for any feedback.
Shouldn't callers who want to deal with a message be calling
mavlink_finalize_message_chan instead?
The code's essentially duplicated between the two functions, with _send
existing to try to minimise resources required.
|
@peterbarker Thanks for the clarification. I'm guessing that my confusion then comes from all the convenience functions using pymavlink/generator/mavgen_c.py Lines 325 to 373 in 8481afb
|
On Mon, 9 Sep 2019, Matthias Grob wrote:
@peterbarker Thanks for the clarification. I'm guessing that my confusion then comes from all the convenience functions using
_mav_finalize_message_chan_send https://github.com/ArduPilot/pymavlink/blob/8481afb968c384fb3f260ea5fe6e0b2e0f0b1c41/generator/mavgen_c.py#L325-L373 So
it's either convenience or one UART access per message?
Yep.
This isn't always running on something with 100kB of free memory - making
that assumption in all of those convenience functions would make it...
less convenient for some users.
|
@peterbarker it would be a maximum of 256 extra bytes, wouldn't it? I know we operate in resource constrained environments, but this is potentially a pretty serious issue on the receiving side, since it is generally a non-preemptive OS that could now require multiple time slices to handle a single message instead of 1. Something like a Raspberry Pi Zero would notice the difference, and depending on implementation, across a network each There's also a slightly different approach: add another helper to get the prefix and suffix length on the message, then the caller can allocate the extra space and position their data correctly in the It would end up being an extra ~2 lines of code on the caller side, wouldn't have any extra memory requirements, and we still get the benefits of just doing a single This would need to be another function that gets added though, so we don't break the API. |
Closing this since it appears to be not the expected way to solve the still unsolved problem. For anyone following the discussion I made an issue here: PX4/PX4-Autopilot#12957 |
Most of the diff just consists of spacings because there were trailing spaces, mixed indentation, ...
The actual change is readability and how the function
_mav_finalize_message_chan_send
operates.Before: It independently handled all the message parts magic number (size +1 everywhere), header, payload, crc, signature independently and also sent them independently each with a system call to the hardware. This saved one payload size of stack during the function call because the payload did need space in the buffer but had the disadvantage of 3-4 system calls to the UART and possibly even fragmentation of messages in the various applications the different users come up with like using the same UART for other protocols at the same time or forwarding the bytes over UDP without reparsing.
New: That's why I suggest to fill up one buffer per message and sending it all at once. I made an effort to make the implementation as readable, efficient and compatible as possible. I'm aware that there are other functions in the same helper which are partly duplicate and would also need adjustment. The calculation of the signature can still be simplified a lot since distinguishing the message parts is not necessary.
Thanks for any feedback.
JFYI @LorenzMeier