Skip to content

Commit

Permalink
add example for can message
Browse files Browse the repository at this point in the history
  • Loading branch information
Simplxss committed Jan 12, 2024
1 parent eaa3ed6 commit 9c7a6fe
Show file tree
Hide file tree
Showing 24 changed files with 173 additions and 77 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
workflow_dispatch:

env:
vcpkgCommitId: c8696863d371ab7f46e213d8f5ca923c4aef2a00
vcpkgCommitId: c9140a3b500812ad3206317885860d9553b93f13


jobs:
Expand Down Expand Up @@ -69,6 +69,7 @@
# the project files. This configuration leverages the vcpkg.cmake toolchain file to
# run vcpkg and install all dependencies specified in vcpkg.json.
configurePreset: 'msvc-vcpkg-static-${{ matrix.arch }}'
configurePresetAdditionalArgs: "['-DMDF_BUILD_SHARED_LIB_NET=ON']"

# This is the name of the CMakePresets.json's configuration to build the project.
buildPreset: 'msvc-vcpkg-static-${{ matrix.arch }}-release'
Expand All @@ -85,7 +86,7 @@
# the project files. This configuration leverages the vcpkg.cmake toolchain file to
# run vcpkg and install all dependencies specified in vcpkg.json.
configurePreset: 'msvc-vcpkg-${{ matrix.arch }}'
configurePresetAdditionalArgs: "['-DMDF_BUILD_TEST=ON']"
configurePresetAdditionalArgs: "['-DMDF_BUILD_SHARED_LIB_NET=ON', '-DMDF_BUILD_TEST=ON', '-DMDF_BUILD_SHARED_LIB_EXAMPLE=ON', '-DMDF_BUILD_TOOL=ON']"

# This is the name of the CMakePresets.json's configuration to build the project.
buildPreset: 'msvc-vcpkg-${{ matrix.arch }}-debug'
Expand Down Expand Up @@ -153,7 +154,7 @@
# the project files. This configuration leverages the vcpkg.cmake toolchain file to
# run vcpkg and install all dependencies specified in vcpkg.json.
configurePreset: 'ninja-vcpkg-${{ matrix.arch }}'
configurePresetAdditionalArgs: "['-DMDF_BUILD_TEST=ON']"
configurePresetAdditionalArgs: "['-DMDF_BUILD_TEST=ON', '-DMDF_BUILD_SHARED_LIB_EXAMPLE=ON']"

# This is the name of the CMakePresets.json's configuration to build the project.
buildPreset: 'ninja-vcpkg-${{ matrix.arch }}-release'
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ 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_NET "Build shared library with .NET." OFF) # Only for MSVC 19.36+
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)
Expand Down
19 changes: 16 additions & 3 deletions include/mdflibrary/CanMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,27 @@ using namespace MdfLibrary::ExportFunctions;
namespace MdfLibrary {
class CanMessage {
private:
bool isNew = false;
mdf::CanMessage* can;

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

CanMessage() : CanMessage(CanMessageInit()) { isNew = true; };
~CanMessage() {
if (isNew) CanMessageUnInit(can);
can = nullptr;
};
CanMessage(const CanMessage&) = delete;
CanMessage(CanMessage&& can) {
if (isNew) CanMessageUnInit(this->can);
this->isNew = can.isNew;
this->can = can.can;
can.isNew = false;
can.can = nullptr;
}
mdf::CanMessage* GetCanMessage() const { return can; }
uint32_t GetMessageId() const { return CanMessageGetMessageId(can); };
void SetMessageId(uint32_t msgId) { CanMessageSetMessageId(can, msgId); };
uint32_t GetCanId() const { return CanMessageGetCanId(can); };
Expand Down
2 changes: 1 addition & 1 deletion include/mdflibrary/MdfAttachment.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MdfAttachment {
public:
MdfAttachment(mdf::IAttachment* attachment) : attachment(attachment) {
if (attachment == nullptr)
throw std::runtime_error("MdfAttachmentInit failed");
throw std::runtime_error("MdfAttachment Init failed");
}
MdfAttachment(const mdf::IAttachment* attachment)
: MdfAttachment(const_cast<mdf::IAttachment*>(attachment)) {}
Expand Down
2 changes: 1 addition & 1 deletion include/mdflibrary/MdfChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MdfChannel {

public:
MdfChannel(mdf::IChannel* channel) : channel(channel) {
if (channel == nullptr) throw std::runtime_error("MdfChannelInit failed");
if (channel == nullptr) throw std::runtime_error("MdfChannel Init failed");
}
MdfChannel(const mdf::IChannel* channel)
: MdfChannel(const_cast<mdf::IChannel*>(channel)) {}
Expand Down
2 changes: 1 addition & 1 deletion include/mdflibrary/MdfChannelConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MdfChannelConversion {
MdfChannelConversion(mdf::IChannelConversion* conversion)
: conversion(conversion) {
if (conversion == nullptr)
throw std::runtime_error("MdfChannelConversionInit failed");
throw std::runtime_error("MdfChannelConversion Init failed");
}
MdfChannelConversion(const mdf::IChannelConversion* conversion)
: MdfChannelConversion(const_cast<mdf::IChannelConversion*>(conversion)) {
Expand Down
2 changes: 1 addition & 1 deletion include/mdflibrary/MdfChannelGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MdfChannelGroup {
public:
MdfChannelGroup(mdf::IChannelGroup* group) : group(group) {
if (group == nullptr)
throw std::runtime_error("MdfChannelGroupInit failed");
throw std::runtime_error("MdfChannelGroup Init failed");
}
MdfChannelGroup(const mdf::IChannelGroup* group)
: MdfChannelGroup(const_cast<mdf::IChannelGroup*>(group)) {}
Expand Down
2 changes: 1 addition & 1 deletion include/mdflibrary/MdfChannelObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MdfChannelObserver {
public:
MdfChannelObserver(mdf::IChannelObserver* observer) : observer(observer) {
if (observer == nullptr)
throw std::runtime_error("MdfChannelObserverInit failed");
throw std::runtime_error("MdfChannelObserver Init failed");
}
MdfChannelObserver(const mdf::IChannelObserver* observer)
: MdfChannelObserver(const_cast<mdf::IChannelObserver*>(observer)) {}
Expand Down
9 changes: 7 additions & 2 deletions include/mdflibrary/MdfDataGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MdfDataGroup {

public:
MdfDataGroup(mdf::IDataGroup* group) : group(group) {
if (group == nullptr) throw std::runtime_error("MdfDataGroupInit failed");
if (group == nullptr) throw std::runtime_error("MdfDataGroup Init failed");
}
MdfDataGroup(const mdf::IDataGroup* group)
: MdfDataGroup(const_cast<mdf::IDataGroup*>(group)) {}
Expand All @@ -30,6 +30,12 @@ class MdfDataGroup {
const MdfMetaData GetMetaData() const {
return MdfDataGroupGetMetaData(group);
}
MdfChannelGroup GetChannelGroup(const std::string name) const {
return MdfDataGroupGetChannelGroupByName(group, name.c_str());
}
MdfChannelGroup GetChannelGroup(uint64_t record_id) const {
return MdfDataGroupGetChannelGroupByRecordId(group, record_id);
}
std::vector<MdfChannelGroup> GetChannelGroups() const {
size_t count = MdfDataGroupGetChannelGroups(group, nullptr);
if (count <= 0) return {};
Expand All @@ -49,6 +55,5 @@ class MdfDataGroup {
const MdfChannelGroup FindParentChannelGroup(MdfChannel channel) {
return MdfDataGroupFindParentChannelGroup(group, channel.GetChannel());
}
void ResetSample() { MdfDataGroupResetSample(group); }
};
} // namespace MdfLibrary
13 changes: 8 additions & 5 deletions include/mdflibrary/MdfETag.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* SPDX-License-Identifier: MIT
*/
#pragma once
#include <string>
#include <stdexcept>
#include <string>

#include "MdfExport.h"

Expand All @@ -13,22 +13,25 @@ using namespace MdfLibrary::ExportFunctions;
namespace MdfLibrary {
class MdfETag {
private:
bool isNew = false;
mdf::ETag* eTag;

public:
MdfETag(mdf::ETag* eTag) : eTag(eTag) {
if (eTag == nullptr) throw std::runtime_error("MdfETagInit failed");
if (eTag == nullptr) throw std::runtime_error("MdfETag Init failed");
}
MdfETag(const mdf::ETag* eTag) : MdfETag(const_cast<mdf::ETag*>(eTag)) {}
MdfETag() : MdfETag(MdfETagInit()) {}
MdfETag() : MdfETag(MdfETagInit()) { isNew = true; }
~MdfETag() {
if (eTag == nullptr) return;
MdfETagUnInit(eTag);
if (isNew) MdfETagUnInit(eTag);
eTag = nullptr;
}
MdfETag(const MdfETag&) = delete;
MdfETag(MdfETag&& eTag) {
if (isNew) MdfETagUnInit(this->eTag);
this->isNew = eTag.isNew;
this->eTag = eTag.eTag;
eTag.isNew = false;
eTag.eTag = nullptr;
}
mdf::ETag* GetETag() const { return eTag; }
Expand Down
2 changes: 1 addition & 1 deletion include/mdflibrary/MdfEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MdfEvent {

public:
MdfEvent(mdf::IEvent* event) : event(event) {
if (event == nullptr) throw std::runtime_error("MdfEventInit failed");
if (event == nullptr) throw std::runtime_error("MdfEvent Init failed");
}
MdfEvent(const mdf::IEvent* event)
: MdfEvent(const_cast<mdf::IEvent*>(event)) {}
Expand Down
16 changes: 13 additions & 3 deletions include/mdflibrary/MdfExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,12 @@ EXPORTFEATUREFUNC(MdfStorageType, GetStorageType);
EXPORTFEATUREFUNC(void, SetStorageType, MdfStorageType type);
EXPORTFEATUREFUNC(uint32_t, GetMaxLength);
EXPORTFEATUREFUNC(void, SetMaxLength, uint32_t length);
EXPORTFEATUREFUNC(bool, CreateBusLogConfiguration);
EXPORTFEATUREFUNC(mdf::IDataGroup*, CreateDataGroup);
EXPORTFEATUREFUNC(bool, InitMeasurement);
EXPORTFEATUREFUNC(void, SaveSample, mdf::IChannelGroup* group, uint64_t time);
EXPORTFEATUREFUNC(void, SaveCanMessage, mdf::IChannelGroup* group,
uint64_t time, mdf::CanMessage* message);
EXPORTFEATUREFUNC(void, StartMeasurement, uint64_t start_time);
EXPORTFEATUREFUNC(void, StopMeasurement, uint64_t stop_time);
EXPORTFEATUREFUNC(bool, FinalizeMeasurement);
Expand Down Expand Up @@ -479,14 +482,16 @@ EXPORTFEATUREFUNC(void, SetStartAngle, double angle);
EXPORTFEATUREFUNC(bool, IsStartDistanceUsed);
EXPORTFEATUREFUNC(double, GetStartDistance);
EXPORTFEATUREFUNC(void, SetStartDistance, double distance);
EXPORTFEATUREFUNC(const mdf::IMetaData*, GetMetaDatas);
EXPORTFEATUREFUNC(const mdf::IMetaData*, GetMetaData);
EXPORTFEATUREFUNC(size_t, GetAttachments, mdf::IAttachment* pAttachments[]);
EXPORTFEATUREFUNC(size_t, GetFileHistorys, mdf::IFileHistory* pFileHistorys[]);
EXPORTFEATUREFUNC(size_t, GetEvents, mdf::IEvent* pEvents[]);
EXPORTFEATUREFUNC(size_t, GetDataGroups, mdf::IDataGroup* pDataGroups[]);
EXPORTFEATUREFUNC(mdf::IDataGroup*, GetLastDataGroup);
EXPORTFEATUREFUNC(mdf::IMetaData*, CreateMetaData);
EXPORTFEATUREFUNC(mdf::IAttachment*, CreateAttachment);
EXPORTFEATUREFUNC(mdf::IFileHistory*, CreateFileHistory);
#undef CreateEvent
#undef CreateEvent // **** Microsoft !!
EXPORTFEATUREFUNC(mdf::IEvent*, CreateEvent);
EXPORTFEATUREFUNC(mdf::IDataGroup*, CreateDataGroup);
#undef EXPORTFEATUREFUNC
Expand All @@ -500,14 +505,17 @@ EXPORTFEATUREFUNC(int64_t, GetIndex);
EXPORTFEATUREFUNC(size_t, GetDescription, char* description);
EXPORTFEATUREFUNC(uint8_t, GetRecordIdSize);
EXPORTFEATUREFUNC(const mdf::IMetaData*, GetMetaData);
EXPORTFEATUREFUNC(mdf::IChannelGroup*, GetChannelGroupByName,
const char* name);
EXPORTFEATUREFUNC(mdf::IChannelGroup*, GetChannelGroupByRecordId,
uint64_t record_id);
EXPORTFEATUREFUNC(size_t, GetChannelGroups,
mdf::IChannelGroup* pChannelGroups[]);
EXPORTFEATUREFUNC(bool, IsRead);
EXPORTFEATUREFUNC(mdf::IMetaData*, CreateMetaData);
EXPORTFEATUREFUNC(mdf::IChannelGroup*, CreateChannelGroup);
EXPORTFEATUREFUNC(const mdf::IChannelGroup*, FindParentChannelGroup,
const mdf::IChannel* channel);
EXPORTFEATUREFUNC(void, ResetSample);
#undef EXPORTFEATUREFUNC
#pragma endregion

Expand Down Expand Up @@ -836,8 +844,10 @@ EXPORTFEATUREFUNC(void, AddCommonProperty, mdf::ETag* tag);
#pragma endregion

#pragma region mdf::CanMessage
EXPORT(mdf::CanMessage*, CanMessage, Init);
#define EXPORTFEATUREFUNC(ReturnType, FuncName, ...) \
EXPORT(ReturnType, CanMessage, FuncName, mdf::CanMessage* can, ##__VA_ARGS__)
EXPORTFEATUREFUNC(void, UnInit);
EXPORTFEATUREFUNC(uint32_t, GetMessageId);
EXPORTFEATUREFUNC(void, SetMessageId, const uint32_t msgId);
EXPORTFEATUREFUNC(uint32_t, GetCanId);
Expand Down
2 changes: 1 addition & 1 deletion include/mdflibrary/MdfFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MdfFile {

public:
MdfFile(mdf::MdfFile* file) : file(file) {
if (file == nullptr) throw std::runtime_error("MdfFileInit failed");
if (file == nullptr) throw std::runtime_error("MdfFile Init failed");
}
MdfFile(const mdf::MdfFile* file)
: MdfFile(const_cast<mdf::MdfFile*>(file)) {}
Expand Down
2 changes: 1 addition & 1 deletion include/mdflibrary/MdfFileHistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MdfFileHistory {
public:
MdfFileHistory(mdf::IFileHistory* history) : history(history) {
if (history == nullptr)
throw std::runtime_error("MdfFileHistoryInit failed");
throw std::runtime_error("MdfFileHistory Init failed");
}
MdfFileHistory(const mdf::IFileHistory* history)
: MdfFileHistory(const_cast<mdf::IFileHistory*>(history)) {}
Expand Down
8 changes: 5 additions & 3 deletions include/mdflibrary/MdfHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MdfHeader {

public:
MdfHeader(mdf::IHeader* header) : header(header) {
if (header == nullptr) throw std::runtime_error("MdfHeaderInit failed");
if (header == nullptr) throw std::runtime_error("MdfHeader Init failed");
}
MdfHeader(const mdf::IHeader* header)
: MdfHeader(const_cast<mdf::IHeader*>(header)) {}
Expand Down Expand Up @@ -84,8 +84,8 @@ class MdfHeader {
void SetStartDistance(double distance) {
MdfHeaderSetStartDistance(header, distance);
}
const MdfMetaData GetMetaDatas() const {
return MdfHeaderGetMetaDatas(header);
const MdfMetaData GetMetaData() const {
return MdfHeaderGetMetaData(header);
}
std::vector<MdfAttachment> GetAttachments() const {
size_t count = MdfHeaderGetAttachments(header, nullptr);
Expand Down Expand Up @@ -127,6 +127,8 @@ class MdfHeader {
delete[] pDataGroups;
return dataGroups;
}
MdfDataGroup GetLastDataGroup() { return MdfHeaderGetLastDataGroup(header); }
MdfMetaData CreateMetaData() { return MdfHeaderCreateMetaData(header); }
MdfAttachment CreateAttachment() { return MdfHeaderCreateAttachment(header); }
MdfFileHistory CreateFileHistory() {
return MdfHeaderCreateFileHistory(header);
Expand Down
6 changes: 3 additions & 3 deletions include/mdflibrary/MdfMetaData.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MdfMetaData {

public:
MdfMetaData(mdf::IMetaData* metaData) : metaData(metaData) {
if (metaData == nullptr) throw std::runtime_error("MdfMetaDataInit failed");
if (metaData == nullptr) throw std::runtime_error("MdfMetaData Init failed");
}
MdfMetaData(const mdf::IMetaData* metaData)
: MdfMetaData(const_cast<mdf::IMetaData*>(metaData)) {}
Expand Down Expand Up @@ -55,7 +55,7 @@ class MdfMetaData {
delete[] pTags;
return tags;
}
void SetCommonProperties(std::vector<MdfETag> pProperty, size_t count) {
void SetCommonProperties(const std::vector<MdfETag> pProperty, size_t count) {
auto pTags = new const mdf::ETag*[count];
for (size_t i = 0; i < count; i++) pTags[i] = pProperty[i].GetETag();
MdfMetaDataSetCommonProperties(metaData, pTags, count);
Expand All @@ -69,7 +69,7 @@ class MdfMetaData {
void SetXmlSnippet(const char* xml) {
MdfMetaDataSetXmlSnippet(metaData, xml);
}
void AddCommonProperty(MdfETag tag) {
void AddCommonProperty(const MdfETag &tag) {
MdfMetaDataAddCommonProperty(metaData, tag.GetETag());
}
};
Expand Down
2 changes: 1 addition & 1 deletion include/mdflibrary/MdfReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MdfReader {

public:
MdfReader(const char* filename) : reader(MdfReaderInit(filename)) {
if (reader == nullptr) throw std::runtime_error("MdfReaderInit failed");
if (reader == nullptr) throw std::runtime_error("MdfReader Init failed");
}
~MdfReader() {
if (reader == nullptr) return;
Expand Down
2 changes: 1 addition & 1 deletion include/mdflibrary/MdfSourceInformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MdfSourceInformation {
MdfSourceInformation(mdf::ISourceInformation* sourceInformation)
: sourceInformation(sourceInformation) {
if (sourceInformation == nullptr)
throw std::runtime_error("MdfSourceInformationInit failed");
throw std::runtime_error("MdfSourceInformation Init failed");
}
MdfSourceInformation(const mdf::ISourceInformation* sourceInformation)
: MdfSourceInformation(
Expand Down
9 changes: 7 additions & 2 deletions include/mdflibrary/MdfWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
#pragma once
#include "MdfFile.h"
#include "CanMessage.h"

using namespace MdfLibrary::ExportFunctions;

Expand All @@ -15,7 +16,7 @@ class MdfWriter {
public:
MdfWriter(MdfWriterType type, const char* filename)
: writer(MdfWriterInit(type, filename)) {
if (writer == nullptr) throw std::runtime_error("MdfWriterInit failed");
if (writer == nullptr) throw std::runtime_error("MdfWriter Init failed");
}
~MdfWriter() {
if (writer == nullptr) return;
Expand Down Expand Up @@ -46,13 +47,17 @@ class MdfWriter {
}
uint32_t GetMaxLength() const { return MdfWriterGetMaxLength(writer); }
void SetMaxLength(uint32_t length) { MdfWriterSetMaxLength(writer, length); }
bool CreateBusLogConfiguration() { return MdfWriterCreateBusLogConfiguration(writer); }
MdfDataGroup CreateDataGroup() {
return MdfDataGroup(MdfWriterCreateDataGroup(writer));
}
bool InitMeasurement() { return MdfWriterInitMeasurement(writer); }
void SaveSample(MdfChannelGroup group, uint64_t time) {
MdfWriterSaveSample(writer, group.GetChannelGroup(), time);
}
void SaveCanMessage(const MdfChannelGroup group, uint64_t time, const CanMessage& msg) {
MdfWriterSaveCanMessage(writer, group.GetChannelGroup(), time, msg.GetCanMessage());
}
bool InitMeasurement() { return MdfWriterInitMeasurement(writer); }
void StartMeasurement(uint64_t start_time) {
MdfWriterStartMeasurement(writer, start_time);
}
Expand Down
Loading

0 comments on commit 9c7a6fe

Please sign in to comment.