Skip to content

Commit

Permalink
fix build and add functions to dll (#50)
Browse files Browse the repository at this point in the history
* fix build in win32

* add functions of CanMessage

* fix bugs

* add functions & fix bug

* fix typo

* add some discriptions of mdflibrary

* add functions

* fix format

* fix header

* Update CMakeLists.txt

* optimize read string
  • Loading branch information
Simplxss authored Nov 30, 2023
1 parent 6d154b9 commit 7978bd8
Show file tree
Hide file tree
Showing 42 changed files with 886 additions and 1,250 deletions.
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ else()
endif()

option(MDF_BUILD_SHARED_LIB "Build shared library." ON)
option(MDF_BUILD_SHARED_LIB_NET "Build shared library with .NET." ON)
option(MDF_BUILD_SHARED_LIB_EXAMPLE "Build MdfLibrary Example." OFF)
option(MDF_BUILD_DOC "Build documentation. Requires Doxygen and Release mode." OFF)
option(MDF_BUILD_TOOL "Build tools like the MDF Viewer. Requires WxWidgets." OFF)
if(MDF_BUILD_TOOL AND VCPKG)
# Boost & wxWidgets is not available for static linking
# Boost & wxWidgets need /MT for static linking
string(REPLACE "-static" "" VCPKG_TARGET_TRIPLET "${VCPKG_TARGET_TRIPLET}")
list(APPEND VCPKG_MANIFEST_FEATURES "mdfviewer")
endif()
option(MDF_BUILD_TEST "Build Google unit tests. Requires Google Test." OFF)
if(MDF_BUILD_TEST AND VCPKG)
# GTest is not available for static linking
# GTest need /MT for static linking
string(REPLACE "-static" "" VCPKG_TARGET_TRIPLET "${VCPKG_TARGET_TRIPLET}")
list(APPEND VCPKG_MANIFEST_FEATURES "mdflibtest")
endif()
Expand All @@ -29,13 +30,13 @@ project(
VERSION 2.0
DESCRIPTION "Interface against MDF 3/4 files"
LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_DEBUG_POSTFIX d)


add_subdirectory(mdflib)

if(MDF_BUILD_SHARED_LIB)
if(NOT (MSVC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.36))
set(MDF_BUILD_SHARED_LIB_NET OFF)
endif()
add_subdirectory(mdflibrary)
endif()

Expand Down
20 changes: 0 additions & 20 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,5 @@
"install"
]
}
],
"testPresets": [
{
"name": "ninja-multi-vcpkg-x64",
"description": "Build ninja-multi-vcpkg-x64 GTest",
"displayName": "Build ninja-multi-vcpkg-x64 GTest",
"configurePreset": "ninja-multi-vcpkg-x64"
},
{
"name": "msvc-multi-vcpkg-x64",
"description": "Build msvc-multi-vcpkg-x64 GTest",
"displayName": "Build msvc-multi-vcpkg-x64 GTest",
"configurePreset": "msvc-multi-vcpkg-x64"
},
{
"name": "msvc-multi-vcpkg-x64_x86",
"description": "Build msvc-multi-vcpkg-x64_x86 GTest",
"displayName": "Build msvc-multi-vcpkg-x64_x86 GTest",
"configurePreset": "msvc-multi-vcpkg-x64_x86"
}
]
}
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,35 @@ The MDF library repository implements an interface against the ASAM Measurement
It supports reading and writing of MDF files version 3 and 4.
The release 2.0 of the project support reading and writing of MDF files up to version 4.2.

The main project is a C++ static library and its used applications.
- **MDF Viewer**. Simple GUI application that list the contents of an MDF file.
- **MDF .NET (C++/CLI) Assembly**. Basic reading of MDF files for .NET friends.
- **MDF lib** is a C++ static library.
- **MDF lib test** is a C++ unit tests application for mdflib.
- **MDF library** is a C++ shared library, and it contains .NET (C++/CLI) Assembly(need to be built with msvc>=19.36).
- **MDF library example** is a C++ application that use MDF library as dll/so.
- **MDF library test net** is a C# unit tests application that use the .NET Assembly of MDF library.
- **MDF Viewer**. Simple GUI application that list the contents of an MDF file.
- **MDF gRPC Server**. Microservice for reading and writing of MDF files. On request.
- **MDF Python Library**. Basic reading and writing for Python friends. On request or use the ASAMMDF library.

The library and its applications, compiles/runs on Windows, Linux and Mac operating system.
The .NET library only runs on Windows operating system.
The library and its applications, compiles/runs on Windows, Linux and Mac operating system.

## Installation

[Windows Install (exe)](https://github.com/ihedvall/mdflib/releases/download/v2.0.%2C0/mdflib.exe)

## Building

Most project uses CMAKE for building. But mdflibrary_test_net need to build with Visual Studio.
The project uses CMAKE for building. But mdflibrary_test_net is a Visual Studio build.

The following third-party libraries are improted by [vcpkg](https://github.com/microsoft/vcpkg).
- ZLIB Library.
- EXPAT Library.
- Boost Library. Required if the GUI applications should be built.
- WxWidgets Library. Required if the GUI applications should be built.
- Google Test Library. Is required for running and build the unit tests.
The following third-party libraries are used and needs to be downloaded and pre-built.

The following third-party application need to be downloaded by yourself.
- ZLIB Library. Set the 'ZLIB_ROOT' variable to the ZLIB root path.
- EXPAT Library. Set the 'EXPAT_ROOT' variable to the ZLIB root path.
- Boost Library. Required if the GUI applications should be built.
- WxWidgets Library. Required if the GUI applications should be built.
- Google Test Library. Is required for running and build the unit tests.
- Doxygen's application. Is required if the documentation should be built.


Also, you can use [vcpkg](https://github.com/microsoft/vcpkg) to import the dependencies.

## License

Expand Down
3 changes: 1 addition & 2 deletions include/mdf/canmessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
*/
#pragma once

#include <cstdint>
#include <vector>

#include "mdf/samplerecord.h"

namespace mdf {
Expand Down
1 change: 1 addition & 0 deletions include/mdf/ichannelgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* \brief Defines an interface against a channel group (CG) block.
*/
#pragma once
#include <algorithm>
#include <string>
#include <vector>

Expand Down
1 change: 1 addition & 0 deletions include/mdf/samplerecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
#pragma once
#include <cstdint>
#include <cstddef>
#include <vector>
namespace mdf {

Expand Down
86 changes: 86 additions & 0 deletions include/mdflibrary/CanMessage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright 2023 Simplxs
* SPDX-License-Identifier: MIT
*/
#pragma once
#include <stdexcept>
#include <vector>

#include "MdfExport.h"

using namespace MdfLibrary::ExportFunctions;

namespace MdfLibrary {
class CanMessage {
private:
mdf::CanMessage* can;

public:
CanMessage(mdf::CanMessage* can) : can(can) {
if (can == nullptr) throw std::runtime_error("MdfAttachmentInit failed");
}
~CanMessage() { can = nullptr; };

uint32_t GetMessageId() const { return CanMessageGetMessageId(can); };
void SetMessageId(uint32_t msgId) { CanMessageSetMessageId(can, msgId); };
uint32_t GetCanId() const { return CanMessageGetCanId(can); };
void SetExtendedId(bool extendedId) {
CanMessageSetExtendedId(can, extendedId);
};
bool GetExtendedId() const { return CanMessageGetExtendedId(can); };
uint8_t GetDlc() const { return CanMessageGetDlc(can); };
void SetDlc(uint8_t dlc) { CanMessageSetDlc(can, dlc); };
uint32_t GetDataLength() const { return CanMessageGetDataLength(can); };
void SetDataLength(uint32_t dataLength) {
CanMessageSetDataLength(can, dataLength);
};
std::vector<uint8_t> GetDataBytes() const {
size_t count = CanMessageGetDataBytes(can, nullptr);
if (count <= 0) return {};
auto dataList = std::vector<uint8_t>(count);
CanMessageGetDataBytes(can, dataList.data());
return dataList;
};
void SetDataBytes(const std::vector<uint8_t>& dataList) {
CanMessageSetDataBytes(can, dataList.data(), dataList.size());
};
void SetDataBytes(const uint8_t* dataList, const size_t size) {
CanMessageSetDataBytes(can, dataList, size);
};
uint64_t GetDataIndex() const { return CanMessageGetDataIndex(can); };
void SetDataIndex(const uint64_t index) {
CanMessageSetDataIndex(can, index);
};
bool GetDir() const { return CanMessageGetDir(can); };
void SetDir(const bool transmit) { CanMessageSetDir(can, transmit); };
bool GetSrr() const { return CanMessageGetSrr(can); };
void SetSrr(const bool srr) { CanMessageSetSrr(can, srr); };
bool GetEdl() const { return CanMessageGetEdl(can); };
void SetEdl(const bool edl) { CanMessageSetEdl(can, edl); };
bool GetBrs() const { return CanMessageGetBrs(can); };
void SetBrs(const bool brs) { CanMessageSetBrs(can, brs); };
bool GetEsi() const { return CanMessageGetEsi(can); };
void SetEsi(const bool esi) { CanMessageSetEsi(can, esi); };
bool GetRtr() const { return CanMessageGetRtr(can); };
void SetRtr(const bool rtr) { CanMessageSetRtr(can, rtr); };
bool GetWakeUp() const { return CanMessageGetWakeUp(can); };
void SetWakeUp(const bool wakeUp) { CanMessageSetWakeUp(can, wakeUp); };
bool GetSingleWire() const { return CanMessageGetSingleWire(can); };
void SetSingleWire(const bool singleWire) {
CanMessageSetSingleWire(can, singleWire);
};
uint8_t GetBusChannel() const { return CanMessageGetBusChannel(can); };
void SetBusChannel(const uint8_t channel) {
CanMessageSetBusChannel(can, channel);
};
uint8_t GetBitPosition() const { return CanMessageGetBitPosition(can); };
void SetBitPosition(const uint8_t position) {
CanMessageSetBitPosition(can, position);
};
CanErrorType GetErrorType() const { return CanMessageGetErrorType(can); };
void SetErrorType(const CanErrorType type) {
CanMessageSetErrorType(can, type);
};
void Reset();
};
} // namespace MdfLibrary
21 changes: 11 additions & 10 deletions include/mdflibrary/MdfAttachment.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
* SPDX-License-Identifier: MIT
*/
#pragma once
#include <string>
#include <stdexcept>

#include "MdfExport.h"
#include "MdfMetaData.h"

using namespace MdfLibrary::ExportFunctions;

Expand Down Expand Up @@ -45,22 +42,26 @@ class MdfAttachment {
return std::string(str);
}
std::string GetFileName() const {
std::string str;
str.reserve(MdfAttachmentGetFileName(attachment, nullptr) + 1);
str.resize(MdfAttachmentGetFileName(attachment, str.data()));;
std::string str(MdfAttachmentGetFileName(attachment, nullptr) + 1, '\0');
str.resize(MdfAttachmentGetFileName(attachment, str.data()));
return str;
}
void SetFileName(const char* name) {
MdfAttachmentSetFileName(attachment, name);
}
std::string GetFileType() const {
std::string str;
str.reserve(MdfAttachmentGetFileType(attachment, nullptr) + 1);
str.resize(MdfAttachmentGetFileType(attachment, str.data()));;
std::string str(MdfAttachmentGetFileType(attachment, nullptr) + 1, '\0');
str.resize(MdfAttachmentGetFileType(attachment, str.data()));
return str;
}
void SetFileType(const char* type) {
MdfAttachmentSetFileType(attachment, type);
}
const MdfMetaData GetMetaData() const {
return MdfAttachmentGetMetaData(attachment);
}
MdfMetaData CreateMetaData() {
return MdfAttachmentCreateMetaData(attachment);
}
};
} // namespace MdfLibrary
63 changes: 40 additions & 23 deletions include/mdflibrary/MdfChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,31 @@ class MdfChannel {
mdf::IChannel* GetChannel() const { return channel; }
int64_t GetIndex() const { return MdfChannelGetIndex(channel); }
std::string GetName() const {
std::string str;
str.reserve(MdfChannelGetName(channel, nullptr) + 1);
str.resize(MdfChannelGetName(channel, str.data()));;
std::string str(MdfChannelGetName(channel, nullptr) + 1, '\0');
str.resize(MdfChannelGetName(channel, str.data()));
return str;
}
void SetName(const char* name) { MdfChannelSetName(channel, name); }
std::string GetDisplayName() const {
std::string str;
str.reserve(MdfChannelGetDisplayName(channel, nullptr) + 1);
str.resize(MdfChannelGetDisplayName(channel, str.data()));;
std::string str(MdfChannelGetDisplayName(channel, nullptr) + 1, '\0');
str.resize(MdfChannelGetDisplayName(channel, str.data()));
return str;
}
void SetDisplayName(const char* name) {
MdfChannelSetDisplayName(channel, name);
}
std::string GetDescription() const {
std::string str;
str.reserve(MdfChannelGetDescription(channel, nullptr) + 1);
str.resize(MdfChannelGetDescription(channel, str.data()));;
std::string str(MdfChannelGetDescription(channel, nullptr) + 1, '\0');
str.resize(MdfChannelGetDescription(channel, str.data()));
return str;
}
void SetDescription(const char* desc) {
MdfChannelSetDescription(channel, desc);
}
bool IsUnitUsed() { return MdfChannelIsUnitUsed(channel); }
std::string GetUnit() const {
std::string str;
str.reserve(MdfChannelGetUnit(channel, nullptr) + 1);
str.resize(MdfChannelGetUnit(channel, str.data()));;
std::string str(MdfChannelGetUnit(channel, nullptr) + 1, '\0');
str.resize(MdfChannelGetUnit(channel, str.data()));
return str;
}
void SetUnit(const char* unit) { MdfChannelSetUnit(channel, unit); }
Expand All @@ -65,8 +61,8 @@ class MdfChannel {
}
uint32_t GetFlags() const { return MdfChannelGetFlags(channel); }
void SetFlags(uint32_t flags) { MdfChannelSetFlags(channel, flags); }
size_t GetDataBytes() const { return MdfChannelGetDataBytes(channel); }
void SetDataBytes(size_t bytes) { MdfChannelSetDataBytes(channel, bytes); }
uint64_t GetDataBytes() const { return MdfChannelGetDataBytes(channel); }
void SetDataBytes(uint64_t bytes) { MdfChannelSetDataBytes(channel, bytes); }
bool IsPrecisionUsed() { return MdfChannelIsPrecisionUsed(channel); }
uint8_t GetPrecision() const { return MdfChannelGetPrecision(channel); }
bool IsRangeUsed() { return MdfChannelIsRangeUsed(channel); }
Expand All @@ -88,23 +84,44 @@ class MdfChannel {
MdfChannelSetExtLimit(channel, min, max);
}
double GetSamplingRate() const { return MdfChannelGetSamplingRate(channel); }
uint64_t GetVlsdRecordId() const {
return MdfChannelGetVlsdRecordId(channel);
}
void SetVlsdRecordId(uint64_t record_id) {
MdfChannelSetVlsdRecordId(channel, record_id);
}
uint32_t GetBitCount() const { return MdfChannelGetBitCount(channel); }
void SetBitCount(uint32_t bits) { MdfChannelSetBitCount(channel, bits); }
uint16_t GetBitOffset() const { return MdfChannelGetBitOffset(channel); }
void SetBitOffset(uint16_t bits) { MdfChannelSetBitOffset(channel, bits); }
const MdfMetaData GetMetaData() const {
return MdfMetaData(MdfChannelGetMetaData(channel));
return MdfChannelGetMetaData(channel);
}
const MdfSourceInformation GetSourceInformation() const {
return MdfSourceInformation(MdfChannelGetSourceInformation(channel));
return MdfChannelGetSourceInformation(channel);
}
const MdfChannelConversion GetChannelConversion() const {
return MdfChannelConversion(MdfChannelGetChannelConversion(channel));
}
MdfMetaData CreateMetaData() {
return MdfMetaData(MdfChannelCreateMetaData(channel));
}
return MdfChannelGetChannelConversion(channel);
}
std::vector<MdfChannel> GetChannelCompositions() {
size_t count = MdfChannelGetChannelCompositions(channel, nullptr);
if (count <= 0) return {};
auto pChannels = new mdf::IChannel*[count];
MdfChannelGetChannelCompositions(channel, pChannels);
std::vector<MdfChannel> channelss;
for (size_t i = 0; i < count; i++) channelss.push_back(pChannels[i]);
delete[] pChannels;
return channelss;
}
MdfMetaData CreateMetaData() { return MdfChannelCreateMetaData(channel); }
MdfSourceInformation CreateSourceInformation() {
return MdfSourceInformation(MdfChannelCreateSourceInformation(channel));
return MdfChannelCreateSourceInformation(channel);
}
MdfChannelConversion CreateChannelConversion() {
return MdfChannelConversion(MdfChannelCreateChannelConversion(channel));
return MdfChannelCreateChannelConversion(channel);
}
MdfChannel CreateChannelComposition() {
return MdfChannelCreateChannelComposition(channel);
}
void SetChannelValue(const int64_t value, bool valid = true) {
MdfChannelSetChannelValueAsSigned(channel, value, valid);
Expand Down
Loading

0 comments on commit 7978bd8

Please sign in to comment.