MDF Lib 2.2
Interface against MDF 3/4 files
Loading...
Searching...
No Matches
mdf::MdfHelper Class Reference

Support class for the MDF library.

#include <mdfhelper.h>

Static Public Member Functions

static uint64_t NanoSecToLocal (uint64_t ns_since_1970)
 Adds the time zone offset to the time stamp.
 
static int64_t TimeZoneOffset ()
 return the time zone offset in seconds.
 
static int64_t GmtOffsetNs ()
 Returns the GMT offset in nanoseconds.
 
static int64_t DstOffsetNs ()
 Returns the daylight saving time (DST) offset in nanoseconds.
 
static std::string NsToLocalIsoTime (uint64_t ns_since_1970)
 Converts a nanosecond since 1970 to a local ISO date and time string.
 
static std::vector< uint8_t > NsToCanOpenDateArray (uint64_t ns_since_1970)
 Converts from nanoseconds to CANopen 7 byte Date array.
 
static std::vector< uint8_t > NsToCanOpenTimeArray (uint64_t ns_since_1970)
 Converts from nanoseconds to CANopen 6 byte Time array.
 
static uint64_t CanOpenDateArrayToNs (const std::vector< uint8_t > &buffer)
 Converts from a CANopen 7 byte Date array to nanoseconds since 1970.
 
static uint64_t CanOpenTimeArrayToNs (const std::vector< uint8_t > &buffer)
 Converts from a CANopen 6 byte Time array to nanoseconds since 1970.
 
static std::string NanoSecToDDMMYYYY (uint64_t ns_since_1970)
 Converts ns since 1970 UTC to local date DD:MM:YYYY string.
 
static std::string NanoSecToHHMMSS (uint64_t ns_since_1970)
 Converts ns since 1970 UTC to local time HH:MM:SS string.
 
static std::string NanoSecUtcToHHMMSS (uint64_t timestamp_ns)
 Converts ns since 1970 UTC to UTC time in 'HH:MM:SS' format.
 
static std::string NanoSecUtcToDDMMYYYY (uint64_t timestamp_ns)
 Converts ns since 1970 UTC to UTC date in 'DD/MM/YYYY' format.
 
static std::string NanoSecTzToHHMMSS (uint64_t timestamp_ns, int16_t tz_offset_min, int16_t dst_offset_min)
 Converts ns since 1970 UTC to a time string in 'HH:MM:SS' format in a specified timezone.
 
static std::string NanoSecTzToDDMMYYYY (uint64_t timestamp_ns, int16_t tz_offset_min, int16_t dst_offset_min)
 Converts ns since 1970 UTC to a date string in 'DD/MM/YYYY' format in a specified timezone.
 
static void Trim (std::string &text)
 Remove white space from string.
 
static std::string FormatDouble (double value, uint8_t decimals, bool fixed=false, const std::string &unit={})
 Converts a float to a string.
 
static uint64_t NowNs ()
 Return nano-seconds since 1970.
 
static std::string Latin1ToUtf8 (const std::string &latin1)
 Converts a Latin1 string to UTF8 string.
 
static std::string Utf16ToUtf8 (const std::wstring &utf16)
 Converts a wide UTF16 string to an UTF8 string.
 
static std::wstring Utf8ToUtf16 (const std::string &utf8)
 Converts a wide UTF8 string to an UTF16 string.
 
static bool ComputerUseLittleEndian ()
 Returns tru if this computer uses Little Endian.
 
static std::vector< uint8_t > TextToByteArray (const std::string &text)
 Converts a text string to a byte array.
 

Member Function Documentation

◆ CanOpenDateArrayToNs()

static uint64_t mdf::MdfHelper::CanOpenDateArrayToNs ( const std::vector< uint8_t > & buffer)
static

Converts from 7 byte CANopen date array to a uint64_t nanoseconds since

  1. This format is used in CANopen protocol and in ASAM MDF files.

7-byte CANopen date format:

  • uint16_t Milliseconds since last minute
  • uint8_t Minute (0..59)
  • uint8_t Hour (0..23)
  • uint8_t Day in month (1..31) + Day in week (1 = Monday..7 = Sunday)
  • uint8_t Month (1..12)
  • uint8_t Year (0..99)
    Parameters
    [in]buffer7-byte CANopen date array
    Returns
    Nanoseconds since 1970-01-01

◆ CanOpenTimeArrayToNs()

static uint64_t mdf::MdfHelper::CanOpenTimeArrayToNs ( const std::vector< uint8_t > & buffer)
static

Converts from nanoseconds since 1970-01-01 to a 6-byte CANopen time array This format is used in CANopen protocol and in ASAM MDF files.

6-byte CANopen time format:

  • uint32_t Milliseconds since midnight
  • uint16_t Days since 1984
Parameters
[in]buffer6-byte CANopen time array
Returns
Nanoseconds since 1970-01-01

◆ DstOffsetNs()

static int64_t mdf::MdfHelper::DstOffsetNs ( )
static

This function returns the current daylight saving time (DST) offset in nanoseconds.

Returns
DST offset in nanoseconds.

◆ FormatDouble()

static std::string mdf::MdfHelper::FormatDouble ( double value,
uint8_t decimals,
bool fixed = false,
const std::string & unit = {} )
static

Converts a floating point value to a string using number of decimals.
It also fix rounding and returning a fixed decimals. Presenting fixed number of decimals means that it fills up the string with '0' characters.
Example: Value: 1.23 and decimals 3,String: (Fixed = false) "1.23" (Fixed = true) "1.230"
Optional it can append a unit to the string (Example: "1.23 m/s").

Parameters
[in]valueThe floating point value.
[in]decimalsMax number of decimals.
[in]fixedIf it should show fixed number of decimals.
[in]unitAppends a unit string to the output.
Returns
The formatted string.

◆ GmtOffsetNs()

static int64_t mdf::MdfHelper::GmtOffsetNs ( )
static

This function returns the current GMT offset in nanoseconds.

Returns
GMT offset in nanoseconds.

◆ NanoSecToDDMMYYYY()

static std::string mdf::MdfHelper::NanoSecToDDMMYYYY ( uint64_t ns_since_1970)
static

Generates a local date string with the 'DD:MM:YYYY' format, from an UTC time stamp nanoseconds since 1970-01-01 (midnight). The nanosecond timestamp is commonly used when transfer a timestamp. Note that this may not be used as epoch in different internal clocks.

Parameters
[in]ns_since_1970Nanoseconds since 1970 UTC
Returns
Local date format 'DD:MM:YYYY'

◆ NanoSecToHHMMSS()

static std::string mdf::MdfHelper::NanoSecToHHMMSS ( uint64_t ns_since_1970)
static

Generates a local time string with the 'HH:MM:ss' format, from an UTC time stamp nanoseconds since 1970-01-01 (midnight). The nanosecond timestamp is commonly used when transfer a timestamp. Note that this may not be used as epoch in different internal clocks.

Parameters
[in]ns_since_1970Nanoseconds since 1970 UTC
Returns
Local date format 'HH:MM:SS'

◆ NanoSecToLocal()

static uint64_t mdf::MdfHelper::NanoSecToLocal ( uint64_t ns_since_1970)
static

Adds the time zone offset and dst to the UTC nanoseconds since 1970.

Parameters
[in]ns_since_1970Nano-seconds since 1970
Returns
local time = system time + time zone offset

◆ NanoSecTzToDDMMYYYY()

static std::string mdf::MdfHelper::NanoSecTzToDDMMYYYY ( uint64_t timestamp_ns,
int16_t tz_offset_min,
int16_t dst_offset_min )
static

Generates a date string in the 'DD/MM/YYYY' format based on a timestamp representing nanoseconds since 1970-01-01 (midnight) UTC, adjusted for a specified timezone and daylight saving time (DST) offset. This function is useful for converting a high-precision timestamp into a human-readable date in a specific timezone.

Parameters
[in]timestamp_nsNanoseconds since 1970 UTC.
[in]tz_offset_minTimezone offset in minutes from UTC.
[in]dst_offset_minDaylight saving time (DST) offset in minutes.
Returns
Date format 'DD/MM/YYYY' adjusted for the specified timezone and DST offset.

◆ NanoSecTzToHHMMSS()

static std::string mdf::MdfHelper::NanoSecTzToHHMMSS ( uint64_t timestamp_ns,
int16_t tz_offset_min,
int16_t dst_offset_min )
static

Generates a time string in the 'HH:MM:SS' format based on a timestamp representing nanoseconds since 1970-01-01 (midnight) UTC, adjusted for a specified timezone and daylight saving time (DST) offset. This function is useful for converting a high-precision timestamp into a human-readable time in a specific timezone.

Parameters
[in]timestamp_nsNanoseconds since 1970 UTC.
[in]tz_offset_minTimezone offset in minutes from UTC.
[in]dst_offset_minDaylight saving time (DST) offset in minutes.
Returns
Time format 'HH:MM:SS' adjusted for the specified timezone and DST offset.

◆ NanoSecUtcToDDMMYYYY()

static std::string mdf::MdfHelper::NanoSecUtcToDDMMYYYY ( uint64_t timestamp_ns)
static

Generates a UTC date string in the 'DD/MM/YYYY' format from a timestamp representing nanoseconds since 1970-01-01 (midnight) UTC. This function is useful for converting a high-precision timestamp into a human-readable date in UTC.

Parameters
[in]timestamp_nsNanoseconds since 1970 UTC.
Returns
UTC date format 'DD/MM/YYYY'.

◆ NanoSecUtcToHHMMSS()

static std::string mdf::MdfHelper::NanoSecUtcToHHMMSS ( uint64_t timestamp_ns)
static

Generates a UTC time string in the 'HH:MM:SS' format from a timestamp representing nanoseconds since 1970-01-01 (midnight) UTC. This is useful for converting a high-precision timestamp to a human-readable time format in UTC.

Parameters
[in]timestamp_nsNanoseconds since 1970 UTC.
Returns
UTC time format 'HH:MM:SS'.

◆ NsToCanOpenDateArray()

static std::vector< uint8_t > mdf::MdfHelper::NsToCanOpenDateArray ( uint64_t ns_since_1970)
static

Converts from nanoseconds since 1970-01-01 to a 7 byte CANopen date array This format is used in CANopen protocol and in ASAM MDF files.

7-byte CANopen date format:

  • uint16_t Milliseconds since last minute
  • uint8_t Minute (0..59)
  • uint8_t Hour (0..23)
  • uint8_t Day in month (1..31) + Day in week (1 = Monday..7 = Sunday)
  • uint8_t Month (1..12)
  • uint8_t Year (0..99)
    Parameters
    [in]ns_since_1970Nanoseconds since 1970-01-01
    Returns
    7-byte CANopen date array

◆ NsToCanOpenTimeArray()

static std::vector< uint8_t > mdf::MdfHelper::NsToCanOpenTimeArray ( uint64_t ns_since_1970)
static

Converts from nanoseconds since 1970-01-01 to a 6-byte CANopen time array This format is used in CANopen protocol and in ASAM MDF files.

6-byte CANopen time format:

  • uint32_t Milliseconds since midnight
  • uint16_t Days since 1984
Parameters
[in]ns_since_1970Nanoseconds since 1970-01-01
Returns
6-byte CANopen date array

◆ NsToLocalIsoTime()

static std::string mdf::MdfHelper::NsToLocalIsoTime ( uint64_t ns_since_1970)
static
Parameters
[in]ns_since_1970Nanosecond since 1970
Returns
Return a date and time string in format YYYY-MM-DD hh:mm:ss.ms

◆ TimeZoneOffset()

static int64_t mdf::MdfHelper::TimeZoneOffset ( )
static

Returns the current used time zone offset in seconds

Returns
Time offset in seconds

◆ Trim()

static void mdf::MdfHelper::Trim ( std::string & text)
static

Removes white spaces from the begin and end of the string

Parameters
textString to trim

The documentation for this class was generated from the following file: