Skip to content

Commit

Permalink
Mavgen JS: Heartbeat message mavlink_version should be automatic
Browse files Browse the repository at this point in the history
Remove from constructor parameter list, and assign directly.
Remains settable by the unpacker for received messages.
Heartbeat test cases updated to reflect new interface.
  • Loading branch information
shancock884 authored and peterbarker committed Mar 15, 2024
1 parent f4e45e4 commit e0caa6f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 1 addition & 3 deletions generator/javascript/test/message10.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,12 @@ describe('Complete MAVLink 1.0 packet', function() {
, base_mode=45
, custom_mode=68
, system_status=13
, mavlink_version=1
);

this.mav.seq = 7;

// Create a buffer that matches what the Python version of MAVLink creates
var reference = new Buffer.from([0xfe, 0x09, 0x07, 0x2a, 0x96, 0x00, 0x44, 0x00, 0x00, 0x00, 0x05, 0x03, 0x2d, 0x0d, 0x01, 0xac, 0x9d]);
var reference = new Buffer.from([0xfe, 0x09, 0x07, 0x2a, 0x96, 0x00, 0x44, 0x00, 0x00, 0x00, 0x05, 0x03, 0x2d, 0x0d, 0x03, 0x1c, 0xae]);
new Buffer.from(heartbeat.pack(this.mav)).should.eql(reference);

});
Expand Down Expand Up @@ -161,7 +160,6 @@ describe('MAVLink 1.0 message', function() {
0, // base mode, mavlink10.MAV_MODE_FLAG_***
0, // custom mode
mavlink10.MAV_STATE_STANDBY, // system status
3 // MAVLink version
);

this.mav = new MAVLink10Processor();
Expand Down
2 changes: 0 additions & 2 deletions generator/javascript/test/message20.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ describe('Complete MAVLink 2.0 packet', function() {
, base_mode=45
, custom_mode=68
, system_status=13
, mavlink_version=3 // it's NOT a v1 vs v2 thing here. 3 really is its normal value.
);

this.mav.seq = 7;
Expand Down Expand Up @@ -356,7 +355,6 @@ describe('MAVLink 2.0 message', function() {
0, // base mode, mavlink.MAV_MODE_FLAG_***
0, // custom mode
mavlink20.MAV_STATE_STANDBY, // system status
3 // MAVLink version
);

this.mav = new MAVLink20Processor();
Expand Down
16 changes: 10 additions & 6 deletions generator/mavgen_javascript.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,22 @@ def generate_classes(outf, msgs, xml):
def field_descriptions(fields):
ret = ""
for f in fields:
ret += " %-18s : %s (%s)\n" % (f.name, f.description.strip(), f.type)
if not f.omit_arg:
ret += " %-18s : %s (%s)\n" % (f.name, f.description.strip(), f.type)
return ret

# now do all the messages
for m in msgs:

# assemble some strings we'll use later in outputting ..
comment = "%s\n\n%s" % (wrapper.fill(m.description.strip()), field_descriptions(m.fields))
selffieldnames = 'self, '
argfieldnames = []
conststr = ""
for f in m.fields:
selffieldnames += '%s, ' % f.name
selffieldnames = selffieldnames[:-2]
if not f.omit_arg:
argfieldnames.append(f.name)
else:
conststr = conststr + " this.%s = %s;\n" % (f.name, f.const_value)

# instance field support copied from mavgen_python
if m.instance_field is not None:
Expand All @@ -289,11 +293,11 @@ def field_descriptions(fields):
outf.write(" %s.messages.%s = function(" % ( get_mavhead(xml), m.name.lower() ) )
outf.write(" ...moreargs ) {\n")
# passing the dynamic args into the correct attributes, we can call the constructor with or without the 'moreargs'
outf.write(" [ this.%s ] = moreargs;\n" % " , this.".join(m.fieldnames))
outf.write(" [ this.%s ] = moreargs;\n" % " , this.".join(argfieldnames))
outf.write(conststr)

# body: set message type properties
outf.write("""
this._format = '%s';
this._id = %s.MAVLINK_MSG_ID_%s;
this.order_map = %s;
Expand Down

0 comments on commit e0caa6f

Please sign in to comment.