Using external sensor drivers
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:
-
Provide your external sensor driver library with implementations for the following
function types (mandatory):
- open_external_sensor_funct_t()
- close_external_sensor_func_t()
- init_sensor_func_t()
- deinit_sensor_func_t()
- start_streaming_func_t()
- stop_streaming_func_t()
- fill_format_info_func_t()
- get_packet_func_t()
- get_buffer_requirements_func_t()
Optionally, you can provide implementations for these function types:
For more information about the specifics to implement, see external_sensor_api.h inSensor 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. -
Create an instance called
external_sensor_defsand 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:The Sensor service dynamically loads the structure to retrieve the function pointers so that it can interface with your sensor driver library.In your sensor driver library, you must useexternal_sensor_defsto declare your variable name for the structure sensor_external_sensor_t. -
In the file that declares
external_sensor_defs, you need to specify#define EXTERNAL_SENSOR_API_IMPLEMENTprior 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> - 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 theSensor
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.
