Skip to content

Commit a67ee7d

Browse files
authored
Merge pull request #484 from memrecakal/master
Enhance and refactor MessageGeneration to support ROS2 message interface
2 parents a71cb5e + 324c8fb commit a67ee7d

File tree

721 files changed

+2860
-2890
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

721 files changed

+2860
-2890
lines changed

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.cs text eol=crlf
2+
*.csproj text eol=crlf
3+
Libraries/RosBridgeClient/MessageTypes/** text eol=lf
4+
com.siemens.ros-sharp/Runtime/Libraries/RosBridgeClient/MessageTypes/** text eol=lf

Libraries/MessageGeneration/ActionAutoGen.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ namespace RosSharp.RosBridgeClient.MessageGeneration
3030
public class ActionAutoGen
3131
{
3232
public static bool isRos2 = true;
33-
private static readonly string[] types = {"Goal", "Result", "Feedback"};
33+
private static readonly string[] types = { "Goal", "Result", "Feedback" };
3434

35-
public static List<string> GenerateSingleAction(string inPath, string outPath, string rosPackageName = "", bool verbose = false) {
35+
public static List<string> GenerateSingleAction(string inPath, string outPath, string rosPackageName = "", bool verbose = false)
36+
{
3637
// If no ROS package name is provided, extract from path
3738
if (rosPackageName.Equals(""))
3839
{
@@ -62,7 +63,8 @@ public static List<string> GenerateSingleAction(string inPath, string outPath, s
6263

6364
ActionWrapper actionWrapper = new ActionWrapper(inPath, rosPackageName, outPath);
6465

65-
for (int i = 0; i < listsOfTokens.Count; i++) {
66+
for (int i = 0; i < listsOfTokens.Count; i++)
67+
{
6668
List<MessageToken> tokens = listsOfTokens[i];
6769

6870
// Action is made up of goal, result, feedback
@@ -71,7 +73,7 @@ public static List<string> GenerateSingleAction(string inPath, string outPath, s
7173
// Parse and generate goal, result, feedback messages
7274
MessageParser parser = new MessageParser(tokens, outPath, rosPackageName, "action", MsgAutoGenUtilities.builtInTypesMapping, MsgAutoGenUtilities.builtInTypesDefaultInitialValues, className, className, isRos2: isRos2);
7375
parser.Parse();
74-
warnings.AddRange(parser.GetWarnings());
76+
warnings.AddRange(parser.warnings);
7577

7678
// Generate action section wrapper messages
7779
actionWrapper.WrapActionSections(types[i]);
@@ -140,7 +142,8 @@ public static List<string> GenerateDirectoryActions(string inPath, string outPat
140142
}
141143
}
142144

143-
public class ActionWrapper {
145+
public class ActionWrapper
146+
{
144147

145148
private const string ONE_TAB = " ";
146149
private const string TWO_TABS = " ";
@@ -154,7 +157,8 @@ public class ActionWrapper {
154157

155158
private Dictionary<string, string> symbolTable;
156159

157-
public ActionWrapper(string inPath, string rosPackageName, string outPath) {
160+
public ActionWrapper(string inPath, string rosPackageName, string outPath)
161+
{
158162
this.inPath = inPath;
159163
this.inFileName = Path.GetFileNameWithoutExtension(inPath);
160164
this.rosPackageName = rosPackageName;
@@ -210,7 +214,7 @@ private string GenerateParameterizedConstructor(string className, string msgType
210214

211215
if (ActionAutoGen.isRos2)
212216
{
213-
if (msgType.Equals("Goal"))
217+
if (msgType.Equals("Goal"))
214218
{
215219
paramsIn += "Header header, GoalInfo goalInfo, ";
216220
paramsOut += "header, goalInfo";
@@ -334,7 +338,7 @@ public void WrapActionSections(string type)
334338

335339
// Write class declaration
336340
writer.Write(
337-
ONE_TAB + "public class " + wrapperName + " : Action" + type + "<" + inFileName + type + ">\n" +
341+
ONE_TAB + "public class " + wrapperName + " : Action" + type + "<" + inFileName + type + ">\n" +
338342
ONE_TAB + "{\n"
339343
);
340344

@@ -417,15 +421,15 @@ public void WrapAction()
417421
inFileName + "Feedback"
418422
};
419423
writer.Write(
420-
ONE_TAB + "public class " + wrapperName + " : Action<" + string.Join(", ", genericParams) + ">\n" +
424+
ONE_TAB + "public class " + wrapperName + " : Action<" + string.Join(", ", genericParams) + ">\n" +
421425
ONE_TAB + "{\n"
422426
);
423427

424428
// Write ROS package name
425429
if (ActionAutoGen.isRos2)
426430
{
427431
writer.Write(
428-
TWO_TABS + "public const string RosMessageName = \"" + rosPackageName + "/" + "action" + "/"
432+
TWO_TABS + "public const string RosMessageName = \"" + rosPackageName + "/" + "action" + "/"
429433
+ wrapperName + "\";\n");
430434
}
431435
else

Libraries/MessageGeneration/MessageAutoGen.cs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public class MessageAutoGen
2929
public static List<string> GenerateSingleMessage(string inPath, string outPath, string rosPackageName = "", bool verbose = false)
3030
{
3131
// If no ROS package name is provided, extract from path
32-
if (rosPackageName.Equals("")) {
32+
if (rosPackageName.Equals(""))
33+
{
3334
string[] hierarchy = inPath.Split(new char[] { '/', '\\' });
3435
rosPackageName = hierarchy[hierarchy.Length - 3];
3536
}
@@ -40,7 +41,8 @@ public static List<string> GenerateSingleMessage(string inPath, string outPath,
4041

4142
if (!(rosPackageName.Equals("std_msgs") && (inFileName.Equals("Time") || inFileName.Equals("Duration"))))
4243
{
43-
if (verbose) {
44+
if (verbose)
45+
{
4446
Console.WriteLine("Parsing: " + inPath);
4547
Console.WriteLine("Output Location: " + outPath);
4648
}
@@ -55,22 +57,26 @@ public static List<string> GenerateSingleMessage(string inPath, string outPath,
5557

5658
MessageParser parser = new MessageParser(listOfTokens[0], outPath, rosPackageName, "msg", MsgAutoGenUtilities.builtInTypesMapping, MsgAutoGenUtilities.builtInTypesDefaultInitialValues, isRos2: isRos2);
5759
parser.Parse();
58-
return parser.GetWarnings();
60+
return parser.warnings;
5961
}
60-
else {
62+
else
63+
{
6164
Console.WriteLine(inFileName + " will not be generated, needs manuel attention.");
6265
return new List<string>();
6366
}
6467
}
6568

66-
public static List<string> GeneratePackageMessages(string inPath, string outPath, string rosPackageName = "", bool verbose = false) {
69+
public static List<string> GeneratePackageMessages(string inPath, string outPath, string rosPackageName = "", bool verbose = false)
70+
{
6771
List<string> warnings = new List<string>();
6872

69-
if (inPath.EndsWith("/") || inPath.EndsWith("\\")) {
70-
inPath = inPath.Remove(inPath.Length-1);
73+
if (inPath.EndsWith("/") || inPath.EndsWith("\\"))
74+
{
75+
inPath = inPath.Remove(inPath.Length - 1);
7176
}
7277

73-
if (rosPackageName.Equals("")) {
78+
if (rosPackageName.Equals(""))
79+
{
7480
rosPackageName = inPath.Split(new char[] { '/', '\\' }).Last();
7581
}
7682

@@ -81,19 +87,22 @@ public static List<string> GeneratePackageMessages(string inPath, string outPath
8187
Console.Error.WriteLine("No message files found!");
8288
return warnings;
8389
}
84-
else {
90+
else
91+
{
8592
if (verbose)
8693
{
8794
Console.WriteLine("Found " + files.Length + " message files.");
8895
}
89-
foreach (string file in files) {
96+
foreach (string file in files)
97+
{
9098
warnings.AddRange(GenerateSingleMessage(file, outPath, rosPackageName, verbose));
9199
}
92100
}
93101
return warnings;
94102
}
95103

96-
public static List<string> GenerateDirectoryMessages(string inPath, string outPath, bool verbose = false) {
104+
public static List<string> GenerateDirectoryMessages(string inPath, string outPath, bool verbose = false)
105+
{
97106
List<string> warnings = new List<string>();
98107

99108
if (inPath.EndsWith("/") || inPath.EndsWith("\\"))
@@ -108,12 +117,14 @@ public static List<string> GenerateDirectoryMessages(string inPath, string outPa
108117
Console.Error.WriteLine("No message files found!");
109118
return warnings;
110119
}
111-
else {
120+
else
121+
{
112122
if (verbose)
113123
{
114124
Console.WriteLine("Found " + files.Length + " message files.");
115125
}
116-
foreach (string file in files) {
126+
foreach (string file in files)
127+
{
117128
warnings.AddRange(GenerateSingleMessage(file, outPath, verbose: verbose));
118129
}
119130
}

Libraries/MessageGeneration/MessageGeneration.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
<Company>Siemens AG</Company>
1313
<Product>ROS#</Product>
1414
<Copyright>Copyright © 2025</Copyright>
15-
<AssemblyVersion>2.1.1.0</AssemblyVersion>
16-
<FileVersion>2.1.1.0</FileVersion>
17-
<Version>2.1.1</Version>
15+
<AssemblyVersion>2.2.0.0</AssemblyVersion>
16+
<FileVersion>2.2.0.0</FileVersion>
17+
<Version>2.2.0</Version>
1818
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
1919
<PackageId>Siemens.RosSharp.MessageGeneration</PackageId>
2020
<Title>MessageGeneration</Title>

0 commit comments

Comments
 (0)