Mdf API Reference
MDF API
The MDF API (a part of the DSE C Lib) provides methods for creating an MDF4 data stream. Data is saved according to the ASAM Standards.
Because of the streaming design the exact number of samples written to an MDF file is not known when the MDF file is initially created. Accordingly, to indicate this condition, the follwing flags are set in the MDF file:
- Update of cycle counters for CG-/CABLOCK required.
- Update of length for last DTBLOCK required.
Block Order Diagram
Note: Repeating elements are marked in blue.
Example
The following example demonstrates how to use the MDF API for a simple arrays based data source.
// Copyright 2024 Robert Bosch GmbH
#include <stdint.h>
#include <dse/clib/mdf/mdf.h>
#define ARRAY_SIZE(x) (sizeof((x)) / sizeof((x)[0]))
void mdf_api_example(void)
{
const char* signal[] = { "SigA", "SigB", "SigC", "SigD" };
double scalar[] = { 0, 1, 2, 3 };
// Configure the MDF Channel Groups.
MdfChannelGroup groups[] = {
{
.name = "Physical",
.signal = signal,
.scalar = scalar,
.count = ARRAY_SIZE(signal),
},
};
// Open a file stream for writing MDF data.
FILE* f = fopen("tsetfile.MF4", "w");
// Create the MDF Descriptor.
MdfDesc mdf = mdf_create(f, groups, ARRAY_SIZE(groups));
// Write a number of samples to the MDF file stream.
mdf_start_blocks(&mdf);
for (double timestamp = 0.0; timestamp < 0.010; timestamp += 0.0005) {
for (size_t i = 0; i < ARRAY_SIZE(scalar); i++) {
scalar[i] += 1;
}
mdf_write_records(&mdf, timestamp);
}
// Close the file stream.
fclose(f);
}
Typedefs
MdfChannelGroup
typedef struct MdfChannelGroup {
const char* name;
size_t count;
int record_count;
const char** signal;
double* scalar;
int record_id;
}
MdfDesc
typedef struct MdfDesc {
FILE* file;
size_t offset;
struct (anonymous struct at dse/clib/mdf/mdf.h:77:5) channel;
}
Functions
mdf_create
Create and configure an MdfDesc
object to represet an MDF stream.
Parameters
- file (void*)
- File stream pointer.
- list (MdfChannelGroup*)
- Pointer to a list of MdfChannelGroup objects which specifies the MDF channel and signal source.
- count (size_t)
- Number of objects in the
list
.
Returns
- MdfDesc (struct)
- MdfDesc object.
mdf_start_blocks
Write the start blocks of an MDF4 file to the MDF file stream.
Parameters
- mdf (MdfDesc*)
- MdfDesc object.
mdf_write_records
Write the current channel samples to the MDF file stream.
Parameters
- mdf (MdfDesc*)
- MdfDesc object.
- timestamp (double)
- Timestamp to apply for this set of samples.