(minimal) code to write a blf-file

Issue #11 closed
Former user created an issue

Hi Tobias,

I'm trying to write a simple code which should write(log) incoming Can-Messages to a BLF... but I don't really know how to do this.

I tried using Vector::BLF::CompressedFile file; ... Vector::BLF::CanMessage msg; msg.id = 0x111; msg.data[0] = 0x11; msg.write(file); ...

but how can I write this AbstractFile to a physical file on disk? when logging can-data for many minutes: is it necessary to regularly flush the file or does the library take car of that automatically?

any starters? maybe a simple example like Parser.cpp but for writing?

thanks a lot, Hannes

Comments (13)

  1. Tobias Lorenz repo owner

    Hi Hannes,

    you can take a look in the test cases. There objects a being instantiated and written into a new BLF file.

    The main class to instantiate is File. AbstractFile is an internal class. Write operations are done with the normal fstream class, however it's not exposed. So if you need a flush() method, then I need to add it.

    Does this help you?

    Bye Tobias

  2. Hannes Lechner

    Hi Tobias,

    thanks for the quick answer.

    well- i already checked the test cases. but wasn't very successful :( I especially looked into test_AllLogfiles/copyObjects(). but calling this with "text_CanMessage.bfl" as the filein and "text_CanMessage.copy.bfl" as the fileout, it fails at fileout.close(); at the end of copyObjects(){...} with Debug Assertation "cannot decrement begin list iterator"...

    the same is true for my own test-code which now simply instantiates and opens a Vector::BLF::File, then creates a Vector::BLF::CanMessage(), writes the canMsg using "file.write(reinterpret_cast<Vector::BLF::CanMessage *>(msg));" and finally calls "file.close();" ==> again- the above Debug Assertation :(

    ...what am I missing???

    thanks, Hannes

  3. Tobias Lorenz repo owner

    Hi Hannes,

    I'll try to add a quick example on the weekend.

    Basically you need to pass the ownership of the new message to the library. So you need to instantiate it and then hand it over to file.write. So taking your example from above:

    Vector::BLF::File file; file.open(...); ... Vector::BLF::CanMessage * msg = new Vector::BLF::CanMessage; msg.id = 0x111; msg.data[0] = 0x11; file.write(msg); ... file.close();

    Bye Tobias

  4. Hannes Lechner

    Tobias - thanks a lot for your efforts!

    my test-code was basically identical to your "Write-Example.cpp". so - to no surprise - I'm faced with the very same error :(

    now I digged a little further: seems this problem is Windows related (haven't tried to compile test everything unter linux yet - altough the first implementation should run on linux anyway; and I assume, you develop your code mainly on Linux so you're not facing that problem?!) seems the problem is related e.g. to: https://social.msdn.microsoft.com/Forums/vstudio/en-US/964b7ebe-3a0d-44db-b901-74453f97d359/quotlist-iterator-not-decrementablequot-error?forum=vcgeneral

    not sure yet whether I can fix/workaround this on my side?! --> however, changing the solution-configuration to "Release" omits this debug-assertation in "list": _STL_VERIFY(_New_ptr != _Mycont->_Myhead, "cannot decrement begin list iterator"); and the code works just fine ;)

    for Debug: #define _ITERATOR_DEBUG_LEVEL=0 in the test.cpp disables the assertation, but then "UncompressedFile::write(..) fails in line 168...

    Hannes

  5. Tobias Lorenz repo owner

    Hi Hannes,

    I need to analyze this further. If the warning is correct, then I seem to iterate before the beginning of the list, or beyond it's end. This would indeed be an issue in the implementation of my code.

    Yes, my main development is Debian Testing, which currently has gcc 8. All other compilers are only tested on Jenkins. Currently I have VS2017 in there. Which compiler have you used?

    Bye Tobias

  6. Hannes Lechner

    Hi Tobias,

    I'm using VS2017, too...

    sorry - I could not yet try any other compiler nor Linux due to lack of time :(

  7. Tobias Lorenz repo owner

    Hi, the line you referred to, checks if the last element of the list is valid. This is done by comparing back() != nullptr. This might be the issue, as it would through an exception instead of returning a nullptr. So it's better to use !empty() instead. I pushed a commit that does this change. Can you test if it solves the issue? Bye Tobias

  8. Log in to comment