Skip to content

Commit

Permalink
Merge pull request #28 from mROS-base/v0.3.2
Browse files Browse the repository at this point in the history
clear `cntPub` aproprieately
  • Loading branch information
takasehideki authored Mar 10, 2022
2 parents 9ebc66c + e0fa104 commit 4f3f7e2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
25 changes: 10 additions & 15 deletions mros2_header_generator/header_generator.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# 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]
msgFile = arg[1]

def toCamelCase(string):
return ''.join(x.capitalize() for x in string.split('_'))
Expand All @@ -19,21 +17,18 @@ def toSnakeCase(string):
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()))
msgs.append(msgDataGenerator(msgFile))

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

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

if not(os.path.isdir("../mros2_msgs")):
os.mkdir("../mros2_msgs")
if not(os.path.isdir("custom_msgs")):
os.mkdir("custom_msgs")
if not(os.path.isdir(msgPkgPath)):
os.mkdir(msgPkgPath)
if not(os.path.isdir(msgPkgPath + "/msg")):
Expand All @@ -47,14 +42,14 @@ def genDepMsgHeader(genMsg):
msgs=[]
msgs.append(msgDataGenerator(genMsg.strip()))
for msg in msgs:
env = Environment(loader=FileSystemLoader(mros2Dir + '/mros2_header_generator'))
env = Environment(loader=FileSystemLoader('../mros2/mros2_header_generator'))
template = env.get_template('header_template.tpl')
datatext = template.render({ "msg": msg })

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

if not(os.path.isdir("../mros2_msgs")):
os.mkdir("../mros2_msgs")
if not(os.path.isdir("custom_msgs")):
os.mkdir("custom_msgs")
if not(os.path.isdir(msgPkgPath)):
os.mkdir(msgPkgPath)
if not(os.path.isdir(msgPkgPath + "/msg")):
Expand Down
4 changes: 3 additions & 1 deletion mros2_header_generator/header_template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,9 @@ public:
}

uint32_t getTotalSize(){
return cntPub ;
uint32_t tmpCntPub = cntPub;
cntPub = 0;
return tmpCntPub ;
}

private:
Expand Down
7 changes: 3 additions & 4 deletions mros2_header_generator/templates_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from jinja2 import Environment, FileSystemLoader

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

includeFiles = []
pubMsgTypes = []
Expand Down Expand Up @@ -39,13 +38,13 @@ def main():
includeFiles.append(includeFile)


env = Environment(loader=FileSystemLoader(mros2Dir + '/mros2_header_generator'))
env = Environment(loader=FileSystemLoader('../mros2/mros2_header_generator'))
template = env.get_template('templates.tpl')
datatext = template.render({ "includeFiles":includeFiles, "pubMsgTypes":pubMsgTypes, "subMsgTypes":subMsgTypes })
with open(os.path.join(app+"/templates.hpp"), "wb") as f:
f.write(datatext.encode('utf-8'))

env = Environment(loader=FileSystemLoader(mros2Dir + '/mros2_header_generator'))
env = Environment(loader=FileSystemLoader('../mros2/mros2_header_generator'))
template = env.get_template('header_includer.tpl')
datatext = template.render({ "app": app })
with open(os.path.join("../header_includer/header_includer.hpp"), "wb") as f:
Expand Down

0 comments on commit 4f3f7e2

Please sign in to comment.