DLT:dlt-daemon示例解析2

DLT:dlt-daemon示例解析

回顾一下上期第一个示例打印DLT日志的流程。

这次来分析第二个示例。

目录dlt-daemon/examples/example2/下有以下文件

 CMakeLists.txt  dlt_id.h  example2.c  example2.xml

其中example2.xml编译用不到,里面描述了一些程序的信息,我们先不管它。

// CMakeLists.txt

#######
# SPDX license identifier: MPL-2.0
#
# Copyright (C) 2011-2015, BMW AG
#
# This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
#
# This Source Code Form is subject to the terms of the
# Mozilla Public License (MPL), v. 2.0.
# If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# For further information see http://www.genivi.org/.
########
# DLT example implementation
#cmake_minimum_required( VERSION 2.6 )
project( automotive-dlt-example2 )#
# find dependency packages
#find_package(PkgConfig)
pkg_check_modules(DLT REQUIRED automotive-dlt)#
# include directories
#include_directories(${DLT_INCLUDE_DIRS}
)#
# build project
#set(dlt_example2_SRCS example2.c)
add_executable(dlt-example2 ${dlt_example2_SRCS})
target_link_libraries(dlt-example2 ${DLT_LIBRARIES})
set_target_properties(dlt-example2 PROPERTIES LINKER_LANGUAGE C)install(TARGETS dlt-example2RUNTIME DESTINATION binCOMPONENT base)

//dlt_id.h

/** SPDX license identifier: MPL-2.0** Copyright (C) 2011-2015, BMW AG** This file is part of GENIVI Project DLT - Diagnostic Log and Trace.** This Source Code Form is subject to the terms of the* Mozilla Public License (MPL), v. 2.0.* If a copy of the MPL was not distributed with this file,* You can obtain one at http://mozilla.org/MPL/2.0/.** For further information see http://www.genivi.org/.*//* generated file, do not edit */#ifndef DLT_ID_H
#define DLT_ID_H#define DLT_EXA2_CON_EXA2_ID1 1000
#define DLT_EXA2_CON_EXA2_ID2 1001
#define DLT_EXA2_CON_EXA2_ID3 1002#endif /* DLT_ID_H */

文件中用宏定义了3个ID,打印log时使用,没有什么特殊意义。

//example2.c


/** SPDX license identifier: MPL-2.0** Copyright (C) 2011-2015, BMW AG** This file is part of GENIVI Project DLT - Diagnostic Log and Trace.** This Source Code Form is subject to the terms of the* Mozilla Public License (MPL), v. 2.0.* If a copy of the MPL was not distributed with this file,* You can obtain one at http://mozilla.org/MPL/2.0/.** For further information see http://www.genivi.org/.*//*!* \author Alexander Wenzel <alexander.aw.wenzel@bmw.de>** \copyright Copyright © 2011-2015 BMW AG. \n* License MPL-2.0: Mozilla Public License version 2.0 http://mozilla.org/MPL/2.0/.** \file example2.c*//*******************************************************************************
**                                                                            **
**  SRC-MODULE: example2.c                                                    **
**                                                                            **
**  TARGET    : linux                                                         **
**                                                                            **
**  PROJECT   : DLT                                                           **
**                                                                            **
**  AUTHOR    : Alexander Wenzel Alexander.AW.Wenzel@bmw.de                   **
**                                                                            **
**  PURPOSE   :                                                               **
**                                                                            **
**  REMARKS   :                                                               **
**                                                                            **
**  PLATFORM DEPENDANT [yes/no]: yes                                          **
**                                                                            **
**  TO BE CHANGED BY USER [yes/no]: no                                        **
**                                                                            **
*******************************************************************************/#include <stdio.h>      /* for printf() and fprintf() */
#include <stdlib.h>     /* for atoi() and exit() */#include <dlt.h>#include "dlt_id.h"DLT_DECLARE_CONTEXT(con_exa2);int main()
{int num;struct timespec ts;DLT_REGISTER_APP("EXA2", "Third Example");DLT_REGISTER_CONTEXT(con_exa2, "CON", "First context");DLT_NONVERBOSE_MODE();for (num = 0; num < 10; num++) {DLT_LOG_ID(con_exa2, DLT_LOG_INFO, DLT_EXA2_CON_EXA2_ID1, DLT_INT32(12345678), DLT_STRING("Hello world 1!"));DLT_LOG_ID(con_exa2, DLT_LOG_ERROR, DLT_EXA2_CON_EXA2_ID2, DLT_INT32(87654321), DLT_STRING("Hello world 2!"));DLT_LOG_ID(con_exa2, DLT_LOG_WARN, DLT_EXA2_CON_EXA2_ID3, DLT_INT32(11223344), DLT_STRING("Hello world 3!"));ts.tv_sec = 0;ts.tv_nsec = 1000000;nanosleep(&ts, NULL);}DLT_UNREGISTER_CONTEXT(con_exa2);DLT_UNREGISTER_APP();
}

Application ID是“EXA2”, Context ID是“CON”。

这里的流程与示例1相比有变化:

1. 增加了DLT_NONVERBOSE_MODE设置。

2. 打印log的位置换成了 DLT_LOG_ID.

3. 打印的内容变成多条,更贴近实际。

4. 每条消息中的等级不同,包括INFO,ERROR,WARN等。消息中增加了ID,消息包括int和String多种类型。

三条消息每条打印10次。

DLT_NONVERBOSE_MODE

/*** Switch to non-verbose mode**/
#define DLT_NONVERBOSE_MODE() do { \(void)dlt_nonverbose_mode(); } while(false)

这个宏调用了dlt_nonverbose_mode()函数,含义为切换到非冗余模式。默认是冗余模式。

简单说明下非冗余模式和冗余模式:

NonVerbose Mode

To be able to transmit parameter values only - without the need of any meta information about them -, additional properties like parameter names or types -, the Non-Verbose Mode can be used.

To allow the correct disassembly of the contained parameter values within a received Dlt message, a dedicated Message ID is added to the payload.

A separate, external file contains the description of the payload layout according to the corresponding Message ID.

概况的说就是传递消息比较简洁。

数据格式如下,消息头后面就是消息ID和数据

Verbose Mode

Dlt messages which are sent in Verbose Mode contain a complete description of the parameters next to the parameter values itself.

This means that on the one hand no external file is needed for disassembly; On the other hand, a higher amount of data is sent on the bus.

The Verbose Mode can be used on ECUs where enough memory and high network bandwidth are available. Because of the self-description, the stored data on the external client is interpretable at any time and without any further external information.

通俗的含义就是什么详细信息都发,发的数据多所以用在内存充足而且网络带宽高的地方。

数据格式比上面详细很多。

DLT_LOG_ID

/*** Send log message with variable list of messages (intended for non-verbose mode)* @param CONTEXT object containing information about one special logging context* @param LOGLEVEL the log level of the log message* @param MSGID the message id of log message* @param ... variable list of arguments* calls to DLT_STRING(), DLT_BOOL(), DLT_FLOAT32(), DLT_FLOAT64(),* DLT_INT(), DLT_UINT(), DLT_RAW()* @note To avoid the MISRA warning "The comma operator has been used outside a for statement"*       use a semicolon instead of a comma to separate the __VA_ARGS__.*       Example: DLT_LOG_ID(hContext, DLT_LOG_INFO, 0x1234, DLT_STRING("Hello world"); DLT_INT(123));*/
#ifdef _MSC_VER
/* DLT_LOG_ID is not supported by MS Visual C++ */
/* use function interface instead               */
#else
#   define DLT_LOG_ID(CONTEXT, LOGLEVEL, MSGID, ...) \do { \DltContextData log_local; \int dlt_local; \dlt_local = dlt_user_log_write_start_id(&CONTEXT, &log_local, LOGLEVEL, MSGID); \if (dlt_local == DLT_RETURN_TRUE) \{ \__VA_ARGS__; \(void)dlt_user_log_write_finish(&log_local); \} \} while(false)
#endif

发送带有消息变量列表的日志消息(用于NonVerbose Mode)。日志带ID。

带有ID的日志更有实用性,可以区分不同来源的日志。运行的结果在dlt-viewer中显示如下:

只关注log日志(而且是打印消息的),其他消息由DLT处理不关注。解析第1条打印log日志:

[1000]  Na----Hello world 1!-|4e 61 bc 00 0f 00 48 65 6c 6c 6f 20 77 6f 72 6c 64 20 31 21 00

1000:表示MSGID,就是程序里面的DLT_EXA2_CON_EXA2_ID1

Na----Hello world 1!-:表示LOG数据DLT_INT32(12345678)DLT_STRING("Hello world 1!")

其中12345678写成16进制为0x00bc614e,在小端模式存储时,写成4e 61 bc 00。其余字符按照ASCII码显示。

4e 61 bc 00 0f 00 48 65 6c 6c 6f 20 77 6f 72 6c 64 20 31 21 00这串数字表示DLT_INT32(12345678)DLT_STRING("Hello world 1!")ASCII码值。

其他条目的日志类似。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/340474.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ssm框架的简单整合!!!(配置环境)

项目结构&#xff1a; pom.xml: <packaging>war</packaging><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target><project.build.sourceEncoding>UTF-8</proj…

24/01/11 qt work

1. 作业&#xff1a; xx.h 文件#ifndef MYWIDGET_H #define MYWIDGET_H#include <QWidget> #include <QDate> #include <QTime> #include <QTimerEvent> #include <QMessageBox> #include <QDebug> #include <QTextToSpeech>QT_BEGI…

【C++】C++11中的常见语法(上)

C11 一、C11简介二、统一的列表初始化1.&#xff5b;&#xff5d;初始化2. std::initializer_list 三、声明1. auto2. decltype3. nullptr 四、右值引用和移动语义1. 左值引用和右值引用2. 左值引用与右值引用比较3. 右值引用使用场景和意义4. 右值引用引用左值及其一些更深入的…

FineBI实战项目一(16):下订单总用户数分析开发

点击新建组件&#xff0c;创建下订单总用户数组件。 选择自定义图表&#xff0c;选择文本&#xff0c;拖拽要分析的字段到文本中。 修改指针值名称。 将指针值名称修改为用户数。 进入仪表板&#xff0c;拖拽刚刚的组件进入仪表板&#xff0c;然后在再编辑标题。 效果如下&…

可狱可囚的爬虫系列课程 11:Requests中的SSL

一、SSL 证书 SSL 证书是数字证书的一种&#xff0c;类似于驾驶证、护照、营业执照等的电子副本。SSL 证书也称为 SSL 服务器证书&#xff0c;因为它是配置在服务器上。 SSL 证书是由受信任的数字证书颁发机构 CA 在验证服务器身份后颁发的&#xff0c;其具有服务器身份验证和…

【PostgreSql】本地备份为dump文件与恢复数据库(单表和整个数据库)

目录 1.准备脚本1.1 脚本介绍 2.开始备份3.进行恢复3.单张表的备份与恢复3.1 单张表的备份3.2 单张表的恢复 4.常用命令和参数4.1 备份常用参数4.2 备份常用命令4.3 还原常用命令 环境&#xff1a;windows数据库&#xff1a;postgresql 1.准备脚本 backUpDb.bat 脚本为备份脚本…

多态、抽象类和接口(深拷贝和浅拷贝)

目录​​​​​​​ 前言&#xff1a; 多态&#xff1a; 多态的定义&#xff1a; 向上转型&#xff1a; 方法重写&#xff1a; 再看toString方法&#xff1a; 动态绑定&#xff1a; 向下转型&#xff1a; 小练习&#xff1a; 抽象类&#xff1a; 什么是抽象类&am…

if单分支,二分支,多分支,语句嵌套,while语句,for语句(Python实现)

一、主要目的&#xff1a; 1&#xff0e;熟悉程序设计结构的三种方式 2.掌握if单分支语句、if二分支语句、if多分支语句及if语句嵌套的使用方法 3.掌握while语句的使用方法 4.掌握for语句的使用方法 5.掌握循环嵌套的使用方法 二、主要内容和结果展现&#xff1a; 1&…

网工内推 | 高级网工,H3C认证优先,朝九晚六,周末双休

01 万德 招聘岗位&#xff1a;高级网络工程师 职责描述&#xff1a; 1、项目交付&#xff1a;项目管理和交付&#xff0c;包括项目前期的规划、实施以及后期的运维支持、项目验收等。 2、技术支持&#xff1a;为客户及合作伙伴提供网上问题远程和现场支持&#xff1b;对公司内…

【链表】力扣206反转链表

题目 力扣206反转链表 思路图解 代码实现 双指针代码实现 public static ListNode reverseList(ListNode head) {// 初始化pre&#xff0c;curListNode pre null;ListNode cur head;// 当cur为null时&#xff0c;说明反转结束while(cur ! null) {// 临时保存cur.next节点…

【现代密码学】笔记3.4-3.7--构造安全加密方案、CPA安全、CCA安全 《introduction to modern cryphtography》

【现代密码学】笔记3.4-3.7--构造安全加密方案、CPA安全、CCA安全 《introduction to modern cryphtography》 写在最前面私钥加密与伪随机性 第二部分流加密与CPA多重加密 CPA安全加密方案CPA安全实验、预言机访问&#xff08;oracle access&#xff09; 操作模式伪随机函数PR…

c++析构函数

析构函数的简述 1. 析构函数和构造函数类似&#xff0c;是c规定当对象的生命周期结束时&#xff0c;默认你会调用析构函数。 2. 同理&#xff0c;当我们不写析构函数的时候&#xff0c;编译器会自动生成一个空实现的析构函数。 3. 析构函数只能编译器自己调用&#xff0c;我们…