Skip to content
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

generator: add javascript "lite" #921

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion generator/mavgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

# List the supported languages. This is done globally because it's used by the GUI wrapper too
# Right now, 'JavaScript' ~= 'JavaScript_Stable', in the future it may be made equivalent to 'JavaScript_NextGen'
supportedLanguages = ["Ada", "C", "CS", "JavaScript", "JavaScript_Stable","JavaScript_NextGen", "TypeScript", "Python2", "Python3", "Python", "Lua", "WLua", "ObjC", "Swift", "Java", "C++11"]
supportedLanguages = ["Ada", "C", "CS", "JavaScript", "JavaScript_Stable","JavaScript_NextGen", "JavaScript_lite", "TypeScript", "Python2", "Python3", "Python", "Lua", "WLua", "ObjC", "Swift", "Java", "C++11"]


def mavgen(opts, args):
Expand Down Expand Up @@ -303,6 +303,9 @@ def mavgen_validate(xmlfile):
else:
from . import mavgen_ada
mavgen_ada.generate(opts.output, xml)
elif opts.language == 'javascript_lite':
from . import mavgen_javascript_lite
mavgen_javascript_lite.generate(opts.output, xml)
else:
print("Unsupported language %s" % opts.language)

Expand Down
44 changes: 44 additions & 0 deletions generator/mavgen_javascript_lite.py
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)

Loading