Unable to write structures to blf using CAN FD message format

Issue #39 resolved
Former user created an issue

Hi Tobias, I want to write structures(>64 size) into blf but not able to to do so as CAN FD message can not be more than 64 byte. I am using following logic.

auto* stdCAN = new Vector::BLF::CanFdMessage; size_t var = size; stdCAN->objectTimeStamp = time_ns; stdCAN->channel = channel; stdCAN->id = messageID; stdCAN->canFdFlags = Vector::BLF::CanFdMessage::CanFdFlags::EDL;

        if (size > 64)

// stdCAN->dlc = size; stdCAN->dlc = 15; else if (size > 48) stdCAN->dlc = 15; else if (size > 32) stdCAN->dlc = 14; else if (size > 24) stdCAN->dlc = 13; else if (size > 20) stdCAN->dlc = 12; else if (size > 16) stdCAN->dlc = 11; else if (size > 12) stdCAN->dlc = 10; else if (size > 8) stdCAN->dlc = 9; else stdCAN->dlc = 8; if(size > 64) var = 64;

        stdCAN->validDataBytes= var;
        memcpy(&stdCAN->data, data, var);
        hFile.write(stdCAN);

So going by this logic i can only copy 64 byte data and when i try to copy more than 64 byte ( memcpy(&stdCAN->data, data, var);), i am getting runtime errors. I think we need to use some different Message class ? NOTE : I want to srite the structure into same blf file having CANfd messages.

Comments (6)

  1. Tobias Lorenz repo owner

    Hi, you are facing the following problem here: CANFD supports up to 64 data bytes, but not more. Hence “data” is a std::array of 64 bytes maximum. If you write more, you get memory corruption. Even if it would be possible, I doubt that any BLF tool would properly handle it. Bye Tobias

  2. Deepen M

    The following logic i have been using for windows. Same i need to do for Linux.

        case BL_OBJ_TYPE_ETHERNET_FRAME_EX:
        {
            BLF_VBLEthernetFrameEx_t ethernetEx;
            EthernetHeaderEx header;
            header.messageID = messageID;
            header.size = uint32_t(size);
            header.reverseBytes();
    
            ethernetEx.mHeader.mObjectTimeStamp = time_ns;
            ethernetEx.mChannel = channel;
            //ethernetEx.mFrameLength = 74 + uint16_t(size);  //20 bytes more data size
            ethernetEx.mFrameLength = 54 + uint16_t(size);    //Mu
    //        std::cout << messageID << ethernetEx.mFrameLength << endl;        //SIL
    //        system("pause");   //SIL
            ethernetEx.mFrameData = new BYTE[ethernetEx.mFrameLength];
            memcpy(ethernetEx.mFrameData, &header.Mac_ADAS, 54);
            memcpy(ethernetEx.mFrameData + 54, data, size);
            ethernetEx.mHeader.mBase.mObjectSize = offsetof(VBLEthernetFrameEx, mFrameData) + ethernetEx.mFrameLength;
    
            bool ok = BLWriteObject(hFile, &ethernetEx.mHeader.mBase);
            delete[] ethernetEx.mFrameData;
            return ok;
    

  3. Log in to comment