This standalone WASM module for Microsoft Flight Simulator 2020 enables us to send events to the sim and execute them in the context of the aircraft gauges system. Also it provides SimConnect access to certain variable types which are not accessible otherwise. With this module you can interface your home cockpit hardware more efficiently.
This module also is released together with the MobiFlight Connector application as part of the MobiFlight Open Source Project - [https://mobiflight.com].
WASM modules in general are able to execute gauge calculator scripts, which can be used to read special variables like L- or A-Variables (execute_calculator_code). They can communicate and exchange data with external SimConnect clients via newly created shared memory areas (CreateClientData).
The MobiFlight WASM module uses three shared memory areas/channels for communication with an external SimConnect client.
- The Command-Channel to receive commands from the external SimConnect client.
- The LVars-Channel to continuously provide the variable data to the SimConnect client.
- The Response-Channel to send other information to the SimConnect client.
The default channels for the MobiFlight client are auto created on startup. Each channel has a fix unique name.
Command (string) | Responses (string) | LVars offset (float) |
---|---|---|
MF.Ping |
MF.Pong |
|
MF.LVars.List |
MF.LVars.List.Start A32NX_AUTOPILOT_1_ACTIVE A32NX_AUTOPILOT_HEADING_SELECTED ... MF.LVars.List.End |
|
MF.SimVars.Add.(A:GROUND ALTITUDE,Meters) |
1455.23 |
|
MF.SimVars.Clear |
||
MF.SimVars.Set.5 (>L:MyVar) |
||
MF.Clients.Add.ClientName |
MF.Clients.Add.ClientName.Finished |
|
MF.Config.MAX_VARS_PER_FRAME.Set.30 |
||
MF.Version.Get |
MF.Version.0.6.0 |
MF.SimVars.Add. The "SimVars.Add." command needs to be extended with a gauge calculator scipt for reading a variable, like shown in the table. Each added variable needs 4 reserved bytes to return its float value in the LVars channel. The bytes are allocated in the order of the LVars being added. The first variable starts at offset 0, the second at offset 4, the third at offset 8 and so on. To access each value, the external SimConnect clients needs a unique DataDefinitionId for each memory segment. It is recommended to start with ID 1000.
MF.Clients.Add.
The default channels are reserved for communication with the MobiFlight client. But they can be used to request additional channels for other SimConnect clients as well. If another client wants to use the WASM module for variable access, it can register itself with the command MF.Clients.Add.MyClientName
using the default command channel. The WASM module then creates the new shared memory channels "MyClientName.LVars", "MyClientName.Command", "MyClientName.Response" and informs the client with MF.Clients.Add.ClientName.Finished
.
The MobiFlight default client code can be found here and here.
First the client needs to map each shared memory aka ClientDataArea with MapClientDataNameToID using the correct name and a new ID for each ClientDataArea.
Then the client needs to add each memory segment (=variable) it wants to access to its data definition with AddToClientDataDefinition. For each segment a not yet used DefinitionId must be provided. ClientDataDefinitions cannot be reused across different ClientDataAreas and the DefinitionIds must be unique in the context of the client.
Finally the client can subscribe to changes in the Response- or LVar-channel with RequestClientData using the SIMCONNECT_PERIOD_ON_SET parameter.
Sending a command in the Command-channel can be done with SetClientData. Hint: Sometimes the first command after a new start of the client via SetClientData seems to be ignored, therefore send an arbitrary dummy command in the beginning.
- Subscribe to the "MobiFlight.Response" channel.
- Register your new client "MyGreatClient" via the "MobiFlight.Command" channel:
MF.Clients.Add.MyGreatClient
- After getting the response
MF.Clients.Add.MyGreatClient.Finished
, map and use your new communication channels (ClientDataAreas) "MyGreatClient.LVars", "MyGreatClient.Command", "MyGreatClient.Response". - Add Variables via the "MyGreatClient.Command" channel:
MF.SimVars.Add.(xxx).
- Receive the values via the "MyGreatClient.LVars" channel.
A Python example implementation can be found here.