-
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
Open
bugobliterator
wants to merge
4
commits into
ArduPilot:master
Choose a base branch
from
bugobliterator:pr-bridge-option-mcast
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5,132
−5,132
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
17e5428
AP_HAL: change IsMavCAN to IsForwardedFrame
bugobliterator be63a37
AP_CANManager: use updated frame callback types
bugobliterator c6702e8
AP_Networking: make can multicast an endpoint by default
bugobliterator 37b2924
bootloaders: update bootloaders using networking
bugobliterator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,7 +117,7 @@ void AP_Networking_CAN::mcast_server(void) | |
} | ||
|
||
if (!cbus->register_frame_callback( | ||
FUNCTOR_BIND_MEMBER(&AP_Networking_CAN::can_frame_callback, void, uint8_t, const AP_HAL::CANFrame &), | ||
FUNCTOR_BIND_MEMBER(&AP_Networking_CAN::can_frame_callback, void, uint8_t, const AP_HAL::CANFrame &, AP_HAL::CANIface::CanIOFlags), | ||
callback_id)) { | ||
GCS_SEND_TEXT(MAV_SEVERITY_ERROR, "CAN_MCAST[%u]: failed to register", unsigned(bus)); | ||
goto de_allocate; | ||
|
@@ -180,18 +180,29 @@ void AP_Networking_CAN::mcast_server(void) | |
*/ | ||
AP_HAL::CANFrame frame; | ||
const uint16_t timeout_us = 2000; | ||
#if AP_NETWORKING_CAN_MCAST_BRIDGING_ENABLED | ||
const bool bridged = AP::network().is_can_mcast_ep_bridged(bus); | ||
#else | ||
const bool bridged = false; | ||
#endif | ||
|
||
while (frame_buffers[bus]->peek(frame)) { | ||
auto *cbus = get_caniface(bus); | ||
if (cbus == nullptr) { | ||
break; | ||
} | ||
auto retcode = cbus->send(frame, | ||
AP_HAL::micros64() + timeout_us, | ||
AP_HAL::CANIface::IsMAVCAN); | ||
if (retcode == 0) { | ||
break; | ||
if (bridged) { | ||
auto retcode = cbus->send(frame, AP_HAL::micros64() + timeout_us, | ||
AP_HAL::CANIface::IsForwardedFrame); | ||
if (retcode == 0) { | ||
break; | ||
} | ||
} else { | ||
// only call the AP_HAL::CANIface send if we are not in bridged mode | ||
cbus->AP_HAL::CANIface::send(frame, AP_HAL::micros64() + timeout_us, | ||
AP_HAL::CANIface::IsForwardedFrame); | ||
} | ||
|
||
// we either sent it or there was an error, either way we discard the frame | ||
frame_buffers[bus]->pop(); | ||
} | ||
|
@@ -203,12 +214,27 @@ void AP_Networking_CAN::mcast_server(void) | |
handler for CAN frames from the registered callback, sending frames | ||
out as multicast UDP | ||
*/ | ||
void AP_Networking_CAN::can_frame_callback(uint8_t bus, const AP_HAL::CANFrame &frame) | ||
void AP_Networking_CAN::can_frame_callback(uint8_t bus, const AP_HAL::CANFrame &frame, AP_HAL::CANIface::CanIOFlags flags) | ||
{ | ||
if (bus >= HAL_NUM_CAN_IFACES || mcast_sockets[bus] == nullptr) { | ||
return; | ||
} | ||
|
||
#if AP_NETWORKING_CAN_MCAST_BRIDGING_ENABLED | ||
// check if bridged mode is enabled | ||
const bool bridged = AP::network().is_can_mcast_ep_bridged(bus); | ||
#else | ||
// never bridge in bootloader, as we can cause loops if multiple | ||
// bootloaders with mcast are running on the same network and CAN Bus | ||
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 commentThe 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 |
||
// we don't forward frames that we received from the multicast | ||
// server if not in bridged mode | ||
return; | ||
} | ||
|
||
struct mcast_pkt pkt {}; | ||
pkt.magic = MCAST_MAGIC; | ||
pkt.flags = 0; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
to this:
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.