DLT:dlt-daemon示例解析2

news2025/2/22 20:29:47

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-example2
	RUNTIME DESTINATION bin
	COMPONENT 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.coloradmin.cn/o/1375672.html

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

相关文章

Elasticsearch聚合优化 | 聚合速度提升5倍!

1、聚合为什么慢&#xff1f; 大多数时候对单个字段的聚合查询还是非常快的&#xff0c; 但是当需要同时聚合多个字段时&#xff0c;就可能会产生大量的分组&#xff0c;最终结果就是占用 Elasticsearch大量内存&#xff0c;从而导致 OOM 的情况发生。 实践应用发现&#xff0…

git入门之本地操作

1、启动git命令输入 在想要建立仓库&#xff0c;建议的方式是在文件夹中右键单击&#xff0c;选择git bash here 2、初始化仓库命令&#xff1a;git init 3、查看仓库状态&#xff1a;git status 4、更新仓库特定文件&#xff1a;git add xxx 5、更新仓库所有文件&#xff1…

【机器学习】聚类算法(二)

五、基于密度的算法 5.1 DBSCAN 算法 import sys # 导入 sys 模块&#xff0c;用于访问系统相关的参数和功能 import os # 导入 os 模块&#xff0c;用于处理文件和目录 import math # 导入 math 模块&#xff0c;用于进行数学运算 import random # 导入 random 模块&#xff0…

JVM基础(5)——JVM垃圾回收算法

作者简介&#xff1a;大家好&#xff0c;我是smart哥&#xff0c;前中兴通讯、美团架构师&#xff0c;现某互联网公司CTO 联系qq&#xff1a;184480602&#xff0c;加我进群&#xff0c;大家一起学习&#xff0c;一起进步&#xff0c;一起对抗互联网寒冬 学习必须往深处挖&…

【机器学习】模型调参工具:Hyperopt 使用指南

机器学习| 模型调参工具&#xff1a;Hyperopt 使用指南 前言1. Hyperopt是什么&#xff1f;2. Hyperopt的优缺点3. 如何使用 Hyperopt 进行调参3.1 安装 Hyperopt3.2 构建超参数空间3.3 定义目标函数3.4 运行 Hyperopt 优化3.5 获取最优超参数 4. XGB调参代码示例参考资料 前言…

Java Http各个请求类型详细介绍

1. 前言 在Spring Boot框架中&#xff0c;HTTP请求类型是构建Web应用程序的重要组成部分。常见的请求类型包括GET、POST、PUT和DELETE&#xff0c;每种类型都有其特定的用途和特点。本文将详细比较这四种请求类型&#xff0c;帮助您在开发过程中做出明智的选择。 2. GET请求…

12.扩展字典(ExtensionDictionary)

愿你出走半生,归来仍是少年! 环境:.NET FrameWork4.5、ObjectArx 2016 64bit、Entity Framework 6. 在10.扩展数据(XData)中我们讲到每个DbObject有一个XData对象可以存储数据,除此之外每个DbObject对象还有一个ExtensionDictionary(扩展字典)可以进行数据存储。…

vue3+ts+vite中封装axios,使用方法从0到1

一、安装axios npm install axios types/axios --save二、配置代理vite.config.ts&#xff0c;如果没有需要新建该文件 module.exports {server: {proxy: {/api: {target: http://localhost:5000, // 设置代理目标changeOrigin: true, // 是否改变请求源地址rewrite: (path)…

【开源】基于JAVA+Vue+SpringBoot的大病保险管理系统

目录 一、摘要1.1 项目介绍1.2 项目录屏 二、功能模块2.1 系统配置维护2.2 系统参保管理2.3 大病保险管理2.4 大病登记管理2.5 保险审核管理 三、系统详细设计3.1 系统整体配置功能设计3.2 大病人员模块设计3.3 大病保险模块设计3.4 大病登记模块设计3.5 保险审核模块设计 四、…

写点东西《Docker入门(上)》

写点东西《Docker入门&#xff08;上&#xff09;》 环境变量 Docker 镜像 Docker CMD 与 ENTRYPOINT 有什么区别 Docker 中的网络&#xff1a; Docker 存储&#xff1a; Docker 是一个工具&#xff0c;允许开发人员将他们的应用程序及其所有依赖项打包到一个容器中。然后&…

SQL--case语句

case语句&#xff0c;按从上到下的书写顺序计算每个WHEN子句的布尔表达式。返回第一个取值为TRUE的布尔表达式所对应的结果表达式的值。如果没有取值为TRUE的布尔表达式&#xff0c;则当指定了ELSE子句时,返回ELSE子句中指定的结果&#xff1b;如果没有指定ELSE子句&#xff0c…

【Docker】快速入门之Docker的安装及使用

一、引言 1、什么是Docker Docker是一个开源的应用容器引擎&#xff0c;它让开发者可以将他们的应用及其依赖打包到一个可移植的镜像中&#xff0c;然后发布到任何流行的Linux或Windows操作系统的机器上&#xff0c;也可以实现虚拟化。容器是完全使用沙箱机制&#xff0c;相互之…

1688采购工厂货源对接API

1688现有API列表 item_get 获得1688商品详情item_search 按关键字搜索商品item_search_img 按图搜索1688商品&#xff08;拍立淘&#xff09;item_search_suggest 获得搜索词推荐item_fee 获得商品快递费用seller_info 获得店铺详情item_search_shop 获得店铺的所有商品item_p…

解决python画图无法显示中文的问题

python画图遇到的问题&#xff1a; 中文不显示&#xff1a; 解决方法&#xff1a;把字体设置为支持中文的字体&#xff0c;比如黑体 黑体下载链接&#xff1a; 链接&#xff1a;https://pan.baidu.com/s/1BD7zQEBUfcIs6mC2CPYy6A?pwdv120 提取码&#xff1a;v120 pyhon…

SpringBoot默认配置文件

✅作者简介:大家好,我是Leo,热爱Java后端开发者,一个想要与大家共同进步的男人😉😉 🍎个人主页:Leo的博客 💞当前专栏: 循序渐进学SpringBoot ✨特色专栏: MySQL学习 🥭本文内容:SpringBoot默认配置文件 📚个人知识库: Leo知识库,欢迎大家访问 1.前言☕…

Git 基础指令

Git 基础指令 本章涵盖了我们在使用 Git 完成各种操作时将会用到的各种基本命令。 在学习完本章之后&#xff0c;我们应该能够配置并初始化一个仓库&#xff08;repository&#xff09;、开始或停止跟踪&#xff08;track&#xff09;文件、暂存&#xff08;stage&#xff09;…

教你如何打造自己的知识付费平台!

明理信息科技知识付费saas租户平台 一、确定目标群体 首先&#xff0c;你需要明确你的知识付费平台的目标用户是谁。这将帮助你确定所需的内容和功能&#xff0c;以及如何吸引和留住这些用户。例如&#xff0c;如果你的目标群体是职场新人&#xff0c;你的平台可能需要提供职…

如何编写和管理自动化测试用例

开始本篇文章之前&#xff0c;先来介绍下什么是自动化测试用例&#xff0c;即通过编写脚本程序来模拟用户操作和功能验证&#xff0c;并由机器自动执行无人值守的测试用例。 相比手工测试用例&#xff0c;自动化测试用例更快、更准确、更可靠、容易重复执行&#xff0c;且每次…

【python】python新年烟花代码【附源码】

欢迎来到英杰社区https://bbs.csdn.net/topics/617804998 新年的钟声即将敲响&#xff0c;为了庆祝这个喜庆的时刻&#xff0c;我们可以用 Python 编写一个炫彩夺目的烟花盛典。本文将详细介绍如何使用 Pygame 库创建一个令人惊叹的烟花效果。 一、效果图&#xff1a; 二…

植物大战僵尸-C语言搭建童年游戏(easyx)

游戏索引 游戏名称&#xff1a;植物大战僵尸 游戏介绍&#xff1a; 本游戏是在B站博主<程序员Rock>的视频指导下完成 想学的更详细的小伙伴可以移步到<程序员Rock>视频 语言项目&#xff1a;完整版植物大战僵尸&#xff01;可能是B站最好的植物大战僵尸教程了&…