Compiling a Custom Driver
You can create a custom driver for the SmartServer to provide support for additional protocols not built into the standard SmartServer software. To develop a custom driver you implement your driver-specific code in C++ using the GNU C++ compiler (g++) and link your driver with the IAP Driver Library (IDL) that is included with the SmartServer. IDL is implemented as a shared object (.SO) written in C++, as is the associated header file, libidl.h. The SmartServer includes an installed instance of GCC (GNU Compiler Collections) and the g++ compiler. Using a console application like PuTTY to access the SmartServer, you can verify the installation of g++ by checking the version using the ‘g++ --version’ command from the console.
The provided example custom driver includes a simple makefile. Using the makefile is the easiest way to compile this example driver. Using a console application, navigate to the /var/apollo/data/example/ directory and enter ‘make’ to compile the example.
The make file specifies the –g option with g++ in order to include the debugging information in the resulting object / executable file. You can exclude this option for a final driver build. Several library files must also be specified in the compilation process including:
- idl – The required IDL library.
- mosquitto – The MQTT message broker library.
- pthread – The POSIX threading library (if custom driver threads are instantiated).
- rt – The Linux real-time library. This is required as the IDL library itself uses message queuing (mqueue).
After compiling the application, the resulting executable ( /.example ) is in the /var/apollo/data/example/ directory.
While this documentation section is focused on the basics associated with compiling the provided example custom driver on a SmartServer, you can also develop and compile on a different computer such as a Windows-based computer. Running an custom driver on a non-Linux target other than that SmartServer may not be practical, given the close connection between a custom driver and the underlying hardware and the SmartServer CMS, but development environments like Visual Studio Code can facilitate code development. Following are a few useful tools for developing a custom driver on a Windows host.
The Microsoft C/C++ extension for Visual Studio Code enables cross-platform C and C++ development on Windows and Linux. This extension can be easily downloaded & installed from within Visual Studio Code.
Mingw-w64 is an open source project and a free runtime environment created to support the GCC compiler (g++) on 32-bit and 64-bit Windows-based systems. Mingw-w64 can be freely downloaded and installed from the SourceForge website.
During installation, set the architecture to x86_64 and add the path to your Mingw-w64 folder to the Windows PATH environment variable. You can verify the minGW installation using a Windows console to check the installed version of g++ ‘g++ --version’.
Within Visual Studio Code you can ‘Configure Default Build Task’ from the Terminal and choose g++.exe as the active build file which will create an associated tasks.json file in the .vscode folder. This ultimately provides a means to build custom driver code via the ‘Run Build Task’ from the Terminal in Visual Studio Code.