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.mzph.cn/news/614862.shtml

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

相关文章

【FFMPEG应用篇】基于FFmpeg的转码应用(FLV MP4)

方法声明 extern "C" //ffmpeg使用c语言实现的&#xff0c;引入用c写的代码就要用extern { #include <libavcodec/avcodec.h> //注册 #include <libavdevice/avdevice.h> //设备 #include <libavformat/avformat.h> #include <libavutil/…

致远OA getAjaxDataServlet XXE漏洞复现(QVD-2023-30027)

0x01 产品简介 致远互联-OA 是数字化构建企业数字化协同运营中台,面向企业各种业务场景提供一站式大数据分析解决方案的协同办公软件。 0x02 漏洞概述 致远互联-OA getAjaxDataServlet 接口处存在XML实体注入漏洞,未经身份认证的攻击者可以利用此漏洞读取系统内部敏感文件…

Aurora中显示中文

Aurora是可以在word里面作为插件使用&#xff0c;可以画一些三线表&#xff0c;是一款非常好用的工具&#xff0c;写论文必备。 我们可以通过现在excel里面创建表格&#xff0c;然后将excel转成latex格式&#xff0c;具体做法参考如下&#xff1a; Aurora Equation——Latex表…

2024.1.10力扣每日一题——删除子串后的字符串最小长度

2024.1.10 题目来源我的题解方法一 递归方法二 循环 题目来源 力扣每日一题&#xff1b;题序&#xff1a;2696 我的题解 方法一 递归 每次将s中的“AB”和“CD”替换为空串&#xff0c;然后递归&#xff0c;直到s中不含两个字符串中的任意一个。 可以使用栈来替代递归。 时间…

vue中slot和template用法传值

1 父页面调用assets-trend子组件&#xff0c;并接受assets-trend子组件传来的参数 <assets-trend style"flex: 2.7"><template slot-scope"slot">{{slot.slotMsg}}</template></assets-trend>2 子页面assets-trend使用slot传值 &…

2024年AMC8最后一周复习建议,以及往年真题练习和答案详解(5)

今天是1月12日&#xff0c;下周的今天就要正式举办AMC8的比赛了。最后一周该如何准备AMC8的竞赛呢&#xff1f; 六分成长的建议是&#xff1a; 1、以刷真题为主&#xff0c;把各种题型的解题思路、涉及到的知识点、公式再复习。如果遇到不懂的知识点再看教材或笔记。 2、每天…

Java填充Execl模板并返回前端下载

功能&#xff1a;后端使用Java POI填充Execl模板&#xff0c;并返回前端下载 Execl模板如下&#xff1a; 1. Java后端 功能&#xff1a;填充模板EXECL,并返回前端 controller层 package org.huan.controller;import org.huan.dto.ExcelData; import org.huan.util.ExcelT…

Cylinder3D论文阅读

Cylindrical and Asymmetrical 3D Convolution Networks for LiDAR Segmentation&#xff08;2020年论文&#xff09; 作者&#xff1a;香港中文大学 论文链接&#xff1a;https://arxiv.org/pdf/2011.10033.pdf 代码链接&#xff1a;https://github.com/xinge008/Cylinder3D …

Java21 如何使用switch case

1. Java8 和 Java21 Java8 引入字符串和枚举 Java21 可以返回值, yield关键字, switch 表达式, 模式匹配, null值处理 2. 代码案例 1. Java8 public static void java8() {String day "tuesday";switch (day) {case "monday":System.out.println("w…

梦想贩卖机升级版知识付费源码,包含前后端源码,非线传,修复最新登录接口问题

梦想贩卖机升级版&#xff0c;变现宝吸收了资源变现类产品的许多优势&#xff0c;并剔除了那些无关紧要的元素&#xff0c;使得本产品在运营和变现能力方面实现了质的飞跃。多领域素材资源知识变现营销裂变独立版本。 支持&#xff1a;视频、音频、图文、文档、会员、社群、用…

Linux中批量创建用户的方法

在Linux中&#xff0c;可以使用脚本来批量创建用户。以下是一个具体的步骤&#xff1a; 1&#xff09;在 /home/user1/ 目录下创建目录&#xff1a; sudo mkdir /home/user1 sudo chown root:root /home/user1执行命令 sudo chown root:root /home/user1 将 /home/user1 目录…

基于JavaWeb+BS架构+SpringBoot+Vue+Hadoop的物品租赁系统的设计与实现

基于JavaWebBS架构SpringBootVueHadoop的物品租赁系统的设计与实现 文末获取源码Lun文目录前言主要技术系统设计功能截图订阅经典源码专栏Java项目精品实战案例《500套》 源码获取 文末获取源码 Lun文目录 目  录 I 1绪 论 1 1.1开发背景 1 1.2开发目的与意义 1 1.2.1开发目…

Qt QTableView和QStandardItemModel包含搜索出现的文本及隐藏顶层节点

前言 使用Qt进行开发时&#xff0c;树结构一般是使用QTreeWidget或使用QTreeViewQStandardItemModel结合。 查找 如果要进行查找树的所有项中&#xff0c;是否包含某文本&#xff0c;就需要遍历。 QTreeWidget查找 以下是使用QTreeWidget进行查找&#xff1a; 首先初始化一…

OpenGL和OpenGL ES显示YUV图片的着色器差别(一)

这里解释的只是用于显示YUV图片的代码&#xff0c;没有增加任何效果&#xff1a; OpenGL 的片段着色器片段&#xff1a; const char *fsrc "varying vec2 textureOut; \uniform sampler2D tex_y; \uniform sampler2D tex_u; \uniform sampler2D tex_v; \void main(void…

css 怎么绘制一个带圆角的渐变色的边框

1&#xff0c;可以写两个样式最外面的div设置一个渐变的背景色。里面的元素使用纯色。但是宽高要比外面元素的小。可以利用里面的元素设置padding这样挡住部分渐变色。漏出来的渐变色就像边框一样。 <div class"cover-wrapper"> <div class"item-cover…

leetcode 每日一题 2024年01月11日 构造有效字符串的最少插入数

题目 2645. 构造有效字符串的最少插入数 给你一个字符串 word &#xff0c;你可以向其中任何位置插入 “a”、“b” 或 “c” 任意次&#xff0c;返回使 word 有效 需要插入的最少字母数。 如果字符串可以由 “abc” 串联多次得到&#xff0c;则认为该字符串 有效 。 示例 …

【ChatGPT-Share,国内可用】GPTS商店大更新:一探前沿科技的魅力!

使用地址&#xff1a;https://hello.zhangsan.cloud/list GPTS商店预览,王炸更新 精选应用&#xff1a; 系统内置应用&#xff1a; 绘画应用&#xff1a; 写作应用&#xff1a; 高效工具应用&#xff1a; 学术搜索和分析应用&#xff1a; 编程应用&#xff1a; 教育应…

C++白皮书学习

decltype C decltype用法详解-CSDN博客 <-参考文章 用来在编译时期进行自动类型推导。引入decltype是因为auto并不适用于所有的自动类型推导场景&#xff0c;在某些特殊情况下auto用起来很不方便&#xff0c;甚至压根无法使用。 auto varNamevalue; decltype(exp) varN…

万字长文 详细讲述 计算机网络层

文章目录 网络层网络层的几个重要概念网络层的两个层面 网际协议 IP虚拟互连网络IP 地址IP 地址及其表示方法IP 地址与 MAC 地址地址解析协议 ARPIP 数据报的格式 IP层转发分组过程基于终点的转发最长前缀匹配 网际控制报文协议 ICMPICMP 报文的种类ICMP 的应用举例IPv6 的基本…

Discourse 未活动的用户是怎么处理的

Discourse 目前有一个参数为 clean up inactive users after days 来控制不活跃或者未激活的用户。 如果你的用户满足下面的条件的话&#xff0c;系统将会在到期后对用户进行清理和删除 从未在 Discourse 站点上发布任何内容 如果你在 Discourse 站点上发布了内容&#xff0c…