MDF4 File Format
MDF Overview
Measurement Data Format version 4 (MDF 4) is a standard file format used by the automotive industry for storing measurement data in binary file format.Following blocks are supported.
ID block
Header block
Meta data block
File History block
Channel block
Channel group block
Data group block
DT block
Block Sections
Each block has three sections.
Header section
Link section
data section
Block Types
ID Block (ID)
Identification block is used to identify the file as an mdf4 file.It has MDF version and program Identification. This is the only block that has no general block header.IDblock are the only block types which occur only once and which have a fixed position in the MDF file.
Header Block (HD)
Header block defines the general description of measurement of a file. Header block is used to set the offset of following data group offset,channel group offset, and header text comment and set the start time in nano seconds.HD block are the only block types which occur only once and which have a fixed position in the MDF file.
Meta Data Block (MD)
Meta data block is a block which has a container for an XML string of variable length.
File history block (FH)
This block contains file time in nanoseconds and has file history text comment.
Channel Block (CN)
It contains channels that describes data structure and signals, i.e information about the measured signals and hwo the signal values are stored.
Channel Group Block (CG)
Describes the layout of records,i.e channels which are always measured jointly.
Data Group block (DG)
Contains description of the data block that may refer to one or more channel groups,measurement data including data blocks and channnel groups
Data Block (DT)
It contains data records with signal values (e.g CAN frames)
Refer to the MDF Demo page for an example about how the RAPIDSEA uses the mdf file format.
Application Interface
Function |
Description |
---|---|
rs_mdf4_init |
Function to open the mdf4 logging system |
rs_mdf4_set_file_info |
Function to sets the file path and name for MDF4 logging. |
rs_mdf4_set_compression |
Function to sets the compression level for MDF4 logging. |
rs_mdf4_set_prog_identity |
Function to sets the program identity for MDF4 logging. |
rs_mdf4_data_log |
Function to Logs CAN data into the MDF4 system. |
rs_mdf4_default_blks |
Function to initializes the default blocks for MDF4 logging. |
Error Code
Every API’s for the mdf returns some success or failure values. Please refer below section,
MDF4 Header Details
Documentation from the relevant header as follows:
MDF Specific APIs.
Defines macros and functions specific to Rapidsea MDF functionality
- Author
Embien RAPIDSEA Team
- Copyright
Embien Technologies India Pvt. Ltd.
Defines
-
RS_MD4_VERSION_4_0
MD4 version and Size details.
-
RS_MD4_VERSION_4_1
-
RS_MAX_FILE_NAME_SIZE
-
RS_MAX_FILE_PATH_SIZE
Typedefs
-
typedef struct tag_rs_dynamic_mdf_config rs_mdf_dynamic_config_t
Contains information about dynamic mdf configuration.
-
typedef struct tag_rs_mdf_config rs_mdf_config_t
Contains information about mdf configuration.
Functions
-
rs_ret_val_t rs_mdf4_init(rs_mdf_config_t *ptr_config, uint8_t *ptr_buff, uint16_t u16_version, uint32_t u32_buff_size, uint32_t u32_max_file_size, uint32_t u32_max_blk_size)
Initializes the MDF4 logging system.
This function initializes the MDF4 logging system with the specified configuration.
- Parameters:
ptr_config – [in] - Pointer to the MDF4 configuration structure.
ptr_buff – [in] - Pointer to the memory buffer used by the system.
u16_version – [in] - The version of the MDF4 format.
u32_buff_size – [in] - The size of the buffer in bytes.
u32_max_file_size – [in] - The maximum allowed file size in bytes.
u32_max_blk_size – [in] - The maximum allowed block size in bytes.
- Returns:
0 on success or error code on failure
-
rs_ret_val_t rs_mdf4_set_file_info(rs_mdf_config_t *ptr_config, uint8_t *ptr_file_path, uint8_t *ptr_file_name)
Sets the file path and name for MDF4 logging.
This function ets the path and name of the file where the MDF4 data will be stored.
- Parameters:
ptr_config – [in] - Pointer to the MDF4 configuration structure.
ptr_file_path – [in] - Pointer to a string containing the file path.
ptr_file_name – [in] - Pointer to a string containing the file name.
- Returns:
0 on success or error code on failure
-
rs_ret_val_t rs_mdf4_set_compression(rs_mdf_config_t *ptr_config, uint8_t u8_value)
Sets the compression level for MDF4 logging.
This function configures the compression level for MDF4 data logging. The
u8_value
parameter defines the compression setting (e.g., 0 for no compression, 1 for basic compression, etc.).- Parameters:
ptr_config – [in] - Pointer to the MDF4 configuration structure.
u8_value – [in] - The compression level (0 for no compression, higher values for more compression).
- Returns:
0 on success or error code on failure
-
rs_ret_val_t rs_mdf4_set_prog_identity(rs_mdf_config_t *ptr_config, int8_t *ptr_identity)
Sets the program identity for MDF4 logging.
This function sets the program’s identity string, which will be associated with the MDF4 logs.
- Parameters:
ptr_config – [in] - Pointer to the MDF4 configuration structure.
ptr_identity – [in] - Pointer to the program identity string (e.g., name or description).
- Returns:
0 on success or error code on failure
-
rs_ret_val_t rcb_can_data_get_first_frame(uint8_t *ptr_can_buff)
Retrieves the first frame of CAN data.
This function retrieves the first frame of data from the CAN bus and stores it in the provided buffer.
- Parameters:
ptr_can_buff – [out] - Pointer to a buffer where the first CAN data frame will be stored.
- Returns:
0 on success or error code on failure
-
rs_ret_val_t rcb_can_data_get_second_frame(uint8_t *ptr_can_buff)
Retrieves the second frame of CAN data.
This function retrieves the second frame of data from the CAN bus and stores it in the provided buffer.
- Parameters:
ptr_can_buff – [out] - Pointer to a buffer where the second CAN data frame will be stored.
- Returns:
0 on success or error code on failure
-
rs_ret_val_t rs_mdf4_data_log(rs_mdf_config_t *ptr_config, uint8_t *ptr_can_buff, uint32_t u32_data_size)
Logs CAN data into the MDF4 system.
This function logs the provided CAN data into the MDF4 system.
- Parameters:
ptr_config – [in] - Pointer to the MDF4 configuration structure.
ptr_can_buff – [in] - Pointer to the CAN data buffer.
u32_data_size – [in] - The size of the data to log (in bytes).
- Returns:
0 on success or error code on failure
-
rs_ret_val_t rs_mdf4_default_blks(rs_mdf_config_t *ptr_config, uint8_t *ptr_buffer, size_t buffer_size)
Initializes the default blocks for MDF4 logging.
This function initializes the default data blocks for the MDF4 logging system, preparing the provided buffer with default block data.
- Parameters:
ptr_config – [in] - Pointer to the MDF4 configuration structure.
ptr_can_buff – [in] - Pointer to the buffer to hold the default blocks.
u32_data_size – [in] -The size of the buffer in bytes.
- Returns:
0 on success or error code on failure
-
struct tag_rs_dynamic_mdf_config
- #include <rs_mdf.h>
Contains information about dynamic mdf configuration.
-
struct tag_rs_mdf_config
- #include <rs_mdf.h>
Contains information about mdf configuration.
Public Members
-
rs_fatfs_t file
fatfs structure
-
uint8_t new_file
Indicates whether this is a new file.
-
uint8_t *ptr_file_name
Pointer to the file name.
-
int8_t *ptr_identity
Pointer to the identity of the mdf.
-
uint8_t file_name[RS_MAX_FILE_NAME_SIZE]
File name of the mdf.
-
uint8_t file_path[RS_MAX_FILE_PATH_SIZE]
File path of the mdf.
-
uint8_t *ptr_log_buffer
Pointer to the log buffer of the mdf.
-
uint8_t blk_index
Blk_index of the mdf.
-
uint16_t version
Version of the mdf.
-
uint32_t file_size
File size of the mdf.
-
uint32_t blk_size
Block size of the mdf.
-
uint32_t buff_size
Buffer of the mdf.
-
uint32_t write_index
Write index of the input array.
-
uint32_t frame_count
Frame count.
-
uint32_t write_file_count
Write file count.
-
uint64_t data_list_pos
Data list position.
-
uint64_t channel_pos
Channel position.
-
rs_mdf_dynamic_config_t dynamic_mdf
Dynamic MDF configuration.
-
rs_fatfs_t file