ihedvall / mdflib

Implementation of the ASAM MDF data file.
https://ihedvall.github.io/mdflib/
MIT License
57 stars 25 forks source link

MimeStream and MimeStream handling need to be corrected. #46

Closed songjmcn closed 7 months ago

songjmcn commented 7 months ago

Hello developers: I found a bug when I using this library. I use this library to read byte array from MF4 file, this library return error array length. I review the code and find read the data using wrong function. I change the ichannelobserver.cpp as follow: Xnip2023-11-23_14-31-13 This code can work correct.

ihedvall commented 7 months ago

Yes you are right. This function are missing a lot of functionality as string to byte array handling (see also the GetChannelValue() function.

To be honest, I never figure out what type of data this MimeStream and MimeSample are. Currently it is treated as string but this can be wrong. Some research might be needed.

ihedvall commented 7 months ago

There is an underlying problen with the storage of MimeSample and MimeStream channels. I need to fix this. I assign this bug to me and fix it ASAP.

jezzzzza commented 7 months ago

Hi, i think i have a similar problem. Im trying to save this as byte array in the example (test.cpp).

Saving strings works though..

const char* str =
          "testkslflkshd/0fkhslkdfhlksdhflkhsdlkfasdiadslöasjdjäaäsfhpoaihüoahsfd"
          "üoasgüogoüahgpon<psonfd0934htß92hß0h0)?=$?W=&UI&?=AOSNPAsdp0ßj#+#+"
          "üasf";

      channels[5].SetChannelValue(str);

      // Example data to be sent to the channel
      uint8_t data[] = {10, 20, 30, 40, 50, 0, 124, 229, 87};

      std::vector<uint8_t> data2 = {10, 20, 30, 40, 50, 0, 124, 229, 87};

      channels[6].SetChannelValue(data2.data(), data2.size());

In the read section the channel value for byte array is empty. String is there..

Channel: testkslflkshd/0fkhslkdfhlksdhflkhsdlkfasdiadsl195182asjdj195164a195164sfhpoaih195188oahsfd195188oasg195188ogo195188ahgpon<psonfd0934ht19515992h1951590h0)?=$?W=&UI&?=AOSNPAsdp0195159j#+#+195188asf, Eng: testkslflkshd/0fkhslkdfhlksdhflkhsdlkfasdiadsl195182asjdj195164a195164sfhpoaih195188oahsfd195188oasg195188ogo195188ahgpon<psonfd0934ht19515992h1951590h0)?=$?W=&UI&?=AOSNPAsdp0195159j#+#+195188asf
Channel: , Eng:
ihedvall commented 7 months ago

I have started the MIME fix but I can't find any MDF file with MIME sample/stream data. So fixing the bug is difficult to verify. Anybody have a sample MDF file?

jezzzzza commented 7 months ago

hi, can you try the above part and add it to your example in test.cpp?

ihedvall commented 7 months ago

I have fixed the MDF library regarding the MIME sample and streams. Please verify with existing file or test.cpp.

jezzzzza commented 7 months ago

thx for the quick fix.. i tried the above example in test.cpp uint8_t vector but in replay part there is still no data inside.. not sure if i make everything right..

ihedvall commented 7 months ago

There is a new unit test TestWrite::Mdf4Mime that demonstrate how to use the MIME types. I don't understand the Replay meaning nor have access to the test.cpp file.

jezzzzza commented 7 months ago

The test.cpp is in mdflibrary_example folder. The SetChannelValue function in test.cpp is a member of MdfChannel class in namespace mdflibrary, this still seems not to work.. the setChannelValue function in testwrite.cpp is a member of IChannel in namespace mdflib and seems to work.

Anyhow, dont know what is the difference between mdflibrary and mdflib, though.. in test.cpp the mdflibrary namespace is used..

ihedvall commented 7 months ago

MdfLib is a C++ library while MdfLibrary is a .NET assembly. I don't understand why the .NET example is written in C++ instead of in C#.

Simplxss commented 7 months ago

The test.cpp is in mdflibrary_example folder. The SetChannelValue function in test.cpp is a member of MdfChannel class in namespace mdflibrary, this still seems not to work.. the setChannelValue function in testwrite.cpp is a member of IChannel in namespace mdflib and seems to work.

Anyhow, dont know what is the difference between mdflibrary and mdflib, though.. in test.cpp the mdflibrary namespace is used..

mdflib is a static library. mdflibrary is a shard library that export most functions of mdflib.

Simplxss commented 7 months ago

mdflibrary_example is not a .NET example. It is a example that how to use the native function in mdflibrary. You could see all functions exported in mdflibrary with DLL Export Viewer. image

jezzzzza commented 7 months ago

Ok, understood, somehow this function in MdfChannelObserver doesn't return a value, any idea how to fix it?

image

image

Simplxss commented 7 months ago

Could you try to use dll form here? https://github.com/ihedvall/mdflib/actions/runs/7001808212

jezzzzza commented 7 months ago

not working either unfortunately..

Simplxss commented 7 months ago

ok, I will fix it soon

jezzzzza commented 7 months ago

ok thank you!

One more thing..

I had to add this to main cmake and mdflibrary cmake file: in order being able to build the whole project, including the shared library..

image

image

that gave me that compiler warnings though.. i ignored them until now..

image

[2/42] Building CXX object mdflibrary\CMakeFiles\mdflibrary.dir\src\AssemblyInfo.cpp.obj D:\git\mdflib\build\ninja-multi-vcpkg-x64\mdflib\cl : Command line warning D9025: overriding '/EHs' with '/EHa' [3/42] Building CXX object mdflibrary\CMakeFiles\mdflibrary.dir\src\MdfChannelArray.cpp.obj D:\git\mdflib\build\ninja-multi-vcpkg-x64\mdflib\cl : Command line warning D9025: overriding '/EHs' with '/EHa' [4/42] Building CXX object mdflibrary\CMakeFiles\mdflibrary.dir\src\MdfDataGroup.cpp.obj D:\git\mdflib\build\ninja-multi-vcpkg-x64\mdflib\cl : Command line warning D9025: overriding '/EHs' with '/EHa' [5/42] Building CXX object mdflibrary\CMakeFiles\mdflibrary.dir\src\MdfChannelConversion.cpp.obj D:\git\mdflib\build\ninja-multi-vcpkg-x64\mdflib\cl : Command line warning D9025: overriding '/EHs' with '/EHa'

im building with

Microsoft Visual Studio Professional 2022 (64-bit) - Current Version 17.7.6

Simplxss commented 7 months ago

/EHs conflect with /clr(build .NET stuff). If you don't need use .NET, change the condition in line 5 of mdflibrary/CMakeLists.txt to false. I will add an option to control it soon.

jezzzzza commented 7 months ago

Ok, did that..

Now it seems like nth is being copied into value here, value is a nullptr..

image

  | Name | Value | Type -- | -- | -- | -- ◢ | value | 0x0000000000000000 | unsigned char *
ihedvall commented 7 months ago

I think the value object should be a reference like the size variable

Simplxss commented 7 months ago

try to modify std::vector<uint8_t> value of GetChannelValue in line 75 to std::vector<uint8_t>& value

Simplxss commented 7 months ago

uint8_t value[] equal to uint8_t* value

ihedvall commented 7 months ago

I'm still lost. If your application is C++, use mdflib. If its a C# application use the .NET assembly mdflibrary.

jezzzzza commented 7 months ago

@Simplxss not sure what you mean..

@ihedvall I started with mdflibrary example since i thought it is the legit example of how to use mdflib. And it also works fine for single values (float, integer etc...). Later, after i figured that i cannot read back byte arrays i tried to use mdflib but ran into execution errors somehow related to observer_list which is a unique ptr list as far as i remember..

so i thought trying debugging the mdflibrary example might be the faster path..

Anyhow, maybe try rethinking naming here!?

Simplxss commented 7 months ago

I think it works now.

https://github.com/ihedvall/mdflib/actions/runs/7020847467/job/19101525608

ihedvall commented 7 months ago

If you want a shared mdflib, you may just changes the mdflib add_library(mdf to SHARED... instead of STATIC or remove it and let the CMake BUILD_SHARED_LIBS=ON(/OFF) option control the build. The latter is the CMake standard approach.

The -NET assembly (mdflibrary.dll) is build by Visual Studio solution file (mdflib.sln). I never got CMake produce .NET application nor assemblies. The .NET assembly is used by some users.

jezzzzza commented 7 months ago

ok, thank you..

@Simplxss seems like this did the trick.. thank you..

image

@ihedvall im building with cmake in vs2022 and now it works fine with the hints from @Simplxss and now it seems to work..

jezzzzza commented 7 months ago

@ihedvall seems to work only for non-zipped/uncompressed data now.. maybe some more fixes in #51 needed?

ihedvall commented 7 months ago

The DZ to SD conversion was missing for one type of signal data configuration.

There where more error little bit here and there, so I don't know if I can close this bug?