Back to Serial Studio

MDF Lib: include/mdf/mdfhelper.h Source File

lib/mdflib/docs/manual/html/mdfhelper_8h_source.html

3.2.710.5 KB
Original Source

| 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:

23static uint64_t NanoSecToLocal(uint64_t ns_since_1970);

24

30static int64_t TimeZoneOffset();

31

38static int64_t GmtOffsetNs();

39

47static int64_t DstOffsetNs();

48

55static std::string NsToLocalIsoTime(uint64_t ns_since_1970);

56

72static std::vector<uint8_t> NsToCanOpenDateArray(uint64_t ns_since_1970);

73

86static std::vector<uint8_t> NsToCanOpenTimeArray(uint64_t ns_since_1970);

87

104static uint64_t CanOpenDateArrayToNs(const std::vector<uint8_t> &buffer);

105

119static uint64_t CanOpenTimeArrayToNs(const std::vector<uint8_t> &buffer);

120

131static std::string NanoSecToDDMMYYYY(uint64_t ns_since_1970);

132

143static std::string NanoSecToHHMMSS(uint64_t ns_since_1970);

144

154static std::string NanoSecUtcToHHMMSS(uint64_t timestamp_ns);

155

165static std::string NanoSecUtcToDDMMYYYY(uint64_t timestamp_ns);

166

180static std::string NanoSecTzToHHMMSS(uint64_t timestamp_ns, int16_t tz_offset_min, int16_t dst_offset_min);

181

195static std::string NanoSecTzToDDMMYYYY(uint64_t timestamp_ns, int16_t tz_offset_min, int16_t dst_offset_min);

196

202static void Trim(std::string &text);

203

213static std::string FormatDouble(

214double value, uint8_t decimals, bool fixed = false,

215const std::string &unit = {});

216

217static uint64_t NowNs();

218

220static std::string Latin1ToUtf8(const std::string &latin1);

222static std::string Utf16ToUtf8(const std::wstring &utf16);

224static std::wstring Utf8ToUtf16(const std::string &utf8);

226static bool ComputerUseLittleEndian();

227

229static std::vector<uint8_t> TextToByteArray(const std::string& text);

230};

231

232} // namespace mdf

mdf::MdfHelper

Support class for the MDF library.

Definition mdfhelper.h:15

mdf::MdfHelper::CanOpenDateArrayToNs

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

Converts from a CANopen 7 byte Date array to nanoseconds since 1970.

mdf::MdfHelper::NowNs

static uint64_t NowNs()

Return nano-seconds since 1970.

mdf::MdfHelper::NanoSecToLocal

static uint64_t NanoSecToLocal(uint64_t ns_since_1970)

Adds the time zone offset to the time stamp.

mdf::MdfHelper::NanoSecTzToDDMMYYYY

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.

mdf::MdfHelper::ComputerUseLittleEndian

static bool ComputerUseLittleEndian()

Returns tru if this computer uses Little Endian.

mdf::MdfHelper::Latin1ToUtf8

static std::string Latin1ToUtf8(const std::string &latin1)

Converts a Latin1 string to UTF8 string.

mdf::MdfHelper::Utf16ToUtf8

static std::string Utf16ToUtf8(const std::wstring &utf16)

Converts a wide UTF16 string to an UTF8 string.

mdf::MdfHelper::NanoSecToDDMMYYYY

static std::string NanoSecToDDMMYYYY(uint64_t ns_since_1970)

Converts ns since 1970 UTC to local date DD:MM:YYYY string.

mdf::MdfHelper::FormatDouble

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

Converts a float to a string.

mdf::MdfHelper::NsToLocalIsoTime

static std::string NsToLocalIsoTime(uint64_t ns_since_1970)

Converts a nanosecond since 1970 to a local ISO date and time string.

mdf::MdfHelper::GmtOffsetNs

static int64_t GmtOffsetNs()

Returns the GMT offset in nanoseconds.

mdf::MdfHelper::NanoSecToHHMMSS

static std::string NanoSecToHHMMSS(uint64_t ns_since_1970)

Converts ns since 1970 UTC to local time HH:MM:SS string.

mdf::MdfHelper::TimeZoneOffset

static int64_t TimeZoneOffset()

return the time zone offset in seconds.

mdf::MdfHelper::NanoSecUtcToDDMMYYYY

static std::string NanoSecUtcToDDMMYYYY(uint64_t timestamp_ns)

Converts ns since 1970 UTC to UTC date in 'DD/MM/YYYY' format.

mdf::MdfHelper::Trim

static void Trim(std::string &text)

Remove white space from string.

mdf::MdfHelper::NanoSecUtcToHHMMSS

static std::string NanoSecUtcToHHMMSS(uint64_t timestamp_ns)

Converts ns since 1970 UTC to UTC time in 'HH:MM:SS' format.

mdf::MdfHelper::DstOffsetNs

static int64_t DstOffsetNs()

Returns the daylight saving time (DST) offset in nanoseconds.

mdf::MdfHelper::CanOpenTimeArrayToNs

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

Converts from a CANopen 6 byte Time array to nanoseconds since 1970.

mdf::MdfHelper::Utf8ToUtf16

static std::wstring Utf8ToUtf16(const std::string &utf8)

Converts a wide UTF8 string to an UTF16 string.

mdf::MdfHelper::TextToByteArray

static std::vector< uint8_t > TextToByteArray(const std::string &text)

Converts a text string to a byte array.

mdf::MdfHelper::NanoSecTzToHHMMSS

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.

mdf::MdfHelper::NsToCanOpenTimeArray

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

Converts from nanoseconds to CANopen 6 byte Time array.

mdf::MdfHelper::NsToCanOpenDateArray

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

Converts from nanoseconds to CANopen 7 byte Date array.

mdf

Main namespace for the MDF library.

Definition canmessage.h:17


Generated by 1.12.0