def generate(basename, xml):
    '''generate complete javascript implementation'''

    if basename.endswith('.js'):
        filename = basename
    else:
        filename = basename + '.js'

    msgs = []
    enums = []
    filelist = []
    for x in xml:
        msgs.extend(x.message)
        enums.extend(x.enum)
        filelist.append(os.path.basename(x.filename))

    for m in msgs:
        if xml[0].little_endian:
            m.fmtstr = '<'
        else:
            m.fmtstr = '>'
        for f in m.ordered_fields:
            m.fmtstr += mavfmt(f)
        m.order_map = [ 0 ] * len(m.fieldnames)
        for i in range(0, len(m.fieldnames)):
            m.order_map[i] = m.ordered_fieldnames.index(m.fieldnames[i])

    print("Generating %s" % filename)
    outf = open(filename, "w")
    generate_preamble(outf, msgs, filelist, xml[0])
    generate_enums(outf, enums)
    generate_message_ids(outf, msgs)
    generate_classes(outf, msgs)
    generate_mavlink_class(outf, msgs, xml[0])
    generate_footer(outf)
    outf.close()
    print("Generated %s OK" % filename)
def generate ( basename , xml ) : if basename . endswith ( '.js' ) : filename = basename else : filename = basename + '.js' msgs = [ ] enums = [ ] filelist = [ ] for x in xml : msgs . extend ( x . message ) enums . extend ( x . enum ) filelist . append ( os . path . basename ( x . filename ) ) for m in msgs : if xml [ 0 ] . little_endian : m . fmtstr = '<' else : m . fmtstr = '>' for f in m . ordered_fields : m . fmtstr += mavfmt ( f ) m . order_map = [ 0 ] * len ( m . fieldnames ) for i in range ( 0 , len ( m . fieldnames ) ) : m . order_map [ i ] = m . ordered_fieldnames . index ( m . fieldnames [ i ] ) print ( "Generating %s" % filename ) outf = open ( filename , "w" ) generate_preamble ( outf , msgs , filelist , xml [ 0 ] ) generate_enums ( outf , enums ) generate_message_ids ( outf , msgs ) generate_classes ( outf , msgs ) generate_mavlink_class ( outf , msgs , xml [ 0 ] ) generate_footer ( outf ) outf . close ( ) print ( "Generated %s OK" % filename )
generate complete javascript implementation