diff --git a/generator/mavgen_javascript.py b/generator/mavgen_javascript.py index 5598dc9bd..1e1cd608c 100644 --- a/generator/mavgen_javascript.py +++ b/generator/mavgen_javascript.py @@ -35,17 +35,9 @@ def generate_preamble(outf, msgs, args, xml): */ jspack = require("jspack").jspack, - _ = require("underscore"), events = require("events"), // for .emit(..), MAVLink20Processor inherits from events.EventEmitter util = require("util"); -var Buffer = require('buffer').Buffer; // required in react - no impact in node -var Long = require('long'); - -// Add a convenience method to Buffer -Buffer.prototype.toByteArray = function () { - return Array.prototype.slice.call(this, 0) -} ${MAVHEAD} = function(){}; @@ -54,7 +46,7 @@ def generate_preamble(outf, msgs, args, xml): var bytes = buffer; var crcOUT = crcIN === undefined ? 0xffff : crcIN; - _.each(bytes, function(e) { + bytes.forEach(function(e) { var tmp = e ^ (crcOUT & 0xff); tmp = (tmp ^ (tmp << 4)) & 0xff; crcOUT = (crcOUT >> 8) ^ (tmp << 8) ^ (tmp << 3) ^ (tmp >> 4); @@ -132,16 +124,15 @@ def generate_preamble(outf, msgs, args, xml): // Convenience setter to facilitate turning the unpacked array of data into member properties ${MAVHEAD}.message.prototype.set = function(args,verbose) { // inspect - _.each(this.fieldnames, function(e, i) { + this.fieldnames.forEach(function(e, i) { var num = parseInt(i,10); if (this.hasOwnProperty(e) && isNaN(num) ){ // asking for an attribute that's non-numeric is ok unless its already an attribute we have if ( verbose >= 1) { console.log("WARNING, overwriting an existing property is DANGEROUS:"+e+" ==>"+i+"==>"+args[i]+" -> "+JSON.stringify(this)); } } }, this); - //console.log(this.fieldnames); -// then modify - _.each(this.fieldnames, function(e, i) { + // then modify + this.fieldnames.forEach(function(e, i) { this[e] = args[i]; }, this); }; @@ -167,11 +158,11 @@ def generate_preamble(outf, msgs, args, xml): // first add the linkid(1 byte) and timestamp(6 bytes) that start the signature this._msgbuf = this._msgbuf.concat(jspack.Pack(' payloadBuf.length) { - payloadBuf = Buffer.concat([payloadBuf, Buffer.alloc(paylen - payloadBuf.length)]); + payloadBuf = this.concat_buffer(payloadBuf, new Uint8Array(paylen - payloadBuf.length).fill(0)); } """) @@ -915,7 +890,7 @@ def generate_mavlink_class(outf, msgs, xml): if (elementsInMsg == actualElementsInMsg) { // Reorder the fields to match the order map - _.each(t, function(e, i, l) { + t.forEach(function(e, i, l) { args[i] = t[decoder.order_map[i]] }); } else { @@ -959,7 +934,7 @@ def generate_mavlink_class(outf, msgs, xml): } // Finally reorder the fields to match the order map - _.each(t, function(e, i, l) { + t.forEach(function(e, i, l) { args[i] = tempArgs[decoder.order_map[i]] }); }