Git Product home page Git Product logo

jetbridge's Introduction

Jetbridge is a simple WebAssembly (WASM) module that allows out-of-process SimConnect modules to act as if they were in-process ones. Specifically, the current development version allows for external modules to dispatch execute_calculator_code calls which can be used to write L: simvars, or even dispatch H: events. Reading the value of local named variables using get_named_variable is also supported.

How does this even work?

Jetbridge establishes a communication protocol using SimConnect's Client Data Areas. It then defines some basic operations that external clients can use, such as calling execute_calculator_code. Jetbridge ships with a C++ SDK which defines a Client class which allows the consumer to communcate with Jetbridge without having to implement the underlying protocol. SDK's for other language may eventually be provided (e.g. C#).

Mโ€™kayโ€ฆ But will anyone actually use this?

Jetbridge is currently being used by myself, as well as other FlyByWire Simulations developers, to code hardware drivers for the A32NX. It allows for external programs (such as a hardware driver) to access the inner workings of MSFS in ways not otherwise possible through pure SimConnect.

What are all these folders?

Currently, the repo is structured as a single Visual Studio solution, with 4 projects. The Protocol project is a C++ static library that defines core protocol entities (e.g. Packet). The Module project is the core WASM module and it depends on Protocol. The Client project is another C++ static library that defines the consumer-facing SDK (i.e. the Client) - it also depends on Protocol. Finally, the Example project is a simple C++ command line interface executable that shows how Jetbridge can be used by other developers - it of course depends on Client, and requires Module to be loaded in the simulator.

Client/
โ”œโ”€ Client.vcxproj
Example/
โ”œโ”€ Example.vcxproj
Module/
โ”œโ”€ Module.vcxproj
Protocol/
โ”œโ”€ Protocol.vcxproj
jetbridge.sln

How to use the example

You must first install the Module wasm artifact. You'll have to create a Microsoft Flight Simulator package to do this. If this has been done correctly, you should be able to see an initialising message in the MSFS console. Then, simply start the Example.exe artifact. You can then use the CLI to send Reverse Polish Notation code which will be executed using execute_calculator_code. This should look something like this:

2021-03-05-05-29-01

Specifically, use the exe verb followed by the your RNN code. You may also use the get verb followed by the name of a local variable (without the L:) to get the value of an LocalVar. See the example source code for more info

How to use the C++ Client software development kit

Make sure you've correctly imported the static library (header files need to be accessible, .lib file needs to be available to the Linker). Create a Client instance by passing a SimConnect HANDLE:

client = new jetbridge::Client(simconnect);

Then you can send some data using Client->Request:

auto response = client->Request((char*)"x2 (>L:A320_Neo_MFD_NAV_MODE_1)");

This example RPN will set (x opchar) the A320_Neo_MFD_NAV_MODE_1 LocalVar to 2. Client->Request blocks until a response from Jetbridge has been received, or the timeout is reached. If a response is received, it will return a Packet pointer. Important: don't forget to delete this when done using it to avoid a memory leak.

delete response;

Important: You should call the client->HandleReceivedClientDataEvent function with received data for all SIMCONNECT_RECV_ID_CLIENT_DATA events where the RequestID matches jetbridge::kDownlinkRequest. Basically, add something along these lines to your MyDispatchProc:

case SIMCONNECT_RECV_ID_CLIENT_DATA:
  auto e = static_cast<SIMCONNECT_RECV_CLIENT_DATA*>(pData);
  if (e->dwRequestID == jetbridge::kDownlinkRequest) client->HandleReceivedClientDataEvent(e);
  break;

There are also two helper methods to send packets to (1) ExecuteCalculatorCode, and (2) GetNamedVariable:

// Execute the given RPN code:
client->ExecuteCalculatorCode("2 (>L:A320_Neo_MFD_NAV_MODE_1)");
// Get the value of a local named variable:
double value = client->GetNamedVariable("A320_Neo_MFD_NAV_MODE_1");

Jetbridge is currently at a very early stage of development so bear with us whilst we get everything sorted ๐Ÿงธ

jetbridge's People

Contributors

scott-vincent avatar theomessin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

jetbridge's Issues

C# Software Development Kit

There's a couple of people that have expressed interest in using Jetbridge in C#. I believe that a Client equivalent would have to be implemented in C#.

Allow longer scripts

The 128 byte packet size isn't enough to handle some event scripts for the WT CJ4, possibly others. For instance, pressing the BARO knob runs the script:

(L:XMLVAR_Baro1_ForcedToSTD) ! (>L:XMLVAR_Baro1_ForcedToSTD) 
(L:XMLVAR_Baro1_ForcedToSTD) if{ 
      (A:KOHLSMAN SETTING MB:1, mbars) 16 * (>L:XMLVAR_Baro1_SavedPressure) 
      1 (>K:BAROMETRIC_STD_PRESSURE) 
} els{ 
      1 (L:XMLVAR_Baro1_SavedPressure) (>K:2:KOHLSMAN_SET)
}

The quickest solution would be to just increase kPacketDataSize to 256 or 512. (This example was actually 257 characters)

What is the bandwidth of the SimConnect ClientData communication channel?

It would be good to know what the bandwidth of the SimConnect ClientData communication channel is. This would help answer some questions, such as whether it is viable to use a single uplink/downlink channel pair or whether we need separate channels per client. It will also help answer the question of whether splitting Protocol Data Units into multiple packets to allow for larger data transfers is possible.

Testing this should be pretty straightforward. We need a client to spam the Jetbridge Module with requests and for it to count the actual responses received per unit time. We then need to check what happens if multiple (I'd say at least 5) different clients spam the module with requests at the same time.

Subscribe to Simulation Variables

Currently a consumer needing to get the value of a simvar at regular intervals needs to create a separate request for each refresh of each individual variable. It would be nice if a consumer was able to create their own ClientDataArea and instruct jetbridge to subscribe to certain simvars and to update their value at e.g. every frame.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.