MDF Lib 2.2
Interface against MDF 3/4 files
Loading...
Searching...
No Matches
mdfhelper.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 Ingemar Hedvall
3 * SPDX-License-Identifier: MIT
4 */
8#pragma once
9#include <cstdint>
10#include <string>
11#include <vector>
12
13namespace mdf {
15class MdfHelper {
16 public:
23 static uint64_t NanoSecToLocal(uint64_t ns_since_1970);
24
30 static int64_t TimeZoneOffset();
31
38 static int64_t GmtOffsetNs();
39
47 static int64_t DstOffsetNs();
48
55 static std::string NsToLocalIsoTime(uint64_t ns_since_1970);
56
72 static std::vector<uint8_t> NsToCanOpenDateArray(uint64_t ns_since_1970);
73
86 static std::vector<uint8_t> NsToCanOpenTimeArray(uint64_t ns_since_1970);
87
104 static uint64_t CanOpenDateArrayToNs(const std::vector<uint8_t> &buffer);
105
119 static uint64_t CanOpenTimeArrayToNs(const std::vector<uint8_t> &buffer);
120
131 static std::string NanoSecToDDMMYYYY(uint64_t ns_since_1970);
132
143 static std::string NanoSecToHHMMSS(uint64_t ns_since_1970);
144
154 static std::string NanoSecUtcToHHMMSS(uint64_t timestamp_ns);
155
165 static std::string NanoSecUtcToDDMMYYYY(uint64_t timestamp_ns);
166
180 static std::string NanoSecTzToHHMMSS(uint64_t timestamp_ns, int16_t tz_offset_min, int16_t dst_offset_min);
181
195 static std::string NanoSecTzToDDMMYYYY(uint64_t timestamp_ns, int16_t tz_offset_min, int16_t dst_offset_min);
196
202 static void Trim(std::string &text);
203
213 static std::string FormatDouble(
214 double value, uint8_t decimals, bool fixed = false,
215 const std::string &unit = {});
216
217 static uint64_t NowNs();
218
220 static std::string Latin1ToUtf8(const std::string &latin1);
222 static std::string Utf16ToUtf8(const std::wstring &utf16);
224 static std::wstring Utf8ToUtf16(const std::string &utf8);
227
229 static std::vector<uint8_t> TextToByteArray(const std::string& text);
230};
231
232} // namespace mdf
Support class for the MDF library.
Definition mdfhelper.h:15
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 NowNs()
Return nano-seconds since 1970.
static uint64_t NanoSecToLocal(uint64_t ns_since_1970)
Adds the time zone offset to the time stamp.
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 bool ComputerUseLittleEndian()
Returns tru if this computer uses Little Endian.
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::string NanoSecToDDMMYYYY(uint64_t ns_since_1970)
Converts ns since 1970 UTC to local date DD:MM:YYYY string.
static std::string FormatDouble(double value, uint8_t decimals, bool fixed=false, const std::string &unit={})
Converts a float to a string.
static std::string NsToLocalIsoTime(uint64_t ns_since_1970)
Converts a nanosecond since 1970 to a local ISO date and time string.
static int64_t GmtOffsetNs()
Returns the GMT offset in nanoseconds.
static std::string NanoSecToHHMMSS(uint64_t ns_since_1970)
Converts ns since 1970 UTC to local time HH:MM:SS string.
static int64_t TimeZoneOffset()
return the time zone offset in seconds.
static std::string NanoSecUtcToDDMMYYYY(uint64_t timestamp_ns)
Converts ns since 1970 UTC to UTC date in 'DD/MM/YYYY' format.
static void Trim(std::string &text)
Remove white space from string.
static std::string NanoSecUtcToHHMMSS(uint64_t timestamp_ns)
Converts ns since 1970 UTC to UTC time in 'HH:MM:SS' format.
static int64_t DstOffsetNs()
Returns the daylight saving time (DST) offset in nanoseconds.
static uint64_t CanOpenTimeArrayToNs(const std::vector< uint8_t > &buffer)
Converts from a CANopen 6 byte Time array to nanoseconds since 1970.
static std::wstring Utf8ToUtf16(const std::string &utf8)
Converts a wide UTF8 string to an UTF16 string.
static std::vector< uint8_t > TextToByteArray(const std::string &text)
Converts a text string to a byte array.
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::vector< uint8_t > NsToCanOpenTimeArray(uint64_t ns_since_1970)
Converts from nanoseconds to CANopen 6 byte Time array.
static std::vector< uint8_t > NsToCanOpenDateArray(uint64_t ns_since_1970)
Converts from nanoseconds to CANopen 7 byte Date array.
Main namespace for the MDF library.
Definition canmessage.h:17