Skip to content

Commit 3fb5e5f

Browse files
authored
Add wchar support (#349)
* Add wchar support and .idl example * Undo automatic IDE formatting noise * Added back unused imports to see if this fixes the build * More attempts to fix the weird build failure * Removed the linter tests for auto-generated message source files in `rclrs_example_msgs`. Re-applied some changes removed when root causing. --------- Co-authored-by: Sam Privett <sam@privett.dev>
1 parent 812b91a commit 3fb5e5f

File tree

4 files changed

+100
-7
lines changed

4 files changed

+100
-7
lines changed

examples/message_demo/src/message_demo.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ fn check_default_values() {
6868
);
6969
}
7070

71+
fn check_default_idl_values() {
72+
let idiomatic_msg = rclrs_example_msgs::msg::MyMessage::default();
73+
let rmw_msg = rclrs_example_msgs::msg::rmw::MyMessage::default();
74+
75+
assert_eq!(idiomatic_msg.wchar_value, 0u16);
76+
assert_eq!(rmw_msg.wchar_value, 0u16);
77+
}
78+
7179
fn demonstrate_printing() {
7280
let default_msg = rclrs_example_msgs::msg::VariousTypes::default();
7381
println!("================== Compact debug representation ==================");
@@ -170,6 +178,7 @@ fn demonstrate_pubsub() -> Result<(), Error> {
170178

171179
fn main() -> Result<(), Error> {
172180
check_default_values();
181+
check_default_idl_values();
173182
demonstrate_printing();
174183
demonstrate_serde()?;
175184
demonstrate_sequences();

rclrs_example_msgs/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ find_package(rosidl_default_generators REQUIRED)
1616
set(msg_files
1717
"msg/NestedType.msg"
1818
"msg/VariousTypes.msg"
19+
"msg/MyMessage.idl"
1920
)
21+
2022
rosidl_generate_interfaces(${PROJECT_NAME}
2123
${msg_files}
22-
ADD_LINTER_TESTS
2324
)
2425

2526
ament_export_dependencies(rosidl_default_runtime)

rclrs_example_msgs/msg/MyMessage.idl

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Taken and slightly adapted from
2+
// https://github.com/ros2/rosidl/blob/iron/rosidl_parser/test/msg/MyMessage.idl
3+
4+
module rclrs_example_msgs {
5+
module msg {
6+
module MyMessage_Constants {
7+
const short SHORT_CONSTANT = -23;
8+
const unsigned long UNSIGNED_LONG_CONSTANT = 42;
9+
const float FLOAT_CONSTANT = 1.25;
10+
const boolean BOOLEAN_CONSTANT = TRUE;
11+
const string STRING_CONSTANT = "string_value";
12+
const wstring WSTRING_CONSTANT = "wstring_value_\u2122";
13+
const string EMPTY_STRING_CONSTANT = "";
14+
};
15+
16+
@verbatim ( language="comment", text="Documentation of MyMessage." "Adjacent string literal." )
17+
@transfer_mode(SHMEM_REF)
18+
struct MyMessage {
19+
short short_value, short_value2;
20+
@default ( value=123 )
21+
unsigned short unsigned_short_value;
22+
@key
23+
@range ( min=-10, max=10 )
24+
long long_value;
25+
@verbatim (language="comment", text="")
26+
unsigned long unsigned_long_value;
27+
long long long_long_value;
28+
unsigned long long unsigned_long_long_value;
29+
float float_value;
30+
double double_value;
31+
// long double long_double_value;
32+
char char_value;
33+
wchar wchar_value;
34+
boolean boolean_value;
35+
octet octet_value;
36+
int8 int8_value;
37+
uint8 uint8_value;
38+
int16 int16_value;
39+
uint16 uint16_value;
40+
int32 int32_value;
41+
uint32 uint32_value;
42+
int64 int64_value;
43+
uint64 uint64_value;
44+
string string_value;
45+
string<5> bounded_string_value;
46+
wstring wstring_value;
47+
wstring<23> bounded_wstring_value;
48+
// wstring<UNSIGNED_LONG_CONSTANT> constant_bounded_wstring_value;
49+
sequence<short> unbounded_short_values;
50+
sequence<short, 5> bounded_short_values;
51+
sequence<string<3>> unbounded_values_of_bounded_strings;
52+
sequence<string<3>, 4> bounded_values_of_bounded_strings;
53+
short array_short_values[23];
54+
55+
// Tests of the floating point parser (7.2.6.4)
56+
@default ( value=1.9e10 )
57+
float int_and_frac_with_positive_scientific;
58+
@default ( value=1.9e+10 )
59+
float int_and_frac_with_explicit_positive_scientific;
60+
@default ( value=1.1e-10)
61+
float int_and_frac_with_negative_scientific;
62+
@default ( value=0.00009 )
63+
float int_and_frac;
64+
@default ( value = 1. )
65+
float int_with_empty_frac;
66+
@default ( value = .1 )
67+
float frac_only;
68+
@default ( value=9e05 )
69+
float int_with_positive_scientific;
70+
@default ( value=9e+05 )
71+
float int_with_explicit_positive_scientific;
72+
@default ( value=9e-05 )
73+
float int_with_negative_scientific;
74+
75+
// Tests of the fixed point parser (7.2.6.5)
76+
@default ( value=8.7d )
77+
float fixed_int_and_frac;
78+
@default ( value=4.d )
79+
float fixed_int_with_dot_only;
80+
@default ( value=.3d )
81+
float fixed_frac_only;
82+
@default ( value=7d )
83+
float fixed_int_only;
84+
};
85+
};
86+
};

rosidl_generator_rs/rosidl_generator_rs/__init__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import os
1616
import pathlib
17-
import subprocess
1817

1918
from pathlib import Path
2019

@@ -24,12 +23,7 @@
2423
import rosidl_pycommon
2524

2625
from rosidl_parser.definition import AbstractGenericString
27-
from rosidl_parser.definition import AbstractNestedType
28-
from rosidl_parser.definition import AbstractSequence
29-
from rosidl_parser.definition import AbstractString
30-
from rosidl_parser.definition import AbstractWString
3126
from rosidl_parser.definition import Array
32-
from rosidl_parser.definition import BASIC_TYPES
3327
from rosidl_parser.definition import BasicType
3428
from rosidl_parser.definition import BoundedSequence
3529
from rosidl_parser.definition import BoundedString
@@ -219,6 +213,7 @@ def primitive_value_to_rs(type_, value):
219213
if type_.type in [
220214
'byte',
221215
'char',
216+
'wchar',
222217
'int8',
223218
'uint8',
224219
'int16',
@@ -311,6 +306,8 @@ def get_rmw_rs_type(type_):
311306
return 'u8'
312307
elif type_.typename == 'char':
313308
return 'u8'
309+
elif type_.typename == 'wchar':
310+
return 'u16'
314311
elif type_.typename == 'float':
315312
return 'f32'
316313
elif type_.typename == 'double':

0 commit comments

Comments
 (0)