欢迎关注《汽车软件技术》公众号,回复关键字获取资料。
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 CANmessage */
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 theenvironment 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开发