-
Notifications
You must be signed in to change notification settings - Fork 18k
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
Create separate option for bridging mcast and hw can #28913
base: master
Are you sure you want to change the base?
Create separate option for bridging mcast and hw can #28913
Conversation
d377968
to
f9fd251
Compare
f9fd251
to
fe0cd52
Compare
libraries/AP_HAL/CANIface.h
Outdated
struct { | ||
#ifndef HAL_BOOTLOADER_BUILD | ||
HAL_Semaphore sem; | ||
#endif | ||
// allow up to 3 callbacks per interface | ||
FrameCb cb[3]; | ||
bool rx_cb_disable[3]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need these disable flags? if we want to disable, why don't we just call unregister_frame_callback()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tridge the disable is only to remove calling on rx, but we still call the callback on tx from CANIface. Basically we don't forward what we receive from CAN Bus, but we still transmit frames that are to be sent out. That's how we leave the interaction with the device itself functional. Unregistering will remove the call from both tx and rx.
@bugobliterator could this be handled in the callback in the AP_Networking layer? |
I don't think there's a way to do this without changes to CANIface, there's a common callback for both RX and TX. We have to either pass the direction as callback parameter, make it part of each frame or the way I have done which is to have the direction selection per callback. First method will require wider changes, second one costs more memory and third one I think is a happy middle. |
fe0cd52
to
e36c82f
Compare
@@ -64,9 +64,9 @@ int16_t AP_HAL::CANIface::receive(CANFrame& out_frame, uint64_t& out_ts_monotoni | |||
#ifndef HAL_BOOTLOADER_BUILD | |||
WITH_SEMAPHORE(callbacks.sem); | |||
#endif | |||
for (auto &cb : callbacks.cb) { | |||
if (cb != nullptr) { | |||
cb(get_iface_num(), out_frame); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding an bool is_send as an additional field in the callback
maybe change
FUNCTOR_TYPEDEF(FrameCb, void, uint8_t, const AP_HAL::CANFrame &);
to this:
FUNCTOR_TYPEDEF(FrameCb, void, uint8_t, const AP_HAL::CANFrame &, uint8_t flags);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or could be a bool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to using CANIOFlags actually to keep things consistent.
Also changed IsMAVCAN flag to IsForwardedFrame. This flag is then used to check if the frame was forwarded from different physical iface.
e36c82f
to
c3a9d42
Compare
c3a9d42
to
8600482
Compare
also change to IsForwardedFrame from IsMAVCAN
8600482
to
9347507
Compare
also add option to enable multicast with bridging to CAN bus in application and disabled in bootloader
9347507
to
37b2924
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requested changes made
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks much better, thank you!
just the one trivial fix needed then should be merged
const bool bridged = false; | ||
#endif | ||
|
||
if (flags & AP_HAL::CANIface::IsForwardedFrame && !bridged) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need parentheses around the bitmask test, or some compilers will complain
Changes done: