Using external sensor drivers

Updated: May 06, 2022

Sensors that aren't already supported by the Sensor Framework for QNX SDP can be provided by an external sensor driver library.

You may provide a library that supports an external sensor. To use an external sensor driver library, you must:

  1. Provide your external sensor driver library with implementations for the following function types (mandatory):

    Optionally, you can provide implementations for these function types:

    For more information about the specifics to implement, see external_sensor_api.h in “Sensor Library Reference” for each of the functions.
    Note: For a code example, see the reference source code for the Sensor example application included in the QNX SDP 7.1 Sensor Framework Base package.
  2. Create an instance called external_sensor_defs and assign the function pointers to the name of your function implementations using the sensor_external_sensor_t structure. For optional functions you didn't implement, you can assign NULL.
    sensor_external_sensor_t external_sensor_defs = {
        open:                    my_external_open_sensor,
        close:                   my_external_close_sensor,
        init:                    my_external_init_sensor,
        deinit:                  my_external_deinit_sensor,
        start_streaming:         my_start_streaming_sensor,
        stop_streaming:          my_stop_streaming_sensor,
        get_packet:              my_get_packet,
        get_buffer_requirements: my_get_buffer_requirements,
        get_time:                my_gettime,
        parse_config:            my_parse_config,
        set_sensor_metadata:     my_set_sensor_metadata,
        get_metadata_limits:     my_get_metadata_limits,
        fill_format_info:        my_fill_format
    };
    Note: In your sensor driver library, you must use external_sensor_defs to declare your variable name for the structure sensor_external_sensor_t.
    The Sensor service dynamically loads the structure to retrieve the function pointers so that it can interface with your sensor driver library.
  3. In the file that declares external_sensor_defs, you need to specify #define EXTERNAL_SENSOR_API_IMPLEMENT prior to including external_sensor_api.h or any other Sensor library header file. This is necessary to ensure backwards compatibility with future versions of the library. This can be done as follows:
    #define EXTERNAL_SENSOR_API_IMPLEMENT
    #include <sensor/external_sensor_api.h>
  4. Configure the type as external_sensor and the address with the path to your sensor driver library in the sensor configuration file. See the “Sensor configuration file” in the Sensor chapter of the Sensor Framework Services guide.

An example of an external sensor driver implementation is available with the Sensor Framework for QNX SDP from the QNX Software Center. See the source directory for more information in your host installation at $QNX_BASE/source/adas-sensor-examples-version.zip. After you extract the ZIP file, you'll find the example at extraction_directory/source_package_adas_sensor/lib/sensor_drivers/external_sensor_example.