X-Plane RESTful API

Screencast

Windows-only REST API for X-Plane.

Source Code & Status

https://github.com/delacruz/XplaneRestApi

Status

Experimental. Your input is welcome. Your code contribution to improve and stabilize the project is even more welcome! ;)

Wiki

https://github.com/delacruz/XplaneRestApi/wiki

Intro

This project aims to provide a conceptual RESTful interface into X-Plane.

The purpose is to provide an alternative to the X-Plane UDP interface for executing commands and retrieving status, making use of documented datarefs of the X-Plane Plugin-Based SDK.

Limitations

  • Windows Only: This code is an abstraction from a Windows based solution. Therefore, it is currently the only platform supported. Your contribution to the project to help get it onto other platforms is welcome!

  • The ideal use for this solution is for executing commands and retrieving status in a single-shot manner. In other words, this is solution is not ideal if you need to retrieve data at a set rate (ie. 30Hz).

Background

I've recently been working on a project involving instructional subsystems for simulation environments. One of the initial requirements was to interface with a simulator. I elected X-Plane as my simulator test bed, its combination of robustness and price point was attractive to me. I also dig the fact they have such a complete API, and the SDK website appears to be very well documented - a huge plus when you're looking to hit the ground running!

Development

The X-Plane SDK website has excellent documentation and examples to get you up to speed on your plugin development.

The Beginning

Initially, I needed only the airframe's latitude and longitude, which was a breeze to retrieve and make available to my application. But I soon needed the Indicated Airspeed as well, so I wrote code, recompiled, and dropped in my new plugin. Just a day later, I wanted to extend functionality such that I could affect the environment, so I wrote code, recompiled, and dropped in my new plugin. I soon needed the to be able to change the aircraft's tail number, so I wrote code, recompiled.... you see where this is going.... Sure I love coding, but I wasn't about to continue going thru this process writing C code and making a new plugin every time I needed to read or write a new variable. There had to be a better way.

I looked into using X-Plane's UDP interface, but that seemed to be a very slippery slope - a good single-source documentation was hard to come by, and not much hinted at it even being officially supported.

A Better Approach

I wanted a solution to solve most of my (evolving) requirements, the vast majority of which involved executing commands, and retrieving state data; I wanted to minimize the amount of coding on the plugin side.

The ideal solution: Wrap the API somehow, expose it via a much simpler interface - a web service. Better yet a RESTful service!

How it Works

The X-Plane REST API for Windows solution consists of two parts:

  • X-Plane Plugin written in C

  • Web Service written in C#

The X-Plane plugin monitors shared memory for incoming queries, and also writes responses to shared memory when necessary. The web service interfaces with your application via JSON messages, and interfaces with the plugin via shared memory.

rest-diagram.png