Skip to content

Commit

Permalink
Merge pull request #25 from mROS-base/v0.2.4
Browse files Browse the repository at this point in the history
V0.2.4
  • Loading branch information
takasehideki authored Feb 20, 2022
2 parents f5c1a04 + af35a19 commit af19fe8
Show file tree
Hide file tree
Showing 27 changed files with 906 additions and 130 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ target_sources(mros2
embeddedRTPS/thirdparty/Micro-CDR/src/c/types/string.c
embeddedRTPS/thirdparty/Micro-CDR/src/c/types/sequence.c
embeddedRTPS/thirdparty/Micro-CDR/src/c/types/array.c
)
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ Please let us know if you have a request for a support of board/kernel, or if yo
## License

The source code of this repository itself is published under [Apache License 2.0](https://github.com/mROS-base/mros2/blob/main/LICENSE).
Please note that this repository contains [embeddedRTPS and its third party libraries](https://github.com/mROS-base/embeddedRTPS#third-party-libraries) as the submodule, and also check their Licenses.
Please note that this repository contains [embeddedRTPS and its third party libraries](https://github.com/mROS-base/embeddedRTPS#third-party-libraries) as the submodule, and also check their Licenses.
2 changes: 1 addition & 1 deletion include/mros2.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ static const char* value();
};
} /* namespace message_traits */

#endif /* MROS2_MROS2_H */
#endif /* MROS2_MROS2_H */
68 changes: 68 additions & 0 deletions mros2_header_generator/header_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# generate message type header file for mROS2

import os
import json
import sys
import re
from jinja2 import Environment, FileSystemLoader

arg = sys.argv
mros2Dir = arg[1]
msgDir = arg[2]

def toCamelCase(string):
return ''.join(x.capitalize() for x in string.split('_'))

def toSnakeCase(string):
return re.sub("(.[A-Z])",lambda x:x.group(1)[0] + "_" +x.group(1)[1],string).lower()

def main():
from msg_data_generator import msgDataGenerator
# load msg settings & prepare information for .tpl file
with open(msgDir + "/" + "msg_settings.json", 'r') as f:
jsonData = json.load(f)
for genMsg in jsonData['pubsubMsgs']:
msgs.append(msgDataGenerator(genMsg.strip()))

# generate header file for mros2
for msg in msgs:
env = Environment(loader=FileSystemLoader(mros2Dir + '/mros2_header_generator'))
template = env.get_template('header_template.tpl')
datatext = template.render({ "msg": msg })

msgPkgPath = "../mros2_msgs" + "/" + msg['pkg']

if not(os.path.isdir("../mros2_msgs")):
os.mkdir("../mros2_msgs")
if not(os.path.isdir(msgPkgPath)):
os.mkdir(msgPkgPath)
if not(os.path.isdir(msgPkgPath + "/msg")):
os.mkdir(msgPkgPath + "/msg")

with open(os.path.join(msgPkgPath, "msg", toSnakeCase(msg['name']) + ".hpp"), "wb") as f:
f.write(datatext.encode('utf-8'))

def genDepMsgHeader(genMsg):
from msg_data_generator import msgDataGenerator
msgs=[]
msgs.append(msgDataGenerator(genMsg.strip()))
for msg in msgs:
env = Environment(loader=FileSystemLoader(mros2Dir + '/mros2_header_generator'))
template = env.get_template('header_template.tpl')
datatext = template.render({ "msg": msg })

msgPkgPath = "../mros2_msgs" + "/" + msg['pkg']

if not(os.path.isdir("../mros2_msgs")):
os.mkdir("../mros2_msgs")
if not(os.path.isdir(msgPkgPath)):
os.mkdir(msgPkgPath)
if not(os.path.isdir(msgPkgPath + "/msg")):
os.mkdir(msgPkgPath + "/msg")

with open(os.path.join(msgPkgPath, "msg", toSnakeCase(msg['name']) + ".hpp"), "wb") as f:
f.write(datatext.encode('utf-8'))

if __name__ == "__main__":
msgs = []
main()
1 change: 1 addition & 0 deletions mros2_header_generator/header_includer.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "../workspace/{{app}}/templates.hpp"
Loading

0 comments on commit af19fe8

Please sign in to comment.