Skip to content
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

AP_DroneCAN: fix and clean up DNA server #27543

Merged
merged 9 commits into from
Jul 29, 2024

Conversation

tpwrules
Copy link
Contributor

@tpwrules tpwrules commented Jul 13, 2024

Please see commit messages for details.

Fixes the following issues:

  • Correctly annotates and validates the node ID parameter set by the user
  • Fix various cases where invalid node IDs could be used or stored
  • Fixes 1/256 chance where a node's unique ID could not be registered
  • Cleans up the code

Does not yet address the elephant in the room of multiple servers using the same storage. That will come next; this all makes that easier.

Tested on SITL and a Cube Orange on the bench using various configurations of AP_Periph nodes. Tested that the DNA database is preserved and that the DroneCAN GUI tool still works properly as well.

tpwrules added 3 commits July 13, 2024 17:43
Ensures the occupation mask doesn't get populated with junk if the magic
is not valid.
The StorageManager read_block/write_block methods only return failure if
an out of bounds access is performed. Assert statically that this does
not happen.

Also remove the now-impossible failed to add node state.
libraries/AP_DroneCAN/AP_DroneCAN.cpp Outdated Show resolved Hide resolved
libraries/AP_DroneCAN/AP_DroneCAN_DNA_Server.cpp Outdated Show resolved Hide resolved
tpwrules added 6 commits July 15, 2024 20:40
Node IDs >= 128 don't exist, and IDs 126 and 127 are "reserved for
network maintenance tools" according to the spec.
Slightly reduces flash usage and probably is clearer.
Replaces the check for a CRC of 0 with a check that the hwid is 0.
Substantially reduces 1/256 chance that a particular node ID couldn't be
stored.
Put documentation with each bitmask and use the object directly. Node ID
range checks can be removed as the bitmask itself checks and we don't
expect to trip them.

Substantially cleans up the code.
@tpwrules tpwrules force-pushed the pr/dna-server-fixup branch from 426be3f to fc3342b Compare July 16, 2024 01:59
@tpwrules tpwrules requested a review from tridge July 16, 2024 02:00
@tpwrules
Copy link
Contributor Author

tpwrules commented Jul 16, 2024

Performed the following tests with a Cube Orange and 3x MatekL431 node boards:

  • Set up flight controller with 4.5.4 and default parameters
  • Plugged in each node individually to assign IDs and program firmware with MatekL431-Periph 1.7.0. 125 has nothing plugged in, 124 and 123 have UART GPSes
  • Rebooted and plugged in each node individually in ID order to make sure the IDs are preserved
  • Set GPS_CAN_NODEID1 to 123 and GPS_CAN_NODEID2 to 124, and both GPS types to DroneCAN
  • Verified that disabling a particular GPS caused the expected GPS to fail in MAVProxy
  • Upgraded the autopilot to this branch
  • Rebooted and plugged in each node individually in ID order to make sure the IDs are preserved
  • Plugged in each GPS individually and verified that the expected GPS worked properly in MAVProxy
  • Plugged in both simultaneously and verified that disabling a particular GPS caused the expected GPS to fail in MAVProxy

So I am confident that GPSes will continue to work and their IDs won't change.

Copy link
Contributor

@tridge tridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bugobliterator has offered to review this PR (Sid is the original author of the code)

uint8_t crc = crc_crc8(node_data.hwid_hash, sizeof(node_data.hwid_hash));
if (crc == node_data.crc && node_data.crc != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to backport just this small fix (in minimal form) for 4.5.x

@tridge tridge removed the DevCallEU label Jul 17, 2024
Copy link
Member

@bugobliterator bugobliterator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reasoning behind removing the checks if storage operations were successful?

@bugobliterator
Copy link
Member

bugobliterator commented Jul 28, 2024

What is the reasoning behind removing the checks if storage operations were successful?

Actually, nevermind. Had a look through the StorageManager, we write to files on separate thread, and don't return error on io failures. So certainly logical to remove the runtime checks.

@bugobliterator bugobliterator self-requested a review July 28, 2024 05:29
@tridge tridge merged commit 60a9f17 into ArduPilot:master Jul 29, 2024
93 checks passed
@tpwrules tpwrules deleted the pr/dna-server-fixup branch July 29, 2024 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants