OAC Serial Protocol and Command Gateway

It sometimes happens. You can dedicate hours and hours to solve a problem, and then you realize that the solution was in front of your eyes all the time.

Some day, I was working with Prepar3D files when I found a folder named FSUIPC Documents under Modules directory of the Prepar3D installation. Once open, I saw a bunch of PDF files there and one of them called my attention: FSUIPC Lua Library Reference. Then I remembered the Lua scripting engine provided by FSUIPC. I read time ago about it. The ability to execute scripts that interacts with the internal state of the simulator. In that time, I didn’t want to look any further. I thought that’s something out of scope of Open Airbus Cockpit. But then, the curiosity lead me to open the file and check out what kind of interactions are supported by the Lua libraries. And then I realized I shouldn’t ignore the FSUIPC Lua engine the first time I knew about it.

One of the biggest challenges of the project was how to integrate the Arduino boards with the simulator. There were several options. First of all, the channel used to communicate the Arduino board with the PC: use the built-in serial over USB or a Ethernet shield? The former is cheaper but rudimentary. The former is more expensive but more flexible. And then we have to decide what’s behind the cable. Serial communication requires a very specific process running in the PC to act as a bridge between the serial device and the simulator. Ethernet requires a TCP/IP enabled process for the same.

The initial approach was to use a custom serial bridge to FSUIPC, what initiated the Wilco Exporter subproject to have the Wilco Airbus internal state available as FSUIPC offsets. Then was the time for FlightVars. An initial version using a custom protocol over TCP and some recent experiments with MQTT. But we were far away to have something that could interact with the Arduino board.

And some weeks ago I was opening that PDF file. I read about the Lua libraries available for script makers. I read about the IPC library to read and write FSUIPC offsets and LVARs. The COM library to connect with the outside world using serial ports. And the Event library to have a event-oriented design in your script. And then I realized those were the building-blocks to have a process that integrates the Arduino board with the simulation state. The building-blocks of OAC Command Gateway.

The rest was only coding. Design the OAC Serial protocol used to send write and observe commands from the Arduino to the gateway running as a Lua script, and to receive events coming from the gateway back to the board. That grants access to FSUIPC offsets and aircraft LVARs using the serial port. And that’s it. You may find OAC Command Gateway in the GitHub repository with the corresponding instructions to install it in your system.

But, Command Gateway is useless if you cannot communicate with it, isn’t it? Of course you could send the commands using the serial port with your own code. But that would be tedious. In order to solve that, the OACSP Arduino library does it for you. You’ll find OACSP in GitHub repository with the appropriate instructions on how to install it and some examples on how you can use it.

Are OACSP and OAC Command Gateway the final solution of OAC project to integrate electronics and software? Honestly, I don’t know. It depends on its limitations that will be arised as the time goes, and the benefit-cost rate of implementing a more sophisticated solution as FlightVars. Right now, OAC Command Gateway has demostrated to offer low-latency receiving events, and I’m working on some stress tests to verify its performance on a realistic setup for a cockpit. And the most important: it works. I succeed to integrate the A320 engine ignition and the ECAM control panels. And one of our beta testers (thanks David!) has designed an IAS gauge controlled by an Arduino board using OACSP with a very good performance. As long as OACSP fits the expectations, it will be the integration solution for the project.

Finally, I want to encourage you to try OACSP and OAC Command Gateway. As the rest of the results of the project, you are free to use it without any fee, and the code is available for you to adapt it to your needs according to its open source license. If you find any problem or you have any question, please don’t hesitate to ask.

Happy flying!

Leave a comment