Skip to content

add sanity check for command-int conversion #28866

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

peterbarker
Copy link
Contributor

Replaces #28790

This provides a useful return value to the GCS that they've passed in invalid lat/lng in their command-long positions. Which they shouldn't be using anyway.

Board,plane
CubeOrange,0
Pixhawk1-1M,40

@peterbarker peterbarker force-pushed the pr/convert-better-errors branch from e850849 to 46bd498 Compare December 15, 2024 02:23
out.x = convert_COMMAND_LONG_loc_param(in.param5, stores_location);
out.y = convert_COMMAND_LONG_loc_param(in.param6, stores_location);

// we can't convert NaN/INF to an integer:
Copy link
Member

Choose a reason for hiding this comment

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

We are supposed to deal with NaNs, it might be fine if the command is not using those params. We could convert from NaN which is no value for float Int32 max which is no value for int32 according to the spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oof. Hmmm. Will think about this more in the morning.

Problem is that if we just squash them to zero them we may end up triggering the sanitise-using-a-default-location code....

Copy link
Member

Choose a reason for hiding this comment

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

The spec calls for INT32 max for invalid. (https://mavlink.io/en/messages/common.html#COMMAND_INT), so NaN should be converted to that. Then your new range check will bounce if it is a location.

Copy link
Contributor Author

@peterbarker peterbarker Dec 15, 2024

Choose a reason for hiding this comment

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

OK, squashed to INT32_MAX as you suggest - seems the best way forward here.

Note that this will be a behavioural change - previously we would have treated these as 0.

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.

need to see if the change of behaviour is safe

out.x = param5 * 1e7;
out.y = param6 * 1e7;
} else {
out.x = param5;
Copy link
Contributor

Choose a reason for hiding this comment

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

we need to see if there may be any commands that relied on the previous zero, and now will get INT32_MAX, motor test is a possible issue

Copy link
Member

@IamPete1 IamPete1 left a comment

Choose a reason for hiding this comment

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

Code changes look good now. We do generally need to be better handling incoming commands with invalid values.

@peterbarker peterbarker force-pushed the pr/convert-better-errors branch from 7abba85 to 11f6f2b Compare March 3, 2025 22:19
@peterbarker peterbarker force-pushed the pr/convert-better-errors branch from 11f6f2b to 649265e Compare May 13, 2025 23:27
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.

3 participants