diff --git a/mros2_header_generator/header_generator.py b/mros2_header_generator/header_generator.py index 5ee7f38..88f8d59 100644 --- a/mros2_header_generator/header_generator.py +++ b/mros2_header_generator/header_generator.py @@ -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('_')) @@ -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")): @@ -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")): diff --git a/mros2_header_generator/header_template.tpl b/mros2_header_generator/header_template.tpl index 3f88434..99aa2e1 100644 --- a/mros2_header_generator/header_template.tpl +++ b/mros2_header_generator/header_template.tpl @@ -464,7 +464,9 @@ public: } uint32_t getTotalSize(){ - return cntPub ; + uint32_t tmpCntPub = cntPub; + cntPub = 0; + return tmpCntPub ; } private: diff --git a/mros2_header_generator/templates_generator.py b/mros2_header_generator/templates_generator.py index 517c864..90e9698 100644 --- a/mros2_header_generator/templates_generator.py +++ b/mros2_header_generator/templates_generator.py @@ -4,8 +4,7 @@ from jinja2 import Environment, FileSystemLoader arg = sys.argv -mros2Dir = arg[1] -app = arg[2] +app = arg[1] includeFiles = [] pubMsgTypes = [] @@ -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: