Sternum Embedded SDK
|
This section documents how to use the API to generate traces and provide associated data (trace arguments) in C/C++ applications .
The following include files shall be loaded in order to use the SDK API functions:
Note The trace_protocol_user_definition.h file generated by Studio is automatically loaded by the SDK. It contains the definitions of the traces and trace arguments associated to your Device Profile. You can also download this file directly from the device profile menu Download Traces Definition -> Header File in the Sternum Platform.
The SDK environment (i.e. settings) shall be defined before calling the SDK initialization function. The environment is defined by the struct sternum_sdk_settings_t structure. It defines for example the trace flush behavior, the device id to use, and other parameters:
You can also use the predefined function init_sternum_sdk_settings(sternum_sdk_settings_t * settings) to initialize your settings struct object.
This table provides more information on each parameter:
Parameter | Default Value | Description |
---|---|---|
inter_transmission_delay_ms | 100 | Time to wait in milliseconds between each transmission. |
firmware_version | none | Device firmware version string. Used in system trace generated by the sdk_init(). |
flush_automatically | false | Automatically call sdk_flush() for each trace. |
trace_buffer | none | Pointer to buffer holding single trace. You are responsible to allocate the buffer and assign this field with its address. |
trace_buffer_size | none | Size of buffer holding single trace. You are responsible to set this field with the size of the allocated trace_buffer. |
communication_buffer | none | Pointer to buffer holding all pending traces. You are responsible to allocate the buffer and assign this field with its address. |
communication_buffer_size | none | Size of buffer holding all pending traces. You are responsible to set this field with the size of the allocated communication_buffer. |
access_token | none | The access token (aka. Device Profile ID) obtained from ADS for your device/firmware type. Refer to ADS Device Profiles. |
device_id | none | The ID of the device (uint64_t value). |
A simple way to define the settings is to use the predefined settings and completes its non-initialized parameters, a shown in the next example.
The function sternum_sdk_initialize() shall be invoked right after the system was completely initialized and before any use of other API functions. This function uses the provided settings to initialize the API and the tracing capabilities. For example, it triggers the creation of underlying resources (e.g. mutexes or communication channels, depending on the operating system/integration).
An example of initialization is:
The SDK provides the following functions to generate traces in your application code:
Examples of use of these functions are described below.
To generate a trace with no argument:
with:
Refer to the API reference information for the status return value.
To generate a trace with one trace argument:
with:
Refer to the API reference information for the status return value.
1- Example: Generating a trace with an unsigned integer argument
2- Example: Generating a trace with a string argument
3- Generating a trace with a blob argument
myByteBufferLen is the amount of bytes to be collected. myByteBuffer is the blob itself and can be a literal or a pointer variable.
To generate a trace with multiple trace arguments:
with the same parameters as above.
Refer to the API reference information for the status return value.
The STERNUM_ADS_TRACEF() function allows to generate a trace with a formatted string argument:
Where Format is a string that contains the text argument value. It can optionally contain format tags that are replaced by the values specified in subsequent additional arguments (represented as …) and formatted as requested.
See https://linux.die.net/man/3/printf to learn more on the format structure.
Traces with malformed arguments will be sent if possible. An indicative error will be returned.
Refer to the API reference information for the status return value.
To enhance user convenience, we have included a collection of predefined logs that are commonly used. The complete set of predefined log functions is detailed in the sternum_trace_api.h file.
To employ a predefined log, you can easily call it as a function with the required argument.
Refer to sternum_trace_api.h for a comprehensive list of available predefined log functions.
The sternum_sdk_flush() function will trigger and wait for the completion of the transmission of pending traces that have not been yet sent to the Sternum Platform.
If the transmission cannot be completed, the function will return an error.
The SDK can manage the flushing of traces automatically.
To enable auto-flush, set the flush_automatically flag to true in the sdk_settings set during the SDK initialization.
Refer to the API reference information for the status return value.
The activity diagram detailing the sequence of events when a user initiates the STERNUM_ADS_TRACE()
or sternum_sdk_flush()
operation provides a comprehensive overview of the system's behavior during these specific actions.