歡迎關注《汽車軟件技術》公眾號,回復關鍵字獲取資料。
Vector工具錄制的數據,一般有ASC和BLF兩種格式,本文介紹ASC。
1.BLF定義
BLF(binary logging format)即二進制數據文件。
2.BLF查看
因其是二進制文件,且又做了數據壓縮,已經無法直接看到物理數值。需要在Vector工具中回放。
3.BLF組成
安裝完Vector軟件后,可以在Doc\LoggingFormat_BLF目錄下看到《CAN_and_General_BLF_Format.pdf》(回復“BLF文檔"獲取)。此文檔詳細說明了BLF內容。BLF內由一系列數據塊組成。介紹幾個常用的:
1)VBLObjectHeaderBase
Parameter |
Type |
mSignature |
DWORD |
mHeaderSize |
WORD |
mHeaderVersion |
WORD |
mObjectSize |
DWORD |
mObjectType |
DWORD |
2)VBLObjectHeader
Parameter |
Type |
mBase |
VBLObjectHeaderBase |
mObjectFlags |
DWORD |
mClientIndex |
WORD |
mObjectVersion |
WORD |
mObjectTimeStamp |
ULONGLONG |
3)VBLCANMessage
Parameter |
Type |
mHeader |
VBLObjectHeader |
mChannel |
DWORD |
mFlags |
BYTE |
mDLC |
BYTE |
mID |
DWORD |
mData[8] |
BYTE |
4.BLF解析
因BLF的保密性,無法直接讀到值,需要使用Vector提供的binlog.dll,相關的例子可以參考《C:\Users\Public\Documents\Vector\CANoe\9.0 (x64)\CANoe Sample Configurations\Programming\BLF_Logging》。下面介紹《bl.c》的函數read_test。(回復“BLF例子”,可以獲取ector例子)
/******************************************************************************
* *
* read BL file *
* *
******************************************************************************/
int read_test( LPCTSTR pFileName, LPDWORD pRead)
{
HANDLE hFile;
VBLObjectHeaderBase base;
VBLCANMessage message;
VBLEnvironmentVariable variable;
VBLEthernetFrame ethframe;
VBLAppText appText;
VBLFileStatisticsEx statistics = { sizeof( statistics)};
BOOL bSuccess;
if ( NULL == pRead)
{
return -1;
}
*pRead = 0;
/* open file */
hFile = BLCreateFile( pFileName, GENERIC_READ);
if ( INVALID_HANDLE_VALUE == hFile)
{
return -1;
}
BLGetFileStatisticsEx( hFile, &statistics);
bSuccess = TRUE;
/* read base object header from file */
while ( bSuccess && BLPeekObject( hFile, &base))
{
switch ( base.mObjectType)
{
case BL_OBJ_TYPE_CAN_MESSAGE:
/* read CAN message */
message.mHeader.mBase = base;
bSuccess = BLReadObjectSecure( hFile, &message.mHeader.mBase, sizeof(message));
/* free memory for the CAN message */
if( bSuccess) {
BLFreeObject( hFile, &message.mHeader.mBase);
}
break;
case BL_OBJ_TYPE_ENV_INTEGER:
case BL_OBJ_TYPE_ENV_DOUBLE:
case BL_OBJ_TYPE_ENV_STRING:
case BL_OBJ_TYPE_ENV_DATA:
/* read environment variable */
variable.mHeader.mBase = base;
bSuccess = BLReadObjectSecure( hFile, &variable.mHeader.mBase, sizeof(variable));
/* free memory for the environment variable */
if( bSuccess) {
BLFreeObject( hFile, &variable.mHeader.mBase);
}
break;
case BL_OBJ_TYPE_ETHERNET_FRAME:
/* read ethernet frame */
ethframe.mHeader.mBase = base;
bSuccess = BLReadObjectSecure( hFile, ðframe.mHeader.mBase, sizeof(ethframe));
/* free memory for the frame */
if( bSuccess) {
BLFreeObject( hFile, ðframe.mHeader.mBase);
}
break;
case BL_OBJ_TYPE_APP_TEXT:
/* read text */
appText.mHeader.mBase = base;
bSuccess = BLReadObjectSecure( hFile, &appText.mHeader.mBase, sizeof(appText));
if ( NULL != appText.mText)
{
printf( "%s\n", appText.mText);
}
/* free memory for the text */
if( bSuccess) {
BLFreeObject( hFile, &appText.mHeader.mBase);
}
break;
default:
/* skip all other objects */
bSuccess = BLSkipObject( hFile, &base);
break;
}
if ( bSuccess)
{
*pRead += 1;
}
}
/* close file */
if ( !BLCloseHandle( hFile))
{
return -1;
}
return bSuccess ? 0 : -1;
}
1)hFile = BLCreateFile( pFileName, GENERIC_READ);
以讀取的方式,打開BLF文件
2)BLGetFileStatisticsEx( hFile, &statistics);
讀取文件統計信息
3)while ( bSuccess && BLPeekObject( hFile, &base))
讀取文件object
4)switch ( base.mObjectType)
5)bSuccess = BLReadObjectSecure( hFile, &message.mHeader.mBase, sizeof(message));
讀取CAN message
6)bSuccess = BLSkipObject( hFile, &base);
跳過其他object
7) if ( !BLCloseHandle( hFile))
5.開發步驟
需要c/c++基礎
1)新建vc++項目
2)引入頭文件:binlog.h和binlog_objects.h
3)引入庫文件:binlog.dll和binlog.lib
4)參考bl.c開發