-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
1 deletion.
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,44 @@ | ||
#!/usr/bin/env python | ||
''' | ||
parse a MAVLink protocol XML file and generate a javascript file to get CRC extra and name from message ID and MAV_COMPONENT enum. No payload fields are considered. | ||
''' | ||
from __future__ import print_function | ||
|
||
from builtins import range | ||
|
||
import os | ||
|
||
def generate(basename, xml): | ||
msgs = [] | ||
enums = [] | ||
filelist = [] | ||
for x in xml: | ||
msgs.extend(x.message) | ||
enums.extend(x.enum) | ||
filelist.append(os.path.basename(x.filename)) | ||
|
||
print("Generating %s/mavlink_msgs.js" % basename) | ||
# create the output directory if needed | ||
if not os.path.exists(basename): | ||
os.makedirs(basename) | ||
outf = open("%s/mavlink_msgs.js" % basename, "w") | ||
|
||
outf.write("// Auto generated MAVLink parsing script\n\nmavlink_msgs = []\n") | ||
|
||
for msg in msgs: | ||
outf.write("mavlink_msgs[%i] = { name: \"%s\", CRC: %i }\n" % (msg.id, msg.name, msg.crc_extra)) | ||
outf.write("\n") | ||
|
||
for enum in enums: | ||
if enum.name != "MAV_COMPONENT": | ||
# Only need component ID | ||
continue | ||
outf.write("%s = []\n" % enum.name) | ||
for entry in enum.entry: | ||
outf.write("%s[%i] = \"%s\"\n" % (enum.name, entry.value, entry.name)) | ||
outf.write("\n") | ||
|
||
|
||
outf.close() | ||
print("Generated %s OK" % basename) | ||
|