-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export pprz messages into OpenDDS format #69
Open
podhrmic
wants to merge
3
commits into
master
Choose a base branch
from
opendds
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#!/usr/bin/env python | ||
''' | ||
parse a PPRZLink protocol XML file and generate a OpenDDS compatible | ||
IDL file. See http://opendds.org/ for details. | ||
|
||
Copyright (C) 2017 Michal Podhradsky <mpodhradsky@galois.com> | ||
For the Paparazzi UAV and PPRZLINK projects | ||
''' | ||
import re | ||
import sys, os | ||
import gen_messages, pprz_template, pprz_parse | ||
|
||
t = pprz_template.PPRZTemplate() | ||
|
||
def generate_messages_h(directory, name, xml): | ||
print(xml) | ||
'''generate messages header''' | ||
if name == 'stdout': | ||
f = sys.stdout | ||
else: | ||
f = open(os.path.join(directory, name), mode='w') | ||
t.write(f,''' | ||
/* | ||
* | ||
* | ||
* Distributed under the OpenDDS License. | ||
* See: http://www.opendds.org/license.html | ||
*/ | ||
|
||
typedef sequence<unsigned short> unsigned_short_array; // uint8 ot uint16[] | ||
typedef sequence<short> short_array; // int8 or int16[] | ||
typedef sequence<unsigned long> unsigned_long_array; // uint32[] | ||
typedef sequence<long> long_array; // int32[] | ||
typedef sequence<float> float_array; // float[] | ||
typedef sequence<double> double_array; // double[] | ||
|
||
module ${class_name} { | ||
${{message: | ||
#pragma DCPS_DATA_TYPE "${class_name}::${msg_name}" | ||
#pragma DCPS_DATA_TYPE "${class_name}::${msg_name} msg_id" | ||
|
||
struct ${msg_name} { | ||
short msg_id; | ||
${{fields: ${opendds_type} field_${attrib_macro}}} | ||
}; | ||
}} | ||
|
||
}; | ||
''', xml) | ||
if name != 'stdout': | ||
f.close() | ||
|
||
def eval_int(expr): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is it used ? |
||
import ast | ||
return int(eval(compile(ast.parse(expr, mode='eval'), '<string>', 'eval'))) | ||
|
||
def generate(output, xml): | ||
'''generate complete PPRZLink C implemenation from a XML messages file''' | ||
|
||
directory, name = os.path.split(output) | ||
|
||
|
||
print("Generating C implementation in %s" % output) | ||
if directory != '': | ||
pprz_parse.mkdir_p(directory) | ||
|
||
# fix the class name to conform with standards | ||
xml.class_name = xml.class_name.title() | ||
|
||
# add some extra field attributes for convenience with arrays | ||
for m in xml.message: | ||
m.msg_name = m.msg_name.title() | ||
m.msg_name = re.sub('[_]', '', m.msg_name) | ||
offset = 2 # 2 bytes initial offset (sender id, message id) | ||
for f in m.fields: | ||
if f.type == 'uint8_t' or f.type == 'uint16_t' or f.type == 'char': | ||
f.opendds_type = 'unsigned short' | ||
elif f.type == 'int8_t' or f.type == 'int16_t': | ||
f.opendds_type = 'short' | ||
elif f.type == 'uint32_t': | ||
f.opendds_type = 'unsigned long' | ||
elif f.type == 'int32_t': | ||
f.opendds_type = 'long' | ||
elif f.type == 'float': | ||
f.opendds_type = 'float' | ||
elif f.type == 'double': | ||
f.opendds_type = 'double' | ||
else: | ||
f.opendds_type = 'void' | ||
|
||
if not type(f.array_type) == type(None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. usually something like |
||
# it is an array - wrap as a stream | ||
f.opendds_type = re.sub('[ ]', '_', f.opendds_type) + '_array' | ||
|
||
f.attrib_macro = '%s;\n' % f.field_name | ||
|
||
generate_messages_h(directory, name, xml) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe find a better name, it is not a
.h
file