JavaScript Message API¶
Overview¶
The Message API lets you write values to a Custom Message from JavaScript.
Example Message Definition
{ "name": "Altitude", "unit": "Meters", "lowValue": 0, "highValue": 30000, "stepSize": 100 },
{ "name": "GPSSatsInView", "unit": "Count", "lowValue": 0, "highValue": 32, "stepSize": 4 },
{ "name": "GPSLockTime", "unit": "Seconds", "lowValue": 0, "highValue": 120, "stepSize": 2 },
{ "name": "Pressure", "unit": "MilliBar", "lowValue": 0, "highValue": 1020, "stepSize": 1 },
The fields you can set on msg
depend on what your Message Definition is!
In the Message Definition above, you have a field
named Altitude
which has the unit
of Meters
.
Because of that, you can automatically call msg.SetAltitudeMeters(x)
to set the value of that field to x
.
This applies to every field in the Message Definition.
All fields are "clamped" to their defined range, so no need to check the values you're setting fall into that range, it's handled automatically. For example, if you call msg.SetAltitudeMeters(35000)
, then the actual value set will be 30000 (the maximum defined in the Message Definition).
You can also "Get" the values back from the message, such as by msg.GetAltitudeMeters()
, such as for Logging, or setting other variables, etc.
Editor¶
The Editor page explains this in more detail.