Skip to content

Conversation

@shancock884
Copy link
Contributor

When trying to use mavgen.py with "JavaScript_NextGen" language, on Windows I was getting the following error:

Traceback (most recent call last):
  File "C:\Users\shanc\linkingdrones\mavlink\pymavlink\tools\mavgen.py", line 30, in <module>
    ok = mavgen.mavgen(args, args.definitions)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\shanc\linkingdrones\mavlink\pymavlink\generator\mavgen.py", line 267, in mavgen
    mavgen_javascript.generate(opts.output, xml)
  File "C:\Users\shanc\linkingdrones\mavlink\pymavlink\generator\mavgen_javascript.py", line 1371, in generate
    generate_preamble(outf, msgs, filelist, xml[0])
  File "C:\Users\shanc\linkingdrones\mavlink\pymavlink\generator\mavgen_javascript.py", line 177, in generate_preamble
    t.write(outf, """
  File "C:\Users\shanc\linkingdrones\mavlink\pymavlink\generator\mavtemplate.py", line 132, in write
    file.write(self.substitute(text, subvars=subvars, trim_leading_lf=trim_leading_lf))
  File "C:\Users\shanc\AppData\Local\Programs\Python\Python312\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode character '\u03a3' in position 2079: character maps to <undefined>

It seems that on Windows the opened output file encoding defaults to cp1252 encoding, but mavgen is attempting to output some JS functions containing UTF8 characters, such as this one:

function Σ0(x) { return ROTR(2, x) ^ ROTR(13, x) ^ ROTR(22, x); }

The fix is to force the encoding of the output JS files to be UTF8.
Checked and seems to work in my local Windows environment, generating valid JS files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant