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

Add hex support for msg constants #559

Merged
merged 1 commit into from
Feb 9, 2021
Merged

Conversation

dawonn
Copy link
Contributor

@dawonn dawonn commented Dec 22, 2020

fixes #558

@clalancette
Copy link
Contributor

clalancette commented Dec 22, 2020

@dawonn I think the idea makes sense, but I would like to:

  1. Get input from the rest of the @ros2/team
  2. Figure out whether this was allowed in ROS 1 (and if not, why not)
  3. Figure out whether there is a specification for the ROS message types, and if so, update it
  4. Have tests for this functionality

@dawonn
Copy link
Contributor Author

dawonn commented Dec 22, 2020

Sounds good, I'll work on the tests in the next day or two.

FWIW: This feature would really help with hardware driver interfaces that I'm developing so that the values match across the device API and User Manuals.

@sloretz
Copy link
Contributor

sloretz commented Dec 22, 2020

  1. Figure out whether there is a specification for the ROS message types, and if so, update it

http://design.ros2.org/articles/legacy_interface_definition.html

Copy link
Member

@jacobperron jacobperron left a comment

Choose a reason for hiding this comment

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

Seems okay to me.

rosidl_adapter/rosidl_adapter/parser.py Outdated Show resolved Hide resolved
@jacobperron
Copy link
Member

Technically, this change also adds support for base-2 and base-8 constants too, e.g. 0b01 and 0o01.

@clalancette
Copy link
Contributor

  1. Figure out whether there is a specification for the ROS message types, and if so, update it

http://design.ros2.org/articles/legacy_interface_definition.html

Great, thanks @sloretz . @dawonn So I think the first step here is to update https://github.com/ros2/design/blob/gh-pages/articles/116_legacy_interface_definition.md to add hex, binary, and octal into the "constants" section. Once we have that, then we can go ahead and get the actual code change in.

Signed-off-by: Dereck Wonnacott <dereck@gmail.com>
@dawonn
Copy link
Contributor Author

dawonn commented Dec 26, 2020

  1. Update 116_legacy_interface_definition.md design#308
  2. Tests added for bin, oct, & hex.

@gavanderhoorn
Copy link

gavanderhoorn commented Dec 26, 2020

@jacobperron wrote:

Technically, this change also adds support for base-2 and base-8 constants too, e.g. 0b01 and 0o01.

Wouldn't the grammar need to be updated as well?

decimal_literal: DIGIT
| "1".."9" DIGIT+
octal_literal: "0" "0".."7"+
hexadecimal_literal: "0x"i HEXDIGIT+

The IDL spec also doesn't appear to allow for any other bases than 8, 10 and 16 (version 4.2 anyway, section 7.2.6.1).

@sloretz
Copy link
Contributor

sloretz commented Dec 28, 2020

Wouldn't the grammar need to be updated as well?

IIUC this is adding a feature to the legacy ROS 1 style msg/srv/action format, not the IDL parser. The grammar for IDL parsing should be unchanged by this PR.

@jacobperron
Copy link
Member

IIUC this is adding a feature to the legacy ROS 1 style msg/srv/action format, not the IDL parser. The grammar for IDL parsing should be unchanged by this PR.

That sounds right to me.

To be sure, it might be good to extend our test interfaces files to exercise this new feature (e.g. add new fields to Constants.msg). Depending which message definitions are changed, it might also involve updating the test fixtures here and here.

@gavanderhoorn
Copy link

Wouldn't that make it possible to create .msg (etc) files which would be problematic when considering their "IDL use"? Or is this something where ROS does not need to follow the IDL spec?

@sloretz
Copy link
Contributor

sloretz commented Dec 29, 2020

Wouldn't that make it possible to create .msg (etc) files which would be problematic when considering their "IDL use"? Or is this something where ROS does not need to follow the IDL spec?

I think using int here in rosidl_adapter means the constants written to the OMG IDL file would always be base 10 regardless of the base used in the .msg file.

@jacobperron
Copy link
Member

jacobperron commented Dec 29, 2020

I think using int here in rosidl_adapter means the constants written to the OMG IDL file would always be base 10 regardless of the base used in the .msg file.

This is what I thought too. As I suggested, modifying our current test files would help confirm.

@clalancette clalancette added the more-information-needed Further information is required label Jan 14, 2021
Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

This looks like it is backwards compatible, and faithfully implements ros2/design#308 . I'm going to run full CI on it just to make sure nothing breaks.

@clalancette
Copy link
Contributor

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@clalancette clalancette removed the more-information-needed Further information is required label Feb 8, 2021
@clalancette
Copy link
Contributor

The failures on macOS and Windows are well-known, so not caused by this PR. Going ahead and merging, thanks @dawonn

@clalancette clalancette merged commit 279d129 into ros2:master Feb 9, 2021
dawonn added a commit to dawonn/rosidl that referenced this pull request Feb 9, 2021
Signed-off-by: Dereck Wonnacott <dereck@gmail.com>
clalancette pushed a commit that referenced this pull request Feb 26, 2021
* Treat \t as whitespace (#557)

Signed-off-by: Dereck Wonnacott <dereck@gmail.com>

* Support hex constants in msg files (#559)

Signed-off-by: Dereck Wonnacott <dereck@gmail.com>
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.

support msg constants in hex
5 participants